@@ -19,7 +19,7 @@ vector<aiBone*> bones;
1919unsigned int numBones = 0 ;
2020
2121std::vector<String> materialsInFile;
22-
22+ std::vector<String> meshesInFile;
2323
2424bool writeNormals = false ;
2525bool writeTangents = false ;
@@ -28,6 +28,15 @@ bool writeBoneWeights = false;
2828bool writeUVs = false ;
2929bool writeSecondaryUVs = false ;
3030
31+ bool hasMesh (String meshName) {
32+ for (int i=0 ; i < meshesInFile.size (); i++) {
33+ if (meshesInFile[i] == meshName) {
34+ return true ;
35+ }
36+ }
37+ return false ;
38+ }
39+
3140bool hasMaterial (String materialName) {
3241 for (int i=0 ; i < materialsInFile.size (); i++) {
3342 if (materialsInFile[i] == materialName) {
@@ -46,7 +55,7 @@ unsigned int addBone(aiBone *bone) {
4655 return bones.size ()-1 ;
4756}
4857
49- void addToMesh (String prefix, Polycode::Mesh *tmesh, const struct aiScene *sc, const struct aiNode * nd, bool swapZY, bool addSubmeshes, bool listOnly, ObjectEntry *parentSceneObject, String overrideMaterial, ObjectEntry *materialsParent, String assetPrefixPath) {
58+ void addToMesh (String prefix, Polycode::Mesh *tmesh, const struct aiScene *sc, const struct aiNode * nd, bool swapZY, bool addSubmeshes, bool listOnly, ObjectEntry *parentSceneObject, String overrideMaterial, ObjectEntry *materialsParent, String assetPrefixPath, String baseFileName ) {
5059 int i, nIgnoredPolygons = 0 ;
5160 unsigned int n = 0 , t;
5261 // draw all meshes assigned to this node
@@ -62,9 +71,26 @@ void addToMesh(String prefix, Polycode::Mesh *tmesh, const struct aiScene *sc, c
6271
6372 Vector3 bBox;
6473
74+ String meshFileName = String (nd->mName .data );
75+
76+ if (meshFileName == " " ) {
77+ meshFileName = baseFileName;
78+ }
79+
80+
81+ int idx = 0 ;
82+ String baseMeshFileName = meshFileName;
83+
84+ while (hasMesh (meshFileName)) {
85+ meshFileName = baseMeshFileName + String::IntToString (idx);
86+ idx++;
87+ }
88+
89+ meshesInFile.push_back (meshFileName);
90+
6591 if (listOnly) {
6692 if (!addSubmeshes) {
67- printf (" %s%s.mesh\n " , prefix.c_str (), nd-> mName . data );
93+ printf (" %s%s.mesh\n " , prefix.c_str (), meshFileName. c_str () );
6894 }
6995 } else {
7096 printf (" Importing mesh:%s (%d vertices) (%d faces) \n " , mesh->mName .data , mesh->mNumVertices , mesh->mNumFaces );
@@ -149,7 +175,7 @@ void addToMesh(String prefix, Polycode::Mesh *tmesh, const struct aiScene *sc, c
149175 }
150176
151177 if (!addSubmeshes && !listOnly) {
152- String fileNameMesh = prefix+String (nd-> mName . data ) +" .mesh" ;
178+ String fileNameMesh = prefix+meshFileName +" .mesh" ;
153179 OSFILE *outFile = OSBasics::open (fileNameMesh.c_str (), " wb" );
154180 tmesh->saveToFile (outFile, writeNormals, writeTangents, writeColors, writeBoneWeights, writeUVs, writeSecondaryUVs);
155181 OSBasics::close (outFile);
@@ -257,7 +283,7 @@ void addToMesh(String prefix, Polycode::Mesh *tmesh, const struct aiScene *sc, c
257283
258284 // draw all children
259285 for (n = 0 ; n < nd->mNumChildren ; ++n) {
260- addToMesh (prefix, tmesh, sc, nd->mChildren [n], swapZY, addSubmeshes, listOnly, parentSceneObject, overrideMaterial, materialsParent, assetPrefixPath);
286+ addToMesh (prefix, tmesh, sc, nd->mChildren [n], swapZY, addSubmeshes, listOnly, parentSceneObject, overrideMaterial, materialsParent, assetPrefixPath, baseFileName );
261287 }
262288}
263289
@@ -333,7 +359,7 @@ int exportToFile(String prefix, bool swapZY, bool addSubmeshes, bool listOnly, b
333359
334360 Polycode::Mesh *mesh = new Polycode::Mesh (Mesh::TRI_MESH);
335361 mesh->indexedMesh = true ;
336- addToMesh (prefix, mesh, scene, scene->mRootNode , swapZY, addSubmeshes, listOnly, children, overrideMaterial, materialsParent, assetPrefixPath);
362+ addToMesh (prefix, mesh, scene, scene->mRootNode , swapZY, addSubmeshes, listOnly, children, overrideMaterial, materialsParent, assetPrefixPath, baseFileName );
337363
338364
339365 if (addSubmeshes) {
0 commit comments