2019-12-09 00:28:10 +01:00
|
|
|
package;
|
2019-06-22 00:25:38 +02:00
|
|
|
|
|
|
|
|
import kha.Window;
|
|
|
|
|
import kha.WindowOptions;
|
|
|
|
|
import kha.WindowMode;
|
|
|
|
|
import kha.System;
|
2019-08-21 11:53:56 +02:00
|
|
|
import iron.object.Object;
|
2019-06-22 00:25:38 +02:00
|
|
|
import iron.Scene;
|
|
|
|
|
import iron.RenderPath;
|
|
|
|
|
import arm.render.Inc;
|
2020-04-27 14:01:45 +02:00
|
|
|
import arm.render.RenderPathForward;
|
2019-06-22 00:25:38 +02:00
|
|
|
import arm.render.RenderPathDeferred;
|
2019-08-25 21:21:56 +02:00
|
|
|
import arm.render.Uniforms;
|
2020-03-26 17:52:56 +01:00
|
|
|
import arm.util.BuildMacros;
|
2019-06-22 00:25:38 +02:00
|
|
|
import arm.Config;
|
2020-04-27 14:01:45 +02:00
|
|
|
import arm.Context;
|
2020-08-07 15:22:56 +02:00
|
|
|
#if arm_vr
|
|
|
|
|
import arm.render.RenderPathForwardVR;
|
|
|
|
|
#end
|
2019-06-22 00:25:38 +02:00
|
|
|
|
2019-05-25 20:15:08 +02:00
|
|
|
class Main {
|
2019-10-06 19:03:59 +02:00
|
|
|
|
2020-03-18 20:26:28 +01:00
|
|
|
public static var version = "0.8";
|
2020-03-26 17:52:56 +01:00
|
|
|
public static var sha = BuildMacros.sha().substr(1, 7);
|
|
|
|
|
public static var date = BuildMacros.date().split(" ")[0];
|
2019-12-09 00:28:10 +01:00
|
|
|
static var tasks: Int;
|
2019-06-22 00:25:38 +02:00
|
|
|
|
2020-11-04 20:49:49 +01:00
|
|
|
#if arm_snapshot
|
2020-11-09 20:06:23 +01:00
|
|
|
static function embedRaw(handle: String, name: String, file: js.lib.ArrayBuffer) {
|
|
|
|
|
iron.data.Data.cachedBlobs.set(name, kha.Blob.fromBytes(haxe.io.Bytes.ofData(file)));
|
2020-11-04 20:49:49 +01:00
|
|
|
iron.data.Data.getSceneRaw(handle, function(_) {});
|
|
|
|
|
iron.data.Data.cachedBlobs.remove(name);
|
|
|
|
|
}
|
2020-11-09 20:06:23 +01:00
|
|
|
static function embedBlob(name: String, file: js.lib.ArrayBuffer) {
|
|
|
|
|
iron.data.Data.cachedBlobs.set(name, kha.Blob.fromBytes(haxe.io.Bytes.ofData(file)));
|
2020-11-04 20:49:49 +01:00
|
|
|
}
|
2020-11-09 20:06:23 +01:00
|
|
|
static function embedFont(name: String, file: js.lib.ArrayBuffer) {
|
2020-11-16 14:14:17 +01:00
|
|
|
iron.data.Data.cachedFonts.set(name, new kha.Font(kha.Blob.fromBytes(haxe.io.Bytes.ofData(file))));
|
2020-11-04 20:49:49 +01:00
|
|
|
}
|
|
|
|
|
#end
|
|
|
|
|
|
2019-06-22 00:25:38 +02:00
|
|
|
public static function main() {
|
2020-11-04 13:21:57 +01:00
|
|
|
#if arm_snapshot
|
|
|
|
|
|
2020-11-09 20:06:23 +01:00
|
|
|
var global = js.Syntax.code("globalThis");
|
|
|
|
|
global.kickstart = kickstart;
|
|
|
|
|
|
|
|
|
|
embedRaw("Scene", "Scene.arm", untyped global['data/Scene.arm']);
|
|
|
|
|
untyped global['data/Scene.arm'] = null;
|
|
|
|
|
|
|
|
|
|
embedRaw("shader_datas", "shader_datas.arm", untyped global['data/shader_datas.arm']);
|
|
|
|
|
untyped global['data/shader_datas.arm'] = null;
|
|
|
|
|
|
|
|
|
|
embedFont("font.ttf", untyped global['data/font.ttf']);
|
|
|
|
|
untyped global['data/font.ttf'] = null;
|
|
|
|
|
|
|
|
|
|
embedFont("font_mono.ttf", untyped global['data/font_mono.ttf']);
|
|
|
|
|
untyped global['data/font_mono.ttf'] = null;
|
|
|
|
|
|
|
|
|
|
var files = [
|
|
|
|
|
"font13.bin",
|
|
|
|
|
"ltc_mag.arm",
|
|
|
|
|
"ltc_mat.arm",
|
|
|
|
|
"default_brush.arm",
|
|
|
|
|
"default_material.arm",
|
|
|
|
|
"World_irradiance.arm",
|
|
|
|
|
"World_radiance.k",
|
|
|
|
|
"World_radiance_0.k",
|
|
|
|
|
"World_radiance_1.k",
|
|
|
|
|
"World_radiance_2.k",
|
|
|
|
|
"World_radiance_3.k",
|
|
|
|
|
"World_radiance_4.k",
|
|
|
|
|
"World_radiance_5.k",
|
|
|
|
|
"World_radiance_6.k",
|
|
|
|
|
"World_radiance_7.k",
|
|
|
|
|
"World_radiance_8.k",
|
|
|
|
|
"brdf.k",
|
|
|
|
|
"color_wheel.k",
|
|
|
|
|
"cursor.k",
|
|
|
|
|
"icons.k",
|
|
|
|
|
"icons2x.k",
|
|
|
|
|
"noise256.k",
|
|
|
|
|
"smaa_search.k",
|
|
|
|
|
"smaa_area.k"
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
for (file in files) {
|
|
|
|
|
embedBlob(file, untyped global['data/' + file]);
|
|
|
|
|
untyped global['data/' + file] = null;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-12 16:15:16 +01:00
|
|
|
#if (kha_direct3d12 || kha_vulkan)
|
|
|
|
|
|
|
|
|
|
var ext = #if kha_direct3d12 ".cso" #else ".spirv" #end ;
|
|
|
|
|
|
|
|
|
|
var files_renderlib = [
|
|
|
|
|
"bnoise_rank.k",
|
|
|
|
|
"bnoise_scramble.k",
|
|
|
|
|
"bnoise_sobol.k",
|
|
|
|
|
"raytrace_bake_ao" + ext,
|
|
|
|
|
"raytrace_bake_bent" + ext,
|
|
|
|
|
"raytrace_bake_light" + ext,
|
|
|
|
|
"raytrace_bake_thick" + ext,
|
|
|
|
|
"raytrace_brute_core" + ext,
|
|
|
|
|
"raytrace_brute_full" + ext
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
for (file in files_renderlib) {
|
|
|
|
|
embedBlob(file, untyped global['data/' + file]);
|
|
|
|
|
untyped global['data/' + file] = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#end
|
|
|
|
|
|
2020-11-09 20:06:23 +01:00
|
|
|
#end // arm_snapshot
|
|
|
|
|
|
|
|
|
|
#if (!arm_snapshot)
|
2020-11-13 23:20:02 +01:00
|
|
|
iron.data.ShaderData.shaderPath = ""; // Use arm_data_dir
|
2020-11-04 13:21:57 +01:00
|
|
|
kickstart();
|
|
|
|
|
#end
|
2020-11-03 15:19:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@:keep
|
|
|
|
|
public static function kickstart() {
|
2020-03-18 20:26:28 +01:00
|
|
|
// Used to locate external application data folder
|
2020-01-24 12:51:18 +01:00
|
|
|
Krom.setApplicationName("ArmorPaint");
|
2020-03-18 20:26:28 +01:00
|
|
|
|
2019-06-22 00:25:38 +02:00
|
|
|
tasks = 1;
|
2019-08-21 11:53:56 +02:00
|
|
|
tasks++; Config.load(function() { tasks--; start(); });
|
2019-12-03 00:25:38 +01:00
|
|
|
#if arm_physics
|
2020-03-18 20:26:28 +01:00
|
|
|
tasks++; arm.plugin.PhysicsWorld.load();
|
2019-12-03 00:25:38 +01:00
|
|
|
#end
|
2019-06-22 00:25:38 +02:00
|
|
|
tasks--; start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static function start() {
|
|
|
|
|
if (tasks > 0) return;
|
2019-10-06 19:03:59 +02:00
|
|
|
|
2020-01-21 09:49:13 +01:00
|
|
|
Config.init();
|
2019-06-22 00:25:38 +02:00
|
|
|
var c = Config.raw;
|
2020-03-18 20:26:28 +01:00
|
|
|
|
2019-06-22 00:25:38 +02:00
|
|
|
var windowMode = c.window_mode == 0 ? WindowMode.Windowed : WindowMode.Fullscreen;
|
|
|
|
|
var windowFeatures = None;
|
|
|
|
|
if (c.window_resizable) windowFeatures |= FeatureResizable;
|
|
|
|
|
if (c.window_maximizable) windowFeatures |= FeatureMaximizable;
|
|
|
|
|
if (c.window_minimizable) windowFeatures |= FeatureMinimizable;
|
2020-01-24 12:51:18 +01:00
|
|
|
var title = "untitled - ArmorPaint";
|
2019-12-09 00:28:10 +01:00
|
|
|
var options: kha.SystemOptions = {
|
|
|
|
|
title: title,
|
|
|
|
|
window: {
|
|
|
|
|
width: c.window_w,
|
|
|
|
|
height: c.window_h,
|
|
|
|
|
x: c.window_x,
|
|
|
|
|
y: c.window_y,
|
|
|
|
|
mode: windowMode,
|
|
|
|
|
windowFeatures: windowFeatures
|
|
|
|
|
},
|
|
|
|
|
framebuffer: {
|
|
|
|
|
samplesPerPixel: 1,
|
2020-06-30 17:41:22 +02:00
|
|
|
verticalSync: c.window_vsync,
|
|
|
|
|
frequency: c.window_frequency
|
2019-12-09 00:28:10 +01:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
System.start(options, function(window: Window) {
|
2020-09-07 14:44:01 +02:00
|
|
|
if (Config.raw.layout == null) Config.initLayout();
|
2020-01-24 12:51:18 +01:00
|
|
|
Krom.setApplicationName("ArmorPaint");
|
2019-06-22 00:25:38 +02:00
|
|
|
iron.App.init(function() {
|
2019-12-09 00:28:10 +01:00
|
|
|
Scene.setActive("Scene", function(o: Object) {
|
2019-08-25 21:21:56 +02:00
|
|
|
Uniforms.init();
|
2019-08-22 12:05:03 +02:00
|
|
|
var path = new RenderPath();
|
|
|
|
|
Inc.init(path);
|
2020-04-27 14:01:45 +02:00
|
|
|
|
2020-08-07 15:22:56 +02:00
|
|
|
#if arm_vr
|
|
|
|
|
RenderPathDeferred.init(path); // Allocate gbuffer
|
|
|
|
|
RenderPathForward.init(path);
|
|
|
|
|
RenderPathForwardVR.init(path);
|
|
|
|
|
path.commands = RenderPathForwardVR.commands;
|
|
|
|
|
#else
|
2020-04-27 14:01:45 +02:00
|
|
|
if (Context.renderMode == RenderForward) {
|
|
|
|
|
RenderPathDeferred.init(path); // Allocate gbuffer
|
|
|
|
|
RenderPathForward.init(path);
|
|
|
|
|
path.commands = RenderPathForward.commands;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
RenderPathDeferred.init(path);
|
|
|
|
|
path.commands = RenderPathDeferred.commands;
|
|
|
|
|
}
|
2020-08-07 15:22:56 +02:00
|
|
|
#end
|
2020-04-27 14:01:45 +02:00
|
|
|
|
2019-08-22 12:05:03 +02:00
|
|
|
RenderPath.setActive(path);
|
|
|
|
|
new arm.App();
|
2019-12-03 00:25:38 +01:00
|
|
|
#if arm_physics
|
|
|
|
|
o.addTrait(new arm.plugin.PhysicsWorld());
|
|
|
|
|
#end
|
2019-06-22 00:25:38 +02:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
2019-05-25 20:15:08 +02:00
|
|
|
}
|