gemer zhang 1 rok pred
rodič
commit
7f2f9bfcd5

+ 7 - 1
src/core/Scene.js

@@ -67,15 +67,21 @@ export default class Scene {
     if (!list) return;
     console.log("scene: ", list, type);
     //axesHeloer
+    this.clearScene();
     const axesHelper = new THREE.AxesHelper(1);
     this.scene.add(axesHelper);
-
     this.boxManager = new BoxManager(this);
     this.boxManager.load(list, type);
     //light
     this.loadLight();
   };
 
+  clearScene() {
+    for (var i = this.scene.children.length - 1; i >= 0; i--) {
+      let obj = this.scene.children[i];
+      this.scene.remove(obj);
+    }
+  }
   loadLight = () => {
     const light = new THREE.AmbientLight(0xffffff, 1.5); // 柔和的白光
     this.scene.add(light);

+ 9 - 5
src/core/box/BoxManager.js

@@ -1,12 +1,13 @@
 import * as THREE from "three";
 import HorizontalBox from "./horizontalBox";
-
+import VerticalBox from "./VerticalBox";
 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;
@@ -15,21 +16,24 @@ export default class BoxManager {
   }
 
   load = (list, type) => {
-    this.model.remove(...this.model.children);
-
+    console.log("this.model.name", this.model.name);
     list.forEach((item, index) => {
       if (type === 1) {
         //横排
+        console.log("横排");
         const box = new HorizontalBox(this, item, index);
         this.model.add(box);
       }
       if (type === 2) {
         //竖排
-        console.log("竖排");
+        const box = new VerticalBox(this, item, index);
+        // console.log("竖排");
+        this.model.add(box);
       }
     });
-    console.log("this.model", this.model);
+
     this.scene.scene.add(this.model);
+    console.log("this.scene.scene", this.scene.scene);
   };
 
   onBindEvent = () => {

+ 2 - 0
src/core/box/HorizontalBox.js

@@ -48,9 +48,11 @@ export default class HorizontalBox extends THREE.Group {
     data.forEach((i, j) => {
       //img
       let img;
+
       this.manager.loader.load(i.imgUrl, (texture) => {
         texture.colorSpace = THREE.SRGBColorSpace;
         img = new ImgLabel(texture, matLine);
+        img.userData = i.id;
         img.position.y += 1;
         if (j === 0) {
           img.position.z -= 0.8;

+ 5 - 3
src/core/box/object/Line.js

@@ -123,12 +123,14 @@ export default class Line extends Line2 {
     }
 
     const geometry = new LineGeometry();
-    // console.log("points", points);
-
+  
     cross.visible = false;
     geometry.setPositions(points);
     super(geometry, matLine);
-    this.userData = points;
+    this.userData = {
+      dir: endEdge.name,
+      points: points,
+    };
     this.scale.set(1, 1, 1);
     this.position.y += 0.5;
     this.add(cross);

+ 5 - 17
src/core/player/Player.js

@@ -49,7 +49,7 @@ export default class Player {
     );
 
     this.floorplanControls.enablePan = true;
-    this.floorplanControls.target.set(0, 1, 0);
+    // this.floorplanControls.target.set(0, 1, 0);
     // this.floorplanControls.rotateSpeed = 0.5;
     // this.floorplanControls.panSpeed = 0.75
     // this.floorplanControls.maxDistance = 100
@@ -117,28 +117,16 @@ export default class Player {
     this.startObj = null;
 
     if (this.drawLine) {
-      console.log("last Line", this.drawLine.userData);
-      const points = this.drawLine.userData;
+      const points = this.drawLine.userData.points;
+      const dir = this.drawLine.userData.dir;
       const finishLine = new LinePoints(points, 0, this.matLine);
       this.renderLines.push(points);
       this.scene.scene.add(finishLine);
-      console.log("this.touchImg", this.touchImg);
+      const imageId = this.touchImg.object.userData;
+      console.log("this.touchImg", dir, imageId, points);
     }
   };
 
-  getPostionsFromDrawLine() {
-    if (!this.drawLine) {
-      return [];
-    }
-    let gp = this.drawLine.geometry.attributes.position;
-    let wPos = [];
-    for (let i = 0; i < gp.count; i++) {
-      let p = new THREE.Vector3().fromBufferAttribute(gp, i); // set p from `position`
-      this.drawLine.localToWorld(p); // p has wordl coords
-      wPos.push(p);
-    }
-    return wPos;
-  }
   Listener = {
     onPointerDown: this.onPointerDown.bind(this),
     onPointerMove: this.onPointerMove.bind(this),

Rozdielové dáta súboru neboli zobrazené, pretože súbor je príliš veľký
+ 867 - 752
yarn.lock