| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128 |
- import * as THREE from 'three';
- import UseThree from '../../../../utils/threejs/useThree';
- import FireDoor from './fireDoor.threejs.fire';
- import { animateCamera } from '/@/utils/threejs/util';
- import useEvent from '../../../../utils/threejs/useEvent';
- import { useGlobSetting } from '/@/hooks/setting';
- // 模型对象、 文字对象
- let model,
- fireDoor, //液压风门
- group: THREE.Object3D,
- fmType = '';
- const { mouseDownFn } = useEvent();
- // 初始化左右摇摆动画
- const startAnimation = () => {
- // 定义鼠标点击事件
- model.canvasContainer?.addEventListener('mousedown', mouseEvent.bind(null));
- model.canvasContainer?.addEventListener('pointerup', (event) => {
- event.stopPropagation();
- // 单道、 双道
- if (fmType === 'fireDoor') {
- fireDoor?.mouseUpModel.call(fireDoor);
- }
- });
- };
- // 鼠标点击、松开事件
- const mouseEvent = (event) => {
- if (event.button == 0) {
- mouseDownFn(model, group, event, (intersects) => {
- if (fmType === 'fireDoor' && fireDoor) {
- fireDoor?.mousedownModel.call(fireDoor, intersects);
- }
- });
- // console.log('摄像头控制信息', model.orbitControls, model.camera);
- }
- };
- export const play = (handlerState, flag?) => {
- if (fmType === 'fireDoor' && fireDoor) {
- return fireDoor.play.call(fireDoor, handlerState, flag);
- }
- };
- // 切换风门类型
- export const setModelType = (type) => {
- fmType = type;
- return new Promise((resolve) => {
- // 暂停风门1动画
- if (fmType === 'fireDoor' && fireDoor && fireDoor.group) {
- if (fireDoor.clipActionArr.door) {
- fireDoor.clipActionArr.door.reset();
- fireDoor.clipActionArr.door.time = 0.5;
- fireDoor.clipActionArr.door.stop();
- }
- if (fireDoor.damperOpenMesh) fireDoor.damperOpenMesh.visible = false;
- if (fireDoor.damperClosedMesh) fireDoor.damperClosedMesh.visible = true;
- model.scene.remove(group);
- model.startAnimation = fireDoor.render.bind(fireDoor);
- group = fireDoor.group;
- group.rotation.y = 0;
- const oldCameraPosition = { x: -1000, y: 100, z: 500 };
- setTimeout(async () => {
- resolve(null);
- model.scene.add(fireDoor.group);
- await animateCamera(
- oldCameraPosition,
- { x: 0, y: 0, z: 0 },
- { x: -654.2006991449887, y: 103.16181473511944, z: -30.348656073478562 },
- { x: -7.380506513422206, y: 56.36967052459397, z: -29.230675020846963 },
- model,
- 0.8
- );
- }, 300);
- }
- });
- };
- export const initCameraCanvas = async (playerVal1) => {
- if (fmType === 'fireDoor' && fireDoor) {
- return await fireDoor.initCamera.call(fireDoor, playerVal1);
- }
- };
- const setControls = () => {
- if (model && model.orbitControls) {
- model.orbitControls.maxPolarAngle = Math.PI / 2;
- model.orbitControls.minPolarAngle = Math.PI / 3;
- model.orbitControls.minDistance = 600;
- model.orbitControls.maxDistance = 900;
- }
- };
- export const mountedThree = () => {
- // const { sysOrgCode } = useGlobSetting();
- return new Promise(async (resolve) => {
- model = new UseThree('#damper3D', '', '#deviceDetail');
- model.setEnvMap('test1');
- model.renderer.toneMappingExposure = 1.0;
- model.camera.position.set(100, 0, 1000);
- fireDoor = new FireDoor(model);
- fireDoor.mountedThree();
- resolve(null);
- setControls();
- model.animate();
- startAnimation();
- });
- };
- export const destroy = () => {
- if (model) {
- model.orbitControls.maxPolarAngle = Math.PI;
- model.orbitControls.minPolarAngle = 0;
- model.orbitControls.enableRotate = true;
- model.orbitControls.minDistance = 0;
- model.orbitControls.maxDistance = Infinity;
- model.orbitControls.update();
- model.isRender = false;
- if (fireDoor) fireDoor.destroy();
- fireDoor = null;
- group = null;
- model.mixers = [];
- model.destroy();
- }
- model = null;
- };
|