windrect.threejs.ts 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. import * as THREE from 'three';
  2. import { animateCamera, getTextCanvas, renderVideo } from '/@/utils/threejs/util';
  3. import UseThree from '../../../../utils/threejs/useThree';
  4. import lmWindRect from './longmen.threejs';
  5. import zdWindRect from './zhedie.threejs';
  6. import dsWindRect from './duishe.threejs';
  7. import lmWindRectSide from './longmenSide.threejs';
  8. import useEvent from '../../../../utils/threejs/useEvent';
  9. import gsap from 'gsap';
  10. import ddWindRect from './dantou.threejs';
  11. // import * as dat from 'dat.gui';
  12. // const gui = new dat.GUI();
  13. // gui.domElement.style = 'position:absolute;top:100px;left:10px;z-index:99999999999999';
  14. // 模型对象、 文字对象
  15. let model, //
  16. group,
  17. lmWindRectObj,
  18. zdWindRectObj,
  19. dsWindRectObj,
  20. lmWindRectSideObj,
  21. ddWindRectObj,
  22. windRectType = 'lmWindRect';
  23. const { mouseDownFn } = useEvent();
  24. // 初始化左右摇摆动画
  25. const startAnimation = () => {
  26. // 定义鼠标点击事件
  27. model.canvasContainer?.addEventListener('mousedown', mouseEvent.bind(null));
  28. model.canvasContainer?.addEventListener('pointerup', (event) => {
  29. event.stopPropagation();
  30. // 单道、 双道
  31. if (windRectType === 'lmWindRect') {
  32. lmWindRectObj.mouseUpModel.call(lmWindRectObj);
  33. } else if (windRectType === 'zdWindRect') {
  34. zdWindRectObj.mouseUpModel.call(zdWindRectObj);
  35. } else if (windRectType.startsWith('dsWindRect')) {
  36. dsWindRectObj.mouseUpModel.call(dsWindRectObj);
  37. } else if (windRectType === 'lmWindSide') {
  38. lmWindRectSideObj.mouseUpModel.call(lmWindRectSideObj);
  39. } else if (windRectType === 'ddWindSide') {
  40. ddWindRectObj.mouseUpModel.call(ddWindRectObj);
  41. }
  42. });
  43. };
  44. // 鼠标点击、松开事件
  45. const mouseEvent = (event) => {
  46. mouseDownFn(model, group, event, (intersects) => {
  47. if (windRectType === 'lmWindRect') {
  48. lmWindRectObj.mousedownModel.call(lmWindRectObj, intersects);
  49. } else if (windRectType === 'zdWindRect') {
  50. zdWindRectObj.mousedownModel.call(zdWindRectObj, intersects);
  51. } else if (windRectType.startsWith('dsWindRect')) {
  52. dsWindRectObj.mousedownModel.call(dsWindRectObj, intersects);
  53. } else if (windRectType === 'lmWindSide') {
  54. lmWindRectSideObj.mousedownModel.call(lmWindRectSideObj, intersects);
  55. } else if (windRectType === 'ddWindSide') {
  56. ddWindRectObj.mousedownModel.call(ddWindRectObj, intersects);
  57. }
  58. });
  59. console.log('摄像头控制信息', model.orbitControls, model.camera);
  60. };
  61. /* 添加监控数据 */
  62. export const addMonitorText = (selectData) => {
  63. if (windRectType === 'lmWindRect') {
  64. return lmWindRectObj.addMonitorText.call(lmWindRectObj, selectData);
  65. } else if (windRectType === 'zdWindRect') {
  66. return zdWindRectObj.addMonitorText.call(zdWindRectObj, selectData);
  67. } else if (windRectType.startsWith('dsWindRect')) {
  68. return dsWindRectObj.addMonitorText.call(dsWindRectObj, selectData);
  69. } else if (windRectType === 'lmWindSide') {
  70. return lmWindRectSideObj.addMonitorText.call(lmWindRectSideObj, selectData);
  71. } else if (windRectType === 'ddWindSide') {
  72. return ddWindRectObj.addMonitorText.call(ddWindRectObj, selectData);
  73. }
  74. };
  75. export const play = (flag, isDirect = false) => {
  76. if (windRectType === 'lmWindRect') {
  77. return lmWindRectObj.play.call(lmWindRectObj, flag, isDirect);
  78. } else if (windRectType === 'zdWindRect') {
  79. return zdWindRectObj.play.call(zdWindRectObj, flag, isDirect);
  80. } else if (windRectType.startsWith('dsWindRect')) {
  81. return dsWindRectObj.play.call(dsWindRectObj, flag, isDirect);
  82. } else if (windRectType === 'lmWindSide') {
  83. lmWindRectSideObj.play.call(lmWindRectSideObj, flag, isDirect);
  84. }
  85. };
  86. export const playCamera = (flag) => {
  87. if (windRectType === 'lmWindSide') {
  88. lmWindRectSideObj.playCamera.call(lmWindRectSideObj, flag);
  89. }
  90. };
  91. // 切换风窗类型
  92. export const setModelType = (type) => {
  93. windRectType = type;
  94. model.camera.position.set(-1000, 100, 500);
  95. // 暂停龙门动画
  96. const lmGsap = gsap.getById('lm') || null;
  97. if (lmGsap != null) {
  98. lmGsap.pause();
  99. lmGsap.kill();
  100. }
  101. lmWindRectObj.deviceRunState = '';
  102. dsWindRectObj.isRun = false;
  103. lmWindRectSideObj.deviceRunState = '';
  104. lmWindRectSideObj.tanTouRunState = '';
  105. return new Promise((resolve) => {
  106. // 显示双道风窗
  107. if (windRectType === 'lmWindRect') {
  108. model.startAnimation = lmWindRectObj.render.bind(lmWindRectObj);
  109. group = lmWindRectObj.group;
  110. const cfTanTou = lmWindRectObj.group?.getObjectByName('lmTanTou') as THREE.Group;
  111. cfTanTou.position.setY(0);
  112. if (model.scene.getObjectByName('zdcf')) {
  113. model.scene.remove(zdWindRectObj.group);
  114. }
  115. if (model.scene.getObjectByName('dscf')) {
  116. model.scene.remove(dsWindRectObj.group);
  117. }
  118. if (model.scene.getObjectByName('lmcfSide')) {
  119. model.scene.remove(lmWindRectSideObj.group);
  120. }
  121. if (model.scene.getObjectByName('ddcf')) {
  122. model.scene.remove(ddWindRectObj.group);
  123. }
  124. const oldCameraPosition = { x: -1000, y: 100, z: 500 };
  125. model.scene.add(lmWindRectObj.group);
  126. setTimeout(async () => {
  127. resolve(null);
  128. const position = { x: 0, y: 0, z: 0 };
  129. await animateCamera(
  130. oldCameraPosition,
  131. { x: 0, y: 0, z: 0 },
  132. { x: 46.257, y: 57.539, z: 94.313 },
  133. { x: position.x, y: position.y, z: position.z },
  134. model,
  135. 0.8
  136. );
  137. }, 300);
  138. } else if (windRectType === 'zdWindRect') {
  139. // 停用混合器上所有预定的动作
  140. zdWindRectObj.animationAction.time = 0;
  141. model.startAnimation = zdWindRectObj.render.bind(zdWindRectObj);
  142. group = zdWindRectObj.group;
  143. if (model.scene.getObjectByName('lmcf')) {
  144. model.scene.remove(lmWindRectObj.group);
  145. }
  146. if (model.scene.getObjectByName('dscf')) {
  147. model.scene.remove(dsWindRectObj.group);
  148. }
  149. if (model.scene.getObjectByName('lmcfSide')) {
  150. model.scene.remove(lmWindRectSideObj.group);
  151. }
  152. if (model.scene.getObjectByName('ddcf')) {
  153. model.scene.remove(ddWindRectObj.group);
  154. }
  155. model.scene.add(zdWindRectObj.group);
  156. const oldCameraPosition = { x: -1000, y: 100, z: 500 };
  157. setTimeout(async () => {
  158. resolve(null);
  159. const position = { x: 0, y: 0, z: 0 };
  160. await animateCamera(
  161. oldCameraPosition,
  162. { x: 0, y: 0, z: 0 },
  163. { x: 66.257, y: 57.539, z: 104.313 },
  164. { x: position.x, y: position.y, z: position.z },
  165. model,
  166. 0.8
  167. );
  168. }, 300);
  169. } else if (windRectType.startsWith('dsWindRect')) {
  170. debugger;
  171. const type = windRectType.split('_')[1];
  172. // dsWindRectObj.isRun = false;
  173. model.startAnimation = dsWindRectObj.render.bind(dsWindRectObj);
  174. group = dsWindRectObj.group;
  175. dsWindRectObj.setModelType(type); // 设置对射类型
  176. const dsmove = dsWindRectObj.group?.getObjectByName('dsmove') as THREE.Object3D;
  177. const dsTanTou = dsmove?.getObjectByName('probe') as THREE.Object3D;
  178. dsTanTou.position.setY(0.45);
  179. if (model.scene.getObjectByName('lmcf')) {
  180. model.scene.remove(lmWindRectObj.group);
  181. }
  182. if (model.scene.getObjectByName('zdcf')) {
  183. model.scene.remove(zdWindRectObj.group);
  184. }
  185. if (model.scene.getObjectByName('lmcfSide')) {
  186. model.scene.remove(lmWindRectSideObj.group);
  187. }
  188. if (model.scene.getObjectByName('ddcf')) {
  189. model.scene.remove(ddWindRectObj.group);
  190. }
  191. model.scene.add(dsWindRectObj.group);
  192. setTimeout(async () => {
  193. resolve(null);
  194. const oldCameraPosition = { x: -1020, y: 100, z: 500 };
  195. await animateCamera(
  196. oldCameraPosition,
  197. { x: 0, y: 0, z: 0 },
  198. { x: 46.257, y: 57.539, z: 104.313 },
  199. { x: 1.84, y: 0.98, z: -1.44 },
  200. model,
  201. 0.8
  202. );
  203. }, 300);
  204. } else if (windRectType === 'lmWindSide') {
  205. model.startAnimation = lmWindRectSideObj.render.bind(lmWindRectSideObj);
  206. group = lmWindRectSideObj.group;
  207. const cfTanTou = lmWindRectSideObj.group?.getObjectByName('probe_bar') as THREE.Group;
  208. cfTanTou.position.setY(0.377);
  209. if (model.scene.getObjectByName('lmcf')) {
  210. model.scene.remove(lmWindRectObj.group);
  211. }
  212. if (model.scene.getObjectByName('zdcf')) {
  213. model.scene.remove(zdWindRectObj.group);
  214. }
  215. if (model.scene.getObjectByName('dscf')) {
  216. model.scene.remove(dsWindRectObj.group);
  217. }
  218. if (model.scene.getObjectByName('ddcf')) {
  219. model.scene.remove(ddWindRectObj.group);
  220. }
  221. const oldCameraPosition = { x: -1000, y: 100, z: 500 };
  222. model.scene.add(lmWindRectSideObj.group);
  223. setTimeout(async () => {
  224. resolve(null);
  225. const position = lmWindRectSideObj.group.position;
  226. // const position = new THREE.Vector3(0, 0, 0)
  227. await animateCamera(
  228. oldCameraPosition,
  229. { x: 0, y: 0, z: 0 },
  230. { x: 46.257, y: 57.539, z: 94.313 },
  231. // { x: 1, y: 2, z: 4 },
  232. { x: position.x, y: position.y, z: position.z },
  233. model,
  234. 0.8
  235. );
  236. // lmWindRectSideObj.playCamera(true);
  237. }, 300);
  238. } else if (windRectType === 'ddWindSide') {
  239. model.startAnimation = ddWindRectObj.render.bind(ddWindRectObj);
  240. group = ddWindRectObj.group;
  241. if (model.scene.getObjectByName('lmcf')) {
  242. model.scene.remove(lmWindRectObj.group);
  243. }
  244. if (model.scene.getObjectByName('zdcf')) {
  245. model.scene.remove(zdWindRectObj.group);
  246. }
  247. if (model.scene.getObjectByName('lmcfSide')) {
  248. model.scene.remove(lmWindRectSideObj.group);
  249. }
  250. if (model.scene.getObjectByName('dscf')) {
  251. model.scene.remove(dsWindRectObj.group);
  252. }
  253. model.scene.add(ddWindRectObj.group);
  254. setTimeout(async () => {
  255. resolve(null);
  256. const oldCameraPosition = { x: -1020, y: 100, z: 500 };
  257. await animateCamera(
  258. oldCameraPosition,
  259. { x: 0, y: 0, z: 0 },
  260. { x: 22.839308656135486, y: 56.930433490209, z: 103.22614933268565 },
  261. { x: -4.4575304696469304, y: 0.26828436264018835, z: -0.7214855106998845 },
  262. model,
  263. 0.8
  264. );
  265. }, 300);
  266. }
  267. });
  268. };
  269. export const mountedThree = (playerVal1, playerVal2) => {
  270. return new Promise(async (resolve) => {
  271. model = new UseThree('#window3D');
  272. model.setEnvMap('test1');
  273. model.renderer.toneMappingExposure = 1;
  274. lmWindRectObj = new lmWindRect(model, playerVal1, playerVal2);
  275. await lmWindRectObj.mountedThree();
  276. zdWindRectObj = new zdWindRect(model, playerVal1);
  277. await zdWindRectObj.mountedThree();
  278. dsWindRectObj = new dsWindRect(model, playerVal1);
  279. await dsWindRectObj.mountedThree();
  280. lmWindRectSideObj = new lmWindRectSide(model, playerVal1, playerVal2);
  281. await lmWindRectSideObj.mountedThree();
  282. ddWindRectObj = new ddWindRect(model);
  283. await ddWindRectObj.mountedThree();
  284. resolve(null);
  285. model.animate();
  286. startAnimation();
  287. });
  288. };
  289. export const destroy = () => {
  290. if (model) {
  291. lmWindRectObj?.destroy();
  292. zdWindRectObj?.destroy();
  293. zdWindRectObj?.destroy();
  294. lmWindRectSideObj?.destroy();
  295. model.deleteModal();
  296. model = null;
  297. group = null;
  298. }
  299. };