|
@@ -4,23 +4,12 @@ import Player from "./player/Player.js";
|
|
|
import BoxManager from "./box/BoxManager.js";
|
|
|
import { Mitt } from "./mitt.js";
|
|
|
import testData from "./save.json";
|
|
|
+import { dataURItoBlob, saveFile } from "./utils/utils.js";
|
|
|
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") {
|
|
|
- document.body.appendChild(link); //Firefox requires the link to be in the body
|
|
|
- link.download = filename;
|
|
|
- link.href = strData;
|
|
|
- link.click();
|
|
|
- document.body.removeChild(link); //remove the link when done
|
|
|
- } else {
|
|
|
- location.replace(uri);
|
|
|
- }
|
|
|
-};
|
|
|
|
|
|
export default class Scene extends Mitt {
|
|
|
constructor(domElement) {
|
|
@@ -36,7 +25,7 @@ export default class Scene extends Mitt {
|
|
|
this.defaultZoom = 250;
|
|
|
this.initCamPView = new THREE.Vector3();
|
|
|
this.initCamRView = new THREE.Vector3();
|
|
|
-
|
|
|
+ this.blobScreens = [];
|
|
|
this.inited = false;
|
|
|
|
|
|
this.init = () => {
|
|
@@ -213,8 +202,8 @@ export default class Scene extends Mitt {
|
|
|
this.renderer.render(this.scene, this.orthCamera, null, false);
|
|
|
|
|
|
const dataURL = this.renderer.domElement.toDataURL("image/jpeg");
|
|
|
-
|
|
|
- saveFile(dataURL, `${index}.jpg`);
|
|
|
+ this.blobScreens.push(dataURItoBlob(dataURL));
|
|
|
+ // saveFile(dataURL, `${index}.jpg`);
|
|
|
this.onResize(this.width, this.height);
|
|
|
}
|
|
|
|
|
@@ -222,16 +211,11 @@ export default class Scene extends Mitt {
|
|
|
this.orthCamera.zoom = this.defaultZoom;
|
|
|
const object = this.boxManager.model;
|
|
|
let total;
|
|
|
- if (this.sceneType === 2) {
|
|
|
- total = this.boxManager.imgList.length;
|
|
|
- } else {
|
|
|
- total = this.boxManager.imgList.length / 2;
|
|
|
- }
|
|
|
+ total = object.children.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;
|
|
@@ -244,8 +228,12 @@ export default class Scene extends Mitt {
|
|
|
const offset = -(one * 3 * index);
|
|
|
console.log("Iteration:", offset);
|
|
|
that.screenshot(offset, index);
|
|
|
-
|
|
|
console.log(`Width: ${offset}`);
|
|
|
+ if (index === slides) {
|
|
|
+ console.log("last");
|
|
|
+ that.scene.position.x = 0;
|
|
|
+ this.scene.emit('submitScreenshot')
|
|
|
+ }
|
|
|
}, index * 1000);
|
|
|
})(i, this); // 传递当前迭代的索引i给setTimeout的回调函数
|
|
|
}
|