Skip to content

Commit

Permalink
🎈 perf: Shortcut keys to toggle view translation and rotation
Browse files Browse the repository at this point in the history
  • Loading branch information
xiangechen committed Mar 6, 2024
1 parent 9b45dfa commit 0ce306a
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions packages/chili-three/src/threeViewEventHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ export class ThreeViewHandler implements IEventHandler {
private _lastDown: MouseDownData | undefined;
private _clearDownId: number | undefined;

dispose() {}
canRotate: boolean = true;

dispose() {
this.clearTimeout();
}

mouseWheel(view: IView, event: WheelEvent): void {
view.cameraController.zoom(event.offsetX, event.offsetY, event.deltaY);
Expand All @@ -22,10 +26,10 @@ export class ThreeViewHandler implements IEventHandler {

pointerMove(view: IView, event: PointerEvent): void {
if (event.buttons === MIDDLE) {
if (event.shiftKey) {
view.cameraController.pan(event.movementX, event.movementY);
} else if (!event.shiftKey) {
if (event.shiftKey && this.canRotate) {
view.cameraController.rotate(event.movementX, event.movementY);
} else if (!event.shiftKey) {
view.cameraController.pan(event.movementX, event.movementY);
}
if (event.movementX !== 0 && event.movementY !== 0) this._lastDown = undefined;
view.update();
Expand Down

0 comments on commit 0ce306a

Please sign in to comment.