1+ import { appScale } from "../../../../utils/platform" ;
12import { sleep } from "../../../../utils/sleep" ;
23import { Vector } from "../../../dataStruct/Vector" ;
34import { Renderer } from "../../../render/canvas2d/renderer" ;
45import { Camera } from "../../../stage/Camera" ;
56import { Canvas } from "../../../stage/Canvas" ;
67import { StageManager } from "../../../stage/stageManager/StageManager" ;
78import { StageStyleManager } from "../../feedbackService/stageStyle/StageStyleManager" ;
8- import { appScale } from "../../../../utils/platform " ;
9+ import { Settings } from "../../Settings " ;
910
1011export 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" ;
0 commit comments