Explorar o código

Add dispose to TransformNode class

David Catuhe %!s(int64=7) %!d(string=hai) anos
pai
achega
4e1abfa99c

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 4839 - 4829
Playground/babylon.d.txt


A diferenza do arquivo foi suprimida porque é demasiado grande
+ 5029 - 5019
dist/preview release/babylon.d.ts


A diferenza do arquivo foi suprimida porque é demasiado grande
+ 10 - 10
dist/preview release/babylon.js


+ 42 - 19
dist/preview release/babylon.max.js

@@ -12565,14 +12565,24 @@ var BABYLON;
         /**
          * Get all child-meshes of this node.
          */
-        Node.prototype.getChildMeshes = function (directDecendantsOnly, predicate) {
+        Node.prototype.getChildMeshes = function (directDescendantsOnly, predicate) {
             var results = [];
-            this._getDescendants(results, directDecendantsOnly, function (node) {
+            this._getDescendants(results, directDescendantsOnly, function (node) {
                 return ((!predicate || predicate(node)) && (node instanceof BABYLON.AbstractMesh));
             });
             return results;
         };
         /**
+         * Get all child-transformNodes of this node.
+         */
+        Node.prototype.getChildTransformNodes = function (directDescendantsOnly, predicate) {
+            var results = [];
+            this._getDescendants(results, directDescendantsOnly, function (node) {
+                return ((!predicate || predicate(node)) && (node instanceof BABYLON.TransformNode));
+            });
+            return results;
+        };
+        /**
          * Get all direct children of this node.
         */
         Node.prototype.getChildren = function (predicate) {
@@ -13846,6 +13856,35 @@ var BABYLON;
             }
             return transformNode;
         };
+        /**
+             * Disposes the TransformNode.
+             * By default, all the children are also disposed unless the parameter `doNotRecurse` is set to `true`.
+             * Returns nothing.
+             */
+        TransformNode.prototype.dispose = function (doNotRecurse) {
+            // Animations
+            this.getScene().stopAnimation(this);
+            // Remove from scene
+            this.getScene().removeTransformNode(this);
+            this._cache = null;
+            if (!doNotRecurse) {
+                // Children
+                var objects = this.getDescendants(true);
+                for (var index = 0; index < objects.length; index++) {
+                    objects[index].dispose();
+                }
+            }
+            else {
+                var childMeshes = this.getChildMeshes(true);
+                for (index = 0; index < childMeshes.length; index++) {
+                    var child = childMeshes[index];
+                    child.parent = null;
+                    child.computeWorldMatrix(true);
+                }
+            }
+            this.onAfterWorldMatrixUpdateObservable.clear();
+            _super.prototype.dispose.call(this);
+        };
         // Statics
         TransformNode.BILLBOARDMODE_NONE = 0;
         TransformNode.BILLBOARDMODE_X = 1;
@@ -15086,8 +15125,6 @@ var BABYLON;
             }
             // Skeleton
             this.skeleton = null;
-            // Animations
-            this.getScene().stopAnimation(this);
             // Physics
             if (this.physicsImpostor) {
                 this.physicsImpostor.dispose();
@@ -15150,7 +15187,6 @@ var BABYLON;
             engine.wipeCaches();
             // Remove from scene
             this.getScene().removeMesh(this);
-            this._cache = null;
             if (disposeMaterialAndTextures) {
                 if (this.material) {
                     this.material.dispose(false, true);
@@ -15164,19 +15200,6 @@ var BABYLON;
                         index--;
                     }
                 }
-                // Children
-                var objects = this.getDescendants(true);
-                for (index = 0; index < objects.length; index++) {
-                    objects[index].dispose();
-                }
-            }
-            else {
-                var childMeshes = this.getChildMeshes(true);
-                for (index = 0; index < childMeshes.length; index++) {
-                    var child = childMeshes[index];
-                    child.parent = null;
-                    child.computeWorldMatrix(true);
-                }
             }
             // facet data
             if (this._facetDataEnabled) {
@@ -15186,7 +15209,7 @@ var BABYLON;
             this.onCollideObservable.clear();
             this.onCollisionPositionChangeObservable.clear();
             this._isDisposed = true;
-            _super.prototype.dispose.call(this);
+            _super.prototype.dispose.call(this, doNotRecurse);
         };
         /**
          * Adds the passed mesh as a child to the current mesh.

A diferenza do arquivo foi suprimida porque é demasiado grande
+ 10 - 10
dist/preview release/babylon.worker.js


A diferenza do arquivo foi suprimida porque é demasiado grande
+ 506 - 496
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.d.ts


A diferenza do arquivo foi suprimida porque é demasiado grande
+ 10 - 10
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.js


+ 42 - 19
dist/preview release/customConfigurations/minimalGLTFViewer/babylon.max.js

@@ -12565,14 +12565,24 @@ var BABYLON;
         /**
          * Get all child-meshes of this node.
          */
-        Node.prototype.getChildMeshes = function (directDecendantsOnly, predicate) {
+        Node.prototype.getChildMeshes = function (directDescendantsOnly, predicate) {
             var results = [];
-            this._getDescendants(results, directDecendantsOnly, function (node) {
+            this._getDescendants(results, directDescendantsOnly, function (node) {
                 return ((!predicate || predicate(node)) && (node instanceof BABYLON.AbstractMesh));
             });
             return results;
         };
         /**
+         * Get all child-transformNodes of this node.
+         */
+        Node.prototype.getChildTransformNodes = function (directDescendantsOnly, predicate) {
+            var results = [];
+            this._getDescendants(results, directDescendantsOnly, function (node) {
+                return ((!predicate || predicate(node)) && (node instanceof BABYLON.TransformNode));
+            });
+            return results;
+        };
+        /**
          * Get all direct children of this node.
         */
         Node.prototype.getChildren = function (predicate) {
@@ -13846,6 +13856,35 @@ var BABYLON;
             }
             return transformNode;
         };
+        /**
+             * Disposes the TransformNode.
+             * By default, all the children are also disposed unless the parameter `doNotRecurse` is set to `true`.
+             * Returns nothing.
+             */
+        TransformNode.prototype.dispose = function (doNotRecurse) {
+            // Animations
+            this.getScene().stopAnimation(this);
+            // Remove from scene
+            this.getScene().removeTransformNode(this);
+            this._cache = null;
+            if (!doNotRecurse) {
+                // Children
+                var objects = this.getDescendants(true);
+                for (var index = 0; index < objects.length; index++) {
+                    objects[index].dispose();
+                }
+            }
+            else {
+                var childMeshes = this.getChildMeshes(true);
+                for (index = 0; index < childMeshes.length; index++) {
+                    var child = childMeshes[index];
+                    child.parent = null;
+                    child.computeWorldMatrix(true);
+                }
+            }
+            this.onAfterWorldMatrixUpdateObservable.clear();
+            _super.prototype.dispose.call(this);
+        };
         // Statics
         TransformNode.BILLBOARDMODE_NONE = 0;
         TransformNode.BILLBOARDMODE_X = 1;
@@ -15086,8 +15125,6 @@ var BABYLON;
             }
             // Skeleton
             this.skeleton = null;
-            // Animations
-            this.getScene().stopAnimation(this);
             // Physics
             if (this.physicsImpostor) {
                 this.physicsImpostor.dispose();
@@ -15150,7 +15187,6 @@ var BABYLON;
             engine.wipeCaches();
             // Remove from scene
             this.getScene().removeMesh(this);
-            this._cache = null;
             if (disposeMaterialAndTextures) {
                 if (this.material) {
                     this.material.dispose(false, true);
@@ -15164,19 +15200,6 @@ var BABYLON;
                         index--;
                     }
                 }
-                // Children
-                var objects = this.getDescendants(true);
-                for (index = 0; index < objects.length; index++) {
-                    objects[index].dispose();
-                }
-            }
-            else {
-                var childMeshes = this.getChildMeshes(true);
-                for (index = 0; index < childMeshes.length; index++) {
-                    var child = childMeshes[index];
-                    child.parent = null;
-                    child.computeWorldMatrix(true);
-                }
             }
             // facet data
             if (this._facetDataEnabled) {
@@ -15186,7 +15209,7 @@ var BABYLON;
             this.onCollideObservable.clear();
             this.onCollisionPositionChangeObservable.clear();
             this._isDisposed = true;
-            _super.prototype.dispose.call(this);
+            _super.prototype.dispose.call(this, doNotRecurse);
         };
         /**
          * Adds the passed mesh as a child to the current mesh.

+ 1 - 18
src/Mesh/babylon.abstractMesh.ts

@@ -1311,9 +1311,6 @@
             // Skeleton
             this.skeleton = null;
 
-            // Animations
-            this.getScene().stopAnimation(this);
-
             // Physics
             if (this.physicsImpostor) {
                 this.physicsImpostor.dispose(/*!doNotRecurse*/);
@@ -1395,7 +1392,6 @@
             // Remove from scene
             this.getScene().removeMesh(this);
 
-            this._cache = null;
             if (disposeMaterialAndTextures) {
                 if (this.material) {
                     this.material.dispose(false, true);
@@ -1410,19 +1406,6 @@
                         index--;
                     }
                 }
-
-                // Children
-                var objects = this.getDescendants(true);
-                for (index = 0; index < objects.length; index++) {
-                    objects[index].dispose();
-                }
-            } else {
-                var childMeshes = this.getChildMeshes(true);
-                for (index = 0; index < childMeshes.length; index++) {
-                    var child = childMeshes[index];
-                    child.parent = null;
-                    child.computeWorldMatrix(true);
-                }
             }
 
             // facet data
