123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291 |
- import * as THREE from 'three';
- import { CSS2DObject } from 'three/examples/jsm/renderers/CSS2DRenderer.js';
- import { getTextCanvas, renderVideo } from '/@/utils/threejs/util';
- import { drawHot } from '/@/utils/threejs/util';
- import { useAppStore } from '/@/store/modules/app';
- // import * as dat from 'dat.gui';
- // const gui = new dat.GUI();
- // gui.domElement.style = 'position:absolute;top:100px;left:10px;z-index:99999999999999';
- class FmSp1 {
- modelName = 'fmSp1';
- model; //
- group;
- isLRAnimation = true; // 是否开启左右摇摆动画
- direction = 1; // 摇摆方向
- animationTimer: NodeJS.Timeout | null = null; // 摇摆开启定时器
- player1;
- player2;
- deviceDetailCSS3D;
- playerStartClickTime1 = new Date().getTime();
- playerStartClickTime2 = new Date().getTime();
- fmClock = new THREE.Clock();
- mixers: THREE.AnimationMixer | undefined;
- appStore = useAppStore();
- backDamperOpenMesh;
- backDamperClosedMesh;
- frontDamperOpenMesh;
- frontDamperClosedMesh;
- clipActionArr = {
- frontDoor: null as unknown as THREE.AnimationAction,
- backDoor: null as unknown as THREE.AnimationAction,
- };
- constructor(model) {
- this.model = model;
- }
- addLight() {
- const directionalLight = new THREE.DirectionalLight(0xffffff, 1.5);
- directionalLight.position.set(344, 690, 344);
- this.group?.add(directionalLight);
- directionalLight.target = this.group as THREE.Object3D;
- const pointLight2 = new THREE.PointLight(0xffeeee, 1, 300);
- pointLight2.position.set(-4, 10, 1.8);
- pointLight2.shadow.bias = 0.05;
- this.group?.add(pointLight2);
- const pointLight3 = new THREE.PointLight(0xffeeee, 1, 200);
- pointLight3.position.set(-0.5, -0.5, 0.75);
- pointLight3.shadow.bias = 0.05;
- this.group?.add(pointLight3);
- }
- // 重置摄像头
- resetCamera() {
- this.model.camera.far = 274;
- this.model.orbitControls?.update();
- this.model.camera.updateProjectionMatrix();
- }
- // 设置模型位置
- setModalPosition() {
- this.group?.scale.set(22, 22, 22);
- this.group?.position.set(-20, 20, 9);
- }
- /* 添加监控数据 */
- addMonitorText(selectData) {
- if (!this.group) {
- return;
- }
- const screenDownText = VENT_PARAM['modalText']
- ? VENT_PARAM['modalText']
- : History_Type['type'] == 'remote'
- ? `国能神东煤炭集团监制`
- : '煤炭科学技术研究院有限公司研制';
- const screenDownTextX = 90 - (screenDownText.length - 11) * 6;
- const textArr = [
- {
- text: `远程控制自动风门`,
- font: 'normal 30px Arial',
- color: '#00FF00',
- strokeStyle: '#007400',
- x: 120,
- y: 100,
- },
- {
- text: `净通行高度(m):`,
- font: 'normal 30px Arial',
- color: '#00FF00',
- strokeStyle: '#007400',
- x: 0,
- y: 155,
- },
- {
- text: `${selectData.fclearheight ? selectData.fclearheight : '-'}`,
- font: 'normal 30px Arial',
- color: '#00FF00',
- strokeStyle: '#007400',
- x: 330,
- y: 155,
- },
- {
- text: `净通行宽度(m): `,
- font: 'normal 30px Arial',
- color: '#00FF00',
- strokeStyle: '#007400',
- x: 0,
- y: 215,
- },
- {
- text: ` ${selectData.fclearwidth ? selectData.fclearwidth : '-'}`,
- font: 'normal 30px Arial',
- color: '#00FF00',
- strokeStyle: '#007400',
- x: 320,
- y: 215,
- },
- {
- text: `故障诊断:`,
- font: 'normal 30px Arial',
- color: '#00FF00',
- strokeStyle: '#007400',
- x: 0,
- y: 275,
- },
- {
- text: `${selectData.warnLevel_str ? selectData.warnLevel_str : '-'}`,
- font: 'normal 30px Arial',
- color: '#00FF00',
- strokeStyle: '#007400',
- x: 320,
- y: 275,
- },
- {
- text: screenDownText,
- font: 'normal 28px Arial',
- color: '#00FF00',
- strokeStyle: '#007400',
- x: screenDownTextX,
- y: 325,
- },
- ];
- //
- getTextCanvas(526, 346, textArr, '').then((canvas: HTMLCanvasElement) => {
- const textMap = new THREE.CanvasTexture(canvas); // 关键一步
- textMap.colorSpace = THREE.SRGBColorSpace;
- const textMaterial = new THREE.MeshBasicMaterial({
- // 关于材质并未讲解 实操即可熟悉 这里是漫反射类似纸张的材质,对应的就有高光类似金属的材质.
- map: textMap, // 设置纹理贴图
- transparent: true,
- side: THREE.FrontSide, // 这里是双面渲染的意思
- });
- textMaterial.blending = THREE.CustomBlending;
- const monitorPlane = this.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(3.995, 0.67, -0.27);
- this.group.add(planeMesh);
- }
- textMap.dispose();
- });
- }
- /* 风门动画 */
- render() {
- if (!this.model) {
- return;
- }
- if (this.mixers && this.fmClock.running) {
- this.mixers.update(2);
- }
- }
- mouseUpModel() {}
- /* 提取风门序列帧,初始化前后门动画 */
- initAnimation() {
- debugger;
- const fmSp1 = this.group.getObjectByName('FengMen_SiShanLing').getObjectByName('men1');
- const tracks = this.group.animations[0].tracks;
- const fontTracks: any[] = [];
- for (let i = 0; i < tracks.length; i++) {
- const track = tracks[i];
- fontTracks.push(track);
- }
- this.mixers = new THREE.AnimationMixer(fmSp1);
- const frontDoor = new THREE.AnimationClip('frontDoor', 22, fontTracks);
- const frontClipAction = this.mixers.clipAction(frontDoor, fmSp1);
- frontClipAction.clampWhenFinished = true;
- frontClipAction.loop = THREE.LoopOnce;
- this.clipActionArr.frontDoor = frontClipAction;
- }
- // 播放动画
- play(handlerState, timeScale = 0.05) {
- if (this.clipActionArr.frontDoor) {
- let handler = () => {};
- switch (handlerState) {
- case 1: // 打开前门
- handler = () => {
- this.clipActionArr.frontDoor.paused = true;
- this.clipActionArr.frontDoor.reset();
- this.clipActionArr.frontDoor.time = 0;
- this.clipActionArr.frontDoor.timeScale = timeScale;
- // this.clipActionArr.frontDoor.clampWhenFinished = true;
- this.clipActionArr.frontDoor.play();
- this.fmClock.start();
- // 显示打开前门文字
- if (this.frontDamperOpenMesh) this.frontDamperOpenMesh.visible = true;
- if (this.frontDamperClosedMesh) this.frontDamperClosedMesh.visible = false;
- };
- break;
- case 2: // 关闭前门
- handler = () => {
- this.clipActionArr.frontDoor.paused = true;
- this.clipActionArr.frontDoor.reset(); //
- this.clipActionArr.frontDoor.time = 1.5;
- this.clipActionArr.frontDoor.timeScale = -timeScale;
- // this.clipActionArr.frontDoor.clampWhenFinished = true;
- this.clipActionArr.frontDoor.play();
- this.fmClock.start();
- if (this.frontDamperOpenMesh) this.frontDamperOpenMesh.visible = false;
- if (this.frontDamperClosedMesh) this.frontDamperClosedMesh.visible = true;
- };
- break;
- default:
- }
- handler();
- }
- }
- mountedThree(playerDom) {
- this.group = new THREE.Object3D();
- this.group.name = this.modelName;
- return new Promise((resolve) => {
- if (!this.model) {
- resolve(null);
- }
- this.model.setGLTFModel('fmSp1').then((gltf) => {
- this.group = gltf[0];
- this.group.name = 'fmSp1';
- console.log('fmSp1', this.group);
- this.setModalPosition();
- this.initAnimation();
- this.addLight();
- this.model.animate();
- resolve(this.model);
- });
- });
- }
- destroy() {
- if (this.model) {
- if (this.mixers) {
- this.mixers.uncacheClip(this.clipActionArr.frontDoor.getClip());
- this.mixers.uncacheClip(this.clipActionArr.backDoor.getClip());
- this.mixers.uncacheAction(this.clipActionArr.frontDoor.getClip(), this.group);
- this.mixers.uncacheAction(this.clipActionArr.backDoor.getClip(), this.group);
- this.mixers.uncacheRoot(this.group);
- if (this.model.animations[0]) this.model.animations[0].tracks = [];
- }
- this.model.clearGroup(this.group);
- this.clipActionArr.backDoor = undefined;
- this.clipActionArr.frontDoor = undefined;
- this.mixers = undefined;
- // document.getElementById('damper3D').parentElement.remove(document.getElementById('damper3D'))
- }
- }
- }
- export default FmSp1;
|