chamber.threejs.base.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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(15, 69, -39);
  15. this.group?.add(directionalLight);
  16. directionalLight.target = this.group as THREE.Object3D;
  17. // gui.add(directionalLight.position, 'x', -100, 100);
  18. // gui.add(directionalLight.position, 'y', -100, 100);
  19. // gui.add(directionalLight.position, 'z', -100, 100);
  20. // gui.add(spotLight.position, 'x', -600, 600).onChange(function (value) {
  21. // spotLight.position.x = Number(value);
  22. // _this.render();
  23. // });
  24. // gui.add(spotLight.position, 'y', -600, 800).onChange(function (value) {
  25. // spotLight.position.y = Number(value);
  26. // _this.render();
  27. // });
  28. // gui.add(spotLight.position, 'z', -500, 1000).onChange(function (value) {
  29. // spotLight.position.z = Number(value);
  30. // _this.render();
  31. // });
  32. }
  33. mountedThree() {
  34. return new Promise((resolve) => {
  35. this.model.setGLTFModel([this.modelName]).then((gltf) => {
  36. this.group = gltf[0];
  37. if (this.group) {
  38. this.group?.scale.set(0.1, 0.1, 0.1);
  39. this.group.position.y += 40;
  40. resolve(null);
  41. this.addLight();
  42. }
  43. });
  44. });
  45. }
  46. destroy() {
  47. this.model.clearGroup(this.group);
  48. this.model = null;
  49. this.group = null;
  50. }
  51. }
  52. export default ChamberBase;