Skip to content

Commit

Permalink
Prevent using change event of transform controls
Browse files Browse the repository at this point in the history
  • Loading branch information
arjxn-py committed Jan 7, 2025
1 parent 625f651 commit 58cdbbe
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions packages/base/src/3dview/mainview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,12 @@ export class MainView extends React.Component<IProps, IStates> {
this._transformControls.rotationSnap = THREE.MathUtils.degToRad(
this.state.rotationSnapValue
);
this._transformControls.addEventListener('change', () => {
const newMode = this._transformControls.mode || 'translate';
if (this.state.transformMode !== newMode) {
this.setState({ transformMode: newMode });
document.addEventListener('keydown', event => {
if (event.key === 'r') {
const newMode = this._transformControls.mode || 'translate';
if (this.state.transformMode !== newMode) {
this.setState({ transformMode: newMode });
}
}
});
}
Expand Down Expand Up @@ -189,6 +191,18 @@ export class MainView extends React.Component<IProps, IStates> {
this._mainViewModel.renderSignal.disconnect(this._requestRender, this);
this._mainViewModel.workerBusy.disconnect(this._workerBusyHandler, this);
this._mainViewModel.dispose();
// Add event listener for keydown and keyup to enable/disable rotation snapping
document.addEventListener('keydown', event => {
if (event.key === 'Control') {
this._transformControls.rotationSnap = THREE.MathUtils.degToRad(10);
}
});

document.addEventListener('keyup', event => {
if (event.key === 'Control') {
this._transformControls.rotationSnap = null;
}
});
}

addContextMenu = (): void => {
Expand Down Expand Up @@ -439,18 +453,6 @@ export class MainView extends React.Component<IProps, IStates> {
this._transformControls.addEventListener('dragging-changed', event => {
this._controls.enabled = !event.value;
});
// Add event listener for keydown and keyup to enable/disable rotation snapping
document.addEventListener('keydown', event => {
if (event.key === 'Control') {
this._transformControls.rotationSnap = THREE.MathUtils.degToRad(10);
}
});

document.addEventListener('keyup', event => {
if (event.key === 'Control') {
this._transformControls.rotationSnap = null;
}
});
// Update the currently transformed object in the shared model once finished moving
this._transformControls.addEventListener('mouseUp', async () => {
const updatedObject = this._selectedMeshes[0];
Expand Down

0 comments on commit 58cdbbe

Please sign in to comment.