瀏覽代碼

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 || {}; 
 
@@ -448,11 +448,14 @@ var BABYLON = BABYLON || {};
         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) {
             hierarchyIds.push(mesh.id);
@@ -521,7 +524,7 @@ var BABYLON = BABYLON || {};
                 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
             var database = new BABYLON.Database(rootUrl + sceneFilename);
             scene.database = database;
@@ -539,7 +542,10 @@ var BABYLON = BABYLON || {};
                 for (var index = 0; index < parsedData.meshes.length; 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 ?
                         if (parsedMesh.materialId) {
                             var materialFound = (loadedMaterialsIds.indexOf(parsedMesh.materialId) !== -1);
@@ -729,4 +735,4 @@ var BABYLON = BABYLON || {};
             }
         }
     };
-})();
+})();