Skip to content

Commit eed34d9

Browse files
committed
🐛 导出png时防止渲染坐标轴
1 parent 6fa879d commit eed34d9

File tree

2 files changed

+48
-9
lines changed

2 files changed

+48
-9
lines changed

app/src/core/service/dataGenerateService/stageExportEngine/StageExportPng.tsx

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
import { appScale } from "../../../../utils/platform";
12
import { sleep } from "../../../../utils/sleep";
23
import { Vector } from "../../../dataStruct/Vector";
34
import { Renderer } from "../../../render/canvas2d/renderer";
45
import { Camera } from "../../../stage/Camera";
56
import { Canvas } from "../../../stage/Canvas";
67
import { StageManager } from "../../../stage/stageManager/StageManager";
78
import { StageStyleManager } from "../../feedbackService/stageStyle/StageStyleManager";
8-
import { appScale } from "../../../../utils/platform";
9+
import { Settings } from "../../Settings";
910

1011
export namespace StageExportPng {
1112
/**
@@ -30,7 +31,7 @@ export namespace StageExportPng {
3031
/**
3132
* 将整个舞台导出为png图片
3233
*/
33-
export async function exportStage() {
34+
async function exportStage_() {
3435
// 创建一个新的画布
3536
const resultCanvas = generateCanvasNode();
3637
const resultCtx = resultCanvas.getContext("2d")!;
@@ -53,9 +54,9 @@ export namespace StageExportPng {
5354
for (let y = topLeft.y; y <= bottomRight.y; y += viewRect.size.y) {
5455
for (let x = topLeft.x; x <= bottomRight.x; x += viewRect.size.x) {
5556
// 先移动再暂停等待
56-
await sleep(200);
57+
await sleep(50);
5758
Camera.location = new Vector(x + viewRect.size.x / 2, y + viewRect.size.y / 2);
58-
await sleep(200);
59+
await sleep(50);
5960
const imageData = Canvas.ctx.getImageData(0, 0, viewRect.size.x * SCALE, viewRect.size.y * SCALE);
6061
resultCtx.putImageData(
6162
imageData,
@@ -75,6 +76,39 @@ export namespace StageExportPng {
7576
}
7677
}
7778

79+
export async function exportStage() {
80+
// 背景网格信息
81+
const showBackgroundCartesian = await Settings.get("showBackgroundCartesian");
82+
Settings.set("showBackgroundCartesian", false);
83+
const showBackgroundDots = await Settings.get("showBackgroundDots");
84+
Settings.set("showBackgroundDots", false);
85+
const showBackgroundHorizontalLines = await Settings.get("showBackgroundHorizontalLines");
86+
Settings.set("showBackgroundHorizontalLines", false);
87+
const showBackgroundVerticalLines = await Settings.get("showBackgroundVerticalLines");
88+
Settings.set("showBackgroundVerticalLines", false);
89+
90+
// 渲染问题
91+
const isPauseRenderWhenManipulateOvertime = await Settings.get("isPauseRenderWhenManipulateOvertime");
92+
Settings.set("isPauseRenderWhenManipulateOvertime", false);
93+
// 先记录摄像机信息
94+
const cameraLocation = Camera.location.clone();
95+
const cameraTargetLocation = Camera.targetLocationByScale.clone();
96+
const cameraScale = Camera.currentScale;
97+
// 开始渲染
98+
await exportStage_();
99+
// 恢复摄像机信息
100+
Camera.location = cameraLocation;
101+
Camera.targetLocationByScale = cameraTargetLocation;
102+
Camera.currentScale = cameraScale;
103+
104+
// 背景网格信息
105+
Settings.set("showBackgroundCartesian", showBackgroundCartesian);
106+
Settings.set("showBackgroundDots", showBackgroundDots);
107+
Settings.set("showBackgroundHorizontalLines", showBackgroundHorizontalLines);
108+
Settings.set("showBackgroundVerticalLines", showBackgroundVerticalLines);
109+
Settings.set("isPauseRenderWhenManipulateOvertime", isPauseRenderWhenManipulateOvertime);
110+
}
111+
78112
export function generateCanvasNode(): HTMLCanvasElement {
79113
const resultCanvas = document.createElement("canvas");
80114
resultCanvas.style.position = "fixed";

app/src/pages/_fixed_panel/_export_png_panel.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import { useEffect, useState } from "react";
2-
import { isExportPNGPanelOpenAtom } from "../../state";
31
import { useAtom } from "jotai";
4-
import { cn } from "../../utils/cn";
2+
import { Download, RefreshCcw } from "lucide-react";
3+
import { useEffect, useState } from "react";
54
import Button from "../../components/Button";
5+
import { Dialog } from "../../components/dialog";
66
import { StageExportPng } from "../../core/service/dataGenerateService/stageExportEngine/StageExportPng";
77
import { Camera } from "../../core/stage/Camera";
8-
import { Dialog } from "../../components/dialog";
9-
import { Download, RefreshCcw } from "lucide-react";
108
import { Stage } from "../../core/stage/Stage";
9+
import { isExportPNGPanelOpenAtom } from "../../state";
10+
import { cn } from "../../utils/cn";
1111
import { PathString } from "../../utils/pathString";
1212

1313
/**
@@ -104,6 +104,11 @@ export default function ExportPNGPanel() {
104104
下载当前图片
105105
</Button>
106106
</div>
107+
<div>
108+
<p className="text-panel-details-text text-xs">
109+
渲染图片时,会逐个拼接小块,需要等待若干秒才能完成渲染,摄像机缩放比率越大,渲染时间越长,画面分辨率越高
110+
</p>
111+
</div>
107112
{/* 关闭按钮 */}
108113
<button
109114
className="absolute right-0 top-0 rounded bg-red-500 px-4 py-2 font-bold text-white hover:bg-red-700"

0 commit comments

Comments
 (0)