chamber.threejs.base.ts 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. // gui.add(spotLight.position, 'x', -600, 600).onChange(function (value) {
  30. // spotLight.position.x = Number(value);
  31. // _this.render();
  32. // });
  33. // gui.add(spotLight.position, 'y', -600, 800).onChange(function (value) {
  34. // spotLight.position.y = Number(value);
  35. // _this.render();
  36. // });
  37. // gui.add(spotLight.position, 'z', -500, 1000).onChange(function (value) {
  38. // spotLight.position.z = Number(value);
  39. // _this.render();
  40. // });
  41. }
  42. mountedThree() {
  43. return new Promise((resolve) => {
  44. this.model.setGLTFModel([this.modelName]).then((gltf) => {
  45. this.group = gltf[0];
  46. if (this.group) {
  47. this.group?.scale.set(0.1, 0.1, 0.1);
  48. this.group.position.y += 40;
  49. resolve(null);
  50. this.addLight();
  51. }
  52. });
  53. });
  54. }
  55. destroy() {
  56. this.model.clearGroup(this.group);
  57. this.model = null;
  58. this.group = null;
  59. }
  60. }
  61. export default ChamberBase;