Browse Source

feat(draw): save

gemer zhang 1 year ago
parent
commit
357e42030f
4 changed files with 241 additions and 14 deletions
  1. 2 1
      src/core/Scene.js
  2. 27 10
      src/core/player/Player.js
  3. 211 3
      src/core/save.json
  4. 1 0
      src/view/case/photos/index.vue

+ 2 - 1
src/core/Scene.js

@@ -3,6 +3,7 @@ import Stats from "three/examples/jsm/libs/stats.module.js";
 import Player from "./player/Player.js";
 import BoxManager from "./box/BoxManager.js";
 import { Mitt } from "./mitt.js";
+import testData from "./save.json";
 const stats = new Stats();
 
 export default class Scene extends Mitt {
@@ -77,7 +78,7 @@ export default class Scene extends Mitt {
     this.boxManager.load(list, type);
     //light
     this.loadLight();
-    this.player.load(data);
+    this.player.load(type, testData);
   };
 
   clearScene() {

+ 27 - 10
src/core/player/Player.js

@@ -84,7 +84,6 @@ export default class Player {
     };
   }
 
-  load() {}
   init = () => {
     // //floorplanControls
     // this.floorplanControls = new FloorplanControls(
@@ -402,18 +401,36 @@ export default class Player {
       };
     }
 
-    console.log("sceneType", this.scene.sceneType);
+    // 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);
-  // }
+  load(type, data) {
+    if (type === 1) {
+      console.log("data1", data);
+      const { activeEdges, hor_lines, hor_markers } = data;
+      activeEdges && (this.activeEdges = activeEdges);
+      if (hor_lines && Array.isArray(hor_lines)) {
+        this.renderLines = hor_lines;
+        hor_lines.forEach((line) => {
+          const finishLine = new LinePoints(line, 0, this.matLine);
+          this.scene.scene.add(finishLine);
+        });
+      }
+      if (hor_markers && Array.isArray(hor_markers)) {
+        this.renderMarkers = hor_markers;
+        hor_markers.forEach((pos) => {
+          console.log("pos");
+          const p = new THREE.Vector3().fromArray(pos.point);
+          const marker = new Marker(p);
+          this.scene.scene.add(marker);
+        });
+      }
+    }
 
+    if (type === 2) {
+      console.log("data2", data);
+    }
+  }
   reset() {
     if (this.marker) {
       this.scene.scene.remove(this.marker);

+ 211 - 3
src/core/save.json

@@ -1,5 +1,213 @@
 {
-    hor_lines:[],
-    activeEdges:[],
-    vir_lines:[],
+    "hor_lines": [
+        [
+            0.37457214355468404,
+            5,
+            -0.6844542108877344,
+            0.8751436157226529,
+            5,
+            -0.6844542108877344,
+            0.8751436157226529,
+            5,
+            -0.7187400995595923,
+            1.375,
+            5,
+            -0.7187400995595923
+        ],
+        [
+            0.6077149658203091,
+            5,
+            0.3624029668461173,
+            1.024857727050778,
+            5,
+            0.3624029668461173,
+            1.024857727050778,
+            5,
+            0.37383192192423637,
+            1.375,
+            5,
+            0.37383192192423637
+        ],
+        [
+            2.6100012207031225,
+            5,
+            -0.5930254999502802,
+            3.055715576171872,
+            5,
+            -0.5930254999502802,
+            3.055715576171872,
+            5,
+            -0.746168444286141,
+            3.5,
+            5,
+            -0.746168444286141
+        ],
+        [
+            2.7014287109374973,
+            5,
+            0.4241170781742112,
+            3.115142944335935,
+            5,
+            0.4241170781742112,
+            3.115142944335935,
+            5,
+            0.3098319219242684,
+            3.5,
+            5,
+            0.3098319219242684
+        ],
+        [
+            4.749429931640627,
+            5,
+            -0.7255969721181826,
+            5.307144287109377,
+            5,
+            -0.7255969721181826,
+            5.307144287109377,
+            5,
+            0.22068873344775067,
+            5.625,
+            5,
+            0.22068873344775067
+        ],
+        [
+            4.520857421875002,
+            5,
+            0.26640357719772756,
+            5.154000854492189,
+            5,
+            0.26640357719772756,
+            5.154000854492189,
+            5,
+            -0.7278824335439628,
+            5.625,
+            5,
+            -0.7278824335439628
+        ],
+        [
+            6.819491195426028,
+            5,
+            -0.842840401132085,
+            7.436712472459824,
+            5,
+            -0.842840401132085,
+            7.436712472459824,
+            5,
+            -0.7682142811004876,
+            7.75,
+            5,
+            -0.7682142811004876
+        ],
+        [
+            6.950087113058009,
+            5,
+            0.27966222561165854,
+            6.950087113058009,
+            5,
+            -0.12500000000000006,
+            8.588756739629568,
+            5,
+            -0.12500000000000006,
+            8.588756739629568,
+            5,
+            -0.37500000000000006
+        ]
+    ],
+    "activeEdges": [
+        {
+            "id": 28,
+            "dir": [
+                1
+            ]
+        },
+        {
+            "id": 26,
+            "dir": [
+                1
+            ]
+        },
+        {
+            "id": 12,
+            "dir": [
+                1
+            ]
+        },
+        {
+            "id": 7,
+            "dir": [
+                1
+            ]
+        },
+        {
+            "id": 2,
+            "dir": [
+                1
+            ]
+        },
+        {
+            "id": 13,
+            "dir": [
+                1
+            ]
+        },
+        {
+            "id": 1,
+            "dir": [
+                1,
+                2
+            ]
+        }
+    ],
+    "vir_lines": [],
+    "hor_markers": [
+        {
+            "id": 8,
+            "point": [
+                0.2785721435546846,
+                5,
+                -0.9495972162586956
+            ]
+        },
+        {
+            "id": 28,
+            "point": [
+                1.6454287109374972,
+                5,
+                -0.7987400995595524
+            ]
+        },
+        {
+            "id": 26,
+            "point": [
+                1.5174287109374966,
+                5,
+                0.300689099658648
+            ]
+        },
+        {
+            "id": 29,
+            "point": [
+                0.31285729980468435,
+                5,
+                0.15668909965872002
+            ]
+        },
+        {
+            "id": 12,
+            "point": [
+                3.6065715332031223,
+                5,
+                -0.9541686273915058
+            ]
+        },
+        {
+            "id": 7,
+            "point": [
+                3.6591433105468725,
+                5,
+                0.11326002251030426
+            ]
+        }
+    ],
+    "vir_markers": []
 }

+ 1 - 0
src/view/case/photos/index.vue

@@ -175,6 +175,7 @@ const handleLine = () => {
 const handleSave = async () => {
   if (window.scene) {
     const data = scene.player.getDrawData();
+    console.log("data", data);
     const res = await saveCaseImgTagData({
       caseId: caseId.value,
       data: data,