import * as THREE from 'three'; import UseThree from '../../../../utils/threejs/useThree'; import singleWindow from './dandaoFc.threejs'; import doubleWindow from './shuangdaoFc.threejs'; import { animateCamera } from '/@/utils/threejs/util'; import useEvent from '../../../../utils/threejs/useEvent'; // import * as dat from 'dat.gui'; // const gui = new dat.GUI(); // gui.domElement.style = 'position:absolute;top:100px;left:10px;z-index:99999999999999'; // 模型对象、 文字对象 let model: UseThree, singleWindowObj: singleWindow, doubleWindowObj: doubleWindow, group: THREE.Object3D, windowType = 'singleWindow'; const { mouseDownFn } = useEvent(); // 打灯光 const addLight = () => { if (!model || !model.scene) return; const directionalLight = new THREE.DirectionalLight(0xffffff, 1); directionalLight.position.set(-110, 150, 647); model.scene?.add(directionalLight); // directionalLight.target = group; const pointLight2 = new THREE.PointLight(0xffffff, 1, 150); pointLight2.position.set(-101, 34, 16); pointLight2.shadow.bias = 0.05; model.scene.add(pointLight2); const pointLight3 = new THREE.PointLight(0xffffff, 1, 150); pointLight3.position.set(19, 25, -7); pointLight3.shadow.bias = 0.05; model.scene.add(pointLight3); const pointLight6 = new THREE.PointLight(0xffffff, 1, 300); pointLight6.position.set(51, 51, 9); pointLight6.shadow.bias = 0.05; model.scene.add(pointLight6); // const pointLight7 = new THREE.PointLight(0xffffff, 1, 1000); // pointLight7.position.set(45, 51, -4.1); // pointLight7.shadow.bias = 0.05; // model.scene.add(pointLight7); // const spotLight = new THREE.SpotLight(); // spotLight.angle = Math.PI / 16; // spotLight.penumbra = 0; // spotLight.castShadow = true; // spotLight.intensity = 1; // spotLight.position.set(-231, 463, 687); // model.scene.add(spotLight); // spotLight.shadow.camera.near = 0.5; // default // spotLight.shadow.camera.far = 1000; // default // spotLight.shadow.focus = 1.2; // spotLight.shadow.bias = -0.000002; // gui.add(directionalLight.position, 'x', -1000, 1000); // gui.add(directionalLight.position, 'y', -1000, 1000); // gui.add(directionalLight.position, 'z', -1000, 1000); }; // // 重置摄像头 // const resetCamera = () => { // model.camera.position.set(30.328, 58.993, 148.315); // model.camera.rotation.set(-31.85, 30.07, 17.29); // model.orbitControls?.update(); // model.camera.updateProjectionMatrix(); // }; // 初始化左右摇摆动画 const startAnimation = () => { // 定义鼠标点击事件 model.canvasContainer?.addEventListener('mousedown', mouseEvent.bind(null)); model.canvasContainer?.addEventListener('pointerup', (event) => { event.stopPropagation(); // 单道、 双道 if (windowType === 'doubleWindow' && doubleWindowObj) { doubleWindowObj.mouseUpModel.call(doubleWindowObj); } else if (windowType === 'singleWindow' && singleWindowObj) { singleWindowObj.mouseUpModel.call(singleWindowObj); } }); }; // 鼠标点击、松开事件 const mouseEvent = (event) => { if (event.button == 0) { mouseDownFn(model, group, event, (intersects) => { if (windowType === 'doubleWindow' && doubleWindowObj) { doubleWindowObj.mousedownModel.call(doubleWindowObj, intersects); } else if (windowType === 'singleWindow' && singleWindowObj) { singleWindowObj.mousedownModel.call(singleWindowObj, intersects); } }); } }; export const addMonitorText = (selectData) => { if (windowType === 'doubleWindow' && doubleWindowObj) { return doubleWindowObj.addMonitorText.call(doubleWindowObj, selectData); } else if (windowType === 'singleWindow' && singleWindowObj) { return singleWindowObj.addMonitorText.call(singleWindowObj, selectData); } }; export const play = (rotationParam, flag) => { if (windowType === 'doubleWindow' && doubleWindowObj) { return doubleWindowObj.play.call(doubleWindowObj, rotationParam, flag); } else if (windowType === 'singleWindow' && singleWindowObj) { return singleWindowObj.play.call(singleWindowObj, rotationParam, flag); } }; export const initCameraCanvas = async (playerVal1?, playerVal2?) => { debugger if (windowType === 'singleWindow' && singleWindowObj) { return await singleWindowObj.initCamera.call(singleWindowObj, playerVal1); } else if (windowType === 'doubleWindow' && doubleWindowObj) { return doubleWindowObj.initCamera.call(doubleWindowObj, playerVal1); } }; // 切换风窗类型 export const setModelType = (type) => { // if (!model || !model.scene) return; windowType = type; return new Promise((resolve) => { // 显示双道风窗 if (windowType === 'doubleWindow' && doubleWindowObj && doubleWindowObj.group) { model.startAnimation = doubleWindowObj.render.bind(doubleWindowObj); group = doubleWindowObj.group; if (model.scene?.getObjectByName('ddFc')) { model.scene.remove(singleWindowObj.group); } const oldCameraPosition = { x: 100, y: 0, z: 500 }; model.scene?.add(doubleWindowObj.group); setTimeout(async () => { resolve(null); await animateCamera(oldCameraPosition, { x: 0, y: 0, z: 0 }, { x: 66.257, y: 57.539, z: 94.313 }, { x: 0, y: 0, z: 0 }, model); }, 300); } else if (windowType === 'singleWindow') { // 显示单道风窗 model.startAnimation = singleWindowObj.render.bind(singleWindowObj); group = singleWindowObj.group; if (model.scene?.getObjectByName('sdFc')) { model.scene?.remove(doubleWindowObj.group); } const oldCameraPosition = { x: 100, y: 0, z: 500 }; model.scene?.add(singleWindowObj.group); setTimeout(async () => { resolve(null); await animateCamera(oldCameraPosition, { x: 0, y: 0, z: 0 }, { x: 66.257, y: 57.539, z: 94.313 }, { x: 0, y: 0, z: 0 }, model); }, 300); } }); }; export const mountedThree = () => { return new Promise(async (resolve) => { model = new UseThree('#window3D'); if (!model || !model.renderer || !model.camera) return; model.setEnvMap('test1'); model.camera.position.set(100, 0, 1000); // 单道、 双道 doubleWindowObj = new doubleWindow(model); singleWindowObj = new singleWindow(model); await doubleWindowObj.mountedThree(); await singleWindowObj.mountedThree(); model.animate(); resolve(null); addLight(); startAnimation(); }); }; export const destroy = () => { if (model) { model.isRender = false; console.log('场景销毁前信息----------->', model.renderer?.info); model.isRender = false; doubleWindowObj.destroy(); singleWindowObj.destroy(); model.destroy(); model = null; group = null; singleWindowObj = null; doubleWindowObj = null; } };