@@ -2,19 +2,19 @@ import fs from "fs/promises";
2
2
import { createCanvas } from "node-canvas-webgl" ;
3
3
import { FfmpegFrameExporter } from "./exporter.js" ;
4
4
import { AssetPath , SpineRenderer , TexturePath , loadTexture } from "./renderer.js" ;
5
- import { formatOutputPath , traverseDir } from "./utils.js" ;
5
+ import { formatOutputPath , traverseDir , Viewsize } from "./utils.js" ;
6
6
import { TExporterType } from "./exporter.js" ;
7
7
import { AssetManager , ManagedWebGLRenderingContext } from "@node-spine-runtimes/webgl-3.8.99" ;
8
8
import sharp from "sharp" ;
9
9
import path from "path" ;
10
10
import { formatString } from "./utils.js" ;
11
11
12
- export function parseCanvasSize ( size : string ) {
13
- const canvasWxH = size . split ( "x" ) ;
14
- if ( canvasWxH . length !== 2 ) {
12
+ export function parseCanvasSize ( size : string ) : Viewsize {
13
+ const canvasSize = size . split ( "x" ) ;
14
+ if ( canvasSize . length !== 2 ) {
15
15
throw new Error ( "Canvas size format error! \n" + "Correct format: [width]x[height], for example 500x500." ) ;
16
16
}
17
- return { width : parseInt ( canvasWxH [ 0 ] ) , height : parseInt ( canvasWxH [ 1 ] ) } ;
17
+ return { width : parseInt ( canvasSize [ 0 ] ) , height : parseInt ( canvasSize [ 1 ] ) } ;
18
18
}
19
19
20
20
export interface SpineAnimationExportOptions {
@@ -48,10 +48,7 @@ export async function exportSpineAnimation(inputDir: string, options: SpineAnima
48
48
} ;
49
49
await checkParams ( ) ;
50
50
51
- const isOldCanvasMode = typeof canvasSize === "string" ;
52
- const size = isOldCanvasMode ? parseCanvasSize ( canvasSize ) : { width : 1000 , height : 1000 } ;
53
-
54
- const renderer = new SpineRenderer ( createCanvas ( size . width , size . height ) ) ;
51
+ const renderer = new SpineRenderer ( createCanvas ( 1000 , 1000 ) ) ;
55
52
const exporter = new FfmpegFrameExporter ( exporterMaxConcurrent )
56
53
57
54
const paths = await traverseDir ( inputDir , AssetPath ) ;
@@ -67,12 +64,13 @@ export async function exportSpineAnimation(inputDir: string, options: SpineAnima
67
64
if ( selectedAnimation . length && ! selectedAnimation . includes ( animationName ) ) {
68
65
continue ;
69
66
}
70
-
67
+ const viewsize = typeof canvasSize === "string" ? parseCanvasSize ( canvasSize ) : undefined ;
71
68
console . log ( `${ assetProcess } Start rendering the animation '${ animationName } ' of asset '${ assetName } '...` ) ;
72
69
const animationFrames = renderer . render ( {
73
70
skeleton,
74
71
state,
75
72
animationName,
73
+ viewsize,
76
74
fps,
77
75
endPosition,
78
76
} ) ;
@@ -85,7 +83,7 @@ export async function exportSpineAnimation(inputDir: string, options: SpineAnima
85
83
{
86
84
outputPath : formatOutputPath ( outputPath , formatObject ) ,
87
85
fps,
88
- autoCrop : isOldCanvasMode ,
86
+ autoCrop : viewsize !== undefined ,
89
87
}
90
88
) ;
91
89
}
0 commit comments