gate.threejs.ts 24 KB

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