gate.threejs.ts 31 KB

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