gemercheung před 1 rokem
rodič
revize
1612e9e1ec

+ 2 - 1
src/core/Scene.js

@@ -106,7 +106,8 @@ export default class Scene extends Mitt {
     for (var i = this.scene.children.length - 1; i >= 0; i--) {
       let obj = this.scene.children[i];
       if (obj.uuid === uuid) {
-        console.log("deleteItemById", obj);
+        console.log("deleteItemById-userData", obj.userData);
+        this.player.deleteItemByType(type, obj.userData);
         this.scene.remove(obj);
       }
     }

+ 4 - 1
src/core/box/object/CircleTextLabel.js

@@ -4,8 +4,9 @@ import { LineSegments2 } from "three/examples/jsm/lines/LineSegments2.js";
 import { LineGeometry } from "three/examples/jsm/lines/LineGeometry.js";
 
 export default class CircleTextLabel extends THREE.Mesh {
-  constructor(text, outline) {
+  constructor(text, pos) {
     let res = 5;
+    let point = new THREE.Vector3().copy(pos);
     const canvas = document.createElement("canvas");
     canvas.width = 128 * res;
     canvas.height = 128 * res;
@@ -55,6 +56,8 @@ export default class CircleTextLabel extends THREE.Mesh {
     line_n.position.y += 0.5;
 
     this.add(line_n);
+    this.userData = point.toArray();
+    this.position.copy(point);
     this.name = "circle_" + text;
   }
 }

+ 69 - 7
src/core/player/Player.js

@@ -48,6 +48,7 @@ export default class Player {
     this.renderMarkers = [];
     this.activeEdges = [];
     this.renderSymbols = [];
+    this.renderTexts = [];
     this.matLine = null;
     this.lineColor = 0xe44d54;
     // 1是画线,2是标方向, 3符号, 4文本
@@ -79,7 +80,7 @@ export default class Player {
       pos.unproject(this.orthCamera);
       pos.y = 5;
       this.symbolIndex += 1;
-      this.symbol = new CircleTextLabel(this.symbolIndex, true);
+      this.symbol = new CircleTextLabel(this.symbolIndex, pos);
       this.symbol.visible = false;
       this.scene.scene.add(this.symbol);
       console.log("this.symbol", this.symbol);
@@ -247,10 +248,31 @@ export default class Player {
       intersects.forEach((i) => {
         if (
           String(i.object.name).includes("marker") ||
-          String(i.object.name).includes("line")
+          String(i.object.name).includes("line") ||
+          String(i.object.name).includes("circle") ||
+          String(i.object.name).includes("pureText")
         ) {
+          let type;
+          switch (true) {
+            case String(i.object.name).includes("marker"):
+              type = 1;
+              break;
+            case String(i.object.name).includes("line"):
+              type = 2;
+              break;
+            case String(i.object.name).includes("circle"):
+              type = 3;
+              break;
+            case String(i.object.name).includes("pureText"):
+              type = 4;
+              break;
+          }
+
           this.selectItem = i.object;
-          this.scene.emit("confirmDelete", i.object.uuid);
+          this.scene.emit("confirmDelete", {
+            id: i.object.uuid,
+            type,
+          });
         }
       });
     }
@@ -315,11 +337,15 @@ export default class Player {
           this.pointerdown.y,
           -1
         );
+        lasPos.unproject(this.orthCamera);
+        lasPos.y = 5;
+        
         const activeSymbolItem = {
-          id: this.symbolIndex,
+          index: this.symbolIndex,
           point: lasPos.toArray(),
         };
         this.renderSymbols.push(activeSymbolItem);
+        console.log("activeSymbolItem", activeSymbolItem);
         this.setMode(0);
       }
     }
@@ -523,7 +549,22 @@ export default class Player {
       }
     }
   }
-
+  deleteItemByType(type, pos) {
+    if (type === 1) {
+    }
+    if (type === 2) {
+    }
+    if (type === 3) {
+      const index = this.renderSymbols.findIndex((syb) => {
+        const p = new THREE.Vector3().fromArray(syb.point);
+        const v = new THREE.Vector3().fromArray(pos);
+        return p.equals(v);
+      });
+      this.renderSymbols.splice(index, 1);
+    }
+    if (type === 4) {
+    }
+  }
   editing(item) {
     if (item.type === 4) {
       console.log("editing", item);
@@ -550,6 +591,7 @@ export default class Player {
         hor_lines: this.renderLines,
         hor_activeEdges: this.activeEdges,
         hor_markers: this.renderMarkers,
+        hor_symbols: this.renderSymbols,
         vir_lines: [],
         vir_activeEdges: [],
         vir_markers: [],
@@ -562,6 +604,7 @@ export default class Player {
         vir_lines: this.renderLines,
         vir_activeEdges: this.activeEdges,
         vir_markers: this.renderMarkers,
+        vir_symbols: this.renderSymbols,
       };
     }
 
@@ -576,7 +619,7 @@ export default class Player {
   load(type, data) {
     if (type === 1) {
       console.log("data1", data);
-      const { hor_activeEdges, hor_lines, hor_markers } = data;
+      const { hor_activeEdges, hor_lines, hor_markers, hor_symbols } = data;
       hor_activeEdges && (this.activeEdges = hor_activeEdges);
       if (hor_lines && Array.isArray(hor_lines)) {
         this.renderLines = hor_lines;
@@ -594,10 +637,20 @@ export default class Player {
           this.scene.scene.add(marker);
         });
       }
+
+      if (hor_symbols && Array.isArray(hor_symbols)) {
+        this.renderSymbols = hor_symbols;
+        hor_symbols.forEach((syb) => {
+          console.log("pos");
+          const p = new THREE.Vector3().fromArray(syb.point);
+          const symbol = new CircleTextLabel(syb.index, p);
+          this.scene.scene.add(symbol);
+        });
+      }
     }
 
     if (type === 2) {
-      const { vir_activeEdges, vir_lines, vir_markers } = data;
+      const { vir_activeEdges, vir_lines, vir_markers, vir_symbols } = data;
       vir_activeEdges && (this.activeEdges = vir_activeEdges);
       if (vir_lines && Array.isArray(vir_lines)) {
         this.renderLines = vir_lines;
@@ -614,6 +667,15 @@ export default class Player {
           this.scene.scene.add(marker);
         });
       }
+      if (vir_symbols && Array.isArray(vir_symbols)) {
+        this.renderSymbols = vir_symbols;
+        vir_symbols.forEach((syb) => {
+          console.log("pos", syb);
+          const p = new THREE.Vector3().fromArray(syb.point);
+          const symbol = new CircleTextLabel(syb.index, p);
+          this.scene.scene.add(symbol);
+        });
+      }
     }
     this.syncDrawData();
   }

+ 3 - 2
src/view/case/photos/index.vue

@@ -177,14 +177,15 @@ const renderCanvas = () => {
   scene.on("markerExist", () => {
     ElMessage.error("该案件已有方向标注!");
   });
-  scene.on("confirmDelete", async (uuid) => {
+  scene.on("confirmDelete", async ({ id, type }) => {
     const res = await ElMessageBox.confirm("是否删除该部件?", "温馨提示", {
       confirmButtonText: "确定",
       cancelButtonText: "取消",
       type: "default",
     });
     if (res) {
-      window.scene.deleteItemById(uuid);
+      window.scene.deleteItemById(id, type);
+
     }
   });
   scene.on("data", (data) => {