123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- import * as THREE from 'three';
- import UseThree from '../../../../utils/threejs/useThree';
- import Fm1 from './gate.threejs.two';
- import Fm2 from './gate.threejs.three';
- import { animateCamera } from '/@/utils/threejs/util';
- import useEvent from '../../../../utils/threejs/useEvent';
- // 模型对象、 文字对象
- let model,
- fm1: Fm1,
- fm2: Fm2,
- 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 === 'fm1') {
- fm1.mouseUpModel.call(fm1);
- } else if (fmType === 'fm2') {
- fm2.mouseUpModel.call(fm2);
- }
- });
- };
- // 鼠标点击、松开事件
- const mouseEvent = (event) => {
- if (event.button == 0) {
- mouseDownFn(model, group, event, (intersects) => {
- if (fmType === 'fm1' && fm1) {
- fm1.mousedownModel.call(fm1, intersects);
- } else if (fmType === 'fm2' && fm2) {
- fm2.mousedownModel.call(fm2, intersects);
- }
- });
- // console.log('摄像头控制信息', model.orbitControls, model.camera);
- }
- };
- export const addMonitorText = (selectData) => {
- if (fmType === 'fm1' && fm1) {
- return fm1.addMonitorText.call(fm1, selectData);
- } else if (fmType === 'fm2' && fm2) {
- return fm2.addMonitorText.call(fm2, selectData);
- }
- };
- export const deviceDetailCard = () => {
- if (fmType === 'fm1') {
- return fm1.deviceDetailCard.call(fm1);
- } else {
- // return fm2.addMonitorText.call(fm2);
- }
- };
- export const play = (handlerState, flag?) => {
- if (fmType === 'fm1' && fm1) {
- return fm1.play.call(fm1, handlerState, flag);
- } else if (fmType === 'fm2' && fm2) {
- return fm2.play.call(fm2, handlerState, flag);
- }
- };
- // 切换风门类型
- export const setModelType = (type) => {
- fmType = type;
- return new Promise((resolve) => {
- // 暂停风门1动画
- fm1.clipActionArr.frontDoor.reset();
- fm1.clipActionArr.frontDoor.time = 0.5;
- fm1.clipActionArr.backDoor.reset();
- fm1.clipActionArr.backDoor.time = 0.5;
- fm1.clipActionArr.frontDoor.stop();
- fm1.clipActionArr.backDoor.stop();
- if (fmType === 'fm1' && fm1 && fm1.group) {
- model.startAnimation = fm1.render.bind(fm1);
- group = fm1.group;
- group.rotation.y = 0;
- if (model.scene.getObjectByName('fm2')) {
- model.scene.remove(fm2.group);
- }
- const oldCameraPosition = { x: -1000, y: 100, z: 500 };
- setTimeout(async () => {
- resolve(null);
- model.scene.add(fm1.group);
- await animateCamera(
- oldCameraPosition,
- { x: 0, y: 0, z: 0 },
- { x: 50.99, y: 69.32, z: 93.61 },
- { x: -10.04, y: -14.38, z: -31.4 },
- model,
- 0.8
- );
- }, 300);
- } else if (fmType === 'fm2' && fm2 && fm2.group) {
- fm2.clipActionArr.frontDoor.reset();
- fm2.clipActionArr.frontDoor.time = 0.5;
- fm2.clipActionArr.backDoor.reset();
- fm2.clipActionArr.backDoor.time = 0.5;
- fm2.clipActionArr.centerDoor.reset();
- fm2.clipActionArr.centerDoor.time = 0.5;
- fm2.clipActionArr.frontDoor.stop();
- fm2.clipActionArr.backDoor.stop();
- fm2.clipActionArr.centerDoor.stop();
- // 显示单道风窗
- model.startAnimation = fm2.render.bind(fm2);
- group = fm2.group;
- if (model.scene.getObjectByName('fm1')) {
- model.scene.remove(fm1.group);
- }
- const oldCameraPosition = { x: -761, y: 569, z: 871 };
- setTimeout(async () => {
- resolve(null);
- model.scene.add(fm2.group);
- const position = { x: -2.28, y: -0.91, z: -5.68 };
- await animateCamera(
- oldCameraPosition,
- { x: -2.27, y: -0.91, z: -5.67 },
- { x: 66.257, y: 57.539, z: 94.313 },
- { x: position.x, y: position.y, z: position.z },
- model,
- 0.6
- );
- }, 300);
- }
- });
- };
- export const mountedThree = (playerVal1, playerVal2) => {
- 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);
- // 单道、 双道
- fm1 = new Fm1(model, playerVal1, playerVal2);
- await fm1.mountedThree();
- fm2 = new Fm2(model, playerVal1);
- await fm2.mountedThree();
- model.animate();
- resolve(null);
- startAnimation();
- });
- };
- export const destroy = () => {
- if (model) {
- model.isRender = false;
- console.log('场景销毁前信息----------->', model.renderer?.info);
- if (fm1) fm1.destroy();
- if (fm2) fm2.destroy();
- fm1 = null;
- fm2 = null;
- group = null;
- model.mixers = [];
- model.destroy();
- }
- model = null;
- };
|