bertai.threejs.base.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 BertaiBase {
  6. model;
  7. modelName = 'Bertai';
  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(-130, -33, 32);
  15. this.group?.add(directionalLight);
  16. directionalLight.target = this.group as THREE.Object3D;
  17. // gui.add(directionalLight.position, 'x', -500, 500);
  18. // gui.add(directionalLight.position, 'y', -500, 500);
  19. // gui.add(directionalLight.position, 'z', -500, 500);
  20. const spotLight = new THREE.SpotLight();
  21. spotLight.angle = Math.PI / 2;
  22. spotLight.penumbra = 0;
  23. spotLight.castShadow = true;
  24. spotLight.intensity = 1;
  25. spotLight.shadow.camera.near = 0.5; // default
  26. spotLight.shadow.focus = 1.2;
  27. spotLight.shadow.bias = -0.000002;
  28. spotLight.position.set(-1, 68, 22);
  29. this.group?.add(spotLight);
  30. // gui.add(spotLight.position, 'x', -600, 600);
  31. // gui.add(spotLight.position, 'y', -600, 800);
  32. // gui.add(spotLight.position, 'z', -500, 1000);
  33. }
  34. addChamberText(selectData) {
  35. //
  36. }
  37. mountedThree() {
  38. return new Promise((resolve) => {
  39. this.model.setGLTFModel([this.modelName]).then((gltf) => {
  40. this.group = gltf[0];
  41. if (this.group) {
  42. // this.group?.scale.set(12.5, 12.5, 12.5);
  43. this.group?.scale.set(3, 3, 3);
  44. this.group.position.y = 4;
  45. resolve(null);
  46. this.addLight();
  47. }
  48. });
  49. });
  50. }
  51. destroy() {
  52. this.model.clearGroup(this.group);
  53. this.model = null;
  54. this.group = null;
  55. }
  56. }
  57. export default BertaiBase;