gasPump.threejs.over.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 gasPumpBase {
  6. model;
  7. modelName = 'gasPump';
  8. group: THREE.Object3D | null = null;
  9. constructor(model) {
  10. this.model = model;
  11. }
  12. addLight() {
  13. const directionalLight = new THREE.DirectionalLight(0xffffff, 1);
  14. directionalLight.position.set(-217, 500, -347);
  15. this.group?.add(directionalLight);
  16. directionalLight.target = this.group as THREE.Object3D;
  17. // gui.add(directionalLight.position, 'x', -500, 800);
  18. // gui.add(directionalLight.position, 'y', -500, 800);
  19. // gui.add(directionalLight.position, 'z', -500, 800);
  20. // gui.add(pointLight2.position, 'x', -300, 300);
  21. // gui.add(pointLight2.position, 'y', -300, 300);
  22. // gui.add(pointLight2.position, 'z', -300, 300);
  23. }
  24. mountedThree() {
  25. return new Promise((resolve) => {
  26. this.model.setGLTFModel([this.modelName]).then((gltf) => {
  27. this.group = gltf[0];
  28. if (this.group) {
  29. // this.group?.scale.set(0.1, 0.1, 0.1);
  30. // this.group.position.y += 40;
  31. resolve(null);
  32. this.addLight();
  33. }
  34. });
  35. });
  36. }
  37. destroy() {
  38. this.model.clearGroup(this.group);
  39. this.model = null;
  40. this.group = null;
  41. }
  42. }
  43. export default gasPumpBase;