2019-06-19 09:40:14 +02:00
|
|
|
package arm.io;
|
|
|
|
|
|
2019-06-20 11:23:01 +02:00
|
|
|
import haxe.Json;
|
|
|
|
|
import zui.Nodes;
|
2019-06-19 09:40:14 +02:00
|
|
|
import iron.data.SceneFormat;
|
2019-06-20 11:23:01 +02:00
|
|
|
import iron.system.ArmPack;
|
2019-06-19 09:40:14 +02:00
|
|
|
import arm.ui.UITrait;
|
2019-06-19 18:45:36 +02:00
|
|
|
import arm.ui.UINodes;
|
|
|
|
|
import arm.util.Lz4;
|
|
|
|
|
import arm.util.Path;
|
2019-06-19 22:42:17 +02:00
|
|
|
import arm.Project;
|
2019-06-20 12:30:31 +02:00
|
|
|
using StringTools;
|
2019-06-19 09:40:14 +02:00
|
|
|
|
|
|
|
|
class ExportArm {
|
|
|
|
|
|
|
|
|
|
public static function run(path:String) {
|
|
|
|
|
var raw:TSceneFormat = { mesh_datas: [ UITrait.inst.paintObject.data.raw ] };
|
2019-06-20 11:23:01 +02:00
|
|
|
var b = ArmPack.encode(raw);
|
2019-06-20 12:30:31 +02:00
|
|
|
if (!path.endsWith(".arm")) path += ".arm";
|
2019-06-19 09:40:14 +02:00
|
|
|
#if kha_krom
|
|
|
|
|
Krom.fileSaveBytes(path, b.getData());
|
|
|
|
|
#end
|
|
|
|
|
}
|
2019-06-19 18:45:36 +02:00
|
|
|
|
|
|
|
|
public static function runProject() {
|
2019-06-20 11:23:01 +02:00
|
|
|
var mnodes:Array<TNodeCanvas> = [];
|
|
|
|
|
var bnodes:Array<TNodeCanvas> = [];
|
2019-06-19 18:45:36 +02:00
|
|
|
|
|
|
|
|
for (m in UITrait.inst.materials) {
|
2019-06-20 11:23:01 +02:00
|
|
|
var c:TNodeCanvas = Json.parse(Json.stringify(UINodes.inst.canvasMap.get(m)));
|
2019-06-19 18:45:36 +02:00
|
|
|
for (n in c.nodes) {
|
|
|
|
|
if (n.type == "TEX_IMAGE") { // Convert image path from absolute to relative
|
|
|
|
|
var sameDrive = UITrait.inst.projectPath.charAt(0) == n.buttons[0].data.charAt(0);
|
|
|
|
|
if (sameDrive) {
|
|
|
|
|
n.buttons[0].data = Path.toRelative(UITrait.inst.projectPath, n.buttons[0].data);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
mnodes.push(c);
|
|
|
|
|
}
|
|
|
|
|
for (b in UITrait.inst.brushes) bnodes.push(UINodes.inst.canvasBrushMap.get(b));
|
|
|
|
|
|
|
|
|
|
var md:Array<TMeshData> = [];
|
|
|
|
|
for (p in UITrait.inst.paintObjects) md.push(p.data.raw);
|
|
|
|
|
|
|
|
|
|
var asset_files:Array<String> = [];
|
|
|
|
|
for (a in UITrait.inst.assets) {
|
|
|
|
|
// Convert image path from absolute to relative
|
|
|
|
|
var sameDrive = UITrait.inst.projectPath.charAt(0) == a.file.charAt(0);
|
|
|
|
|
if (sameDrive) {
|
|
|
|
|
asset_files.push(Path.toRelative(UITrait.inst.projectPath, a.file));
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
asset_files.push(a.file);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var ld:Array<TLayerData> = [];
|
|
|
|
|
for (l in UITrait.inst.layers) {
|
|
|
|
|
ld.push({
|
|
|
|
|
res: l.texpaint.width,
|
|
|
|
|
texpaint: Lz4.encode(l.texpaint.getPixels()),
|
|
|
|
|
texpaint_nor: Lz4.encode(l.texpaint_nor.getPixels()),
|
|
|
|
|
texpaint_pack: Lz4.encode(l.texpaint_pack.getPixels()),
|
|
|
|
|
texpaint_mask: l.texpaint_mask != null ? Lz4.encode(l.texpaint_mask.getPixels()) : null,
|
|
|
|
|
opacity_mask: l.maskOpacity,
|
|
|
|
|
material_mask: l.material_mask != null ? UITrait.inst.materials.indexOf(l.material_mask) : -1,
|
|
|
|
|
object_mask: l.objectMask
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UITrait.inst.project = {
|
2019-06-20 11:23:01 +02:00
|
|
|
version: App.version,
|
2019-06-19 18:45:36 +02:00
|
|
|
material_nodes: mnodes,
|
|
|
|
|
brush_nodes: bnodes,
|
|
|
|
|
mesh_datas: md,
|
|
|
|
|
layer_datas: ld,
|
|
|
|
|
assets: asset_files
|
|
|
|
|
};
|
|
|
|
|
|
2019-06-20 11:23:01 +02:00
|
|
|
var bytes = ArmPack.encode(UITrait.inst.project);
|
2019-06-19 18:45:36 +02:00
|
|
|
|
|
|
|
|
#if kha_krom
|
|
|
|
|
Krom.fileSaveBytes(UITrait.inst.projectPath, bytes.getData());
|
|
|
|
|
#end
|
|
|
|
|
}
|
2019-06-19 09:40:14 +02:00
|
|
|
}
|