dandaoFcBd1.threejs.ts 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. import * as THREE from 'three';
  2. import { getTextCanvas, renderVideo } from '/@/utils/threejs/util';
  3. import gsap from 'gsap';
  4. class ddFc_4 {
  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: `最大面积(㎡):`,
  65. font: 'normal 30px Arial',
  66. color: '#009900',
  67. strokeStyle: '#002200',
  68. x: 5,
  69. y: 145,
  70. },
  71. {
  72. text: selectData.maxarea ? Number(`${selectData.maxarea}`).toFixed(2) : '-',
  73. font: 'normal 30px Arial',
  74. color: '#009900',
  75. strokeStyle: '#002200',
  76. x: 330,
  77. y: 145,
  78. },
  79. {
  80. text: `${selectData.OpenDegree ? '开度值(°)' : selectData.forntArea ? '过风面积(㎡)' : '过风面积(㎡)'}:`,
  81. font: 'normal 30px Arial',
  82. color: '#009900',
  83. strokeStyle: '#002200',
  84. x: 5,
  85. y: 200,
  86. },
  87. {
  88. text: selectData.OpenDegree
  89. ? Number(`${selectData.OpenDegree}`).toFixed(2)
  90. : selectData.forntArea
  91. ? Number(`${selectData.forntArea}`).toFixed(2)
  92. : '-',
  93. font: 'normal 30px Arial',
  94. color: '#009900',
  95. strokeStyle: '#002200',
  96. x: 330,
  97. y: 200,
  98. },
  99. {
  100. text: `${selectData.frontRearDP ? '风窗压差(Pa)' : selectData.windSpeed ? '风速(m/s)' : '通信状态:'}:`,
  101. font: 'normal 30px Arial',
  102. color: '#009900',
  103. strokeStyle: '#002200',
  104. x: 5,
  105. y: 250,
  106. },
  107. {
  108. text: `${
  109. selectData.frontRearDP
  110. ? selectData.frontRearDP
  111. : selectData.windSpeed
  112. ? selectData.windSpeed
  113. : selectData.netStatus == '0'
  114. ? '断开'
  115. : '连接'
  116. }`,
  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_1')?.getObjectByName('FengChuang_1_1');
  159. if (fcGroup) {
  160. const sy1 = fcGroup.getObjectByName('FengChuang_1_2') as THREE.Mesh;
  161. const sy2 = fcGroup.getObjectByName('FengChuang_1_3') as THREE.Mesh;
  162. sy1.rotateOnAxis(new THREE.Vector3(0, 0, 1), 0);
  163. sy2.rotateOnAxis(new THREE.Vector3(0, 0, 1), 0);
  164. meshArr01.push(sy1);
  165. meshArr01.push(sy2);
  166. }
  167. this.windowsActionArr.frontWindow = meshArr01;
  168. }
  169. play(rotationParam, flag) {
  170. if (!this.windowsActionArr.frontWindow) {
  171. return;
  172. }
  173. if (flag === 1) {
  174. // 前风窗动画
  175. this.windowsActionArr.frontWindow.forEach((mesh: THREE.Mesh) => {
  176. gsap.to(mesh.rotation, {
  177. z: THREE.MathUtils.degToRad(rotationParam.frontDeg1),
  178. duration: (1 / 9) * Math.abs(rotationParam.frontDeg1 - mesh.rotation.z),
  179. overwrite: true,
  180. });
  181. });
  182. } else if (flag === 0) {
  183. ([...this.windowsActionArr.frontWindow] as THREE.Mesh[]).forEach((mesh) => {
  184. gsap.to(mesh.rotation, {
  185. z: THREE.MathUtils.degToRad(90),
  186. overwrite: true,
  187. });
  188. });
  189. }
  190. }
  191. /* 点击风窗,风窗全屏 */
  192. mousedownModel(intersects: THREE.Intersection<THREE.Object3D<THREE.Event>>[]) {
  193. if (this.animationTimer) {
  194. clearTimeout(this.animationTimer);
  195. this.animationTimer = null;
  196. }
  197. // 判断是否点击到视频
  198. intersects.find((intersect) => {
  199. const mesh = intersect.object;
  200. if (mesh.name === 'player1') {
  201. if (new Date().getTime() - this.playerStartClickTime1 < 400) {
  202. // 双击,视频放大
  203. if (this.player1) {
  204. this.player1.requestFullscreen();
  205. }
  206. }
  207. this.playerStartClickTime1 = new Date().getTime();
  208. return true;
  209. }
  210. return false;
  211. });
  212. }
  213. mouseUpModel() {}
  214. /* 风门动画 */
  215. render() {
  216. if (!this.model) {
  217. return;
  218. }
  219. }
  220. mountedThree() {
  221. return new Promise((resolve) => {
  222. this.model.setGLTFModel('ddFc-bd1').then((gltf) => {
  223. this.group = gltf[0];
  224. this.group.name = this.modelName;
  225. this.setModalPosition();
  226. this.initAnimation();
  227. resolve(null);
  228. });
  229. });
  230. }
  231. destroy() {
  232. this.model.clearGroup(this.group);
  233. this.windowsActionArr.frontWindow = undefined;
  234. this.model = null;
  235. this.group = null;
  236. }
  237. }
  238. export default ddFc_4;