main.threejs.ts 26 KB

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