@@ -1436,7 +1419,7 @@
 
             this._isDisposed = true;
 
-            super.dispose();
+            super.dispose(doNotRecurse);
         }
 
         /**

+ 35 - 0
src/Mesh/babylon.transformNode.ts

@@ -906,5 +906,40 @@ module BABYLON {
          
             return transformNode;
         }        
+
+    /**
+         * Disposes the TransformNode.  
+         * By default, all the children are also disposed unless the parameter `doNotRecurse` is set to `true`.  
+         * Returns nothing.  
+         */
+        public dispose(doNotRecurse?: boolean): void {
+            // Animations
+            this.getScene().stopAnimation(this);
+
+            // Remove from scene
+            this.getScene().removeTransformNode(this);
+
+            this._cache = null;
+
+            if (!doNotRecurse) {
+                // Children
+                var objects = this.getDescendants(true);
+                for (var index = 0; index < objects.length; index++) {
+                    objects[index].dispose();
+                }
+            } else {
+                var childMeshes = this.getChildMeshes(true);
+                for (index = 0; index < childMeshes.length; index++) {
+                    var child = childMeshes[index];
+                    child.parent = null;
+                    child.computeWorldMatrix(true);
+                }
+            }
+
+            this.onAfterWorldMatrixUpdateObservable.clear();
+
+            super.dispose();
+        }
+        
     }
 }

