浏览代码

Merge pull request #4743 from TrevorDev/boundingBoxAvoidEveryFrameUpdate

Bounding box avoid every frame update
David Catuhe 7 年之前
父节点
当前提交
57121a4e27
共有 2 个文件被更改,包括 14 次插入6 次删除
  1. 1 1
      dist/preview release/what's new.md
  2. 13 5
      src/Gizmos/babylon.boundingBoxGizmo.ts

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

@@ -7,7 +7,7 @@
 - New GUI 3D controls toolset. [Complete doc + demos](http://doc.babylonjs.com/how_to/gui3d) ([Deltakosh](https://github.com/deltakosh))
 - Added [Environment Texture Tools](https://doc.babylonjs.com/how_to/physically_based_rendering#creating-a-compressed-environment-texture) to reduce the size of the usual .DDS file ([sebavan](http://www.github.com/sebavan))
 - New GUI control: the [Grid](http://doc.babylonjs.com/how_to/gui#grid) ([Deltakosh](https://github.com/deltakosh))
-- Gizmo and GizmoManager classes used to manipulate meshes in a scene. Gizmo types include: position, scale, rotation and bounding box. [Doc](http://doc.babylonjs.com/how_to/gizmo) ([TrevorDev](https://github.com/TrevorDev))
+- Gizmo and GizmoManager classes used to manipulate meshes in a scene. Gizmo types include: position, rotation, scale and bounding box. [Doc](http://doc.babylonjs.com/how_to/gizmo) ([TrevorDev](https://github.com/TrevorDev))
 - New behaviors: PointerDragBehavior, SixDofDragBehavior and MultiPointerScaleBehavior to enable smooth drag and drop/scaling with mouse or 6dof controller on a mesh. [Doc](http://doc.babylonjs.com/how_to/meshbehavior) ([TrevorDev](https://github.com/TrevorDev))
 - Particle system improvements ([Deltakosh](https://github.com/deltakosh))
   - Added a ParticleHelper class to create some pre-configured particle systems in a one-liner method style. [Doc](https://doc.babylonjs.com/How_To/ParticleHelper) ([Deltakosh](https://github.com/deltakosh)) / ([DevChris](https://github.com/yovanoc))

+ 13 - 5
src/Gizmos/babylon.boundingBoxGizmo.ts

@@ -44,6 +44,7 @@ module BABYLON {
          */
         public onDragEndObservable = new Observable<{}>();
         private _anchorMesh:AbstractMesh;
+        private _existingMeshScale = new Vector3();
         /**
          * Creates an BoundingBoxGizmo
          * @param gizmoLayer The utility layer the gizmo will be added to
@@ -143,6 +144,7 @@ module BABYLON {
                             this._anchorMesh.rotationQuaternion!.multiplyToRef(this._tmpQuaternion,this._anchorMesh.rotationQuaternion!);
                             this._anchorMesh.removeChild(this.attachedMesh);
                         }
+                        this.updateBoundingBox(); 
                     }
                 });
 
@@ -179,7 +181,7 @@ module BABYLON {
                             if(this.attachedMesh){
                                 var deltaScale = new Vector3(event.dragDistance,event.dragDistance,event.dragDistance);
                                 deltaScale.scaleInPlace(this._scaleDragSpeed);
-                                this._updateBoundingBox(); 
+                                this.updateBoundingBox(); 
 
                                  // Scale from the position of the opposite corner                   
                                 box.absolutePosition.subtractToRef(this._anchorMesh.position, this._tmpVector);
@@ -229,9 +231,12 @@ module BABYLON {
 
             // Update bounding box positions
             this._renderObserver = this.gizmoLayer.originalScene.onBeforeRenderObservable.add(()=>{
-                this._updateBoundingBox();
+                // Only update the bouding box if scaling has changed
+                if(this.attachedMesh && !this._existingMeshScale.equals(this.attachedMesh.scaling)){
+                    this.updateBoundingBox();
+                }
             })
-            this._updateBoundingBox();
+            this.updateBoundingBox();
         }
         
         protected _attachedMeshChanged(value:Nullable<AbstractMesh>){
@@ -240,7 +245,7 @@ module BABYLON {
                 // This is needed to avoid invalid box/sphere position on first drag
                 this._anchorMesh.addChild(value);
                 this._anchorMesh.removeChild(value);
-                this._updateBoundingBox();
+                this.updateBoundingBox();
             }
         }
 
@@ -258,7 +263,7 @@ module BABYLON {
             });
         }
 
-        private _updateBoundingBox(){
+        public updateBoundingBox(){
             if(this.attachedMesh){             
                 // Rotate based on axis
                 if(!this.attachedMesh.rotationQuaternion){
@@ -345,6 +350,9 @@ module BABYLON {
                     }
                 }
             }
+            if(this.attachedMesh){
+                this._existingMeshScale.copyFrom(this.attachedMesh.scaling);
+            }
         }
 
         /**