diff --git a/code/FBXConverter.cpp b/code/FBXConverter.cpp index dafc9bfa4..09ae06a64 100644 --- a/code/FBXConverter.cpp +++ b/code/FBXConverter.cpp @@ -78,6 +78,16 @@ namespace Assimp { FBXConverter::FBXConverter(aiScene* out, const Document& doc) : defaultMaterialIndex() + , lights() + , cameras() + , textures() + , materials_converted() + , textures_converted() + , meshes_converted() + , node_anim_chain_bits() + , mNodeNameInstances() + , mNodeNames() + , anim_fps() , out(out) , doc(doc) { // animations need to be converted first since this will @@ -410,19 +420,24 @@ namespace Assimp { void FBXConverter::GetUniqueName(const std::string &name, std::string &uniqueName) { - int i = 0; uniqueName = name; - while (mNodeNames.find(uniqueName) != mNodeNames.end()) + int i = 0; + auto it = mNodeNameInstances.find(name); // duplicate node name instance count + if (it != mNodeNameInstances.end()) { - ++i; - std::stringstream ext; - ext << name << std::setfill('0') << std::setw(3) << i; - uniqueName = ext.str(); + i = it->second; + while (mNodeNames.find(uniqueName) != mNodeNames.end()) + { + i++; + std::stringstream ext; + ext << name << std::setfill('0') << std::setw(3) << i; + uniqueName = ext.str(); + } } + mNodeNameInstances[name] = i; mNodeNames.insert(uniqueName); } - const char* FBXConverter::NameTransformationComp(TransformationComp comp) { switch (comp) { case TransformationComp_Translation: diff --git a/code/FBXConverter.h b/code/FBXConverter.h index 398baa445..50637468b 100644 --- a/code/FBXConverter.h +++ b/code/FBXConverter.h @@ -58,6 +58,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include +#include struct aiScene; struct aiNode; @@ -74,8 +76,6 @@ namespace FBX { class Document; -using NodeNameCache = std::set; - /** * Convert a FBX #Document to #aiScene * @param out Empty scene to be populated @@ -419,7 +419,6 @@ private: void TransferDataToScene(); private: - // 0: not assigned yet, others: index is value - 1 unsigned int defaultMaterialIndex; @@ -429,22 +428,27 @@ private: std::vector lights; std::vector cameras; std::vector textures; - - typedef std::map MaterialMap; + using MaterialMap = std::map; MaterialMap materials_converted; - typedef std::map VideoMap; + using VideoMap = std::map; VideoMap textures_converted; - typedef std::map > MeshMap; + using MeshMap = std::map >; MeshMap meshes_converted; // fixed node name -> which trafo chain components have animations? - typedef std::map NodeAnimBitMap; + using NodeAnimBitMap = std::map ; NodeAnimBitMap node_anim_chain_bits; + // number of nodes with the same name + using NodeAnimNameMap = std::unordered_map; + NodeAnimNameMap mNodeNameInstances; + + using NodeNameCache = std::unordered_set; NodeNameCache mNodeNames; + double anim_fps; aiScene* const out;