main.threejs.ts 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  1. import * as THREE from 'three';
  2. import { animateCamera } from '/@/utils/threejs/util';
  3. import UseThree from '../../../../utils/threejs/useThree';
  4. import mainWindRect from './mainWind.threejs';
  5. import mainXjWindRect from './mainWind.xj.threejs';
  6. import mainLjWindRect from './mainWind.lj.threejs';
  7. import mainWindLj3 from './mainWind.li3.threejs';
  8. import mainWindLjDt from './mainWind.lidt.threejs';
  9. import useEvent from '../../../../utils/threejs/useEvent';
  10. import { getDictItemsByCode } from '/@/utils/dict';
  11. // import * as dat from 'dat.gui';
  12. // const gui = new dat.GUI();
  13. // gui.domElement.style = 'position:absolute;top:100px;left:10px;z-index:99999999999999';
  14. // 模型对象、 文字对象
  15. let model: UseThree | undefined, //
  16. group: THREE.Object3D | undefined,
  17. bgGroup: THREE.Object3D | undefined,
  18. mainWindObj: mainWindRect | undefined,
  19. mainXjWindObj: mainXjWindRect | undefined,
  20. mainLjWindObj: mainLjWindRect | undefined,
  21. mainLj3WindObj: mainWindLj3 | undefined,
  22. mainFanLjDtObj: mainWindLjDt | undefined,
  23. modalType = 'mainWindRect',
  24. explosionVentClose = -1,
  25. explosionVentOpen = -1;
  26. const { mouseDownFn, mousemoveFn, mouseUpFn } = useEvent();
  27. // 打灯光
  28. const addLight = () => {
  29. const directionalLight = new THREE.DirectionalLight(0xffffff, 1);
  30. directionalLight.position.set(63, 258, -261);
  31. model?.scene?.add(directionalLight);
  32. const pointLight6 = new THREE.PointLight(0xffffff, 1.5, 300);
  33. pointLight6.position.set(64, -12, 129);
  34. pointLight6.shadow.bias = 0.05;
  35. model?.scene?.add(pointLight6);
  36. //
  37. const pointLight7 = new THREE.PointLight(0xffffff, 1, 500);
  38. pointLight7.position.set(21, 64, 75);
  39. pointLight7.shadow.bias = -0.05;
  40. model?.scene?.add(pointLight7);
  41. };
  42. // 重置摄像头
  43. const resetCamera = () => {
  44. if (!model) return;
  45. model.camera?.position.set(-500, 0, 2000);
  46. model.orbitControls?.update();
  47. model.camera?.updateProjectionMatrix();
  48. };
  49. const setControls = () => {
  50. if (model && model.orbitControls) {
  51. model.orbitControls.panSpeed = 0.5;
  52. model.orbitControls.rotateSpeed = 0.5;
  53. model.orbitControls.maxPolarAngle = Math.PI / 3;
  54. model.orbitControls.minPolarAngle = Math.PI / 4;
  55. }
  56. };
  57. // 初始化事件
  58. const startAnimation = () => {
  59. // 定义鼠标点击事件
  60. model?.canvasContainer?.addEventListener('mousedown', mouseEvent.bind(null));
  61. model?.canvasContainer?.addEventListener('pointerup', mouseUp);
  62. };
  63. // 鼠标点击、松开事件
  64. const mouseEvent = (event) => {
  65. if (event.button == 0) {
  66. model?.canvasContainer?.addEventListener('mousemove', mousemove);
  67. mouseDownFn(<UseThree>model, <THREE.Object3D>group, event, (intersects) => {
  68. if (modalType === 'mainWindRect' && mainWindObj) {
  69. mainWindObj?.mousedownModel.call(mainWindObj, intersects);
  70. } else if (modalType === 'mainXjWindRect' && mainXjWindObj) {
  71. mainXjWindObj?.mousedownModel.call(mainXjWindObj, intersects);
  72. } else if (modalType === 'mainWindRect3' && mainLj3WindObj) {
  73. mainLj3WindObj?.mousedownModel.call(mainLj3WindObj, intersects);
  74. } else if (modalType === 'mainLjDtWindRect' && mainFanLjDtObj) {
  75. mainFanLjDtObj?.mousedownModel.call(mainFanLjDtObj, intersects);
  76. }
  77. });
  78. }
  79. };
  80. const mouseUp = () => {
  81. if (!model) return;
  82. mouseUpFn(model);
  83. model.canvasContainer?.removeEventListener('mousemove', mousemove);
  84. };
  85. const mousemove = () => {
  86. mousemoveFn();
  87. };
  88. /* 添加监控数据 */
  89. export const addText = () => {
  90. if (!mainWindObj) return;
  91. if (modalType === 'mainWindRect' && mainWindObj) {
  92. return mainWindObj.addCssText.call(mainWindObj);
  93. } else if (modalType === 'mainXjWindRect' && mainXjWindObj) {
  94. return mainXjWindObj.addCssText.call(mainXjWindObj);
  95. } else if (modalType === 'mainLjWindRect' && mainLjWindObj) {
  96. return mainLjWindObj.addCssText.call(mainLjWindObj);
  97. } else if (modalType === 'mainWindRect3' && mainLj3WindObj) {
  98. return mainLj3WindObj.addCssText.call(mainLj3WindObj);
  99. } else if (modalType === 'mainLjDtWindRect' && mainFanLjDtObj) {
  100. return mainFanLjDtObj.addCssText.call(mainFanLjDtObj);
  101. }
  102. };
  103. /* 刷新echarts曲线图 */
  104. export const resetEcharts = (selectData) => {
  105. if (!mainWindObj) return;
  106. if (modalType === 'mainWindRect' && mainWindObj) {
  107. return mainWindObj.addEcharts.call(mainWindObj);
  108. } else if (modalType === 'mainXjWindRect' && mainXjWindObj) {
  109. return mainXjWindObj.addEcharts.call(mainXjWindObj);
  110. } else if (modalType === 'mainLjWindRect' && mainLjWindObj) {
  111. return mainLjWindObj.addEcharts.call(mainLjWindObj);
  112. } else if (modalType === 'mainWindRect3' && mainLj3WindObj) {
  113. return mainLj3WindObj.addEcharts.call(mainLj3WindObj);
  114. }
  115. };
  116. /**
  117. *
  118. * @param controlType //操作类型
  119. * @param deviceType // 设备类型,前后风机
  120. * @param frequencyVal // 频率
  121. * @param state // 启停状态
  122. * @param smokeDirection // 气流路径
  123. * @returns
  124. */
  125. export const play = (controlType, deviceType, frequencyVal?, state?, smokeDirection?) => {
  126. if (!mainWindObj) return;
  127. if (modalType === 'mainWindRect' && mainWindObj) {
  128. return mainWindObj.playSmoke.call(mainWindObj, controlType, deviceType, frequencyVal, state, smokeDirection);
  129. } else if (modalType === 'mainXjWindRect' && mainXjWindObj) {
  130. return mainXjWindObj.playSmoke.call(mainXjWindObj, controlType, deviceType, frequencyVal, state, smokeDirection);
  131. } else if (modalType === 'mainLjWindRect' && mainLjWindObj) {
  132. return mainLjWindObj.playSmoke.call(mainLjWindObj, controlType, deviceType, frequencyVal, state, smokeDirection);
  133. } else if (modalType === 'mainWindRect3' && mainLj3WindObj) {
  134. return mainLj3WindObj.playSmoke.call(mainLj3WindObj, controlType, deviceType, frequencyVal, state, smokeDirection);
  135. } else if (modalType === 'mainLjDtWindRect' && mainFanLjDtObj) {
  136. return mainFanLjDtObj.playSmoke.call(mainFanLjDtObj, controlType, deviceType, frequencyVal, state, smokeDirection);
  137. }
  138. };
  139. export const playAnimate1 = async (selectData, duration?) => {
  140. if (!mainWindObj) return;
  141. let mainObj: mainWindRect | mainXjWindRect | undefined;
  142. if (modalType === 'mainWindRect') {
  143. mainObj = mainWindObj;
  144. } else if (modalType === 'mainXjWindRect') {
  145. mainObj = mainXjWindObj;
  146. } else if (modalType === 'mainLjWindRect') {
  147. mainObj = mainLjWindObj;
  148. } else if (modalType === 'mainWindRect3') {
  149. mainObj = mainLj3WindObj;
  150. } else if (modalType === 'mainLjDtWindRect') {
  151. mainObj = mainFanLjDtObj;
  152. }
  153. if (selectData && mainObj) {
  154. if (selectData.Fan1WindowOpen !== undefined) {
  155. // 主风机水平窗开启
  156. if (selectData.Fan1WindowOpen == 1) mainObj?.openOrCloseWindow('front', 'openWindow');
  157. if (selectData.Fan1WindowOpen == 0) mainObj?.openOrCloseWindow('front', 'closeWindow');
  158. }
  159. if (selectData.Fan2WindowOpen !== undefined) {
  160. // 备风机水平窗开启
  161. if (selectData.Fan2WindowOpen == 1) mainObj?.openOrCloseWindow('back', 'openWindow');
  162. if (selectData.Fan2WindowOpen == 0) mainObj?.openOrCloseWindow('back', 'closeWindow');
  163. }
  164. if (selectData.Fan1ButterflyOpen !== undefined) {
  165. if (selectData.Fan1ButterflyOpen == 1) {
  166. // 主风机蝶阀打开
  167. mainObj.openOrCloseValve('front', 'open', duration);
  168. } else {
  169. // 主风机蝶阀关闭
  170. mainObj.openOrCloseValve('front', 'close', duration);
  171. }
  172. }
  173. if (selectData.Fan2ButterflyOpen !== undefined) {
  174. if (selectData.Fan2ButterflyOpen == 1) {
  175. // 主风机蝶阀打开
  176. mainObj.openOrCloseValve('back', 'open', duration);
  177. } else {
  178. // 主风机蝶阀关闭
  179. mainObj.openOrCloseValve('back', 'close', duration);
  180. }
  181. }
  182. if (selectData.Fan1FreqHz !== undefined) {
  183. // 主风机频率设置
  184. mainObj.resetSmokeParam('front', selectData.Fan1FreqHz, duration);
  185. }
  186. if (selectData.Fan2FreqHz !== undefined) {
  187. // 主风机频率设置
  188. mainObj.resetSmokeParam('back', selectData.Fan2FreqHz, duration);
  189. }
  190. if (selectData.Fan1StartStatus) {
  191. if (selectData.Fan1StartStatus == 1) {
  192. // 主风机开启
  193. mainObj.lookMotor('front', 'open', duration);
  194. // if (selectData.Fan1FreqForwardRun && selectData.Fan1FreqForwardRun == 1) {
  195. // // 主风机正转
  196. // await mainWindObj.setSmokeDirection('front', 'tubPositivePath');
  197. // } else if (selectData.Fan1FreqReverseRun && selectData.Fan1FreqReverseRun == 1) {
  198. // // 主风机反转
  199. // await mainWindObj.setSmokeDirection('front', 'tubInversePath');
  200. // }
  201. // 齿轮转动
  202. mainObj.startGearAnimation('front', 'open', 'tubPositivePath', selectData.Fan1FreqHz, duration);
  203. await mainObj.setSmokeDirection('front', 'tubPositivePath');
  204. if (!mainObj.frontSmoke?.frameId) mainObj?.frontSmoke?.startSmoke(duration);
  205. } else {
  206. mainObj?.lookMotor('front', 'close', duration);
  207. }
  208. }
  209. if (selectData.Fan2StartStatus) {
  210. if (selectData.Fan2StartStatus == 1) {
  211. // 备风机开启
  212. mainObj.lookMotor('back', 'open', duration);
  213. // if (selectData.Fan2FreqForwardRun && selectData.Fan2FreqForwardRun == 1) {
  214. // // 主风机正转
  215. // } else if (selectData.Fan2FreqReverseRun && selectData.Fan2FreqReverseRun == 1) {
  216. // // 主风机反转
  217. // }
  218. await mainObj.setSmokeDirection('back', 'tubPositivePath');
  219. if (!mainObj.backSmoke?.frameId) mainObj?.backSmoke?.startSmoke(duration);
  220. } else {
  221. mainObj?.lookMotor('back', 'close', duration);
  222. }
  223. }
  224. }
  225. };
  226. export const playAnimate = async (selectData, duration?) => {
  227. // if (Number(selectData.Fan1FreqHz) < 0) selectData.Fan1FreqHz = Math.abs(Number(selectData.Fan1FreqHz));
  228. // if (Number(selectData.Fan2FreqHz) < 0) selectData.Fan2FreqHz = Math.abs(Number(selectData.Fan2FreqHz));
  229. if (!mainWindObj) return;
  230. let mainObj: mainWindRect | mainXjWindRect | mainWindLj3 | mainWindLjDt | undefined;
  231. if (modalType === 'mainWindRect') {
  232. mainObj = mainWindObj;
  233. } else if (modalType === 'mainXjWindRect') {
  234. mainObj = mainXjWindObj;
  235. } else if (modalType === 'mainLjWindRect') {
  236. mainObj = mainLjWindObj;
  237. } else if (modalType === 'mainWindRect3') {
  238. mainObj = mainLj3WindObj;
  239. } else if (modalType === 'mainLjDtWindRect') {
  240. mainObj = mainFanLjDtObj;
  241. }
  242. if (selectData && mainObj) {
  243. if (selectData['Fan1FreqHz'] == undefined || selectData['Fan1FreqHz'] == null || selectData['Fan1FreqHz'] == '') selectData['Fan1FreqHz'] = 50;
  244. if (selectData['Fan2FreqHz'] == undefined || selectData['Fan2FreqHz'] == null || selectData['Fan2FreqHz'] == '') selectData['Fan2FreqHz'] = 50;
  245. if (selectData['Fan3FreqHz'] == undefined || selectData['Fan3FreqHz'] == null || selectData['Fan3FreqHz'] == '') selectData['Fan3FreqHz'] = 50;
  246. if (modalType === 'mainWindRect3') {
  247. mainObj.resetSmokeParam('front', selectData.Fan1FreqHz, duration);
  248. mainObj.resetSmokeParam('center', selectData.Fan2FreqHz, duration);
  249. mainObj.resetSmokeParam('back', selectData.Fan3FreqHz, duration);
  250. if (selectData.Fan1StartStatus == 1) {
  251. // 主风机开启
  252. mainObj.lookMotor('front', 'open', duration);
  253. mainObj.openOrCloseValve('front', 'open', duration);
  254. // 1. 已经运行,首次切入动画
  255. // 2. 在页面上,切换动画
  256. if (selectData.Fan1FreqForwardRun == 1 && selectData.Fan1FreqReverseRun == 0) {
  257. // 主风机正转
  258. // 主风机正转
  259. mainObj.startGearAnimation('front', 'open', 'tubPositivePath', selectData.Fan1FreqHz, duration);
  260. await mainObj.setSmokeDirection('front', 'tubPositivePath');
  261. } else if (selectData.Fan1FreqReverseRun == 1 && selectData.Fan1FreqForwardRun == 0) {
  262. mainObj.startGearAnimation('front', 'open', 'tubInversePath', selectData.Fan1FreqHz, duration);
  263. await mainObj.setSmokeDirection('front', 'tubInversePath');
  264. } else {
  265. mainObj.startGearAnimation('front', 'open', 'tubPositivePath', selectData.Fan1FreqHz, duration);
  266. await mainObj.setSmokeDirection('front', 'tubPositivePath');
  267. }
  268. if (!mainObj?.frontSmoke?.frameId) mainObj?.frontSmoke?.startSmoke(duration);
  269. } else {
  270. // 主风机停止
  271. mainObj.closeDevice('front');
  272. }
  273. if (selectData.Fan2StartStatus == 1) {
  274. // 主风机开启
  275. mainObj?.lookMotor('center', 'open', duration);
  276. mainObj?.openOrCloseValve('center', 'open', duration);
  277. // 1. 已经运行,首次切入动画
  278. // 2. 在页面上,切换动画
  279. if (selectData.Fan2FreqForwardRun == 1 && selectData.Fan2FreqReverseRun == 0) {
  280. // 主风机正转
  281. mainObj.startGearAnimation('center', 'open', 'tubPositivePath', selectData.Fan2FreqHz, duration);
  282. await mainObj.setSmokeDirection('center', 'tubPositivePath');
  283. } else if (selectData.Fan2FreqReverseRun == 1 && selectData.Fan2FreqForwardRun == 0) {
  284. // 主风机反转
  285. mainObj.startGearAnimation('center', 'open', 'tubInversePath', selectData.Fan2FreqHz, duration);
  286. await mainObj.setSmokeDirection('center', 'tubInversePath');
  287. } else {
  288. // 默认主风机正转
  289. mainObj.startGearAnimation('center', 'open', 'tubPositivePath', selectData.Fan2FreqHz, duration);
  290. await mainObj.setSmokeDirection('center', 'tubPositivePath');
  291. }
  292. if (!mainObj?.centerSmoke?.frameId) mainObj?.centerSmoke?.startSmoke(duration);
  293. } else {
  294. // 主风机停止
  295. mainObj.closeDevice('center');
  296. }
  297. if (selectData.Fan3StartStatus == 1) {
  298. // 主风机开启
  299. mainObj?.lookMotor('back', 'open', duration);
  300. mainObj?.openOrCloseValve('back', 'open', duration);
  301. // 1. 已经运行,首次切入动画
  302. // 2. 在页面上,切换动画
  303. if (selectData.Fan2FreqForwardRun == 1 && selectData.Fan2FreqReverseRun == 0) {
  304. // 主风机正转
  305. mainObj.startGearAnimation('back', 'open', 'tubPositivePath', selectData.Fan2FreqHz, duration);
  306. await mainObj.setSmokeDirection('back', 'tubPositivePath');
  307. } else if (selectData.Fan2FreqReverseRun == 1 && selectData.Fan2FreqForwardRun == 0) {
  308. // 主风机反转
  309. mainObj.startGearAnimation('back', 'open', 'tubInversePath', selectData.Fan2FreqHz, duration);
  310. await mainObj.setSmokeDirection('back', 'tubInversePath');
  311. } else {
  312. // 默认主风机正转
  313. mainObj.startGearAnimation('back', 'open', 'tubPositivePath', selectData.Fan2FreqHz, duration);
  314. await mainObj.setSmokeDirection('back', 'tubPositivePath');
  315. }
  316. if (!mainObj?.backSmoke?.frameId) mainObj?.backSmoke?.startSmoke(duration);
  317. } else {
  318. // 主风机停止
  319. mainObj.closeDevice('back');
  320. }
  321. } else if (modalType === 'mainLjDtWindRect') {
  322. (mainObj as mainWindLjDt).playSmoke(selectData.Fan1StartStatus == 1, selectData.Fan2FreqForwardRun == 1, selectData.Fan2FreqReverseRun == 1);
  323. } else {
  324. mainObj.resetSmokeParam('front', selectData.Fan2FreqHz, duration);
  325. mainObj.resetSmokeParam('back', selectData.Fan1FreqHz, duration);
  326. if (selectData.Fan2StartStatus == 1) {
  327. // 主风机开启
  328. mainObj?.lookMotor('front', 'open', duration);
  329. mainObj?.openOrCloseValve('front', 'open', duration);
  330. // 1. 已经运行,首次切入动画
  331. // 2. 在页面上,切换动画
  332. if (selectData.Fan2FreqForwardRun == 1 && selectData.Fan2FreqReverseRun == 0) {
  333. // 主风机正转
  334. if (mainObj['airChu2'] && !mainObj['airChu2'].visible) {
  335. mainObj['airJin1'].visible = false;
  336. mainObj['airJin2'].visible = false;
  337. mainObj['airChu1'].visible = false;
  338. mainObj['airChu2'].visible = true;
  339. }
  340. mainObj.startGearAnimation('front', 'open', 'tubPositivePath', selectData.Fan2FreqHz, duration);
  341. await mainObj.setSmokeDirection('front', 'tubPositivePath');
  342. } else if (selectData.Fan2FreqReverseRun == 1 && selectData.Fan2FreqForwardRun == 0) {
  343. // 主风机反转
  344. if (mainObj['airJin2'] && !mainObj['airJin2'].visible) {
  345. mainObj['airJin1'].visible = false;
  346. mainObj['airJin2'].visible = true;
  347. mainObj['airChu1'].visible = false;
  348. mainObj['airChu2'].visible = false;
  349. }
  350. mainObj.startGearAnimation('front', 'open', 'tubInversePath', selectData.Fan2FreqHz, duration);
  351. await mainObj.setSmokeDirection('front', 'tubInversePath');
  352. } else {
  353. // 默认主风机正转
  354. if (mainObj['airChu2'] && !mainObj['airChu2'].visible) {
  355. mainObj['airJin1'].visible = false;
  356. mainObj['airJin2'].visible = false;
  357. mainObj['airChu1'].visible = false;
  358. mainObj['airChu2'].visible = true;
  359. }
  360. mainObj.startGearAnimation('front', 'open', 'tubPositivePath', selectData.Fan2FreqHz, duration);
  361. await mainObj.setSmokeDirection('front', 'tubPositivePath');
  362. }
  363. if (!mainObj?.frontSmoke?.frameId) mainObj?.frontSmoke?.startSmoke(duration);
  364. } else {
  365. // 主风机停止
  366. mainObj.closeDevice('front');
  367. }
  368. if (selectData.Fan1StartStatus == 1) {
  369. // 主风机开启
  370. mainObj.lookMotor('back', 'open', duration);
  371. mainObj.openOrCloseValve('back', 'open', duration);
  372. // 1. 已经运行,首次切入动画
  373. // 2. 在页面上,切换动画
  374. if (selectData.Fan1FreqForwardRun == 1 && selectData.Fan1FreqReverseRun == 0) {
  375. // 主风机正转
  376. // 主风机正转
  377. if (mainObj['airChu1'] && !mainObj['airChu1'].visible) {
  378. mainObj['airJin1'].visible = false;
  379. mainObj['airJin2'].visible = false;
  380. mainObj['airChu1'].visible = true;
  381. mainObj['airChu2'].visible = false;
  382. }
  383. mainObj.startGearAnimation('back', 'open', 'tubPositivePath', selectData.Fan1FreqHz, duration);
  384. await mainObj.setSmokeDirection('back', 'tubPositivePath');
  385. } else if (selectData.Fan1FreqReverseRun == 1 && selectData.Fan1FreqForwardRun == 0) {
  386. // 主风机反转
  387. if (mainObj['airJin1'] && !mainObj['airJin1'].visible) {
  388. mainObj['airJin1'].visible = true;
  389. mainObj['airJin2'].visible = false;
  390. mainObj['airChu1'].visible = false;
  391. mainObj['airChu2'].visible = false;
  392. }
  393. mainObj.startGearAnimation('back', 'open', 'tubInversePath', selectData.Fan1FreqHz, duration);
  394. await mainObj.setSmokeDirection('back', 'tubInversePath');
  395. } else {
  396. if (mainObj['airChu1'] && !mainObj['airChu1'].visible) {
  397. mainObj['airJin1'].visible = false;
  398. mainObj['airJin2'].visible = false;
  399. mainObj['airChu1'].visible = true;
  400. mainObj['airChu2'].visible = false;
  401. }
  402. mainObj.startGearAnimation('back', 'open', 'tubPositivePath', selectData.Fan1FreqHz, duration);
  403. await mainObj.setSmokeDirection('back', 'tubPositivePath');
  404. }
  405. if (!mainObj?.backSmoke?.frameId) mainObj?.backSmoke?.startSmoke(duration);
  406. } else {
  407. // 主风机停止
  408. mainObj.closeDevice('back');
  409. }
  410. }
  411. // 防爆门动画
  412. if (modalType === 'mainWindRect' && selectData['ExplosionVentOpen'] == 1 && explosionVentOpen !== 1) {
  413. if (explosionVentOpen == -1) {
  414. // 直接打开
  415. mainObj.playAnimation('open', 0);
  416. } else {
  417. mainObj.playAnimation('open');
  418. }
  419. explosionVentOpen = 1;
  420. explosionVentClose = 0;
  421. }
  422. if (modalType === 'mainWindRect' && selectData['ExplosionVentClose'] == 1 && explosionVentClose !== 1) {
  423. if (explosionVentOpen == -1) {
  424. // 直接关闭
  425. mainObj.playAnimation('close', 0);
  426. } else {
  427. mainObj.playAnimation('close');
  428. }
  429. explosionVentClose = 1;
  430. explosionVentOpen = 0;
  431. }
  432. }
  433. };
  434. // 切换风机类型
  435. export const setModelType = (type) => {
  436. if (!model) return;
  437. modalType = type;
  438. return new Promise((resolve) => {
  439. // 停止气流动画
  440. mainWindObj?.stopSmoke();
  441. mainXjWindObj?.stopSmoke();
  442. mainLj3WindObj?.stopSmoke();
  443. mainFanLjDtObj?.stopSmoke();
  444. mainLjWindObj?.stopSmoke();
  445. if (group) model?.scene?.remove(group);
  446. if (modalType === 'mainWindRect' && mainWindObj && mainWindObj.group) {
  447. (<UseThree>model).startAnimation = mainWindObj.render.bind(mainWindObj);
  448. group = mainWindObj.group;
  449. setTimeout(async () => {
  450. resolve(null);
  451. // const position = mainWindObj.group.position;
  452. const position = new THREE.Vector3(-1.0127, -3.4717, -7.864);
  453. const oldCameraPosition = { x: -332.39, y: 283.47, z: 438.61 };
  454. await animateCamera(
  455. oldCameraPosition,
  456. { x: -3.41, y: -29.01, z: 8.84 },
  457. { x: -1.7927, y: 70.8399, z: 120.8451 },
  458. { x: position.x, y: position.y, z: position.z },
  459. model,
  460. 0.8
  461. );
  462. if (group) model?.scene?.add(group);
  463. }, 300);
  464. } else if (modalType === 'mainXjWindRect' && mainXjWindObj && mainXjWindObj.group) {
  465. (<UseThree>model).startAnimation = mainXjWindObj.render.bind(mainXjWindObj);
  466. group = mainXjWindObj.group;
  467. setTimeout(async () => {
  468. resolve(null);
  469. // const position = mainWindObj.group.position;
  470. const position = new THREE.Vector3(12.96, 23.17, -23.16);
  471. const oldCameraPosition = { x: -332.39, y: 283.47, z: 438.61 };
  472. await animateCamera(
  473. oldCameraPosition,
  474. { x: -3.41, y: -29.01, z: 8.84 },
  475. { x: 12.09, y: 105.51, z: 119.45 },
  476. { x: position.x, y: position.y, z: position.z },
  477. model,
  478. 0.8
  479. );
  480. if (group) model?.scene?.add(group);
  481. }, 300);
  482. } else if (modalType === 'mainLjWindRect' && mainLjWindObj && mainLjWindObj.group) {
  483. (<UseThree>model).startAnimation = mainLjWindObj.render.bind(mainLjWindObj);
  484. group = mainLjWindObj.group;
  485. setTimeout(async () => {
  486. resolve(null);
  487. // const position = mainWindObj.group.position;
  488. const position = new THREE.Vector3(-32.98, -4.15, -8.14);
  489. const oldCameraPosition = { x: -332.39, y: 283.47, z: 438.61 };
  490. await animateCamera(
  491. oldCameraPosition,
  492. { x: -3.41, y: -29.01, z: 8.84 },
  493. { x: -33.9, y: 82.51, z: 141.97 },
  494. { x: position.x, y: position.y, z: position.z },
  495. model,
  496. 0.8
  497. );
  498. if (group) model?.scene?.add(group);
  499. }, 300);
  500. } else if (modalType === 'mainWindRect3' && mainLj3WindObj && mainLj3WindObj.group) {
  501. (<UseThree>model).startAnimation = mainLj3WindObj.render.bind(mainLj3WindObj);
  502. group = mainLj3WindObj.group;
  503. setTimeout(async () => {
  504. resolve(null);
  505. const position = new THREE.Vector3(2.815, -7.014, -5.985);
  506. const oldCameraPosition = { x: -332.39, y: 283.47, z: 438.61 };
  507. await animateCamera(
  508. oldCameraPosition,
  509. { x: -3.41, y: -29.01, z: 8.84 },
  510. { x: 5.128, y: 72.363, z: 93.655 },
  511. { x: position.x, y: position.y, z: position.z },
  512. model,
  513. 0.8
  514. );
  515. if (group) model?.scene?.add(group);
  516. }, 300);
  517. } else if (modalType === 'mainLjDtWindRect' && mainFanLjDtObj && mainFanLjDtObj.group) {
  518. (<UseThree>model).startAnimation = mainFanLjDtObj.render.bind(mainFanLjDtObj);
  519. group = mainFanLjDtObj.group;
  520. setTimeout(async () => {
  521. resolve(null);
  522. const position = new THREE.Vector3(2.815, -7.014, -5.985);
  523. const oldCameraPosition = { x: -332.39, y: 283.47, z: 438.61 };
  524. await animateCamera(
  525. oldCameraPosition,
  526. { x: -3.41, y: -29.01, z: 8.84 },
  527. { x: 5.128, y: 72.363, z: 93.655 },
  528. { x: position.x, y: position.y, z: position.z },
  529. model,
  530. 0.8
  531. );
  532. if (group) model?.scene?.add(group);
  533. }, 300);
  534. }
  535. });
  536. };
  537. export const mountedThree = (playerVal1) => {
  538. return new Promise(async (resolve) => {
  539. model = new UseThree('#main3D', '#main3DCSS');
  540. if (!model || !model.renderer || !model.camera) return;
  541. model.setEnvMap('test1.hdr');
  542. model.renderer.toneMappingExposure = 1.0;
  543. if (model.renderer) {
  544. model.renderer.sortObjects = true;
  545. }
  546. addLight();
  547. setControls();
  548. resetCamera();
  549. model.setGLTFModel(['bg']).then(async (gltf) => {
  550. bgGroup = gltf[0] as THREE.Object3D;
  551. bgGroup.position.set(3.43, 27.13, 22.0);
  552. model?.scene?.add(bgGroup);
  553. // 这里根据字典判断
  554. const dictCodes = getDictItemsByCode('mainFanType');
  555. if (dictCodes && dictCodes.length > 0) {
  556. for (let i = 0; i < dictCodes.length; i++) {
  557. const dict = dictCodes[i];
  558. switch (dict.value) {
  559. case 'lijing':
  560. modalType = 'mainWindRect';
  561. mainWindObj = new mainWindRect(model, playerVal1);
  562. await mainWindObj.mountedThree();
  563. break;
  564. case 'xiejing':
  565. modalType = 'mainXjWindRect';
  566. mainXjWindObj = new mainXjWindRect(model, playerVal1);
  567. await mainXjWindObj.mountedThree();
  568. break;
  569. case 'lijing1':
  570. modalType = 'mainLjWindRect';
  571. mainLjWindObj = new mainLjWindRect(model, playerVal1);
  572. await mainLjWindObj.mountedThree();
  573. break;
  574. case 'lijing_3':
  575. modalType = 'mainWindRect3';
  576. mainLj3WindObj = new mainWindLj3(model, playerVal1);
  577. await mainLj3WindObj.mountedThree();
  578. break;
  579. case 'lijing_1':
  580. modalType = 'mainLjDtWindRect';
  581. mainFanLjDtObj = new mainWindLjDt(model);
  582. await mainFanLjDtObj.mountedThree();
  583. break;
  584. }
  585. }
  586. } else {
  587. mainWindObj = new mainWindRect(model, playerVal1);
  588. await mainWindObj.mountedThree();
  589. }
  590. model?.animate();
  591. resolve(null);
  592. if (mainWindObj) {
  593. if (mainWindObj.airJin1) mainWindObj.airJin1.visible = false;
  594. if (mainWindObj.airJin2) mainWindObj.airJin2.visible = false;
  595. if (mainWindObj.airChu1) mainWindObj.airChu1.visible = false;
  596. if (mainWindObj.airChu2) mainWindObj.airChu2.visible = false;
  597. }
  598. if (mainXjWindObj) {
  599. if (mainXjWindObj.airJin1) mainXjWindObj.airJin1.visible = false;
  600. if (mainXjWindObj.airJin2) mainXjWindObj.airJin2.visible = false;
  601. if (mainXjWindObj.airChu1) mainXjWindObj.airChu1.visible = false;
  602. if (mainXjWindObj.airChu2) mainXjWindObj.airChu2.visible = false;
  603. }
  604. if (mainLjWindObj) {
  605. if (mainLjWindObj.airChu2) mainLjWindObj.airChu2.visible = false;
  606. if (mainLjWindObj.airJin1) mainLjWindObj.airJin1.visible = false;
  607. if (mainLjWindObj.airJin2) mainLjWindObj.airJin2.visible = false;
  608. if (mainLjWindObj.airChu1) mainLjWindObj.airChu1.visible = false;
  609. }
  610. if (mainLj3WindObj) {
  611. if (mainLj3WindObj.airChu2) mainLj3WindObj.airChu2.visible = false;
  612. if (mainLj3WindObj.airJin1) mainLj3WindObj.airJin1.visible = false;
  613. if (mainLj3WindObj.airJin2) mainLj3WindObj.airJin2.visible = false;
  614. if (mainLj3WindObj.airChu1) mainLj3WindObj.airChu1.visible = false;
  615. }
  616. if (mainFanLjDtObj) {
  617. // if (mainFanLjDtObj.airChu2) mainFanLjDtObj.airChu2.visible = false;
  618. // if (mainFanLjDtObj.airJin1) mainFanLjDtObj.airJin1.visible = false;
  619. // if (mainFanLjDtObj.airJin2) mainFanLjDtObj.airJin2.visible = false;
  620. // if (mainFanLjDtObj.airChu1) mainFanLjDtObj.airChu1.visible = false;
  621. }
  622. });
  623. startAnimation();
  624. });
  625. };
  626. export const destroy = () => {
  627. if (model) {
  628. model.isRender = false;
  629. console.log('场景销毁前信息----------->', model.renderer?.info);
  630. mainWindObj?.destroy();
  631. mainWindObj = undefined;
  632. mainXjWindObj?.destroy();
  633. mainXjWindObj = undefined;
  634. mainLjWindObj?.destroy();
  635. mainLjWindObj = undefined;
  636. model.clearGroup(bgGroup);
  637. bgGroup = undefined;
  638. group = undefined;
  639. model.destroy();
  640. model = undefined;
  641. }
  642. };