1
0

fanLocal.three.ts 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655
  1. import * as THREE from 'three';
  2. import { CSS3DObject } from 'three/examples/jsm/renderers/CSS3DRenderer.js';
  3. import { animateCamera, getTextCanvas, renderVideo, updateAxisCenter } from '/@/utils/threejs/util';
  4. import UseThree from '../../../../utils/threejs/useThree';
  5. import fcFan from './fcfanLocal.three';
  6. import fmFan from './fmfanLocal.three';
  7. import Smoke from '/@/views/vent/comment/threejs/Smoke';
  8. import gsap from 'gsap';
  9. import useEvent from '../../../../utils/threejs/useEvent';
  10. // import * as dat from 'dat.gui';
  11. // const gui = new dat.GUI();
  12. // gui.domElement.style = 'position:absolute;top:100px;left:10px;z-index:99999999999999';
  13. const modelName = 'jbfj-hd';
  14. // 模型对象、 文字对象
  15. let model: UseThree | undefined,
  16. group: THREE.Object3D | undefined,
  17. fcFanObj: fcFan | undefined,
  18. fmFanObj: fmFan | undefined,
  19. player1,
  20. fanType,
  21. topSmoke: Smoke | undefined,
  22. downSmoke: Smoke | undefined, //
  23. returnSmoke: Smoke | undefined,
  24. topLife: number | undefined,
  25. downLife: number | undefined,
  26. playerStartClickTime1 = new Date().getTime();
  27. const { mouseDownFn, mousemoveFn, mouseUpFn } = useEvent();
  28. // 打灯光
  29. const addLight = () => {
  30. const directionalLight = new THREE.DirectionalLight(0xffffff, 1.2);
  31. directionalLight.position.set(-564, 602, -261);
  32. group?.add(directionalLight);
  33. // directionalLight.target = group;
  34. // const spotLight = new THREE.SpotLight();
  35. // spotLight.angle = Math.PI / 16;
  36. // spotLight.penumbra = 0;
  37. // spotLight.castShadow = true;
  38. // spotLight.position.set(0, 463, 687);
  39. // scene.add(spotLight);
  40. // spotLight.shadow.camera.near = 0.5; // default
  41. // spotLight.shadow.camera.far = 1000; // default
  42. // spotLight.shadow.focus = 1;
  43. // spotLight.shadow.bias = -0.000002;
  44. // spotLight.target = group;
  45. // const pointLight6 = new THREE.PointLight(0xffffff, 1, 500);
  46. // pointLight6.position.set(-131, 64, -1);
  47. // pointLight6.shadow.bias = 0.05;
  48. // group?.add(pointLight6);
  49. // gui.add(directionalLight.position, 'x', -1000, 1000);
  50. // gui.add(directionalLight.position, 'y', -1000, 1000);
  51. // gui.add(directionalLight.position, 'z', -1000, 1000);
  52. // gui.add(pointLight6.position, 'x', -500, 500);
  53. // gui.add(pointLight6.position, 'y', -500, 500);
  54. // gui.add(pointLight6.position, 'z', -500, 500);
  55. // gui.add(pointLight6, 'distance', 0, 500);
  56. };
  57. // 重置摄像头
  58. const resetCamera = () => {
  59. model.camera.position.set(0, -1000, 100);
  60. model.camera.far = 1000;
  61. model.orbitControls?.update();
  62. model.camera.updateProjectionMatrix();
  63. };
  64. // 设置模型位置
  65. const setModalPosition = () => {
  66. if (!group) return;
  67. group.position.set(0, 10, -50);
  68. group.rotation.y = Math.PI / 2;
  69. };
  70. const setControls = () => {
  71. if (model && model.orbitControls) {
  72. model.orbitControls.panSpeed = 0.5;
  73. model.orbitControls.rotateSpeed = 0.5;
  74. model.orbitControls.maxPolarAngle = Math.PI / 2.4;
  75. model.orbitControls.minPolarAngle = Math.PI / 3;
  76. }
  77. };
  78. // 切换局部通风机类型
  79. export const setModelType = (type) => {
  80. fanType = type;
  81. return new Promise((resolve) => {
  82. // 显示双道风窗
  83. let childGroup;
  84. if (fanType === 'fm' && fcFanObj && fcFanObj.group) {
  85. if (group?.getObjectByName('jbfj-fc')) {
  86. group?.remove(fcFanObj.group);
  87. }
  88. childGroup = fmFanObj?.group;
  89. if (group && group?.getObjectByName('text5') && group?.getObjectByName('text4')) {
  90. group.getObjectByName('text5')['visible'] = false;
  91. group.getObjectByName('text4')['visible'] = true;
  92. }
  93. } else if (fanType === 'fc' && fmFanObj && fmFanObj.group) {
  94. // 显示单道风窗
  95. if (group?.getObjectByName('jbfj-fm')) {
  96. group?.remove(fmFanObj.group);
  97. }
  98. childGroup = fcFanObj?.group;
  99. if (group && group?.getObjectByName('text5') && group?.getObjectByName('text4')) {
  100. group.getObjectByName('text5')['visible'] = true;
  101. group.getObjectByName('text4')['visible'] = false;
  102. }
  103. } else {
  104. if (group?.getObjectByName('jbfj-fc')) {
  105. group?.remove(fcFanObj.group);
  106. }
  107. if (group?.getObjectByName('jbfj-fm')) {
  108. group?.remove(fmFanObj.group);
  109. }
  110. if (group && group?.getObjectByName('text5') && group?.getObjectByName('text4')) {
  111. group.getObjectByName('text5')['visible'] = false;
  112. group.getObjectByName('text4')['visible'] = false;
  113. }
  114. childGroup = null;
  115. }
  116. setTimeout(async () => {
  117. if (childGroup) group?.add(childGroup);
  118. const oldCameraPosition = { x: 615, y: 275, z: 744 };
  119. await animateCamera(oldCameraPosition, { x: 0, y: 0, z: 0 }, { x: 0.08, y: 21.73, z: 78.45 }, { x: 0.13, y: -0.82, z: 0.236 }, model, 0.8);
  120. resolve(null);
  121. }, 300);
  122. });
  123. };
  124. /* 添加监控数据 */
  125. export const addText = (selectData) => {
  126. if (!group) {
  127. return;
  128. }
  129. const textArr = [
  130. {
  131. text: `智能局部通风机监测与控制系统`,
  132. font: 'normal 30px Arial',
  133. color: '#009900',
  134. strokeStyle: '#002200',
  135. x: 20,
  136. y: 108,
  137. },
  138. {
  139. text: `供风距离(m):`,
  140. font: 'normal 30px Arial',
  141. color: '#009900',
  142. strokeStyle: '#002200',
  143. x: 0,
  144. y: 152,
  145. },
  146. {
  147. text: `${
  148. selectData.fchimenylength ? selectData.fchimenylength : selectData.airSupplyDistence_merge ? selectData.airSupplyDistence_merge : '-'
  149. }`,
  150. font: 'normal 30px Arial',
  151. color: '#009900',
  152. strokeStyle: '#002200',
  153. x: 228,
  154. y: 152,
  155. },
  156. {
  157. text: `风筒直径(mm): `,
  158. font: 'normal 30px Arial',
  159. color: '#009900',
  160. strokeStyle: '#002200',
  161. x: 0,
  162. y: 200,
  163. },
  164. {
  165. text: ` ${selectData.fchimenydiamlimit ? selectData.fchimenydiamlimit : selectData.ductDiameter_merge ? selectData.ductDiameter_merge : '-'}`,
  166. font: 'normal 30px Arial',
  167. color: '#009900',
  168. strokeStyle: '#002200',
  169. x: 220,
  170. y: 200,
  171. },
  172. {
  173. text: `故障诊断:`,
  174. font: 'normal 30px Arial',
  175. color: '#009900',
  176. strokeStyle: '#002200',
  177. x: 0,
  178. y: 245,
  179. },
  180. {
  181. text: `${selectData.warnLevel_str ? selectData.warnLevel_str : '-'}`,
  182. font: 'normal 30px Arial',
  183. color: '#009900',
  184. strokeStyle: '#002200',
  185. x: 220,
  186. y: 245,
  187. },
  188. {
  189. text: `型号功率:`,
  190. font: 'normal 30px Arial',
  191. color: '#009900',
  192. strokeStyle: '#002200',
  193. x: 0,
  194. y: 285,
  195. },
  196. {
  197. text: `${selectData.model_Power_merge ? selectData.model_Power_merge : '-'}`,
  198. font: 'normal 26px Arial',
  199. color: '#009900',
  200. strokeStyle: '#002200',
  201. x: 220,
  202. y: 285,
  203. },
  204. {
  205. text: History_Type['type'] == 'remote' ? `国能神东煤炭集团监制` : '煤炭科学技术研究院有限公司研制',
  206. font: 'normal 28px Arial',
  207. color: '#009900',
  208. strokeStyle: '#002200',
  209. x: History_Type['type'] == 'remote' ? 80 : 20, //20 煤炭科学技术研究院有限公司研制
  210. y: 325,
  211. },
  212. ];
  213. getTextCanvas(526, 346, textArr, '').then((canvas: HTMLCanvasElement) => {
  214. const textMap = new THREE.CanvasTexture(canvas); // 关键一步
  215. const textMaterial = new THREE.MeshBasicMaterial({
  216. // 关于材质并未讲解 实操即可熟悉 这里是漫反射类似纸张的材质,对应的就有高光类似金属的材质.
  217. map: textMap, // 设置纹理贴图
  218. transparent: true,
  219. side: THREE.FrontSide, // 这里是双面渲染的意思
  220. });
  221. textMaterial.blending = THREE.CustomBlending;
  222. const monitorPlane = group.getObjectByName('monitorText');
  223. if (monitorPlane) {
  224. monitorPlane.material = textMaterial;
  225. } else {
  226. const planeGeometry = new THREE.PlaneGeometry(526, 346); // 平面3维几何体PlaneGeometry
  227. const planeMesh = new THREE.Mesh(planeGeometry, textMaterial);
  228. planeMesh.name = 'monitorText';
  229. planeMesh.scale.set(0.0135, 0.0135, 0.0135);
  230. planeMesh.rotation.y = -Math.PI / 2;
  231. planeMesh.position.set(-84.79, 0.82, 17.0);
  232. group.add(planeMesh);
  233. }
  234. });
  235. };
  236. // // css3D文字
  237. export const addCssText = () => {
  238. if (!group) return;
  239. if (!group.getObjectByName('text1')) {
  240. const element = document.getElementById('inputBox') as HTMLElement;
  241. if (element) {
  242. const fanLocalCSS3D = new CSS3DObject(element);
  243. fanLocalCSS3D.name = 'text1';
  244. fanLocalCSS3D.scale.set(0.04, 0.04, 0.04);
  245. fanLocalCSS3D.rotation.y = -Math.PI / 2;
  246. fanLocalCSS3D.position.set(-85.68, 5.97, -3.39);
  247. group.add(fanLocalCSS3D);
  248. }
  249. }
  250. if (!group.getObjectByName('text2')) {
  251. const element = document.getElementById('outBox') as HTMLElement;
  252. if (element) {
  253. const fanLocalCSS3D = new CSS3DObject(element);
  254. fanLocalCSS3D.name = 'text2';
  255. fanLocalCSS3D.scale.set(0.1, 0.1, 0.1);
  256. fanLocalCSS3D.rotation.y = -Math.PI / 2;
  257. fanLocalCSS3D.position.set(74.63, 13.54, 3.84);
  258. group.add(fanLocalCSS3D);
  259. }
  260. }
  261. if (!group.getObjectByName('text3')) {
  262. const element = document.getElementById('returnBox') as HTMLElement;
  263. if (element) {
  264. const fanLocalCSS3D = new CSS3DObject(element);
  265. fanLocalCSS3D.name = 'text3';
  266. fanLocalCSS3D.scale.set(0.07, 0.07, 0.07);
  267. fanLocalCSS3D.rotation.y = -Math.PI / 2;
  268. fanLocalCSS3D.position.set(-25.97, 9.3, -15.09);
  269. group.add(fanLocalCSS3D);
  270. }
  271. }
  272. if (!group.getObjectByName('text4')) {
  273. const element = document.getElementById('gateBox') as HTMLElement;
  274. if (element) {
  275. // element.innerHTML = '';
  276. const fanLocalCSS3D = new CSS3DObject(element);
  277. fanLocalCSS3D.name = 'text4';
  278. fanLocalCSS3D.scale.set(0.04, 0.04, 0.04);
  279. fanLocalCSS3D.rotation.y = -Math.PI / 2;
  280. fanLocalCSS3D.position.set(-73.13, 8.44, -23.52);
  281. group.add(fanLocalCSS3D);
  282. }
  283. }
  284. if (!group.getObjectByName('text5')) {
  285. const element = document.getElementById('windownBox') as HTMLElement;
  286. if (element) {
  287. // element.innerHTML = '';
  288. const fanLocalCSS3D = new CSS3DObject(element);
  289. fanLocalCSS3D.name = 'text5';
  290. fanLocalCSS3D.scale.set(0.07, 0.07, 0.07);
  291. fanLocalCSS3D.rotation.y = -Math.PI / 2;
  292. fanLocalCSS3D.position.set(-28.44, 9.78, -40.42);
  293. group.add(fanLocalCSS3D);
  294. }
  295. }
  296. if (!group.getObjectByName('text6')) {
  297. const element = document.getElementById('inputBox1') as HTMLElement;
  298. if (element) {
  299. const fanLocalCSS3D = new CSS3DObject(element);
  300. fanLocalCSS3D.name = 'text6';
  301. fanLocalCSS3D.scale.set(0.04, 0.04, 0.04);
  302. fanLocalCSS3D.rotation.y = -Math.PI / 2;
  303. fanLocalCSS3D.position.set(-84.23, 4.97, -18.92);
  304. group.add(fanLocalCSS3D);
  305. }
  306. }
  307. };
  308. // export const playSmoke = (controlType, deviceType, frequency, state) => {
  309. // if (frequency) {
  310. // setSmokeFrequency(deviceType, frequency);
  311. // }
  312. // if (controlType === 'startSmoke') {
  313. // runFly(deviceType, state);
  314. // }
  315. // };
  316. export const playSmoke = (selectData) => {
  317. // debugger;
  318. console.log('selectData[Fan1fHz]------------》', selectData['Fan1fHz'], Number(selectData['Fan1fHz']));
  319. if (selectData['Fan1StartStatus'] == '1') {
  320. // 主风机打开
  321. // setSmokeFrequency('top', Number(selectData['Fan1fHz']) || 40);
  322. setSmokeFrequency('top', 40);
  323. runFly('top', 'open');
  324. } else {
  325. // 备风机关闭
  326. runFly('top', 'close');
  327. }
  328. if (selectData['Fan2StartStatus'] == '1') {
  329. // 备风机打开
  330. // setSmokeFrequency('down', Number(selectData['Fan2fHz']) || 40);
  331. setSmokeFrequency('down', 40);
  332. runFly('down', 'open');
  333. } else {
  334. // 备风机关闭
  335. runFly('down', 'close');
  336. }
  337. if (selectData['Fan1StartStatus'] != '1' && selectData['Fan2StartStatus'] != '1') {
  338. runFly('all', 'close');
  339. }
  340. // if (frequency) {
  341. // setSmokeFrequency(deviceType, frequency);
  342. // }
  343. // if (controlType === 'startSmoke') {
  344. // runFly(deviceType, state);
  345. // }
  346. };
  347. const initFly = async () => {
  348. const topCurve = [
  349. {
  350. path0: new THREE.Vector3(-89.84, 2.359, 4.91),
  351. path1: new THREE.Vector3(-85.678, 2.359, 3.61),
  352. isSpread: true,
  353. spreadDirection: -1, //
  354. },
  355. {
  356. path0: new THREE.Vector3(-85.678, 2.352, 3.66),
  357. path1: new THREE.Vector3(-85.636, 2.353, -3.829),
  358. isSpread: false,
  359. spreadDirection: 0,
  360. },
  361. {
  362. path0: new THREE.Vector3(-85.636, 2.353, -3.829),
  363. path1: new THREE.Vector3(-85.636, 1.026, -5.881),
  364. isSpread: false,
  365. spreadDirection: 0,
  366. },
  367. {
  368. path0: new THREE.Vector3(-85.636, 1.026, -5.881),
  369. path1: new THREE.Vector3(-85.618, 0.887, -12.862),
  370. isSpread: false,
  371. spreadDirection: 0,
  372. },
  373. {
  374. path0: new THREE.Vector3(-85.618, 0.827, -12.962),
  375. path1: new THREE.Vector3(80.404, 0.827, -12.962),
  376. isSpread: false,
  377. spreadDirection: 0,
  378. },
  379. {
  380. path0: new THREE.Vector3(80.404, 0.827, -12.962),
  381. path1: new THREE.Vector3(93.164, 0.85, -12.962),
  382. isSpread: true,
  383. spreadDirection: 1, // 1是由小变大,-1是由大变小
  384. },
  385. ];
  386. const downCurve = [
  387. {
  388. path0: new THREE.Vector3(-94.84, -0.388, 3.61),
  389. path1: new THREE.Vector3(-85.678, -0.393, 3.61),
  390. isSpread: true,
  391. spreadDirection: -1, //
  392. },
  393. {
  394. path0: new THREE.Vector3(-85.678, -0.393, 3.275),
  395. path1: new THREE.Vector3(-85.636, -0.392, -3.829),
  396. isSpread: false,
  397. spreadDirection: 0,
  398. },
  399. {
  400. path0: new THREE.Vector3(-85.636, -0.392, -3.829),
  401. path1: new THREE.Vector3(-85.636, 0.926, -5.881),
  402. isSpread: false,
  403. spreadDirection: 0,
  404. },
  405. {
  406. path0: new THREE.Vector3(-85.636, 1.026, -5.881),
  407. path1: new THREE.Vector3(-85.618, 0.887, -12.862),
  408. isSpread: false,
  409. spreadDirection: 0,
  410. },
  411. {
  412. path0: new THREE.Vector3(-85.618, 0.887, -12.962),
  413. path1: new THREE.Vector3(80.404, 0.887, -12.962),
  414. isSpread: false,
  415. spreadDirection: 0,
  416. },
  417. {
  418. path0: new THREE.Vector3(80.404, 0.887, -12.962),
  419. path1: new THREE.Vector3(93.164, 0.91, -12.962),
  420. isSpread: true,
  421. spreadDirection: 1, // 1是由小变大,-1是由大变小
  422. },
  423. ];
  424. const returnCurve = [
  425. {
  426. path0: new THREE.Vector3(93.164, 0.85, -12.962),
  427. path1: new THREE.Vector3(86.39, 0.827, -12.962),
  428. isSpread: false,
  429. spreadDirection: 2,
  430. },
  431. {
  432. path0: new THREE.Vector3(86.39, 0.827, -12.962),
  433. path1: new THREE.Vector3(83.341, 0.847, -17.658),
  434. isSpread: false,
  435. spreadDirection: 2,
  436. },
  437. {
  438. path0: new THREE.Vector3(83.341, 0.847, -17.658),
  439. path1: new THREE.Vector3(-29.077, 0.847, -17.658),
  440. isSpread: false,
  441. spreadDirection: 2,
  442. },
  443. {
  444. path0: new THREE.Vector3(-29.077, 0.847, -17.658),
  445. path1: new THREE.Vector3(-29.64, 0.827, -39.047),
  446. isSpread: false,
  447. spreadDirection: 2,
  448. },
  449. ];
  450. if (!topSmoke) {
  451. topSmoke = new Smoke('/model/img/texture-smoke.png', '#ffffff', 0, 0.75, 0.5, 400);
  452. topSmoke.setPath(topCurve);
  453. await topSmoke.setPoints();
  454. group?.add(topSmoke.points);
  455. }
  456. if (!downSmoke) {
  457. downSmoke = new Smoke('/model/img/texture-smoke.png', '#ffffff', 0, 0.75, 0.5, 400);
  458. downSmoke.setPath(downCurve);
  459. await downSmoke.setPoints();
  460. group?.add(downSmoke.points);
  461. }
  462. if (!returnSmoke) {
  463. returnSmoke = new Smoke('/model/img/texture-smoke.png', '#777777', 0, 0.35, 1.5, 200);
  464. returnSmoke.setPath(returnCurve);
  465. await returnSmoke.setPoints();
  466. group?.add(returnSmoke.points);
  467. }
  468. };
  469. const runFly = (deviceType, state) => {
  470. if (state === 'open') {
  471. if (deviceType === 'top') {
  472. if (downSmoke && downSmoke.frameId) {
  473. downSmoke.stopSmoke();
  474. }
  475. if (topSmoke && !topSmoke.frameId) {
  476. topSmoke.startSmoke();
  477. }
  478. } else {
  479. if (topSmoke && topSmoke.frameId) {
  480. topSmoke.stopSmoke();
  481. }
  482. if (downSmoke && !downSmoke.frameId) {
  483. downSmoke.startSmoke();
  484. }
  485. }
  486. if (returnSmoke && !returnSmoke.frameId) {
  487. returnSmoke?.startSmoke();
  488. }
  489. } else {
  490. if (deviceType === 'top') {
  491. if (topSmoke && topSmoke.frameId) {
  492. topSmoke.stopSmoke();
  493. }
  494. } else {
  495. if (downSmoke && downSmoke.frameId) {
  496. downSmoke.stopSmoke();
  497. }
  498. }
  499. }
  500. if (deviceType === 'all' && state === 'close') {
  501. returnSmoke?.stopSmoke();
  502. }
  503. };
  504. // 调频 30-50 (life 300 - 800) , 25 = (800 - 300)/ 20
  505. const setSmokeFrequency = (deviceType, frequency) => {
  506. const life = (frequency - 30) * 25;
  507. let duration = 0;
  508. let smoke;
  509. if (deviceType === 'top') {
  510. if (topLife == life) {
  511. return;
  512. }
  513. topLife = life;
  514. smoke = topSmoke;
  515. duration = (Math.abs(life - smoke.life) / 500) * 25;
  516. } else {
  517. if (downLife == life) {
  518. return;
  519. }
  520. downLife = life;
  521. smoke = downSmoke;
  522. duration = (Math.abs(life - smoke.life) / 500) * 25;
  523. }
  524. if (smoke) {
  525. gsap.to(smoke, {
  526. life: life,
  527. duration: duration,
  528. ease: 'easeInCubic',
  529. overwrite: true,
  530. });
  531. }
  532. };
  533. const clearFly = () => {
  534. if (topSmoke) topSmoke.clearSmoke();
  535. if (downSmoke) downSmoke.clearSmoke();
  536. if (returnSmoke) returnSmoke.clearSmoke();
  537. };
  538. // 初始化事件
  539. const startAnimation = () => {
  540. // 定义鼠标点击事件
  541. model.canvasContainer?.addEventListener('mousedown', mouseEvent.bind(null));
  542. model.canvasContainer?.addEventListener('pointerup', mouseUp);
  543. };
  544. // 鼠标点击、松开事件
  545. const mouseEvent = (event) => {
  546. if (event.button == 0) {
  547. model?.canvasContainer?.addEventListener('mousemove', mousemove);
  548. mouseDownFn(<UseThree>model, <THREE.Object3D>group, event, (intersects) => {
  549. intersects.find((intersect) => {
  550. const mesh = intersect.object;
  551. });
  552. });
  553. console.log('摄像头控制信息', model?.orbitControls, model?.camera);
  554. }
  555. };
  556. const mouseUp = () => {
  557. if (!model) return;
  558. mouseUpFn(model);
  559. model.canvasContainer?.removeEventListener('mousemove', mousemove);
  560. };
  561. const mousemove = () => {
  562. mousemoveFn();
  563. };
  564. export const mountedThree = (playerVal1) => {
  565. player1 = playerVal1;
  566. return new Promise((resolve) => {
  567. // model = VENT_PARAM['simulatedPassword'] ? new UseThree('#fanLocal3D', '#fanLocal3DCSS') : new UseThree('#fanLocal3D');
  568. model = new UseThree('#fanLocal3D', '#fanLocal3DCSS');
  569. model.setEnvMap('test1');
  570. model.renderer.toneMappingExposure = 1.0;
  571. if (model.renderer) {
  572. model.renderer.sortObjects = true;
  573. }
  574. resetCamera();
  575. model.setGLTFModel([modelName]).then(async (gltf) => {
  576. group = <THREE.Object3D>gltf[0];
  577. const Fengtongbu01 = group?.getObjectByName('Cylinder1054') as THREE.Mesh;
  578. if (Fengtongbu01) {
  579. const textMaterial = new THREE.MeshBasicMaterial({
  580. color: '#000',
  581. transparent: true,
  582. opacity: 0.3,
  583. side: THREE.DoubleSide, // 这里是双面渲染的意思
  584. });
  585. Fengtongbu01.material = textMaterial;
  586. Fengtongbu01.renderOrder = 300;
  587. }
  588. model?.scene?.add(group);
  589. setModalPosition();
  590. setControls();
  591. await initFly();
  592. model?.animate();
  593. addLight(model?.scene);
  594. fcFanObj = new fcFan(model);
  595. await fcFanObj.mountedThree();
  596. fmFanObj = new fmFan(model);
  597. await fmFanObj.mountedThree();
  598. startAnimation();
  599. resolve(model);
  600. });
  601. });
  602. };
  603. export const destroy = () => {
  604. if (model) {
  605. model.isRender = false;
  606. console.log('场景销毁后信息----------->', model.renderer?.info);
  607. clearFly();
  608. topSmoke = undefined;
  609. downSmoke = undefined;
  610. returnSmoke = undefined;
  611. if (fcFanObj) fcFanObj.destroy();
  612. if (fmFanObj) fmFanObj.destroy();
  613. group = undefined;
  614. model.destroy();
  615. model = undefined;
  616. }
  617. };