|
@@ -1,7 +1,7 @@
|
|
|
import { Observer, Observable } from "../Misc/observable";
|
|
|
import { Nullable } from "../types";
|
|
|
import { PointerInfo } from "../Events/pointerEvents";
|
|
|
-import { Vector3, Matrix } from "../Maths/math.vector";
|
|
|
+import { Vector3 } from "../Maths/math.vector";
|
|
|
import { TransformNode } from "../Meshes/transformNode";
|
|
|
import { Node } from "../node";
|
|
|
import { Mesh } from "../Meshes/mesh";
|
|
@@ -101,32 +101,27 @@ export class AxisDragGizmo extends Gizmo {
|
|
|
this.dragBehavior.moveAttached = false;
|
|
|
this._rootMesh.addBehavior(this.dragBehavior);
|
|
|
|
|
|
- var localDelta = new Vector3();
|
|
|
- var tmpMatrix = new Matrix();
|
|
|
this.dragBehavior.onDragObservable.add((event) => {
|
|
|
if (this.attachedNode) {
|
|
|
- // Convert delta to local translation if it has a parent
|
|
|
- if (this.attachedNode.parent) {
|
|
|
- this.attachedNode.parent.getWorldMatrix().invertToRef(tmpMatrix);
|
|
|
- tmpMatrix.setTranslationFromFloats(0, 0, 0);
|
|
|
- Vector3.TransformCoordinatesToRef(event.delta, tmpMatrix, localDelta);
|
|
|
- } else {
|
|
|
- localDelta.copyFrom(event.delta);
|
|
|
- }
|
|
|
+ // Keep world translation and use it to update world transform
|
|
|
+ // if the node has parent, the local transform properties (position, rotation, scale)
|
|
|
+ // will be recomputed in _matrixChanged function
|
|
|
+
|
|
|
// Snapping logic
|
|
|
if (this.snapDistance == 0) {
|
|
|
if ((this.attachedNode as any).position) { // Required for nodes like lights
|
|
|
- (this.attachedNode as any).position.addInPlaceFromFloats(localDelta.x, localDelta.y, localDelta.z);
|
|
|
+ (this.attachedNode as any).position.addInPlaceFromFloats(event.delta.x, event.delta.y, event.delta.z);
|
|
|
}
|
|
|
+
|
|
|
// use _worldMatrix to not force a matrix update when calling GetWorldMatrix especialy with Cameras
|
|
|
- this.attachedNode._worldMatrix.addTranslationFromFloats(localDelta.x, localDelta.y, localDelta.z);
|
|
|
+ this.attachedNode._worldMatrix.addTranslationFromFloats(event.delta.x, event.delta.y, event.delta.z);
|
|
|
this.attachedNode.updateCache();
|
|
|
} else {
|
|
|
currentSnapDragDistance += event.dragDistance;
|
|
|
if (Math.abs(currentSnapDragDistance) > this.snapDistance) {
|
|
|
var dragSteps = Math.floor(Math.abs(currentSnapDragDistance) / this.snapDistance);
|
|
|
currentSnapDragDistance = currentSnapDragDistance % this.snapDistance;
|
|
|
- localDelta.normalizeToRef(tmpVector);
|
|
|
+ event.delta.normalizeToRef(tmpVector);
|
|
|
tmpVector.scaleInPlace(this.snapDistance * dragSteps);
|
|
|
this.attachedNode._worldMatrix.addTranslationFromFloats(tmpVector.x, tmpVector.y, tmpVector.z);
|
|
|
this.attachedNode.updateCache();
|