Преглед на файлове

Adding multi mesh import from same file

I've edited importMesh and isDescendantOf method to accepts array of meshes to import from same file. If you use .incremental file with this method it loads meshes one by one (like when you import whole .incremental file). I don't know if it's the clearest way to do that, but the idea is here ;)
OBRE Nicolas преди 11 години
родител
ревизия
4132e9ee5b
променени са 1 файла, в които са добавени 15 реда и са изтрити 9 реда
  1. 15 9
      Babylon/Tools/babylon.sceneLoader.js

+ 15 - 9
Babylon/Tools/babylon.sceneLoader.js

@@ -1,4 +1,4 @@
-"use strict";
+"use strict";
 
 
 var BABYLON = BABYLON || {}; 
 var BABYLON = BABYLON || {}; 
 
 
@@ -448,11 +448,14 @@ var BABYLON = BABYLON || {};
         return mesh;
         return mesh;
     };
     };
 
 
-    var isDescendantOf = function (mesh, name, hierarchyIds) {
-        if (mesh.name === name) {
-            hierarchyIds.push(mesh.id);
-            return true;
-        }
+    var isDescendantOf = function (mesh, names, hierarchyIds) {
+		names = (names instanceof Array) ? names : [names];
+		for(var i in names){
+			if (mesh.name === names[i]) {
+				hierarchyIds.push(mesh.id);
+				return true;
+			}
+		}
 
 
         if (mesh.parentId && hierarchyIds.indexOf(mesh.parentId) !== -1) {
         if (mesh.parentId && hierarchyIds.indexOf(mesh.parentId) !== -1) {
             hierarchyIds.push(mesh.id);
             hierarchyIds.push(mesh.id);
@@ -521,7 +524,7 @@ var BABYLON = BABYLON || {};
                 scene._selectionOctree.addMesh(mesh);
                 scene._selectionOctree.addMesh(mesh);
             }
             }
         },
         },
-        ImportMesh: function (meshName, rootUrl, sceneFilename, scene, then, progressCallBack) {
+        ImportMesh: function (meshesNames, rootUrl, sceneFilename, scene, then, progressCallBack) {
             // Checking if a manifest file has been set for this scene and if offline mode has been requested
             // Checking if a manifest file has been set for this scene and if offline mode has been requested
             var database = new BABYLON.Database(rootUrl + sceneFilename);
             var database = new BABYLON.Database(rootUrl + sceneFilename);
             scene.database = database;
             scene.database = database;
@@ -539,7 +542,10 @@ var BABYLON = BABYLON || {};
                 for (var index = 0; index < parsedData.meshes.length; index++) {
                 for (var index = 0; index < parsedData.meshes.length; index++) {
                     var parsedMesh = parsedData.meshes[index];
                     var parsedMesh = parsedData.meshes[index];
 
 
-                    if (!meshName || isDescendantOf(parsedMesh, meshName, hierarchyIds)) {
+                    if (!meshesNames || isDescendantOf(parsedMesh, meshesNames, hierarchyIds)) {
+						// Remove found mesh name from list.
+						delete meshesNames[meshesNames.indexOf(parsedMesh.name)];
+						
                         // Material ?
                         // Material ?
                         if (parsedMesh.materialId) {
                         if (parsedMesh.materialId) {
                             var materialFound = (loadedMaterialsIds.indexOf(parsedMesh.materialId) !== -1);
                             var materialFound = (loadedMaterialsIds.indexOf(parsedMesh.materialId) !== -1);
@@ -729,4 +735,4 @@ var BABYLON = BABYLON || {};
             }
             }
         }
         }
     };
     };
-})();
+})();