| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213 |
- import * as THREE from 'three';
- import UseThree from '../../../../utils/threejs/useThree';
- import FireDoor from './fireDoor.threejs.fire';
- import FireDoorF from './fireDoor.threejs.fireF';
- import FireDoorSsl from './fireDoor.threejs.ssl';
- import { animateCamera } from '/@/utils/threejs/util';
- import useEvent from '../../../../utils/threejs/useEvent';
- // 模型对象、 文字对象
- let model,
- fireDoor, //液压风门
- fireDoorF, //液压风门
- fireDoorSsl, // 思山岭防火门
- group: THREE.Object3D,
- fhmType = '';
- const { mouseDownFn } = useEvent();
- // 初始化左右摇摆动画
- const startAnimation = () => {
- // 定义鼠标点击事件
- model.canvasContainer?.addEventListener('mousedown', mouseEvent.bind(null));
- model.canvasContainer?.addEventListener('pointerup', (event) => {
- event.stopPropagation();
- // 单道、 双道
- if (fhmType === 'fireDoor') {
- fireDoor?.mouseUpModel.call(fireDoor);
- }
- if (fhmType === 'fireDoorF') {
- fireDoorF?.mouseUpModel.call(fireDoorF);
- }
- if (fhmType === 'fireDoorSsl') {
- fireDoorSsl?.mouseUpModel.call(fireDoorSsl);
- }
- });
- };
- // 鼠标点击、松开事件
- const mouseEvent = (event) => {
- if (event.button == 0) {
- mouseDownFn(model, group, event, (intersects) => {
- if (fhmType === 'fireDoor' && fireDoor) {
- fireDoor?.mousedownModel.call(fireDoor, intersects);
- }
- if (fhmType === 'fireDoorF' && fireDoorF) {
- fireDoorF?.mousedownModel.call(fireDoorF, intersects);
- }
- if (fhmType === 'fireDoorSsl' && fireDoorSsl) {
- fireDoorSsl?.mousedownModel.call(fireDoorSsl, intersects);
- }
- });
- // console.log('摄像头控制信息', model.orbitControls, model.camera);
- }
- };
- export const play = (handlerState, flag?) => {
- if (fhmType === 'fireDoor' && fireDoor) {
- return fireDoor.play.call(fireDoor, handlerState, flag);
- }
- if (fhmType === 'fireDoorF' && fireDoorF) {
- return fireDoorF.play.call(fireDoorF, handlerState, flag);
- }
- if (fhmType === 'fireDoorSsl' && fireDoorSsl) {
- return fireDoorSsl.play.call(fireDoorSsl, handlerState, flag);
- }
- };
- // 切换风门类型
- export const setModelType = (type) => {
- fhmType = type;
- return new Promise((resolve) => {
- // 暂停风门1动画
- if (fhmType === '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);
- } else if (fhmType === 'fireDoorF' && fireDoorF && fireDoorF.group) {
- if (fireDoorF.clipActionArr.door) {
- fireDoorF.clipActionArr.door.reset();
- fireDoorF.clipActionArr.door.time = 0;
- fireDoorF.clipActionArr.door.stop();
- }
- model.scene.remove(group);
- model.startAnimation = fireDoorF.render.bind(fireDoorF);
- group = fireDoorF.group;
- group.rotation.y = 0;
- const oldCameraPosition = { x: -1000, y: 100, z: 500 };
- setTimeout(async () => {
- resolve(null);
- model.scene.add(fireDoorF.group);
- await animateCamera(
- oldCameraPosition,
- { x: 0, y: 0, z: 0 },
- { x: -655.0169729333649, y: 47.24181078408825, z: -9.781926649842067 },
- { x: -7.380506513422206, y: 47.24181078408821, z: -37.9244016972381 },
- model,
- 0.8
- );
- }, 300);
- } else if (fhmType === 'fireDoorSsl' && fireDoorSsl && fireDoorSsl.group) {
- // if (fireDoorSsl.clipActionArr.door) {
- // fireDoorSsl.clipActionArr.door.reset();
- // fireDoorSsl.clipActionArr.door.time = 0;
- // fireDoorSsl.clipActionArr.door.stop();
- // }
- // model.scene.remove(group);
- // model.startAnimation = fireDoorSsl.render.bind(fireDoorSsl);
- group = fireDoorSsl.group;
- group.rotation.y = 0;
- const oldCameraPosition = { x: -1000, y: 100, z: 500 };
- setTimeout(async () => {
- resolve(null);
- model.scene.add(fireDoorSsl.group);
- await animateCamera(
- oldCameraPosition,
- { x: 0, y: 0, z: 0 },
- {
- x: 342.74781900192056,
- y: 183.50210411099545,
- z: 451.0806333923029,
- },
- {
- x: 72.33938301176254,
- y: -35.03891296652319,
- z: -37.91742549963208,
- },
- model,
- 0.8
- );
- }, 300);
- }
- });
- };
- export const initCameraCanvas = async (playerVal1) => {
- if (fhmType === 'fireDoor' && fireDoor) {
- return await fireDoor.initCamera.call(fireDoor, playerVal1);
- } else if (fhmType === 'fireDoorF' && fireDoorF) {
- return await fireDoorF.initCamera.call(fireDoorF, playerVal1);
- } else if (fhmType === 'fireDoorSsl' && fireDoorSsl) {
- return await fireDoorSsl.initCamera.call(fireDoorSsl, 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 = () => {
- return new Promise(async (resolve) => {
- model = new UseThree('#damper3D', '', '#deviceDetail');
- model.setEnvMap('test1.hdr');
- model.renderer.toneMappingExposure = 1.0;
- model.camera.position.set(100, 0, 1000);
- fireDoor = new FireDoor(model);
- fireDoor.mountedThree();
- fireDoorF = new FireDoorF(model);
- fireDoorF.mountedThree();
- fireDoorSsl = new FireDoorSsl(model);
- fireDoorSsl.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;
- // @ts-ignore-next-line
- group = null;
- model.mixers = [];
- model.destroy();
- }
- model = null;
- };
|