1
0

workFace.threejs.base.ts 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576
  1. import * as THREE from 'three';
  2. import { EffectComposer } from 'three/examples/jsm/postprocessing/EffectComposer.js';
  3. import { RenderPass } from 'three/examples/jsm/postprocessing/RenderPass.js';
  4. import { ShaderPass } from 'three/examples/jsm/postprocessing/ShaderPass.js';
  5. import { OutlinePass } from 'three/examples/jsm/postprocessing/OutlinePass.js';
  6. import { FXAAShader } from 'three/examples/jsm/shaders/FXAAShader.js';
  7. import { UnrealBloomPass } from 'three/examples/jsm/postprocessing/UnrealBloomPass.js';
  8. import { OutputPass } from 'three/examples/jsm/postprocessing/OutputPass.js';
  9. import { setModalCenter, setTag3D, gradientColors } from '/@/utils/threejs/util';
  10. import { CSS3DObject } from 'three/examples/jsm/renderers/CSS3DRenderer.js';
  11. import { number } from 'vue-types';
  12. // import * as dat from 'dat.gui';
  13. // const gui = new dat.GUI();
  14. // gui.domElement.style = 'position:absolute;top:100px;left:10px;z-index:99999999999999';
  15. class WorkFace {
  16. model;
  17. modelName = 'workFace';
  18. group: THREE.Object3D = new THREE.Object3D();
  19. planeGroup: THREE.Group = new THREE.Group();
  20. bloomComposer: EffectComposer | null = null;
  21. finalComposer: EffectComposer | null = null;
  22. outlinePass: OutlinePass | null = null;
  23. positions: THREE.Vector3[][] = [];
  24. bloomLayer = new THREE.Layers();
  25. darkMaterial = new THREE.MeshBasicMaterial({ color: 'black', transparent: true, side: THREE.DoubleSide });
  26. materials = {};
  27. glob = {
  28. ENTIRE_SCENE: 0,
  29. BLOOM_SCENE: 10,
  30. N: 100,
  31. };
  32. locationTexture: THREE.Texture | null = null;
  33. warningLocationTexture: THREE.Texture | null = null;
  34. errorLocationTexture: THREE.Texture | null = null;
  35. playerStartClickTime1 = new Date().getTime();
  36. playerStartClickTime2 = new Date().getTime();
  37. planeNum = 0;
  38. constructor(model) {
  39. this.model = model;
  40. this.group.name = this.modelName;
  41. }
  42. addLight() {
  43. // const _this = this;
  44. const directionalLight = new THREE.DirectionalLight(0xffffff, 1);
  45. directionalLight.position.set(-196, 150, 258);
  46. this.group.add(directionalLight);
  47. directionalLight.target = this.group;
  48. // const pointLight = new THREE.PointLight(0xffffff, 1, 1000);
  49. // pointLight.position.set(12, 51, -27);
  50. // pointLight.shadow.bias = 0.05;
  51. // this.group.add(pointLight);
  52. // gui.add(directionalLight.position, 'x', -1000, 1000).onChange(() => {
  53. // _this.render();
  54. // });
  55. // gui.add(directionalLight.position, 'y', -1000, 1000).onChange(() => {
  56. // _this.render();
  57. // });
  58. // gui.add(directionalLight.position, 'z', -1000, 1000).onChange(() => {
  59. // _this.render();
  60. // });
  61. }
  62. render() {
  63. this.model.renderer?.render(this.model.scene as THREE.Scene, this.model.camera as THREE.PerspectiveCamera);
  64. // const _this = this;
  65. // if (this.model && this.model.scene.getObjectByName(this.modelName)) {
  66. // this.group?.traverse((obj) => {
  67. // _this.darkenNonBloomed(obj);
  68. // });
  69. // this.bloomComposer?.render();
  70. // this.group?.traverse((obj) => {
  71. // _this.restoreMaterial(obj);
  72. // });
  73. // this.finalComposer?.render();
  74. // }
  75. }
  76. // 绘制抽采单元
  77. setPlanes = (n, colors = new Array(n).fill(new THREE.Color('rgb(100%, 0%, 0%)'))) => {
  78. colors = gradientColors('#00FF2C', '#FF0000', n, 2);
  79. this.planeNum = n;
  80. const lenScale = 0.77 / n;
  81. const planeGeo = new THREE.PlaneGeometry();
  82. planeGeo.applyMatrix4(new THREE.Matrix4().makeTranslation(-1, 0, 0));
  83. for (let i = 0; i < n; i++) {
  84. const material = new THREE.MeshBasicMaterial({ color: colors[i], transparent: true, opacity: 0.6, depthTest: false, depthWrite: false });
  85. const plane = new THREE.Mesh(planeGeo, material);
  86. plane.name = 'unit' + i;
  87. plane.rotation.x = -Math.PI / 2;
  88. plane.scale.set(lenScale - 0.001, 0.375, 1.0);
  89. plane.position.set(0.282 - lenScale * (i - 0.5), 0.015, 0.142);
  90. this.planeGroup.add(plane);
  91. }
  92. };
  93. // 清除抽采单元绘制面
  94. clearPlanes = () => {
  95. for (let i = 0; i < this.planeNum; i++) {
  96. const plane = this.planeGroup.getObjectByName(`unit${i}`);
  97. const label = this.planeGroup.getObjectByName(`planeText${i}`);
  98. if (plane) this.planeGroup.remove(plane);
  99. if (label) this.planeGroup.remove(label);
  100. }
  101. };
  102. // 抽采单元内容显示
  103. setCss3D = () => {
  104. const obj = this.group.getObjectByName(`unitText`);
  105. if (!obj) {
  106. const element = document.getElementById(`gasUnitBox`) as HTMLElement;
  107. if (element) {
  108. const gasUnitCSS3D = new CSS3DObject(element);
  109. gasUnitCSS3D.name = `unitText`;
  110. gasUnitCSS3D.scale.set(0.0009, 0.0009, 0.0009);
  111. gasUnitCSS3D.position.set(-0.1, 0.11, 0.05);
  112. gasUnitCSS3D.lookAt(-0.1, 0.5, 1);
  113. this.planeGroup.add(gasUnitCSS3D);
  114. }
  115. }
  116. for (let i = 0; i < this.planeNum; i++) {
  117. const lenScale = 0.77 / this.planeNum;
  118. const label = setTag3D(`抽采单元${i + 1}`, 'gas_unit_text');
  119. label.scale.set(0.0018, 0.0018, 1); //根据相机渲染范围控制HTML 3D标签尺寸
  120. label.position.set(0.282 - lenScale * (i + 0.5), 0.015, 0.142);
  121. label.name = 'planeText' + i;
  122. this.planeGroup.add(label);
  123. }
  124. };
  125. // 显示或隐藏抽采单元显示内容
  126. changeCss3D = (isHide) => {
  127. for (let i = 0; i < this.planeNum; i++) {
  128. const obj = this.group.getObjectByName(`unitText${i}`);
  129. if (obj) {
  130. obj.visible = isHide;
  131. }
  132. }
  133. };
  134. // 清除抽采单元显示内容
  135. clearCss3D = () => {
  136. const obj = this.group.getObjectByName(`unitText`);
  137. if (obj) this.group.remove(obj);
  138. const element = document.getElementById(`gasUnitBox`) as HTMLElement;
  139. if (element) {
  140. element.remove();
  141. }
  142. for (let i = 0; i < this.planeNum; i++) {
  143. const label = this.planeGroup.getObjectByName(`planeText${i}`);
  144. if (label) this.planeGroup.remove(label);
  145. }
  146. };
  147. setRenderPass = () => {
  148. this.bloomLayer.set(this.glob.BLOOM_SCENE);
  149. const params = {
  150. bloomStrength: 2.5,
  151. bloomThreshold: 0,
  152. bloomRadius: 0,
  153. };
  154. const renderScene = new RenderPass(this.model.scene, this.model.camera);
  155. const bloomPass = new UnrealBloomPass(new THREE.Vector2(window.innerWidth, window.innerHeight), 1.5, 0.4, 0.85);
  156. bloomPass.strength = params.bloomStrength;
  157. bloomPass.radius = params.bloomRadius;
  158. bloomPass.threshold = params.bloomThreshold;
  159. this.bloomComposer = new EffectComposer(this.model.renderer);
  160. this.bloomComposer.renderToScreen = false;
  161. this.bloomComposer.addPass(renderScene);
  162. this.bloomComposer.addPass(bloomPass);
  163. const finalPass = new ShaderPass(
  164. new THREE.ShaderMaterial({
  165. uniforms: {
  166. baseTexture: { value: null },
  167. bloomTexture: { value: this.bloomComposer.renderTarget2.texture },
  168. },
  169. vertexShader: `
  170. varying vec2 vUv;
  171. void main() {
  172. vUv = uv;
  173. gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
  174. }`,
  175. fragmentShader: `uniform sampler2D baseTexture;
  176. uniform sampler2D bloomTexture;
  177. varying vec2 vUv;
  178. void main() {
  179. gl_FragColor = ( texture2D( baseTexture, vUv ) + vec4( 1.0, 1.0, 1.0, 0.0 ) * texture2D( bloomTexture, vUv ) );
  180. }`,
  181. defines: {},
  182. }),
  183. 'baseTexture'
  184. );
  185. // const gammaCorrection = new ShaderPass(GammaCorrectionShader);
  186. const outputPass = new OutputPass();
  187. finalPass.needsSwap = true;
  188. this.model.renderer.toneMapping = THREE.ReinhardToneMapping;
  189. this.finalComposer = new EffectComposer(this.model.renderer);
  190. this.finalComposer.addPass(renderScene);
  191. this.finalComposer.addPass(outputPass);
  192. this.finalComposer.addPass(finalPass);
  193. const effectFXAA = new ShaderPass(FXAAShader);
  194. effectFXAA.uniforms['resolution'].value.set(1 / window.innerWidth, 1 / window.innerHeight);
  195. this.finalComposer.addPass(effectFXAA);
  196. // this.outlinePass = new OutlinePass(new THREE.Vector2(window.innerWidth, window.innerHeight), this.model.scene, this.model.camera);
  197. // this.finalComposer.addPass(this.outlinePass);
  198. };
  199. getPositions(num = 40) {
  200. const curve1 = new THREE.LineCurve3(new THREE.Vector3(-595.2, 0.046, -2.863), new THREE.Vector3(595.2, 0.046, -2.863)); // 前
  201. const curve2 = new THREE.LineCurve3(new THREE.Vector3(-595.065, 0.014, 1.696), new THREE.Vector3(595.048, 0.014, 1.696)); // 中
  202. const curve3 = new THREE.LineCurve3(new THREE.Vector3(0.0, 0.0, 190.611), new THREE.Vector3(0.0, 0.0, -190.611)); // 后‘
  203. const len1 = curve1.getLength();
  204. const len2 = curve2.getLength();
  205. const len3 = curve3.getLength();
  206. const unit = (len1 + len2 + len3) / num;
  207. const num1 = Math.floor(len1 / unit);
  208. const num2 = Math.floor(len2 / unit);
  209. const num3 = Math.floor(len3 / unit);
  210. const points1 = curve1.getPoints(num1);
  211. const points2 = curve2.getPoints(num2);
  212. const points3 = curve3.getPoints(num3);
  213. this.positions = [points1, points2, points3];
  214. }
  215. drawSpheres = () => {
  216. const _this = this;
  217. const pointLines = new THREE.Object3D();
  218. pointLines.name = 'pointLines';
  219. return new Promise((resolve) => {
  220. new THREE.TextureLoader().load('/model/img/texture-smoke.png', (texture) => {
  221. const material = new THREE.PointsMaterial({
  222. color: '#FFFFFF',
  223. size: 0.008,
  224. map: texture,
  225. opacity: 0.8,
  226. transparent: true, // 开启透明度
  227. });
  228. _this.positions.forEach((position, index) => {
  229. const geometry = new THREE.BufferGeometry();
  230. geometry.setFromPoints(position);
  231. const points = new THREE.Points(geometry, material);
  232. points.renderOrder = 0;
  233. index == 0 ? (points.name = 'line_q') : index == 1 ? (points.name = 'line_h') : (points.name = 'line_z');
  234. let opticalfiber;
  235. if (index == 0) {
  236. points.name = 'line_q';
  237. opticalfiber = this.group.getObjectByName('opticalfiber03');
  238. } else if (index == 1) {
  239. points.name = 'line_h';
  240. opticalfiber = this.group.getObjectByName('opticalfiber01');
  241. } else {
  242. points.name = 'line_z';
  243. opticalfiber = this.group.getObjectByName('opticalfiber02');
  244. }
  245. if (opticalfiber) points.applyMatrix4(opticalfiber.matrix);
  246. const box = new THREE.Box3();
  247. box.setFromObject(points);
  248. // points.geometry.boundingBox?.set(box);
  249. pointLines.add(points);
  250. points.layers.enable(_this.glob.BLOOM_SCENE);
  251. });
  252. this.group.add(pointLines);
  253. resolve(null);
  254. texture.dispose();
  255. });
  256. });
  257. };
  258. darkenNonBloomed(obj) {
  259. if (obj.isMesh && this.bloomLayer.test(obj.layers) === false) {
  260. const opacity = obj.material.opacity;
  261. this.materials[obj.uuid] = obj.material;
  262. obj.material = this.darkMaterial.clone();
  263. obj.material.opacity = opacity;
  264. }
  265. }
  266. restoreMaterial(obj) {
  267. if (this.materials[obj.uuid]) {
  268. obj.material = this.materials[obj.uuid];
  269. delete this.materials[obj.uuid];
  270. }
  271. }
  272. resetMesh() {
  273. // const opticalFiber = this.group.getObjectByName('opticalfiber');
  274. const optical = this.group?.getObjectByName('optical_fiber_02');
  275. const optical1 = this.group?.getObjectByName('optical_fiber_01');
  276. const optical2 = this.group?.getObjectByName('optical_fiber_03');
  277. if (optical && optical1 && optical2) {
  278. optical.renderOrder = 100;
  279. optical1.renderOrder = 100;
  280. optical2.renderOrder = 100;
  281. optical.material =
  282. optical1.material =
  283. optical2.material =
  284. new THREE.MeshStandardMaterial({
  285. color: 0x555555,
  286. side: THREE.DoubleSide,
  287. transparent: true,
  288. opacity: 0.45,
  289. });
  290. }
  291. }
  292. /* 点击 */
  293. mousedownModel(rayCaster: THREE.Raycaster) {
  294. const opticalFiber = this.group.getObjectByName('opticalfiber');
  295. if (opticalFiber) {
  296. const intersects = rayCaster?.intersectObjects([...opticalFiber.children]) as THREE.Intersection[];
  297. // 判断是否点击到视频
  298. intersects.find((intersect) => {
  299. const mesh = intersect.object;
  300. if (mesh.name.startsWith('optical_fiber_')) {
  301. // outlinePass?.selectedObjects.push(mesh);
  302. return true;
  303. }
  304. return false;
  305. });
  306. }
  307. this.render();
  308. }
  309. mouseUpModel() {
  310. //
  311. }
  312. setThreePlane() {
  313. const gltfModal = this.group.getObjectByName('workFace');
  314. const PouMian01 = gltfModal?.getObjectByName('PouMian01');
  315. const DiXing = PouMian01?.getObjectByName('DiXing');
  316. // 绘制采空区三带
  317. // new THREE.Vector3(934.695, -141.85, -365.375),
  318. // new THREE.Vector3(934.695, 623.933, -365.375),
  319. //-365.355
  320. const material1 = new THREE.MeshBasicMaterial({ side: THREE.DoubleSide, vertexColors: true });
  321. const offeset = 10;
  322. const yellowLen = offeset * 8;
  323. // 红=》红
  324. const curveRed = new THREE.CatmullRomCurve3([new THREE.Vector3(-477.721, -141.83, -365.375), new THREE.Vector3(-477.721, 623.933, -365.375)]);
  325. const curve0 = new THREE.CatmullRomCurve3([
  326. new THREE.Vector3(-231.811 - 150, -141.83, -365.375),
  327. new THREE.Vector3(-121.899 - 150, 67.201, -365.375),
  328. new THREE.Vector3(-242.441 - 150, 408.812, -365.375),
  329. new THREE.Vector3(-179.811 - 150, 620.836, -365.375),
  330. ]);
  331. const pointsRed = curveRed.getPoints(80);
  332. const points0 = curve0.getPoints(80);
  333. const newPointRed: number[] = [];
  334. const normalsRed: number[] = [];
  335. const colorsRed: number[] = [];
  336. for (let i = 0; i < 80; i++) {
  337. newPointRed.push(pointsRed[i].x, pointsRed[i].y, pointsRed[i].z);
  338. newPointRed.push(points0[i].x, points0[i].y, points0[i].z);
  339. newPointRed.push(points0[i + 1].x, points0[i + 1].y, points0[i + 1].z);
  340. newPointRed.push(points0[i + 1].x, points0[i + 1].y, points0[i + 1].z);
  341. newPointRed.push(pointsRed[i + 1].x, pointsRed[i + 1].y, pointsRed[i + 1].z);
  342. newPointRed.push(pointsRed[i].x, pointsRed[i].y, pointsRed[i].z);
  343. normalsRed.push(0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1);
  344. colorsRed.push(1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0);
  345. }
  346. const geometryRed = new THREE.BufferGeometry();
  347. geometryRed.setAttribute('position', new THREE.BufferAttribute(new Float32Array(newPointRed), 3));
  348. geometryRed.setAttribute('normal', new THREE.BufferAttribute(new Float32Array(normalsRed), 3));
  349. geometryRed.setAttribute('color', new THREE.BufferAttribute(new Float32Array(colorsRed), 3));
  350. const meshRed = new THREE.Mesh(geometryRed, material1);
  351. meshRed.position.setZ(-1);
  352. DiXing?.add(meshRed);
  353. // 红=》黄
  354. const curve1 = new THREE.CatmullRomCurve3([
  355. new THREE.Vector3(-231.811 - yellowLen, -141.83, -365.375),
  356. new THREE.Vector3(-121.899 - yellowLen, 67.201, -365.375),
  357. new THREE.Vector3(-242.441 - yellowLen, 408.812, -365.375),
  358. new THREE.Vector3(-179.811 - yellowLen, 620.836, -365.375),
  359. ]);
  360. const points1 = curve1.getPoints(80);
  361. const newPoints0: number[] = [];
  362. const normals0: number[] = [];
  363. const colors0: number[] = [];
  364. for (let i = 0; i < 80; i++) {
  365. newPoints0.push(points0[i].x, points0[i].y, points0[i].z);
  366. newPoints0.push(points1[i].x, points1[i].y, points1[i].z);
  367. newPoints0.push(points1[i + 1].x, points1[i + 1].y, points1[i + 1].z);
  368. newPoints0.push(points1[i + 1].x, points1[i + 1].y, points1[i + 1].z);
  369. newPoints0.push(points0[i + 1].x, points0[i + 1].y, points0[i + 1].z);
  370. newPoints0.push(points0[i].x, points0[i].y, points0[i].z);
  371. normals0.push(0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1);
  372. colors0.push(1, 0, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 0);
  373. }
  374. const geometry0 = new THREE.BufferGeometry();
  375. geometry0.setAttribute('position', new THREE.BufferAttribute(new Float32Array(newPoints0), 3));
  376. geometry0.setAttribute('normal', new THREE.BufferAttribute(new Float32Array(normals0), 3));
  377. geometry0.setAttribute('color', new THREE.BufferAttribute(new Float32Array(colors0), 3));
  378. geometry0.computeBoundingBox();
  379. // const material1 = new THREE.MeshBasicMaterial({ side: THREE.DoubleSide, color: '#fff' });
  380. const mesh0 = new THREE.Mesh(geometry0, material1);
  381. mesh0.name = 'yellow';
  382. mesh0.position.setZ(-1);
  383. DiXing?.add(mesh0);
  384. // 黄=》黄
  385. const curveYellow1 = new THREE.CatmullRomCurve3([
  386. new THREE.Vector3(-179.811 + offeset, 620.836, -365.375),
  387. new THREE.Vector3(-242.441 + offeset, 408.812, -365.375),
  388. new THREE.Vector3(-121.899 + offeset, 67.201, -365.375),
  389. new THREE.Vector3(-231.811 + offeset, -141.83, -365.375),
  390. ]);
  391. const curveYellow2 = new THREE.CatmullRomCurve3([
  392. new THREE.Vector3(-179.811 - yellowLen, 620.836, -365.375),
  393. new THREE.Vector3(-242.441 - yellowLen, 408.812, -365.375),
  394. new THREE.Vector3(-121.899 - yellowLen, 67.201, -365.375),
  395. new THREE.Vector3(-231.811 - yellowLen, -141.83, -365.375),
  396. ]);
  397. const pointsYellow1 = curveYellow1.getPoints(80);
  398. const pointsYellow2 = curveYellow2.getPoints(80);
  399. const newPointYellow: number[] = [];
  400. const normalsYellow: number[] = [];
  401. const colorsYellow: number[] = [];
  402. for (let i = 0; i < 80; i++) {
  403. newPointYellow.push(pointsYellow1[i].x, pointsYellow1[i].y, pointsYellow1[i].z);
  404. newPointYellow.push(pointsYellow2[i].x, pointsYellow2[i].y, pointsYellow2[i].z);
  405. newPointYellow.push(pointsYellow2[i + 1].x, pointsYellow2[i + 1].y, pointsYellow2[i + 1].z);
  406. newPointYellow.push(pointsYellow2[i + 1].x, pointsYellow2[i + 1].y, pointsYellow2[i + 1].z);
  407. newPointYellow.push(pointsYellow1[i + 1].x, pointsYellow1[i + 1].y, pointsYellow1[i + 1].z);
  408. newPointYellow.push(pointsYellow1[i].x, pointsYellow1[i].y, pointsYellow1[i].z);
  409. normalsYellow.push(0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1);
  410. colorsYellow.push(1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0);
  411. }
  412. const geometryYellow = new THREE.BufferGeometry();
  413. geometryYellow.setAttribute('position', new THREE.BufferAttribute(new Float32Array(newPointYellow), 3));
  414. geometryYellow.setAttribute('normal', new THREE.BufferAttribute(new Float32Array(normalsYellow), 3));
  415. geometryYellow.setAttribute('color', new THREE.BufferAttribute(new Float32Array(colorsYellow), 3));
  416. const meshYellow = new THREE.Mesh(geometryYellow, material1);
  417. meshYellow.position.setZ(-1);
  418. DiXing?.add(meshYellow);
  419. // 蓝 =》 蓝
  420. const curve3 = new THREE.CatmullRomCurve3([
  421. new THREE.Vector3(784.664, 623.933, -365.355),
  422. new THREE.Vector3(167.212, 450.517, -365.355),
  423. new THREE.Vector3(7.587, 262.225, -365.355),
  424. new THREE.Vector3(426.499, 31.416, -365.355),
  425. new THREE.Vector3(261.665, -139.495, -365.355),
  426. ]);
  427. const points = curve3.getPoints(80);
  428. points.unshift(new THREE.Vector3(934.695, 623.933, -365.375));
  429. points.unshift(new THREE.Vector3(934.695, -141.85, -365.375));
  430. points.push(new THREE.Vector3(934.695, -141.85, -365.375));
  431. const newPoints: THREE.Vector2[] = [];
  432. for (let i = 0; i < points.length; i++) {
  433. const point = points[i];
  434. newPoints.push(new THREE.Vector2(point.x, point.y));
  435. }
  436. const shape = new THREE.Shape(newPoints);
  437. const geometry = new THREE.ShapeGeometry(shape);
  438. const material = new THREE.MeshBasicMaterial({ side: THREE.BackSide, color: '#00F' });
  439. const mesh = new THREE.Mesh(geometry, material);
  440. mesh.position.setZ(-366.485);
  441. DiXing?.add(mesh);
  442. // 黄色-》蓝色
  443. const curve2 = new THREE.CatmullRomCurve3([
  444. new THREE.Vector3(-179.811 + offeset, 620.836, -365.375),
  445. new THREE.Vector3(-242.441 + offeset, 408.812, -365.375),
  446. new THREE.Vector3(-121.899 + offeset, 67.201, -365.375),
  447. new THREE.Vector3(-231.811 + offeset, -141.83, -365.375),
  448. ]);
  449. const points2 = curve2.getPoints(80);
  450. const points3 = curve3.getPoints(80);
  451. const newPoints1: number[] = [];
  452. const normals: number[] = [];
  453. const colors: number[] = [];
  454. for (let i = 0; i < 80; i++) {
  455. newPoints1.push(points2[i].x, points2[i].y, points2[i].z);
  456. newPoints1.push(points3[i].x, points3[i].y, points3[i].z);
  457. newPoints1.push(points3[i + 1].x, points3[i + 1].y, points3[i + 1].z);
  458. newPoints1.push(points3[i + 1].x, points3[i + 1].y, points3[i + 1].z);
  459. newPoints1.push(points2[i + 1].x, points2[i + 1].y, points2[i + 1].z);
  460. newPoints1.push(points2[i].x, points2[i].y, points2[i].z);
  461. normals.push(0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1);
  462. colors.push(1, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 1, 1, 0);
  463. }
  464. const geometry1 = new THREE.BufferGeometry();
  465. geometry1.setAttribute('position', new THREE.BufferAttribute(new Float32Array(newPoints1), 3));
  466. geometry1.setAttribute('normal', new THREE.BufferAttribute(new Float32Array(normals), 3));
  467. geometry1.setAttribute('color', new THREE.BufferAttribute(new Float32Array(colors), 3));
  468. geometry1.computeBoundingBox();
  469. const mesh1 = new THREE.Mesh(geometry1, material1);
  470. mesh1.name = 'blue';
  471. mesh1.position.setZ(-1);
  472. DiXing?.add(mesh1);
  473. }
  474. setModalType(modalType) {
  475. // debugger;
  476. const gltfModal = this.group.getObjectByName('workFace');
  477. const workFace1 = gltfModal?.getObjectByName('YiJinYiHui');
  478. const workFace2 = gltfModal?.getObjectByName('LiangJinYiHui');
  479. const workFace3 = gltfModal?.getObjectByName('LiangJinLiangHui');
  480. if (workFace1 && workFace2 && workFace3) {
  481. if (modalType === 'workFace1') {
  482. // 单进单回
  483. workFace1.visible = true;
  484. workFace2.visible = false;
  485. workFace3.visible = false;
  486. } else if (modalType === 'workFace3') {
  487. // 双进单回
  488. workFace1.visible = false;
  489. workFace2.visible = true;
  490. workFace3.visible = false;
  491. } else if (modalType === 'workFace4') {
  492. workFace1.visible = false;
  493. workFace2.visible = false;
  494. workFace3.visible = true;
  495. }
  496. }
  497. }
  498. mountedThree() {
  499. return new Promise(async (resolve) => {
  500. this.model.renderer.sortObjects = true;
  501. this.model.orbitControls.update();
  502. this.model.setGLTFModel('workFace').then(async (gltf) => {
  503. const gltfModal = gltf[0];
  504. this.group = gltfModal;
  505. this.group.name = this.modelName;
  506. setModalCenter(this.group);
  507. this.group.scale.set(2.5, 2.5, 2.5);
  508. // this.resetMesh();
  509. this.getPositions(this.glob.N);
  510. this.addLight();
  511. this.setThreePlane();
  512. // this.drawSpheres();
  513. resolve(null);
  514. });
  515. });
  516. }
  517. destroy() {
  518. this.model.clearGroup(this.group);
  519. this.model = null;
  520. this.group = null;
  521. this.bloomComposer?.dispose();
  522. this.finalComposer?.dispose();
  523. }
  524. }
  525. export default WorkFace;