123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215 |
- import * as THREE from 'three';
- import { getTextCanvas, renderVideo } from '/@/utils/threejs/util';
- import gsap from 'gsap';
- // import * as dat from 'dat.gui';
- // const gui = new dat.GUI();
- // gui.domElement.style = 'position:absolute;top:100px;left:10px;z-index:99999999999999';
- class ddWindRect {
- model;
- modelName = 'ddcf';
- group: THREE.Object3D = new THREE.Object3D();
- animationTimer;
- isLRAnimation = true;
- direction = 1;
- constructor(model) {
- this.model = model;
- this.group.name = this.modelName;
- }
- addLight() {
- const directionalLight = new THREE.DirectionalLight(0xffffff, 1);
- directionalLight.position.set(42.4, 248, 86);
- this.group.add(directionalLight);
- directionalLight.target = this.group;
- // gui.add(directionalLight.position, 'x', -500, 500);
- // gui.add(directionalLight.position, 'y', -500, 500);
- // gui.add(directionalLight.position, 'z', -500, 500);
- 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.group.add(spotLight);
- spotLight.shadow.camera.near = 0.5; // default
- spotLight.shadow.camera.far = 1000; // default
- spotLight.shadow.focus = 1;
- spotLight.shadow.bias = -0.000002;
- // gui.add(spotLight.position, 'x', -500, 500);
- // gui.add(spotLight.position, 'y', -500, 500);
- // gui.add(spotLight.position, 'z', -500, 500);
- // gui.add(spotLight, 'distance', 0, 1000);
- }
- // 设置模型位置
- setModalPosition() {
- this.group?.scale.set(22, 22, 22);
- this.group?.position.set(-10, 25, 20);
- }
- addFmText(selectData) {
- if (!this.group) {
- return;
- }
- const textArr = [
- {
- text: `单点式测风装置`,
- font: 'normal 32px Arial',
- color: '#009900',
- strokeStyle: '#002200',
- x: 140,
- y: 75,
- },
- {
- text: `风量(m3/min):`,
- font: 'normal 29px Arial',
- color: '#009900',
- strokeStyle: '#002200',
- x: 12,
- y: 133,
- },
- {
- text: `${selectData.m3 ? selectData.m3 : '-'}`,
- font: 'normal 29px Arial',
- color: '#009900',
- strokeStyle: '#002200',
- x: 311,
- y: 133,
- },
- {
- text: `风速(m/s): `,
- font: 'normal 29px Arial',
- color: '#009900',
- strokeStyle: '#002200',
- x: 12,
- y: 192,
- },
- {
- text: `${selectData.va ? selectData.va : '-'}`,
- font: 'normal 29px Arial',
- color: '#009900',
- strokeStyle: '#002200',
- x: 310,
- y: 192,
- },
- {
- text: `断面积(㎡):`,
- font: 'normal 29px Arial',
- color: '#009900',
- strokeStyle: '#002200',
- x: 12,
- y: 247,
- },
- {
- text: `${selectData.fsectarea ? selectData.fsectarea : '-'}`,
- font: 'normal 29px Arial',
- color: '#009900',
- strokeStyle: '#002200',
- x: 310,
- y: 247,
- },
- {
- text: `煤炭科学技术研究院有限公司研制`,
- font: 'normal 28px Arial',
- color: '#009900',
- strokeStyle: '#002200',
- x: 50,
- 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(5.6, 3.46); // 平面3维几何体PlaneGeometry
- const planeMesh = new THREE.Mesh(planeGeometry, textMaterial);
- planeMesh.name = 'monitorText';
- planeMesh.scale.set(0.26, 0.26, 0.26);
- planeMesh.position.set(-2.52, 0.038, -0.42);
- 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.00002 * 30 * this.direction;
- } else {
- this.group.rotation.y += 0.00002 * 30 * this.direction;
- }
- }
- }
- /* 点击风窗,风窗全屏 */
- mousedownModel(intersects: THREE.Intersection<THREE.Object3D<THREE.Event>>[]) {
- this.isLRAnimation = false;
- if (this.animationTimer) {
- clearTimeout(this.animationTimer);
- this.animationTimer = null;
- }
- // 判断是否点击到视频
- intersects.find((intersect) => {
- intersect;
- return false;
- });
- }
- mouseUpModel() {
- // 10s后开始摆动
- if (!this.animationTimer && !this.isLRAnimation) {
- this.animationTimer = setTimeout(() => {
- this.isLRAnimation = true;
- }, 10000);
- }
- }
- resetModel() {
- clearTimeout(this.animationTimer);
- this.isLRAnimation = false;
- }
- mountedThree() {
- return new Promise((resolve) => {
- this.model.setGLTFModel([this.modelName]).then((gltf) => {
- this.group.name = this.modelName;
- this.group = gltf[0];
- this.setModalPosition();
- this.addLight();
- });
- });
- }
- destroy() {
- if (this.group) {
- this.model.clearGroup(this.group);
- }
- this.model = null;
- this.group = null;
- }
- }
- export default ddWindRect;
|