1
0

BoxManager.js 2.1 KB

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