gate.threejs.ts 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  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 (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. if (fmType === 'fmWindowHjg' && fmWindowHjg) {
  165. fmWindowHjg.playWindow(rotationParam, 1);
  166. fmWindowHjg.playWindow(rotationParam, 2);
  167. fmWindowHjg.playWindow(rotationParam, 3);
  168. fmWindowHjg.playWindow(rotationParam, 4);
  169. }
  170. } else if (data.frontArea && data.rearArea) {
  171. maxarea = 90;
  172. rotationParam.frontLeftDeg0 = (90 / maxarea) * Number(isFirst ? 0 : data.frontArea);
  173. rotationParam.frontRightDeg0 = (90 / maxarea) * Number(isFirst ? 0 : data.frontArea);
  174. rotationParam.frontLeftDeg1 = (90 / maxarea) * Number(data.frontArea) || 0;
  175. rotationParam.frontRightDeg1 = (90 / maxarea) * Number(data.frontArea) || 0;
  176. rotationParam.backLeftDeg0 = (90 / maxarea) * Number(isFirst ? 0 : data.rearArea);
  177. rotationParam.backRightDeg0 = (90 / maxarea) * Number(isFirst ? 0 : data.rearArea);
  178. rotationParam.backLeftDeg1 = (90 / maxarea) * Number(data.rearArea) || 0;
  179. rotationParam.backRightDeg1 = (90 / maxarea) * Number(data.rearArea) || 0;
  180. if (fmType === 'fmWindow' && fmWindow) {
  181. fmWindow.playWindow(rotationParam, 1);
  182. fmWindow.playWindow(rotationParam, 2);
  183. fmWindow.playWindow(rotationParam, 3);
  184. fmWindow.playWindow(rotationParam, 4);
  185. }
  186. }
  187. }
  188. // 切换风门类型
  189. export const setModelType = (type) => {
  190. fmType = type;
  191. return new Promise((resolve) => {
  192. // 暂停风门1动画
  193. if (fmType === 'fm1' && fm1 && fm1.group) {
  194. if (fm1.clipActionArr.frontDoor && fm1.clipActionArr.backDoor) {
  195. fm1.clipActionArr.frontDoor.reset();
  196. fm1.clipActionArr.frontDoor.time = 0.5;
  197. fm1.clipActionArr.backDoor.reset();
  198. fm1.clipActionArr.backDoor.time = 0.5;
  199. fm1.clipActionArr.frontDoor.stop();
  200. fm1.clipActionArr.backDoor.stop();
  201. }
  202. if (fm1.frontDamperOpenMesh) fm1.frontDamperOpenMesh.visible = false;
  203. if (fm1.frontDamperClosedMesh) fm1.frontDamperClosedMesh.visible = true;
  204. if (fm1.backDamperOpenMesh) fm1.backDamperOpenMesh.visible = false;
  205. if (fm1.backDamperClosedMesh) fm1.backDamperClosedMesh.visible = true;
  206. model.scene.remove(group);
  207. model.startAnimation = fm1.render.bind(fm1);
  208. group = fm1.group;
  209. group.rotation.y = 0;
  210. const oldCameraPosition = { x: -1000, y: 100, z: 500 };
  211. setTimeout(async () => {
  212. resolve(null);
  213. model.scene.add(fm1.group);
  214. await animateCamera(
  215. oldCameraPosition,
  216. { x: 0, y: 0, z: 0 },
  217. { x: 50.99, y: 69.32, z: 93.61 },
  218. { x: -10.04, y: -14.38, z: -31.4 },
  219. model,
  220. 0.8
  221. );
  222. }, 300);
  223. } else if (fmType === 'fm2' && fm2 && fm2.group) {
  224. if (fm2.clipActionArr.frontDoor && fm2.clipActionArr.backDoor) {
  225. fm2.clipActionArr.frontDoor.reset();
  226. fm2.clipActionArr.frontDoor.time = 0.5;
  227. fm2.clipActionArr.backDoor.reset();
  228. fm2.clipActionArr.backDoor.time = 0.5;
  229. fm2.clipActionArr.centerDoor.reset();
  230. fm2.clipActionArr.centerDoor.time = 0.5;
  231. fm2.clipActionArr.frontDoor.stop();
  232. fm2.clipActionArr.backDoor.stop();
  233. fm2.clipActionArr.centerDoor.stop();
  234. }
  235. // 显示单道风窗
  236. model.startAnimation = fm2.render.bind(fm2);
  237. model.scene.remove(group);
  238. group = fm2.group;
  239. const oldCameraPosition = { x: -761, y: 569, z: 871 };
  240. setTimeout(async () => {
  241. resolve(null);
  242. model.scene.add(fm2.group);
  243. const position = { x: -2.28, y: -0.91, z: -5.68 };
  244. await animateCamera(
  245. oldCameraPosition,
  246. { x: -2.27, y: -0.91, z: -5.67 },
  247. { x: 66.257, y: 57.539, z: 94.313 },
  248. { x: position.x, y: position.y, z: position.z },
  249. model,
  250. 0.6
  251. );
  252. }, 300);
  253. } else if (fmType === 'fmWindow' && fmWindow && fmWindow.group) {
  254. if (fmWindow.clipActionArr.frontDoor && fmWindow.clipActionArr.backDoor) {
  255. fmWindow.clipActionArr.frontDoor.reset();
  256. fmWindow.clipActionArr.frontDoor.time = 0.5;
  257. fmWindow.clipActionArr.backDoor.reset();
  258. fmWindow.clipActionArr.backDoor.time = 0.5;
  259. fmWindow.clipActionArr.frontDoor.stop();
  260. fmWindow.clipActionArr.backDoor.stop();
  261. }
  262. model.startAnimation = fmWindow.render.bind(fmWindow);
  263. model.scene.remove(group);
  264. group = fmWindow.group;
  265. const oldCameraPosition = { x: -761, y: 569, z: 871 };
  266. setTimeout(async () => {
  267. resolve(null);
  268. model.scene.add(fmWindow.group);
  269. const position = { x: -2.28, y: -0.91, z: -5.68 };
  270. await animateCamera(
  271. oldCameraPosition,
  272. { x: -2.27, y: -0.91, z: -5.67 },
  273. { x: 66.257, y: 57.539, z: 94.313 },
  274. { x: position.x, y: position.y, z: position.z },
  275. model,
  276. 0.6
  277. );
  278. }, 300);
  279. } else if (fmType === 'fmWindowHjg' && fmWindowHjg && fmWindowHjg.group) {
  280. if (fmWindowHjg.clipActionArr.frontDoor && fmWindowHjg.clipActionArr.backDoor) {
  281. fmWindowHjg.clipActionArr.frontDoor.reset();
  282. fmWindowHjg.clipActionArr.frontDoor.time = 0.5;
  283. fmWindowHjg.clipActionArr.backDoor.reset();
  284. fmWindowHjg.clipActionArr.backDoor.time = 0.5;
  285. fmWindowHjg.clipActionArr.frontDoor.stop();
  286. fmWindowHjg.clipActionArr.backDoor.stop();
  287. }
  288. model.startAnimation = fmWindowHjg.render.bind(fmWindowHjg);
  289. model.scene.remove(group);
  290. group = fmWindowHjg.group;
  291. const oldCameraPosition = { x: -761, y: 569, z: 871 };
  292. setTimeout(async () => {
  293. resolve(null);
  294. model.scene.add(fmWindowHjg.group);
  295. const position = { x: -2.28, y: -0.91, z: -5.68 };
  296. await animateCamera(
  297. oldCameraPosition,
  298. { x: -2.27, y: -0.91, z: -5.67 },
  299. { x: 66.257, y: 57.539, z: 94.313 },
  300. { x: position.x, y: position.y, z: position.z },
  301. model,
  302. 0.6
  303. );
  304. }, 300);
  305. } else if (fmType === 'fmThreeTl' && fmThreeTl && fmThreeTl.group) {
  306. if (fmThreeTl.clipActionArr.frontDoor && fmThreeTl.clipActionArr.backDoor && fmThreeTl.clipActionArr.centerDoor) {
  307. fmThreeTl.clipActionArr.frontDoor.reset();
  308. fmThreeTl.clipActionArr.frontDoor.time = 0.5;
  309. fmThreeTl.clipActionArr.backDoor.reset();
  310. fmThreeTl.clipActionArr.backDoor.time = 0.5;
  311. fmThreeTl.clipActionArr.centerDoor.reset();
  312. fmThreeTl.clipActionArr.centerDoor.time = 0.5;
  313. fmThreeTl.clipActionArr.frontDoor.stop();
  314. fmThreeTl.clipActionArr.backDoor.stop();
  315. fmThreeTl.clipActionArr.centerDoor.stop();
  316. }
  317. if (fmThreeTl.frontDamperOpenMesh) fmThreeTl.frontDamperOpenMesh.visible = false;
  318. if (fmThreeTl.frontDamperClosedMesh) fmThreeTl.frontDamperClosedMesh.visible = true;
  319. if (fmThreeTl.centerDamperOpenMesh) fmThreeTl.centerDamperOpenMesh.visible = false;
  320. if (fmThreeTl.centerDamperClosedMesh) fmThreeTl.centerDamperClosedMesh.visible = true;
  321. if (fmThreeTl.backDamperOpenMesh) fmThreeTl.backDamperOpenMesh.visible = false;
  322. if (fmThreeTl.backDamperClosedMesh) fmThreeTl.backDamperClosedMesh.visible = true;
  323. // 显示单道风窗
  324. model.startAnimation = fmThreeTl.render.bind(fmThreeTl);
  325. model.scene.remove(group);
  326. group = fmThreeTl.group;
  327. const oldCameraPosition = { x: -761, y: 569, z: 871 };
  328. setTimeout(async () => {
  329. resolve(null);
  330. model.scene.add(fmThreeTl.group);
  331. const position = { x: 31.873075535732386, y: -3.501715880262631, z: -15.490295891616942 };
  332. await animateCamera(
  333. oldCameraPosition,
  334. { x: -2.27, y: -0.91, z: -5.67 },
  335. { x: 88.60102093060523, y: 53.89462381404774, z: 109.90762232602137 },
  336. { x: position.x, y: position.y, z: position.z },
  337. model,
  338. 0.6
  339. );
  340. }, 300);
  341. } else if (fmType === 'fm3' && fm3 && fm3.group) {
  342. if (fm3.clipActionArr.frontDoor && fm3.clipActionArr.backDoor) {
  343. fm3.clipActionArr.frontDoor.reset();
  344. fm3.clipActionArr.frontDoor.time = 0.5;
  345. fm3.clipActionArr.backDoor.reset();
  346. fm3.clipActionArr.backDoor.time = 0.5;
  347. fm3.clipActionArr.frontDoor.stop();
  348. fm3.clipActionArr.backDoor.stop();
  349. }
  350. if (fm3.frontDamperOpenMesh) fm3.frontDamperOpenMesh.visible = false;
  351. if (fm3.frontDamperClosedMesh) fm3.frontDamperClosedMesh.visible = true;
  352. if (fm3.backDamperOpenMesh) fm3.backDamperOpenMesh.visible = false;
  353. if (fm3.backDamperClosedMesh) fm3.backDamperClosedMesh.visible = true;
  354. model.scene.remove(group);
  355. model.startAnimation = fm3.render.bind(fm3);
  356. group = fm3.group;
  357. group.rotation.y = 0;
  358. const oldCameraPosition = { x: -1000, y: 100, z: 500 };
  359. setTimeout(async () => {
  360. resolve(null);
  361. model.scene.add(fm3.group);
  362. await animateCamera(
  363. oldCameraPosition,
  364. { x: 0, y: 0, z: 0 },
  365. { x: 50.99, y: 69.32, z: 93.61 },
  366. { x: -10.04, y: -14.38, z: -31.4 },
  367. model,
  368. 0.8
  369. );
  370. }, 300);
  371. } else if (fmType === 'fmXr' && fmXr && fmXr.group) {
  372. if (fmXr.clipActionArr.frontDoor && fmXr.clipActionArr.backDoor) {
  373. fmXr.clipActionArr.frontDoor.reset();
  374. fmXr.clipActionArr.frontDoor.time = 0.5;
  375. fmXr.clipActionArr.backDoor.reset();
  376. fmXr.clipActionArr.backDoor.time = 0.5;
  377. fmXr.clipActionArr.frontDoor.stop();
  378. fmXr.clipActionArr.backDoor.stop();
  379. }
  380. if (fmXr.frontDamperOpenMesh) fmXr.frontDamperOpenMesh.visible = false;
  381. if (fmXr.frontDamperClosedMesh) fmXr.frontDamperClosedMesh.visible = true;
  382. if (fmXr.backDamperOpenMesh) fmXr.backDamperOpenMesh.visible = false;
  383. if (fmXr.backDamperClosedMesh) fmXr.backDamperClosedMesh.visible = true;
  384. model.startAnimation = fmXr.render.bind(fmXr);
  385. model.scene.remove(group);
  386. group = fmXr.group;
  387. group.rotation.y = 0;
  388. const oldCameraPosition = { x: -1000, y: 100, z: 500 };
  389. setTimeout(async () => {
  390. resolve(null);
  391. model.scene.add(fmXr.group);
  392. await animateCamera(
  393. oldCameraPosition,
  394. { x: 0, y: 0, z: 0 },
  395. { x: 50.99, y: 69.32, z: 93.61 },
  396. { x: -10.04, y: -14.38, z: -31.4 },
  397. model,
  398. 0.8
  399. );
  400. }, 300);
  401. } else if (fmType === 'fmTwoSs' && fmTwoSs && fmTwoSs.group) {
  402. if (fmTwoSs.clipActionArr.frontDoor && fmTwoSs.clipActionArr.backDoor) {
  403. fmTwoSs.clipActionArr.frontDoor.reset();
  404. fmTwoSs.clipActionArr.frontDoor.time = 0.5;
  405. fmTwoSs.clipActionArr.backDoor.reset();
  406. fmTwoSs.clipActionArr.backDoor.time = 0.5;
  407. fmTwoSs.clipActionArr.frontDoor.stop();
  408. fmTwoSs.clipActionArr.backDoor.stop();
  409. }
  410. if (fmTwoSs.frontDamperOpenMesh) fmTwoSs.frontDamperOpenMesh.visible = false;
  411. if (fmTwoSs.frontDamperClosedMesh) fmTwoSs.frontDamperClosedMesh.visible = true;
  412. if (fmTwoSs.backDamperOpenMesh) fmTwoSs.backDamperOpenMesh.visible = false;
  413. if (fmTwoSs.backDamperClosedMesh) fmTwoSs.backDamperClosedMesh.visible = true;
  414. model.startAnimation = fmTwoSs.render.bind(fmTwoSs);
  415. model.scene.remove(group);
  416. group = fmTwoSs.group;
  417. group.rotation.y = 0;
  418. const oldCameraPosition = { x: -1000, y: 100, z: 500 };
  419. setTimeout(async () => {
  420. resolve(null);
  421. model.scene.add(fmTwoSs.group);
  422. await animateCamera(
  423. oldCameraPosition,
  424. { x: 0, y: 0, z: 0 },
  425. { x: 50.99, y: 69.32, z: 93.61 },
  426. { x: -10.04, y: -14.38, z: -31.4 },
  427. model,
  428. 0.8
  429. );
  430. }, 300);
  431. }
  432. });
  433. };
  434. export const initCameraCanvas = async (playerVal1) => {
  435. if (fmType === 'fm1' && fm1) {
  436. return await fm1.initCamera.call(fm1, playerVal1);
  437. } else if (fmType === 'fm2' && fm2) {
  438. return fm2.initCamera.call(fm2, playerVal1);
  439. } else if (fmType === 'fm3' && fm3) {
  440. return fm3.initCamera.call(fm3, playerVal1);
  441. } else if (fmType === 'fmXr' && fmXr) {
  442. return fmXr.initCamera.call(fmXr, playerVal1);
  443. }
  444. };
  445. export const mountedThree = (playerDom) => {
  446. const { sysOrgCode } = useGlobSetting();
  447. debugger;
  448. // const sysOrgCode = 'gsgszdek';
  449. return new Promise(async (resolve) => {
  450. model = new UseThree('#damper3D', '', '#deviceDetail');
  451. model.setEnvMap('test1.hdr');
  452. model.renderer.toneMappingExposure = 0.9;
  453. model.camera.position.set(100, 0, 1000);
  454. switch (sysOrgCode) {
  455. case 'yjmdsankuang': //窑街三矿
  456. case 'yjmdhswmk': //窑街海石湾
  457. case 'yjmdjhmk': //窑街金河矿
  458. const FmYj = await import('./gate.threejs.yj');
  459. if (FmYj) fm3 = new FmYj.default(model);
  460. if (fm3) fm3.mountedThree(playerDom);
  461. const FmTwoYj = await import('./gate.threejs.two.yj');
  462. if (FmTwoYj) fmTwoSs = new FmTwoYj.default(model);
  463. fmTwoSs.mountedThree(playerDom);
  464. fmXr = new FmXR(model);
  465. fmXr.mountedThree(playerDom);
  466. break;
  467. case 'zmjthjg': //黄家沟
  468. const FmNoSubStation = await import('./gate.threejs.noStation');
  469. if (FmNoSubStation) fm3 = new FmNoSubStation.default(model);
  470. if (fm3) fm3.mountedThree(playerDom);
  471. fmXr = new FmXR(model);
  472. fmXr.mountedThree(playerDom);
  473. break;
  474. case 'gsgszdek': //大海则
  475. fmWindowHjg = new FmDc(model);
  476. if (fmWindowHjg) fmWindowHjg.mountedThree(playerDom);
  477. fm3 = new Fm3(model);
  478. fm3.mountedThree(playerDom);
  479. fmXr = new FmXR(model);
  480. fmXr.mountedThree(playerDom);
  481. break;
  482. case 'sdmtjtbltmk': //补连塔
  483. fm3 = new Fm3(model);
  484. fm3.mountedThree(playerDom);
  485. fmXr = new FmXR(model);
  486. fmXr.mountedThree(playerDom);
  487. // 三道门
  488. fmThreeTl = new FmThreeTl(model);
  489. if (fmThreeTl) fmThreeTl.mountedThree(playerDom);
  490. break;
  491. default:
  492. debugger;
  493. // 根据字典加载模型
  494. const dictCodes = getDictItemsByCode('gateStyle');
  495. if (dictCodes.length > 0) {
  496. for (let i = 0; i < dictCodes.length; i++) {
  497. const dict = dictCodes[i];
  498. switch (dict.value) {
  499. case 'fmXr':
  500. fmXr = new FmXR(model);
  501. fmXr.mountedThree(playerDom);
  502. break;
  503. case 'fmYy':
  504. fm1 = new Fm1(model);
  505. fm1.mountedThree(playerDom);
  506. break;
  507. case 'gate_qd':
  508. fm3 = new Fm3(model);
  509. await fm3.mountedThree();
  510. break;
  511. case 'fmSs':
  512. fmTwoSs = new FmTwoSs(model);
  513. await fmTwoSs.mountedThree();
  514. break;
  515. case 'fmtl3':
  516. fmThreeTl = new FmThreeTl(model);
  517. await fmThreeTl.mountedThree();
  518. break;
  519. case 'fmSs3':
  520. fm2 = new Fm2(model);
  521. await fm2.mountedThree();
  522. break;
  523. case 'fm_fc_hjg':
  524. fmWindowHjg = new FmDcHJG(model);
  525. await fmWindowHjg.mountedThree();
  526. break;
  527. case 'fm_fc':
  528. fmWindow = new FmDc(model);
  529. await fmWindow.mountedThree();
  530. break;
  531. }
  532. }
  533. resolve(null);
  534. } else {
  535. fm3 = new Fm3(model);
  536. fm3.mountedThree(playerDom);
  537. fmTwoSs = new FmTwoSs(model);
  538. fmTwoSs.mountedThree(playerDom);
  539. fm2 = new Fm2(model);
  540. fm2.mountedThree(playerDom);
  541. // 三道门
  542. fmThreeTl = new FmThreeTl(model);
  543. if (fmThreeTl) fmThreeTl.mountedThree(playerDom);
  544. fmXr = new FmXR(model);
  545. fmXr.mountedThree(playerDom);
  546. // 液压风门
  547. fm1 = new Fm1(model);
  548. fm1.mountedThree(playerDom);
  549. resolve(null);
  550. break;
  551. }
  552. }
  553. model.animate();
  554. startAnimation();
  555. });
  556. };
  557. export const destroy = () => {
  558. if (model) {
  559. model.isRender = false;
  560. if (fm1) fm1.destroy();
  561. if (fm2) fm2.destroy();
  562. if (fm3) fm3.destroy();
  563. if (fmXr) fmXr.destroy();
  564. if (fmTwoSs) fmTwoSs.destroy();
  565. if (fmWindowHjg) fmWindowHjg.destroy();
  566. if (fmWindow) fmWindow.destroy();
  567. if (fmThreeTl) fmThreeTl.destroy();
  568. fm1 = null;
  569. fm2 = null;
  570. fm3 = null;
  571. fmXr = null;
  572. fmWindow = null;
  573. fmWindowHjg = null;
  574. fmThreeTl = null;
  575. fmTwoSs = null;
  576. group = null;
  577. model.mixers = [];
  578. model.destroy();
  579. }
  580. model = null;
  581. };