| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- import UseThree from '../../../../utils/threejs/useThree';
- import balancePressBase from './balancePress.threejs.base';
- import balancePressTun from './balancePress.threejs.tun';
- import balancePressSp from './balancePress.threejs.sp';
- import { animateCamera } from '/@/utils/threejs/util';
- import useEvent from '../../../../utils/threejs/useEvent';
- import * as THREE from 'three';
- // 模型对象、 文字对象
- let model: UseThree,
- balancePressBaseObj: balancePressBase | undefined,
- balancePressTunObj: balancePressTun | undefined,
- balancePressSpObj: balancePressSp | undefined,
- group: THREE.Object3D | undefined,
- balancePressType = 'balancePressBase'; // workerFaceFiber
- const { mouseDownFn, mousemoveFn, mouseUpFn } = useEvent();
- // 鼠标点击事件
- const mouseEvent = (event) => {
- if (event.button == 0) {
- model.canvasContainer?.addEventListener('mousemove', mousemove);
- mouseDownFn(model, group as THREE.Object3D, event, (intersects) => {
- if (balancePressType === 'balancePressType') {
- // balancePressBaseObj.mousedownModel.call(balancePressBaseObj, model.rayCaster);
- }
- });
- }
- };
- const mouseUp = () => {
- if (!model) return;
- mouseUpFn(model, 1);
- model.canvasContainer?.removeEventListener('mousemove', mousemove);
- };
- const mousemove = () => {
- mousemoveFn();
- };
- const addMouseEvent = () => {
- // 定义鼠标点击事件
- model.canvasContainer?.addEventListener('mousedown', mouseEvent.bind(null));
- model.canvasContainer?.addEventListener('pointerup', mouseUp);
- };
- export const play = (controlType, deviceType, frequency, state, duration?) => {
- if (balancePressType === 'balancePressBase') {
- return balancePressBaseObj?.playSmoke.call(balancePressBaseObj, controlType, deviceType, frequency, state, duration);
- }
- };
- export const updateText = (selectData) => {
- if (balancePressType === 'balancePressBase') {
- return balancePressBaseObj?.addText.call(balancePressBaseObj, selectData);
- }
- };
- // 切换模型类型
- export const setModelType = (type) => {
- debugger;
- balancePressType = type;
- return new Promise((resolve) => {
- if (balancePressType === 'balancePressBase' && balancePressBaseObj && balancePressBaseObj.group) {
- group = balancePressBaseObj.group;
- if (group) {
- const oldCameraPosition = { x: 27.9165, y: 17.3763, z: 51.3388 };
- setTimeout(async () => {
- model.scene.add(balancePressBaseObj?.group);
- await animateCamera(
- oldCameraPosition,
- { x: 3.9025, y: 0.7782, z: 6.6307 },
- { x: 0.1218, y: 3.8213, z: 17.27671 },
- { x: 0.2348, y: 0.7182, z: 6.8413 },
- model,
- 0.8
- );
- }, 300);
- }
- resolve(null);
- } else if (balancePressType === 'balancePressTun' && balancePressTunObj && balancePressTunObj.group) {
- group = balancePressTunObj.group;
- if (group) {
- const oldCameraPosition = { x: 27.9165, y: 17.3763, z: 51.3388 };
- setTimeout(async () => {
- model.scene.add(balancePressTunObj?.group);
- await animateCamera(
- oldCameraPosition,
- { x: 3.9025, y: 0.7782, z: 6.6307 },
- { x: 0.2185637607064918, y: 2.476256183591406, z: 2.7017622865334987 },
- { x: 0.21856376070649214, y: 0.09479035032624854, z: 0.7165903260342672 },
- model,
- 1
- );
- }, 300);
- }
- resolve(null);
- } else if (balancePressType === 'balancePressSp' && balancePressSpObj && balancePressSpObj.group) {
- group = balancePressSpObj.group;
- if (group) {
- setTimeout(async () => {
- model.scene.add(balancePressSpObj?.group);
- await animateCamera(
- { x: 27.9165, y: 17.3763, z: 51.3388 },
- { x: 3.9025, y: 0.7782, z: 6.6307 },
- { x: 0.1275, y: 2.4409, z: 1.627 },
- { x: 0.1275, y: 0.3118, z: 0.3478 },
- model,
- 1
- );
- }, 300);
- }
- resolve(null);
- }
- });
- };
- export const mountedThree = () => {
- return new Promise(async (resolve) => {
- model = new UseThree('#balancePress3D');
- model.setEnvMap('test1.hdr');
- model.renderer.toneMappingExposure = 1.0;
- balancePressBaseObj = new balancePressBase(model);
- await balancePressBaseObj.mountedThree();
- balancePressTunObj = new balancePressTun(model);
- await balancePressTunObj.mountedThree();
- balancePressSpObj = new balancePressSp(model);
- await balancePressSpObj.mountedThree();
- addMouseEvent();
- model.animate();
- resolve(null);
- });
- };
- export const destroy = () => {
- if (model) {
- model.isRender = false;
- console.log('场景销毁前信息----------->', model.renderer?.info);
- balancePressBaseObj?.destroy();
- balancePressBaseObj = undefined;
- balancePressTunObj?.destroy();
- balancePressTunObj = undefined;
- balancePressSpObj?.destroy();
- balancePressSpObj = undefined;
- group = undefined;
- model.destroy();
- model = undefined;
- }
- };
|