chamber.threejs.base.ts 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. import * as THREE from 'three';
  2. import { setModalCenter } from '/@/utils/threejs/util';
  3. // import * as dat from 'dat.gui';
  4. // const gui = new dat.GUI();
  5. // gui.domElement.style = 'position:absolute;top:100px;left:10px;z-index:99999999999999';
  6. class ChamberBase {
  7. model;
  8. modelName = 'chamber';
  9. group: THREE.Object3D | null = null;
  10. constructor(model) {
  11. this.model = model;
  12. }
  13. addLight() {
  14. const directionalLight = new THREE.DirectionalLight(0xffffff, 1.2);
  15. directionalLight.position.set(-0.8, 23, 3.9);
  16. this.group?.add(directionalLight);
  17. directionalLight.target = this.group as THREE.Object3D;
  18. // gui.add(directionalLight.position, 'x', -10, 20).onChange(function (value) {
  19. // directionalLight.position.x = Number(value);
  20. // _this.render();
  21. // });
  22. // gui.add(directionalLight.position, 'y', -50, 50).onChange(function (value) {
  23. // directionalLight.position.y = Number(value);
  24. // _this.render();
  25. // });
  26. // gui.add(directionalLight.position, 'z', -20, 20).onChange(function (value) {
  27. // directionalLight.position.z = Number(value);
  28. // _this.render();
  29. // });
  30. // const pointLight5 = new THREE.PointLight(0xffffff, 0.8, 120);
  31. // pointLight5.position.set(-54, 30, 23.8);
  32. // pointLight5.shadow.bias = 0.05;
  33. // this.group.add(pointLight5);
  34. // const pointLight7 = new THREE.PointLight(0xffffff, 1, 1000);
  35. // pointLight7.position.set(45, 51, -4.1);
  36. // pointLight7.shadow.bias = 0.05;
  37. // this.model.scene.add(pointLight7);
  38. const spotLight = new THREE.SpotLight();
  39. spotLight.angle = Math.PI / 2;
  40. spotLight.penumbra = 0;
  41. spotLight.castShadow = true;
  42. spotLight.intensity = 1;
  43. spotLight.shadow.camera.near = 0.5; // default
  44. spotLight.shadow.focus = 1.2;
  45. spotLight.shadow.bias = -0.000002;
  46. spotLight.position.set(-7.19, 199, -68.1);
  47. // this.group.add(spotLight);
  48. // gui.add(directionalLight.position, 'x', -10, 20).onChange(function (value) {
  49. // directionalLight.position.x = Number(value);
  50. // _this.render();
  51. // });
  52. // gui.add(directionalLight.position, 'y', -50, 50).onChange(function (value) {
  53. // directionalLight.position.y = Number(value);
  54. // _this.render();
  55. // });
  56. // gui.add(directionalLight.position, 'z', -20, 20).onChange(function (value) {
  57. // directionalLight.position.z = Number(value);
  58. // _this.render();
  59. // });
  60. // gui.add(spotLight.position, 'x', -600, 600).onChange(function (value) {
  61. // spotLight.position.x = Number(value);
  62. // _this.render();
  63. // });
  64. // gui.add(spotLight.position, 'y', -600, 800).onChange(function (value) {
  65. // spotLight.position.y = Number(value);
  66. // _this.render();
  67. // });
  68. // gui.add(spotLight.position, 'z', -500, 1000).onChange(function (value) {
  69. // spotLight.position.z = Number(value);
  70. // _this.render();
  71. // });
  72. }
  73. mountedThree() {
  74. return new Promise((resolve) => {
  75. this.model.setGLTFModel([this.modelName]).then((gltf) => {
  76. this.group = gltf[0];
  77. if (this.group) {
  78. this.group?.scale.set(0.1, 0.1, 0.1);
  79. this.group.position.y += 40;
  80. resolve(null);
  81. this.addLight();
  82. }
  83. });
  84. });
  85. }
  86. destroy() {
  87. this.model.clearGroup(this.group);
  88. this.model = null;
  89. this.group = null;
  90. }
  91. }
  92. export default ChamberBase;