dandaoFcYjl.threejs.ts 7.1 KB

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