Skip to content

Commit 389e606

Browse files
committed
Add option: listenToKeyEvents
1 parent 2dfc83e commit 389e606

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ const viewer = new GaussianSplats3D.Viewer({
282282
'renderer': renderer,
283283
'camera': camera,
284284
'useBuiltInControls': false,
285+
'listenToKeyEvents': false,
285286
'ignoreDevicePixelRatio': false,
286287
'gpuAcceleratedSort': true,
287288
`enableSIMDInSort`: true,
@@ -321,6 +322,7 @@ Advanced `Viewer` parameters
321322
| `renderer` | Pass an instance of a Three.js `Renderer` to the viewer, otherwise it will create its own. Defaults to `undefined`.
322323
| `camera` | Pass an instance of a Three.js `Camera` to the viewer, otherwise it will create its own. Defaults to `undefined`.
323324
| `useBuiltInControls` | Tells the viewer to use its own camera controls. Defaults to `true`.
325+
| `listenToKeyEvents` | Tells the viewer to enable key controls, needs `useBuiltInControls` enabled to take effect. Defaults to `true`.
324326
| `ignoreDevicePixelRatio` | Tells the viewer to pretend the device pixel ratio is 1, which can boost performance on devices where it is larger, at a small cost to visual quality. Defaults to `false`.
325327
| `gpuAcceleratedSort` | Tells the viewer to use a partially GPU-accelerated approach to sorting splats. Currently this means pre-computation of splat distances from the camera is performed on the GPU. It is recommended that this only be set to `true` when `sharedMemoryForWorkers` is also `true`. Defaults to `false` on mobile devices, `true` otherwise.
326328
| `enableSIMDInSort` | Enable the usage of SIMD WebAssembly instructions for the splat sort. Default is `true`.

src/DropInViewer.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export class DropInViewer extends THREE.Group {
1212

1313
options.selfDrivenMode = false;
1414
options.useBuiltInControls = false;
15+
options.listenToKeyEvents = false;
1516
options.rootElement = null;
1617
options.dropInMode = true;
1718
options.camera = undefined;

src/Viewer.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,10 @@ export class Viewer {
6565

6666
// If 'useBuiltInControls' is true, the viewer will create its own instance of OrbitControls and attach to the camera
6767
if (options.useBuiltInControls === undefined) options.useBuiltInControls = true;
68+
if (options.listenToKeyEvents === undefined) options.listenToKeyEvents = true;
69+
6870
this.useBuiltInControls = options.useBuiltInControls;
71+
this.listenToKeyEvents = options.listenToKeyEvents;
6972

7073
// parent element of the Three.js renderer canvas
7174
this.rootElement = options.rootElement;
@@ -404,7 +407,7 @@ export class Viewer {
404407
}
405408
for (let controls of [this.orthographicControls, this.perspectiveControls,]) {
406409
if (controls) {
407-
controls.listenToKeyEvents(window);
410+
this.listenToKeyEvents ?? controls.listenToKeyEvents(window);
408411
controls.rotateSpeed = 0.5;
409412
controls.maxPolarAngle = Math.PI * .75;
410413
controls.minPolarAngle = 0.1;
@@ -427,7 +430,9 @@ export class Viewer {
427430
this.renderer.domElement.addEventListener('pointerdown', this.mouseDownListener, false);
428431
this.mouseUpListener = this.onMouseUp.bind(this);
429432
this.renderer.domElement.addEventListener('pointerup', this.mouseUpListener, false);
430-
this.keyDownListener = this.onKeyDown.bind(this);
433+
if (listenToKeyEvents) {
434+
this.keyDownListener = this.onKeyDown.bind(this);
435+
}
431436
window.addEventListener('keydown', this.keyDownListener, false);
432437
}
433438
}
@@ -440,7 +445,7 @@ export class Viewer {
440445
this.mouseDownListener = null;
441446
this.renderer.domElement.removeEventListener('pointerup', this.mouseUpListener);
442447
this.mouseUpListener = null;
443-
window.removeEventListener('keydown', this.keyDownListener);
448+
this.listenToKeyEvents ?? window.removeEventListener('keydown', this.keyDownListener);
444449
this.keyDownListener = null;
445450
}
446451
}

0 commit comments

Comments
 (0)