Browse Source

feat:save

gemercheung 1 year ago
parent
commit
4fab1df878
2 changed files with 54 additions and 10 deletions
  1. 39 4
      src/core/Scene.js
  2. 15 6
      src/view/case/photos/index.vue

+ 39 - 4
src/core/Scene.js

@@ -6,6 +6,9 @@ import { Mitt } from "./mitt.js";
 import testData from "./save.json";
 const stats = new Stats();
 
+function sleep(ms) {
+  return new Promise((resolve) => setTimeout(resolve, ms));
+}
 const saveFile = function (strData, filename) {
   var link = document.createElement("a");
   if (typeof link.download === "string") {
@@ -30,6 +33,7 @@ export default class Scene extends Mitt {
     this.sceneType = 1;
     this.width = 0;
     this.height = 0;
+    this.defaultZoom = 250;
     this.inited = false;
 
     this.init = () => {
@@ -58,7 +62,7 @@ export default class Scene extends Mitt {
         0.1,
         1000
       );
-      this.orthCamera.zoom = 250;
+      this.orthCamera.zoom = this.defaultZoom;
 
       this.orthCamera.position.set(0, 10, 0);
       this.orthCamera.lookAt(0, 0, 0);
@@ -178,10 +182,11 @@ export default class Scene extends Mitt {
     this.player.editing(item);
   }
 
-  screenshot() {
+  screenshot(x, index) {
     var imgData, imgNode;
     const times = 4;
-    this.orthCamera.zoom = 230;
+    this.orthCamera.zoom = this.defaultZoom;
+    this.scene.position.x = x || 0;
 
     this.renderer.setSize(this.width * times, this.height * times);
     this.orthCamera.aspect = this.width / this.height;
@@ -193,9 +198,39 @@ export default class Scene extends Mitt {
 
     const dataURL = this.renderer.domElement.toDataURL("image/jpeg");
 
-    saveFile(dataURL, "test.jpg");
+    saveFile(dataURL, `${index}.jpg`);
     this.onResize(this.width, this.height);
   }
+
+  test() {
+    this.orthCamera.zoom = this.defaultZoom;
+    const object = this.boxManager.model;
+    const total = this.boxManager.imgList.length;
+
+    object.updateMatrixWorld();
+    this.orthCamera.updateProjectionMatrix();
+    const boundingBox = new THREE.Box3().setFromObject(object);
+
+    // 计算宽度、高度和深度
+    const width = boundingBox.max.x - boundingBox.min.x;
+    const one = width / total;
+    let slides = Math.floor(total / 3);
+    console.log("slides", slides);
+    if (slides > 1) {
+      for (var i = 0; i <= slides; i++) {
+        (function (index, that) {
+          setTimeout(function () {
+            const offset = -(one * 3 * index + 0.21);
+            console.log("Iteration:", offset);
+            that.screenshot(offset, index);
+
+            console.log(`Width: ${offset}`);
+          }, index * 1000);
+        })(i, this); // 传递当前迭代的索引i给setTimeout的回调函数
+      }
+    }
+  }
+
   onBindEvent = () => {
     //window.addEventListener('resize', this.onResize)
   };

+ 15 - 6
src/view/case/photos/index.vue

@@ -238,13 +238,17 @@ const handleDetele = async (item) => {
   }
 };
 const handleSwitchGrid = async () => {
-  const res = await ElMessageBox.confirm("切换模版不包括标注内容,确定要切换吗?", "温馨提示", {
-    confirmButtonText: "确定",
-    cancelButtonText: "取消",
-    type: "default",
-  });
+  const res = await ElMessageBox.confirm(
+    "切换模版不包括标注内容,确定要切换吗?",
+    "温馨提示",
+    {
+      confirmButtonText: "确定",
+      cancelButtonText: "取消",
+      type: "default",
+    }
+  );
   if (res) {
-    sortType.value = !sortType.value
+    sortType.value = !sortType.value;
     handleClear();
   }
 };
@@ -417,3 +421,8 @@ onMounted(() => {
   }
 }
 </style>
+<style scoped>
+:global(.body-layer) {
+  padding-right: 0 !important;
+}
+</style>