/
texconv.ts
76 lines (73 loc) · 1.33 KB
/
texconv.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import { spawn } from '../utils'
export interface TexconvArgs {
exe?: string
input: string
// Output directory.
output?: string
// A file type for the output texture
fileType: string
//
format?: string
// overwrite existing output file
overwrite: boolean
width?: number
height?: number
invertY?: boolean
reconstructZ?: boolean
alpha?: boolean
sepalpha?: boolean
}
export async function texconv({
exe,
input,
output,
fileType,
format,
overwrite,
width,
height,
invertY,
reconstructZ,
alpha,
sepalpha,
}: TexconvArgs) {
// https://github.com/Microsoft/DirectXTex/wiki/Texconv
const tool = exe || 'texconv.exe'
const args: string[] = []
if (fileType) {
args.push(`-ft`, fileType)
}
if (format) {
args.push(`-f`, format)
}
if (overwrite) {
args.push(`-y`)
}
if (output) {
args.push(`-o`, output)
}
if (width) {
args.push(`-w`, String(width))
}
if (height) {
args.push(`-h`, String(height))
}
if (invertY) {
args.push(`-inverty`, String(invertY))
}
if (reconstructZ) {
args.push(`-reconstructz`, String(reconstructZ))
}
if (alpha) {
args.push(`-alpha`)
}
if (sepalpha) {
args.push(`-sepalpha`)
}
args.push('-nologo')
args.push('-fl', '12.1')
args.push(input)
await spawn(tool, args, {
stdio: 'inherit',
})
}