Improving ColladaExporter to allow non-destructive cycles of import/export
parent
bbfd56046b
commit
b4b39e026d
|
@ -44,6 +44,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
#ifndef ASSIMP_BUILD_NO_COLLADA_EXPORTER
|
#ifndef ASSIMP_BUILD_NO_COLLADA_EXPORTER
|
||||||
#include "ColladaExporter.h"
|
#include "ColladaExporter.h"
|
||||||
|
|
||||||
|
#include <set>
|
||||||
|
|
||||||
using namespace Assimp;
|
using namespace Assimp;
|
||||||
|
|
||||||
namespace Assimp
|
namespace Assimp
|
||||||
|
@ -225,6 +227,8 @@ void ColladaExporter::WriteMaterials()
|
||||||
{
|
{
|
||||||
materials.resize( mScene->mNumMaterials);
|
materials.resize( mScene->mNumMaterials);
|
||||||
|
|
||||||
|
std::set<std::string> material_names;
|
||||||
|
|
||||||
/// collect all materials from the scene
|
/// collect all materials from the scene
|
||||||
size_t numTextures = 0;
|
size_t numTextures = 0;
|
||||||
for( size_t a = 0; a < mScene->mNumMaterials; ++a )
|
for( size_t a = 0; a < mScene->mNumMaterials; ++a )
|
||||||
|
@ -234,7 +238,12 @@ void ColladaExporter::WriteMaterials()
|
||||||
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") + boost::lexical_cast<std::string> (a) + name.C_Str();
|
if(material_names.find(name.C_Str()) != material_names.end()) {
|
||||||
|
materials[a].name = std::string( "m") + boost::lexical_cast<std::string> (a) + "_" + name.C_Str();
|
||||||
|
material_names.insert(materials[a].name);
|
||||||
|
} else {
|
||||||
|
materials[a].name = name.C_Str();
|
||||||
|
}
|
||||||
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( *it) )
|
if( !isalnum( *it) )
|
||||||
*it = '_';
|
*it = '_';
|
||||||
|
@ -560,6 +569,10 @@ void ColladaExporter::WriteSceneLibrary()
|
||||||
// Recursively writes the given node
|
// Recursively writes the given node
|
||||||
void ColladaExporter::WriteNode( const aiNode* pNode)
|
void ColladaExporter::WriteNode( const aiNode* pNode)
|
||||||
{
|
{
|
||||||
|
std::string name(pNode->mName.C_Str());
|
||||||
|
std::transform(name.begin(), name.end(), name.begin(), ::tolower);
|
||||||
|
|
||||||
|
if(name.compare("myscene") != 0) {
|
||||||
mOutput << startstr << "<node id=\"" << pNode->mName.data << "\" name=\"" << pNode->mName.data << "\">" << endstr;
|
mOutput << startstr << "<node id=\"" << pNode->mName.data << "\" name=\"" << pNode->mName.data << "\">" << endstr;
|
||||||
PushTag();
|
PushTag();
|
||||||
|
|
||||||
|
@ -595,13 +608,16 @@ void ColladaExporter::WriteNode( const aiNode* pNode)
|
||||||
PopTag();
|
PopTag();
|
||||||
mOutput << startstr << "</instance_geometry>" << endstr;
|
mOutput << startstr << "</instance_geometry>" << endstr;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// recurse into subnodes
|
// recurse into subnodes
|
||||||
for( size_t a = 0; a < pNode->mNumChildren; ++a )
|
for( size_t a = 0; a < pNode->mNumChildren; ++a )
|
||||||
WriteNode( pNode->mChildren[a]);
|
WriteNode( pNode->mChildren[a]);
|
||||||
|
|
||||||
|
if(name.compare("myscene") != 0) {
|
||||||
PopTag();
|
PopTag();
|
||||||
mOutput << startstr << "</node>" << endstr;
|
mOutput << startstr << "</node>" << endstr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue