|
@@ -1,735 +1,193 @@
|
|
|
import * as THREE from 'three';
|
|
|
-
|
|
|
-import { CSS3DObject } from 'three/examples/jsm/renderers/CSS3DRenderer.js';
|
|
|
-import { CSS2DObject } from 'three/examples/jsm/renderers/CSS2DRenderer.js';
|
|
|
-import { getTextCanvas, renderVideo, transScreenCoord } from '/@/utils/threejs/util';
|
|
|
import UseThree from '../../../../utils/threejs/useThree';
|
|
|
+import Fm1 from './gate.threejs.three';
|
|
|
import { animateCamera } from '/@/utils/threejs/util';
|
|
|
-import { flyLine } from '/@/views/vent/comment/threejs/FlyLine';
|
|
|
-import { createComposer } from '/@/views/vent/comment/threejs/bloomPass';
|
|
|
-import * as dat from 'dat.gui';
|
|
|
-import { drawHot } from '/@/utils/threejs/util';
|
|
|
-import { useAppStore } from '/@/store/modules/app';
|
|
|
-
|
|
|
-// const gui = new dat.GUI();
|
|
|
-// gui.domElement.style = 'position:absolute;top:10px;right:10px;z-index:99999999999999';
|
|
|
+import useEvent from '../../../../utils/threejs/useEvent';
|
|
|
|
|
|
-const modelName = 'fm';
|
|
|
// 模型对象、 文字对象
|
|
|
-let model, //
|
|
|
+let model,
|
|
|
+ fm1,
|
|
|
+ fm2,
|
|
|
group,
|
|
|
- fmCSS3D, //文字
|
|
|
- isLRAnimation = true, // 是否开启左右摇摆动画
|
|
|
- direction = 1, // 摇摆方向
|
|
|
- animationtimer: NodeJS.Timeout | null, // 摇摆开启定时器
|
|
|
- renderBloomPass,
|
|
|
- player1,
|
|
|
- player2,
|
|
|
- deviceDetailCSS3D,
|
|
|
- playerStartClickTime1 = new Date().getTime(),
|
|
|
- playerStartClickTime2 = new Date().getTime();
|
|
|
-
|
|
|
-const frontClock = new THREE.Clock();
|
|
|
-const backClock = new THREE.Clock();
|
|
|
+ fmType = '';
|
|
|
|
|
|
-const appStore = useAppStore();
|
|
|
-
|
|
|
-const clipActionArr = {
|
|
|
- frontDoor: null as unknown as THREE.AnimationAction,
|
|
|
- backDoor: null as unknown as THREE.AnimationAction,
|
|
|
-};
|
|
|
+const { mouseDownFn } = useEvent();
|
|
|
|
|
|
// 打灯光
|
|
|
-function addLight(scene) {
|
|
|
- const pointLight2 = new THREE.PointLight(0xffeeee, 0.8, 300);
|
|
|
- pointLight2.position.set(-113, 29, 10);
|
|
|
- // light2.castShadow = true
|
|
|
- pointLight2.shadow.bias = -0.05;
|
|
|
- scene.add(pointLight2);
|
|
|
- // const pointLightHelper2 = new THREE.PointLightHelper( pointLight2, 1 );
|
|
|
- // scene.add( pointLightHelper2 );
|
|
|
-
|
|
|
- const pointLight3 = new THREE.PointLight(0xffffff, 0.8, 100);
|
|
|
- pointLight3.position.set(0, 30, 3);
|
|
|
- // light2.castShadow = true
|
|
|
- pointLight3.shadow.bias = -0.05;
|
|
|
- scene.add(pointLight3);
|
|
|
- // const pointLightHelper = new THREE.PointLightHelper( pointLight3, 1 );
|
|
|
- // scene.add( pointLightHelper );
|
|
|
-
|
|
|
- const pointLight4 = new THREE.PointLight(0xffeeee, 0.6, 100);
|
|
|
- pointLight4.position.set(-14, 29, 13);
|
|
|
- // light2.castShadow = true
|
|
|
- pointLight4.shadow.bias = -0.05;
|
|
|
- scene.add(pointLight4);
|
|
|
- // const pointLightHelper4 = new THREE.PointLightHelper( pointLight4, 1 );
|
|
|
- // scene.add( pointLightHelper4 );
|
|
|
-
|
|
|
- const pointLight5 = new THREE.PointLight(0xffffff, 0.8, 100);
|
|
|
- pointLight5.position.set(80, 43, -5.3);
|
|
|
- // light2.castShadow = true
|
|
|
- pointLight5.shadow.bias = -0.05;
|
|
|
- scene.add(pointLight5);
|
|
|
- // const pointLightHelper5 = new THREE.PointLightHelper( pointLight5, 1 );
|
|
|
- // scene.add( pointLightHelper5 );
|
|
|
-
|
|
|
- const pointLight6 = new THREE.PointLight(0xffffff, 1, 300);
|
|
|
- // pointLight6.position.set(-47, 49, 12.9)
|
|
|
- pointLight6.position.set(-7, 40, 9);
|
|
|
- // light2.castShadow = true
|
|
|
- pointLight6.shadow.bias = -0.05;
|
|
|
- scene.add(pointLight6);
|
|
|
- // const pointLightHelper6 = new THREE.PointLightHelper( pointLight6, 1 );
|
|
|
- // scene.add( pointLightHelper6 );
|
|
|
-
|
|
|
- const pointLight7 = new THREE.PointLight(0xffffff, 0.8, 300);
|
|
|
+const addLight = () => {
|
|
|
+ const pointLight2 = new THREE.PointLight(0xffeeee, 1, 83);
|
|
|
+ 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(-61, 37, 13.9);
|
|
|
+ pointLight3.shadow.bias = 0.05;
|
|
|
+ model.scene.add(pointLight3);
|
|
|
+
|
|
|
+ const pointLight4 = new THREE.PointLight(0xffeeee, 0.6, 300);
|
|
|
+ pointLight4.position.set(-2, 26, 20);
|
|
|
+ pointLight4.shadow.bias = 0.05;
|
|
|
+ model.scene.add(pointLight4);
|
|
|
+
|
|
|
+ const pointLight5 = new THREE.PointLight(0xffffff, 0.8, 120);
|
|
|
+ pointLight5.position.set(-54, 30, 23.8);
|
|
|
+ pointLight5.shadow.bias = 0.05;
|
|
|
+ model.scene.add(pointLight5);
|
|
|
+
|
|
|
+ const pointLight7 = new THREE.PointLight(0xffffff, 1, 1000);
|
|
|
pointLight7.position.set(45, 51, -4.1);
|
|
|
- // light2.castShadow = true
|
|
|
- pointLight7.shadow.bias = -0.05;
|
|
|
- scene.add(pointLight7);
|
|
|
- // const pointLightHelper7 = new THREE.PointLightHelper( pointLight7, 1 );
|
|
|
- // scene.add( pointLightHelper7 );
|
|
|
-
|
|
|
- // const directionalLight = new THREE.DirectionalLight(0xffffff, 0.5);
|
|
|
- // directionalLight.target = group;
|
|
|
- // directionalLight.position.set(-18, 20, 39);
|
|
|
- // directionalLight.rotation.set(1.3, 0.3, 5.8);
|
|
|
- // scene.add(directionalLight);
|
|
|
- // const helper = new THREE.DirectionalLightHelper(directionalLight, 5);
|
|
|
- // scene.add(helper);
|
|
|
+ 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.castShadow = true;
|
|
|
+ spotLight.intensity = 1;
|
|
|
spotLight.position.set(-231, 463, 687);
|
|
|
- scene.add(spotLight);
|
|
|
+ model.scene.add(spotLight);
|
|
|
|
|
|
- // spotLight.shadow.mapSize.width = 1500; // default
|
|
|
- // spotLight.shadow.mapSize.height = 800; // default
|
|
|
spotLight.shadow.camera.near = 0.5; // default
|
|
|
spotLight.shadow.camera.far = 1000; // default
|
|
|
spotLight.shadow.focus = 1.2;
|
|
|
spotLight.shadow.bias = -0.000002;
|
|
|
-
|
|
|
- // const spotLightHelper = new THREE.SpotLightHelper(spotLight);
|
|
|
- // scene.add(spotLightHelper);
|
|
|
-
|
|
|
- // model.canvasContainer?.appendChild(gui.domElement);
|
|
|
- // gui.add(directionalLight.position, 'x', -100, 100).step(1);
|
|
|
- // gui.add(directionalLight.position, 'y', -100, 100).step(1);
|
|
|
- // gui.add(directionalLight.position, 'z', -100, 100).step(1);
|
|
|
- // gui.add(directionalLight.rotation, 'x', -Math.PI, 2 * Math.PI).step(0.1);
|
|
|
- // gui.add(directionalLight.rotation, 'y', -Math.PI, 2 * Math.PI).step(0.1);
|
|
|
- // gui.add(directionalLight.rotation, 'z', -Math.PI, 2 * Math.PI).step(0.1);
|
|
|
- // gui.add(spotLight, 'angle', 0, Math.PI / 2);
|
|
|
- // gui.add(spotLight, 'distance', 0, 1000);
|
|
|
- // gui.add(pointLight6.position, 'x', -200, 200)
|
|
|
- // gui.add(pointLight6.position, 'y', -200, 200)
|
|
|
- // gui.add(pointLight6.position, 'z', -200, 200)
|
|
|
-}
|
|
|
-
|
|
|
-// 重置摄像头
|
|
|
-function resetCamera() {
|
|
|
- model.camera.far = 274;
|
|
|
- model.orbitControls?.update();
|
|
|
- model.camera.updateProjectionMatrix();
|
|
|
-}
|
|
|
-
|
|
|
-// 设置模型位置
|
|
|
-function setModalPosition() {
|
|
|
- group?.scale.set(22, 22, 22);
|
|
|
- group?.position.set(-20, 20, 9);
|
|
|
-}
|
|
|
-
|
|
|
-/* 添加监控数据 */
|
|
|
-export function addFmText(selectData) {
|
|
|
- if (!group) {
|
|
|
- return;
|
|
|
- }
|
|
|
- const textArr = [
|
|
|
- {
|
|
|
- text: `远程控制自动风门`,
|
|
|
- font: 'normal 30px Arial',
|
|
|
- color: '#00FF00',
|
|
|
- strokeStyle: '#007400',
|
|
|
- x: 120,
|
|
|
- y: 100,
|
|
|
- },
|
|
|
- {
|
|
|
- text: `压力(Pa):`,
|
|
|
- font: 'normal 30px Arial',
|
|
|
- color: '#00FF00',
|
|
|
- strokeStyle: '#007400',
|
|
|
- x: 0,
|
|
|
- y: 155,
|
|
|
- },
|
|
|
- {
|
|
|
- text: `${selectData.frontRearDP}`,
|
|
|
- font: 'normal 30px Arial',
|
|
|
- color: '#00FF00',
|
|
|
- strokeStyle: '#007400',
|
|
|
- x: 290,
|
|
|
- y: 155,
|
|
|
- },
|
|
|
- {
|
|
|
- text: `动力源压力(MPa): `,
|
|
|
- font: 'normal 30px Arial',
|
|
|
- color: '#00FF00',
|
|
|
- strokeStyle: '#007400',
|
|
|
- x: 0,
|
|
|
- y: 215,
|
|
|
- },
|
|
|
- {
|
|
|
- text: ` ${selectData.sourcePressure}`,
|
|
|
- font: 'normal 30px Arial',
|
|
|
- color: '#00FF00',
|
|
|
- strokeStyle: '#007400',
|
|
|
- x: 280,
|
|
|
- y: 215,
|
|
|
- },
|
|
|
- {
|
|
|
- text: `故障诊断:`,
|
|
|
- font: 'normal 30px Arial',
|
|
|
- color: '#00FF00',
|
|
|
- strokeStyle: '#007400',
|
|
|
- x: 0,
|
|
|
- y: 275,
|
|
|
- },
|
|
|
- {
|
|
|
- text: `${selectData.fault}`,
|
|
|
- font: 'normal 30px Arial',
|
|
|
- color: '#00FF00',
|
|
|
- strokeStyle: '#007400',
|
|
|
- x: 280,
|
|
|
- y: 275,
|
|
|
- },
|
|
|
- {
|
|
|
- text: `煤炭科学技术研究院有限公司研制`,
|
|
|
- font: 'normal 28px Arial',
|
|
|
- color: '#00FF00',
|
|
|
- strokeStyle: '#007400',
|
|
|
- x: 20,
|
|
|
- y: 325,
|
|
|
- },
|
|
|
- ];
|
|
|
-
|
|
|
- //
|
|
|
- getTextCanvas(526, 346, textArr, '').then((canvas: HTMLCanvasElement) => {
|
|
|
- const textMap = new THREE.CanvasTexture(canvas); // 关键一步
|
|
|
- textMap.encoding = THREE.sRGBEncoding;
|
|
|
- const textMaterial = new THREE.MeshBasicMaterial({
|
|
|
- // 关于材质并未讲解 实操即可熟悉 这里是漫反射类似纸张的材质,对应的就有高光类似金属的材质.
|
|
|
- map: textMap, // 设置纹理贴图
|
|
|
- transparent: true,
|
|
|
- side: THREE.FrontSide, // 这里是双面渲染的意思
|
|
|
- });
|
|
|
- textMaterial.blending = THREE.CustomBlending;
|
|
|
- const monitorPlane = group.getObjectByName('monitorText');
|
|
|
- if (monitorPlane) {
|
|
|
- monitorPlane.material = textMaterial;
|
|
|
- } else {
|
|
|
- const planeGeometry = new THREE.PlaneGeometry(526, 346); // 平面3维几何体PlaneGeometry
|
|
|
- const planeMesh = new THREE.Mesh(planeGeometry, textMaterial);
|
|
|
- planeMesh.name = 'monitorText';
|
|
|
- planeMesh.scale.set(0.002, 0.002, 0.002);
|
|
|
- planeMesh.position.set(-1.255, 0.09, -0.41);
|
|
|
- group.add(planeMesh);
|
|
|
- }
|
|
|
- });
|
|
|
-}
|
|
|
-
|
|
|
-/** 添加热点 */
|
|
|
-function drawHots() {
|
|
|
- const hotPositions = [
|
|
|
- { x: -0.37, y: 0.26, z: -0.32 },
|
|
|
- { x: 0.28, y: -0.2, z: -0.43 },
|
|
|
- { x: 0.55, y: -0.22, z: -0.38 },
|
|
|
- ];
|
|
|
- for (let i = 0; i < 3; i++) {
|
|
|
- const hotPoint = drawHot(0.1);
|
|
|
- const position = hotPositions[i];
|
|
|
- // hotPoint.scale.set(0.3, 0.3, 0.3);
|
|
|
- hotPoint.position.set(position.x, position.y, position.z);
|
|
|
- hotPoint.name = 'hotPoint' + i;
|
|
|
- group?.add(hotPoint);
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-/* 漫游路线 */
|
|
|
-function createLine() {
|
|
|
- const position = model.camera.position.clone();
|
|
|
- //创建样条曲线,作为运动轨迹
|
|
|
- const curve = new THREE.CatmullRomCurve3([
|
|
|
- new THREE.Vector3(position.x, position.y, position.z),
|
|
|
- new THREE.Vector3(26.586, 17.86, 14.144),
|
|
|
- new THREE.Vector3(-0.075, 19.669, 15.051),
|
|
|
- new THREE.Vector3(-154.882, 17.462, 14.981),
|
|
|
- // new THREE.Vector3(76, 28, 27),
|
|
|
- ]);
|
|
|
- const geometry = new THREE.BufferGeometry().setFromPoints(curve.getPoints(5000));
|
|
|
- // 材质对象
|
|
|
- const material = new THREE.LineBasicMaterial({
|
|
|
- color: 'red',
|
|
|
- });
|
|
|
- // 线条模型对象
|
|
|
- const line = new THREE.Line(geometry, material);
|
|
|
- // model?.scene.add(line) // 线条对象添加到场景中
|
|
|
- return curve;
|
|
|
-}
|
|
|
-
|
|
|
-/* 开启漫游 */
|
|
|
-function enterMY() {
|
|
|
- model.startAnimation = () => {};
|
|
|
- model.camera.position.set(114.27, 15.293, 14.189);
|
|
|
- model.camera.rotation.set(-86.23, 69.89, 85.98);
|
|
|
- const curve = createLine();
|
|
|
- let progress = 0;
|
|
|
-
|
|
|
- model.startMY = () => {
|
|
|
- if (progress <= 1 - 0.004 * 20) {
|
|
|
- const point = curve.getPointAt(progress); //获取样条曲线指定点坐标,作为相机的位置
|
|
|
- const pointBox = curve.getPointAt(progress + 0.004 * 20); //获取样条曲线指定点坐标
|
|
|
- model.camera.position.set(point.x, point.y, point.z);
|
|
|
- model.camera.lookAt(pointBox.x + 5, pointBox.y, pointBox.z);
|
|
|
- // model.orbitControls.position0.set(point.x, point.y, point.z) //非必要,场景有控件时才加上
|
|
|
- // model.orbitControls.target.set(pointBox.x, pointBox.y , pointBox.z) //非必要,场景有控件时才加上
|
|
|
- progress += 0.004;
|
|
|
- } else {
|
|
|
- // progress = 0
|
|
|
- model.camera.position.set(30.328, 58.993, 148.315);
|
|
|
- model.camera.rotation.set(-27.88, 14.35, 7.47);
|
|
|
- model.camera.lookAt(0, 0, 0);
|
|
|
- model.startMY = () => {};
|
|
|
- model.startAnimation = fmAnimation.bind(null);
|
|
|
- }
|
|
|
- };
|
|
|
-}
|
|
|
-
|
|
|
-/* 风门动画 */
|
|
|
-
|
|
|
-function render() {
|
|
|
- if (!model) {
|
|
|
- return;
|
|
|
- }
|
|
|
- if (isLRAnimation && group) {
|
|
|
- // 左右摇摆动画
|
|
|
- if (Math.abs(group.rotation.y) >= 0.2) {
|
|
|
- direction = -direction;
|
|
|
- group.rotation.y += 0.00002 * 30 * direction;
|
|
|
- } else {
|
|
|
- group.rotation.y += 0.00002 * 30 * direction;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // // //自发光
|
|
|
- // const screen = group.getObjectByName('对象156');
|
|
|
- // if (screen) {
|
|
|
- // model.renderer.clearDepth();
|
|
|
- // screen.layers.enable(31);
|
|
|
- // !!renderBloomPass && renderBloomPass(group);
|
|
|
- // }
|
|
|
-
|
|
|
- // 风门开关动画
|
|
|
- const frontDelta = frontClock?.getElapsedTime() + 0.5;
|
|
|
- const backDelta = backClock?.getElapsedTime() + 0.5;
|
|
|
- if (model.mixers[0]) model.mixers[0]?.update(frontDelta); //前门
|
|
|
- if (model.mixers[1]) model.mixers[1]?.update(backDelta); // 后门
|
|
|
-}
|
|
|
-
|
|
|
-// 鼠标点击、松开事件
|
|
|
-function mouseEvent(event) {
|
|
|
- const widthScale = appStore.getWidthScale;
|
|
|
- const heightScale = appStore.getHeightScale;
|
|
|
- // debugger;
|
|
|
- event.stopPropagation();
|
|
|
- // 将鼠标位置归一化为设备坐标。x 和 y 方向的取值范围是 (-1 to +1)
|
|
|
- model.mouse.x =
|
|
|
- ((-model.canvasContainer.getBoundingClientRect().left * widthScale + event.clientX) / (model.canvasContainer.clientWidth * widthScale)) * 2 - 1;
|
|
|
- model.mouse.y =
|
|
|
- -((-model.canvasContainer.getBoundingClientRect().top + event.clientY) / (model.canvasContainer.clientHeight * heightScale)) * 2 + 1;
|
|
|
- (model.rayCaster as THREE.Raycaster).setFromCamera(model.mouse, model.camera as THREE.Camera);
|
|
|
- // 计算物体和射线的焦点
|
|
|
- const FmWall = group.getObjectByName('Fm-wall');
|
|
|
- const intersects = model.rayCaster?.intersectObjects([...group.children, ...(FmWall?.children || [])], false) as THREE.Intersection[];
|
|
|
- if (intersects.length > 0) {
|
|
|
- isLRAnimation = false;
|
|
|
- if (animationtimer) {
|
|
|
- clearTimeout(animationtimer);
|
|
|
- animationtimer = null;
|
|
|
- }
|
|
|
- if (model.camera.layers.mask == -1) model.camera.layers.toggle(1);
|
|
|
- // 判断是否点击到视频
|
|
|
- intersects.find((intersect) => {
|
|
|
- const mesh = intersect.object;
|
|
|
- // deviceDetailCSS3D?.layers.set(1);
|
|
|
- if (mesh.name === 'player1') {
|
|
|
- if (new Date().getTime() - playerStartClickTime1 < 400) {
|
|
|
- // model.orbitControls?.dispatchEvent.call(model.orbitControls, { type: 'end' })
|
|
|
- // 双击,视频放大
|
|
|
- if (player1) {
|
|
|
- player1.requestFullscreen();
|
|
|
- }
|
|
|
- }
|
|
|
- playerStartClickTime1 = new Date().getTime();
|
|
|
- return true;
|
|
|
- } else if (mesh.name === 'player2') {
|
|
|
- if (new Date().getTime() - playerStartClickTime2 < 400) {
|
|
|
- // model.orbitControls?.dispatchEvent.call(model.orbitControls, { type: 'end' })
|
|
|
- // 双击,视频放大
|
|
|
- if (player2) {
|
|
|
- player2.requestFullscreen();
|
|
|
- }
|
|
|
- }
|
|
|
- playerStartClickTime2 = new Date().getTime();
|
|
|
- return true;
|
|
|
- } else if (mesh.name.startsWith('hotPoint')) {
|
|
|
- if (deviceDetailCSS3D) {
|
|
|
- // document.getElementById('deviceCard') as HTMLElement;
|
|
|
- deviceDetailCSS3D.position.set(intersect.point.x, intersect.point.y + 18, intersect.point.z);
|
|
|
- console.log('[ deviceDetailCSS3D.position ] >', deviceDetailCSS3D.position);
|
|
|
- // deviceDetailCSS3D?.layers.set(0);
|
|
|
- model.camera.layers.enableAll();
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
- // let position = new THREE.Vector3(mesh.position.x, mesh.position.y, 0.5);
|
|
|
- // position = position.applyMatrix4(group.matrixWorld);
|
|
|
- // model.scene.updateMatrixWorld(true);
|
|
|
- // // let worldPosition = new THREE.Vector3();
|
|
|
- // // let worldScale = new THREE.Vector3();
|
|
|
- // // worldPosition = mesh.getWorldPosition(worldPosition);
|
|
|
- // // worldScale = mesh.getWorldScale(worldScale);
|
|
|
- // const devicePosition = transScreenCoord(intersect.point, model.camera);
|
|
|
- // element.style.left = devicePosition.x + 'px';
|
|
|
- // element.style.top = devicePosition.y + 'px';
|
|
|
- // console.log('[ point 坐标位置 ] >', devicePosition, mesh.position);
|
|
|
- } else {
|
|
|
- // deviceDetailCSS3D?.layers.set(1);
|
|
|
-
|
|
|
- console.log('[ 点击事件 ] >');
|
|
|
- }
|
|
|
-
|
|
|
- return false;
|
|
|
- });
|
|
|
- }
|
|
|
-}
|
|
|
+};
|
|
|
|
|
|
// 初始化左右摇摆动画
|
|
|
-function startAnimation() {
|
|
|
- // 开启动画
|
|
|
- model.startAnimation = render.bind(null);
|
|
|
- // 定义鼠标点击事件x
|
|
|
+const startAnimation = () => {
|
|
|
+ // 定义鼠标点击事件
|
|
|
model.canvasContainer?.addEventListener('mousedown', mouseEvent.bind(null));
|
|
|
model.canvasContainer?.addEventListener('pointerup', (event) => {
|
|
|
event.stopPropagation();
|
|
|
- // 10s后开始摆动
|
|
|
- if (!animationtimer && !isLRAnimation) {
|
|
|
- animationtimer = setTimeout(() => {
|
|
|
- isLRAnimation = true;
|
|
|
- }, 10000);
|
|
|
+ // 单道、 双道
|
|
|
+ if (fmType === 'fm1') {
|
|
|
+ fm1.mouseUpModel.call(fm1);
|
|
|
+ } else if (fmType === 'fm2') {
|
|
|
+ // fm2.mouseUpModel.call(fm2);
|
|
|
}
|
|
|
});
|
|
|
-}
|
|
|
+};
|
|
|
|
|
|
-/* 提取风门序列帧,初始化前后门动画 */
|
|
|
-function initAnimation() {
|
|
|
- const fmGroup = group?.getObjectByName('Fm-door');
|
|
|
- if (fmGroup) {
|
|
|
- const tracks = fmGroup.animations[0].tracks;
|
|
|
- const fontTracks: any[] = [],
|
|
|
- backTracks: any[] = [];
|
|
|
- for (let i = 0; i < tracks.length; i++) {
|
|
|
- const track = tracks[i];
|
|
|
- if (track.name.startsWith('qianmen')) {
|
|
|
- fontTracks.push(track);
|
|
|
- } else if (track.name.startsWith('houmen')) {
|
|
|
- backTracks.push(track);
|
|
|
- }
|
|
|
+// 鼠标点击、松开事件
|
|
|
+const mouseEvent = (event) => {
|
|
|
+ mouseDownFn(model, group, event, (intersects) => {
|
|
|
+ if (fmType === 'fm1') {
|
|
|
+ fm1.mousedownModel.call(fm1, intersects);
|
|
|
+ } else if (fmType === 'fm2') {
|
|
|
+ // fm2.mousedownModel.call(fm2, intersects);
|
|
|
}
|
|
|
- const frontDoor = new THREE.AnimationClip('frontDoor', 4, fontTracks);
|
|
|
- const frontMixer = new THREE.AnimationMixer(fmGroup);
|
|
|
- model.mixers.push(frontMixer);
|
|
|
- const frontClipAction = frontMixer.clipAction(frontDoor, fmGroup);
|
|
|
- frontClipAction.clampWhenFinished = true;
|
|
|
- frontClipAction.loop = THREE.LoopOnce;
|
|
|
- clipActionArr.frontDoor = frontClipAction;
|
|
|
+ });
|
|
|
+ console.log('摄像头控制信息', model.orbitControls, model.camera);
|
|
|
+};
|
|
|
|
|
|
- const backDoor = new THREE.AnimationClip('backDoor', 4, backTracks);
|
|
|
- const backMixer = new THREE.AnimationMixer(fmGroup);
|
|
|
- model.mixers.push(backMixer);
|
|
|
- const backClipAction = backMixer.clipAction(backDoor, fmGroup);
|
|
|
- backClipAction.clampWhenFinished = true;
|
|
|
- backClipAction.loop = THREE.LoopOnce;
|
|
|
- clipActionArr.backDoor = backClipAction;
|
|
|
+export const addFmText = (selectData) => {
|
|
|
+ if (fmType === 'fm1') {
|
|
|
+ return fm1.addFmText.call(fm1, selectData);
|
|
|
+ } else {
|
|
|
+ // return fm2.addFmText.call(fm2, selectData);
|
|
|
}
|
|
|
-}
|
|
|
-
|
|
|
-export function deviceDetailCard(position = { x: 0, y: 0, z: 0 }) {
|
|
|
- const element = document.getElementById('deviceCard') as HTMLElement;
|
|
|
- deviceDetailCSS3D = new CSS2DObject(element);
|
|
|
- deviceDetailCSS3D.name = 'deviceCard';
|
|
|
- deviceDetailCSS3D.position.set(position.x, position.y, position.z);
|
|
|
- deviceDetailCSS3D?.layers.set(1);
|
|
|
- // group.add(deviceDetailCSS3D);
|
|
|
- model.scene.add(deviceDetailCSS3D);
|
|
|
-}
|
|
|
-// 播放动画
|
|
|
-export function play(handlerState, timeScale = 0.01) {
|
|
|
- debugger;
|
|
|
- let handler = () => {};
|
|
|
- switch (handlerState) {
|
|
|
- case 1: // 打开前门
|
|
|
- handler = () => {
|
|
|
- debugger;
|
|
|
- clipActionArr.frontDoor.paused = true;
|
|
|
- clipActionArr.frontDoor.reset();
|
|
|
- clipActionArr.frontDoor.time = 1.2;
|
|
|
- clipActionArr.frontDoor.timeScale = timeScale;
|
|
|
- clipActionArr.frontDoor.clampWhenFinished = true;
|
|
|
- clipActionArr.frontDoor.play();
|
|
|
- frontClock.start();
|
|
|
- };
|
|
|
- break;
|
|
|
- case 2: // 关闭前门
|
|
|
- handler = () => {
|
|
|
- debugger;
|
|
|
- clipActionArr.frontDoor.paused = true;
|
|
|
- clipActionArr.frontDoor.reset(); //
|
|
|
- clipActionArr.frontDoor.time = 4;
|
|
|
- clipActionArr.frontDoor.timeScale = -timeScale;
|
|
|
- clipActionArr.frontDoor.clampWhenFinished = true;
|
|
|
- clipActionArr.frontDoor.play();
|
|
|
- frontClock.start();
|
|
|
- };
|
|
|
- break;
|
|
|
- case 3: // 打开后门
|
|
|
- handler = () => {
|
|
|
- debugger;
|
|
|
- clipActionArr.backDoor.paused = true;
|
|
|
- clipActionArr.backDoor.reset();
|
|
|
- clipActionArr.backDoor.time = 1.2;
|
|
|
- clipActionArr.backDoor.timeScale = timeScale;
|
|
|
- clipActionArr.backDoor.clampWhenFinished = true;
|
|
|
- clipActionArr.backDoor.play();
|
|
|
- backClock.start();
|
|
|
- };
|
|
|
- break;
|
|
|
- case 4: // 关闭后门
|
|
|
- handler = () => {
|
|
|
- debugger;
|
|
|
- clipActionArr.backDoor.paused = true;
|
|
|
- clipActionArr.backDoor.reset();
|
|
|
- clipActionArr.backDoor.time = 4;
|
|
|
- clipActionArr.backDoor.timeScale = -timeScale;
|
|
|
- clipActionArr.backDoor.clampWhenFinished = true;
|
|
|
- clipActionArr.backDoor.play();
|
|
|
- backClock.start();
|
|
|
- };
|
|
|
- break;
|
|
|
- case 5: // 打开前后门
|
|
|
- handler = () => {
|
|
|
- debugger;
|
|
|
- clipActionArr.backDoor.paused = true;
|
|
|
- clipActionArr.frontDoor.paused = true;
|
|
|
-
|
|
|
- clipActionArr.frontDoor.reset();
|
|
|
- clipActionArr.frontDoor.time = 0;
|
|
|
- clipActionArr.frontDoor.timeScale = 0.01;
|
|
|
- clipActionArr.frontDoor.clampWhenFinished = true;
|
|
|
- clipActionArr.frontDoor.play();
|
|
|
-
|
|
|
- clipActionArr.backDoor.reset();
|
|
|
- clipActionArr.backDoor.time = 0;
|
|
|
- clipActionArr.backDoor.timeScale = 0.01;
|
|
|
- clipActionArr.backDoor.clampWhenFinished = true;
|
|
|
- clipActionArr.backDoor.play();
|
|
|
- frontClock.start();
|
|
|
- backClock.start();
|
|
|
- };
|
|
|
- break;
|
|
|
- case 6: // 关闭前后门
|
|
|
- handler = () => {
|
|
|
- debugger;
|
|
|
- clipActionArr.backDoor.paused = true;
|
|
|
- clipActionArr.frontDoor.paused = true;
|
|
|
+};
|
|
|
|
|
|
- clipActionArr.frontDoor.reset();
|
|
|
- clipActionArr.frontDoor.time = 4;
|
|
|
- clipActionArr.frontDoor.timeScale = -0.01;
|
|
|
- clipActionArr.frontDoor.clampWhenFinished = true;
|
|
|
- clipActionArr.frontDoor.play();
|
|
|
- clipActionArr.backDoor.reset();
|
|
|
- clipActionArr.backDoor.time = 4;
|
|
|
- clipActionArr.backDoor.timeScale = -0.01;
|
|
|
- clipActionArr.backDoor.clampWhenFinished = true;
|
|
|
- clipActionArr.backDoor.play();
|
|
|
- frontClock.start();
|
|
|
- backClock.start();
|
|
|
- };
|
|
|
- break;
|
|
|
- default:
|
|
|
+export const deviceDetailCard = () => {
|
|
|
+ if (fmType === 'fm1') {
|
|
|
+ return fm1.deviceDetailCard.call(fm1);
|
|
|
+ } else {
|
|
|
+ // return fm2.addFmText.call(fm2);
|
|
|
}
|
|
|
+};
|
|
|
|
|
|
- handler();
|
|
|
- // model.clock.start();
|
|
|
- // const honglvdeng = group.getObjectByName('honglvdeng');
|
|
|
- // const material = honglvdeng.material;
|
|
|
- // setTimeout(() => {
|
|
|
- // if (handlerState === 2 || handlerState === 4 || handlerState === 6) {
|
|
|
- // material.color = new THREE.Color(0x00ff00);
|
|
|
- // } else {
|
|
|
- // material.color = new THREE.Color(0xff0000);
|
|
|
- // }
|
|
|
- // }, 1000);
|
|
|
-}
|
|
|
+export const play = (rotationParam, flag) => {
|
|
|
+ if (fmType === 'fm1') {
|
|
|
+ return fm1.play.call(fm1, rotationParam, flag);
|
|
|
+ } else {
|
|
|
+ // return fm2.play.call(fm2, rotationParam, flag);
|
|
|
+ }
|
|
|
+};
|
|
|
|
|
|
-// 初始化门的开关状态
|
|
|
-export function initOpenState(selectData) {
|
|
|
- if (!group) return;
|
|
|
- model.camera.position.set(-1000, 100, 500);
|
|
|
- group.rotation.y = 0;
|
|
|
- return new Promise(async (resolve) => {
|
|
|
- const oldCameraPosition = { x: -1000, y: 100, z: 500 };
|
|
|
- await animateCamera(oldCameraPosition, oldCameraPosition, { x: 46.257, y: 57.539, z: 94.313 }, { x: -50, y: 0, z: 0 }, model, 0.8);
|
|
|
- resolve(null);
|
|
|
- if (!selectData) {
|
|
|
- return;
|
|
|
+// 切换风门类型
|
|
|
+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') {
|
|
|
+ model.startAnimation = fm1.render.bind(fm1);
|
|
|
+ group = fm1.group;
|
|
|
+ group.rotation.y = 0;
|
|
|
+ if (model.scene.getObjectByName('fm')) {
|
|
|
+ model.scene.remove(fm2.group);
|
|
|
+ }
|
|
|
+ const oldCameraPosition = { x: -1000, y: 100, z: 500 };
|
|
|
+ model.scene.add(fm1.group);
|
|
|
+ setTimeout(async () => {
|
|
|
+ resolve(null);
|
|
|
+ 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') {
|
|
|
+ // 显示单道风窗
|
|
|
+ // model.startAnimation = fm2.render.bind(fm2);
|
|
|
+ // group = fm2.group;
|
|
|
+ // if (model.scene.getObjectByName('fm2')) {
|
|
|
+ // model.scene.remove(fm1.group);
|
|
|
+ // }
|
|
|
+ // const oldCameraPosition = { x: 100, y: 0, z: 500 };
|
|
|
+ // model.scene.add(fm2.group);
|
|
|
+ // setTimeout(async () => {
|
|
|
+ // resolve(null);
|
|
|
+ // const position = { x: 0, y: 0, z: 0 };
|
|
|
+ // await animateCamera(
|
|
|
+ // oldCameraPosition,
|
|
|
+ // { x: 0, y: 0, z: 0 },
|
|
|
+ // { x: 66.257, y: 57.539, z: 94.313 },
|
|
|
+ // { x: position.x, y: position.y, z: position.z },
|
|
|
+ // model
|
|
|
+ // );
|
|
|
+ // }, 300);
|
|
|
}
|
|
|
- clipActionArr.frontDoor.reset();
|
|
|
- clipActionArr.frontDoor.time = 0.5;
|
|
|
-
|
|
|
- clipActionArr.backDoor.reset();
|
|
|
- clipActionArr.backDoor.time = 0.5;
|
|
|
-
|
|
|
- clipActionArr.frontDoor.stop();
|
|
|
- clipActionArr.backDoor.stop();
|
|
|
-
|
|
|
- // frontClock.stop();
|
|
|
- // backClock.stop();
|
|
|
});
|
|
|
-}
|
|
|
+};
|
|
|
|
|
|
-export function mountedThree(playerVal1, playerVal2) {
|
|
|
- group = new THREE.Object3D();
|
|
|
- group.name = modelName;
|
|
|
- return new Promise((resolve) => {
|
|
|
+export const mountedThree = (playerVal1, playerVal2) => {
|
|
|
+ return new Promise(async (resolve) => {
|
|
|
model = new UseThree('#damper3D', '', '#deviceDetail');
|
|
|
-
|
|
|
model.setEnvMap('test1');
|
|
|
- model.renderer.toneMappingExposure = 1;
|
|
|
- model.scene?.add(group);
|
|
|
- group?.layers.enableAll();
|
|
|
- const bb = new Date().getTime();
|
|
|
-
|
|
|
- model.setGLTFModel(['Fm-door', 'Fm-wire', 'Fm-wall'], group).then(() => {
|
|
|
- setModalPosition();
|
|
|
- // 初始化左右摇摆动画;
|
|
|
- // startAnimation();
|
|
|
- initAnimation();
|
|
|
- drawHots();
|
|
|
-
|
|
|
- // deviceDetailCard();
|
|
|
- // model.camera.position.set(-1000, 100, 500);
|
|
|
- addLight(model.scene);
|
|
|
- startAnimation();
|
|
|
- model.animate();
|
|
|
- if (model.camera.layers.mask == -1) model.camera.layers.toggle(1);
|
|
|
- setTimeout(async () => {
|
|
|
- player1 = playerVal1;
|
|
|
- player2 = playerVal2;
|
|
|
- const videoPlayer1 = document.getElementById('fm-player1')?.getElementsByClassName('vjs-tech')[0];
|
|
|
- const videoPlayer2 = document.getElementById('fm-player2')?.getElementsByClassName('vjs-tech')[0];
|
|
|
- if (!videoPlayer1 || !videoPlayer2) {
|
|
|
- const textArr = [
|
|
|
- {
|
|
|
- text: `无信号输入`,
|
|
|
- font: 'normal 40px Arial',
|
|
|
- color: '#009900',
|
|
|
- strokeStyle: '#002200',
|
|
|
- x: 170,
|
|
|
- y: 40,
|
|
|
- },
|
|
|
- ];
|
|
|
- getTextCanvas(560, 346, textArr, '').then((canvas: HTMLCanvasElement) => {
|
|
|
- const textMap = new THREE.CanvasTexture(canvas); // 关键一步
|
|
|
- const textMaterial = new THREE.MeshBasicMaterial({
|
|
|
- map: textMap, // 设置纹理贴图
|
|
|
- transparent: true,
|
|
|
- side: THREE.DoubleSide, // 这里是双面渲染的意思
|
|
|
- });
|
|
|
- textMaterial.blending = THREE.CustomBlending;
|
|
|
- const monitorPlane = group?.getObjectByName('noPlayer');
|
|
|
- if (monitorPlane) {
|
|
|
- monitorPlane.material = textMaterial;
|
|
|
- } else {
|
|
|
- const planeGeometry = new THREE.PlaneGeometry(100, 100); // 平面3维几何体PlaneGeometry
|
|
|
- const planeMesh = new THREE.Mesh(planeGeometry, textMaterial);
|
|
|
- if (!videoPlayer1) {
|
|
|
- planeMesh.name = 'noPlayer1';
|
|
|
- planeMesh.scale.set(0.011, 0.008, 0.011);
|
|
|
- planeMesh.position.set(-4.23, -0.28, -0.39);
|
|
|
- group?.add(planeMesh.clone());
|
|
|
- }
|
|
|
- if (!videoPlayer2) {
|
|
|
- planeMesh.name = 'noPlayer2';
|
|
|
- planeMesh.scale.set(0.012, 0.009, 0.012);
|
|
|
- planeMesh.position.set(4.33, -0.33, -0.39);
|
|
|
- group?.add(planeMesh.clone());
|
|
|
- }
|
|
|
- textMaterial.dispose();
|
|
|
- planeGeometry.dispose();
|
|
|
- }
|
|
|
- });
|
|
|
- } else {
|
|
|
- if (videoPlayer2) {
|
|
|
- const mesh = renderVideo(group, videoPlayer1, 'player1');
|
|
|
- mesh?.scale.set(-0.028, 0.0285, 1);
|
|
|
- mesh?.position.set(4.298, 0.02, -0.4);
|
|
|
- mesh.rotation.y = -Math.PI;
|
|
|
- group.add(mesh);
|
|
|
- }
|
|
|
- if (videoPlayer1) {
|
|
|
- const mesh = renderVideo(group, videoPlayer2, 'player2');
|
|
|
- mesh?.scale.set(-0.028, 0.0285, 1);
|
|
|
- mesh?.position.set(-4.262, 0.02, -0.4);
|
|
|
- mesh.rotation.y = -Math.PI;
|
|
|
- group.add(mesh);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- resolve(model);
|
|
|
- }, 0);
|
|
|
- console.log('模型加载到渲染完成所用时间--------------->', new Date().getTime() - bb);
|
|
|
- });
|
|
|
+ model.renderer.toneMappingExposure = 0.9;
|
|
|
+ model.camera.position.set(100, 0, 1000);
|
|
|
+ // 单道、 双道
|
|
|
+ fm1 = new Fm1(model, playerVal1, playerVal2);
|
|
|
+ // fm2 = new singleWindow(model, playerVal1);
|
|
|
+ await fm1.mountedThree();
|
|
|
+ // await singleWindowObj.mountedThree();
|
|
|
+
|
|
|
+ model.animate();
|
|
|
+ resolve(null);
|
|
|
+ addLight();
|
|
|
+ startAnimation();
|
|
|
});
|
|
|
-}
|
|
|
+};
|
|
|
|
|
|
-export function destroy() {
|
|
|
+export const destroy = () => {
|
|
|
if (model) {
|
|
|
- if (model.mixers[0]) {
|
|
|
- model.mixers[0].uncacheClip(clipActionArr.frontDoor.getClip());
|
|
|
- model.mixers[0].uncacheClip(clipActionArr.backDoor.getClip());
|
|
|
- model.mixers[0].uncacheAction(clipActionArr.frontDoor, group);
|
|
|
- model.mixers[0].uncacheAction(clipActionArr.backDoor, group);
|
|
|
- model.mixers[0].uncacheRoot(group);
|
|
|
-
|
|
|
- model.mixers[1].uncacheClip(clipActionArr.frontDoor.getClip());
|
|
|
- model.mixers[1].uncacheClip(clipActionArr.backDoor.getClip());
|
|
|
- model.mixers[1].uncacheAction(clipActionArr.frontDoor, group);
|
|
|
- model.mixers[1].uncacheAction(clipActionArr.backDoor, group);
|
|
|
- model.mixers[1].uncacheRoot(group);
|
|
|
-
|
|
|
- if (model.animations[0]) model.animations[0].tracks = [];
|
|
|
- }
|
|
|
-
|
|
|
- clipActionArr.backDoor = undefined;
|
|
|
- clipActionArr.frontDoor = undefined;
|
|
|
-
|
|
|
- model.mixers = [];
|
|
|
+ fm1.destroy();
|
|
|
+ // fm2.destroy();
|
|
|
model.deleteModal();
|
|
|
model = null;
|
|
|
group = null;
|
|
|
- // document.getElementById('damper3D').parentElement.remove(document.getElementById('damper3D'))
|
|
|
+ fm1 = null;
|
|
|
+ fm2 = null;
|
|
|
}
|
|
|
};
|