dandaoFcHjt.threejs.ts 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. import * as THREE from 'three';
  2. import { getTextCanvas, renderVideo } from '/@/utils/threejs/util';
  3. import gsap from 'gsap';
  4. class ddFc_6 {
  5. model;
  6. modelName = 'ddFc';
  7. group: THREE.Object3D = new THREE.Object3D();
  8. animationTimer;
  9. isLRAnimation = true;
  10. direction = 1;
  11. windowsActionArr = {
  12. frontWindow: [],
  13. };
  14. player1;
  15. player2;
  16. playerStartClickTime1 = new Date().getTime();
  17. constructor(model) {
  18. this.model = model;
  19. this.group.name = 'ddFc';
  20. }
  21. addLight = () => {
  22. if (!this.group || !this.group) return;
  23. const directionalLight = new THREE.DirectionalLight(0xffffff, 2);
  24. directionalLight.position.set(-437, 61, 559);
  25. this.group.add(directionalLight);
  26. const pointLight2 = new THREE.PointLight(0xffffff, 1, 150);
  27. pointLight2.position.set(-101, 34, 16);
  28. pointLight2.shadow.bias = 0.05;
  29. this.group.add(pointLight2);
  30. const pointLight3 = new THREE.PointLight(0xffffff, 1, 150);
  31. pointLight3.position.set(19, 25, -7);
  32. pointLight3.shadow.bias = 0.05;
  33. this.group.add(pointLight3);
  34. const pointLight6 = new THREE.PointLight(0xffffff, 1, 300);
  35. pointLight6.position.set(51, 51, 9);
  36. pointLight6.shadow.bias = 0.05;
  37. this.group.add(pointLight6);
  38. };
  39. // 设置模型位置
  40. setModalPosition() {
  41. this.group?.scale.set(22, 22, 22);
  42. this.group?.position.set(-35, 25, 15);
  43. }
  44. addMonitorText(selectData) {
  45. if (!this.group) {
  46. return;
  47. }
  48. const screenDownText = VENT_PARAM['modalText']
  49. ? VENT_PARAM['modalText']
  50. : History_Type['type'] == 'remote'
  51. ? `国能神东煤炭集团监制`
  52. : '煤炭科学技术研究院有限公司研制';
  53. const screenDownTextX = 90 - (screenDownText.length - 10) * 6;
  54. const textArr = [
  55. {
  56. text: `远程定量调节自动风窗`,
  57. font: 'normal 30px Arial',
  58. color: '#009900',
  59. strokeStyle: '#002200',
  60. x: 100,
  61. y: 95,
  62. },
  63. {
  64. text: `${selectData.OpenDegree ? '开度值(°)' : selectData.forntArea ? '过风面积(㎡)' : '过风面积(㎡)'}:`,
  65. font: 'normal 30px Arial',
  66. color: '#009900',
  67. strokeStyle: '#002200',
  68. x: 5,
  69. y: 145,
  70. },
  71. {
  72. text: selectData.OpenDegree
  73. ? Number(`${selectData.OpenDegree}`).toFixed(2)
  74. : selectData.forntArea
  75. ? Number(`${selectData.forntArea}`).toFixed(2)
  76. : '-',
  77. font: 'normal 30px Arial',
  78. color: '#009900',
  79. strokeStyle: '#002200',
  80. x: 330,
  81. y: 145,
  82. },
  83. {
  84. text: `${selectData.frontRearDP ? '风窗压差(Pa)' : selectData.windSpeed ? '风速(m/s)' : '通信状态:'}:`,
  85. font: 'normal 30px Arial',
  86. color: '#009900',
  87. strokeStyle: '#002200',
  88. x: 5,
  89. y: 200,
  90. },
  91. {
  92. text: `${
  93. selectData.frontRearDP
  94. ? selectData.frontRearDP
  95. : selectData.windSpeed
  96. ? selectData.windSpeed
  97. : selectData.netStatus == '0'
  98. ? '断开'
  99. : '连接'
  100. }`,
  101. font: 'normal 30px Arial',
  102. color: '#009900',
  103. strokeStyle: '#002200',
  104. x: 330,
  105. y: 200,
  106. },
  107. {
  108. text: `${selectData.fWindowM3 ? '过风量(m³/min)' : '风窗道数'}: `,
  109. font: 'normal 30px Arial',
  110. color: '#009900',
  111. strokeStyle: '#002200',
  112. x: 5,
  113. y: 250,
  114. },
  115. {
  116. text: `${selectData.fWindowM3 ? selectData.fWindowM3 : selectData.nwindownum}`,
  117. font: 'normal 30px Arial',
  118. color: '#009900',
  119. strokeStyle: '#002200',
  120. x: 330,
  121. y: 250,
  122. },
  123. {
  124. text: screenDownText,
  125. font: 'normal 28px Arial',
  126. color: '#009900',
  127. strokeStyle: '#002200',
  128. x: screenDownTextX,
  129. y: 300,
  130. },
  131. ];
  132. getTextCanvas(750, 546, textArr, '').then((canvas: HTMLCanvasElement) => {
  133. const textMap = new THREE.CanvasTexture(canvas); // 关键一步
  134. const textMaterial = new THREE.MeshBasicMaterial({
  135. // 关于材质并未讲解 实操即可熟悉 这里是漫反射类似纸张的材质,对应的就有高光类似金属的材质.
  136. map: textMap, // 设置纹理贴图
  137. transparent: true,
  138. side: THREE.DoubleSide, // 这里是双面渲染的意思
  139. });
  140. textMap.dispose();
  141. textMaterial.blending = THREE.CustomBlending;
  142. const monitorPlane = this.group?.getObjectByName('monitorText');
  143. if (monitorPlane) {
  144. monitorPlane.material = textMaterial;
  145. } else {
  146. const planeGeometry = new THREE.PlaneGeometry(526, 346); // 平面3维几何体PlaneGeometry
  147. const planeMesh = new THREE.Mesh(planeGeometry, textMaterial);
  148. planeMesh.name = 'monitorText';
  149. planeMesh.scale.set(0.003, 0.0034, 0.004);
  150. planeMesh.position.set(4.25, 0.44, -0.27);
  151. this.group?.add(planeMesh);
  152. }
  153. });
  154. }
  155. /* 提取风门序列帧,初始化前后门动画 */
  156. initAnimation() {
  157. const meshArr01: THREE.Mesh[] = [];
  158. const fcGroup = this.group?.getObjectByName('FengChuang_BaoDe_3')?.getObjectByName('FengChuang_1_17');
  159. if (fcGroup) {
  160. const shanyeNames = [
  161. 'FengChuang_1_22',
  162. 'FengChuang_1_24',
  163. 'FengChuang_1_25',
  164. 'FengChuang_1_26',
  165. 'FengChuang_1_27',
  166. 'FengChuang_1_28',
  167. 'FengChuang_1_29',
  168. ];
  169. fcGroup.children.forEach((obj: THREE.Mesh) => {
  170. if (obj.type === 'Mesh' && obj.name && shanyeNames.includes(obj.name)) {
  171. obj.rotateOnAxis(new THREE.Vector3(0, 1, 0), 90);
  172. meshArr01.push(obj);
  173. }
  174. });
  175. }
  176. this.windowsActionArr.frontWindow = meshArr01;
  177. }
  178. play(rotationParam, flag) {
  179. if (!this.windowsActionArr.frontWindow) {
  180. return;
  181. }
  182. if (flag === 1) {
  183. // 前风窗动画
  184. this.windowsActionArr.frontWindow.forEach((mesh: THREE.Mesh) => {
  185. gsap.to(mesh.rotation, {
  186. y: THREE.MathUtils.degToRad(rotationParam.frontDeg1),
  187. duration: (1 / 9) * Math.abs(rotationParam.frontDeg1 - mesh.rotation.z),
  188. overwrite: true,
  189. });
  190. });
  191. } else if (flag === 0) {
  192. ([...this.windowsActionArr.frontWindow] as THREE.Mesh[]).forEach((mesh) => {
  193. gsap.to(mesh.rotation, {
  194. y: THREE.MathUtils.degToRad(90),
  195. overwrite: true,
  196. });
  197. });
  198. }
  199. }
  200. /* 点击风窗,风窗全屏 */
  201. mousedownModel(intersects: THREE.Intersection<THREE.Object3D<THREE.Event>>[]) {
  202. if (this.animationTimer) {
  203. clearTimeout(this.animationTimer);
  204. this.animationTimer = null;
  205. }
  206. // 判断是否点击到视频
  207. intersects.find((intersect) => {
  208. const mesh = intersect.object;
  209. if (mesh.name === 'player1') {
  210. if (new Date().getTime() - this.playerStartClickTime1 < 400) {
  211. // 双击,视频放大
  212. if (this.player1) {
  213. this.player1.requestFullscreen();
  214. }
  215. }
  216. this.playerStartClickTime1 = new Date().getTime();
  217. return true;
  218. }
  219. return false;
  220. });
  221. }
  222. mouseUpModel() {}
  223. /* 风门动画 */
  224. render() {
  225. if (!this.model) {
  226. return;
  227. }
  228. }
  229. mountedThree() {
  230. return new Promise((resolve) => {
  231. this.model.setGLTFModel('ddFc-hjt').then((gltf) => {
  232. this.group = gltf[0];
  233. this.group.name = this.modelName;
  234. this.setModalPosition();
  235. this.initAnimation();
  236. resolve(null);
  237. });
  238. });
  239. }
  240. destroy() {
  241. this.model.clearGroup(this.group);
  242. this.windowsActionArr.frontWindow = undefined;
  243. this.model = null;
  244. this.group = null;
  245. }
  246. }
  247. export default ddFc_6;