-
Notifications
You must be signed in to change notification settings - Fork 33
/
textureCompressor.js
57 lines (53 loc) · 1.36 KB
/
textureCompressor.js
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
var textureCompressor = require("texture-compressor");
var fs = require("fs");
var type = process.argv[2];
var fileName = process.argv[3];
var mainPath = process.argv[4];
var flipY = process.argv[5];
var useJPG = process.argv[6];
if (typeof flipY == "string"){
flipY = flipY.toLowerCase() == "true";
}
if (typeof useJPG == "string"){
useJPG = useJPG.toLowerCase() == "true"
}
compressTexture(type, fileName, mainPath);
function compressTexture(type, fileName, mainPath){
var quality, compression;
var inputExtension;
if (useJPG){
if (fs.existsSync(mainPath+"/"+fileName+".jpg")){
inputExtension = "jpg";
}else if(fs.existsSync(mainPath+"/"+fileName+".jpeg")){
inputExtension = "jpeg";
}else{
throw new Error("Fallback texture not provided.");
}
}else{
inputExtension = "png";
}
var output = mainPath+"/"+fileName+"-"+type+".ktx";
switch(type){
case "astc":
quality = "astcmedium";
compression = "ASTC_4x4";
break;
case "pvrtc":
quality = "pvrtcnormal";
compression = "PVRTC1_4";
break;
case "s3tc":
quality = "normal";
compression = "DXT1A";
break;
}
return textureCompressor.pack({
type: type,
input: mainPath+"/"+fileName+"."+inputExtension,
output: output,
compression: compression,
quality: quality,
verbose: true,
flipY: flipY
});
}