gate.threejs.ts 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  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 { animateCamera } from '/@/utils/threejs/util';
  9. import useEvent from '../../../../utils/threejs/useEvent';
  10. import { useGlobSetting } from '/@/hooks/setting';
  11. // 模型对象、 文字对象
  12. let model,
  13. fm1, //液压风门
  14. fm2, //三道风门
  15. fm3, //气动风门
  16. fmXr: FmXR, //行人风门
  17. fmTwoSs, //
  18. group: THREE.Object3D,
  19. fmType = '',
  20. windowType = 'singleWindow';
  21. const rotationParam = {
  22. frontDeg0: 0, // 前门初始
  23. frontDeg1: 0, // 前门目标
  24. backDeg0: 0, // 后门初始
  25. backDeg1: 0, // 后门目标
  26. };
  27. const { mouseDownFn } = useEvent();
  28. // 初始化左右摇摆动画
  29. const startAnimation = () => {
  30. // 定义鼠标点击事件
  31. model.canvasContainer?.addEventListener('mousedown', mouseEvent.bind(null));
  32. model.canvasContainer?.addEventListener('pointerup', (event) => {
  33. event.stopPropagation();
  34. // 单道、 双道
  35. if (fmType === 'fm1') {
  36. fm1?.mouseUpModel.call(fm1);
  37. } else if (fmType === 'fm2') {
  38. fm2?.mouseUpModel.call(fm2);
  39. } else if (fmType === 'fm3') {
  40. fm3?.mouseUpModel.call(fm3);
  41. } else if (fmType === 'fmXr') {
  42. fmXr?.mouseUpModel.call(fmXr);
  43. } else if (fmType === 'fmTwoSs') {
  44. fmTwoSs?.mouseUpModel.call(fmTwoSs);
  45. }
  46. });
  47. };
  48. // 鼠标点击、松开事件
  49. const mouseEvent = (event) => {
  50. if (event.button == 0) {
  51. mouseDownFn(model, group, event, (intersects) => {
  52. if (fmType === 'fm1' && fm1) {
  53. fm1?.mousedownModel.call(fm1, intersects);
  54. } else if (fmType === 'fm2' && fm2) {
  55. fm2?.mousedownModel.call(fm2, intersects);
  56. } else if (fmType === 'fm3' && fm3) {
  57. fm3?.mousedownModel.call(fm3, intersects);
  58. } else if (fmType === 'fmXr' && fmXr) {
  59. fmXr?.mousedownModel.call(fmXr, intersects);
  60. } else if (fmType === 'fmTwoSs' && fmTwoSs) {
  61. fmTwoSs?.mousedownModel.call(fmTwoSs, intersects);
  62. }
  63. });
  64. // console.log('摄像头控制信息', model.orbitControls, model.camera);
  65. }
  66. };
  67. export const addMonitorText = (selectData) => {
  68. if (fmType === 'fm1' && fm1) {
  69. return fm1?.addMonitorText.call(fm1, selectData);
  70. } else if (fmType === 'fm2' && fm2) {
  71. return fm2?.addMonitorText.call(fm2, selectData);
  72. } else if (fmType === 'fm3' && fm3) {
  73. return fm3?.addMonitorText.call(fm3, selectData);
  74. } else if (fmType === 'fmXr' && fmXr) {
  75. return fmXr?.addMonitorText.call(fmXr, selectData);
  76. } else if (fmType === 'fmTwoSs' && fmTwoSs) {
  77. return fmTwoSs?.addMonitorText.call(fmTwoSs, selectData);
  78. }
  79. };
  80. export const deviceDetailCard = () => {
  81. if (fmType === 'fm1') {
  82. return fm1?.deviceDetailCard.call(fm1);
  83. } else if (fmType === 'fm3') {
  84. return fm3?.deviceDetailCard.call(fm3);
  85. } else if (fmType === 'fmXr') {
  86. return fmXr?.deviceDetailCard.call(fmXr);
  87. } else {
  88. // return fm2.addMonitorText.call(fm2);
  89. }
  90. };
  91. export const play = (handlerState, flag?) => {
  92. if (fmType === 'fm1' && fm1) {
  93. return fm1.play.call(fm1, handlerState, flag);
  94. } else if (fmType === 'fm2' && fm2) {
  95. return fm2.play.call(fm2, handlerState, flag);
  96. } else if (fmType === 'fm3' && fm3) {
  97. return fm3.play.call(fm3, handlerState, flag);
  98. } else if (fmType === 'fmXr' && fmXr) {
  99. return fmXr.play.call(fmXr, handlerState, flag);
  100. } else if (fmType === 'fmTwoSs' && fmTwoSs) {
  101. return fmTwoSs.play.call(fmTwoSs, handlerState, flag);
  102. }
  103. };
  104. export const playWindow = (rotationParam, flag) => {
  105. if (fmType === 'fm3' && fm3) {
  106. return fm3.playWindow.call(fm3, rotationParam, flag);
  107. }
  108. };
  109. export function computePlay(data, maxarea, isFirst = false) {
  110. debugger;
  111. if (data.OpenDegree1 || data.OpenDegree2) {
  112. maxarea = 90;
  113. rotationParam.frontDeg0 = (90 / maxarea) * Number(isFirst ? 0 : data.OpenDegree1);
  114. rotationParam.backDeg0 = (90 / maxarea) * Number(isFirst ? 0 : data.OpenDegree2);
  115. rotationParam.frontDeg1 = (90 / maxarea) * Number(data.OpenDegree1) || 0;
  116. rotationParam.backDeg1 = (90 / maxarea) * Number(data.OpenDegree2) || 0;
  117. // if (!rotationParam.frontDeg1 && !rotationParam.backDeg1) {
  118. // // 当返回值有误时默认关闭
  119. // fm3.playWindow.call(fm3, rotationParam, 1);
  120. // fm3.playWindow.call(fm3, rotationParam, 2);
  121. // }
  122. fm3.playWindow.call(fm3, rotationParam, 1);
  123. fm3.playWindow.call(fm3, rotationParam, 2);
  124. }
  125. }
  126. // 切换风门类型
  127. export const setModelType = (type) => {
  128. debugger;
  129. fmType = type;
  130. return new Promise((resolve) => {
  131. // 暂停风门1动画
  132. if (fmType === 'fm1' && fm1 && fm1.group) {
  133. if (fm1.clipActionArr.frontDoor && fm1.clipActionArr.backDoor) {
  134. fm1.clipActionArr.frontDoor.reset();
  135. fm1.clipActionArr.frontDoor.time = 0.5;
  136. fm1.clipActionArr.backDoor.reset();
  137. fm1.clipActionArr.backDoor.time = 0.5;
  138. fm1.clipActionArr.frontDoor.stop();
  139. fm1.clipActionArr.backDoor.stop();
  140. }
  141. if (fm1.frontDamperOpenMesh) fm1.frontDamperOpenMesh.visible = false;
  142. if (fm1.frontDamperClosedMesh) fm1.frontDamperClosedMesh.visible = true;
  143. if (fm1.backDamperOpenMesh) fm1.backDamperOpenMesh.visible = false;
  144. if (fm1.backDamperClosedMesh) fm1.backDamperClosedMesh.visible = true;
  145. model.scene.remove(group);
  146. model.startAnimation = fm1.render.bind(fm1);
  147. group = fm1.group;
  148. group.rotation.y = 0;
  149. const oldCameraPosition = { x: -1000, y: 100, z: 500 };
  150. setTimeout(async () => {
  151. resolve(null);
  152. model.scene.add(fm1.group);
  153. await animateCamera(
  154. oldCameraPosition,
  155. { x: 0, y: 0, z: 0 },
  156. { x: 50.99, y: 69.32, z: 93.61 },
  157. { x: -10.04, y: -14.38, z: -31.4 },
  158. model,
  159. 0.8
  160. );
  161. }, 300);
  162. } else if (fmType === 'fm2' && fm2 && fm2.group) {
  163. if (fm2.clipActionArr.frontDoor && fm2.clipActionArr.backDoor) {
  164. fm2.clipActionArr.frontDoor.reset();
  165. fm2.clipActionArr.frontDoor.time = 0.5;
  166. fm2.clipActionArr.backDoor.reset();
  167. fm2.clipActionArr.backDoor.time = 0.5;
  168. fm2.clipActionArr.centerDoor.reset();
  169. fm2.clipActionArr.centerDoor.time = 0.5;
  170. fm2.clipActionArr.frontDoor.stop();
  171. fm2.clipActionArr.backDoor.stop();
  172. fm2.clipActionArr.centerDoor.stop();
  173. }
  174. // 显示单道风窗
  175. model.startAnimation = fm2.render.bind(fm2);
  176. model.scene.remove(group);
  177. group = fm2.group;
  178. const oldCameraPosition = { x: -761, y: 569, z: 871 };
  179. setTimeout(async () => {
  180. resolve(null);
  181. model.scene.add(fm2.group);
  182. const position = { x: -2.28, y: -0.91, z: -5.68 };
  183. await animateCamera(
  184. oldCameraPosition,
  185. { x: -2.27, y: -0.91, z: -5.67 },
  186. { x: 66.257, y: 57.539, z: 94.313 },
  187. { x: position.x, y: position.y, z: position.z },
  188. model,
  189. 0.6
  190. );
  191. }, 300);
  192. } else if (fmType === 'fm3' && fm3 && fm3.group) {
  193. if (fm3.clipActionArr.frontDoor && fm3.clipActionArr.backDoor) {
  194. fm3.clipActionArr.frontDoor.reset();
  195. fm3.clipActionArr.frontDoor.time = 0.5;
  196. fm3.clipActionArr.backDoor.reset();
  197. fm3.clipActionArr.backDoor.time = 0.5;
  198. fm3.clipActionArr.frontDoor.stop();
  199. fm3.clipActionArr.backDoor.stop();
  200. }
  201. if (fm3.frontDamperOpenMesh) fm3.frontDamperOpenMesh.visible = false;
  202. if (fm3.frontDamperClosedMesh) fm3.frontDamperClosedMesh.visible = true;
  203. if (fm3.backDamperOpenMesh) fm3.backDamperOpenMesh.visible = false;
  204. if (fm3.backDamperClosedMesh) fm3.backDamperClosedMesh.visible = true;
  205. model.scene.remove(group);
  206. model.startAnimation = fm3.render.bind(fm3);
  207. group = fm3.group;
  208. group.rotation.y = 0;
  209. const oldCameraPosition = { x: -1000, y: 100, z: 500 };
  210. setTimeout(async () => {
  211. resolve(null);
  212. model.scene.add(fm3.group);
  213. await animateCamera(
  214. oldCameraPosition,
  215. { x: 0, y: 0, z: 0 },
  216. { x: 50.99, y: 69.32, z: 93.61 },
  217. { x: -10.04, y: -14.38, z: -31.4 },
  218. model,
  219. 0.8
  220. );
  221. }, 300);
  222. } else if (fmType === 'fmXr' && fmXr && fmXr.group) {
  223. if (fmXr.clipActionArr.frontDoor && fmXr.clipActionArr.backDoor) {
  224. fmXr.clipActionArr.frontDoor.reset();
  225. fmXr.clipActionArr.frontDoor.time = 0.5;
  226. fmXr.clipActionArr.backDoor.reset();
  227. fmXr.clipActionArr.backDoor.time = 0.5;
  228. fmXr.clipActionArr.frontDoor.stop();
  229. fmXr.clipActionArr.backDoor.stop();
  230. }
  231. if (fmXr.frontDamperOpenMesh) fmXr.frontDamperOpenMesh.visible = false;
  232. if (fmXr.frontDamperClosedMesh) fmXr.frontDamperClosedMesh.visible = true;
  233. if (fmXr.backDamperOpenMesh) fmXr.backDamperOpenMesh.visible = false;
  234. if (fmXr.backDamperClosedMesh) fmXr.backDamperClosedMesh.visible = true;
  235. model.startAnimation = fmXr.render.bind(fmXr);
  236. model.scene.remove(group);
  237. group = fmXr.group;
  238. group.rotation.y = 0;
  239. const oldCameraPosition = { x: -1000, y: 100, z: 500 };
  240. setTimeout(async () => {
  241. resolve(null);
  242. model.scene.add(fmXr.group);
  243. await animateCamera(
  244. oldCameraPosition,
  245. { x: 0, y: 0, z: 0 },
  246. { x: 50.99, y: 69.32, z: 93.61 },
  247. { x: -10.04, y: -14.38, z: -31.4 },
  248. model,
  249. 0.8
  250. );
  251. }, 300);
  252. } else if (fmType === 'fmTwoSs' && fmTwoSs && fmTwoSs.group) {
  253. if (fmTwoSs.clipActionArr.frontDoor && fmTwoSs.clipActionArr.backDoor) {
  254. fmTwoSs.clipActionArr.frontDoor.reset();
  255. fmTwoSs.clipActionArr.frontDoor.time = 0.5;
  256. fmTwoSs.clipActionArr.backDoor.reset();
  257. fmTwoSs.clipActionArr.backDoor.time = 0.5;
  258. fmTwoSs.clipActionArr.frontDoor.stop();
  259. fmTwoSs.clipActionArr.backDoor.stop();
  260. }
  261. if (fmTwoSs.frontDamperOpenMesh) fmTwoSs.frontDamperOpenMesh.visible = false;
  262. if (fmTwoSs.frontDamperClosedMesh) fmTwoSs.frontDamperClosedMesh.visible = true;
  263. if (fmTwoSs.backDamperOpenMesh) fmTwoSs.backDamperOpenMesh.visible = false;
  264. if (fmTwoSs.backDamperClosedMesh) fmTwoSs.backDamperClosedMesh.visible = true;
  265. model.startAnimation = fmTwoSs.render.bind(fmTwoSs);
  266. model.scene.remove(group);
  267. group = fmTwoSs.group;
  268. group.rotation.y = 0;
  269. const oldCameraPosition = { x: -1000, y: 100, z: 500 };
  270. setTimeout(async () => {
  271. resolve(null);
  272. model.scene.add(fmTwoSs.group);
  273. await animateCamera(
  274. oldCameraPosition,
  275. { x: 0, y: 0, z: 0 },
  276. { x: 50.99, y: 69.32, z: 93.61 },
  277. { x: -10.04, y: -14.38, z: -31.4 },
  278. model,
  279. 0.8
  280. );
  281. }, 300);
  282. }
  283. });
  284. };
  285. export const initCameraCanvas = async (playerVal1) => {
  286. if (fmType === 'fm1' && fm1) {
  287. return await fm1.initCamera.call(fm1, playerVal1);
  288. } else if (fmType === 'fm2' && fm2) {
  289. return fm2.initCamera.call(fm2, playerVal1);
  290. } else if (fmType === 'fm3' && fm3) {
  291. return fm3.initCamera.call(fm3, playerVal1);
  292. } else if (fmType === 'fmXr' && fmXr) {
  293. return fmXr.initCamera.call(fmXr, playerVal1);
  294. }
  295. };
  296. export const mountedThree = (playerDom) => {
  297. const { sysOrgCode } = useGlobSetting();
  298. // const sysOrgCode = 'gsgszdek';
  299. return new Promise(async (resolve) => {
  300. model = new UseThree('#damper3D', '', '#deviceDetail');
  301. model.setEnvMap('test1');
  302. model.renderer.toneMappingExposure = 0.9;
  303. model.camera.position.set(100, 0, 1000);
  304. switch (sysOrgCode) {
  305. case 'yjmdsankuang': //窑街三矿
  306. case 'yjmdhswmk': //窑街海石湾
  307. case 'yjmdjhmk': //窑街金河矿
  308. const FmYj = await import('./gate.threejs.yj');
  309. if (FmYj) fm3 = new FmYj.default(model);
  310. if (fm3) fm3.mountedThree(playerDom);
  311. const FmTwoYj = await import('./gate.threejs.two.yj');
  312. if (FmTwoYj) fmTwoSs = new FmTwoYj.default(model);
  313. fmTwoSs.mountedThree(playerDom);
  314. break;
  315. case 'zmjthjg':
  316. const FmNoSubStation = await import('./gate.threejs.noStation');
  317. if (FmNoSubStation) fm3 = new FmNoSubStation.default(model);
  318. if (fm3) fm3.mountedThree(playerDom);
  319. break;
  320. case 'gsgszdek':
  321. const FmDc = await import('./gate.threejs.window');
  322. if (FmDc) fm3 = new FmDc.default(model);
  323. if (fm3) fm3.mountedThree(playerDom);
  324. break;
  325. default:
  326. fm3 = new Fm3(model);
  327. fm3.mountedThree(playerDom);
  328. fmTwoSs = new FmTwoSs(model);
  329. fmTwoSs.mountedThree(playerDom);
  330. fm2 = new Fm2(model);
  331. fm2.mountedThree(playerDom);
  332. break;
  333. }
  334. fmXr = new FmXR(model);
  335. fmXr.mountedThree(playerDom);
  336. fm1 = new Fm1(model);
  337. fm1.mountedThree(playerDom);
  338. resolve(null);
  339. model.animate();
  340. startAnimation();
  341. });
  342. };
  343. export const destroy = () => {
  344. if (model) {
  345. model.isRender = false;
  346. if (fm1) fm1.destroy();
  347. if (fm2) fm2.destroy();
  348. if (fm3) fm3.destroy();
  349. if (fmXr) fmXr.destroy();
  350. if (fmTwoSs) fmTwoSs.destroy();
  351. fm1 = null;
  352. fm2 = null;
  353. fm3 = null;
  354. fmXr = null;
  355. fmTwoSs = null;
  356. group = null;
  357. model.mixers = [];
  358. model.destroy();
  359. }
  360. model = null;
  361. };