浏览代码

Support for transform nodes

Julian 7 年之前
父节点
当前提交
a706b17f6a

+ 4 - 0
dist/preview release/inspector/babylon.inspector.css

@@ -273,6 +273,10 @@
         display: inline-block;
         display: inline-block;
         font-family: 'FontAwesome', sans-serif;
         font-family: 'FontAwesome', sans-serif;
         content: "\f054"; }
         content: "\f054"; }
+      .insp-wrapper .insp-tree .line.unfolded.transformNode > span:first-of-type {
+        color: #f29766; }
+      .insp-wrapper .insp-tree .line.folded.transformNode > span:first-of-type {
+        color: #f29766; }
       .insp-wrapper .insp-tree .line .line-content {
       .insp-wrapper .insp-tree .line .line-content {
         padding-left: 15px; }
         padding-left: 15px; }
         .insp-wrapper .insp-tree .line .line-content:hover {
         .insp-wrapper .insp-tree .line .line-content:hover {

+ 8 - 1
inspector/sass/_tree.scss

@@ -35,7 +35,7 @@
             line-height: 1em;
             line-height: 1em;
             display    : inline-block;
             display    : inline-block;
             font-family: 'FontAwesome', sans-serif;
             font-family: 'FontAwesome', sans-serif;
-            content    : "\f078";
+            content    : "\f078";            
         }
         }
         &.folded:before{            
         &.folded:before{            
             width      : 1em;
             width      : 1em;
@@ -45,6 +45,13 @@
             font-family: 'FontAwesome', sans-serif;
             font-family: 'FontAwesome', sans-serif;
             content    : "\f054";
             content    : "\f054";
         }
         }
+        
+        &.unfolded.transformNode > span:first-of-type{
+            color:$color-top;
+        }
+        &.folded.transformNode > span:first-of-type{ 
+            color:$color-top;
+        }
 
 
         // Sub lines
         // Sub lines
         .line-content {
         .line-content {

+ 0 - 5
inspector/src/adapters/Adapter.ts

@@ -20,11 +20,6 @@ module INSPECTOR {
         /** Returns the list of properties to be displayed for this adapter */
         /** Returns the list of properties to be displayed for this adapter */
         public abstract getProperties(): Array<PropertyLine>;
         public abstract getProperties(): Array<PropertyLine>;
 
 
-        /** Returns the actual object behind this adapter */
-        public get actualObject(): any {
-            return this._obj;
-        }
-
         /** Returns true if the given object correspond to this  */
         /** Returns true if the given object correspond to this  */
         public correspondsTo(obj: any) {
         public correspondsTo(obj: any) {
             return obj === this._obj;
             return obj === this._obj;

+ 21 - 16
inspector/src/adapters/MeshAdapter.ts

@@ -6,9 +6,9 @@ module INSPECTOR {
 
 
         /** Keep track of the axis of the actual object */
         /** Keep track of the axis of the actual object */
         private _axesViewer: BABYLON.Nullable<BABYLON.Debug.AxesViewer>;
         private _axesViewer: BABYLON.Nullable<BABYLON.Debug.AxesViewer>;
-        private onBeforeRenderObserver: BABYLON.Nullable<BABYLON.Observer<BABYLON.Scene>>;
+        private _onBeforeRender: () => void;
 
 
-        constructor(mesh: BABYLON.AbstractMesh) {
+        constructor(mesh: BABYLON.Node) {
             super(mesh);
             super(mesh);
         }
         }
 
 
@@ -35,10 +35,13 @@ module INSPECTOR {
             let tools = [];
             let tools = [];
             tools.push(new Checkbox(this));
             tools.push(new Checkbox(this));
             tools.push(new DebugArea(this));
             tools.push(new DebugArea(this));
-            if ((this._obj as BABYLON.AbstractMesh).getTotalVertices() > 0) {
-                tools.push(new BoundingBox(this));
+            if (this._obj instanceof BABYLON.AbstractMesh) {
+                if ((this._obj as BABYLON.AbstractMesh).getTotalVertices() > 0) {
+                    tools.push(new BoundingBox(this));
+                }
             }
             }
 
 
+
             tools.push(new Info(this));
             tools.push(new Info(this));
             return tools;
             return tools;
         }
         }
@@ -60,12 +63,12 @@ module INSPECTOR {
         public debug(enable: boolean) {
         public debug(enable: boolean) {
             // Draw axis the first time
             // Draw axis the first time
             if (!this._axesViewer) {
             if (!this._axesViewer) {
-                 this._drawAxis();
+                this._drawAxis();
             }
             }
             // Display or hide axis
             // Display or hide axis
             if (!enable && this._axesViewer) {
             if (!enable && this._axesViewer) {
-                let mesh = this._obj as BABYLON.AbstractMesh;
-                mesh.getScene().onBeforeRenderObservable.remove(this.onBeforeRenderObserver);
+                let mesh = this._obj as BABYLON.TransformNode;
+                mesh.getScene().unregisterBeforeRender(this._onBeforeRender);
                 this._axesViewer.dispose();
                 this._axesViewer.dispose();
                 this._axesViewer = null;
                 this._axesViewer = null;
             }
             }
@@ -73,7 +76,10 @@ module INSPECTOR {
 
 
         /** Returns some information about this mesh */
         /** Returns some information about this mesh */
         public getInfo(): string {
         public getInfo(): string {
-            return `${(this._obj as BABYLON.AbstractMesh).getTotalVertices()} vertices`;
+            if (this._obj instanceof BABYLON.AbstractMesh) {
+                return `${(this._obj as BABYLON.AbstractMesh).getTotalVertices()} vertices`;
+            }
+            return '0 vertices';
         }
         }
 
 
         /** Draw X, Y and Z axis for the actual object if this adapter.
         /** Draw X, Y and Z axis for the actual object if this adapter.
@@ -82,8 +88,6 @@ module INSPECTOR {
         private _drawAxis() {
         private _drawAxis() {
             this._obj.computeWorldMatrix();
             this._obj.computeWorldMatrix();
 
 
-            let mesh = this._obj as BABYLON.Mesh;
-
             // Axis
             // Axis
             var x = new BABYLON.Vector3(1, 0, 0);
             var x = new BABYLON.Vector3(1, 0, 0);
             var y = new BABYLON.Vector3(0, 1, 0);
             var y = new BABYLON.Vector3(0, 1, 0);
@@ -91,12 +95,13 @@ module INSPECTOR {
 
 
             this._axesViewer = new BABYLON.Debug.AxesViewer(this._obj.getScene());
             this._axesViewer = new BABYLON.Debug.AxesViewer(this._obj.getScene());
 
 
-            this.onBeforeRenderObserver = mesh.getScene().onBeforeRenderObservable.add(() => {
-                let matrix = mesh.getWorldMatrix();
-                let extend = mesh.getBoundingInfo()!.boundingBox.extendSizeWorld;
-                this._axesViewer!.scaleLines = Math.max(extend.x, extend.y, extend.z) * 2;
-                this._axesViewer!.update(this._obj.position, BABYLON.Vector3.TransformNormal(x, matrix), BABYLON.Vector3.TransformNormal(y, matrix), BABYLON.Vector3.TransformNormal(z, matrix));
-            });
+            this._onBeforeRender = () => {
+                if (this._axesViewer) {
+                    this._axesViewer.update(this._obj.position, x, y, z);
+                }
+            }
+
+            this._obj.getScene().registerBeforeRender(this._onBeforeRender);
         }
         }
     }
     }
 }
 }

+ 39 - 22
inspector/src/tabs/MeshTab.ts

@@ -1,66 +1,83 @@
 /// <reference path="../../../dist/preview release/babylon.d.ts"/>
 /// <reference path="../../../dist/preview release/babylon.d.ts"/>
 
 
-module INSPECTOR{
-    
+module INSPECTOR {
+
     export class MeshTab extends PropertyTab {
     export class MeshTab extends PropertyTab {
-                
-        constructor(tabbar:TabBar, inspector:Inspector) {
-            super(tabbar, 'Mesh', inspector); 
+
+        constructor(tabbar: TabBar, inspector: Inspector) {
+            super(tabbar, 'Mesh', inspector);
         }
         }
 
 
         /* Overrides super */
         /* Overrides super */
-        protected _getTree() : Array<TreeItem> {
+        protected _getTree(): Array<TreeItem> {
             let arr = new Array<TreeItem>();
             let arr = new Array<TreeItem>();
             // Tab containing mesh already in results
             // Tab containing mesh already in results
-            let alreadyIn = new Array<BABYLON.AbstractMesh>();
+            let alreadyIn = new Array<BABYLON.Node>();
 
 
             // Recursive method building the tree panel
             // Recursive method building the tree panel
-            let createNode = (obj : BABYLON.AbstractMesh) => {
+            let createNode = (obj: BABYLON.Node) => {
                 let descendants = obj.getDescendants(true);
                 let descendants = obj.getDescendants(true);
 
 
                 let node = new TreeItem(this, new MeshAdapter(obj));
                 let node = new TreeItem(this, new MeshAdapter(obj));
 
 
                 if (descendants.length > 0) {
                 if (descendants.length > 0) {
-                    for (let child of descendants) {     
-                        if (child instanceof BABYLON.AbstractMesh) {
-                            if (!Helpers.IsSystemName(child.name)) {  
+                    for (let child of descendants) {
+                        if (child instanceof BABYLON.TransformNode) {
+                            if (!Helpers.IsSystemName(child.name)) {
                                 let n = createNode(child);
                                 let n = createNode(child);
-                                node.add(n); 
+                                node.add(n);
                             }
                             }
                         }
                         }
                     }
                     }
                     node.update();
                     node.update();
-                } 
+                }
 
 
                 // Retrieve the root node if the mesh is actually child of another mesh
                 // Retrieve the root node if the mesh is actually child of another mesh
                 // This can hapen if the child mesh has been created before the parent mesh
                 // This can hapen if the child mesh has been created before the parent mesh
-                if(obj.parent != null && alreadyIn.indexOf(obj) != -1){
+                if (obj.parent != null && alreadyIn.indexOf(obj) != -1) {
                     let i: number = 0;
                     let i: number = 0;
                     let notFound: boolean = true;
                     let notFound: boolean = true;
                     // Find and delete the root node standing for this mesh
                     // Find and delete the root node standing for this mesh
-                    while(i < arr.length && notFound){
-                        if(obj.name === arr[i].id){
-                             arr.splice(i, 1);
-                             notFound = false;
+                    while (i < arr.length && notFound) {
+                        if (obj.name === arr[i].id) {
+                            arr.splice(i, 1);
+                            notFound = false;
                         }
                         }
                         i++;
                         i++;
                     }
                     }
                 }
                 }
 
 
-                alreadyIn.push(obj);                
+                alreadyIn.push(obj);
                 return node;
                 return node;
             };
             };
-            
+
             // get all meshes from the first scene
             // get all meshes from the first scene
             let instances = this._inspector.scene;
             let instances = this._inspector.scene;
+
+            // Find top of hierarchy for meshes...
+            let meshWithoutAnyParent: Array<BABYLON.Node> = [];
             for (let mesh of instances.meshes) {
             for (let mesh of instances.meshes) {
+                // Not already in the array, not system name and no parent
+                if (meshWithoutAnyParent.indexOf(mesh) == -1 && !Helpers.IsSystemName(mesh.name) && !mesh.parent) {
+                    meshWithoutAnyParent.push(mesh);
+                }
+            }
+            // ... and for transforms
+            for (let tn of instances.transformNodes) {
+                // Not already in the array, not system name and no parent
+                if (meshWithoutAnyParent.indexOf(tn) == -1 && !Helpers.IsSystemName(tn.name) && !tn.parent) {
+                    meshWithoutAnyParent.push(tn);
+                }
+            }
+
+            for (let mesh of meshWithoutAnyParent) {
                 if (alreadyIn.indexOf(mesh) == -1 && !Helpers.IsSystemName(mesh.name)) {
                 if (alreadyIn.indexOf(mesh) == -1 && !Helpers.IsSystemName(mesh.name)) {
                     let node = createNode(mesh);
                     let node = createNode(mesh);
                     arr.push(node);
                     arr.push(node);
                 }
                 }
             }
             }
             return arr;
             return arr;
-        }  
+        }
     }
     }
-    
+
 }
 }

+ 8 - 0
inspector/src/tree/TreeItem.ts

@@ -82,6 +82,14 @@ module INSPECTOR {
         protected _build() {
         protected _build() {
             this._div.className = 'line';
             this._div.className = 'line';
 
 
+            // special class for transform node ONLY
+            if (this.adapter instanceof MeshAdapter) {
+                let obj = this.adapter.object;
+                if (obj instanceof BABYLON.TransformNode && !(obj instanceof BABYLON.AbstractMesh)) {
+                    this._div.className += ' transformNode';
+                }
+            }
+
 
 
             for (let tool of this._tools) {
             for (let tool of this._tools) {
                 this._div.appendChild(tool.toHtml());
                 this._div.appendChild(tool.toHtml());

+ 12 - 3
inspector/test/index.js

@@ -37,15 +37,18 @@ var Test = (function () {
         var canvas = scene.getEngine().getRenderingCanvas();
         var canvas = scene.getEngine().getRenderingCanvas();
 
 
 
 
-        var sceneRoot = new BABYLON.AbstractMesh("SceneRoot");
+        var sceneRoot = new BABYLON.TransformNode("abstractmesh");
+
+        var tn = new BABYLON.TransformNode("transform node");
+
         // Our built-in 'ground' shape. Params: name, width, depth, subdivs, scene
         // Our built-in 'ground' shape. Params: name, width, depth, subdivs, scene
         var ground = BABYLON.Mesh.CreateGround("node_damagedHelmet_-6514", 6, 6, 2, scene);
         var ground = BABYLON.Mesh.CreateGround("node_damagedHelmet_-6514", 6, 6, 2, scene);
-        ground.parent = sceneRoot;
+        ground.parent = tn;
 
 
         let num = 5;
         let num = 5;
         let angStep = 6.283185307 / num;
         let angStep = 6.283185307 / num;
         let rad = 2;
         let rad = 2;
-        let p = ground;
+        let p = sceneRoot;
         for (let i = 0; i < num; i++) {
         for (let i = 0; i < num; i++) {
             // Our built-in 'sphere' shape. Params: name, subdivs, size, scene
             // Our built-in 'sphere' shape. Params: name, subdivs, size, scene
             let sphere = BABYLON.Mesh.CreateSphere(`sphere${i}`, 16, 2, scene);
             let sphere = BABYLON.Mesh.CreateSphere(`sphere${i}`, 16, 2, scene);
@@ -58,6 +61,12 @@ var Test = (function () {
             p = sphere;
             p = sphere;
         }
         }
 
 
+        let t = 0;
+        scene.registerBeforeRender(() => {
+            ground.rotation.y += 0.01;
+            ground.position.y = Math.cos(t += 0.01);
+        });
+
         scene.createDefaultCameraOrLight(true);
         scene.createDefaultCameraOrLight(true);
         scene.activeCamera.attachControl(canvas);
         scene.activeCamera.attachControl(canvas);