Browse Source

Merge pull request #4846 from TrevorDev/boundingBoxPerfAndDragSeperation

Bounding box perf and drag separation
David Catuhe 7 years ago
parent
commit
523451182c
2 changed files with 27 additions and 12 deletions
  1. 1 0
      dist/preview release/what's new.md
  2. 26 12
      src/Gizmos/babylon.boundingBoxGizmo.ts

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

@@ -90,6 +90,7 @@
 - Added Video Recorder [Issue 4708](https://github.com/BabylonJS/Babylon.js/issues/4708) ([sebavan](http://www.github.com/sebavan))
 - Added ACES ToneMapping to the image processing to help getting more parity with other engines ([sebavan](http://www.github.com/sebavan))
 - Added Image Processing to the particle system to allow consistency in one pass forward rendering scenes ([sebavan](http://www.github.com/sebavan))
+- Added ignoreChildren field to bounding box to save performance when using heavily nested meshes ([TrevorDev](https://github.com/TrevorDev))
 
 ### glTF Loader
 

+ 26 - 12
src/Gizmos/babylon.boundingBoxGizmo.ts

@@ -13,6 +13,10 @@ module BABYLON {
 
         private _tmpQuaternion = new Quaternion();
         private _tmpVector = new Vector3(0, 0, 0);
+        /**
+         * If child meshes should be ignored when calculating the boudning box. This should be set to true to avoid perf hits with heavily nested meshes (Default: false)
+         */
+        public ignoreChildren = false;
 
         /**
          * The size of the rotation spheres attached to the bounding box (Default: 0.1)
@@ -36,13 +40,21 @@ module BABYLON {
          */
         public onDragStartObservable = new Observable<{}>();
         /**
-         * Fired when a rotation sphere or scale box drag is started
+         * Fired when a scale box is dragged
          */
-        public onDragObservable = new Observable<{}>();
+        public onScaleBoxDragObservable = new Observable<{}>();
         /**
-         * Fired when a rotation sphere or scale box drag is needed
+          * Fired when a scale box drag is ended
          */
-        public onDragEndObservable = new Observable<{}>();
+        public onScaleBoxDragEndObservable = new Observable<{}>();
+        /**
+         * Fired when a rotation sphere is dragged
+         */
+        public onRotationSphereDragObservable = new Observable<{}>();
+        /**
+         * Fired when a rotation sphere drag is ended
+         */
+        public onRotationSphereDragEndObservable = new Observable<{}>();
         private _anchorMesh: AbstractMesh;
         private _existingMeshScale = new Vector3();
         /**
@@ -109,7 +121,7 @@ module BABYLON {
                     totalTurnAmountOfDrag = 0;
                 })
                 _dragBehavior.onDragObservable.add((event) => {
-                    this.onDragObservable.notifyObservers({});
+                    this.onRotationSphereDragObservable.notifyObservers({});
                     if (this.attachedMesh) {
                         var worldDragDirection = startingTurnDirection;
 
@@ -157,7 +169,7 @@ module BABYLON {
                     this._selectNode(sphere)
                 })
                 _dragBehavior.onDragEndObservable.add(() => {
-                    this.onDragEndObservable.notifyObservers({});
+                    this.onRotationSphereDragEndObservable.notifyObservers({});
                     this._selectNode(null)
                 })
 
@@ -180,7 +192,7 @@ module BABYLON {
                         _dragBehavior.moveAttached = false;
                         box.addBehavior(_dragBehavior);
                         _dragBehavior.onDragObservable.add((event) => {
-                            this.onDragObservable.notifyObservers({});
+                            this.onScaleBoxDragObservable.notifyObservers({});
                             if(this.attachedMesh){
                                 var relativeDragDistance = (event.dragDistance / this._boundingDimensions.length())*this._anchorMesh.scaling.length();
                                 var deltaScale = new Vector3(relativeDragDistance,relativeDragDistance,relativeDragDistance);
@@ -205,7 +217,7 @@ module BABYLON {
                             this._selectNode(box)
                         })
                         _dragBehavior.onDragEndObservable.add(() => {
-                            this.onDragEndObservable.notifyObservers({});
+                            this.onScaleBoxDragEndObservable.notifyObservers({});
                             this._selectNode(null)
                         })
 
@@ -262,9 +274,11 @@ module BABYLON {
 
         private _recurseComputeWorld(mesh: AbstractMesh) {
             mesh.computeWorldMatrix(true);
-            mesh.getChildMeshes().forEach((m) => {
-                this._recurseComputeWorld(m);
-            });
+            if(!this.ignoreChildren){
+                mesh.getChildMeshes().forEach((m) => {
+                    this._recurseComputeWorld(m);
+                });
+            }
         }
 
         /**
@@ -289,7 +303,7 @@ module BABYLON {
                 this.attachedMesh.position.set(0, 0, 0);
 
                 // Update bounding dimensions/positions   
-                var boundingMinMax = this.attachedMesh.getHierarchyBoundingVectors();
+                var boundingMinMax = this.attachedMesh.getHierarchyBoundingVectors(!this.ignoreChildren);
                 boundingMinMax.max.subtractToRef(boundingMinMax.min, this._boundingDimensions);
 
                 // Update gizmo to match bounding box scaling and rotation