瀏覽代碼

add rootNodes array to scene (associated with #5050)

David Catuhe 7 年之前
父節點
當前提交
9094b709a5

文件差異過大導致無法顯示
+ 1746 - 1742
Playground/babylon.d.txt


文件差異過大導致無法顯示
+ 1033 - 1025
dist/preview release/babylon.d.ts


文件差異過大導致無法顯示
+ 1 - 1
dist/preview release/babylon.js


+ 36 - 4
dist/preview release/babylon.max.js

@@ -17598,6 +17598,7 @@ var BABYLON;
             this._scene = (scene || BABYLON.Engine.LastCreatedScene);
             this.uniqueId = this._scene.getUniqueId();
             this._initCache();
+            this._scene.rootNodes.push(this);
         }
         /**
          * Add a new node constructor
@@ -17640,12 +17641,17 @@ var BABYLON;
                 if (this._parentNode === parent) {
                     return;
                 }
+                var previousParentNode = this._parentNode;
                 // Remove self from list of children of parent
                 if (this._parentNode && this._parentNode._children !== undefined && this._parentNode._children !== null) {
                     var index = this._parentNode._children.indexOf(this);
                     if (index !== -1) {
                         this._parentNode._children.splice(index, 1);
                     }
+                    if (!parent) {
+                        // Need to add this node to the rootNodes
+                        this._scene.rootNodes.push(this);
+                    }
                 }
                 // Store new parent
                 this._parentNode = parent;
@@ -17655,6 +17661,13 @@ var BABYLON;
                         this._parentNode._children = new Array();
                     }
                     this._parentNode._children.push(this);
+                    if (!previousParentNode) {
+                        // Need to remove from rootNodes
+                        var rootNodeIndex = this._scene.rootNodes.indexOf(this);
+                        if (rootNodeIndex > -1) {
+                            this._scene.rootNodes.splice(rootNodeIndex, 1);
+                        }
+                    }
                 }
             },
             enumerable: true,
@@ -17952,6 +17965,9 @@ var BABYLON;
          * @returns an array of {BABYLON.Node}
          */
         Node.prototype.getChildren = function (predicate) {
+            if (!predicate) {
+                return this._children;
+            }
             return this.getDescendants(true, predicate);
         };
         /** @hidden */
@@ -18085,7 +18101,15 @@ var BABYLON;
                     transformNode.computeWorldMatrix(true);
                 }
             }
-            this.parent = null;
+            if (!this.parent) {
+                var rootNodeIndex = this._scene.rootNodes.indexOf(this);
+                if (rootNodeIndex > -1) {
+                    this._scene.rootNodes.splice(rootNodeIndex, 1);
+                }
+            }
+            else {
+                this.parent = null;
+            }
             // Callback
             this.onDisposeObservable.notifyObservers(this);
             this.onDisposeObservable.clear();
@@ -23784,6 +23808,10 @@ var BABYLON;
      */
     var AbstractScene = /** @class */ (function () {
         function AbstractScene() {
+            /**
+             * Gets the list of root nodes (ie. nodes with no parent)
+             */
+            this.rootNodes = new Array();
             /** All of the cameras added to this scene
              * @see http://doc.babylonjs.com/babylon101/cameras
              */
@@ -98367,7 +98395,7 @@ var BABYLON;
                 // Listening to the proper controller values changes to confirm teleportation
                 if (Math.sqrt(stateObject.y * stateObject.y + stateObject.x * stateObject.x) < this._padSensibilityDown) {
                     if (this._teleportActive) {
-                        this._teleportCamera(this._haloCenter);
+                        this.teleportCamera(this._haloCenter);
                     }
                     gazer._teleportationRequestInitiated = false;
                 }
@@ -98436,7 +98464,7 @@ var BABYLON;
                     var ray = new BABYLON.Ray(position, this._workingVector);
                     var hit = this._scene.pickWithRay(ray, this._raySelectionPredicate);
                     if (hit && hit.pickedPoint && hit.pickedMesh && this._isTeleportationFloor(hit.pickedMesh) && hit.distance < 5) {
-                        this._teleportCamera(hit.pickedPoint);
+                        this.teleportCamera(hit.pickedPoint);
                     }
                     gazer._teleportationBackRequestInitiated = true;
                 }
@@ -98626,7 +98654,11 @@ var BABYLON;
                 this._teleportationTarget.position.y += 0.1;
             }
         };
