fanLocal.three.bk.ts 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713
  1. import * as THREE from 'three';
  2. import { CSS3DObject } from 'three/examples/jsm/renderers/CSS3DRenderer.js';
  3. import { animateCamera, getTextCanvas, renderVideo, updateAxisCenter } from '/@/utils/threejs/util';
  4. import UseThree from '../../../../utils/threejs/useThree';
  5. import fcFan from './fcfanLocal.three';
  6. import fmFan from './fmfanLocal.three';
  7. import Smoke from '/@/views/vent/comment/threejs/Smoke';
  8. import gsap from 'gsap';
  9. import useEvent from '../../../../utils/threejs/useEvent';
  10. // import * as dat from 'dat.gui';
  11. // const gui = new dat.GUI();
  12. // gui.domElement.style = 'position:absolute;top:100px;left:10px;z-index:99999999999999';
  13. const modelName = 'jbfj-hd';
  14. // 模型对象、 文字对象
  15. let model: UseThree | undefined,
  16. group: THREE.Object3D | undefined,
  17. fcFanObj: fcFan | undefined,
  18. fmFanObj: fmFan | undefined,
  19. player1,
  20. fanType,
  21. topSmoke: Smoke | undefined,
  22. downSmoke: Smoke | undefined, //
  23. returnSmoke: Smoke | undefined,
  24. topLife: number | undefined,
  25. downLife: number | undefined,
  26. playerStartClickTime1 = new Date().getTime();
  27. const { mouseDownFn, mousemoveFn, mouseUpFn } = useEvent();
  28. // 打灯光
  29. const addLight = () => {
  30. const directionalLight = new THREE.DirectionalLight(0xffffff, 1.2);
  31. directionalLight.position.set(-564, 602, -261);
  32. group?.add(directionalLight);
  33. // directionalLight.target = group;
  34. // const spotLight = new THREE.SpotLight();
  35. // spotLight.angle = Math.PI / 16;
  36. // spotLight.penumbra = 0;
  37. // spotLight.castShadow = true;
  38. // spotLight.position.set(0, 463, 687);
  39. // scene.add(spotLight);
  40. // spotLight.shadow.camera.near = 0.5; // default
  41. // spotLight.shadow.camera.far = 1000; // default
  42. // spotLight.shadow.focus = 1;
  43. // spotLight.shadow.bias = -0.000002;
  44. // spotLight.target = group;
  45. // const pointLight6 = new THREE.PointLight(0xffffff, 1, 500);
  46. // pointLight6.position.set(-131, 64, -1);
  47. // pointLight6.shadow.bias = 0.05;
  48. // group?.add(pointLight6);
  49. // gui.add(directionalLight.position, 'x', -1000, 1000);
  50. // gui.add(directionalLight.position, 'y', -1000, 1000);
  51. // gui.add(directionalLight.position, 'z', -1000, 1000);
  52. // gui.add(pointLight6.position, 'x', -500, 500);
  53. // gui.add(pointLight6.position, 'y', -500, 500);
  54. // gui.add(pointLight6.position, 'z', -500, 500);
  55. // gui.add(pointLight6, 'distance', 0, 500);
  56. };
  57. // 重置摄像头
  58. const resetCamera = () => {
  59. model.camera.position.set(0, -1000, 100);
  60. model.camera.far = 1000;
  61. model.orbitControls?.update();
  62. model.camera.updateProjectionMatrix();
  63. };
  64. // 设置模型位置
  65. const setModalPosition = () => {
  66. if (!group) return;
  67. group.position.set(0, 10, -50);
  68. group.rotation.y = Math.PI / 2;
  69. };
  70. const setControls = () => {
  71. if (model && model.orbitControls) {
  72. model.orbitControls.panSpeed = 0.5;
  73. model.orbitControls.rotateSpeed = 0.5;
  74. model.orbitControls.maxPolarAngle = Math.PI / 2.4;
  75. model.orbitControls.minPolarAngle = Math.PI / 3;
  76. }
  77. };
  78. // 切换局部通风机类型
  79. export const setModelType = (type) => {
  80. fanType = type;
  81. return new Promise((resolve) => {
  82. // 显示双道风窗
  83. let childGroup;
  84. if (fanType === 'fm' && fcFanObj && fcFanObj.group) {
  85. if (group?.getObjectByName('jbfj-fc')) {
  86. group?.remove(fcFanObj.group);
  87. }
  88. childGroup = fmFanObj?.group;
  89. if (group && group?.getObjectByName('text5') && group?.getObjectByName('text4')) {
  90. group.getObjectByName('text5')['visible'] = false;
  91. group.getObjectByName('text4')['visible'] = true;
  92. }
  93. } else if (fanType === 'fc' && fmFanObj && fmFanObj.group) {
  94. // 显示单道风窗
  95. if (group?.getObjectByName('jbfj-fm')) {
  96. group?.remove(fmFanObj.group);
  97. }
  98. childGroup = fcFanObj?.group;
  99. if (group && group?.getObjectByName('text5') && group?.getObjectByName('text4')) {
  100. group.getObjectByName('text5')['visible'] = true;
  101. group.getObjectByName('text4')['visible'] = false;
  102. }
  103. } else {
  104. if (group?.getObjectByName('jbfj-fc')) {
  105. group?.remove(fcFanObj.group);
  106. }
  107. if (group?.getObjectByName('jbfj-fm')) {
  108. group?.remove(fmFanObj.group);
  109. }
  110. if (group && group?.getObjectByName('text5') && group?.getObjectByName('text4')) {
  111. group.getObjectByName('text5')['visible'] = false;
  112. group.getObjectByName('text4')['visible'] = false;
  113. }
  114. childGroup = null;
  115. }
  116. setTimeout(async () => {
  117. if (childGroup) group?.add(childGroup);
  118. const oldCameraPosition = { x: 615, y: 275, z: 744 };
  119. await animateCamera(oldCameraPosition, { x: 0, y: 0, z: 0 }, { x: 0.08, y: 21.73, z: 78.45 }, { x: 0.13, y: -0.82, z: 0.236 }, model, 0.8);
  120. resolve(null);
  121. }, 300);
  122. });
  123. };
  124. /* 添加监控数据 */
  125. export const addText = (selectData) => {
  126. if (!group) {
  127. return;
  128. }
  129. const screenDownText = VENT_PARAM['modalText']
  130. ? VENT_PARAM['modalText']
  131. : History_Type['type'] == 'remote'
  132. ? `国能神东煤炭集团监制`
  133. : '煤炭科学技术研究院有限公司研制';
  134. const screenDownTextX = 80 - (screenDownText.length - 10) * 6;
  135. const textArr = [
  136. {
  137. text: `智能局部通风机监测与控制系统`,
  138. font: 'normal 30px Arial',
  139. color: '#009900',
  140. strokeStyle: '#002200',
  141. x: 20,
  142. y: 108,
  143. },
  144. {
  145. text: `供风距离(m):`,
  146. font: 'normal 30px Arial',
  147. color: '#009900',
  148. strokeStyle: '#002200',
  149. x: 0,
  150. y: 152,
  151. },
  152. {
  153. text: `${
  154. selectData.airSupplyDistence_merge
  155. ? selectData.airSupplyDistence_merge
  156. : selectData.fchimenylength
  157. ? selectData.fchimenylength
  158. : selectData.airSupplyDistence_merge
  159. ? selectData.airSupplyDistence_merge
  160. : '-'
  161. }`,
  162. font: 'normal 30px Arial',
  163. color: '#009900',
  164. strokeStyle: '#002200',
  165. x: 228,
  166. y: 152,
  167. },
  168. {
  169. text: `风筒直径(mm): `,
  170. font: 'normal 30px Arial',
  171. color: '#009900',
  172. strokeStyle: '#002200',
  173. x: 0,
  174. y: 200,
  175. },
  176. {
  177. text: ` ${selectData.fchimenydiamlimit ? selectData.fchimenydiamlimit : selectData.ductDiameter_merge ? selectData.ductDiameter_merge : '-'}`,
  178. font: 'normal 30px Arial',
  179. color: '#009900',
  180. strokeStyle: '#002200',
  181. x: 220,
  182. y: 200,
  183. },
  184. {
  185. text: `故障诊断:`,
  186. font: 'normal 30px Arial',
  187. color: '#009900',
  188. strokeStyle: '#002200',
  189. x: 0,
  190. y: 245,
  191. },
  192. {
  193. text: `${selectData.warnLevel_str ? selectData.warnLevel_str : '-'}`,
  194. font: 'normal 30px Arial',
  195. color: '#009900',
  196. strokeStyle: '#002200',
  197. x: 220,
  198. y: 245,
  199. },
  200. {
  201. text: `型号功率:`,
  202. font: 'normal 30px Arial',
  203. color: '#009900',
  204. strokeStyle: '#002200',
  205. x: 0,
  206. y: 285,
  207. },
  208. {
  209. text: `${selectData.model_Power_merge ? selectData.model_Power_merge : '-'}`,
  210. font: 'normal 26px Arial',
  211. color: '#009900',
  212. strokeStyle: '#002200',
  213. x: 220,
  214. y: 285,
  215. },
  216. {
  217. text: screenDownText,
  218. font: 'normal 28px Arial',
  219. color: '#009900',
  220. strokeStyle: '#002200',
  221. x: screenDownTextX,
  222. y: 325,
  223. },
  224. ];
  225. getTextCanvas(526, 346, textArr, '').then((canvas: HTMLCanvasElement) => {
  226. const textMap = new THREE.CanvasTexture(canvas); // 关键一步
  227. const textMaterial = new THREE.MeshBasicMaterial({
  228. // 关于材质并未讲解 实操即可熟悉 这里是漫反射类似纸张的材质,对应的就有高光类似金属的材质.
  229. map: textMap, // 设置纹理贴图
  230. transparent: true,
  231. side: THREE.FrontSide, // 这里是双面渲染的意思
  232. });
  233. textMaterial.blending = THREE.CustomBlending;
  234. const monitorPlane = group.getObjectByName('monitorText');
  235. if (monitorPlane) {
  236. monitorPlane.material = textMaterial;
  237. } else {
  238. const planeGeometry = new THREE.PlaneGeometry(526, 346); // 平面3维几何体PlaneGeometry
  239. const planeMesh = new THREE.Mesh(planeGeometry, textMaterial);
  240. planeMesh.name = 'monitorText';
  241. planeMesh.scale.set(0.0135, 0.0135, 0.0135);
  242. planeMesh.rotation.y = -Math.PI / 2;
  243. planeMesh.position.set(-84.79, 0.82, 17.0);
  244. group.add(planeMesh);
  245. }
  246. });
  247. };
  248. // // css3D文字
  249. export const addCssText = () => {
  250. if (!group) return;
  251. if (!group.getObjectByName('text1')) {
  252. const element = document.getElementById('inputBox') as HTMLElement;
  253. if (element) {
  254. const fanLocalCSS3D = new CSS3DObject(element);
  255. fanLocalCSS3D.name = 'text1';
  256. fanLocalCSS3D.scale.set(0.04, 0.04, 0.04);
  257. fanLocalCSS3D.rotation.y = -Math.PI / 2;
  258. fanLocalCSS3D.position.set(-85.68, 5.97, -3.39);
  259. group.add(fanLocalCSS3D);
  260. }
  261. }
  262. if (!group.getObjectByName('text2')) {
  263. const element = document.getElementById('outBox') as HTMLElement;
  264. if (element) {
  265. const fanLocalCSS3D = new CSS3DObject(element);
  266. fanLocalCSS3D.name = 'text2';
  267. fanLocalCSS3D.scale.set(0.1, 0.1, 0.1);
  268. fanLocalCSS3D.rotation.y = -Math.PI / 2;
  269. // fanLocalCSS3D.position.set(74.63, 13.54, 3.84);
  270. fanLocalCSS3D.position.set(57.84, 10.54, 0.08);
  271. group.add(fanLocalCSS3D);
  272. }
  273. }
  274. if (!group.getObjectByName('text3')) {
  275. const element = document.getElementById('returnBox') as HTMLElement;
  276. if (element) {
  277. const fanLocalCSS3D = new CSS3DObject(element);
  278. fanLocalCSS3D.name = 'text3';
  279. fanLocalCSS3D.scale.set(0.07, 0.07, 0.07);
  280. fanLocalCSS3D.rotation.y = -Math.PI / 2;
  281. fanLocalCSS3D.position.set(-25.97, 9.3, -15.09);
  282. group.add(fanLocalCSS3D);
  283. }
  284. }
  285. if (!group.getObjectByName('text4')) {
  286. const element = document.getElementById('gateBox') as HTMLElement;
  287. if (element) {
  288. // element.innerHTML = '';
  289. const fanLocalCSS3D = new CSS3DObject(element);
  290. fanLocalCSS3D.name = 'text4';
  291. fanLocalCSS3D.scale.set(0.04, 0.04, 0.04);
  292. fanLocalCSS3D.rotation.y = -Math.PI / 2;
  293. fanLocalCSS3D.position.set(-73.13, 8.44, -23.52);
  294. group.add(fanLocalCSS3D);
  295. }
  296. }
  297. if (!group.getObjectByName('text5')) {
  298. const element = document.getElementById('windownBox') as HTMLElement;
  299. if (element) {
  300. // element.innerHTML = '';
  301. const fanLocalCSS3D = new CSS3DObject(element);
  302. fanLocalCSS3D.name = 'text5';
  303. fanLocalCSS3D.scale.set(0.07, 0.07, 0.07);
  304. fanLocalCSS3D.rotation.y = -Math.PI / 2;
  305. fanLocalCSS3D.position.set(-28.44, 9.78, -40.42);
  306. group.add(fanLocalCSS3D);
  307. }
  308. }
  309. if (!group.getObjectByName('text7')) {
  310. const element = document.getElementById('inputBox0') as HTMLElement;
  311. if (element) {
  312. const fanLocalCSS3D = new CSS3DObject(element);
  313. fanLocalCSS3D.name = 'text7';
  314. fanLocalCSS3D.scale.set(0.04, 0.04, 0.04);
  315. fanLocalCSS3D.rotation.y = -Math.PI / 2;
  316. fanLocalCSS3D.position.set(-84.23, 4.97, -18.92);
  317. group.add(fanLocalCSS3D);
  318. }
  319. }
  320. if (!group.getObjectByName('text6')) {
  321. const element = document.getElementById('inputBox1') as HTMLElement;
  322. if (element) {
  323. const fanLocalCSS3D = new CSS3DObject(element);
  324. fanLocalCSS3D.name = 'text6';
  325. fanLocalCSS3D.scale.set(0.04, 0.04, 0.04);
  326. fanLocalCSS3D.rotation.y = -Math.PI / 2;
  327. fanLocalCSS3D.position.set(-84.23, 6.89, -4.2);
  328. group.add(fanLocalCSS3D);
  329. }
  330. }
  331. if (!group.getObjectByName('text8')) {
  332. const element = document.getElementById('gasBox3') as HTMLElement;
  333. if (element) {
  334. const fanLocalCSS3D = new CSS3DObject(element);
  335. fanLocalCSS3D.name = 'text8';
  336. fanLocalCSS3D.scale.set(0.03, 0.03, 0.03);
  337. fanLocalCSS3D.rotation.y = -Math.PI / 2;
  338. fanLocalCSS3D.position.set(-90.04, 6, 5);
  339. group.add(fanLocalCSS3D);
  340. }
  341. }
  342. if (!group.getObjectByName('text9')) {
  343. const element = document.getElementById('gasBox2') as HTMLElement;
  344. if (element) {
  345. const fanLocalCSS3D = new CSS3DObject(element);
  346. fanLocalCSS3D.name = 'text9';
  347. fanLocalCSS3D.scale.set(0.07, 0.07, 0.07);
  348. fanLocalCSS3D.rotation.y = -Math.PI / 2;
  349. fanLocalCSS3D.position.set(-8, 7.46, -35.28);
  350. group.add(fanLocalCSS3D);
  351. }
  352. }
  353. if (!group.getObjectByName('text10')) {
  354. const element = document.getElementById('gasBox1') as HTMLElement;
  355. if (element) {
  356. const fanLocalCSS3D = new CSS3DObject(element);
  357. fanLocalCSS3D.name = 'text10';
  358. fanLocalCSS3D.scale.set(0.1, 0.1, 0.1);
  359. fanLocalCSS3D.rotation.y = -Math.PI / 2;
  360. fanLocalCSS3D.position.set(80, 9, -43);
  361. group.add(fanLocalCSS3D);
  362. }
  363. }
  364. };
  365. // export const playSmoke = (controlType, deviceType, frequency, state) => {
  366. // if (frequency) {
  367. // setSmokeFrequency(deviceType, frequency);
  368. // }
  369. // if (controlType === 'startSmoke') {
  370. // runFly(deviceType, state);
  371. // }
  372. // };
  373. export const playSmoke = (selectData) => {
  374. // debugger;
  375. // console.log('selectData[Fan1fHz]------------》', selectData['Fan1fHz'], Number(selectData['Fan1fHz']));
  376. if (selectData['Fan1StartStatus'] == '1') {
  377. // 主风机打开
  378. // setSmokeFrequency('top', Number(selectData['Fan1fHz']) || 40);
  379. setSmokeFrequency('top', 40);
  380. runFly('top', 'open');
  381. } else {
  382. // 备风机关闭
  383. runFly('top', 'close');
  384. }
  385. if (selectData['Fan2StartStatus'] == '1') {
  386. // 备风机打开
  387. // setSmokeFrequency('down', Number(selectData['Fan2fHz']) || 40);
  388. setSmokeFrequency('down', 40);
  389. runFly('down', 'open');
  390. } else {
  391. // 备风机关闭
  392. runFly('down', 'close');
  393. }
  394. if (selectData['Fan1StartStatus'] != '1' && selectData['Fan2StartStatus'] != '1') {
  395. runFly('all', 'close');
  396. }
  397. // if (frequency) {
  398. // setSmokeFrequency(deviceType, frequency);
  399. // }
  400. // if (controlType === 'startSmoke') {
  401. // runFly(deviceType, state);
  402. // }
  403. };
  404. const initFly = async () => {
  405. const topCurve = [
  406. {
  407. path0: new THREE.Vector3(-89.84, 2.359, 4.91),
  408. path1: new THREE.Vector3(-85.678, 2.359, 3.61),
  409. isSpread: true,
  410. spreadDirection: -1, //
  411. },
  412. {
  413. path0: new THREE.Vector3(-85.678, 2.352, 3.66),
  414. path1: new THREE.Vector3(-85.636, 2.353, -3.829),
  415. isSpread: false,
  416. spreadDirection: 0,
  417. },
  418. {
  419. path0: new THREE.Vector3(-85.636, 2.353, -3.829),
  420. path1: new THREE.Vector3(-85.636, 1.026, -5.881),
  421. isSpread: false,
  422. spreadDirection: 0,
  423. },
  424. {
  425. path0: new THREE.Vector3(-85.636, 1.026, -5.881),
  426. path1: new THREE.Vector3(-85.618, 0.887, -12.862),
  427. isSpread: false,
  428. spreadDirection: 0,
  429. },
  430. {
  431. path0: new THREE.Vector3(-85.618, 0.827, -12.962),
  432. path1: new THREE.Vector3(80.404, 0.827, -12.962),
  433. isSpread: false,
  434. spreadDirection: 0,
  435. },
  436. {
  437. path0: new THREE.Vector3(80.404, 0.827, -12.962),
  438. path1: new THREE.Vector3(93.164, 0.85, -12.962),
  439. isSpread: true,
  440. spreadDirection: 1, // 1是由小变大,-1是由大变小
  441. },
  442. ];
  443. const downCurve = [
  444. {
  445. path0: new THREE.Vector3(-94.84, -0.388, 3.61),
  446. path1: new THREE.Vector3(-85.678, -0.393, 3.61),
  447. isSpread: true,
  448. spreadDirection: -1, //
  449. },
  450. {
  451. path0: new THREE.Vector3(-85.678, -0.393, 3.275),
  452. path1: new THREE.Vector3(-85.636, -0.392, -3.829),
  453. isSpread: false,
  454. spreadDirection: 0,
  455. },
  456. {
  457. path0: new THREE.Vector3(-85.636, -0.392, -3.829),
  458. path1: new THREE.Vector3(-85.636, 0.926, -5.881),
  459. isSpread: false,
  460. spreadDirection: 0,
  461. },
  462. {
  463. path0: new THREE.Vector3(-85.636, 1.026, -5.881),
  464. path1: new THREE.Vector3(-85.618, 0.887, -12.862),
  465. isSpread: false,
  466. spreadDirection: 0,
  467. },
  468. {
  469. path0: new THREE.Vector3(-85.618, 0.887, -12.962),
  470. path1: new THREE.Vector3(80.404, 0.887, -12.962),
  471. isSpread: false,
  472. spreadDirection: 0,
  473. },
  474. {
  475. path0: new THREE.Vector3(80.404, 0.887, -12.962),
  476. path1: new THREE.Vector3(93.164, 0.91, -12.962),
  477. isSpread: true,
  478. spreadDirection: 1, // 1是由小变大,-1是由大变小
  479. },
  480. ];
  481. const returnCurve = [
  482. {
  483. path0: new THREE.Vector3(93.164, 0.85, -12.962),
  484. path1: new THREE.Vector3(86.39, 0.827, -12.962),
  485. isSpread: false,
  486. spreadDirection: 2,
  487. },
  488. {
  489. path0: new THREE.Vector3(86.39, 0.827, -12.962),
  490. path1: new THREE.Vector3(83.341, 0.847, -17.658),
  491. isSpread: false,
  492. spreadDirection: 2,
  493. },
  494. {
  495. path0: new THREE.Vector3(83.341, 0.847, -17.658),
  496. path1: new THREE.Vector3(-29.077, 0.847, -17.658),
  497. isSpread: false,
  498. spreadDirection: 2,
  499. },
  500. {
  501. path0: new THREE.Vector3(-29.077, 0.847, -17.658),
  502. path1: new THREE.Vector3(-29.64, 0.827, -39.047),
  503. isSpread: false,
  504. spreadDirection: 2,
  505. },
  506. ];
  507. if (!topSmoke) {
  508. topSmoke = new Smoke('/model/img/texture-smoke.png', '#ffffff', 0, 0.75, 0.5, 400);
  509. topSmoke.setPath(topCurve);
  510. await topSmoke.setPoints();
  511. group?.add(topSmoke.points);
  512. }
  513. if (!downSmoke) {
  514. downSmoke = new Smoke('/model/img/texture-smoke.png', '#ffffff', 0, 0.75, 0.5, 400);
  515. downSmoke.setPath(downCurve);
  516. await downSmoke.setPoints();
  517. group?.add(downSmoke.points);
  518. }
  519. if (!returnSmoke) {
  520. returnSmoke = new Smoke('/model/img/texture-smoke.png', '#777777', 0, 0.35, 1.5, 200);
  521. returnSmoke.setPath(returnCurve);
  522. await returnSmoke.setPoints();
  523. group?.add(returnSmoke.points);
  524. }
  525. };
  526. const runFly = (deviceType, state) => {
  527. if (state === 'open') {
  528. if (deviceType === 'top') {
  529. if (downSmoke && downSmoke.frameId) {
  530. downSmoke.stopSmoke();
  531. }
  532. if (topSmoke && !topSmoke.frameId) {
  533. topSmoke.startSmoke();
  534. }
  535. } else {
  536. if (topSmoke && topSmoke.frameId) {
  537. topSmoke.stopSmoke();
  538. }
  539. if (downSmoke && !downSmoke.frameId) {
  540. downSmoke.startSmoke();
  541. }
  542. }
  543. if (returnSmoke && !returnSmoke.frameId) {
  544. returnSmoke?.startSmoke();
  545. }
  546. } else {
  547. if (deviceType === 'top') {
  548. if (topSmoke && topSmoke.frameId) {
  549. topSmoke.stopSmoke();
  550. }
  551. } else {
  552. if (downSmoke && downSmoke.frameId) {
  553. downSmoke.stopSmoke();
  554. }
  555. }
  556. }
  557. if (deviceType === 'all' && state === 'close') {
  558. returnSmoke?.stopSmoke();
  559. }
  560. };
  561. // 调频 30-50 (life 300 - 800) , 25 = (800 - 300)/ 20
  562. const setSmokeFrequency = (deviceType, frequency) => {
  563. const life = (frequency - 30) * 25;
  564. let duration = 0;
  565. let smoke;
  566. if (deviceType === 'top') {
  567. if (topLife == life) {
  568. return;
  569. }
  570. topLife = life;
  571. smoke = topSmoke;
  572. duration = (Math.abs(life - smoke.life) / 500) * 25;
  573. } else {
  574. if (downLife == life) {
  575. return;
  576. }
  577. downLife = life;
  578. smoke = downSmoke;
  579. duration = (Math.abs(life - smoke.life) / 500) * 25;
  580. }
  581. if (smoke) {
  582. gsap.to(smoke, {
  583. life: life,
  584. duration: duration,
  585. ease: 'easeInCubic',
  586. overwrite: true,
  587. });
  588. }
  589. };
  590. const clearFly = () => {
  591. if (topSmoke) topSmoke.clearSmoke();
  592. if (downSmoke) downSmoke.clearSmoke();
  593. if (returnSmoke) returnSmoke.clearSmoke();
  594. };
  595. // 初始化事件
  596. const startAnimation = () => {
  597. // 定义鼠标点击事件
  598. model.canvasContainer?.addEventListener('mousedown', mouseEvent.bind(null));
  599. model.canvasContainer?.addEventListener('pointerup', mouseUp);
  600. };
  601. // 鼠标点击、松开事件
  602. const mouseEvent = (event) => {
  603. if (event.button == 0) {
  604. model?.canvasContainer?.addEventListener('mousemove', mousemove);
  605. mouseDownFn(<UseThree>model, <THREE.Object3D>group, event, (intersects) => {
  606. intersects.find((intersect) => {
  607. const mesh = intersect.object;
  608. });
  609. });
  610. console.log('摄像头控制信息', model?.orbitControls, model?.camera);
  611. }
  612. };
  613. const mouseUp = () => {
  614. if (!model) return;
  615. mouseUpFn(model);
  616. model.canvasContainer?.removeEventListener('mousemove', mousemove);
  617. };
  618. const mousemove = () => {
  619. mousemoveFn();
  620. };
  621. export const mountedThree = (playerVal1) => {
  622. player1 = playerVal1;
  623. return new Promise((resolve) => {
  624. // model = VENT_PARAM['simulatedPassword'] ? new UseThree('#fanLocal3D', '#fanLocal3DCSS') : new UseThree('#fanLocal3D');
  625. model = new UseThree('#fanLocal3D', '#fanLocal3DCSS');
  626. model.setEnvMap('test1.hdr');
  627. model.renderer.toneMappingExposure = 1.0;
  628. if (model.renderer) {
  629. model.renderer.sortObjects = true;
  630. }
  631. resetCamera();
  632. model.setGLTFModel([modelName]).then(async (gltf) => {
  633. group = <THREE.Object3D>gltf[0];
  634. const Fengtongbu01 = group?.getObjectByName('Cylinder1054') as THREE.Mesh;
  635. if (Fengtongbu01) {
  636. const textMaterial = new THREE.MeshBasicMaterial({
  637. color: '#000',
  638. transparent: true,
  639. opacity: 0.3,
  640. side: THREE.DoubleSide, // 这里是双面渲染的意思
  641. });
  642. Fengtongbu01.material = textMaterial;
  643. Fengtongbu01.renderOrder = 300;
  644. }
  645. model?.scene?.add(group);
  646. setModalPosition();
  647. setControls();
  648. await initFly();
  649. model?.animate();
  650. addLight(model?.scene);
  651. fcFanObj = new fcFan(model);
  652. await fcFanObj.mountedThree();
  653. fmFanObj = new fmFan(model);
  654. await fmFanObj.mountedThree();
  655. startAnimation();
  656. resolve(model);
  657. });
  658. });
  659. };
  660. export const destroy = () => {
  661. if (model) {
  662. model.isRender = false;
  663. console.log('场景销毁后信息----------->', model.renderer?.info);
  664. clearFly();
  665. topSmoke = undefined;
  666. downSmoke = undefined;
  667. returnSmoke = undefined;
  668. if (fcFanObj) fcFanObj.destroy();
  669. if (fmFanObj) fmFanObj.destroy();
  670. group = undefined;
  671. model.destroy();
  672. model = undefined;
  673. }
  674. };