chamber.threejs.base.ts 3.3 KB

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