-        VRExperienceHelper.prototype._teleportCamera = function (location) {
+        /**
+         * Teleports the users feet to the desired location
+         * @param location The location where the user's feet should be placed
+         */
+        VRExperienceHelper.prototype.teleportCamera = function (location) {
             var _this = this;
             if (!(this.currentVRCamera instanceof BABYLON.FreeCamera)) {
                 return;

+ 36 - 4
dist/preview release/babylon.no-module.max.js

@@ -17565,6 +17565,7 @@ var BABYLON;
             this._scene = (scene || BABYLON.Engine.LastCreatedScene);
             this.uniqueId = this._scene.getUniqueId();
             this._initCache();
+            this._scene.rootNodes.push(this);
         }
         /**
          * Add a new node constructor
@@ -17607,12 +17608,17 @@ var BABYLON;
                 if (this._parentNode === parent) {
                     return;
                 }
+                var previousParentNode = this._parentNode;
                 // Remove self from list of children of parent
                 if (this._parentNode && this._parentNode._children !== undefined && this._parentNode._children !== null) {
                     var index = this._parentNode._children.indexOf(this);
                     if (index !== -1) {
                         this._parentNode._children.splice(index, 1);
                     }
+                    if (!parent) {
+                        // Need to add this node to the rootNodes
+                        this._scene.rootNodes.push(this);
+                    }
                 }
                 // Store new parent
                 this._parentNode = parent;
@@ -17622,6 +17628,13 @@ var BABYLON;
                         this._parentNode._children = new Array();
                     }
                     this._parentNode._children.push(this);
+                    if (!previousParentNode) {
+                        // Need to remove from rootNodes
+                        var rootNodeIndex = this._scene.rootNodes.indexOf(this);
+                        if (rootNodeIndex > -1) {
+                            this._scene.rootNodes.splice(rootNodeIndex, 1);
+                        }
+                    }
                 }
             },
             enumerable: true,
@@ -17919,6 +17932,9 @@ var BABYLON;
          * @returns an array of {BABYLON.Node}
          */
         Node.prototype.getChildren = function (predicate) {
+            if (!predicate) {
+                return this._children;
+            }
             return this.getDescendants(true, predicate);
         };
         /** @hidden */
@@ -18052,7 +18068,15 @@ var BABYLON;
                     transformNode.computeWorldMatrix(true);
                 }
             }
-            this.parent = null;
+            if (!this.parent) {
+                var rootNodeIndex = this._scene.rootNodes.indexOf(this);
+                if (rootNodeIndex > -1) {
+                    this._scene.rootNodes.splice(rootNodeIndex, 1);
+                }
+            }
+            else {
+                this.parent = null;
+            }
             // Callback
             this.onDisposeObservable.notifyObservers(this);
             this.onDisposeObservable.clear();
@@ -23751,6 +23775,10 @@ var BABYLON;
      */
     var AbstractScene = /** @class */ (function () {
         function AbstractScene() {
+            /**
+             * Gets the list of root nodes (ie. nodes with no parent)
+             */
+            this.rootNodes = new Array();
             /** All of the cameras added to this scene
              * @see http://doc.babylonjs.com/babylon101/cameras
              */
@@ -98334,7 +98362,7 @@ var BABYLON;
                 // Listening to the proper controller values changes to confirm teleportation
                 if (Math.sqrt(stateObject.y * stateObject.y + stateObject.x * stateObject.x) < this._padSensibilityDown) {
                     if (this._teleportActive) {
-                        this._teleportCamera(this._haloCenter);
+                        this.teleportCamera(this._haloCenter);
                     }
                     gazer._teleportationRequestInitiated = false;
                 }
@@ -98403,7 +98431,7 @@ var BABYLON;
                     var ray = new BABYLON.Ray(position, this._workingVector);
                     var hit = this._scene.pickWithRay(ray, this._raySelectionPredicate);
                     if (hit && hit.pickedPoint && hit.pickedMesh && this._isTeleportationFloor(hit.pickedMesh) && hit.distance < 5) {
-                        this._teleportCamera(hit.pickedPoint);
+                        this.teleportCamera(hit.pickedPoint);
                     }
                     gazer._teleportationBackRequestInitiated = true;
                 }
@@ -98593,7 +98621,11 @@ var BABYLON;
                 this._teleportationTarget.position.y += 0.1;
             }
         };