+ 13 - 2
src/babylon.node.ts

@@ -321,15 +321,26 @@
         /**
          * Get all child-meshes of this node.
          */
-        public getChildMeshes(directDecendantsOnly?: boolean, predicate?: (node: Node) => boolean): AbstractMesh[] {
+        public getChildMeshes(directDescendantsOnly?: boolean, predicate?: (node: Node) => boolean): AbstractMesh[] {
             var results: Array<AbstractMesh> = [];
-            this._getDescendants(results, directDecendantsOnly, (node: Node) => {
+            this._getDescendants(results, directDescendantsOnly, (node: Node) => {
                 return ((!predicate || predicate(node)) && (node instanceof AbstractMesh));
             });
             return results;
         }
 
         /**
+         * Get all child-transformNodes of this node.
+         */
+        public getChildTransformNodes(directDescendantsOnly?: boolean, predicate?: (node: Node) => boolean): TransformNode[] {
+            var results: Array<TransformNode> = [];
+            this._getDescendants(results, directDescendantsOnly, (node: Node) => {
+                return ((!predicate || predicate(node)) && (node instanceof TransformNode));
+            });
+            return results;
+        }
+
+        /**
          * Get all direct children of this node.
         */
         public getChildren(predicate?: (node: Node) => boolean): Node[] {