[3d] refactor load3d nodes (#2683)

Co-authored-by: github-actions <github-actions@github.com>
This commit is contained in:
Terry Jia
2025-02-22 18:36:47 -05:00
committed by GitHub
parent 86b65d481a
commit c502b86c31
24 changed files with 2341 additions and 1399 deletions

View File

@@ -0,0 +1,72 @@
import * as THREE from 'three'
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls'
import {
ControlsManagerInterface,
EventManagerInterface,
NodeStorageInterface
} from './interfaces'
export class ControlsManager implements ControlsManagerInterface {
controls: OrbitControls
private eventManager: EventManagerInterface
private nodeStorage: NodeStorageInterface
private camera: THREE.Camera
constructor(
renderer: THREE.WebGLRenderer,
camera: THREE.Camera,
eventManager: EventManagerInterface,
nodeStorage: NodeStorageInterface
) {
this.eventManager = eventManager
this.nodeStorage = nodeStorage
this.camera = camera
this.controls = new OrbitControls(camera, renderer.domElement)
this.controls.enableDamping = true
}
init(): void {
this.controls.addEventListener('end', () => {
this.nodeStorage.storeNodeProperty('Camera Info', {
position: this.camera.position.clone(),
target: this.controls.target.clone(),
zoom:
this.camera instanceof THREE.OrthographicCamera
? (this.camera as THREE.OrthographicCamera).zoom
: (this.camera as THREE.PerspectiveCamera).zoom,
cameraType:
this.camera instanceof THREE.PerspectiveCamera
? 'perspective'
: 'orthographic'
})
})
}
dispose(): void {
this.controls.dispose()
}
handleResize(): void {}
update(): void {
this.controls.update()
}
updateCamera(camera: THREE.Camera): void {
const position = this.controls.object.position.clone()
const target = this.controls.target.clone()
this.camera = camera
this.controls.object = camera
this.controls.target = target
camera.position.copy(position)
this.controls.update()
}
reset(): void {
this.controls.target.set(0, 0, 0)
this.controls.update()
}
}