- Bugfix: ColladaExporter avoids output of empty xml elements
git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@1187 67173fc5-114c-0410-ac8e-9d2fd5bffc1fpull/5/head
parent
648e8fe924
commit
9d4c46b53c
|
@ -215,6 +215,7 @@ void ColladaExporter::WriteMaterials()
|
||||||
materials.resize( mScene->mNumMaterials);
|
materials.resize( mScene->mNumMaterials);
|
||||||
|
|
||||||
/// collect all materials from the scene
|
/// collect all materials from the scene
|
||||||
|
size_t numTextures = 0;
|
||||||
for( size_t a = 0; a < mScene->mNumMaterials; ++a )
|
for( size_t a = 0; a < mScene->mNumMaterials; ++a )
|
||||||
{
|
{
|
||||||
const aiMaterial* mat = mScene->mMaterials[a];
|
const aiMaterial* mat = mScene->mMaterials[a];
|
||||||
|
@ -228,16 +229,24 @@ void ColladaExporter::WriteMaterials()
|
||||||
materials[a].name[pos] = 'x';
|
materials[a].name[pos] = 'x';
|
||||||
|
|
||||||
ReadMaterialSurface( materials[a].ambient, mat, aiTextureType_AMBIENT, AI_MATKEY_COLOR_AMBIENT);
|
ReadMaterialSurface( materials[a].ambient, mat, aiTextureType_AMBIENT, AI_MATKEY_COLOR_AMBIENT);
|
||||||
|
if( !materials[a].ambient.texture.empty() ) numTextures++;
|
||||||
ReadMaterialSurface( materials[a].diffuse, mat, aiTextureType_DIFFUSE, AI_MATKEY_COLOR_DIFFUSE);
|
ReadMaterialSurface( materials[a].diffuse, mat, aiTextureType_DIFFUSE, AI_MATKEY_COLOR_DIFFUSE);
|
||||||
|
if( !materials[a].diffuse.texture.empty() ) numTextures++;
|
||||||
ReadMaterialSurface( materials[a].specular, mat, aiTextureType_SPECULAR, AI_MATKEY_COLOR_SPECULAR);
|
ReadMaterialSurface( materials[a].specular, mat, aiTextureType_SPECULAR, AI_MATKEY_COLOR_SPECULAR);
|
||||||
|
if( !materials[a].specular.texture.empty() ) numTextures++;
|
||||||
ReadMaterialSurface( materials[a].emissive, mat, aiTextureType_EMISSIVE, AI_MATKEY_COLOR_EMISSIVE);
|
ReadMaterialSurface( materials[a].emissive, mat, aiTextureType_EMISSIVE, AI_MATKEY_COLOR_EMISSIVE);
|
||||||
|
if( !materials[a].emissive.texture.empty() ) numTextures++;
|
||||||
ReadMaterialSurface( materials[a].reflective, mat, aiTextureType_REFLECTION, AI_MATKEY_COLOR_REFLECTIVE);
|
ReadMaterialSurface( materials[a].reflective, mat, aiTextureType_REFLECTION, AI_MATKEY_COLOR_REFLECTIVE);
|
||||||
|
if( !materials[a].reflective.texture.empty() ) numTextures++;
|
||||||
ReadMaterialSurface( materials[a].normal, mat, aiTextureType_NORMALS, NULL, 0, 0);
|
ReadMaterialSurface( materials[a].normal, mat, aiTextureType_NORMALS, NULL, 0, 0);
|
||||||
|
if( !materials[a].normal.texture.empty() ) numTextures++;
|
||||||
|
|
||||||
mat->Get( AI_MATKEY_SHININESS, materials[a].shininess);
|
mat->Get( AI_MATKEY_SHININESS, materials[a].shininess);
|
||||||
}
|
}
|
||||||
|
|
||||||
// output textures if present
|
// output textures if present
|
||||||
|
if( numTextures > 0 )
|
||||||
|
{
|
||||||
mOutput << startstr << "<library_images>" << endstr;
|
mOutput << startstr << "<library_images>" << endstr;
|
||||||
PushTag();
|
PushTag();
|
||||||
for( std::vector<Material>::const_iterator it = materials.begin(); it != materials.end(); ++it )
|
for( std::vector<Material>::const_iterator it = materials.begin(); it != materials.end(); ++it )
|
||||||
|
@ -252,8 +261,11 @@ void ColladaExporter::WriteMaterials()
|
||||||
}
|
}
|
||||||
PopTag();
|
PopTag();
|
||||||
mOutput << startstr << "</library_images>" << endstr;
|
mOutput << startstr << "</library_images>" << endstr;
|
||||||
|
}
|
||||||
|
|
||||||
// output effects - those are the actual carriers of information
|
// output effects - those are the actual carriers of information
|
||||||
|
if( !materials.empty() )
|
||||||
|
{
|
||||||
mOutput << startstr << "<library_effects>" << endstr;
|
mOutput << startstr << "<library_effects>" << endstr;
|
||||||
PushTag();
|
PushTag();
|
||||||
for( std::vector<Material>::const_iterator it = materials.begin(); it != materials.end(); ++it )
|
for( std::vector<Material>::const_iterator it = materials.begin(); it != materials.end(); ++it )
|
||||||
|
@ -290,9 +302,9 @@ void ColladaExporter::WriteMaterials()
|
||||||
|
|
||||||
WriteTextureColorEntry( mat.reflective, "reflective", mat.name + "-reflective-sampler");
|
WriteTextureColorEntry( mat.reflective, "reflective", mat.name + "-reflective-sampler");
|
||||||
|
|
||||||
// deactivated because the Collada spec PHONG model does not allow other textures.
|
// deactivated because the Collada spec PHONG model does not allow other textures.
|
||||||
// if( !mat.normal.texture.empty() )
|
// if( !mat.normal.texture.empty() )
|
||||||
// WriteTextureColorEntry( mat.normal, "bump", mat.name + "-normal-sampler");
|
// WriteTextureColorEntry( mat.normal, "bump", mat.name + "-normal-sampler");
|
||||||
|
|
||||||
|
|
||||||
PopTag();
|
PopTag();
|
||||||
|
@ -321,6 +333,7 @@ void ColladaExporter::WriteMaterials()
|
||||||
}
|
}
|
||||||
PopTag();
|
PopTag();
|
||||||
mOutput << startstr << "</library_materials>" << endstr;
|
mOutput << startstr << "</library_materials>" << endstr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
|
Loading…
Reference in New Issue