Skip to content

Commit

Permalink
Merge pull request #818 from 3DStreet/transformcontrolsupdate
Browse files Browse the repository at this point in the history
Update transform controls scale on camera change
  • Loading branch information
kfarr authored Aug 31, 2024
2 parents 16d278d + 48f3f57 commit a22ce4b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
16 changes: 5 additions & 11 deletions src/editor/lib/EditorControls.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import debounce from 'lodash-es/debounce';
import { currentOrthoDir } from './cameras';

/**
Expand Down Expand Up @@ -56,10 +55,6 @@ THREE.EditorControls = function (_object, domElement) {

var changeEvent = { type: 'change' };

this.dispatchChange = debounce(() => {
scope.dispatchEvent(changeEvent);
}, 100);

this.focus = function (target) {
if (this.isOrthographic) {
return;
Expand Down Expand Up @@ -101,7 +96,6 @@ THREE.EditorControls = function (_object, domElement) {
scope.transitionSpeed = 0.001;
scope.transitionProgress = 0;
scope.transitioning = true;
// The changeEvent is emitted at the end of the transition below
};

function easeInOutQuad(t) {
Expand Down Expand Up @@ -144,8 +138,8 @@ THREE.EditorControls = function (_object, domElement) {
this.transitioning = false;
object.position.copy(this.transitionCamPosEnd);
object.quaternion.copy(this.transitionCamQuaternionEnd);
scope.dispatchEvent(changeEvent);
}
scope.dispatchEvent(changeEvent);
}
}
};
Expand All @@ -171,7 +165,7 @@ THREE.EditorControls = function (_object, domElement) {
object.position.add(delta);
center.add(delta);

scope.dispatchChange();
scope.dispatchEvent(changeEvent);
};

var ratio = 1;
Expand Down Expand Up @@ -207,7 +201,7 @@ THREE.EditorControls = function (_object, domElement) {
object.position.add(delta);
}

scope.dispatchChange();
scope.dispatchEvent(changeEvent);
};

this.rotate = function (delta) {
Expand All @@ -230,7 +224,7 @@ THREE.EditorControls = function (_object, domElement) {

object.lookAt(center);

scope.dispatchChange();
scope.dispatchEvent(changeEvent);
};

// mouse
Expand Down Expand Up @@ -446,7 +440,7 @@ THREE.EditorControls = function (_object, domElement) {
object.updateMatrixWorld();
}

scope.dispatchChange();
scope.dispatchEvent(changeEvent);
};
};

Expand Down
10 changes: 8 additions & 2 deletions src/editor/lib/viewport.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,10 @@ export function Viewport(inspector) {
controls.rotationSpeed = 0.0035;
controls.zoomSpeed = 0.05;
controls.setAspectRatio(sceneEl.canvas.width / sceneEl.canvas.height);
controls.addEventListener('change', () => {
transformControls.update(true); // true is updateScale
Events.emit('camerachanged');
});

sceneEl.addEventListener('newScene', () => {
controls.resetZoom();
Expand Down Expand Up @@ -282,13 +286,15 @@ export function Viewport(inspector) {
object.el.addEventListener('model-loaded', listener);
}

transformControls.attach(object);
if (inspector.cursor.isPlaying) {
// Only show transform controls when we are in pointer mode
transformControls.attach(object);
}
}
});

Events.on('objectfocus', (object) => {
controls.focus(object);
transformControls.update();
});

Events.on('geometrychanged', (object) => {
Expand Down

0 comments on commit a22ce4b

Please sign in to comment.