Browse Source

Inspector - Mesh are not sorted by hierarchy !

Temechon 8 years ago
parent
commit
7752e00e15
2 changed files with 30 additions and 8 deletions
  1. 29 3
      inspector/src/tabs/MeshTab.ts
  2. 1 5
      inspector/test/index.js

+ 29 - 3
inspector/src/tabs/MeshTab.ts

@@ -9,17 +9,43 @@ module INSPECTOR{
         /* Overrides super */
         protected _getTree() : Array<TreeItem> {
             let arr = [];
+            // Tab containign mesh already in results
+            let alreadyIn = [];
             
             // Returns true if the id of the given object starts and ends with '###'
-            let shouldExcludeThisMesh = (obj:BABYLON.AbstractMesh) : boolean => {
+            let shouldExcludeThisMesh = (obj:BABYLON.Node) : boolean => {
                 return (obj.name && obj.name.indexOf('###') == 0 && obj.name.lastIndexOf('###', 0) === 0);
             };
+
+            // Recursive method building the tree panel
+            let createNode = (obj : BABYLON.AbstractMesh) => {
+                let descendants = obj.getDescendants(true);
+
+                if (descendants.length > 0) {
+                    let node = new TreeItem(this, new MeshAdapter(obj));
+                    alreadyIn.push(node);
+                    for (let child of descendants) {     
+                        if (child instanceof BABYLON.AbstractMesh) {
+                            if (!shouldExcludeThisMesh(child)) {  
+                                let n = createNode(child);
+                                node.add(n); 
+                            }
+                        }
+                    }
+                    node.update();
+                    return node;
+                } else {
+                    alreadyIn.push(obj);
+                    return new TreeItem(this, new MeshAdapter(obj));
+                }
+            };
             
             // get all meshes from the first scene
             let instances = this._inspector.scene;
             for (let mesh of instances.meshes) {
-                if (!shouldExcludeThisMesh(mesh)){
-                    arr.push(new TreeItem(this, new MeshAdapter(mesh)));
+                if (alreadyIn.indexOf(mesh) == -1) {
+                    let node = createNode(mesh);
+                    arr.push(node);
                 }
             }
             return arr;

+ 1 - 5
inspector/test/index.js

@@ -89,11 +89,7 @@ var Test = (function () {
     };
     Test.prototype._initGame = function () {
         this._createCanvas();
-        BABYLON.SceneLoader.ImportMesh('', 'test/', 'Rabbit.babylon', this.scene, (meshes) => {
-            meshes.forEach((mesh) => {
-                console.log(mesh.name);
-            })
-        });
+        BABYLON.SceneLoader.ImportMesh('', 'test/', 'Rabbit.babylon', this.scene);
     };
     /**
      * Create the canvas2D