dandaoFcLt.threejs.ts 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. import * as THREE from 'three';
  2. import { getTextCanvas } from '/@/utils/threejs/util';
  3. import gsap from 'gsap';
  4. class ddFc_lt {
  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_DaLiuTa')?.getObjectByName('FengChuang_DaLiuTa_1')?.getObjectByName('FengChuang_1_17');
  159. if (fcGroup) {
  160. fcGroup.children.filter((item: THREE.Mesh) => {
  161. item.rotateOnAxis(new THREE.Vector3(0, 0, 1), 0);
  162. meshArr01.push(item);
  163. });
  164. }
  165. this.windowsActionArr.frontWindow = meshArr01;
  166. }
  167. play(rotationParam, flag) {
  168. if (!this.windowsActionArr.frontWindow) {
  169. return;
  170. }
  171. if (flag === 1) {
  172. // 前风窗动画
  173. this.windowsActionArr.frontWindow.forEach((mesh: THREE.Mesh) => {
  174. gsap.to(mesh.rotation, {
  175. z: THREE.MathUtils.degToRad(rotationParam.frontDeg1),
  176. duration: (1 / 9) * Math.abs(rotationParam.frontDeg1 - mesh.rotation.z),
  177. overwrite: true,
  178. });
  179. });
  180. } else if (flag === 0) {
  181. ([...this.windowsActionArr.frontWindow] as THREE.Mesh[]).forEach((mesh) => {
  182. gsap.to(mesh.rotation, {
  183. z: THREE.MathUtils.degToRad(0),
  184. overwrite: true,
  185. });
  186. });
  187. }
  188. }
  189. /* 点击风窗,风窗全屏 */
  190. mousedownModel(intersects: THREE.Intersection<THREE.Object3D<THREE.Event>>[]) {
  191. if (this.animationTimer) {
  192. clearTimeout(this.animationTimer);
  193. this.animationTimer = null;
  194. }
  195. // 判断是否点击到视频
  196. intersects.find((intersect) => {
  197. const mesh = intersect.object;
  198. if (mesh.name === 'player1') {
  199. if (new Date().getTime() - this.playerStartClickTime1 < 400) {
  200. // 双击,视频放大
  201. if (this.player1) {
  202. this.player1.requestFullscreen();
  203. }
  204. }
  205. this.playerStartClickTime1 = new Date().getTime();
  206. return true;
  207. }
  208. return false;
  209. });
  210. }
  211. mouseUpModel() {}
  212. /* 风门动画 */
  213. render() {
  214. if (!this.model) {
  215. return;
  216. }
  217. }
  218. mountedThree() {
  219. return new Promise((resolve) => {
  220. this.model.setGLTFModel('ddFc-lt').then((gltf) => {
  221. this.group = gltf[0];
  222. this.group.name = this.modelName;
  223. this.setModalPosition();
  224. this.initAnimation();
  225. resolve(null);
  226. });
  227. });
  228. }
  229. destroy() {
  230. this.model.clearGroup(this.group);
  231. this.windowsActionArr.frontWindow = undefined;
  232. this.model = null;
  233. this.group = null;
  234. }
  235. }
  236. export default ddFc_lt;