-        VRExperienceHelper.prototype._teleportCamera = function (location) {
+        /**
+         * Teleports the users feet to the desired location
+         * @param location The location where the user's feet should be placed
+         */
+        VRExperienceHelper.prototype.teleportCamera = function (location) {
             var _this = this;
             if (!(this.currentVRCamera instanceof BABYLON.FreeCamera)) {
                 return;

文件差異過大導致無法顯示
+ 1 - 1
dist/preview release/babylon.worker.js


+ 36 - 4
dist/preview release/es6.js

@@ -17565,6 +17565,7 @@ var BABYLON;
             this._scene = (scene || BABYLON.Engine.LastCreatedScene);
             this.uniqueId = this._scene.getUniqueId();
             this._initCache();
+            this._scene.rootNodes.push(this);
         }
         /**
          * Add a new node constructor
@@ -17607,12 +17608,17 @@ var BABYLON;
                 if (this._parentNode === parent) {
                     return;
                 }
+                var previousParentNode = this._parentNode;
                 // Remove self from list of children of parent
                 if (this._parentNode && this._parentNode._children !== undefined && this._parentNode._children !== null) {
                     var index = this._parentNode._children.indexOf(this);
                     if (index !== -1) {
                         this._parentNode._children.splice(index, 1);
                     }
+                    if (!parent) {
+                        // Need to add this node to the rootNodes
+                        this._scene.rootNodes.push(this);
+                    }
                 }
                 // Store new parent
                 this._parentNode = parent;
@@ -17622,6 +17628,13 @@ var BABYLON;
                         this._parentNode._children = new Array();
                     }
                     this._parentNode._children.push(this);
+                    if (!previousParentNode) {
+                        // Need to remove from rootNodes
+                        var rootNodeIndex = this._scene.rootNodes.indexOf(this);
+                        if (rootNodeIndex > -1) {
+                            this._scene.rootNodes.splice(rootNodeIndex, 1);
+                        }
+                    }
                 }
             },
             enumerable: true,
@@ -17919,6 +17932,9 @@ var BABYLON;
          * @returns an array of {BABYLON.Node}
          */
         Node.prototype.getChildren = function (predicate) {
+            if (!predicate) {
+                return this._children;
+            }
             return this.getDescendants(true, predicate);
         };
         /** @hidden */
@@ -18052,7 +18068,15 @@ var BABYLON;
                     transformNode.computeWorldMatrix(true);
                 }
             }
-            this.parent = null;
+            if (!this.parent) {
+                var rootNodeIndex = this._scene.rootNodes.indexOf(this);
+                if (rootNodeIndex > -1) {
+                    this._scene.rootNodes.splice(rootNodeIndex, 1);
+                }
+            }
+            else {
+                this.parent = null;
+            }
             // Callback
             this.onDisposeObservable.notifyObservers(this);
             this.onDisposeObservable.clear();
@@ -23751,6 +23775,10 @@ var BABYLON;
      */
     var AbstractScene = /** @class */ (function () {
         function AbstractScene() {
+            /**
+             * Gets the list of root nodes (ie. nodes with no parent)
+             */
+            this.rootNodes = new Array();
             /** All of the cameras added to this scene
              * @see http://doc.babylonjs.com/babylon101/cameras
              */
@@ -98334,7 +98362,7 @@ var BABYLON;
                 // Listening to the proper controller values changes to confirm teleportation
                 if (Math.sqrt(stateObject.y * stateObject.y + stateObject.x * stateObject.x) < this._padSensibilityDown) {
                     if (this._teleportActive) {
-                        this._teleportCamera(this._haloCenter);
+                        this.teleportCamera(this._haloCenter);
                     }
                     gazer._teleportationRequestInitiated = false;
                 }
@@ -98403,7 +98431,7 @@ var BABYLON;
                     var ray = new BABYLON.Ray(position, this._workingVector);
                     var hit = this._scene.pickWithRay(ray, this._raySelectionPredicate);
                     if (hit && hit.pickedPoint && hit.pickedMesh && this._isTeleportationFloor(hit.pickedMesh) && hit.distance < 5) {
-                        this._teleportCamera(hit.pickedPoint);
+                        this.teleportCamera(hit.pickedPoint);
                     }
                     gazer._teleportationBackRequestInitiated = true;
                 }
@@ -98593,7 +98621,11 @@ var BABYLON;
                 this._teleportationTarget.position.y += 0.1;
             }
         };
