Przeglądaj źródła

feat(draw): save

gemer zhang 1 rok temu
rodzic
commit
d6ff8d8776
3 zmienionych plików z 70 dodań i 13 usunięć
  1. 4 2
      src/core/Scene.js
  2. 55 7
      src/core/player/Player.js
  3. 11 4
      src/view/case/photos/index.vue

+ 4 - 2
src/core/Scene.js

@@ -13,7 +13,7 @@ export default class Scene extends Mitt {
     this.renderer = null;
     this.orthCamera = null;
     this.player = null;
-
+    this.sceneType = 1;
     this.width = 0;
     this.height = 0;
     this.inited = false;
@@ -65,17 +65,19 @@ export default class Scene extends Mitt {
     };
   }
 
-  load = (list, type) => {
+  load = (list, type, data) => {
     if (!list) return;
     console.log("scene: ", list, type);
     //axesHeloer
     this.clearScene();
+    this.sceneType = type;
     const axesHelper = new THREE.AxesHelper(1);
     this.scene.add(axesHelper);
     this.boxManager = new BoxManager(this);
     this.boxManager.load(list, type);
     //light
     this.loadLight();
+    this.player.load(data);
   };
 
   clearScene() {

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

@@ -50,6 +50,7 @@ export default class Player {
   setMode(mode) {
     this.mode = mode;
     if (mode === 1 || mode === 2) {
+      this.reset();
       this.setEditMode();
     }
     if (mode === 0) {
@@ -58,12 +59,12 @@ export default class Player {
     this.scene.emit("mode", this.mode);
   }
 
-  removeMarker() {
-    if (this.marker) {
-      this.scene.scene.remove(this.marker);
-      this.marker = null;
-    }
-  }
+  // removeMarker() {
+  //   if (this.marker) {
+  //     this.scene.scene.remove(this.marker);
+  //     this.marker = null;
+  //   }
+  // }
   setFreeMode() {
     this.floorplanControls.enablePan = true;
     this.floorplanControls.mouseButtons = {
@@ -71,6 +72,7 @@ export default class Player {
       MIDDLE: THREE.MOUSE.DOLLY,
       RIGHT: THREE.MOUSE.PAN,
     };
+    this.reset();
   }
 
   setEditMode() {
@@ -82,6 +84,7 @@ export default class Player {
     };
   }
 
+  load() {}
   init = () => {
     // //floorplanControls
     // this.floorplanControls = new FloorplanControls(
@@ -379,9 +382,54 @@ export default class Player {
       });
     }
   }
+  getDrawData() {
+    let data;
+    if (this.scene.sceneType === 1) {
+      data = {
+        hor_lines: this.renderLines,
+        activeEdges: this.activeEdges,
+        vir_lines: [],
+        hor_markers: this.renderMarkers,
+        vir_markers: [],
+      };
+    } else {
+      data = {
+        hor_lines: [],
+        vir_lines: this.renderLines,
+        activeEdges: this.activeEdges,
+        vir_markers: this.renderMarkers,
+        hor_markers: [],
+      };
+    }
+
+    console.log("sceneType", this.scene.sceneType);
+    return data;
+  }
+  // syncDrawData() {
+  //   const data = {
+  //     line: this.renderLines,
+  //     activeEdges: this.activeEdges,
+  //     markers: this.renderMarkers,
+  //   };
+  //   this.scene.emit("sync", data);
+  // }
 
   reset() {
-    this.activeEdges = [];
+    if (this.marker) {
+      this.scene.scene.remove(this.marker);
+      this.marker = null;
+    }
+    if (this.drawLine) {
+      this.scene.scene.remove(this.drawLine);
+      this.drawLine = null;
+    }
+    if (this.touchImg) {
+      this.touchImg = null;
+    }
+    if (this.activeEdge) {
+      this.activeEdge = null;
+    }
+    this.drawing = false;
   }
 
   update = () => {

+ 11 - 4
src/view/case/photos/index.vue

@@ -24,8 +24,10 @@
       <div class="tools">
         <el-button @click="handleMark">标注方向</el-button>
         <el-button @click="handleLine">标注连线</el-button>
-        <el-button @click="handleSave">保存</el-button>
-        <el-button @click="handleFree" v-if="isShowExitEdit">退出</el-button>
+        <el-button @click="handleSave" type="success">保存</el-button>
+        <el-button @click="handleFree" v-if="isShowExitEdit" type="warning"
+          >退出</el-button
+        >
       </div>
       <swiper
         class="swiper"
@@ -74,7 +76,6 @@ import { addCaseImgFile } from "../quisk";
 import { saveCaseImgTagData } from "@/store/case";
 import Scene from "@/core/Scene.js";
 import draggable from "./draggable.vue";
-import { ElMessageBox } from "element-plus";
 const props = defineProps({ caseId: Number });
 const newlist = ref([]);
 const swiperRef = ref(null);
@@ -171,8 +172,14 @@ const handleLine = () => {
     window.scene.player.setMode(1);
   }
 };
-const handleSave = () => {
+const handleSave = async () => {
   if (window.scene) {
+    const data = scene.player.getDrawData();
+    const res = await saveCaseImgTagData({
+      caseId: caseId.value,
+      data: data,
+    });
+    console.log("res", res);
   }
 };
 const handleFree = () => {