123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355 |
- import * as THREE from 'three';
- import { getTextCanvas, renderVideo } from '/@/utils/threejs/util';
- import gsap from 'gsap';
- class lmWindRect {
- model;
- modelName = 'lmcf';
- group: THREE.Group | null = null;
- animationTimer;
- isLRAnimation = true;
- direction = 1;
- player1;
- player2;
- playerStartClickTime1 = new Date().getTime();
- playerStartClickTime2 = new Date().getTime();
- constructor(model, playerVal1, playerVal2) {
- this.model = model;
- this.player1 = playerVal1;
- this.player2 = playerVal2;
- }
- addLight() {
- const pointLight2 = new THREE.PointLight(0xffeeee, 1, 0);
- pointLight2.position.set(317, 41, -21);
- pointLight2.shadow.bias = 0.05;
- this.model.add(pointLight2);
- //
- const pointLight3 = new THREE.PointLight(0xffffff, 1, 138);
- pointLight3.position.set(-202, 50, 27.8);
- pointLight3.shadow.bias = 0.05;
- this.model.add(pointLight3);
- //
- const pointLight4 = new THREE.PointLight(0xffeeee, 1, 162);
- pointLight4.position.set(83, 62, -14);
- pointLight4.shadow.bias = 0.05;
- this.model.add(pointLight4);
- //
- const pointLight5 = new THREE.PointLight(0xffffff, 0.8, 176);
- pointLight5.position.set(-123, 61.6, -18);
- pointLight5.shadow.bias = 0.05;
- this.model.add(pointLight5);
- //
- const pointLight6 = new THREE.PointLight(0xffffff, 1.5, 64);
- pointLight6.position.set(-76, 48, 18);
- pointLight6.shadow.bias = 0.05;
- this.model.add(pointLight6);
- const pointLight7 = new THREE.PointLight(0xffffff, 1, 302);
- pointLight7.position.set(-220, -177, -3.5);
- pointLight7.shadow.bias = -0.05;
- this.model.add(pointLight7);
- const spotLight = new THREE.SpotLight();
- spotLight.angle = Math.PI / 16;
- spotLight.penumbra = 0;
- spotLight.castShadow = true;
- spotLight.distance = 0;
- spotLight.position.set(-470, -500, 500);
- this.model.add(spotLight);
- spotLight.shadow.camera.near = 0.5; // default
- spotLight.shadow.camera.far = 1000; // default
- spotLight.shadow.focus = 1;
- spotLight.shadow.bias = -0.000002;
- }
- // 设置模型位置
- setModalPosition() {
- this.group?.scale.set(22, 22, 22);
- this.group?.position.set(-25, 25, 15);
- }
- addFmText(selectData) {
- if (!this.group) {
- return;
- }
- const textArr = [
- {
- text: `煤矿巷道远程风窗系统`,
- font: 'normal 2.2rem Arial',
- color: '#009900',
- strokeStyle: '#002200',
- x: 90,
- y: 95,
- },
- {
- text: `过风量(m3/min):`,
- font: 'normal 30px Arial',
- color: '#009900',
- strokeStyle: '#002200',
- x: 5,
- y: 115,
- },
- {
- text: `${
- selectData.frontRearDifference && selectData.rearPresentValue
- ? Math.min(selectData.frontRearDifference, selectData.rearPresentValue)
- : selectData.frontRearDifference || selectData.rearPresentValue || '-'
- }`,
- font: 'normal 30px Arial',
- color: '#009900',
- strokeStyle: '#002200',
- x: 235,
- y: 115,
- },
- {
- text: `过风面积(m2): `,
- font: 'normal 30px Arial',
- color: '#009900',
- strokeStyle: '#002200',
- x: 5,
- y: 182,
- },
- {
- text: `${
- selectData.forntArea && selectData.rearArea
- ? Math.min(selectData.forntArea, selectData.rearArea)
- : selectData.forntArea || selectData.rearArea || '-'
- }`,
- font: 'normal 30px Arial',
- color: '#009900',
- strokeStyle: '#002200',
- x: 200,
- y: 182,
- },
- {
- text: `风窗压差(Pa):`,
- font: 'normal 30px Arial',
- color: '#009900',
- strokeStyle: '#002200',
- x: 5,
- y: 245,
- },
- {
- text: `${selectData.dataDh}`,
- font: 'normal 30px Arial',
- color: '#009900',
- strokeStyle: '#002200',
- x: 200,
- y: 245,
- },
- {
- text: `调节精度:`,
- font: 'normal 30px Arial',
- color: '#009900',
- strokeStyle: '#002200',
- x: 320,
- y: 115,
- },
- {
- text: `1% FS`,
- font: 'normal 30px Arial',
- color: '#009900',
- strokeStyle: '#002200',
- x: 460,
- y: 115,
- },
- {
- text: `调节范围:`,
- font: 'normal 30px Arial',
- color: '#009900',
- strokeStyle: '#002200',
- x: 320,
- y: 182,
- },
- {
- text: `${selectData.maxarea}`,
- font: 'normal 30px Arial',
- color: '#009900',
- strokeStyle: '#002200',
- x: 460,
- y: 182,
- },
- {
- text: `煤炭科学技术研究院有限公司研制`,
- font: 'normal 28px Arial',
- color: '#009900',
- strokeStyle: '#002200',
- x: 60,
- y: 302,
- },
- ];
- 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 = this.group?.getObjectByName('monitorText');
- if (monitorPlane) {
- monitorPlane.material = textMaterial;
- } else {
- const planeGeometry = new THREE.PlaneGeometry(560, 346); // 平面3维几何体PlaneGeometry
- const planeMesh = new THREE.Mesh(planeGeometry, textMaterial);
- planeMesh.name = 'monitorText';
- planeMesh.scale.set(0.0022, 0.0022, 0.0022);
- planeMesh.position.set(3.25, -0.002, -0.41);
- this.group?.add(planeMesh);
- }
- });
- }
- /* 风门动画 */
- render() {
- if (!this.model) {
- return;
- }
- if (this.isLRAnimation && this.group) {
- // 左右摇摆动画
- if (Math.abs(this.group.rotation.y) >= 0.2) {
- this.direction = -this.direction;
- this.group.rotation.y += 0.00005 * 30 * this.direction;
- } else {
- this.group.rotation.y += 0.00005 * 30 * this.direction;
- }
- }
- }
- /* 提取风门序列帧,初始化前后门动画 */
- initAnimation() {
- const windGroup = new THREE.Group();
- windGroup.name = 'lmTanTou';
- this.group?.children.forEach((obj) => {
- if (obj.type === 'Mesh' && obj.name && obj.name.startsWith('LMtantou')) {
- if (obj.name.startsWith('LMtantou')) {
- windGroup.add(obj.clone());
- this.group?.remove(obj);
- }
- }
- });
- this.group?.add(windGroup);
- }
- /* 点击风窗,风窗全屏 */
- mousedownModel(intersects: THREE.Intersection<THREE.Object3D<THREE.Event>>[]) {
- this.isLRAnimation = false;
- if (this.animationTimer) {
- clearTimeout(this.animationTimer);
- this.animationTimer = null;
- }
- // 判断是否点击到视频
- intersects.find((intersect) => {
- const mesh = intersect.object;
- if (mesh.name === 'player1') {
- if (new Date().getTime() - this.playerStartClickTime1 < 400) {
- // 双击,视频放大
- if (this.player1) {
- this.player1.requestFullscreen();
- }
- }
- this.playerStartClickTime1 = new Date().getTime();
- return true;
- } else if (mesh.name === 'player2') {
- if (new Date().getTime() - this.playerStartClickTime2 < 400) {
- // 双击,视频放大
- if (this.player2) {
- this.player2.requestFullscreen();
- }
- }
- this.playerStartClickTime2 = new Date().getTime();
- return true;
- }
- return false;
- });
- }
- mouseUpModel() {
- // 10s后开始摆动
- if (!this.animationTimer && !this.isLRAnimation) {
- this.animationTimer = setTimeout(() => {
- this.isLRAnimation = true;
- }, 10000);
- }
- }
- resetModel() {
- clearTimeout(this.animationTimer);
- this.isLRAnimation = false;
- }
- // 播放动画
- play(flag) {
- const cfTanTou = this.group?.getObjectByName('lmTanTou') as THREE.Group;
- if (!cfTanTou) return;
- switch (flag) {
- case 'up':
- gsap.to(cfTanTou['position'], {
- y: 0,
- duration: Math.abs(cfTanTou['position']['y'] - 0) / 14,
- ease: 'easeQutQuad',
- overwrite: true,
- });
- break;
- case 'center':
- gsap.to(cfTanTou['position'], {
- y: -7,
- duration: Math.abs(cfTanTou['position']['y'] + 7) / 14,
- ease: 'easeQutQuad',
- overwrite: true,
- });
- break;
- case 'down':
- gsap.to(cfTanTou['position'], {
- y: -14,
- duration: Math.abs(cfTanTou['position']['y'] + 14) / 14,
- ease: 'easeQutCubic',
- overwrite: true,
- });
- break;
- }
- }
- mountedThree() {
- return new Promise((resolve) => {
- this.model.setModel(this.modelName).then((gltf) => {
- this.group = gltf.scene;
- this.setModalPosition();
- this.initAnimation();
- setTimeout(async () => {
- const videoPlayer1 = document.getElementById('cf-player1')?.getElementsByClassName('vjs-tech')[0];
- // const videoPlayer2 = document.getElementById('cf-player2')?.getElementsByClassName('vjs-tech')[0];
- if (videoPlayer1) {
- const mesh = renderVideo(this.group, videoPlayer1, 'player1');
- mesh?.scale.set(0.042, 0.036, 0.022);
- mesh?.position.set(-2.74, 0.03, -0.39);
- this.group?.add(mesh as THREE.Mesh);
- }
- // if (videoPlayer2) {
- // const mesh = renderVideo(this.group, videoPlayer2, 'player2');
- // mesh?.scale.set(0.0385, 0.028, 0.022);
- // mesh?.position.set(-86.77, 0.405, -9.62);
- // this.group?.add(mesh as THREE.Mesh);
- // }
- resolve(null);
- }, 0);
- });
- });
- }
- destroy() {
- if (this.group) {
- this.model.clearGroup(this.group);
- }
- this.model = null;
- this.group = null;
- }
- }
- export default lmWindRect;
|