|
@@ -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 = () => {
|
|
@@ -152,10 +141,12 @@ export default class Scene extends Mitt {
|
|
|
toVertical = () => {};
|
|
|
|
|
|
lockView(open) {
|
|
|
- if (open) {
|
|
|
+ if (!open) {
|
|
|
this.player.floorplanControls.enablePan = true;
|
|
|
+ this.player.floorplanControls.enableZoom = true;
|
|
|
} else {
|
|
|
this.player.floorplanControls.enablePan = false;
|
|
|
+ this.player.floorplanControls.enableZoom = false;
|
|
|
}
|
|
|
}
|
|
|
setMode(mode) {
|
|
@@ -197,11 +188,17 @@ export default class Scene extends Mitt {
|
|
|
editing(item) {
|
|
|
this.player.editing(item);
|
|
|
}
|
|
|
-
|
|
|
- screenshot(x, index) {
|
|
|
+ endScreenshot() {
|
|
|
+ this.lockView(false);
|
|
|
+ this.blobScreens = [];
|
|
|
+ this.player.floorplanControls.reset();
|
|
|
+ this.onResize();
|
|
|
+ this.renderer.setSize(this.width, this.height);
|
|
|
+ }
|
|
|
+ screenshot(x, zoom) {
|
|
|
var imgData, imgNode;
|
|
|
const times = 4;
|
|
|
- this.orthCamera.zoom = this.defaultZoom;
|
|
|
+ this.orthCamera.zoom = zoom || this.defaultZoom;
|
|
|
this.scene.position.x = x || 0;
|
|
|
|
|
|
this.renderer.setSize(this.width * times, this.height * times);
|
|
@@ -213,50 +210,57 @@ 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);
|
|
|
}
|
|
|
|
|
|
- test() {
|
|
|
+ exportScreenshot() {
|
|
|
+ this.player.floorplanControls.reset();
|
|
|
+ this.lockView(true);
|
|
|
+ this.setMode(0);
|
|
|
+ // await sleep(500);
|
|
|
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;
|
|
|
+ const total = object.children.length;
|
|
|
+ if (total === 0) {
|
|
|
+ return;
|
|
|
+ console.error("没数据");
|
|
|
}
|
|
|
|
|
|
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);
|
|
|
+ // debugger;
|
|
|
console.log("slides", slides);
|
|
|
- if (slides > 1) {
|
|
|
+ if (slides >= 1) {
|
|
|
for (var i = 0; i <= slides; i++) {
|
|
|
(function (index, that) {
|
|
|
setTimeout(function () {
|
|
|
const offset = -(one * 3 * index);
|
|
|
console.log("Iteration:", offset);
|
|
|
- that.screenshot(offset, index);
|
|
|
-
|
|
|
+ that.screenshot(offset);
|
|
|
console.log(`Width: ${offset}`);
|
|
|
- }, index * 1000);
|
|
|
+ if (index === slides) {
|
|
|
+ console.log("last");
|
|
|
+ that.scene.position.x = 0;
|
|
|
+ that.emit("submitScreenshot");
|
|
|
+ }
|
|
|
+ }, index * 500);
|
|
|
})(i, this); // 传递当前迭代的索引i给setTimeout的回调函数
|
|
|
}
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- test1() {
|
|
|
- const object = this.boxManager.model;
|
|
|
- for (var i = 0; i <= object.children.length; i++) {
|
|
|
- console.log(object.children[i]);
|
|
|
- this.scene.lookAt(this.boxManager.model);
|
|
|
+ } else {
|
|
|
+ // 只有一个或0个
|
|
|
+ if (total >= 1 && total <= 3) {
|
|
|
+ console.log("total", total);
|
|
|
+ this.player.floorplanControls.reset();
|
|
|
+ this.screenshot(-0.3, 227);
|
|
|
+ this.emit("submitScreenshot");
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|