main.threejs.ts 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765
  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.includes('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.includes('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.includes('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.includes('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.includes('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.includes('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 if (modalType === 'mainWindRect-Inverse') {
  324. mainObj.resetSmokeParam('back', selectData.Fan2FreqHz, duration);
  325. mainObj.resetSmokeParam('front', selectData.Fan1FreqHz, duration);
  326. if (selectData.Fan1StartStatus == 1) {
  327. // 主风机开启
  328. mainObj?.lookMotor('front', 'open', duration);
  329. mainObj?.openOrCloseValve('front', 'open', duration);
  330. // 1. 已经运行,首次切入动画
  331. // 2. 在页面上,切换动画
  332. if (selectData.Fan1FreqForwardRun == 1 && selectData.Fan1FreqReverseRun == 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.Fan1FreqHz, duration);
  341. await mainObj.setSmokeDirection('front', 'tubPositivePath');
  342. } else if (selectData.Fan1FreqReverseRun == 1 && selectData.Fan1FreqForwardRun == 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.Fan1FreqHz, 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.Fan1FreqHz, 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.Fan2StartStatus == 1) {
  369. // 主风机开启
  370. mainObj.lookMotor('back', 'open', duration);
  371. mainObj.openOrCloseValve('back', 'open', duration);
  372. // 1. 已经运行,首次切入动画
  373. // 2. 在页面上,切换动画
  374. if (selectData.Fan2FreqForwardRun == 1 && selectData.Fan2FreqReverseRun == 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.Fan2FreqHz, duration);
  384. await mainObj.setSmokeDirection('back', 'tubPositivePath');
  385. } else if (selectData.Fan2FreqReverseRun == 1 && selectData.Fan2FreqForwardRun == 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.Fan2FreqHz, 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.Fan2FreqHz, 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. } else {
  411. mainObj.resetSmokeParam('front', selectData.Fan2FreqHz, duration);
  412. mainObj.resetSmokeParam('back', selectData.Fan1FreqHz, duration);
  413. if (selectData.Fan2StartStatus == 1) {
  414. // 主风机开启
  415. mainObj?.lookMotor('front', 'open', duration);
  416. mainObj?.openOrCloseValve('front', 'open', duration);
  417. // 1. 已经运行,首次切入动画
  418. // 2. 在页面上,切换动画
  419. if (selectData.Fan2FreqForwardRun == 1 && selectData.Fan2FreqReverseRun == 0) {
  420. // 主风机正转
  421. if (mainObj['airChu2'] && !mainObj['airChu2'].visible) {
  422. mainObj['airJin1'].visible = false;
  423. mainObj['airJin2'].visible = false;
  424. mainObj['airChu1'].visible = false;
  425. mainObj['airChu2'].visible = true;
  426. }
  427. mainObj.startGearAnimation('front', 'open', 'tubPositivePath', selectData.Fan2FreqHz, duration);
  428. await mainObj.setSmokeDirection('front', 'tubPositivePath');
  429. } else if (selectData.Fan2FreqReverseRun == 1 && selectData.Fan2FreqForwardRun == 0) {
  430. // 主风机反转
  431. if (mainObj['airJin2'] && !mainObj['airJin2'].visible) {
  432. mainObj['airJin1'].visible = false;
  433. mainObj['airJin2'].visible = true;
  434. mainObj['airChu1'].visible = false;
  435. mainObj['airChu2'].visible = false;
  436. }
  437. mainObj.startGearAnimation('front', 'open', 'tubInversePath', selectData.Fan2FreqHz, duration);
  438. await mainObj.setSmokeDirection('front', 'tubInversePath');
  439. } else {
  440. // 默认主风机正转
  441. if (mainObj['airChu2'] && !mainObj['airChu2'].visible) {
  442. mainObj['airJin1'].visible = false;
  443. mainObj['airJin2'].visible = false;
  444. mainObj['airChu1'].visible = false;
  445. mainObj['airChu2'].visible = true;
  446. }
  447. mainObj.startGearAnimation('front', 'open', 'tubPositivePath', selectData.Fan2FreqHz, duration);
  448. await mainObj.setSmokeDirection('front', 'tubPositivePath');
  449. }
  450. if (!mainObj?.frontSmoke?.frameId) mainObj?.frontSmoke?.startSmoke(duration);
  451. } else {
  452. // 主风机停止
  453. mainObj.closeDevice('front');
  454. }
  455. if (selectData.Fan1StartStatus == 1) {
  456. // 主风机开启
  457. mainObj.lookMotor('back', 'open', duration);
  458. mainObj.openOrCloseValve('back', 'open', duration);
  459. // 1. 已经运行,首次切入动画
  460. // 2. 在页面上,切换动画
  461. if (selectData.Fan1FreqForwardRun == 1 && selectData.Fan1FreqReverseRun == 0) {
  462. // 主风机正转
  463. // 主风机正转
  464. if (mainObj['airChu1'] && !mainObj['airChu1'].visible) {
  465. mainObj['airJin1'].visible = false;
  466. mainObj['airJin2'].visible = false;
  467. mainObj['airChu1'].visible = true;
  468. mainObj['airChu2'].visible = false;
  469. }
  470. mainObj.startGearAnimation('back', 'open', 'tubPositivePath', selectData.Fan1FreqHz, duration);
  471. await mainObj.setSmokeDirection('back', 'tubPositivePath');
  472. } else if (selectData.Fan1FreqReverseRun == 1 && selectData.Fan1FreqForwardRun == 0) {
  473. // 主风机反转
  474. if (mainObj['airJin1'] && !mainObj['airJin1'].visible) {
  475. mainObj['airJin1'].visible = true;
  476. mainObj['airJin2'].visible = false;
  477. mainObj['airChu1'].visible = false;
  478. mainObj['airChu2'].visible = false;
  479. }
  480. mainObj.startGearAnimation('back', 'open', 'tubInversePath', selectData.Fan1FreqHz, duration);
  481. await mainObj.setSmokeDirection('back', 'tubInversePath');
  482. } else {
  483. if (mainObj['airChu1'] && !mainObj['airChu1'].visible) {
  484. mainObj['airJin1'].visible = false;
  485. mainObj['airJin2'].visible = false;
  486. mainObj['airChu1'].visible = true;
  487. mainObj['airChu2'].visible = false;
  488. }
  489. mainObj.startGearAnimation('back', 'open', 'tubPositivePath', selectData.Fan1FreqHz, duration);
  490. await mainObj.setSmokeDirection('back', 'tubPositivePath');
  491. }
  492. if (!mainObj?.backSmoke?.frameId) mainObj?.backSmoke?.startSmoke(duration);
  493. } else {
  494. // 主风机停止
  495. mainObj.closeDevice('back');
  496. }
  497. }
  498. // 防爆门动画
  499. if (modalType.includes('mainWindRect') && selectData['ExplosionVentOpen'] == 1 && explosionVentOpen !== 1) {
  500. if (explosionVentOpen == -1) {
  501. // 直接打开
  502. mainObj.playAnimation('open', 0);
  503. } else {
  504. mainObj.playAnimation('open');
  505. }
  506. explosionVentOpen = 1;
  507. explosionVentClose = 0;
  508. }
  509. if (modalType.includes('mainWindRect') && selectData['ExplosionVentClose'] == 1 && explosionVentClose !== 1) {
  510. if (explosionVentOpen == -1) {
  511. // 直接关闭
  512. mainObj.playAnimation('close', 0);
  513. } else {
  514. mainObj.playAnimation('close');
  515. }
  516. explosionVentClose = 1;
  517. explosionVentOpen = 0;
  518. }
  519. }
  520. };
  521. // 切换风机类型
  522. export const setModelType = (type) => {
  523. if (!model) return;
  524. modalType = type;
  525. return new Promise((resolve) => {
  526. // 停止气流动画
  527. mainWindObj?.stopSmoke();
  528. mainXjWindObj?.stopSmoke();
  529. mainLj3WindObj?.stopSmoke();
  530. mainFanLjDtObj?.stopSmoke();
  531. mainLjWindObj?.stopSmoke();
  532. if (group) model?.scene?.remove(group);
  533. if (modalType.includes('mainWindRect') && mainWindObj && mainWindObj.group) {
  534. (<UseThree>model).startAnimation = mainWindObj.render.bind(mainWindObj);
  535. group = mainWindObj.group;
  536. setTimeout(async () => {
  537. resolve(null);
  538. // const position = mainWindObj.group.position;
  539. const position = new THREE.Vector3(-1.0127, -3.4717, -7.864);
  540. const oldCameraPosition = { x: -332.39, y: 283.47, z: 438.61 };
  541. await animateCamera(
  542. oldCameraPosition,
  543. { x: -3.41, y: -29.01, z: 8.84 },
  544. { x: -1.7927, y: 70.8399, z: 120.8451 },
  545. { x: position.x, y: position.y, z: position.z },
  546. model,
  547. 0.8
  548. );
  549. if (group) model?.scene?.add(group);
  550. }, 300);
  551. } else if (modalType === 'mainXjWindRect' && mainXjWindObj && mainXjWindObj.group) {
  552. (<UseThree>model).startAnimation = mainXjWindObj.render.bind(mainXjWindObj);
  553. group = mainXjWindObj.group;
  554. setTimeout(async () => {
  555. resolve(null);
  556. // const position = mainWindObj.group.position;
  557. const position = new THREE.Vector3(12.96, 23.17, -23.16);
  558. const oldCameraPosition = { x: -332.39, y: 283.47, z: 438.61 };
  559. await animateCamera(
  560. oldCameraPosition,
  561. { x: -3.41, y: -29.01, z: 8.84 },
  562. { x: 12.09, y: 105.51, z: 119.45 },
  563. { x: position.x, y: position.y, z: position.z },
  564. model,
  565. 0.8
  566. );
  567. if (group) model?.scene?.add(group);
  568. }, 300);
  569. } else if (modalType === 'mainLjWindRect' && mainLjWindObj && mainLjWindObj.group) {
  570. (<UseThree>model).startAnimation = mainLjWindObj.render.bind(mainLjWindObj);
  571. group = mainLjWindObj.group;
  572. setTimeout(async () => {
  573. resolve(null);
  574. // const position = mainWindObj.group.position;
  575. const position = new THREE.Vector3(-32.98, -4.15, -8.14);
  576. const oldCameraPosition = { x: -332.39, y: 283.47, z: 438.61 };
  577. await animateCamera(
  578. oldCameraPosition,
  579. { x: -3.41, y: -29.01, z: 8.84 },
  580. { x: -33.9, y: 82.51, z: 141.97 },
  581. { x: position.x, y: position.y, z: position.z },
  582. model,
  583. 0.8
  584. );
  585. if (group) model?.scene?.add(group);
  586. }, 300);
  587. } else if (modalType === 'mainWindRect3' && mainLj3WindObj && mainLj3WindObj.group) {
  588. (<UseThree>model).startAnimation = mainLj3WindObj.render.bind(mainLj3WindObj);
  589. group = mainLj3WindObj.group;
  590. setTimeout(async () => {
  591. resolve(null);
  592. const position = new THREE.Vector3(2.815, -7.014, -5.985);
  593. const oldCameraPosition = { x: -332.39, y: 283.47, z: 438.61 };
  594. await animateCamera(
  595. oldCameraPosition,
  596. { x: -3.41, y: -29.01, z: 8.84 },
  597. { x: 5.128, y: 72.363, z: 93.655 },
  598. { x: position.x, y: position.y, z: position.z },
  599. model,
  600. 0.8
  601. );
  602. if (group) model?.scene?.add(group);
  603. }, 300);
  604. } else if (modalType === 'mainLjDtWindRect' && mainFanLjDtObj && mainFanLjDtObj.group) {
  605. (<UseThree>model).startAnimation = mainFanLjDtObj.render.bind(mainFanLjDtObj);
  606. group = mainFanLjDtObj.group;
  607. setTimeout(async () => {
  608. resolve(null);
  609. const position = new THREE.Vector3(2.815, -7.014, -5.985);
  610. const oldCameraPosition = { x: -332.39, y: 283.47, z: 438.61 };
  611. await animateCamera(
  612. oldCameraPosition,
  613. { x: -3.41, y: -29.01, z: 8.84 },
  614. { x: 5.128, y: 72.363, z: 93.655 },
  615. { x: position.x, y: position.y, z: position.z },
  616. model,
  617. 0.8
  618. );
  619. if (group) model?.scene?.add(group);
  620. }, 300);
  621. }
  622. });
  623. };
  624. export const mountedThree = (playerVal1) => {
  625. return new Promise(async (resolve) => {
  626. model = new UseThree('#main3D', '#main3DCSS');
  627. if (!model || !model.renderer || !model.camera) return;
  628. model.setEnvMap('test1.hdr');
  629. model.renderer.toneMappingExposure = 1.0;
  630. if (model.renderer) {
  631. model.renderer.sortObjects = true;
  632. }
  633. addLight();
  634. setControls();
  635. resetCamera();
  636. model.setGLTFModel(['bg']).then(async (gltf) => {
  637. bgGroup = gltf[0] as THREE.Object3D;
  638. bgGroup.position.set(3.43, 27.13, 22.0);
  639. model?.scene?.add(bgGroup);
  640. // 这里根据字典判断
  641. const dictCodes = getDictItemsByCode('mainFanType');
  642. if (dictCodes && dictCodes.length > 0) {
  643. for (let i = 0; i < dictCodes.length; i++) {
  644. const dict = dictCodes[i];
  645. switch (dict.value) {
  646. case 'lijing':
  647. modalType = 'mainWindRect';
  648. mainWindObj = new mainWindRect(model, playerVal1);
  649. await mainWindObj.mountedThree();
  650. break;
  651. case 'xiejing':
  652. modalType = 'mainXjWindRect';
  653. mainXjWindObj = new mainXjWindRect(model, playerVal1);
  654. await mainXjWindObj.mountedThree();
  655. break;
  656. case 'lijing1':
  657. modalType = 'mainLjWindRect';
  658. mainLjWindObj = new mainLjWindRect(model, playerVal1);
  659. await mainLjWindObj.mountedThree();
  660. break;
  661. case 'lijing_3':
  662. modalType = 'mainWindRect3';
  663. mainLj3WindObj = new mainWindLj3(model, playerVal1);
  664. await mainLj3WindObj.mountedThree();
  665. break;
  666. case 'lijing_1':
  667. modalType = 'mainLjDtWindRect';
  668. mainFanLjDtObj = new mainWindLjDt(model);
  669. await mainFanLjDtObj.mountedThree();
  670. break;
  671. }
  672. }
  673. } else {
  674. mainWindObj = new mainWindRect(model, playerVal1);
  675. await mainWindObj.mountedThree();
  676. }
  677. model?.animate();
  678. resolve(null);
  679. if (mainWindObj) {
  680. if (mainWindObj.airJin1) mainWindObj.airJin1.visible = false;
  681. if (mainWindObj.airJin2) mainWindObj.airJin2.visible = false;
  682. if (mainWindObj.airChu1) mainWindObj.airChu1.visible = false;
  683. if (mainWindObj.airChu2) mainWindObj.airChu2.visible = false;
  684. }
  685. if (mainXjWindObj) {
  686. if (mainXjWindObj.airJin1) mainXjWindObj.airJin1.visible = false;
  687. if (mainXjWindObj.airJin2) mainXjWindObj.airJin2.visible = false;
  688. if (mainXjWindObj.airChu1) mainXjWindObj.airChu1.visible = false;
  689. if (mainXjWindObj.airChu2) mainXjWindObj.airChu2.visible = false;
  690. }
  691. if (mainLjWindObj) {
  692. if (mainLjWindObj.airChu2) mainLjWindObj.airChu2.visible = false;
  693. if (mainLjWindObj.airJin1) mainLjWindObj.airJin1.visible = false;
  694. if (mainLjWindObj.airJin2) mainLjWindObj.airJin2.visible = false;
  695. if (mainLjWindObj.airChu1) mainLjWindObj.airChu1.visible = false;
  696. }
  697. if (mainLj3WindObj) {
  698. if (mainLj3WindObj.airChu2) mainLj3WindObj.airChu2.visible = false;
  699. if (mainLj3WindObj.airJin1) mainLj3WindObj.airJin1.visible = false;
  700. if (mainLj3WindObj.airJin2) mainLj3WindObj.airJin2.visible = false;
  701. if (mainLj3WindObj.airChu1) mainLj3WindObj.airChu1.visible = false;
  702. }
  703. if (mainFanLjDtObj) {
  704. // if (mainFanLjDtObj.airChu2) mainFanLjDtObj.airChu2.visible = false;
  705. // if (mainFanLjDtObj.airJin1) mainFanLjDtObj.airJin1.visible = false;
  706. // if (mainFanLjDtObj.airJin2) mainFanLjDtObj.airJin2.visible = false;
  707. // if (mainFanLjDtObj.airChu1) mainFanLjDtObj.airChu1.visible = false;
  708. }
  709. });
  710. startAnimation();
  711. });
  712. };
  713. export const destroy = () => {
  714. if (model) {
  715. model.isRender = false;
  716. console.log('场景销毁前信息----------->', model.renderer?.info);
  717. mainWindObj?.destroy();
  718. mainWindObj = undefined;
  719. mainXjWindObj?.destroy();
  720. mainXjWindObj = undefined;
  721. mainLjWindObj?.destroy();
  722. mainLjWindObj = undefined;
  723. model.clearGroup(bgGroup);
  724. bgGroup = undefined;
  725. group = undefined;
  726. model.destroy();
  727. model = undefined;
  728. }
  729. };