Merge pull request #2391 from mlavik1/issue_2390

FBX: Fix for loading taking a very long time on models with duplicate names
pull/2378/head^2
Kim Kulling 2019-04-06 09:34:43 +02:00 committed by GitHub
commit 03bd8905f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 15 deletions

View File

@ -78,6 +78,16 @@ namespace Assimp {
FBXConverter::FBXConverter(aiScene* out, const Document& doc) FBXConverter::FBXConverter(aiScene* out, const Document& doc)
: defaultMaterialIndex() : defaultMaterialIndex()
, lights()
, cameras()
, textures()
, materials_converted()
, textures_converted()
, meshes_converted()
, node_anim_chain_bits()
, mNodeNameInstances()
, mNodeNames()
, anim_fps()
, out(out) , out(out)
, doc(doc) { , doc(doc) {
// animations need to be converted first since this will // 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) void FBXConverter::GetUniqueName(const std::string &name, std::string &uniqueName)
{ {
int i = 0;
uniqueName = name; uniqueName = name;
int i = 0;
auto it = mNodeNameInstances.find(name); // duplicate node name instance count
if (it != mNodeNameInstances.end())
{
i = it->second;
while (mNodeNames.find(uniqueName) != mNodeNames.end()) while (mNodeNames.find(uniqueName) != mNodeNames.end())
{ {
++i; i++;
std::stringstream ext; std::stringstream ext;
ext << name << std::setfill('0') << std::setw(3) << i; ext << name << std::setfill('0') << std::setw(3) << i;
uniqueName = ext.str(); uniqueName = ext.str();
} }
}
mNodeNameInstances[name] = i;
mNodeNames.insert(uniqueName); mNodeNames.insert(uniqueName);
} }
const char* FBXConverter::NameTransformationComp(TransformationComp comp) { const char* FBXConverter::NameTransformationComp(TransformationComp comp) {
switch (comp) { switch (comp) {
case TransformationComp_Translation: case TransformationComp_Translation:

View File

@ -58,6 +58,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <assimp/texture.h> #include <assimp/texture.h>
#include <assimp/camera.h> #include <assimp/camera.h>
#include <assimp/StringComparison.h> #include <assimp/StringComparison.h>
#include <unordered_map>
#include <unordered_set>
struct aiScene; struct aiScene;
struct aiNode; struct aiNode;
@ -74,8 +76,6 @@ namespace FBX {
class Document; class Document;
using NodeNameCache = std::set<std::string>;
/** /**
* Convert a FBX #Document to #aiScene * Convert a FBX #Document to #aiScene
* @param out Empty scene to be populated * @param out Empty scene to be populated
@ -419,7 +419,6 @@ private:
void TransferDataToScene(); void TransferDataToScene();
private: private:
// 0: not assigned yet, others: index is value - 1 // 0: not assigned yet, others: index is value - 1
unsigned int defaultMaterialIndex; unsigned int defaultMaterialIndex;
@ -430,21 +429,26 @@ private:
std::vector<aiCamera*> cameras; std::vector<aiCamera*> cameras;
std::vector<aiTexture*> textures; std::vector<aiTexture*> textures;
using MaterialMap = std::map<const Material*, unsigned int>;
typedef std::map<const Material*, unsigned int> MaterialMap;
MaterialMap materials_converted; MaterialMap materials_converted;
typedef std::map<const Video*, unsigned int> VideoMap; using VideoMap = std::map<const Video*, unsigned int>;
VideoMap textures_converted; VideoMap textures_converted;
typedef std::map<const Geometry*, std::vector<unsigned int> > MeshMap; using MeshMap = std::map<const Geometry*, std::vector<unsigned int> >;
MeshMap meshes_converted; MeshMap meshes_converted;
// fixed node name -> which trafo chain components have animations? // fixed node name -> which trafo chain components have animations?
typedef std::map<std::string, unsigned int> NodeAnimBitMap; using NodeAnimBitMap = std::map<std::string, unsigned int> ;
NodeAnimBitMap node_anim_chain_bits; NodeAnimBitMap node_anim_chain_bits;
// number of nodes with the same name
using NodeAnimNameMap = std::unordered_map<std::string, unsigned int>;
NodeAnimNameMap mNodeNameInstances;
using NodeNameCache = std::unordered_set<std::string>;
NodeNameCache mNodeNames; NodeNameCache mNodeNames;
double anim_fps; double anim_fps;
aiScene* const out; aiScene* const out;