BoxManager.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import * as THREE from "three";
  2. import HorizontalBox from "./HorizontalBox";
  3. import VerticalBox from "./VerticalBox";
  4. export default class BoxManager {
  5. constructor(scene) {
  6. this.scene = scene;
  7. this.loadingManager = new THREE.LoadingManager();
  8. this.loader = new THREE.TextureLoader(this.loadingManager);
  9. this.model = new THREE.Group();
  10. this.model.name = "boxManager";
  11. this.maps = {};
  12. this.imgList = [];
  13. this.opacity = 1;
  14. this.onBindEvent();
  15. }
  16. load = (list, type) => {
  17. console.log("this.model.name", this.model.name);
  18. list.forEach((item, index) => {
  19. if (type === 1) {
  20. //横排
  21. console.log("横排");
  22. const box = new HorizontalBox(this, item, index);
  23. this.model.add(box);
  24. }
  25. if (type === 2) {
  26. //竖排
  27. const box = new VerticalBox(this, item, index);
  28. // console.log("竖排");
  29. this.model.add(box);
  30. }
  31. });
  32. this.scene.scene.add(this.model);
  33. console.log("this.scene.scene", this.scene.scene);
  34. };
  35. onBindEvent = () => {
  36. const _this = this;
  37. this.loadingManager.onStart = function (url, itemsLoaded, itemsTotal) {
  38. // console.log( 'Started loading file: ' + url + '.\nLoaded ' + itemsLoaded + ' of ' + itemsTotal + ' files.' );
  39. console.log("loading_manager: loading...");
  40. };
  41. this.loadingManager.onLoad = function () {
  42. console.log("loading_manager: loading complete!");
  43. };
  44. this.loadingManager.onProgress = function (url, itemsLoaded, itemsTotal) {
  45. // console.log( 'Loading file: ' + url + '.\nLoaded ' + itemsLoaded + ' of ' + itemsTotal + ' files.' );
  46. };
  47. this.loadingManager.onError = function (url) {
  48. console.error("loading_manager: error loading " + url);
  49. };
  50. };
  51. setVisible = (val) => {
  52. if (!this.model) return;
  53. this.model.visible = val;
  54. };
  55. setOpacity = (val) => {
  56. this.material.opacity = val;
  57. };
  58. }