1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- import * as THREE from "three";
- import HorizontalBox from "./HorizontalBox";
- import VerticalBox from "./VerticalBox";
- import SimpleLabel from "./object/SimpleLabel";
- export default class BoxManager {
- constructor(scene) {
- this.scene = scene;
- this.loadingManager = new THREE.LoadingManager();
- this.loader = new THREE.TextureLoader(this.loadingManager);
- this.model = new THREE.Group();
- this.model.name = "boxManager";
- this.maps = {};
- this.imgList = [];
- this.opacity = 1;
- this.onBindEvent();
- }
- load = (list, type) => {
- console.log("this.model.name", this.model.name);
- const total = list.length;
- list.forEach((item, index) => {
- if (type === 1) {
- //横排
- console.log("横排");
- const box = new HorizontalBox(this, item, index, total);
- this.model.add(box);
- }
- if (type === 2) {
- //竖排
- const box = new VerticalBox(this, item, index, total);
- // console.log("竖排");
- this.model.add(box);
- }
- });
- // this.model.position.y += 0.3;
- // this.model.visible =false;
- this.scene.scene.add(this.model);
- // console.log("this.scene.scene", this.scene.scene);
- };
- onBindEvent = () => {
- const _this = this;
- this.loadingManager.onStart = function (url, itemsLoaded, itemsTotal) {
- // console.log( 'Started loading file: ' + url + '.\nLoaded ' + itemsLoaded + ' of ' + itemsTotal + ' files.' );
- console.log("loading_manager: loading...");
- };
- this.loadingManager.onLoad = function () {
- console.log("loading_manager: loading complete!");
- };
- this.loadingManager.onProgress = function (url, itemsLoaded, itemsTotal) {
- // console.log( 'Loading file: ' + url + '.\nLoaded ' + itemsLoaded + ' of ' + itemsTotal + ' files.' );
- };
- this.loadingManager.onError = function (url) {
- console.error("loading_manager: error loading " + url);
- };
- };
- setVisible = (val) => {
- if (!this.model) return;
- this.model.visible = val;
- };
- setOpacity = (val) => {
- this.material.opacity = val;
- };
- }
|