-        VRExperienceHelper.prototype._teleportCamera = function (location) {
+        /**
+         * Teleports the users feet to the desired location
+         * @param location The location where the user's feet should be placed
+         */
+        VRExperienceHelper.prototype.teleportCamera = function (location) {
             var _this = this;
             if (!(this.currentVRCamera instanceof BABYLON.FreeCamera)) {
                 return;

文件差異過大導致無法顯示
+ 1 - 1
dist/preview release/viewer/babylon.viewer.js


文件差異過大導致無法顯示
+ 1 - 1
dist/preview release/viewer/babylon.viewer.max.js


+ 1 - 0
dist/preview release/what's new.md

@@ -65,6 +65,7 @@
 
 ### Core Engine
 
+- Added `scene.rootNodes` to track root nodes (ie. nodes with no parent) ([Deltakosh](https://github.com/deltakosh))
 - Added `scene.pickSpriteWithRay` function ([Deltakosh](https://github.com/deltakosh))
 - Added support for multiple clip planes. [Demo](https://www.babylonjs-playground.com/#Y6W087) ([Deltakosh](https://github.com/deltakosh))
 - Added new `MixMaterial` to the Materials Library allowing to mix up to 8 textures ([julien-moreau](https://github.com/julien-moreau))

+ 5 - 0
src/babylon.abstractScene.ts

@@ -86,6 +86,11 @@
             }
         }
 
+       /**
+        * Gets the list of root nodes (ie. nodes with no parent)
+        */
+       public rootNodes = new Array<Node>();
+
         /** All of the cameras added to this scene
          * @see http://doc.babylonjs.com/babylon101/cameras
          */

+ 31 - 1
src/babylon.node.ts

@@ -120,12 +120,19 @@
                 return;
             }
 
+            const previousParentNode = this._parentNode;
+
             // Remove self from list of children of parent
             if (this._parentNode && this._parentNode._children !== undefined && this._parentNode._children !== null) {
                 var index = this._parentNode._children.indexOf(this);
                 if (index !== -1) {
                     this._parentNode._children.splice(index, 1);
                 }
+
+                if (!parent) {
+                    // Need to add this node to the rootNodes
+                    this._scene.rootNodes.push(this);
+                }
             }
 
             // Store new parent
@@ -137,6 +144,15 @@
                     this._parentNode._children = new Array<Node>();
                 }
                 this._parentNode._children.push(this);
+
+                if (!previousParentNode) {
+                    // Need to remove from rootNodes
+                    const rootNodeIndex = this._scene.rootNodes.indexOf(this);
+
+                    if (rootNodeIndex > -1) {
+                        this._scene.rootNodes.splice(rootNodeIndex, 1);
+                    }
+                }
             }
         }
 
@@ -195,6 +211,8 @@
             this._scene = <Scene>(scene || Engine.LastCreatedScene);
             this.uniqueId = this._scene.getUniqueId();
             this._initCache();
+
+            this._scene.rootNodes.push(this);
         }
 
         /**
@@ -496,6 +514,10 @@
          * @returns an array of {BABYLON.Node}
          */
         public getChildren(predicate?: (node: Node) => boolean): Node[] {
+            if (!predicate) {
+                return this._children;
+            }
+
             return this.getDescendants(true, predicate);
         }
 
@@ -640,7 +662,15 @@
                 }
             }
 
-            this.parent = null;
+            if (!this.parent) {
+                const rootNodeIndex = this._scene.rootNodes.indexOf(this);
+
+                if (rootNodeIndex > -1) {
+                    this._scene.rootNodes.splice(rootNodeIndex, 1);
+                }
+            } else {
+                this.parent = null;
+            }
 
             // Callback
             this.onDisposeObservable.notifyObservers(this);