Przeglądaj źródła

feat(map): update

gemercheung 1 rok temu
rodzic
commit
781b61da24
2 zmienionych plików z 61 dodań i 9 usunięć
  1. 10 1
      src/core/box/object/LinePoints.js
  2. 51 8
      src/core/player/Player.js

+ 10 - 1
src/core/box/object/LinePoints.js

@@ -17,7 +17,7 @@ let m = new THREE.MeshBasicMaterial({
   transparent: true,
 });
 export default class LinePoints extends Line2 {
-  constructor(points, dir, matLine) {
+  constructor(points, matLine, dir, imgId, id) {
     let g = new THREE.PlaneGeometry(0.1, 0.1);
     g.rotateX(-Math.PI / 2);
     let cross = new THREE.Mesh(g, m);
@@ -61,6 +61,15 @@ export default class LinePoints extends Line2 {
     this.name = "line_point_" + this.uuid;
     this.scale.set(1, 1, 1);
     this.position.y += 0.5;
+    if (id) {
+      this.uuid = id;
+    }
+    this.userData = {
+      id: id || this.uuid,
+      dir: dir,
+      points,
+      imgId: imgId || null,
+    };
     this.add(cross);
   }
 }

+ 51 - 8
src/core/player/Player.js

@@ -387,18 +387,25 @@ export default class Player {
       if (this.drawLine) {
         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);
         const imageId = this.touchImg.object.userData;
+        const finishLine = new LinePoints(points, this.matLine, dir, imageId);
 
+        this.scene.scene.add(finishLine);
         const activeLineItem = {
+          id: finishLine.uuid,
+          imgId: imageId,
+          dir: dir,
+          points: points,
+        };
+        const activeEdgeItem = {
           id: imageId,
           dir: [dir],
         };
 
+        this.renderLines.push(activeLineItem);
         console.log("this.touchImg", activeLineItem, points);
-        this.insertActiveEdge(activeLineItem);
+        this.insertActiveEdge(activeEdgeItem);
+        this.scene.scene.remove(this.drawLine);
         this.drawLine = null;
       }
     }
@@ -557,9 +564,14 @@ export default class Player {
           const exist = imgList.find((item) => item.userData === edge.id);
           // console.log("exist", exist);
           if (exist) {
+            let others = [0, 1, 2, 3].filter((x) => !edge.dir.includes(x));
             edge.dir.forEach((dir) => {
               exist.touchLines.children[dir].visible = true;
             });
+            // console.log("others", others);
+            others.forEach((dir) => {
+              exist.touchLines.children[dir].visible = false;
+            });
           }
         });
       } else {
@@ -584,6 +596,26 @@ export default class Player {
       this.renderMarkers.splice(index, 1);
     }
     if (type === 2) {
+      const { imgId, id, dir, points } = data;
+      const index = this.renderLines.findIndex((item) => item.id === id);
+      index > -1 && this.renderLines.splice(index, 1);
+      //线段处理完成
+      const egIndex = this.activeEdges.findIndex((eg) => eg.id === imgId);
+      if (egIndex > -1) {
+        //存在activeEdge 再找renderLines的sibling
+        const cluEgArr = this.renderLines
+          .filter((l) => l.imgId === this.activeEdges[egIndex].id)
+          .reduce((pre, curr) => pre.concat(curr["dir"]), []);
+        const uni_dir = [...new Set(cluEgArr)];
+        console.log("uni_dir", uni_dir);
+        if (uni_dir.length > 0) {
+          this.activeEdges[egIndex].dir = uni_dir;
+        } else {
+          this.activeEdges.splice(egIndex, 1);
+        }
+        console.log("exist", this.activeEdges);
+        // this.showAllActiveEdges();
+      }
     }
     if (type === 3) {
       const index = this.renderSymbols.findIndex((syb) => {
@@ -596,8 +628,7 @@ export default class Player {
     if (type === 4) {
       const { id } = data;
       const index = this.renderTexts.findIndex((item) => item.id === id);
-      debugger;
-      this.renderTexts.splice(index, 1);
+      index > -1 && this.renderTexts.splice(index, 1);
     }
   }
   editing(item) {
@@ -676,7 +707,13 @@ export default class Player {
       if (hor_lines && Array.isArray(hor_lines)) {
         this.renderLines = hor_lines;
         hor_lines.forEach((line) => {
-          const finishLine = new LinePoints(line, 0, this.matLine);
+          const finishLine = new LinePoints(
+            line.points,
+            this.matLine,
+            line.dir,
+            line.imgId,
+            line.id
+          );
           this.scene.scene.add(finishLine);
         });
       }
@@ -728,7 +765,13 @@ export default class Player {
       if (vir_lines && Array.isArray(vir_lines)) {
         this.renderLines = vir_lines;
         vir_lines.forEach((line) => {
-          const finishLine = new LinePoints(line, 0, this.matLine);
+          const finishLine = new LinePoints(
+            line.points,
+            this.matLine,
+            line.dir,
+            line.imgId,
+            line.id
+          );
           this.scene.scene.add(finishLine);
         });
       }