MaterialSystem: fix some findings.
parent
c849e0108d
commit
dfaea27dfc
|
@ -42,8 +42,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
* @brief Implementation of the material system of the library
|
* @brief Implementation of the material system of the library
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include "Hash.h"
|
#include "Hash.h"
|
||||||
#include "fast_atof.h"
|
#include "fast_atof.h"
|
||||||
#include "ParsingUtils.h"
|
#include "ParsingUtils.h"
|
||||||
|
@ -71,7 +69,7 @@ aiReturn aiGetMaterialProperty(const aiMaterial* pMat,
|
||||||
* could be improved by hashing, but it's possibly
|
* could be improved by hashing, but it's possibly
|
||||||
* no worth the effort (we're bound to C structures,
|
* no worth the effort (we're bound to C structures,
|
||||||
* thus std::map or derivates are not applicable. */
|
* thus std::map or derivates are not applicable. */
|
||||||
for (unsigned int i = 0; i < pMat->mNumProperties;++i) {
|
for ( unsigned int i = 0; i < pMat->mNumProperties; ++i ) {
|
||||||
aiMaterialProperty* prop = pMat->mProperties[i];
|
aiMaterialProperty* prop = pMat->mProperties[i];
|
||||||
|
|
||||||
if (prop /* just for safety ... */
|
if (prop /* just for safety ... */
|
||||||
|
@ -151,14 +149,15 @@ aiReturn aiGetMaterialFloatArray(const aiMaterial* pMat,
|
||||||
iWrite = *pMax;
|
iWrite = *pMax;
|
||||||
}
|
}
|
||||||
// strings are zero-terminated with a 32 bit length prefix, so this is safe
|
// strings are zero-terminated with a 32 bit length prefix, so this is safe
|
||||||
const char* cur = prop->mData+4;
|
const char *cur = prop->mData + 4;
|
||||||
ai_assert(prop->mDataLength>=5 && !prop->mData[prop->mDataLength-1]);
|
ai_assert( prop->mDataLength >= 5 );
|
||||||
for (unsigned int a = 0; ;++a) {
|
ai_assert( !prop->mData[ prop->mDataLength - 1 ] );
|
||||||
|
for ( unsigned int a = 0; ;++a) {
|
||||||
cur = fast_atoreal_move<ai_real>(cur,pOut[a]);
|
cur = fast_atoreal_move<ai_real>(cur,pOut[a]);
|
||||||
if(a==iWrite-1) {
|
if ( a==iWrite-1 ) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(!IsSpace(*cur)) {
|
if ( !IsSpace(*cur) ) {
|
||||||
DefaultLogger::get()->error("Material property" + std::string(pKey) +
|
DefaultLogger::get()->error("Material property" + std::string(pKey) +
|
||||||
" is a string; failed to parse a float array out of it.");
|
" is a string; failed to parse a float array out of it.");
|
||||||
return AI_FAILURE;
|
return AI_FAILURE;
|
||||||
|
@ -170,7 +169,6 @@ aiReturn aiGetMaterialFloatArray(const aiMaterial* pMat,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return AI_SUCCESS;
|
return AI_SUCCESS;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
@ -224,8 +222,9 @@ aiReturn aiGetMaterialIntegerArray(const aiMaterial* pMat,
|
||||||
iWrite = *pMax;
|
iWrite = *pMax;
|
||||||
}
|
}
|
||||||
// strings are zero-terminated with a 32 bit length prefix, so this is safe
|
// strings are zero-terminated with a 32 bit length prefix, so this is safe
|
||||||
const char* cur = prop->mData+4;
|
const char *cur = prop->mData+4;
|
||||||
ai_assert(prop->mDataLength>=5 && !prop->mData[prop->mDataLength-1]);
|
ai_assert( prop->mDataLength >= 5 );
|
||||||
|
ai_assert( !prop->mData[ prop->mDataLength - 1 ] );
|
||||||
for (unsigned int a = 0; ;++a) {
|
for (unsigned int a = 0; ;++a) {
|
||||||
pOut[a] = strtol10(cur,&cur);
|
pOut[a] = strtol10(cur,&cur);
|
||||||
if(a==iWrite-1) {
|
if(a==iWrite-1) {
|
||||||
|
@ -298,7 +297,8 @@ aiReturn aiGetMaterialString(const aiMaterial* pMat,
|
||||||
// The string is stored as 32 but length prefix followed by zero-terminated UTF8 data
|
// The string is stored as 32 but length prefix followed by zero-terminated UTF8 data
|
||||||
pOut->length = static_cast<unsigned int>(*reinterpret_cast<uint32_t*>(prop->mData));
|
pOut->length = static_cast<unsigned int>(*reinterpret_cast<uint32_t*>(prop->mData));
|
||||||
|
|
||||||
ai_assert(pOut->length+1+4==prop->mDataLength && !prop->mData[prop->mDataLength-1]);
|
ai_assert( pOut->length+1+4==prop->mDataLength );
|
||||||
|
ai_assert( !prop->mData[ prop->mDataLength - 1 ] );
|
||||||
memcpy(pOut->data,prop->mData+4,pOut->length+1);
|
memcpy(pOut->data,prop->mData+4,pOut->length+1);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -317,12 +317,12 @@ ASSIMP_API unsigned int aiGetMaterialTextureCount(const C_STRUCT aiMaterial* pMa
|
||||||
{
|
{
|
||||||
ai_assert (pMat != NULL);
|
ai_assert (pMat != NULL);
|
||||||
|
|
||||||
/* Textures are always stored with ascending indices (ValidateDS provides a check, so we don't need to do it again) */
|
// Textures are always stored with ascending indices (ValidateDS provides a check, so we don't need to do it again)
|
||||||
unsigned int max = 0;
|
unsigned int max = 0;
|
||||||
for (unsigned int i = 0; i < pMat->mNumProperties;++i) {
|
for (unsigned int i = 0; i < pMat->mNumProperties;++i) {
|
||||||
aiMaterialProperty* prop = pMat->mProperties[i];
|
aiMaterialProperty* prop = pMat->mProperties[i];
|
||||||
|
|
||||||
if (prop /* just a sanity check ... */
|
if ( prop /* just a sanity check ... */
|
||||||
&& 0 == strcmp( prop->mKey.data, _AI_MATKEY_TEXTURE_BASE )
|
&& 0 == strcmp( prop->mKey.data, _AI_MATKEY_TEXTURE_BASE )
|
||||||
&& prop->mSemantic == type) {
|
&& prop->mSemantic == type) {
|
||||||
|
|
||||||
|
@ -381,14 +381,17 @@ aiReturn aiGetMaterialTexture(const C_STRUCT aiMaterial* mat,
|
||||||
return AI_SUCCESS;
|
return AI_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const unsigned int DefaultNumAllocated = 5;
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
// Construction. Actually the one and only way to get an aiMaterial instance
|
// Construction. Actually the one and only way to get an aiMaterial instance
|
||||||
aiMaterial::aiMaterial()
|
aiMaterial::aiMaterial()
|
||||||
|
: mNumProperties( 0 )
|
||||||
|
, mNumAllocated( DefaultNumAllocated )
|
||||||
|
, mProperties( NULL )
|
||||||
{
|
{
|
||||||
// Allocate 5 entries by default
|
// Allocate 5 entries by default
|
||||||
mNumProperties = 0;
|
mProperties = new aiMaterialProperty*[ DefaultNumAllocated ];
|
||||||
mNumAllocated = 5;
|
|
||||||
mProperties = new aiMaterialProperty*[5];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
@ -543,10 +546,10 @@ aiReturn aiMaterial::AddProperty (const aiString* pInput,
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
uint32_t Assimp :: ComputeMaterialHash(const aiMaterial* mat, bool includeMatName /*= false*/)
|
uint32_t Assimp::ComputeMaterialHash(const aiMaterial* mat, bool includeMatName /*= false*/)
|
||||||
{
|
{
|
||||||
uint32_t hash = 1503; // magic start value, chosen to be my birthday :-)
|
uint32_t hash = 1503; // magic start value, chosen to be my birthday :-)
|
||||||
for (unsigned int i = 0; i < mat->mNumProperties;++i) {
|
for ( unsigned int i = 0; i < mat->mNumProperties; ++i ) {
|
||||||
aiMaterialProperty* prop;
|
aiMaterialProperty* prop;
|
||||||
|
|
||||||
// Exclude all properties whose first character is '?' from the hash
|
// Exclude all properties whose first character is '?' from the hash
|
||||||
|
@ -585,15 +588,16 @@ void aiMaterial::CopyPropertyList(aiMaterial* pcDest,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(pcOld)
|
if ( pcOld ) {
|
||||||
delete[] pcOld;
|
delete[] pcOld;
|
||||||
|
}
|
||||||
|
|
||||||
for (unsigned int i = iOldNum; i< pcDest->mNumProperties;++i) {
|
for (unsigned int i = iOldNum; i< pcDest->mNumProperties;++i) {
|
||||||
aiMaterialProperty* propSrc = pcSrc->mProperties[i];
|
aiMaterialProperty* propSrc = pcSrc->mProperties[i];
|
||||||
|
|
||||||
// search whether we have already a property with this name -> if yes, overwrite it
|
// search whether we have already a property with this name -> if yes, overwrite it
|
||||||
aiMaterialProperty* prop;
|
aiMaterialProperty* prop;
|
||||||
for (unsigned int q = 0; q < iOldNum;++q) {
|
for ( unsigned int q = 0; q < iOldNum; ++q ) {
|
||||||
prop = pcDest->mProperties[q];
|
prop = pcDest->mProperties[q];
|
||||||
if (prop /* just for safety */ && prop->mKey == propSrc->mKey && prop->mSemantic == propSrc->mSemantic
|
if (prop /* just for safety */ && prop->mKey == propSrc->mKey && prop->mSemantic == propSrc->mSemantic
|
||||||
&& prop->mIndex == propSrc->mIndex) {
|
&& prop->mIndex == propSrc->mIndex) {
|
||||||
|
@ -617,5 +621,4 @@ void aiMaterial::CopyPropertyList(aiMaterial* pcDest,
|
||||||
prop->mData = new char[propSrc->mDataLength];
|
prop->mData = new char[propSrc->mDataLength];
|
||||||
memcpy(prop->mData,propSrc->mData,prop->mDataLength);
|
memcpy(prop->mData,propSrc->mData,prop->mDataLength);
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue