gate.threejs.ts 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  1. import * as THREE from 'three';
  2. import UseThree from '../../../../utils/threejs/useThree';
  3. import Fm1 from './gate.threejs.yy';
  4. import Fm3 from './gate.threejs.qd';
  5. import FmXR from './gate.threejs.xr';
  6. import Fm2 from './gate.threejs.three';
  7. import FmTwoSs from './gate.threejs.two.ss';
  8. import FmThreeTl from './gate.threejs.three.tl';
  9. import FmDc from './gate.threejs.window';
  10. import FmDcHJG from './gate.threejs.window.hjg';
  11. import { animateCamera } from '/@/utils/threejs/util';
  12. import useEvent from '../../../../utils/threejs/useEvent';
  13. import { getDictItemsByCode } from '/@/utils/dict';
  14. import { useGlobSetting } from '/@/hooks/setting';
  15. // 模型对象、 文字对象
  16. let model,
  17. fm1, //液压风门
  18. fm2, //三道风门收缩
  19. fm3, //气动风门
  20. fmXr: FmXR, //行人风门
  21. fmTwoSs, //
  22. fmThreeTl, // 三道推拉
  23. fmWindowHjg, // 带风窗
  24. fmWindow, // 带风窗
  25. group: THREE.Object3D,
  26. fmType = '',
  27. windowType = 'singleWindow';
  28. const rotationParam = {
  29. frontLeftDeg0: 0, // 前门初始
  30. frontLeftDeg1: 0, // 前门目标
  31. backLeftDeg0: 0, // 后门初始
  32. backLeftDeg1: 0, // 后门目标
  33. frontRightDeg0: 0, // 前门初始
  34. frontRightDeg1: 0, // 前门目标
  35. backRightDeg0: 0, // 后门初始
  36. backRightDeg1: 0, // 后门目标
  37. };
  38. const { mouseDownFn } = useEvent();
  39. // 初始化左右摇摆动画
  40. const startAnimation = () => {
  41. // 定义鼠标点击事件
  42. model.canvasContainer?.addEventListener('mousedown', mouseEvent.bind(null));
  43. model.canvasContainer?.addEventListener('pointerup', (event) => {
  44. event.stopPropagation();
  45. // 单道、 双道
  46. if (fmType === 'fm1') {
  47. fm1?.mouseUpModel.call(fm1);
  48. } else if (fmType === 'fm2') {
  49. fm2?.mouseUpModel.call(fm2);
  50. } else if (fmType === 'fmThreeTl') {
  51. fmThreeTl?.mouseUpModel.call(fmThreeTl);
  52. } else if (fmType === 'fm3') {
  53. fm3?.mouseUpModel.call(fm3);
  54. } else if (fmType === 'fmXr') {
  55. fmXr?.mouseUpModel.call(fmXr);
  56. } else if (fmType === 'fmTwoSs') {
  57. fmTwoSs?.mouseUpModel.call(fmTwoSs);
  58. } else if (fmType === 'fmWindow') {
  59. fmWindow.mouseUpModel.call(fmWindow);
  60. } else if (fmType === 'fmWindowHjg') {
  61. fmWindowHjg.mouseUpModel();
  62. }
  63. });
  64. };
  65. // 鼠标点击、松开事件
  66. const mouseEvent = (event) => {
  67. if (event.button == 0) {
  68. mouseDownFn(model, group, event, (intersects) => {
  69. if (fmType === 'fm1' && fm1) {
  70. fm1?.mousedownModel.call(fm1, intersects);
  71. } else if (fmType === 'fm2' && fm2) {
  72. fm2?.mousedownModel.call(fm2, intersects);
  73. } else if (fmType === 'fm3' && fm3) {
  74. fm3?.mousedownModel.call(fm3, intersects);
  75. } else if (fmType === 'fmXr' && fmXr) {
  76. fmXr?.mousedownModel.call(fmXr, intersects);
  77. } else if (fmType === 'fmTwoSs' && fmTwoSs) {
  78. fmTwoSs?.mousedownModel.call(fmTwoSs, intersects);
  79. } else if (fmType === 'fmThreeTl') {
  80. fmThreeTl?.mousedownModel.call(fmThreeTl, intersects);
  81. } else if (fmType === 'fmWindow' && fmWindow) {
  82. fmWindow.mousedownModel.call(fmWindow, intersects);
  83. } else if (fmType === 'fmWindowHjg' && fmWindowHjg) {
  84. fmWindowHjg.mousedownModel(intersects);
  85. }
  86. });
  87. console.log('摄像头控制信息', model.orbitControls, model.camera);
  88. }
  89. };
  90. export const addMonitorText = (selectData) => {
  91. if (fmType === 'fm1' && fm1) {
  92. return fm1?.addMonitorText.call(fm1, selectData);
  93. } else if (fmType === 'fm2' && fm2) {
  94. return fm2?.addMonitorText.call(fm2, selectData);
  95. } else if (fmType === 'fm3' && fm3) {
  96. return fm3?.addMonitorText.call(fm3, selectData);
  97. } else if (fmType === 'fmXr' && fmXr) {
  98. return fmXr?.addMonitorText.call(fmXr, selectData);
  99. } else if (fmType === 'fmTwoSs' && fmTwoSs) {
  100. return fmTwoSs?.addMonitorText.call(fmTwoSs, selectData);
  101. } else if (fmType === 'fmThreeTl') {
  102. fmThreeTl?.addMonitorText.call(fmThreeTl, selectData);
  103. } else if (fmType === 'fmWindow' && fmWindow) {
  104. fmWindow.addMonitorText.call(fmWindow, selectData);
  105. } else if (fmType === 'fmWindowHjg' && fmWindowHjg) {
  106. fmWindowHjg.addMonitorText(selectData);
  107. }
  108. };
  109. export const deviceDetailCard = () => {
  110. if (fmType === 'fm1') {
  111. return fm1?.deviceDetailCard.call(fm1);
  112. } else if (fmType === 'fm3') {
  113. return fm3?.deviceDetailCard.call(fm3);
  114. } else if (fmType === 'fmXr') {
  115. return fmXr?.deviceDetailCard.call(fmXr);
  116. } else {
  117. // return fm2.addMonitorText.call(fm2);
  118. }
  119. };
  120. export const play = (handlerState, flag?) => {
  121. if (fmType === 'fm1' && fm1) {
  122. return fm1.play.call(fm1, handlerState, flag);
  123. } else if (fmType === 'fm2' && fm2) {
  124. return fm2.play.call(fm2, handlerState, flag);
  125. } else if (fmType === 'fmWindow' && fmWindow) {
  126. return fmWindow.play.call(fmWindow, handlerState, flag);
  127. } else if (fmType === 'fmWindowHjg' && fmWindowHjg) {
  128. return fmWindowHjg.play.call(fmWindowHjg, handlerState, flag);
  129. } else if (fmType === 'fm3' && fm3) {
  130. return fm3.play.call(fm3, handlerState, flag);
  131. } else if (fmType === 'fmXr' && fmXr) {
  132. return fmXr.play.call(fmXr, handlerState, flag);
  133. } else if (fmType === 'fmTwoSs' && fmTwoSs) {
  134. return fmTwoSs.play.call(fmTwoSs, handlerState, flag);
  135. } else if (fmType === 'fmThreeTl') {
  136. fmThreeTl?.play.call(fmThreeTl, handlerState, flag);
  137. }
  138. };
  139. // export const playWindow = (rotationParam, flag) => {
  140. // if (fmType === 'fmWindow' && fmWindow) {
  141. // return fmWindow.playWindow.call(fmWindow, rotationParam, flag);
  142. // } else if (fmType === 'fmWindowHjg' && fmWindowHjg) {
  143. // return fmWindowHjg.playWindow.call(fmWindowHjg, rotationParam, flag);
  144. // }
  145. // };
  146. export function computePlay(data, maxarea, isFirst = false) {
  147. // 前门后窗 rearPresentValue1
  148. // 前门前窗 frontPresentValue1
  149. // 后门后窗 rearPresentValue2
  150. // 后门前窗 frontPresentValue2
  151. // data['frontArea'] = 70;
  152. // data['rearArea'] = 40;
  153. if (fmType === 'fmWindowHjg' && (data.rearPresentValue1 || data.frontPresentValue1 || data.rearPresentValue2 || data.frontPresentValue2)) {
  154. maxarea = 90;
  155. rotationParam.frontLeftDeg0 = (90 / maxarea) * Number(isFirst ? 0 : data.frontPresentValue1);
  156. rotationParam.frontRightDeg0 = (90 / maxarea) * Number(isFirst ? 0 : data.rearPresentValue1);
  157. rotationParam.frontLeftDeg1 = (90 / maxarea) * Number(data.frontPresentValue1) || 0;
  158. rotationParam.frontRightDeg1 = (90 / maxarea) * Number(data.rearPresentValue1) || 0;
  159. rotationParam.backLeftDeg0 = (90 / maxarea) * Number(isFirst ? 0 : data.frontPresentValue2);
  160. rotationParam.backRightDeg0 = (90 / maxarea) * Number(isFirst ? 0 : data.rearPresentValue2);
  161. rotationParam.backLeftDeg1 = (90 / maxarea) * Number(data.frontPresentValue2) || 0;
  162. rotationParam.backRightDeg1 = (90 / maxarea) * Number(data.rearPresentValue2) || 0;
  163. // rotationParam.backLeftDeg1 = 90;
  164. fmWindowHjg.playWindow(rotationParam, 1);
  165. fmWindowHjg.playWindow(rotationParam, 2);
  166. fmWindowHjg.playWindow(rotationParam, 3);
  167. fmWindowHjg.playWindow(rotationParam, 4);
  168. } else if (fmType === 'fmWindow' && data.frontPresentValue1 && data.frontPresentValue2 && data.rearPresentValue1 && data.rearPresentValue2) {
  169. maxarea = 90;
  170. rotationParam.frontLeftDeg0 = (90 / maxarea) * Number(isFirst ? 0 : data.frontPresentValue1);
  171. rotationParam.frontRightDeg0 = (90 / maxarea) * Number(isFirst ? 0 : data.frontPresentValue2);
  172. rotationParam.frontLeftDeg1 = (90 / maxarea) * Number(data.frontPresentValue1) || 0;
  173. rotationParam.frontRightDeg1 = (90 / maxarea) * Number(data.frontPresentValue2) || 0;
  174. rotationParam.backLeftDeg0 = (90 / maxarea) * Number(isFirst ? 0 : data.rearPresentValue1);
  175. rotationParam.backRightDeg0 = (90 / maxarea) * Number(isFirst ? 0 : data.rearPresentValue2);
  176. rotationParam.backLeftDeg1 = (90 / maxarea) * Number(data.rearPresentValue1) || 0;
  177. rotationParam.backRightDeg1 = (90 / maxarea) * Number(data.rearPresentValue2) || 0;
  178. fmWindow.playWindow(rotationParam, 1);
  179. fmWindow.playWindow(rotationParam, 2);
  180. fmWindow.playWindow(rotationParam, 3);
  181. fmWindow.playWindow(rotationParam, 4);
  182. }
  183. }
  184. // 切换风门类型
  185. export const setModelType = (type) => {
  186. fmType = type;
  187. return new Promise((resolve) => {
  188. // 暂停风门1动画
  189. if (fmType === 'fm1' && fm1 && fm1.group) {
  190. if (fm1.clipActionArr.frontDoor && fm1.clipActionArr.backDoor) {
  191. fm1.clipActionArr.frontDoor.reset();
  192. fm1.clipActionArr.frontDoor.time = 0.5;
  193. fm1.clipActionArr.backDoor.reset();
  194. fm1.clipActionArr.backDoor.time = 0.5;
  195. fm1.clipActionArr.frontDoor.stop();
  196. fm1.clipActionArr.backDoor.stop();
  197. }
  198. if (fm1.frontDamperOpenMesh) fm1.frontDamperOpenMesh.visible = false;
  199. if (fm1.frontDamperClosedMesh) fm1.frontDamperClosedMesh.visible = true;
  200. if (fm1.backDamperOpenMesh) fm1.backDamperOpenMesh.visible = false;
  201. if (fm1.backDamperClosedMesh) fm1.backDamperClosedMesh.visible = true;
  202. model.scene.remove(group);
  203. model.startAnimation = fm1.render.bind(fm1);
  204. group = fm1.group;
  205. group.rotation.y = 0;
  206. const oldCameraPosition = { x: -1000, y: 100, z: 500 };
  207. setTimeout(async () => {
  208. resolve(null);
  209. model.scene.add(fm1.group);
  210. await animateCamera(
  211. oldCameraPosition,
  212. { x: 0, y: 0, z: 0 },
  213. { x: 50.99, y: 69.32, z: 93.61 },
  214. { x: -10.04, y: -14.38, z: -31.4 },
  215. model,
  216. 0.8
  217. );
  218. }, 300);
  219. } else if (fmType === 'fm2' && fm2 && fm2.group) {
  220. if (fm2.clipActionArr.frontDoor && fm2.clipActionArr.backDoor) {
  221. fm2.clipActionArr.frontDoor.reset();
  222. fm2.clipActionArr.frontDoor.time = 0.5;
  223. fm2.clipActionArr.backDoor.reset();
  224. fm2.clipActionArr.backDoor.time = 0.5;
  225. fm2.clipActionArr.centerDoor.reset();
  226. fm2.clipActionArr.centerDoor.time = 0.5;
  227. fm2.clipActionArr.frontDoor.stop();
  228. fm2.clipActionArr.backDoor.stop();
  229. fm2.clipActionArr.centerDoor.stop();
  230. }
  231. // 显示单道风窗
  232. model.startAnimation = fm2.render.bind(fm2);
  233. model.scene.remove(group);
  234. group = fm2.group;
  235. const oldCameraPosition = { x: -761, y: 569, z: 871 };
  236. setTimeout(async () => {
  237. resolve(null);
  238. model.scene.add(fm2.group);
  239. const position = { x: -2.28, y: -0.91, z: -5.68 };
  240. await animateCamera(
  241. oldCameraPosition,
  242. { x: -2.27, y: -0.91, z: -5.67 },
  243. { x: 66.257, y: 57.539, z: 94.313 },
  244. { x: position.x, y: position.y, z: position.z },
  245. model,
  246. 0.6
  247. );
  248. }, 300);
  249. } else if (fmType === 'fmWindow' && fmWindow && fmWindow.group) {
  250. if (fmWindow.clipActionArr.frontDoor && fmWindow.clipActionArr.backDoor) {
  251. fmWindow.clipActionArr.frontDoor.reset();
  252. fmWindow.clipActionArr.frontDoor.time = 0.5;
  253. fmWindow.clipActionArr.backDoor.reset();
  254. fmWindow.clipActionArr.backDoor.time = 0.5;
  255. fmWindow.clipActionArr.frontDoor.stop();
  256. fmWindow.clipActionArr.backDoor.stop();
  257. }
  258. model.startAnimation = fmWindow.render.bind(fmWindow);
  259. model.scene.remove(group);
  260. group = fmWindow.group;
  261. const oldCameraPosition = { x: -761, y: 569, z: 871 };
  262. setTimeout(async () => {
  263. resolve(null);
  264. model.scene.add(fmWindow.group);
  265. const position = { x: -2.28, y: -0.91, z: -5.68 };
  266. await animateCamera(
  267. oldCameraPosition,
  268. { x: -2.27, y: -0.91, z: -5.67 },
  269. { x: 66.257, y: 57.539, z: 94.313 },
  270. { x: position.x, y: position.y, z: position.z },
  271. model,
  272. 0.6
  273. );
  274. }, 300);
  275. } else if (fmType === 'fmWindowHjg' && fmWindowHjg && fmWindowHjg.group) {
  276. if (fmWindowHjg.clipActionArr.frontDoor && fmWindowHjg.clipActionArr.backDoor) {
  277. fmWindowHjg.clipActionArr.frontDoor.reset();
  278. fmWindowHjg.clipActionArr.frontDoor.time = 0.5;
  279. fmWindowHjg.clipActionArr.backDoor.reset();
  280. fmWindowHjg.clipActionArr.backDoor.time = 0.5;
  281. fmWindowHjg.clipActionArr.frontDoor.stop();
  282. fmWindowHjg.clipActionArr.backDoor.stop();
  283. }
  284. model.startAnimation = fmWindowHjg.render.bind(fmWindowHjg);
  285. model.scene.remove(group);
  286. group = fmWindowHjg.group;
  287. const oldCameraPosition = { x: -761, y: 569, z: 871 };
  288. setTimeout(async () => {
  289. resolve(null);
  290. model.scene.add(fmWindowHjg.group);
  291. const position = { x: -2.28, y: -0.91, z: -5.68 };
  292. await animateCamera(
  293. oldCameraPosition,
  294. { x: -2.27, y: -0.91, z: -5.67 },
  295. { x: 66.257, y: 57.539, z: 94.313 },
  296. { x: position.x, y: position.y, z: position.z },
  297. model,
  298. 0.6
  299. );
  300. }, 300);
  301. } else if (fmType === 'fmThreeTl' && fmThreeTl && fmThreeTl.group) {
  302. if (fmThreeTl.clipActionArr.frontDoor && fmThreeTl.clipActionArr.backDoor && fmThreeTl.clipActionArr.centerDoor) {
  303. fmThreeTl.clipActionArr.frontDoor.reset();
  304. fmThreeTl.clipActionArr.frontDoor.time = 0.5;
  305. fmThreeTl.clipActionArr.backDoor.reset();
  306. fmThreeTl.clipActionArr.backDoor.time = 0.5;
  307. fmThreeTl.clipActionArr.centerDoor.reset();
  308. fmThreeTl.clipActionArr.centerDoor.time = 0.5;
  309. fmThreeTl.clipActionArr.frontDoor.stop();
  310. fmThreeTl.clipActionArr.backDoor.stop();
  311. fmThreeTl.clipActionArr.centerDoor.stop();
  312. }
  313. if (fmThreeTl.frontDamperOpenMesh) fmThreeTl.frontDamperOpenMesh.visible = false;
  314. if (fmThreeTl.frontDamperClosedMesh) fmThreeTl.frontDamperClosedMesh.visible = true;
  315. if (fmThreeTl.centerDamperOpenMesh) fmThreeTl.centerDamperOpenMesh.visible = false;
  316. if (fmThreeTl.centerDamperClosedMesh) fmThreeTl.centerDamperClosedMesh.visible = true;
  317. if (fmThreeTl.backDamperOpenMesh) fmThreeTl.backDamperOpenMesh.visible = false;
  318. if (fmThreeTl.backDamperClosedMesh) fmThreeTl.backDamperClosedMesh.visible = true;
  319. // 显示单道风窗
  320. model.startAnimation = fmThreeTl.render.bind(fmThreeTl);
  321. model.scene.remove(group);
  322. group = fmThreeTl.group;
  323. const oldCameraPosition = { x: -761, y: 569, z: 871 };
  324. setTimeout(async () => {
  325. resolve(null);
  326. model.scene.add(fmThreeTl.group);
  327. const position = { x: 31.873075535732386, y: -3.501715880262631, z: -15.490295891616942 };
  328. await animateCamera(
  329. oldCameraPosition,
  330. { x: -2.27, y: -0.91, z: -5.67 },
  331. { x: 88.60102093060523, y: 53.89462381404774, z: 109.90762232602137 },
  332. { x: position.x, y: position.y, z: position.z },
  333. model,
  334. 0.6
  335. );
  336. }, 300);
  337. } else if (fmType === 'fm3' && fm3 && fm3.group) {
  338. if (fm3.clipActionArr.frontDoor && fm3.clipActionArr.backDoor) {
  339. fm3.clipActionArr.frontDoor.reset();
  340. fm3.clipActionArr.frontDoor.time = 0.5;
  341. fm3.clipActionArr.backDoor.reset();
  342. fm3.clipActionArr.backDoor.time = 0.5;
  343. fm3.clipActionArr.frontDoor.stop();
  344. fm3.clipActionArr.backDoor.stop();
  345. }
  346. if (fm3.frontDamperOpenMesh) fm3.frontDamperOpenMesh.visible = false;
  347. if (fm3.frontDamperClosedMesh) fm3.frontDamperClosedMesh.visible = true;
  348. if (fm3.backDamperOpenMesh) fm3.backDamperOpenMesh.visible = false;
  349. if (fm3.backDamperClosedMesh) fm3.backDamperClosedMesh.visible = true;
  350. model.scene.remove(group);
  351. model.startAnimation = fm3.render.bind(fm3);
  352. group = fm3.group;
  353. group.rotation.y = 0;
  354. const oldCameraPosition = { x: -1000, y: 100, z: 500 };
  355. setTimeout(async () => {
  356. resolve(null);
  357. model.scene.add(fm3.group);
  358. await animateCamera(
  359. oldCameraPosition,
  360. { x: 0, y: 0, z: 0 },
  361. { x: 50.99, y: 69.32, z: 93.61 },
  362. { x: -10.04, y: -14.38, z: -31.4 },
  363. model,
  364. 0.8
  365. );
  366. }, 300);
  367. } else if (fmType === 'fmXr' && fmXr && fmXr.group) {
  368. if (fmXr.clipActionArr.frontDoor && fmXr.clipActionArr.backDoor) {
  369. fmXr.clipActionArr.frontDoor.reset();
  370. fmXr.clipActionArr.frontDoor.time = 0.5;
  371. fmXr.clipActionArr.backDoor.reset();
  372. fmXr.clipActionArr.backDoor.time = 0.5;
  373. fmXr.clipActionArr.frontDoor.stop();
  374. fmXr.clipActionArr.backDoor.stop();
  375. }
  376. if (fmXr.frontDamperOpenMesh) fmXr.frontDamperOpenMesh.visible = false;
  377. if (fmXr.frontDamperClosedMesh) fmXr.frontDamperClosedMesh.visible = true;
  378. if (fmXr.backDamperOpenMesh) fmXr.backDamperOpenMesh.visible = false;
  379. if (fmXr.backDamperClosedMesh) fmXr.backDamperClosedMesh.visible = true;
  380. model.startAnimation = fmXr.render.bind(fmXr);
  381. model.scene.remove(group);
  382. group = fmXr.group;
  383. group.rotation.y = 0;
  384. const oldCameraPosition = { x: -1000, y: 100, z: 500 };
  385. setTimeout(async () => {
  386. resolve(null);
  387. model.scene.add(fmXr.group);
  388. await animateCamera(
  389. oldCameraPosition,
  390. { x: 0, y: 0, z: 0 },
  391. { x: 50.99, y: 69.32, z: 93.61 },
  392. { x: -10.04, y: -14.38, z: -31.4 },
  393. model,
  394. 0.8
  395. );
  396. }, 300);
  397. } else if (fmType === 'fmTwoSs' && fmTwoSs && fmTwoSs.group) {
  398. if (fmTwoSs.clipActionArr.frontDoor && fmTwoSs.clipActionArr.backDoor) {
  399. fmTwoSs.clipActionArr.frontDoor.reset();
  400. fmTwoSs.clipActionArr.frontDoor.time = 0.5;
  401. fmTwoSs.clipActionArr.backDoor.reset();
  402. fmTwoSs.clipActionArr.backDoor.time = 0.5;
  403. fmTwoSs.clipActionArr.frontDoor.stop();
  404. fmTwoSs.clipActionArr.backDoor.stop();
  405. }
  406. if (fmTwoSs.frontDamperOpenMesh) fmTwoSs.frontDamperOpenMesh.visible = false;
  407. if (fmTwoSs.frontDamperClosedMesh) fmTwoSs.frontDamperClosedMesh.visible = true;
  408. if (fmTwoSs.backDamperOpenMesh) fmTwoSs.backDamperOpenMesh.visible = false;
  409. if (fmTwoSs.backDamperClosedMesh) fmTwoSs.backDamperClosedMesh.visible = true;
  410. model.startAnimation = fmTwoSs.render.bind(fmTwoSs);
  411. model.scene.remove(group);
  412. group = fmTwoSs.group;
  413. group.rotation.y = 0;
  414. const oldCameraPosition = { x: -1000, y: 100, z: 500 };
  415. setTimeout(async () => {
  416. resolve(null);
  417. model.scene.add(fmTwoSs.group);
  418. await animateCamera(
  419. oldCameraPosition,
  420. { x: 0, y: 0, z: 0 },
  421. { x: 50.99, y: 69.32, z: 93.61 },
  422. { x: -10.04, y: -14.38, z: -31.4 },
  423. model,
  424. 0.8
  425. );
  426. }, 300);
  427. }
  428. });
  429. };
  430. export const initCameraCanvas = async (playerVal1) => {
  431. if (fmType === 'fm1' && fm1) {
  432. return await fm1.initCamera.call(fm1, playerVal1);
  433. } else if (fmType === 'fm2' && fm2) {
  434. return fm2.initCamera.call(fm2, playerVal1);
  435. } else if (fmType === 'fm3' && fm3) {
  436. return fm3.initCamera.call(fm3, playerVal1);
  437. } else if (fmType === 'fmXr' && fmXr) {
  438. return fmXr.initCamera.call(fmXr, playerVal1);
  439. }
  440. };
  441. export const mountedThree = (playerDom) => {
  442. const { sysOrgCode } = useGlobSetting();
  443. debugger;
  444. // const sysOrgCode = 'gsgszdek';
  445. return new Promise(async (resolve) => {
  446. model = new UseThree('#damper3D', '', '#deviceDetail');
  447. model.setEnvMap('test1.hdr');
  448. model.renderer.toneMappingExposure = 0.9;
  449. model.camera.position.set(100, 0, 1000);
  450. switch (sysOrgCode) {
  451. case 'yjmdsankuang': //窑街三矿
  452. case 'yjmdhswmk': //窑街海石湾
  453. case 'yjmdjhmk': //窑街金河矿
  454. const FmYj = await import('./gate.threejs.yj');
  455. if (FmYj) fm3 = new FmYj.default(model);
  456. if (fm3) fm3.mountedThree(playerDom);
  457. const FmTwoYj = await import('./gate.threejs.two.yj');
  458. if (FmTwoYj) fmTwoSs = new FmTwoYj.default(model);
  459. fmTwoSs.mountedThree(playerDom);
  460. fmXr = new FmXR(model);
  461. fmXr.mountedThree(playerDom);
  462. resolve(null);
  463. break;
  464. case 'zmjthjg': //黄家沟
  465. const FmNoSubStation = await import('./gate.threejs.noStation');
  466. if (FmNoSubStation) fm3 = new FmNoSubStation.default(model);
  467. if (fm3) fm3.mountedThree(playerDom);
  468. fmXr = new FmXR(model);
  469. fmXr.mountedThree(playerDom);
  470. resolve(null);
  471. break;
  472. case 'gsgszdek': //大海则
  473. fmWindowHjg = new FmDc(model);
  474. if (fmWindowHjg) fmWindowHjg.mountedThree(playerDom);
  475. fm3 = new Fm3(model);
  476. fm3.mountedThree(playerDom);
  477. fmXr = new FmXR(model);
  478. fmXr.mountedThree(playerDom);
  479. resolve(null);
  480. break;
  481. case 'sdmtjtbltmk': //补连塔
  482. fm3 = new Fm3(model);
  483. fm3.mountedThree(playerDom);
  484. fmXr = new FmXR(model);
  485. fmXr.mountedThree(playerDom);
  486. // 三道门
  487. fmThreeTl = new FmThreeTl(model);
  488. if (fmThreeTl) fmThreeTl.mountedThree(playerDom);
  489. resolve(null);
  490. break;
  491. default:
  492. // 根据字典加载模型
  493. const dictCodes = getDictItemsByCode('gateStyle');
  494. if (dictCodes && dictCodes.length > 0) {
  495. for (let i = 0; i < dictCodes.length; i++) {
  496. const dict = dictCodes[i];
  497. switch (dict.value) {
  498. case 'fmXr':
  499. fmXr = new FmXR(model);
  500. fmXr.mountedThree(playerDom);
  501. break;
  502. case 'fmYy':
  503. fm1 = new Fm1(model);
  504. fm1.mountedThree(playerDom);
  505. break;
  506. case 'gate_qd':
  507. fm3 = new Fm3(model);
  508. await fm3.mountedThree();
  509. break;
  510. case 'fmSs':
  511. fmTwoSs = new FmTwoSs(model);
  512. await fmTwoSs.mountedThree();
  513. break;
  514. case 'fmtl3':
  515. fmThreeTl = new FmThreeTl(model);
  516. await fmThreeTl.mountedThree();
  517. break;
  518. case 'fmSs3':
  519. fm2 = new Fm2(model);
  520. await fm2.mountedThree();
  521. break;
  522. case 'fm_fc_hjg':
  523. fmWindowHjg = new FmDcHJG(model);
  524. await fmWindowHjg.mountedThree();
  525. break;
  526. case 'fm_fc':
  527. fmWindow = new FmDc(model);
  528. await fmWindow.mountedThree();
  529. break;
  530. }
  531. }
  532. resolve(null);
  533. } else {
  534. fm3 = new Fm3(model);
  535. fm3.mountedThree(playerDom);
  536. fmTwoSs = new FmTwoSs(model);
  537. fmTwoSs.mountedThree(playerDom);
  538. fm2 = new Fm2(model);
  539. fm2.mountedThree(playerDom);
  540. // 三道门
  541. fmThreeTl = new FmThreeTl(model);
  542. if (fmThreeTl) fmThreeTl.mountedThree(playerDom);
  543. fmXr = new FmXR(model);
  544. fmXr.mountedThree(playerDom);
  545. // 液压风门
  546. fm1 = new Fm1(model);
  547. fm1.mountedThree(playerDom);
  548. resolve(null);
  549. break;
  550. }
  551. }
  552. model.animate();
  553. startAnimation();
  554. });
  555. };
  556. export const destroy = () => {
  557. if (model) {
  558. model.isRender = false;
  559. if (fm1) fm1.destroy();
  560. if (fm2) fm2.destroy();
  561. if (fm3) fm3.destroy();
  562. if (fmXr) fmXr.destroy();
  563. if (fmTwoSs) fmTwoSs.destroy();
  564. if (fmWindowHjg) fmWindowHjg.destroy();
  565. if (fmWindow) fmWindow.destroy();
  566. if (fmThreeTl) fmThreeTl.destroy();
  567. fm1 = null;
  568. fm2 = null;
  569. fm3 = null;
  570. fmXr = null;
  571. fmWindow = null;
  572. fmWindowHjg = null;
  573. fmThreeTl = null;
  574. fmTwoSs = null;
  575. group = null;
  576. model.mixers = [];
  577. model.destroy();
  578. }
  579. model = null;
  580. };