Improve texture export

This commit is contained in:
luboslenco
2019-04-12 18:12:45 +02:00
parent fa61a341d4
commit bc41d047cb
2 changed files with 151 additions and 111 deletions
+139 -109
View File
@@ -19,33 +19,60 @@ class Exporter {
var selectedLayer = UITrait.inst.selectedLayer;
var pixels:haxe.io.Bytes = null;
if (UITrait.inst.isBase) {
if (UITrait.inst.isBase || UITrait.inst.isOpac) {
pixels = selectedLayer.texpaint.getPixels(); // bgra
if (UITrait.inst.isBaseSpace == 1) {
if (UITrait.inst.isBase && UITrait.inst.isBaseSpace == 1) {
for (i in 0...Std.int(pixels.length / 4)) {
pixels.set(i * 4 + 0, Std.int(Math.pow(pixels.get(i * 4 + 0) / 255, 1.0 / 2.2) * 255));
pixels.set(i * 4 + 1, Std.int(Math.pow(pixels.get(i * 4 + 1) / 255, 1.0 / 2.2) * 255));
pixels.set(i * 4 + 2, Std.int(Math.pow(pixels.get(i * 4 + 2) / 255, 1.0 / 2.2) * 255));
// pixels.set(i * 4 + 3, 255);
}
}
if (formatType == 0) {
var jpgdata:iron.format.jpg.Data.Data = {
width: textureSize,
height: textureSize,
quality: formatQuality,
pixels: pixels
};
var jpgwriter = new iron.format.jpg.Writer(bo);
jpgwriter.write(jpgdata, 1);
if (UITrait.inst.isOpac && UITrait.inst.isOpacSpace == 1) {
for (i in 0...Std.int(pixels.length / 4)) {
pixels.set(i * 4 + 3, Std.int(Math.pow(pixels.get(i * 4 + 3) / 255, 1.0 / 2.2) * 255));
}
}
else {
var pngwriter = new iron.format.png.Writer(bo);
pngwriter.write(iron.format.png.Tools.build32RGBA(textureSize, textureSize, pixels));
if (UITrait.inst.isBase) {
if (formatType == 0) {
var jpgdata:iron.format.jpg.Data.Data = {
width: textureSize,
height: textureSize,
quality: formatQuality,
pixels: pixels
};
var jpgwriter = new iron.format.jpg.Writer(bo);
jpgwriter.write(jpgdata, 1);
}
else {
var pngwriter = new iron.format.png.Writer(bo);
pngwriter.write(iron.format.png.Tools.build32RGBA(textureSize, textureSize, pixels));
}
#if kha_krom
Krom.fileSaveBytes(path + "/" + f + "_base" + ext, bo.getBytes().getData());
#end
}
if (UITrait.inst.isOpac) {
bo = new haxe.io.BytesOutput();
if (formatType == 0) {
var jpgdata:iron.format.jpg.Data.Data = {
width: textureSize,
height: textureSize,
quality: formatQuality,
pixels: pixels
};
var jpgwriter = new iron.format.jpg.Writer(bo);
jpgwriter.write(jpgdata, 2, 3);
}
else {
var pngwriter = new iron.format.png.Writer(bo);
pngwriter.write(iron.format.png.Tools.build32RGBA(textureSize, textureSize, pixels, 3));
}
#if kha_krom
Krom.fileSaveBytes(path + "/" + f + "_opac" + ext, bo.getBytes().getData());
#end
}
#if kha_krom
Krom.fileSaveBytes(path + "/" + f + "_base" + ext, bo.getBytes().getData());
#end
}
if (UITrait.inst.isNor) {
@@ -55,7 +82,6 @@ class Exporter {
pixels.set(i * 4 + 0, Std.int(Math.pow(pixels.get(i * 4 + 0) / 255, 1.0 / 2.2) * 255));
pixels.set(i * 4 + 1, Std.int(Math.pow(pixels.get(i * 4 + 1) / 255, 1.0 / 2.2) * 255));
pixels.set(i * 4 + 2, Std.int(Math.pow(pixels.get(i * 4 + 2) / 255, 1.0 / 2.2) * 255));
// pixels.set(i * 4 + 3, 255);
}
}
bo = new haxe.io.BytesOutput();
@@ -78,85 +104,120 @@ class Exporter {
#end
}
if (UITrait.inst.isOcc || UITrait.inst.isRough || UITrait.inst.isMet) {
if (UITrait.inst.isOcc || UITrait.inst.isRough || UITrait.inst.isMet || UITrait.inst.isHeight) {
pixels = selectedLayer.texpaint_pack.getPixels(); // occ, rough, met
pixels = selectedLayer.texpaint_pack.getPixels(); // occ, rough, met, height
if (UITrait.inst.isOccSpace == 1) {
if (UITrait.inst.isOcc && UITrait.inst.isOccSpace == 1) {
for (i in 0...Std.int(pixels.length / 4)) {
pixels.set(i * 4 + 2, Std.int(Math.pow(pixels.get(i * 4 + 2) / 255, 1.0 / 2.2) * 255));
}
}
if (UITrait.inst.isRoughSpace == 1) {
if (UITrait.inst.isRough && UITrait.inst.isRoughSpace == 1) {
for (i in 0...Std.int(pixels.length / 4)) {
pixels.set(i * 4 + 1, Std.int(Math.pow(pixels.get(i * 4 + 1) / 255, 1.0 / 2.2) * 255));
}
}
if (UITrait.inst.isMetSpace == 1) {
if (UITrait.inst.isMet && UITrait.inst.isMetSpace == 1) {
for (i in 0...Std.int(pixels.length / 4)) {
pixels.set(i * 4 + 0, Std.int(Math.pow(pixels.get(i * 4 + 0) / 255, 1.0 / 2.2) * 255));
}
}
if (UITrait.inst.isHeight && UITrait.inst.isHeightSpace == 1) {
for (i in 0...Std.int(pixels.length / 4)) {
pixels.set(i * 4 + 3, Std.int(Math.pow(pixels.get(i * 4 + 3) / 255, 1.0 / 2.2) * 255));
}
}
if (UITrait.inst.outputType == 0) {
bo = new haxe.io.BytesOutput();
if (formatType == 0) {
var jpgdata:iron.format.jpg.Data.Data = {
width: textureSize,
height: textureSize,
quality: formatQuality,
pixels: pixels
};
var jpgwriter = new iron.format.jpg.Writer(bo);
jpgwriter.write(jpgdata, 2, 0);
}
else {
var pngwriter = new iron.format.png.Writer(bo);
pngwriter.write(iron.format.png.Tools.build32RGBA_(textureSize, textureSize, pixels, 0));
}
#if kha_krom
if (UITrait.inst.isOcc) Krom.fileSaveBytes(path + "/" + f + "_occ" + ext, bo.getBytes().getData());
#end
bo = new haxe.io.BytesOutput();
if (formatType == 0) {
var jpgdata:iron.format.jpg.Data.Data = {
width: textureSize,
height: textureSize,
quality: formatQuality,
pixels: pixels
};
var jpgwriter = new iron.format.jpg.Writer(bo);
jpgwriter.write(jpgdata, 2, 1);
if (UITrait.inst.isOcc) {
bo = new haxe.io.BytesOutput();
if (formatType == 0) {
var jpgdata:iron.format.jpg.Data.Data = {
width: textureSize,
height: textureSize,
quality: formatQuality,
pixels: pixels
};
var jpgwriter = new iron.format.jpg.Writer(bo);
jpgwriter.write(jpgdata, 2, 0);
}
else {
var pngwriter = new iron.format.png.Writer(bo);
pngwriter.write(iron.format.png.Tools.build32RGBA_(textureSize, textureSize, pixels, 0));
}
#if kha_krom
Krom.fileSaveBytes(path + "/" + f + "_occ" + ext, bo.getBytes().getData());
#end
}
else {
var pngwriter = new iron.format.png.Writer(bo);
pngwriter.write(iron.format.png.Tools.build32RGBA_(textureSize, textureSize, pixels, 1));
if (UITrait.inst.isRough) {
bo = new haxe.io.BytesOutput();
if (formatType == 0) {
var jpgdata:iron.format.jpg.Data.Data = {
width: textureSize,
height: textureSize,
quality: formatQuality,
pixels: pixels
};
var jpgwriter = new iron.format.jpg.Writer(bo);
jpgwriter.write(jpgdata, 2, 1);
}
else {
var pngwriter = new iron.format.png.Writer(bo);
pngwriter.write(iron.format.png.Tools.build32RGBA_(textureSize, textureSize, pixels, 1));
}
#if kha_krom
Krom.fileSaveBytes(path + "/" + f + "_rough" + ext, bo.getBytes().getData());
#end
}
#if kha_krom
if (UITrait.inst.isRough) Krom.fileSaveBytes(path + "/" + f + "_rough" + ext, bo.getBytes().getData());
#end
bo = new haxe.io.BytesOutput();
if (formatType == 0) {
var jpgdata:iron.format.jpg.Data.Data = {
width: textureSize,
height: textureSize,
quality: formatQuality,
pixels: pixels
};
var jpgwriter = new iron.format.jpg.Writer(bo);
jpgwriter.write(jpgdata, 2, 2);
if (UITrait.inst.isMet) {
bo = new haxe.io.BytesOutput();
if (formatType == 0) {
var jpgdata:iron.format.jpg.Data.Data = {
width: textureSize,
height: textureSize,
quality: formatQuality,
pixels: pixels
};
var jpgwriter = new iron.format.jpg.Writer(bo);
jpgwriter.write(jpgdata, 2, 2);
}
else {
var pngwriter = new iron.format.png.Writer(bo);
pngwriter.write(iron.format.png.Tools.build32RGBA_(textureSize, textureSize, pixels, 2));
}
#if kha_krom
Krom.fileSaveBytes(path + "/" + f + "_met" + ext, bo.getBytes().getData());
#end
}
else {
var pngwriter = new iron.format.png.Writer(bo);
pngwriter.write(iron.format.png.Tools.build32RGBA_(textureSize, textureSize, pixels, 2));
}
#if kha_krom
if (UITrait.inst.isMet) Krom.fileSaveBytes(path + "/" + f + "_met" + ext, bo.getBytes().getData());
#end
}
else { // UE4
if (UITrait.inst.isOcc || UITrait.inst.isRough || UITrait.inst.isMet) {
bo = new haxe.io.BytesOutput();
if (formatType == 0) {
var jpgdata:iron.format.jpg.Data.Data = {
width: textureSize,
height: textureSize,
quality: formatQuality,
pixels: pixels
};
var jpgwriter = new iron.format.jpg.Writer(bo);
jpgwriter.write(jpgdata, 1);
}
else {
var pngwriter = new iron.format.png.Writer(bo);
pngwriter.write(iron.format.png.Tools.build32RGBA(textureSize, textureSize, pixels));
}
#if kha_krom
Krom.fileSaveBytes(path + "/" + f + "_orm" + ext, bo.getBytes().getData());
#end
}
}
if (UITrait.inst.isHeight) {
bo = new haxe.io.BytesOutput();
if (formatType == 0) {
var jpgdata:iron.format.jpg.Data.Data = {
@@ -166,49 +227,18 @@ class Exporter {
pixels: pixels
};
var jpgwriter = new iron.format.jpg.Writer(bo);
jpgwriter.write(jpgdata, 1);
jpgwriter.write(jpgdata, 2, 3);
}
else {
var pngwriter = new iron.format.png.Writer(bo);
pngwriter.write(iron.format.png.Tools.build32RGBA(textureSize, textureSize, pixels));
pngwriter.write(iron.format.png.Tools.build32RGBA(textureSize, textureSize, pixels, 3));
}
#if kha_krom
if (UITrait.inst.isOcc) Krom.fileSaveBytes(path + "/" + f + "_orm" + ext, bo.getBytes().getData());
Krom.fileSaveBytes(path + "/" + f + "_height" + ext, bo.getBytes().getData());
#end
}
}
if (UITrait.inst.isHeight) {
// pixels = selectedLayer.texpaint_opt.getPixels();
// if (UITrait.inst.isHeightSpace == 1) {
// for (i in 0...Std.int(pixels.length / 4)) {
// pixels.set(i * 4 + 0, Std.int(Math.pow(pixels.get(i * 4 + 0) / 255, 1.0 / 2.2) * 255));
// pixels.set(i * 4 + 1, Std.int(Math.pow(pixels.get(i * 4 + 1) / 255, 1.0 / 2.2) * 255));
// pixels.set(i * 4 + 2, Std.int(Math.pow(pixels.get(i * 4 + 2) / 255, 1.0 / 2.2) * 255));
// // pixels.set(i * 4 + 3, 255);
// }
// }
// bo = new haxe.io.BytesOutput();
// if (formatType == 0) {
// var jpgdata:iron.format.jpg.Data.Data = {
// width: textureSize,
// height: textureSize,
// quality: formatQuality,
// pixels: pixels
// };
// var jpgwriter = new iron.format.jpg.Writer(bo);
// jpgwriter.write(jpgdata, 1);
// }
// else {
// var pngwriter = new iron.format.png.Writer(bo);
// pngwriter.write(iron.format.png.Tools.build32RGBA(textureSize, textureSize, pixels));
// }
// #if kha_krom
// Krom.fileSaveBytes(path + "/" + f + "_height" + ext, bo.getBytes().getData());
// #end
}
// if (UITrait.inst.isOpac) Krom.fileSaveBytes(path + "/tex_opac" + ext, bo.getBytes().getData());
// if (UITrait.inst.isEmis) Krom.fileSaveBytes(path + "/tex_emis" + ext, bo.getBytes().getData());
// if (UITrait.inst.isSubs) Krom.fileSaveBytes(path + "/tex_subs" + ext, bo.getBytes().getData());
}
+12 -2
View File
@@ -88,7 +88,7 @@ class UITrait extends iron.Trait {
public var outputType = 0;
public var isBase = true;
public var isBaseSpace = 0;
public var isOpac = true;
public var isOpac = false;
public var isOpacSpace = 0;
public var isOcc = true;
public var isOccSpace = 0;
@@ -98,8 +98,12 @@ class UITrait extends iron.Trait {
public var isMetSpace = 0;
public var isNor = true;
public var isNorSpace = 0;
public var isHeight = true;
public var isEmis = false;
public var isEmisSpace = 0;
public var isHeight = false;
public var isHeightSpace = 0;
public var isSubs = false;
public var isSubsSpace = 0;
public var isUdim = false;
public var hwnd = Id.handle();
public var hwnd1 = Id.handle();
@@ -2488,8 +2492,14 @@ class UITrait extends iron.Trait {
isNor = ui.check(Id.handle({selected: isNor}), "Normal");
isNorSpace = ui.combo(Id.handle({position: isNorSpace}), ["linear", "srgb"], "Space");
ui.row([1/2, 1/2]);
isEmis = ui.check(Id.handle({selected: isEmis}), "Emission");
isEmisSpace = ui.combo(Id.handle({position: isEmisSpace}), ["linear", "srgb"], "Space");
ui.row([1/2, 1/2]);
isHeight = ui.check(Id.handle({selected: isHeight}), "Height");
isHeightSpace = ui.combo(Id.handle({position: isHeightSpace}), ["linear", "srgb"], "Space");
ui.row([1/2, 1/2]);
isSubs = ui.check(Id.handle({selected: isSubs}), "Subsurface");
isSubsSpace = ui.combo(Id.handle({position: isSubsSpace}), ["linear", "srgb"], "Space");
}
}