Optimisation of FBX node name uniqueness

pull/2076/head
FRICOTEAUX 2018-07-30 17:27:03 +02:00
parent 28fd396db4
commit 92490eea01
2 changed files with 12 additions and 24 deletions

View File

@ -185,12 +185,12 @@ void Converter::ConvertNodes( uint64_t id, aiNode& parent, const aiMatrix4x4& pa
} }
if ( !name_carrier ) { if ( !name_carrier ) {
NodeNameCache::const_iterator it( std::find( mNodeNames.begin(), mNodeNames.end(), original_name ) ); NodeNameCache::const_iterator it = mNodeNames.find(original_name);
if ( it != mNodeNames.end() ) { if ( it != mNodeNames.end() ) {
original_name = original_name + std::string( "001" ); original_name = original_name + std::string( "001" );
} }
mNodeNames.push_back( original_name ); mNodeNames.insert( original_name );
nodes_chain.push_back( new aiNode( original_name ) ); nodes_chain.push_back( new aiNode( original_name ) );
} else { } else {
original_name = nodes_chain.back()->mName.C_Str(); original_name = nodes_chain.back()->mName.C_Str();
@ -398,30 +398,18 @@ void Converter::ConvertCamera( const Camera& cam, const std::string &orig_name )
out_camera->mClipPlaneFar = cam.FarPlane(); out_camera->mClipPlaneFar = cam.FarPlane();
} }
static bool HasName( NodeNameCache &cache, const std::string &name ) { void Converter::GetUniqueName( const std::string &name, std::string &uniqueName )
NodeNameCache::const_iterator it( std::find( cache.begin(), cache.end(), name ) ); {
return it != cache.end(); int i = 0;
}
void Converter::GetUniqueName( const std::string &name, std::string &uniqueName ) {
if ( !HasName( mNodeNames, name ) ) {
uniqueName = name; uniqueName = name;
mNodeNames.push_back( uniqueName ); while (mNodeNames.find(uniqueName) != mNodeNames.end())
return; {
}
int i( 0 );
std::string newName( name );
while ( HasName( mNodeNames, newName ) ) {
++i; ++i;
newName.clear();
newName += name;
std::stringstream ext; std::stringstream ext;
ext << std::setfill( '0' ) << std::setw( 3 ) << i; ext << name << std::setfill('0') << std::setw(3) << i;
newName += ext.str(); uniqueName = ext.str();
} }
uniqueName = newName; mNodeNames.insert(uniqueName);
mNodeNames.push_back( uniqueName );
} }

View File

@ -68,7 +68,7 @@ namespace FBX {
class Document; class Document;
using NodeNameCache = std::vector<std::string>; using NodeNameCache = std::set<std::string>;
/** /**
* Convert a FBX #Document to #aiScene * Convert a FBX #Document to #aiScene