From fed41b2fd390ae729c05f63fcbc9f5e93cfd8f71 Mon Sep 17 00:00:00 2001 From: fuliqi <fuliqi@qq.com> Date: 星期五, 19 四月 2024 15:56:03 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/master' --- src/views/screen/components/screen-map-three/experience/camera.js | 66 +++++++++++++++++++++++++++++++++ 1 files changed, 66 insertions(+), 0 deletions(-) diff --git a/src/views/screen/components/screen-map-three/experience/camera.js b/src/views/screen/components/screen-map-three/experience/camera.js new file mode 100644 index 0000000..fdf3223 --- /dev/null +++ b/src/views/screen/components/screen-map-three/experience/camera.js @@ -0,0 +1,66 @@ +import { MathUtils } from 'three'; +import { PerspectiveCamera, CameraHelper } from 'three'; +import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls'; + + +export default class Camera { + constructor(experience) { + this.experience = experience; + this.scene = experience.scene; + this.canvas = experience.canvas; + this.sizes = experience.sizes; + this.setInstance(); + this.setOrbitControls(); + } + + // 璁剧疆閫忚鐩告満 + setInstance() { + this.instance = new PerspectiveCamera(45, this.sizes.width / this.sizes.height, 0.1, 200); + this.instance.position.set(0, 45, 45); + this.scene.add(this.instance); + // const help = new CameraHelper(this.instance); + // this.scene.add(help); + } + + setOrbitControls() { + this.controls = new OrbitControls(this.instance, this.canvas); + this.controls.target.set(0, 0, 5); + this.controls.enableDamping = true; + this.controls.minDistance = 20; + this.controls.maxDistance = 80; + this.controls.maxPolarAngle = MathUtils.degToRad(80); + // this.controls.maxPolarAngle = (-Math.PI / 2); + } + + resize() { + // 閲嶆柊璁$畻姣斾緥 + this.cameraAspect = this.sizes.width / this.sizes.height; + this.instance.updateProjectionMatrix(); + } + + + update() { + this.controls.update(); + } + + destroy() { + this.disposeObject(); + this.removeObject(); + this.resetObject(); + } + + disposeObject() { + this.controls.dispose(); + } + + removeObject() { + this.scene.remove(this.instance); + } + resetObject() { + this.controls = null; + this.instance = null; + this.scene = null; + this.canvas = null; + this.sizes = null; + } +} \ No newline at end of file -- Gitblit v1.8.0