Переглянути джерело

doNotCachePivotMultipleTimes

Trevor Baron 7 роки тому
батько
коміт
cd7449e6e2

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

@@ -171,8 +171,9 @@
 - Fix File Loading if hosted from `file:`-Protocol ([ltetzlaff](https://github.com/ltetzlaff))
 - Do not throw error when updating a controller with no left stick ([TrevorDev](https://github.com/TrevorDev))
 - Exiting VR can result in messed up view ([TrevorDev](https://github.com/TrevorDev))
-- Dispose existing gazeTrackers when setting a new one, remove pivot matrix of meshes using boundingBoxGizmo ([TrevorDev](https://github.com/TrevorDev))
+- Dispose existing gazeTrackers when setting a new one ([TrevorDev](https://github.com/TrevorDev))
 - Set missing parentId in Mesh.serialize() for instances ([julien-moreau](https://github.com/julien-moreau))
+- Do not modify pivot when using bounding box gizmo ([TrevorDev](https://github.com/TrevorDev))
 
 ### Core Engine
 

+ 8 - 6
src/Gizmos/babylon.boundingBoxGizmo.ts

@@ -63,10 +63,13 @@ module BABYLON {
         private _anchorMesh: AbstractMesh;
         private _existingMeshScale = new Vector3();
 
+        // Stores the state of the pivot cache (_oldPivotPoint, _pivotTranslation)
+        // store/remove pivot point should only be applied during their outermost calls
+        private _pivotCached = 0;
         private _oldPivotPoint = new Vector3();
         private _pivotTranslation = new Vector3();
         private removeAndStorePivotPoint(){
-            if(this.attachedMesh){
+            if(this.attachedMesh && this._pivotCached == 0){
                 // Save old pivot and set pivot to 0,0,0
                 this.attachedMesh.getPivotPointToRef(this._oldPivotPoint);
                 if(this._oldPivotPoint.equalsToFloats(0,0,0)){
@@ -79,16 +82,17 @@ module BABYLON {
                 this._tmpVector.multiplyInPlace(this._pivotTranslation);
                 this.attachedMesh.position.addInPlace(this._tmpVector);
             }
+            this._pivotCached++;
         }
         private restorePivotPoint(){
-            if(this.attachedMesh && !this._oldPivotPoint.equalsToFloats(0,0,0)){
-                this.attachedMesh.setPivotPoint(this._oldPivotPoint);    
-                this._oldPivotPoint.subtractToRef(this.attachedMesh.getPivotPoint(), this._pivotTranslation);
+            if(this.attachedMesh && !this._oldPivotPoint.equalsToFloats(0,0,0) && this._pivotCached == 1){
+                this.attachedMesh.setPivotPoint(this._oldPivotPoint);
                 this._tmpVector.copyFromFloats(1,1,1);
                 this._tmpVector.subtractInPlace(this.attachedMesh.scaling);
                 this._tmpVector.multiplyInPlace(this._pivotTranslation);
                 this.attachedMesh.position.subtractInPlace(this._tmpVector);
             }
+            this._pivotCached--;
         }
 
         /**
@@ -233,12 +237,10 @@ module BABYLON {
                             this.onScaleBoxDragObservable.notifyObservers({});
                             if(this.attachedMesh){
                                 this.removeAndStorePivotPoint();
-                                
                                 var relativeDragDistance = (event.dragDistance / this._boundingDimensions.length())*this._anchorMesh.scaling.length();
                                 var deltaScale = new Vector3(relativeDragDistance,relativeDragDistance,relativeDragDistance);
                                 deltaScale.scaleInPlace(this._scaleDragSpeed);
                                 this.updateBoundingBox();
-
                                 if(this.scalePivot){
                                     this.attachedMesh.getWorldMatrix().getRotationMatrixToRef(this._tmpRotationMatrix);
                                     // Move anchor to desired pivot point (Bottom left corner + dimension/2)