Keep original materials names after RemoveRedundant materials process and export to collada
parent
54c5acd02d
commit
8e8757f800
|
@ -636,9 +636,24 @@ void ColladaExporter::WriteMaterials()
|
||||||
const aiMaterial* mat = mScene->mMaterials[a];
|
const aiMaterial* mat = mScene->mMaterials[a];
|
||||||
|
|
||||||
aiString name;
|
aiString name;
|
||||||
if( mat->Get( AI_MATKEY_NAME, name) != aiReturn_SUCCESS )
|
if( mat->Get( AI_MATKEY_NAME, name) != aiReturn_SUCCESS ) {
|
||||||
name = "mat";
|
name = "mat";
|
||||||
materials[a].name = std::string( "m") + to_string(a) + name.C_Str();
|
materials[a].name = std::string( "m") + to_string(a) + name.C_Str();
|
||||||
|
} else {
|
||||||
|
// try to use the material's name if no other material has already taken it, else append #
|
||||||
|
std::string testName = name.C_Str();
|
||||||
|
size_t materialCountWithThisName = 0;
|
||||||
|
for( size_t i = 0; i < a; i ++ ) {
|
||||||
|
if( materials[i].name == testName ) {
|
||||||
|
materialCountWithThisName ++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if( materialCountWithThisName == 0 ) {
|
||||||
|
materials[a].name = name.C_Str();
|
||||||
|
} else {
|
||||||
|
materials[a].name = std::string(name.C_Str()) + to_string(materialCountWithThisName);
|
||||||
|
}
|
||||||
|
}
|
||||||
for( std::string::iterator it = materials[a].name.begin(); it != materials[a].name.end(); ++it ) {
|
for( std::string::iterator it = materials[a].name.begin(); it != materials[a].name.end(); ++it ) {
|
||||||
if( !isalnum_C( *it ) ) {
|
if( !isalnum_C( *it ) ) {
|
||||||
*it = '_';
|
*it = '_';
|
||||||
|
|
|
@ -177,12 +177,14 @@ void RemoveRedundantMatsProcess::Execute( aiScene* pScene)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// generate new names for all modified materials
|
// generate new names for modified materials that had no names
|
||||||
const unsigned int idx = aiMappingTable[p];
|
const unsigned int idx = aiMappingTable[p];
|
||||||
if (ppcMaterials[idx]) {
|
if (ppcMaterials[idx]) {
|
||||||
aiString sz;
|
aiString sz;
|
||||||
|
if( ppcMaterials[idx]->Get(AI_MATKEY_NAME, sz) != AI_SUCCESS ) {
|
||||||
sz.length = ::ai_snprintf(sz.data,MAXLEN,"JoinedMaterial_#%u",p);
|
sz.length = ::ai_snprintf(sz.data,MAXLEN,"JoinedMaterial_#%u",p);
|
||||||
((aiMaterial*)ppcMaterials[idx])->AddProperty(&sz,AI_MATKEY_NAME);
|
((aiMaterial*)ppcMaterials[idx])->AddProperty(&sz,AI_MATKEY_NAME);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
ppcMaterials[idx] = pScene->mMaterials[p];
|
ppcMaterials[idx] = pScene->mMaterials[p];
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue