Line data Source code
1 : import type * as THREE from 'three'
2 : import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls'
3 :
4 : import type { ControlsManagerInterface } from './interfaces'
5 :
6 24 : export class ControlsManager implements ControlsManagerInterface {
7 : controls: OrbitControls
8 :
9 : constructor(interactionElement: HTMLElement, camera: THREE.Camera) {
10 27 : this.controls = new OrbitControls(camera, interactionElement)
11 27 : this.controls.enableDamping = true
12 : }
13 :
14 : init(): void {}
15 :
16 : dispose(): void {
17 1 : this.controls.dispose()
18 : }
19 :
20 : handleResize(): void {}
21 :
22 : update(): void {
23 999 : this.controls.update()
24 : }
25 :
26 : updateCamera(camera: THREE.Camera): void {
27 52 : const position = this.controls.object.position.clone()
28 52 : const target = this.controls.target.clone()
29 :
30 52 : this.controls.object = camera
31 52 : this.controls.target = target
32 52 : camera.position.copy(position)
33 52 : this.controls.update()
34 : }
35 :
36 : detach(): void {
37 0 : this.controls.enabled = false
38 : }
39 :
40 : attach(): void {
41 0 : this.controls.enabled = true
42 : }
43 :
44 : reset(): void {
45 18 : this.controls.target.set(0, 0, 0)
46 18 : this.controls.update()
47 : }
48 : }
|