|
@@ -65,34 +65,36 @@ module BABYLON {
|
|
|
|
|
|
// 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 && this._pivotCached === 0){
|
|
|
+ private static _PivotCached = 0;
|
|
|
+ private static _OldPivotPoint = new Vector3();
|
|
|
+ private static _PivotTranslation = new Vector3();
|
|
|
+ private static _PivotTmpVector = new Vector3();
|
|
|
+ /** @hidden */
|
|
|
+ public static _RemoveAndStorePivotPoint(mesh:AbstractMesh){
|
|
|
+ if(mesh && BoundingBoxGizmo._PivotCached === 0){
|
|
|
// Save old pivot and set pivot to 0,0,0
|
|
|
- this.attachedMesh.getPivotPointToRef(this._oldPivotPoint);
|
|
|
- if(this._oldPivotPoint.equalsToFloats(0,0,0)){
|
|
|
- return;
|
|
|
+ mesh.getPivotPointToRef(BoundingBoxGizmo._OldPivotPoint);
|
|
|
+ if(!BoundingBoxGizmo._OldPivotPoint.equalsToFloats(0,0,0)){
|
|
|
+ mesh.setPivotMatrix(Matrix.IdentityReadOnly);
|
|
|
+ BoundingBoxGizmo._OldPivotPoint.subtractToRef(mesh.getPivotPoint(), BoundingBoxGizmo._PivotTranslation);
|
|
|
+ BoundingBoxGizmo._PivotTmpVector.copyFromFloats(1,1,1);
|
|
|
+ BoundingBoxGizmo._PivotTmpVector.subtractInPlace(mesh.scaling);
|
|
|
+ BoundingBoxGizmo._PivotTmpVector.multiplyInPlace(BoundingBoxGizmo._PivotTranslation);
|
|
|
+ mesh.position.addInPlace(BoundingBoxGizmo._PivotTmpVector);
|
|
|
}
|
|
|
- this.attachedMesh.setPivotMatrix(Matrix.IdentityReadOnly);
|
|
|
- this._oldPivotPoint.subtractToRef(this.attachedMesh.getPivotPoint(), this._pivotTranslation);
|
|
|
- this._tmpVector.copyFromFloats(1,1,1);
|
|
|
- this._tmpVector.subtractInPlace(this.attachedMesh.scaling);
|
|
|
- this._tmpVector.multiplyInPlace(this._pivotTranslation);
|
|
|
- this.attachedMesh.position.addInPlace(this._tmpVector);
|
|
|
}
|
|
|
- this._pivotCached++;
|
|
|
+ BoundingBoxGizmo._PivotCached++;
|
|
|
}
|
|
|
- private _restorePivotPoint(){
|
|
|
- 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);
|
|
|
+ /** @hidden */
|
|
|
+ public static _RestorePivotPoint(mesh:AbstractMesh){
|
|
|
+ if(mesh && !BoundingBoxGizmo._OldPivotPoint.equalsToFloats(0,0,0) && BoundingBoxGizmo._PivotCached === 1){
|
|
|
+ mesh.setPivotPoint(BoundingBoxGizmo._OldPivotPoint);
|
|
|
+ BoundingBoxGizmo._PivotTmpVector.copyFromFloats(1,1,1);
|
|
|
+ BoundingBoxGizmo._PivotTmpVector.subtractInPlace(mesh.scaling);
|
|
|
+ BoundingBoxGizmo._PivotTmpVector.multiplyInPlace(BoundingBoxGizmo._PivotTranslation);
|
|
|
+ mesh.position.subtractInPlace(BoundingBoxGizmo._PivotTmpVector);
|
|
|
}
|
|
|
- this._pivotCached--;
|
|
|
+ this._PivotCached--;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -161,7 +163,7 @@ module BABYLON {
|
|
|
_dragBehavior.onDragObservable.add((event) => {
|
|
|
this.onRotationSphereDragObservable.notifyObservers({});
|
|
|
if (this.attachedMesh) {
|
|
|
- this._removeAndStorePivotPoint();
|
|
|
+ BoundingBoxGizmo._RemoveAndStorePivotPoint(this.attachedMesh);
|
|
|
|
|
|
var worldDragDirection = startingTurnDirection;
|
|
|
|
|
@@ -201,7 +203,7 @@ module BABYLON {
|
|
|
}
|
|
|
this.updateBoundingBox();
|
|
|
|
|
|
- this._restorePivotPoint();
|
|
|
+ BoundingBoxGizmo._RestorePivotPoint(this.attachedMesh);
|
|
|
}
|
|
|
});
|
|
|
|
|
@@ -236,7 +238,7 @@ module BABYLON {
|
|
|
_dragBehavior.onDragObservable.add((event) => {
|
|
|
this.onScaleBoxDragObservable.notifyObservers({});
|
|
|
if(this.attachedMesh){
|
|
|
- this._removeAndStorePivotPoint();
|
|
|
+ BoundingBoxGizmo._RemoveAndStorePivotPoint(this.attachedMesh);
|
|
|
var relativeDragDistance = (event.dragDistance / this._boundingDimensions.length())*this._anchorMesh.scaling.length();
|
|
|
var deltaScale = new Vector3(relativeDragDistance,relativeDragDistance,relativeDragDistance);
|
|
|
deltaScale.scaleInPlace(this._scaleDragSpeed);
|
|
@@ -263,7 +265,7 @@ module BABYLON {
|
|
|
}
|
|
|
this._anchorMesh.removeChild(this.attachedMesh);
|
|
|
|
|
|
- this._restorePivotPoint();
|
|
|
+ BoundingBoxGizmo._RestorePivotPoint(this.attachedMesh);
|
|
|
}
|
|
|
})
|
|
|
|
|
@@ -315,10 +317,10 @@ module BABYLON {
|
|
|
if (value) {
|
|
|
// Reset anchor mesh to match attached mesh's scale
|
|
|
// This is needed to avoid invalid box/sphere position on first drag
|
|
|
- this._removeAndStorePivotPoint();
|
|
|
+ BoundingBoxGizmo._RemoveAndStorePivotPoint(value);
|
|
|
this._anchorMesh.addChild(value);
|
|
|
this._anchorMesh.removeChild(value);
|
|
|
- this._restorePivotPoint();
|
|
|
+ BoundingBoxGizmo._RestorePivotPoint(value);
|
|
|
this.updateBoundingBox();
|
|
|
}
|
|
|
}
|
|
@@ -344,7 +346,7 @@ module BABYLON {
|
|
|
*/
|
|
|
public updateBoundingBox(){
|
|
|
if(this.attachedMesh){
|
|
|
- this._removeAndStorePivotPoint();
|
|
|
+ BoundingBoxGizmo._RemoveAndStorePivotPoint(this.attachedMesh);
|
|
|
this._update();
|
|
|
// Rotate based on axis
|
|
|
if (!this.attachedMesh.rotationQuaternion) {
|
|
@@ -439,7 +441,7 @@ module BABYLON {
|
|
|
}
|
|
|
if (this.attachedMesh) {
|
|
|
this._existingMeshScale.copyFrom(this.attachedMesh.scaling);
|
|
|
- this._restorePivotPoint();
|
|
|
+ BoundingBoxGizmo._RestorePivotPoint(this.attachedMesh);
|
|
|
}
|
|
|
}
|
|
|
|