BoxManager.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 = function () {
  46. console.log("loading_manager: loading complete!");
  47. };
  48. this.loadingManager.onProgress = function (url, itemsLoaded, itemsTotal) {
  49. // console.log( 'Loading file: ' + url + '.\nLoaded ' + itemsLoaded + ' of ' + itemsTotal + ' files.' );
  50. };
  51. this.loadingManager.onError = function (url) {
  52. console.error("loading_manager: error loading " + url);
  53. };
  54. };
  55. setVisible = (val) => {
  56. if (!this.model) return;
  57. this.model.visible = val;
  58. };
  59. setOpacity = (val) => {
  60. this.material.opacity = val;
  61. };
  62. }