diff --git a/armorpaint/Assets/plugins/dev/converter.js b/armorpaint/Assets/plugins/dev/converter.js index e5b1383d..c6ac5dc9 100644 --- a/armorpaint/Assets/plugins/dev/converter.js +++ b/armorpaint/Assets/plugins/dev/converter.js @@ -1,27 +1,27 @@ -let plugin = new arm.Plugin(); +let plugin = new Plugin(); -let h1 = new zui.Handle(); +let h1 = new Handle(); plugin.drawUI = function(ui) { if (ui.panel(h1, "Converter")) { ui.row([1/2, 1/2]); if (ui.button(".arm to .json")) { - arm.UIFiles.show("arm", false, true, function(path) { - iron.Data.getBlob(path, function(b) { - let parsed = iron.ArmPack.decode(b); - let out = core.System.stringToBuffer(core.Json.stringify(parsed, function(key, value) { - if (value.constructor.name === "Float32Array")) { + UIFiles.show("arm", false, true, function(path) { + Data.getBlob(path, function(b) { + let parsed = ArmPack.decode(b); + let out = System.stringToBuffer(JSON.stringify(parsed, function(key, value) { + if (value.constructor.name === "Float32Array") { let ar = Array.from(value); ar.unshift(0); // Annotate array type return ar; } - else if (value.constructor.name === "Uint32Array")) { + else if (value.constructor.name === "Uint32Array") { let ar = Array.from(value); ar.unshift(1); return ar; } - else if (value.constructor.name === "Int16Array")) { + else if (value.constructor.name === "Int16Array") { let ar = Array.from(value); ar.unshift(2); return ar; @@ -33,12 +33,12 @@ plugin.drawUI = function(ui) { }); } if (ui.button(".json to .arm")) { - arm.UIFiles.show("json", false, true, function(path) { - iron.Data.getBlob(path, function(b) { - let parsed = core.Json.parse(core.System.bufferToString(b)); + UIFiles.show("json", false, true, function(path) { + Data.getBlob(path, function(b) { + let parsed = JSON.parse(System.bufferToString(b)); function iterate(d) { - for (const n of core.ReflectFields(d)) { - let v = core.ReflectField(d, n); + for (const n of ReflectFields(d)) { + let v = ReflectField(d, n); if (v.constructor.name === "Array") { if (v[0].constructor.name === "Number") { console.log(n); @@ -47,7 +47,7 @@ plugin.drawUI = function(ui) { else if (v[0] === 1) ar = new Uint32Array(v.length - 1); else if (v[0] === 2) ar = new Int16Array(v.length - 1); for (let i = 0; i < v.length - 1; ++i) ar[i] = v[i + 1]; - core.ReflectSetField(d, n, ar); + ReflectSetField(d, n, ar); } else for (const e of v) if (typeof e === 'object') iterate(e); } @@ -55,7 +55,7 @@ plugin.drawUI = function(ui) { } } iterate(parsed); - let out = iron.ArmPack.encode(parsed); + let out = ArmPack.encode(parsed); Krom.fileSaveBytes(path.substr(0, path.length - 4) + "arm", out, out.byteLength + 1); }); }); diff --git a/armorpaint/Assets/plugins/hello_node.js b/armorpaint/Assets/plugins/hello_node.js index 64f0441b..f14e4b1d 100644 --- a/armorpaint/Assets/plugins/hello_node.js +++ b/armorpaint/Assets/plugins/hello_node.js @@ -1,12 +1,12 @@ -let plugin = new arm.Plugin(); +let plugin = new Plugin(); let categoryName = "My Nodes"; let nodeName = "Hello World"; let nodeType = "HELLO_WORLD"; // Create new node category -let categories = arm.NodesMaterial.categories; +let categories = NodesMaterial.categories; categories.push(categoryName); // Create new node @@ -51,13 +51,13 @@ let nodes = [ buttons: [] } ]; -arm.NodesMaterial.list.push(nodes); +NodesMaterial.list.push(nodes); // Node shader -arm.ParserMaterial.customNodes.set(nodeType, function(node, socket) { - let frag = arm.ParserMaterial.frag; - let scale = arm.ParserMaterial.parse_value_input(node.inputs[0]); - let my_out = arm.ParserMaterial.node_name(node) + "_out"; +ParserMaterial.customNodes.set(nodeType, function(node, socket) { + let frag = ParserMaterial.frag; + let scale = ParserMaterial.parse_value_input(node.inputs[0]); + let my_out = ParserMaterial.node_name(node) + "_out"; frag.write(` float ${my_out} = cos(sin(texCoord.x * 200.0 * ${scale}) + cos(texCoord.y * 200.0 * ${scale})); @@ -73,7 +73,7 @@ arm.ParserMaterial.customNodes.set(nodeType, function(node, socket) { // Cleanup plugin.delete = function() { - arm.ParserMaterial.customNodes.delete(nodeType); - arm.NodesMaterial.list.splice(arm.NodesMaterial.list.indexOf(nodes), 1); + ParserMaterial.customNodes.delete(nodeType); + NodesMaterial.list.splice(NodesMaterial.list.indexOf(nodes), 1); categories.splice(categories.indexOf(categoryName), 1); }; diff --git a/armorpaint/Assets/plugins/hello_node_brush.js b/armorpaint/Assets/plugins/hello_node_brush.js index 4194eb62..501828c6 100644 --- a/armorpaint/Assets/plugins/hello_node_brush.js +++ b/armorpaint/Assets/plugins/hello_node_brush.js @@ -1,12 +1,12 @@ -let plugin = new arm.Plugin(); +let plugin = new Plugin(); let categoryName = "My Nodes"; let nodeName = "Hello World"; let nodeType = "HELLO_WORLD"; // Create new node category -let categories = arm.NodesBrush.categories; +let categories = NodesBrush.categories; categories.push(categoryName); // Create new node @@ -43,16 +43,16 @@ let nodes = [ buttons: [] } ]; -arm.NodesBrush.list.push(nodes); +NodesBrush.list.push(nodes); // Brush node -arm.ParserLogic.customNodes.set(nodeType, function(node, from) { +ParserLogic.customNodes.set(nodeType, function(node, from) { return Math.sin(iron.Time.time() * node.inputs[0].get(0)); }); // Cleanup plugin.delete = function() { - arm.ParserLogic.customNodes.delete(nodeType); - arm.NodesBrush.list.splice(arm.NodesBrush.list.indexOf(nodes), 1); + ParserLogic.customNodes.delete(nodeType); + NodesBrush.list.splice(NodesBrush.list.indexOf(nodes), 1); categories.splice(categories.indexOf(categoryName), 1); }; diff --git a/armorpaint/Assets/plugins/hello_world.js b/armorpaint/Assets/plugins/hello_world.js index 9ac06309..4e0bd5f6 100644 --- a/armorpaint/Assets/plugins/hello_world.js +++ b/armorpaint/Assets/plugins/hello_world.js @@ -1,13 +1,13 @@ -let plugin = new arm.Plugin(); +let plugin = new Plugin(); -let h1 = new zui.Handle(); -let h2 = new zui.Handle(); -let h3 = new zui.Handle(); -let h4 = new zui.Handle(); -let h5 = new zui.Handle(); -let h6 = new zui.Handle(); -let h7 = new zui.Handle(); +let h1 = new Handle(); +let h2 = new Handle(); +let h3 = new Handle(); +let h4 = new Handle(); +let h5 = new Handle(); +let h6 = new Handle(); +let h7 = new Handle(); plugin.drawUI = function(ui) { if (ui.panel(h1, "My Plugin")) { diff --git a/armorpaint/Assets/plugins/import_stl.js b/armorpaint/Assets/plugins/import_stl.js index 896d3810..50cd6e1b 100644 --- a/armorpaint/Assets/plugins/import_stl.js +++ b/armorpaint/Assets/plugins/import_stl.js @@ -20,7 +20,7 @@ let read_f32 = function(view) { } let import_stl = function(path, done) { - iron.Data.getBlob(path, function(b) { + Data.getBlob(path, function(b) { let view = new DataView(b); pos = 0; // let header = input.read(80); @@ -80,17 +80,17 @@ let import_stl = function(path, done) { scale_tex: 1.0 }); - iron.Data.deleteBlob(path); + Data.deleteBlob(path); }); } -let plugin = new arm.Plugin(); -let formats = arm.Path.meshFormats; -let importers = arm.Path.meshImporters; +let plugin = new Plugin(); +let formats = Path.meshFormats; +let importers = Path.meshImporters; formats.push("stl"); -importers.h["stl"] = import_stl; +importers.set("stl", import_stl); plugin.delete = function() { formats.splice(formats.indexOf("stl"), 1); - importers.h["stl"] = null; + importers.delete("stl"); }; diff --git a/armorpaint/Assets/plugins/import_svg.js b/armorpaint/Assets/plugins/import_svg.js index ab5ed5be..61f3a0ad 100644 --- a/armorpaint/Assets/plugins/import_svg.js +++ b/armorpaint/Assets/plugins/import_svg.js @@ -7,7 +7,7 @@ let r = new R(); // import_svg.js let import_svg = function(path, done) { - iron.Data.getBlob(path, function(b) { + Data.getBlob(path, function(b) { let buf_off = a._init(b.byteLength + 1); //// Allocate r.buffer let buf = new Uint8Array(r.buffer, buf_off, b.byteLength + 1); let bbuf = new Uint8Array(b); @@ -18,21 +18,21 @@ let import_svg = function(path, done) { let w = a._get_pixels_w(); let h = a._get_pixels_h(); let pixels = r.buffer.slice(a._get_pixels(), a._get_pixels() + w * h * 4); - let image = core.Image.fromBytes(pixels, w, h); + let image = Image.fromBytes(pixels, w, h); done(image); // a._destroy(); //// Destroys r.buffer - iron.Data.deleteBlob(path); + Data.deleteBlob(path); }); } -let plugin = new arm.Plugin(); -let formats = arm.Path.textureFormats; -let importers = arm.Path.textureImporters; +let plugin = new Plugin(); +let formats = Path.textureFormats; +let importers = Path.textureImporters; formats.push("svg"); -importers.h["svg"] = import_svg; +importers.set("svg", import_svg); plugin.delete = function() { formats.splice(formats.indexOf("svg"), 1); - importers.h["svg"] = null; + importers.delete("svg"); }; diff --git a/armorpaint/Assets/plugins/import_usdc.js b/armorpaint/Assets/plugins/import_usdc.js index 0aeaf09f..afcf7c1f 100644 --- a/armorpaint/Assets/plugins/import_usdc.js +++ b/armorpaint/Assets/plugins/import_usdc.js @@ -7,7 +7,7 @@ let r = new R(); // import_usdc.js let import_usdc = function(path, done) { - iron.Data.getBlob(path, function(b) { + Data.getBlob(path, function(b) { let buf_off = a._init(b.byteLength); //// Allocate r.buffer let buf = new Uint8Array(r.buffer, buf_off, b.byteLength); let bbuf = new Uint8Array(b); @@ -30,17 +30,17 @@ let import_usdc = function(path, done) { scale_tex: 1.0 }); // a._destroy(); //// Destroys r.buffer - iron.Data.deleteBlob(path); + Data.deleteBlob(path); }); } -let plugin = new arm.Plugin(); -let formats = arm.Path.meshFormats; -let importers = arm.Path.meshImporters; +let plugin = new Plugin(); +let formats = Path.meshFormats; +let importers = Path.meshImporters; formats.push("usdc"); -importers.h["usdc"] = import_usdc; +importers.set("usdc", import_usdc); plugin.delete = function() { formats.splice(formats.indexOf("usdc"), 1); - importers.h["usdc"] = null; + importers.delete("usdc"); }; diff --git a/armorpaint/Assets/plugins/texture_breakdown.js b/armorpaint/Assets/plugins/texture_breakdown.js index 9cbbf006..02699a52 100644 --- a/armorpaint/Assets/plugins/texture_breakdown.js +++ b/armorpaint/Assets/plugins/texture_breakdown.js @@ -1,7 +1,7 @@ -let plugin = new arm.Plugin(); -let h1 = new zui.Handle(); -let h2 = new zui.Handle(); +let plugin = new Plugin(); +let h1 = new Handle(); +let h2 = new Handle(); let slots = ["base", "occ", "rough", "nor"]; let breakdown = null; @@ -21,7 +21,7 @@ plugin.drawUI = function(ui) { let x = ui.inputX - ui._windowX; let w = ui._windowW / slots.length; let i = (x / w) | 0; - arm.UIMenu.draw(function(ui) { + UIMenu.draw(function(ui) { ui.text(slots[i], 2, ui.t.HIGHLIGHT_COL); if (ui.button("Delete", 0)) { slots.splice(i, 1); @@ -32,7 +32,7 @@ plugin.drawUI = function(ui) { ui.row([1 / 4, 1 / 4]); if (ui.button("Add")) { - arm.UIMenu.draw(function(ui) { + UIMenu.draw(function(ui) { ui.text("Channel", 2, ui.t.HIGHLIGHT_COL); if (ui.button("Base Color", 0)) { slots.push("base"); } if (ui.button("Occlusion", 0)) { slots.push("occ"); } @@ -43,12 +43,12 @@ plugin.drawUI = function(ui) { } if (ui.button("Export")) { - arm.UIFiles.show("png", true, false, function(path) { - arm.Base.notifyOnNextFrame(function() { - var f = arm.UIFiles.filename; + UIFiles.show("png", true, false, function(path) { + Base.notifyOnNextFrame(function() { + var f = UIFiles.filename; if (f === "") f = "untitled"; if (!f.endsWith(".png")) f += ".png"; - Krom.writePng(path + arm.Path.sep + f, breakdown.getPixels(), breakdown.get_width(), breakdown.get_height(), 2); + Krom.writePng(path + Path.sep + f, breakdown.getPixels(), breakdown.get_width(), breakdown.get_height(), 2); }); }); } @@ -64,9 +64,9 @@ function drawBreakdown(type) { g2.disableScissor(); if (h2.position === 0) { // Material - var lay = arm.Context.raw.layer; + var lay = Context.raw.layer; for (let i = 0; i < slots.length; ++i) { - g2.set_pipeline(arm.UIView2D.pipe); + g2.set_pipeline(UIView2D.pipe); let image = lay.texpaint; let channel = 0; if (slots[i] === "occ") { @@ -85,7 +85,7 @@ function drawBreakdown(type) { image = lay.texpaint_nor; channel = 5; } - breakdown.get_g4().setInt(arm.UIView2D.channelLocation, channel); + breakdown.get_g4().setInt(UIView2D.channelLocation, channel); var step_source = image.get_width() / slots.length; var step_dest = breakdown.get_width() / slots.length; g2.drawScaledSubImage(image, step_source * i, 0, step_source, image.get_height(), step_dest * i, 0, step_dest, breakdown.get_height()); diff --git a/armorpaint/Assets/plugins/viewport_celshade.js b/armorpaint/Assets/plugins/viewport_celshade.js index 36a13c52..1980bbf0 100644 --- a/armorpaint/Assets/plugins/viewport_celshade.js +++ b/armorpaint/Assets/plugins/viewport_celshade.js @@ -1,8 +1,8 @@ -let plugin = new arm.Plugin(); +let plugin = new Plugin(); // Register custom viewport shader -arm.ContextBase.setViewportShader(function(shader) { +ContextBase.setViewportShader(function(shader) { shader.add_uniform('vec3 lightDir', '_lightDirection'); shader.write(` float dotNL = max(dot(n, lightDir), 0.0); @@ -12,5 +12,5 @@ arm.ContextBase.setViewportShader(function(shader) { }); plugin.delete = function() { - arm.ContextBase.setViewportShader(null); + ContextBase.setViewportShader(null); } diff --git a/armorsculpt/Assets/plugins/hello_world.js b/armorsculpt/Assets/plugins/hello_world.js index 9ac06309..4e0bd5f6 100644 --- a/armorsculpt/Assets/plugins/hello_world.js +++ b/armorsculpt/Assets/plugins/hello_world.js @@ -1,13 +1,13 @@ -let plugin = new arm.Plugin(); +let plugin = new Plugin(); -let h1 = new zui.Handle(); -let h2 = new zui.Handle(); -let h3 = new zui.Handle(); -let h4 = new zui.Handle(); -let h5 = new zui.Handle(); -let h6 = new zui.Handle(); -let h7 = new zui.Handle(); +let h1 = new Handle(); +let h2 = new Handle(); +let h3 = new Handle(); +let h4 = new Handle(); +let h5 = new Handle(); +let h6 = new Handle(); +let h7 = new Handle(); plugin.drawUI = function(ui) { if (ui.panel(h1, "My Plugin")) { diff --git a/base/Assets/plugins/autosave.js b/base/Assets/plugins/autosave.js index 8b4d9b41..9315949d 100644 --- a/base/Assets/plugins/autosave.js +++ b/base/Assets/plugins/autosave.js @@ -1,8 +1,8 @@ -let plugin = new arm.Plugin(); +let plugin = new Plugin(); -let h1 = new zui.Handle(); -let h2 = new zui.Handle({value: 5}); +let h1 = new Handle(); +let h2 = new Handle({value: 5}); let timer = 0.0; plugin.drawUI = function(ui) { @@ -12,10 +12,10 @@ plugin.drawUI = function(ui) { } plugin.update = function() { - if (arm.Project.filepath == "") return; + if (Project.filepath == "") return; timer += 1 / 60; if (timer >= h2.value * 60) { timer = 0.0; - arm.Project.projectSave(); + Project.projectSave(); } } diff --git a/base/Assets/plugins/import_tiff.js b/base/Assets/plugins/import_tiff.js index 4b50348f..60c1d6b0 100644 --- a/base/Assets/plugins/import_tiff.js +++ b/base/Assets/plugins/import_tiff.js @@ -5,26 +5,26 @@ var UTIF={},pako=null;function log(){console.log(arguments)}!function(x,A){funct // Register as ArmorPaint plugin let import_tiff = function(path, done) { - iron.Data.getBlob(path, function(b) { + Data.getBlob(path, function(b) { let ifds = UTIF.decode(b); UTIF.decodeImage(b, ifds[0]); let rgba = UTIF.toRGBA8(ifds[0]); - let image = core.Image.fromBytes(rgba.buffer, ifds[0].width, ifds[0].height); + let image = Image.fromBytes(rgba.buffer, ifds[0].width, ifds[0].height); done(image); }); } -let plugin = new arm.Plugin(); -let formats = arm.Path.textureFormats; -let importers = arm.Path.textureImporters; +let plugin = new Plugin(); +let formats = Path.textureFormats; +let importers = Path.textureImporters; formats.push("tif"); formats.push("tiff"); -importers.h["tif"] = import_tiff; -importers.h["tiff"] = import_tiff; +importers.set("tif", import_tiff); +importers.set("tiff", import_tiff); plugin.delete = function() { formats.splice(formats.indexOf("tif"), 1); formats.splice(formats.indexOf("tiff"), 1); - importers.h["tif"] = null; - importers.h["tiff"] = null; + importers.delete("tif"); + importers.delete("tiff"); }; diff --git a/base/Assets/plugins/import_txt.js b/base/Assets/plugins/import_txt.js index 20cefb23..384fb432 100644 --- a/base/Assets/plugins/import_txt.js +++ b/base/Assets/plugins/import_txt.js @@ -1,11 +1,11 @@ let import_txt = function(path, done) { - iron.Data.getBlob(path, function(b) { + Data.getBlob(path, function(b) { var filename = path.split('\\').pop().split('/').pop(); try { - arm.UIBox.showMessage(filename, core.System.bufferToString(b), true); - arm.UIBox.clickToHide = false; - iron.Data.deleteBlob(path); + UIBox.showMessage(filename, System.bufferToString(b), true); + UIBox.clickToHide = false; + Data.deleteBlob(path); } catch(e) { console.error(e); @@ -13,13 +13,13 @@ let import_txt = function(path, done) { }); } -let plugin = new arm.Plugin(); -let formats = arm.Path.textureFormats; -let importers = arm.Path.textureImporters; +let plugin = new Plugin(); +let formats = Path.textureFormats; +let importers = Path.textureImporters; formats.push("txt"); -importers.h["txt"] = import_txt; +importers.set("txt", import_txt); plugin.delete = function() { formats.splice(formats.indexOf("txt"), 1); - importers.h["txt"] = null; + importers.delete("txt"); }; diff --git a/base/Sources/Base.ts b/base/Sources/Base.ts index 74b46f62..25622845 100644 --- a/base/Sources/Base.ts +++ b/base/Sources/Base.ts @@ -168,7 +168,6 @@ class Base { Base.defaultElementH = Base.uiMenu.t.ELEMENT_H; // Init plugins - Plugin.init(); if (Config.raw.plugins != null) { for (let plugin of Config.raw.plugins) { Plugin.start(plugin); diff --git a/base/Sources/Plugin.ts b/base/Sources/Plugin.ts index 69b81377..00eccb60 100644 --- a/base/Sources/Plugin.ts +++ b/base/Sources/Plugin.ts @@ -1,5 +1,4 @@ -// @:keep class Plugin { static plugins: Map = new Map(); @@ -18,22 +17,6 @@ class Plugin { Plugin.plugins.set(this.name, this); } - static init = () => { - // let api = arm; - ///if (is_paint || is_sculpt) - // api.ParserMaterial = ParserMaterial; - // api.NodesMaterial = NodesMaterial; - // api.UIView2D = UIView2D; - // api.UtilRender = UtilRender; - ///end - ///if is_paint - // api.UtilUV = UtilUV; - ///end - ///if is_lab - // api.BrushOutputNode = BrushOutputNode; - ///end - } - static start = (plugin: string) => { try { Data.getBlob("plugins/" + plugin, (blob: ArrayBuffer) => { @@ -56,82 +39,13 @@ class Plugin { } } -// @:keep -class Keep { - static keep = () => { - return [ - ArmPack.decode, - ArmPack.encode, - UIBox.showMessage - ]; - } -} - -///if is_lab -// @:keep -class KeepLab { - static keep = () => { - let a = Base.uiBox.panel; - return [a]; - } -} -///end - -// @:expose("core") class CoreBridge { - // static Image = Image; - // static System = System; static colorFromFloats = (r: f32, g: f32, b: f32, a: f32): Color => { return color_from_floats(r, g, b, a); } } -// @:expose("iron") -// class IronBridge { -// static App = App; -// static Scene = Scene; -// static RenderPath = RenderPath; -// static Time = Time; -// static Input = Input; -// static ArmPack = ArmPack; -// static BaseObject = BaseObject; -// static Data = Data; -// } - -// @:expose("zui") -// class ZuiBridge { -// static Handle = Handle; -// static Zui = Zui; -// } - -// @:expose("console") class ConsoleBridge { static log = Console.log; static error = Console.error; } - -// @:expose("arm") -// class ArmBridge { -// static Base = Base; -// static Config = Config; -// static Context = Context; -// static History = History; -// static Operator = Operator; -// static Plugin = Plugin; -// static Project = Project; -// static Res = Res; -// static Path = Path; -// static File = File; -// static NodesBrush = NodesBrush; -// static ParserLogic = ParserLogic; -// static UIBase = UIBase; -// static UINodes = UINodes; -// static UIFiles = UIFiles; -// static UIMenu = UIMenu; -// static UIBox = UIBox; -// static UtilMesh = UtilMesh; -// static Viewport = Viewport; -// ///if (krom_direct3d12 || krom_vulkan || krom_metal) -// static RenderPathRaytrace = RenderPathRaytrace; -// ///end -// }