1
0

dandaoFcXk.threejs.ts 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. import * as THREE from 'three';
  2. import { getTextCanvas } from '/@/utils/threejs/util';
  3. import gsap from 'gsap';
  4. class singleWindowXk {
  5. model;
  6. modelName = 'xkFcGroup';
  7. group: THREE.Object3D = new THREE.Object3D();
  8. animationTimer;
  9. isLRAnimation = true;
  10. direction = 1;
  11. windowsActionArr = {
  12. frontWindow: [],
  13. };
  14. constructor(model) {
  15. this.model = model;
  16. this.group.name = 'xkFcGroup';
  17. }
  18. addLight = () => {
  19. if (!this.group || !this.group) return;
  20. const directionalLight = new THREE.DirectionalLight(0xffffff, 1.5);
  21. directionalLight.position.set(800.0, 120.0, 80.0);
  22. this.group.add(directionalLight);
  23. const pointLight2 = new THREE.PointLight(0xffffff, 1, 150);
  24. pointLight2.position.set(-101, 34, 16);
  25. pointLight2.shadow.bias = 0.05;
  26. this.group.add(pointLight2);
  27. const pointLight3 = new THREE.PointLight(0xffffff, 1, 150);
  28. pointLight3.position.set(19, 25, -7);
  29. pointLight3.shadow.bias = 0.05;
  30. this.group.add(pointLight3);
  31. const pointLight6 = new THREE.PointLight(0xffffff, 1, 300);
  32. pointLight6.position.set(51, 51, 9);
  33. pointLight6.shadow.bias = 0.05;
  34. this.group.add(pointLight6);
  35. };
  36. // 设置模型位置
  37. setModalPosition() {
  38. this.group?.scale.set(22, 22, 22);
  39. this.group?.position.set(-35, 25, 15);
  40. }
  41. addMonitorText(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: 100,
  52. y: 95,
  53. },
  54. {
  55. text: `${selectData.OpenDegree ? '开度值(°)' : selectData.forntArea ? '过风面积(㎡)' : '过风面积(㎡)'}:`,
  56. font: 'normal 30px Arial',
  57. color: '#009900',
  58. strokeStyle: '#002200',
  59. x: 5,
  60. y: 145,
  61. },
  62. {
  63. text: selectData.OpenDegree
  64. ? Number(`${selectData.OpenDegree}`).toFixed(2)
  65. : selectData.forntArea
  66. ? Number(`${selectData.forntArea}`).toFixed(2)
  67. : '-',
  68. font: 'normal 30px Arial',
  69. color: '#009900',
  70. strokeStyle: '#002200',
  71. x: 330,
  72. y: 145,
  73. },
  74. {
  75. text: `${selectData.frontRearDP ? '风窗压差(Pa)' : selectData.windSpeed ? '风速(m/s)' : '通信状态:'}:`,
  76. font: 'normal 30px Arial',
  77. color: '#009900',
  78. strokeStyle: '#002200',
  79. x: 5,
  80. y: 200,
  81. },
  82. {
  83. text: `${
  84. selectData.frontRearDP
  85. ? selectData.frontRearDP
  86. : selectData.windSpeed
  87. ? selectData.windSpeed
  88. : selectData.netStatus == '0'
  89. ? '断开'
  90. : '连接'
  91. }`,
  92. font: 'normal 30px Arial',
  93. color: '#009900',
  94. strokeStyle: '#002200',
  95. x: 330,
  96. y: 200,
  97. },
  98. {
  99. text: `${selectData.fWindowM3 ? '过风量(m³/min)' : '风窗道数'}: `,
  100. font: 'normal 30px Arial',
  101. color: '#009900',
  102. strokeStyle: '#002200',
  103. x: 5,
  104. y: 250,
  105. },
  106. {
  107. text: `${selectData.fWindowM3 ? selectData.fWindowM3 : selectData.nwindownum}`,
  108. font: 'normal 30px Arial',
  109. color: '#009900',
  110. strokeStyle: '#002200',
  111. x: 330,
  112. y: 250,
  113. },
  114. {
  115. text: History_Type['type'] == 'remote' ? `国能神东煤炭集团监制` : '煤炭科学技术研究院有限公司研制',
  116. font: 'normal 28px Arial',
  117. color: '#009900',
  118. strokeStyle: '#002200',
  119. x: History_Type['type'] == 'remote' ? 90 : 30,
  120. y: 300,
  121. },
  122. ];
  123. getTextCanvas(750, 546, textArr, '').then((canvas: HTMLCanvasElement) => {
  124. const textMap = new THREE.CanvasTexture(canvas); // 关键一步
  125. const textMaterial = new THREE.MeshBasicMaterial({
  126. // 关于材质并未讲解 实操即可熟悉 这里是漫反射类似纸张的材质,对应的就有高光类似金属的材质.
  127. map: textMap, // 设置纹理贴图
  128. transparent: true,
  129. side: THREE.DoubleSide, // 这里是双面渲染的意思
  130. });
  131. textMap.dispose();
  132. textMaterial.blending = THREE.CustomBlending;
  133. const monitorPlane = this.group?.getObjectByName('monitorText');
  134. if (monitorPlane) {
  135. monitorPlane.material = textMaterial;
  136. } else {
  137. const planeGeometry = new THREE.PlaneGeometry(526, 346); // 平面3维几何体PlaneGeometry
  138. const planeMesh = new THREE.Mesh(planeGeometry, textMaterial);
  139. planeMesh.name = 'monitorText';
  140. planeMesh.scale.set(0.0095, 0.01, 0.01);
  141. planeMesh.position.set(6.97, -0.395, -0.63);
  142. this.group?.add(planeMesh);
  143. }
  144. });
  145. }
  146. /* 提取风门序列帧,初始化前后门动画 */
  147. initAnimation() {
  148. const meshArr01: THREE.Object3D[] = [];
  149. const fmGroup = this.group?.getObjectByName('Fc-Xk');
  150. if (fmGroup) {
  151. fmGroup.children.forEach((obj) => {
  152. if (obj.type === 'Mesh' && obj.name && obj.name.startsWith('Blades')) {
  153. obj.rotateOnAxis(new THREE.Vector3(0, 0, -1), 0);
  154. meshArr01.push(obj);
  155. }
  156. });
  157. }
  158. this.windowsActionArr.frontWindow = meshArr01;
  159. }
  160. play(rotationParam, flag) {
  161. if (!this.windowsActionArr.frontWindow) {
  162. return;
  163. }
  164. if (flag === 1) {
  165. // 前风窗动画
  166. this.windowsActionArr.frontWindow.forEach((mesh: THREE.Mesh) => {
  167. gsap.to(mesh.rotation, {
  168. x: THREE.MathUtils.degToRad(rotationParam.frontDeg1),
  169. duration: Math.abs(rotationParam.frontDeg1 - mesh.rotation.x) / 10,
  170. overwrite: true,
  171. });
  172. });
  173. } else if (flag === 0) {
  174. ([...this.windowsActionArr.frontWindow] as THREE.Mesh[]).forEach((mesh) => {
  175. gsap.to(mesh.rotation, {
  176. x: 0,
  177. overwrite: true,
  178. });
  179. });
  180. }
  181. }
  182. /* 点击风窗,风窗全屏 */
  183. mousedownModel(intersects: THREE.Intersection<THREE.Object3D<THREE.Event>>[]) {
  184. if (this.animationTimer) {
  185. clearTimeout(this.animationTimer);
  186. this.animationTimer = null;
  187. }
  188. console.log('摄像头控制信息', this.model.orbitControls, this.model.camera);
  189. }
  190. mouseUpModel() {}
  191. /* 风门动画 */
  192. render() {
  193. if (!this.model) {
  194. return;
  195. }
  196. }
  197. resetMaterial() {
  198. const fcModal = this.group.getObjectByName('Fc-Xk');
  199. if (fcModal) {
  200. const stainlseeSteel_grey = (fcModal.getObjectByName('Box771') as THREE.Mesh)?.material; // 圈;
  201. const stainlessSteel_light = (fcModal.getObjectByName('Line12241') as THREE.Mesh)?.material; // 框;
  202. const fluorescent_green = (fcModal.getObjectByName('对象276') as THREE.Mesh)?.material; // fluorescent_green;
  203. const fluorescent_green1 = (fcModal.getObjectByName('Box770') as THREE.Mesh)?.material; // 23 - Default;
  204. const wire = (fcModal.getObjectByName('对象281') as THREE.Mesh)?.material; // wire_028149177;
  205. const net = (fcModal.getObjectByName('Plane9230') as THREE.Mesh)?.material; // wire_028149177;
  206. const stainlesssteel_blue = (fcModal.getObjectByName('Blades08') as THREE.Mesh)?.material; // wire_028149177;
  207. (stainlseeSteel_grey as THREE.MeshStandardMaterial).color.set(0xb3b3b3);
  208. (stainlseeSteel_grey as THREE.MeshStandardMaterial).roughness = 0.26;
  209. (stainlessSteel_light as THREE.MeshStandardMaterial).color.set(0x9e9e9e);
  210. (stainlessSteel_light as THREE.MeshStandardMaterial).roughness = 0.26;
  211. (stainlessSteel_light as THREE.MeshStandardMaterial).envMapIntensity = 0.92;
  212. (fluorescent_green as THREE.MeshStandardMaterial).color.set(0x00fff2);
  213. (fluorescent_green as THREE.MeshStandardMaterial).envMapIntensity = 1.5;
  214. //
  215. (fluorescent_green1 as THREE.MeshStandardMaterial).color.set(0x00fff2);
  216. (fluorescent_green1 as THREE.MeshStandardMaterial).envMapIntensity = 1.5;
  217. (wire as THREE.MeshStandardMaterial).color.set(0x38e4ff);
  218. (wire as THREE.MeshStandardMaterial).envMapIntensity = 2;
  219. (net as THREE.MeshStandardMaterial).color.set(0xcfcfcf);
  220. (stainlesssteel_blue as THREE.MeshStandardMaterial).color.set(0xababab);
  221. (stainlesssteel_blue as THREE.MeshStandardMaterial).roughness = 0.45;
  222. }
  223. }
  224. mountedThree() {
  225. return new Promise((resolve) => {
  226. this.model.setGLTFModel(['Fc-Xk'], this.group).then(async () => {
  227. resolve(null);
  228. this.resetMaterial();
  229. this.setModalPosition();
  230. this.initAnimation();
  231. this.addLight();
  232. });
  233. });
  234. }
  235. destroy() {
  236. this.model.clearGroup(this.group);
  237. this.model = null;
  238. this.group = null;
  239. }
  240. }
  241. export default singleWindowXk;