balancePress.threejs.tun.ts 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. import * as THREE from 'three';
  2. import { setModalCenter, getTextCanvas, renderVideo } from '/@/utils/threejs/util';
  3. import Smoke from '/@/views/vent/comment/threejs/Smoke';
  4. // import * as dat from 'dat.gui';
  5. // const gui = new dat.GUI();
  6. // gui.domElement.style = 'position:absolute;top:100px;left:10px;z-index:99999999999999';
  7. class balancePressTun {
  8. model;
  9. modelName = 'balancePressTun';
  10. group: THREE.Object3D | null = null;
  11. topSmoke: Smoke | null = null;
  12. downSmoke: Smoke | null = null;
  13. outSmoke: Smoke | null = null;
  14. constructor(model) {
  15. this.model = model;
  16. }
  17. addLight() {
  18. const directionalLight = new THREE.DirectionalLight(0xffffff, 1);
  19. directionalLight.position.set(34, 7, -61);
  20. this.group?.add(directionalLight);
  21. directionalLight.target = this.group as THREE.Object3D;
  22. // gui.add(directionalLight.position, 'x', -200, 200);
  23. // gui.add(directionalLight.position, 'y', -200, 200);
  24. // gui.add(directionalLight.position, 'z', -200, 200);
  25. const pointLight5 = new THREE.PointLight(0xffffff, 0.8, 120);
  26. pointLight5.position.set(75, -44, 75);
  27. pointLight5.shadow.bias = 0.05;
  28. this.group?.add(pointLight5);
  29. const pointLight7 = new THREE.PointLight(0xffffff, 1, 1000);
  30. pointLight7.position.set(-7, 100, 8.5);
  31. pointLight7.shadow.bias = 0.05;
  32. this.group?.add(pointLight7);
  33. // gui.add(directionalLight.position, 'x', -100, 100);
  34. // gui.add(directionalLight.position, 'y', -100, 100);
  35. // gui.add(directionalLight.position, 'z', -100, 100);
  36. // gui.add(pointLight5.position, 'x', -500, 500);
  37. // gui.add(pointLight5.position, 'y', -500, 500);
  38. // gui.add(pointLight5.position, 'z', -500, 500);
  39. }
  40. /* 添加监控数据 */
  41. addText(selectData) {
  42. if (!this.group) {
  43. return;
  44. }
  45. const textArr = [
  46. {
  47. text: `煤矿巷道远程局部风机系统`,
  48. font: 'normal 30px Arial',
  49. color: '#009900',
  50. strokeStyle: '#002200',
  51. x: 50,
  52. y: 105,
  53. },
  54. {
  55. text: `进风量(m³/min):`,
  56. font: 'normal 30px Arial',
  57. color: '#009900',
  58. strokeStyle: '#002200',
  59. x: 0,
  60. y: 160,
  61. },
  62. {
  63. text: `${selectData.frontRearDP}`,
  64. font: 'normal 30px Arial',
  65. color: '#009900',
  66. strokeStyle: '#002200',
  67. x: 290,
  68. y: 160,
  69. },
  70. {
  71. text: `供风量(m³/min): `,
  72. font: 'normal 30px Arial',
  73. color: '#009900',
  74. strokeStyle: '#002200',
  75. x: 0,
  76. y: 217,
  77. },
  78. {
  79. text: ` ${selectData.sourcePressure}`,
  80. font: 'normal 30px Arial',
  81. color: '#009900',
  82. strokeStyle: '#002200',
  83. x: 280,
  84. y: 217,
  85. },
  86. {
  87. text: `故障诊断:`,
  88. font: 'normal 30px Arial',
  89. color: '#009900',
  90. strokeStyle: '#002200',
  91. x: 0,
  92. y: 275,
  93. },
  94. {
  95. text: `${selectData.warnLevel_str ? selectData.warnLevel_str : '-'}`,
  96. font: 'normal 30px Arial',
  97. color: '#009900',
  98. strokeStyle: '#002200',
  99. x: 280,
  100. y: 275,
  101. },
  102. {
  103. text: `煤炭科学技术研究院有限公司研制`,
  104. font: 'normal 28px Arial',
  105. color: '#009900',
  106. strokeStyle: '#002200',
  107. x: 20,
  108. y: 325,
  109. },
  110. ];
  111. getTextCanvas(526, 346, textArr, '').then((canvas: HTMLCanvasElement) => {
  112. const textMap = new THREE.CanvasTexture(canvas); // 关键一步
  113. const textMaterial = new THREE.MeshBasicMaterial({
  114. // 关于材质并未讲解 实操即可熟悉 这里是漫反射类似纸张的材质,对应的就有高光类似金属的材质.
  115. map: textMap, // 设置纹理贴图
  116. transparent: true,
  117. side: THREE.FrontSide, // 这里是双面渲染的意思
  118. });
  119. textMaterial.blending = THREE.CustomBlending;
  120. const monitorPlane = this.group?.getObjectByName('monitorText') as THREE.Mesh;
  121. if (monitorPlane) {
  122. monitorPlane.material = textMaterial;
  123. } else {
  124. const planeGeometry = new THREE.PlaneGeometry(526, 346); // 平面3维几何体PlaneGeometry
  125. const planeMesh = new THREE.Mesh(planeGeometry, textMaterial);
  126. planeMesh.name = 'monitorText';
  127. planeMesh.scale.set(0.0135, 0.0135, 0.0135);
  128. planeMesh.position.set(57.66, 0.81, 18.19);
  129. this.group?.add(planeMesh);
  130. }
  131. });
  132. }
  133. mountedThree() {
  134. return new Promise((resolve) => {
  135. this.model.setGLTFModel([this.modelName]).then(async (gltf) => {
  136. this.group = gltf[0];
  137. if (this.group) {
  138. this.group?.scale.set(0.1, 0.1, 0.1);
  139. setModalCenter(this.group);
  140. resolve(null);
  141. this.addLight();
  142. }
  143. });
  144. });
  145. }
  146. destroy() {
  147. this.model.clearGroup(this.group);
  148. this.model = null;
  149. this.group = null;
  150. }
  151. }
  152. export default balancePressTun;