From 625a70a540ac0f71ea3cad8f9b47fa337c580ece Mon Sep 17 00:00:00 2001 From: luboslenco Date: Thu, 7 Dec 2023 23:35:02 +0100 Subject: [PATCH] Prepare iron to c port --- armorlab/Sources/arm/logic/InpaintNode.hx | 16 +- armorlab/Sources/arm/logic/PhotoToPBRNode.hx | 59 +-- armorlab/Sources/arm/logic/RGBNode.hx | 12 +- armorlab/Sources/arm/logic/TextToPhotoNode.hx | 34 +- armorlab/Sources/arm/logic/TilingNode.hx | 14 +- armorlab/Sources/arm/logic/UpscaleNode.hx | 22 +- armorlab/Sources/arm/logic/VarianceNode.hx | 4 +- armorpaint/Assets/plugins/import_stl.js | 60 ++- armorpaint/Sources/arm/data/BrushSlot.hx | 7 +- armorpaint/Sources/arm/data/MaterialSlot.hx | 7 +- .../Sources/arm/render/RenderPathPaint.hx | 56 +-- armorpaint/Sources/arm/shader/MakeMaterial.hx | 2 +- armorpaint/Sources/arm/ui/TabLayers.hx | 4 +- armorsculpt/Sources/arm/io/ExportObj.hx | 45 +- base/Sources/Main.hx | 3 +- base/Sources/arm/App.hx | 86 ++-- base/Sources/arm/Args.hx | 4 +- base/Sources/arm/Camera.hx | 8 +- base/Sources/arm/Config.hx | 48 +- base/Sources/arm/Console.hx | 6 +- base/Sources/arm/History.hx | 2 +- base/Sources/arm/Plugin.hx | 10 +- base/Sources/arm/Project.hx | 18 +- base/Sources/arm/ProjectFormat.hx | 16 +- base/Sources/arm/data/ConstData.hx | 9 +- base/Sources/arm/format/BlendParser.hx | 82 +--- base/Sources/arm/format/ExrWriter.hx | 412 +++++++++--------- base/Sources/arm/format/FbxBinaryParser.hx | 33 +- base/Sources/arm/format/FbxParser.hx | 7 +- base/Sources/arm/io/ExportArm.hx | 44 +- base/Sources/arm/io/ExportGpl.hx | 16 +- base/Sources/arm/io/ExportObj.hx | 93 ++-- base/Sources/arm/io/ExportTexture.hx | 87 ++-- base/Sources/arm/io/ImportArm.hx | 39 +- base/Sources/arm/io/ImportBlendMaterial.hx | 3 +- base/Sources/arm/io/ImportBlendMesh.hx | 3 +- base/Sources/arm/io/ImportEnvmap.hx | 5 +- base/Sources/arm/io/ImportFbx.hx | 3 +- base/Sources/arm/io/ImportGpl.hx | 49 +-- base/Sources/arm/io/ImportObj.hx | 9 +- base/Sources/arm/logic/ColorNode.hx | 11 +- base/Sources/arm/logic/FloatNode.hx | 11 +- base/Sources/arm/logic/VectorNode.hx | 11 +- base/Sources/arm/render/RenderPathBase.hx | 2 +- base/Sources/arm/render/RenderPathDeferred.hx | 18 +- base/Sources/arm/render/RenderPathRaytrace.hx | 4 +- base/Sources/arm/ui/BoxExport.hx | 4 +- base/Sources/arm/ui/BoxPreferences.hx | 20 +- base/Sources/arm/ui/BoxProjects.hx | 12 +- base/Sources/arm/ui/TabFonts.hx | 2 +- base/Sources/arm/ui/TabScript.hx | 9 +- base/Sources/arm/ui/TabSwatches.hx | 14 +- base/Sources/arm/ui/TabTextures.hx | 6 +- base/Sources/arm/ui/UIBase.hx | 55 ++- base/Sources/arm/ui/UIBox.hx | 14 +- base/Sources/arm/ui/UIFiles.hx | 15 +- base/Sources/arm/ui/UIHeader.hx | 4 +- base/Sources/arm/ui/UIMenu.hx | 8 +- base/Sources/arm/ui/UIMenubar.hx | 4 +- base/Sources/arm/ui/UINodes.hx | 12 +- base/Sources/arm/ui/UIStatus.hx | 4 +- base/Sources/arm/ui/UIToolbar.hx | 6 +- base/Sources/arm/ui/UIView2D.hx | 18 +- base/Sources/arm/util/MeshUtil.hx | 3 +- base/Sources/arm/util/RenderUtil.hx | 2 +- base/Sources/arm/util/UVUtil.hx | 18 +- base/project.js | 8 + misc/pad/Sources/Main.hx | 22 +- 68 files changed, 871 insertions(+), 883 deletions(-) diff --git a/armorlab/Sources/arm/logic/InpaintNode.hx b/armorlab/Sources/arm/logic/InpaintNode.hx index e20625e0..639cbc2e 100644 --- a/armorlab/Sources/arm/logic/InpaintNode.hx +++ b/armorlab/Sources/arm/logic/InpaintNode.hx @@ -29,7 +29,7 @@ class InpaintNode extends LogicNode { } if (mask == null) { - mask = kha.Image.createRenderTarget(Config.getTextureResX(), Config.getTextureResY(), kha.Image.TextureFormat.L8); + mask = kha.Image.createRenderTarget(Config.getTextureResX(), Config.getTextureResY(), kha.Image.TextureFormat.R8); App.notifyOnNextFrame(function() { mask.g4.begin(); mask.g4.clear(kha.Color.fromFloats(1.0, 1.0, 1.0, 1.0)); @@ -47,7 +47,7 @@ class InpaintNode extends LogicNode { } public static function buttons(ui: zui.Zui, nodes: zui.Zui.Nodes, node: zui.Zui.TNode) { - auto = node.buttons[0].default_value; + auto = node.buttons[0].default_value == 0 ? false : true; if (!auto) { strength = ui.slider(zui.Zui.handle("inpaintnode_0", {value: strength}), tr("strength"), 0, 1, true); prompt = ui.textArea(zui.Zui.handle("inpaintnode_1"), true, tr("prompt"), true); @@ -96,10 +96,10 @@ class InpaintNode extends LogicNode { var w = arm.Config.getTextureResX(); var h = arm.Config.getTextureResY(); - var bytes_img = untyped image.getPixels().b.buffer; - var bytes_mask = mask != null ? untyped mask.getPixels().b.buffer : new js.lib.ArrayBuffer(w * h); - var bytes_out = haxe.io.Bytes.ofData(new js.lib.ArrayBuffer(w * h * 4)); - untyped Krom_texsynth.inpaint(w, h, untyped bytes_out.b.buffer, bytes_img, bytes_mask, tiling); + var bytes_img = image.getPixels(); + var bytes_mask = mask != null ? mask.getPixels() : new js.lib.ArrayBuffer(w * h); + var bytes_out = new js.lib.ArrayBuffer(w * h * 4); + untyped Krom_texsynth.inpaint(w, h, bytes_out, bytes_img, bytes_mask, tiling); result = kha.Image.fromBytes(bytes_out, w, h); done(result); @@ -112,7 +112,7 @@ class InpaintNode extends LogicNode { var u8 = new js.lib.Uint8Array(untyped bytes_img); var f32mask = new js.lib.Float32Array(4 * 64 * 64); - kha.Assets.loadBlobFromPath("data/models/sd_vae_encoder.quant.onnx", function(vae_encoder_blob: kha.Blob) { + iron.data.Data.getBlob("models/sd_vae_encoder.quant.onnx", function(vae_encoder_blob: js.lib.ArrayBuffer) { // for (x in 0...Std.int(image.width / 512)) { // for (y in 0...Std.int(image.height / 512)) { var x = 0; @@ -147,7 +147,7 @@ class InpaintNode extends LogicNode { f32[i + 512 * 512 * 2] = (u8[i * 4 + 2] / 255.0) * 2.0 - 1.0; } - var latents_buf = Krom.mlInference(untyped vae_encoder_blob.toBytes().b.buffer, [f32.buffer], [[1, 3, 512, 512]], [1, 4, 64, 64], Config.raw.gpu_inference); + var latents_buf = Krom.mlInference(untyped vae_encoder_blob, [f32.buffer], [[1, 3, 512, 512]], [1, 4, 64, 64], Config.raw.gpu_inference); var latents = new js.lib.Float32Array(latents_buf); for (i in 0...latents.length) { latents[i] = 0.18215 * latents[i]; diff --git a/armorlab/Sources/arm/logic/PhotoToPBRNode.hx b/armorlab/Sources/arm/logic/PhotoToPBRNode.hx index 044088bf..102444f6 100644 --- a/armorlab/Sources/arm/logic/PhotoToPBRNode.hx +++ b/armorlab/Sources/arm/logic/PhotoToPBRNode.hx @@ -65,8 +65,8 @@ class PhotoToPBRNode extends LogicNode { temp.g2.drawScaledImage(source, borderW - x * tileW, borderW - y * tileW, Config.getTextureResX(), Config.getTextureResY()); temp.g2.end(); - var bytes_img = untyped temp.getPixels().b.buffer; - var u8 = new js.lib.Uint8Array(untyped bytes_img); + var bytes_img = temp.getPixels(); + var u8 = new js.lib.Uint8Array(bytes_img); var f32 = new js.lib.Float32Array(3 * tileWithBorderW * tileWithBorderW); for (i in 0...(tileWithBorderW * tileWithBorderW)) { f32[i ] = (u8[i * 4 ] / 255 - 0.5) / 0.5; @@ -74,19 +74,19 @@ class PhotoToPBRNode extends LogicNode { f32[i + tileWithBorderW * tileWithBorderW * 2] = (u8[i * 4 + 2] / 255 - 0.5) / 0.5; } - kha.Assets.loadBlobFromPath("data/models/photo_to_" + modelNames[from] + ".quant.onnx", function(model_blob: kha.Blob) { - var buf = Krom.mlInference(untyped model_blob.toBytes().b.buffer, [f32.buffer], null, null, Config.raw.gpu_inference); + iron.data.Data.getBlob("models/photo_to_" + modelNames[from] + ".quant.onnx", function(model_blob: js.lib.ArrayBuffer) { + var buf = Krom.mlInference(untyped model_blob, [f32.buffer], null, null, Config.raw.gpu_inference); var ar = new js.lib.Float32Array(buf); - var bytes = haxe.io.Bytes.alloc(4 * tileW * tileW); + var u8 = new js.lib.Uint8Array(4 * tileW * tileW); var offsetG = (from == ChannelBaseColor || from == ChannelNormalMap) ? tileWithBorderW * tileWithBorderW : 0; var offsetB = (from == ChannelBaseColor || from == ChannelNormalMap) ? tileWithBorderW * tileWithBorderW * 2 : 0; for (i in 0...(tileW * tileW)) { var x = borderW + i % tileW; var y = borderW + Std.int(i / tileW); - bytes.set(i * 4 , Std.int((ar[y * tileWithBorderW + x ] * 0.5 + 0.5) * 255)); - bytes.set(i * 4 + 1, Std.int((ar[y * tileWithBorderW + x + offsetG] * 0.5 + 0.5) * 255)); - bytes.set(i * 4 + 2, Std.int((ar[y * tileWithBorderW + x + offsetB] * 0.5 + 0.5) * 255)); - bytes.set(i * 4 + 3, 255); + u8[i * 4 ] = Std.int((ar[y * tileWithBorderW + x ] * 0.5 + 0.5) * 255); + u8[i * 4 + 1] = Std.int((ar[y * tileWithBorderW + x + offsetG] * 0.5 + 0.5) * 255); + u8[i * 4 + 2] = Std.int((ar[y * tileWithBorderW + x + offsetB] * 0.5 + 0.5) * 255); + u8[i * 4 + 3] = 255; } tileFloats.push(ar); @@ -97,9 +97,9 @@ class PhotoToPBRNode extends LogicNode { for (yy in 0...tileW) { for (xx in 0...borderW) { var i = yy * tileW + xx; - var a = bytes.get(i * 4); - var b = bytes.get(i * 4 + 1); - var c = bytes.get(i * 4 + 2); + var a = u8[i * 4]; + var b = u8[i * 4 + 1]; + var c = u8[i * 4 + 2]; var aa = Std.int((ar[(borderW + yy) * tileWithBorderW + borderW + tileW + xx ] * 0.5 + 0.5) * 255); var bb = Std.int((ar[(borderW + yy) * tileWithBorderW + borderW + tileW + xx + offsetG] * 0.5 + 0.5) * 255); @@ -111,9 +111,9 @@ class PhotoToPBRNode extends LogicNode { b = Std.int(b * f + bb * invf); c = Std.int(c * f + cc * invf); - bytes.set(i * 4 , a); - bytes.set(i * 4 + 1, b); - bytes.set(i * 4 + 2, c); + u8[i * 4 ] = a; + u8[i * 4 + 1] = b; + u8[i * 4 + 2] = c; } } } @@ -122,9 +122,9 @@ class PhotoToPBRNode extends LogicNode { for (xx in 0...tileW) { for (yy in 0...borderW) { var i = yy * tileW + xx; - var a = bytes.get(i * 4); - var b = bytes.get(i * 4 + 1); - var c = bytes.get(i * 4 + 2); + var a = u8[i * 4]; + var b = u8[i * 4 + 1]; + var c = u8[i * 4 + 2]; var aa = Std.int((ar[(borderW + tileW + yy) * tileWithBorderW + borderW + xx ] * 0.5 + 0.5) * 255); var bb = Std.int((ar[(borderW + tileW + yy) * tileWithBorderW + borderW + xx + offsetG] * 0.5 + 0.5) * 255); @@ -136,19 +136,19 @@ class PhotoToPBRNode extends LogicNode { b = Std.int(b * f + bb * invf); c = Std.int(c * f + cc * invf); - bytes.set(i * 4 , a); - bytes.set(i * 4 + 1, b); - bytes.set(i * 4 + 2, c); + u8[i * 4 ] = a; + u8[i * 4 + 1] = b; + u8[i * 4 + 2] = c; } } } } #if (krom_metal || krom_vulkan) - if (from == ChannelBaseColor) bgraSwap(bytes); + if (from == ChannelBaseColor) bgraSwap(u8.buffer); #end - var temp2 = kha.Image.fromBytes(bytes, tileW, tileW); + var temp2 = kha.Image.fromBytes(u8.buffer, tileW, tileW); images[from].g2.begin(false); images[from].g2.drawImage(temp2, x * tileW, y * tileW); images[from].g2.end(); @@ -164,13 +164,14 @@ class PhotoToPBRNode extends LogicNode { } #if (krom_metal || krom_vulkan) - static function bgraSwap(bytes: haxe.io.Bytes) { - for (i in 0...Std.int(bytes.length / 4)) { - var r = bytes.get(i * 4); - bytes.set(i * 4, bytes.get(i * 4 + 2)); - bytes.set(i * 4 + 2, r); + static function bgraSwap(buffer: js.lib.ArrayBuffer) { + var u8 = new js.lib.Uint8Array(buffer); + for (i in 0...Std.int(buffer.byteLength / 4)) { + var r = u8[i * 4]; + u8[i * 4] = u8[i * 4 + 2]; + u8[i * 4 + 2] = r; } - return bytes; + return buffer; } #end diff --git a/armorlab/Sources/arm/logic/RGBNode.hx b/armorlab/Sources/arm/logic/RGBNode.hx index 7f3e58ce..0624e3ed 100644 --- a/armorlab/Sources/arm/logic/RGBNode.hx +++ b/armorlab/Sources/arm/logic/RGBNode.hx @@ -22,14 +22,14 @@ class RGBNode extends LogicNode { }); } - var b = haxe.io.Bytes.alloc(16); + var f32 = new js.lib.Float32Array(4); var raw = LogicParser.getRawNode(this); var default_value = raw.outputs[0].default_value; - b.setFloat(0, default_value[0]); - b.setFloat(4, default_value[1]); - b.setFloat(8, default_value[2]); - b.setFloat(12, default_value[3]); - image = kha.Image.fromBytes(b, 1, 1, kha.Image.TextureFormat.RGBA128); + f32[0] = default_value[0]; + f32[1] = default_value[1]; + f32[2] = default_value[2]; + f32[3] = default_value[3]; + image = kha.Image.fromBytes(f32.buffer, 1, 1, kha.Image.TextureFormat.RGBA128); done(image); } diff --git a/armorlab/Sources/arm/logic/TextToPhotoNode.hx b/armorlab/Sources/arm/logic/TextToPhotoNode.hx index d89b34ee..649a5320 100644 --- a/armorlab/Sources/arm/logic/TextToPhotoNode.hx +++ b/armorlab/Sources/arm/logic/TextToPhotoNode.hx @@ -11,9 +11,9 @@ class TextToPhotoNode extends LogicNode { static var prompt = ""; static var image: kha.Image = null; static var tiling = false; - static var text_encoder_blob : kha.Blob; - static var unet_blob : kha.Blob; - static var vae_decoder_blob : kha.Blob; + static var text_encoder_blob : js.lib.ArrayBuffer; + static var unet_blob : js.lib.ArrayBuffer; + static var vae_decoder_blob : js.lib.ArrayBuffer; public function new(tree: LogicTree) { super(tree); @@ -31,15 +31,15 @@ class TextToPhotoNode extends LogicNode { } public static function buttons(ui: zui.Zui, nodes: zui.Zui.Nodes, node: zui.Zui.TNode) { - tiling = node.buttons[0].default_value; + tiling = node.buttons[0].default_value == 0 ? false : true; prompt = ui.textArea(zui.Zui.handle("texttophotonode_0"), true, tr("prompt"), true); node.buttons[1].height = prompt.split("\n").length; } public static function stableDiffusion(prompt: String, done: kha.Image->Void, inpaintLatents: js.lib.Float32Array = null, offset = 0, upscale = true, mask: js.lib.Float32Array = null, latents_orig: js.lib.Float32Array = null) { - kha.Assets.loadBlobFromPath("data/models/sd_text_encoder.quant.onnx", function(_text_encoder_blob: kha.Blob) { - kha.Assets.loadBlobFromPath("data/models/sd_unet.quant.onnx", function(_unet_blob: kha.Blob) { - kha.Assets.loadBlobFromPath("data/models/sd_vae_decoder.quant.onnx", function(_vae_decoder_blob: kha.Blob) { + iron.data.Data.getBlob("models/sd_text_encoder.quant.onnx", function(_text_encoder_blob: js.lib.ArrayBuffer) { + iron.data.Data.getBlob("models/sd_unet.quant.onnx", function(_unet_blob: js.lib.ArrayBuffer) { + iron.data.Data.getBlob("models/sd_vae_decoder.quant.onnx", function(_vae_decoder_blob: js.lib.ArrayBuffer) { text_encoder_blob = _text_encoder_blob; unet_blob = _unet_blob; vae_decoder_blob = _vae_decoder_blob; @@ -65,11 +65,11 @@ class TextToPhotoNode extends LogicNode { } var f32 = new js.lib.Int32Array(text_input_ids); - var text_embeddings_buf = Krom.mlInference(untyped text_encoder_blob.toBytes().b.buffer, [f32.buffer], [[1, 77]], [1, 77, 768], Config.raw.gpu_inference); + var text_embeddings_buf = Krom.mlInference(text_encoder_blob, [f32.buffer], [[1, 77]], [1, 77, 768], Config.raw.gpu_inference); var text_embeddings = new js.lib.Float32Array(text_embeddings_buf); var f32 = new js.lib.Int32Array(uncond_input_ids); - var uncond_embeddings_buf = Krom.mlInference(untyped text_encoder_blob.toBytes().b.buffer, [f32.buffer], [[1, 77]], [1, 77, 768], Config.raw.gpu_inference); + var uncond_embeddings_buf = Krom.mlInference(text_encoder_blob, [f32.buffer], [[1, 77]], [1, 77, 768], Config.raw.gpu_inference); var uncond_embeddings = new js.lib.Float32Array(uncond_embeddings_buf); var f32 = new js.lib.Float32Array(uncond_embeddings.length + text_embeddings.length); @@ -111,7 +111,7 @@ class TextToPhotoNode extends LogicNode { var t32 = new js.lib.Int32Array(2); t32[0] = timestep; - var noise_pred_buf = Krom.mlInference(untyped unet_blob.toBytes().b.buffer, [latent_model_input.buffer, t32.buffer, text_embeddings.buffer], [[2, 4, 64, 64], [1], [2, 77, 768]], [2, 4, 64, 64], Config.raw.gpu_inference); + var noise_pred_buf = Krom.mlInference(unet_blob, [latent_model_input.buffer, t32.buffer, text_embeddings.buffer], [[2, 4, 64, 64], [1], [2, 77, 768]], [2, 4, 64, 64], Config.raw.gpu_inference); var noise_pred = new js.lib.Float32Array(noise_pred_buf); for (i in 0...noise_pred_uncond.length) noise_pred_uncond[i] = noise_pred[i]; @@ -209,7 +209,7 @@ class TextToPhotoNode extends LogicNode { latents[i] = 1.0 / 0.18215 * latents[i]; } - var pyimage_buf = Krom.mlInference(untyped vae_decoder_blob.toBytes().b.buffer, [latents.buffer], [[1, 4, 64, 64]], [1, 3, 512, 512], Config.raw.gpu_inference); + var pyimage_buf = Krom.mlInference(vae_decoder_blob, [latents.buffer], [[1, 4, 64, 64]], [1, 3, 512, 512], Config.raw.gpu_inference); var pyimage = new js.lib.Float32Array(pyimage_buf); for (i in 0...pyimage.length) { @@ -218,14 +218,14 @@ class TextToPhotoNode extends LogicNode { else if (pyimage[i] > 1) pyimage[i] = 1; } - var bytes = haxe.io.Bytes.alloc(4 * 512 * 512); + var u8 = new js.lib.Uint8Array(4 * 512 * 512); for (i in 0...(512 * 512)) { - bytes.set(i * 4 , Std.int(pyimage[i ] * 255)); - bytes.set(i * 4 + 1, Std.int(pyimage[i + 512 * 512 ] * 255)); - bytes.set(i * 4 + 2, Std.int(pyimage[i + 512 * 512 * 2] * 255)); - bytes.set(i * 4 + 3, 255); + u8[i * 4 ] = Std.int(pyimage[i ] * 255); + u8[i * 4 + 1] = Std.int(pyimage[i + 512 * 512 ] * 255); + u8[i * 4 + 2] = Std.int(pyimage[i + 512 * 512 * 2] * 255); + u8[i * 4 + 3] = 255; } - var image = kha.Image.fromBytes(bytes, 512, 512); + var image = kha.Image.fromBytes(u8.buffer, 512, 512); if (tiling) { @:privateAccess TilingNode.prompt = prompt; diff --git a/armorlab/Sources/arm/logic/TilingNode.hx b/armorlab/Sources/arm/logic/TilingNode.hx index 7cb8f4f5..3603717c 100644 --- a/armorlab/Sources/arm/logic/TilingNode.hx +++ b/armorlab/Sources/arm/logic/TilingNode.hx @@ -27,7 +27,7 @@ class TilingNode extends LogicNode { } public static function buttons(ui: zui.Zui, nodes: zui.Zui.Nodes, node: zui.Zui.TNode) { - auto = node.buttons[0].default_value; + auto = node.buttons[0].default_value == 0 ? false : true; if (!auto) { strength = ui.slider(zui.Zui.handle("tilingnode_0", {value: strength}), tr("strength"), 0, 1, true); prompt = ui.textArea(zui.Zui.handle("tilingnode_1"), true, tr("prompt"), true); @@ -67,25 +67,25 @@ class TilingNode extends LogicNode { tile.g2.drawScaledImage(image, 256, 256, 512, 512); tile.g2.end(); - var bytes = haxe.io.Bytes.alloc(512 * 512); + var u8 = new js.lib.Uint8Array(512 * 512); for (i in 0...512 * 512) { var x = i % 512; var y = Std.int(i / 512); var l = y < 256 ? y : (511 - y); - bytes.set(i, (x > 256 - l && x < 256 + l) ? 0 : 255); + u8[i] = (x > 256 - l && x < 256 + l) ? 0 : 255; } - // for (i in 0...512 * 512) bytes.set(i, 255); + // for (i in 0...512 * 512) u8[i] = 255; // for (x in (256 - 32)...(256 + 32)) { // for (y in 0...512) { - // bytes.set(y * 512 + x, 0); + // u8[y * 512 + x] = 0; // } // } // for (x in 0...512) { // for (y in (256 - 32)...(256 + 32)) { - // bytes.set(y * 512 + x, 0); + // u8[y * 512 + x] = 0; // } // } - var mask = kha.Image.fromBytes(bytes, 512, 512, kha.Image.TextureFormat.L8); + var mask = kha.Image.fromBytes(u8.buffer, 512, 512, kha.Image.TextureFormat.R8); @:privateAccess InpaintNode.prompt = prompt; @:privateAccess InpaintNode.strength = strength; diff --git a/armorlab/Sources/arm/logic/UpscaleNode.hx b/armorlab/Sources/arm/logic/UpscaleNode.hx index 828603ca..c3215eb0 100644 --- a/armorlab/Sources/arm/logic/UpscaleNode.hx +++ b/armorlab/Sources/arm/logic/UpscaleNode.hx @@ -10,7 +10,7 @@ class UpscaleNode extends LogicNode { static var temp: kha.Image = null; static var image: kha.Image = null; - static var esrgan_blob: kha.Blob; + static var esrgan_blob: js.lib.ArrayBuffer; public function new(tree: LogicTree) { super(tree); @@ -38,7 +38,7 @@ class UpscaleNode extends LogicNode { } public static function loadBlob(done: Void->Void) { - kha.Assets.loadBlobFromPath("data/models/esrgan.quant.onnx", function(_esrgan_blob: kha.Blob) { + iron.data.Data.getBlob("models/esrgan.quant.onnx", function(_esrgan_blob: js.lib.ArrayBuffer) { esrgan_blob = _esrgan_blob; done(); }); @@ -62,8 +62,8 @@ class UpscaleNode extends LogicNode { temp.g2.drawScaledImage(source, 0, 0, size1w, size1h); temp.g2.end(); - var bytes_img = untyped temp.getPixels().b.buffer; - var u8 = new js.lib.Uint8Array(untyped bytes_img); + var bytes_img = temp.getPixels(); + var u8 = new js.lib.Uint8Array(bytes_img); var f32 = new js.lib.Float32Array(3 * size1w * size1h); for (i in 0...(size1w * size1h)) { f32[i ] = (u8[i * 4 ] / 255); @@ -71,22 +71,22 @@ class UpscaleNode extends LogicNode { f32[i + size1w * size1w * 2] = (u8[i * 4 + 2] / 255); } - var esrgan2x_buf = Krom.mlInference(untyped esrgan_blob.toBytes().b.buffer, [f32.buffer], [[1, 3, size1w, size1h]], [1, 3, size2w, size2h], Config.raw.gpu_inference); + var esrgan2x_buf = Krom.mlInference(esrgan_blob, [f32.buffer], [[1, 3, size1w, size1h]], [1, 3, size2w, size2h], Config.raw.gpu_inference); var esrgan2x = new js.lib.Float32Array(esrgan2x_buf); for (i in 0...esrgan2x.length) { if (esrgan2x[i] < 0) esrgan2x[i] = 0; else if (esrgan2x[i] > 1) esrgan2x[i] = 1; } - var bytes = haxe.io.Bytes.alloc(4 * size2w * size2h); + var u8 = new js.lib.Uint8Array(4 * size2w * size2h); for (i in 0...(size2w * size2h)) { - bytes.set(i * 4 , Std.int(esrgan2x[i ] * 255)); - bytes.set(i * 4 + 1, Std.int(esrgan2x[i + size2w * size2w ] * 255)); - bytes.set(i * 4 + 2, Std.int(esrgan2x[i + size2w * size2w * 2] * 255)); - bytes.set(i * 4 + 3, 255); + u8[i * 4 ] = Std.int(esrgan2x[i ] * 255); + u8[i * 4 + 1] = Std.int(esrgan2x[i + size2w * size2w ] * 255); + u8[i * 4 + 2] = Std.int(esrgan2x[i + size2w * size2w * 2] * 255); + u8[i * 4 + 3] = 255; } - result = kha.Image.fromBytes(bytes, size2w, size2h); + result = kha.Image.fromBytes(u8.buffer, size2w, size2h); return result; } diff --git a/armorlab/Sources/arm/logic/VarianceNode.hx b/armorlab/Sources/arm/logic/VarianceNode.hx index 5e34b012..3a88fb3c 100644 --- a/armorlab/Sources/arm/logic/VarianceNode.hx +++ b/armorlab/Sources/arm/logic/VarianceNode.hx @@ -51,8 +51,8 @@ class VarianceNode extends LogicNode { Console.progress(tr("Processing") + " - " + tr("Variance")); App.notifyOnNextFrame(function() { - kha.Assets.loadBlobFromPath("data/models/sd_vae_encoder.quant.onnx", function(vae_encoder_blob: kha.Blob) { - var latents_buf = Krom.mlInference(untyped vae_encoder_blob.toBytes().b.buffer, [f32.buffer], [[1, 3, 512, 512]], [1, 4, 64, 64], Config.raw.gpu_inference); + iron.data.Data.getBlob("models/sd_vae_encoder.quant.onnx", function(vae_encoder_blob: js.lib.ArrayBuffer) { + var latents_buf = Krom.mlInference(vae_encoder_blob, [f32.buffer], [[1, 3, 512, 512]], [1, 4, 64, 64], Config.raw.gpu_inference); var latents = new js.lib.Float32Array(latents_buf); for (i in 0...latents.length) { latents[i] = 0.18215 * latents[i]; diff --git a/armorpaint/Assets/plugins/import_stl.js b/armorpaint/Assets/plugins/import_stl.js index 6cf8e9a6..896d3810 100644 --- a/armorpaint/Assets/plugins/import_stl.js +++ b/armorpaint/Assets/plugins/import_stl.js @@ -1,30 +1,52 @@ +let pos = 0; + +let read_i16 = function(view) { + let i = view.getInt16(pos, true); + pos += 2; + return i; +} + +let read_i32 = function(view) { + let i = view.getInt32(pos, true); + pos += 4; + return i; +} + +let read_f32 = function(view) { + let f = view.getFloat32(pos, true); + pos += 4; + return f; +} + let import_stl = function(path, done) { iron.Data.getBlob(path, function(b) { - let input = new core.BytesInput(b.bytes); - let header = input.read(80); - if (header.getString(0, 5) == "solid") { - return; // ascii not supported - } - let faces = input.readInt32(); + let view = new DataView(b); + pos = 0; + // let header = input.read(80); + pos += 80; + // if (header.getString(0, 5) == "solid") { + // return; // ascii not supported + // } + let faces = read_i32(view); let posTemp = new Float32Array(faces * 9); let norTemp = new Float32Array(faces * 3); for (let i = 0; i < faces; ++i) { let i3 = i * 3; - norTemp[i3 ] = input.readFloat(); - norTemp[i3 + 1] = input.readFloat(); - norTemp[i3 + 2] = input.readFloat(); + norTemp[i3 ] = read_f32(view); + norTemp[i3 + 1] = read_f32(view); + norTemp[i3 + 2] = read_f32(view); let i9 = i * 9; - posTemp[i9 ] = input.readFloat(); - posTemp[i9 + 1] = input.readFloat(); - posTemp[i9 + 2] = input.readFloat(); - posTemp[i9 + 3] = input.readFloat(); - posTemp[i9 + 4] = input.readFloat(); - posTemp[i9 + 5] = input.readFloat(); - posTemp[i9 + 6] = input.readFloat(); - posTemp[i9 + 7] = input.readFloat(); - posTemp[i9 + 8] = input.readFloat(); - input.readInt16(); // attribute + posTemp[i9 ] = read_f32(view); + posTemp[i9 + 1] = read_f32(view); + posTemp[i9 + 2] = read_f32(view); + posTemp[i9 + 3] = read_f32(view); + posTemp[i9 + 4] = read_f32(view); + posTemp[i9 + 5] = read_f32(view); + posTemp[i9 + 6] = read_f32(view); + posTemp[i9 + 7] = read_f32(view); + posTemp[i9 + 8] = read_f32(view); + read_i16(view); // attribute } let scalePos = 0.0; diff --git a/armorpaint/Sources/arm/data/BrushSlot.hx b/armorpaint/Sources/arm/data/BrushSlot.hx index 73183528..cea41144 100644 --- a/armorpaint/Sources/arm/data/BrushSlot.hx +++ b/armorpaint/Sources/arm/data/BrushSlot.hx @@ -1,7 +1,6 @@ package arm.data; import kha.Image; -import kha.Blob; import zui.Zui.Nodes; import zui.Zui.TNodeCanvas; import iron.data.Data; @@ -13,18 +12,18 @@ class BrushSlot { public var imageIcon: Image = null; // 50px public var previewReady = false; public var id = 0; - static var defaultCanvas: Blob = null; + static var defaultCanvas: js.lib.ArrayBuffer = null; public function new(c: TNodeCanvas = null) { for (brush in Project.brushes) if (brush.id >= id) id = brush.id + 1; if (c == null) { if (defaultCanvas == null) { // Synchronous - Data.getBlob("default_brush.arm", function(b: Blob) { + Data.getBlob("default_brush.arm", function(b: js.lib.ArrayBuffer) { defaultCanvas = b; }); } - canvas = iron.system.ArmPack.decode(defaultCanvas.toBytes()); + canvas = iron.system.ArmPack.decode(defaultCanvas); canvas.name = "Brush " + (id + 1); } else { diff --git a/armorpaint/Sources/arm/data/MaterialSlot.hx b/armorpaint/Sources/arm/data/MaterialSlot.hx index 4593309a..11d45498 100644 --- a/armorpaint/Sources/arm/data/MaterialSlot.hx +++ b/armorpaint/Sources/arm/data/MaterialSlot.hx @@ -1,7 +1,6 @@ package arm.data; import kha.Image; -import kha.Blob; import zui.Zui.Nodes; import zui.Zui.TNodeCanvas; import iron.data.MaterialData; @@ -16,7 +15,7 @@ class MaterialSlot { public var previewReady = false; public var data: MaterialData; public var id = 0; - static var defaultCanvas: Blob = null; + static var defaultCanvas: js.lib.ArrayBuffer = null; public var paintBase = true; public var paintOpac = true; @@ -39,11 +38,11 @@ class MaterialSlot { if (c == null) { if (defaultCanvas == null) { // Synchronous - Data.getBlob("default_material.arm", function(b: Blob) { + Data.getBlob("default_material.arm", function(b: js.lib.ArrayBuffer) { defaultCanvas = b; }); } - canvas = iron.system.ArmPack.decode(defaultCanvas.toBytes()); + canvas = iron.system.ArmPack.decode(defaultCanvas); canvas.name = "Material " + (id + 1); } else { diff --git a/armorpaint/Sources/arm/render/RenderPathPaint.hx b/armorpaint/Sources/arm/render/RenderPathPaint.hx index 4d21c583..de6d3dbc 100644 --- a/armorpaint/Sources/arm/render/RenderPathPaint.hx +++ b/armorpaint/Sources/arm/render/RenderPathPaint.hx @@ -172,16 +172,16 @@ class RenderPathPaint { path.drawMeshes("paint"); var texpaint_posnortex_picker0 = path.renderTargets.get("texpaint_posnortex_picker0").image; var texpaint_posnortex_picker1 = path.renderTargets.get("texpaint_posnortex_picker1").image; - var a = texpaint_posnortex_picker0.getPixels(); - var b = texpaint_posnortex_picker1.getPixels(); - Context.raw.posXPicked = a.getFloat(0); - Context.raw.posYPicked = a.getFloat(4); - Context.raw.posZPicked = a.getFloat(8); - Context.raw.uvxPicked = a.getFloat(12); - Context.raw.norXPicked = b.getFloat(0); - Context.raw.norYPicked = b.getFloat(4); - Context.raw.norZPicked = b.getFloat(8); - Context.raw.uvyPicked = b.getFloat(12); + var a = new js.lib.DataView(texpaint_posnortex_picker0.getPixels()); + var b = new js.lib.DataView(texpaint_posnortex_picker1.getPixels()); + Context.raw.posXPicked = a.getFloat32(0, true); + Context.raw.posYPicked = a.getFloat32(4, true); + Context.raw.posZPicked = a.getFloat32(8, true); + Context.raw.uvxPicked = a.getFloat32(12, true); + Context.raw.norXPicked = b.getFloat32(0, true); + Context.raw.norYPicked = b.getFloat32(4, true); + Context.raw.norZPicked = b.getFloat32(8, true); + Context.raw.uvyPicked = b.getFloat32(12, true); } else { path.setTarget("texpaint_picker", ["texpaint_nor_picker", "texpaint_pack_picker", "texpaint_uv_picker"]); @@ -201,10 +201,10 @@ class RenderPathPaint { var texpaint_nor_picker = path.renderTargets.get("texpaint_nor_picker").image; var texpaint_pack_picker = path.renderTargets.get("texpaint_pack_picker").image; var texpaint_uv_picker = path.renderTargets.get("texpaint_uv_picker").image; - var a = texpaint_picker.getPixels(); - var b = texpaint_nor_picker.getPixels(); - var c = texpaint_pack_picker.getPixels(); - var d = texpaint_uv_picker.getPixels(); + var a = new js.lib.DataView(texpaint_picker.getPixels()); + var b = new js.lib.DataView(texpaint_nor_picker.getPixels()); + var c = new js.lib.DataView(texpaint_pack_picker.getPixels()); + var d = new js.lib.DataView(texpaint_uv_picker.getPixels()); if (Context.raw.colorPickerCallback != null) { Context.raw.colorPickerCallback(Context.raw.pickedColor); @@ -221,23 +221,23 @@ class RenderPathPaint { var i2 = 2; #end var i3 = 3; - Context.raw.pickedColor.base.Rb = a.get(i0); - Context.raw.pickedColor.base.Gb = a.get(i1); - Context.raw.pickedColor.base.Bb = a.get(i2); - Context.raw.pickedColor.normal.Rb = b.get(i0); - Context.raw.pickedColor.normal.Gb = b.get(i1); - Context.raw.pickedColor.normal.Bb = b.get(i2); - Context.raw.pickedColor.occlusion = c.get(i0) / 255; - Context.raw.pickedColor.roughness = c.get(i1) / 255; - Context.raw.pickedColor.metallic = c.get(i2) / 255; - Context.raw.pickedColor.height = c.get(i3) / 255; - Context.raw.pickedColor.opacity = a.get(i3) / 255; - Context.raw.uvxPicked = d.get(i0) / 255; - Context.raw.uvyPicked = d.get(i1) / 255; + Context.raw.pickedColor.base.Rb = a.getUint8(i0); + Context.raw.pickedColor.base.Gb = a.getUint8(i1); + Context.raw.pickedColor.base.Bb = a.getUint8(i2); + Context.raw.pickedColor.normal.Rb = b.getUint8(i0); + Context.raw.pickedColor.normal.Gb = b.getUint8(i1); + Context.raw.pickedColor.normal.Bb = b.getUint8(i2); + Context.raw.pickedColor.occlusion = c.getUint8(i0) / 255; + Context.raw.pickedColor.roughness = c.getUint8(i1) / 255; + Context.raw.pickedColor.metallic = c.getUint8(i2) / 255; + Context.raw.pickedColor.height = c.getUint8(i3) / 255; + Context.raw.pickedColor.opacity = a.getUint8(i3) / 255; + Context.raw.uvxPicked = d.getUint8(i0) / 255; + Context.raw.uvyPicked = d.getUint8(i1) / 255; // Pick material if (Context.raw.pickerSelectMaterial && Context.raw.colorPickerCallback == null) { // matid % 3 == 0 - normal, 1 - emission, 2 - subsurface - var matid = Std.int((b.get(3) - (b.get(3) % 3)) / 3); + var matid = Std.int((b.getUint8(3) - (b.getUint8(3) % 3)) / 3); for (m in Project.materials) { if (m.id == matid) { Context.setMaterial(m); diff --git a/armorpaint/Sources/arm/shader/MakeMaterial.hx b/armorpaint/Sources/arm/shader/MakeMaterial.hx index da6224f4..0b4f92fd 100644 --- a/armorpaint/Sources/arm/shader/MakeMaterial.hx +++ b/armorpaint/Sources/arm/shader/MakeMaterial.hx @@ -311,7 +311,7 @@ class MakeMaterial { var resY = Std.int(Config.getTextureResY()); if (image == null || image.width != resX || image.height != resY) { if (image != null) image.unload(); - image = kha.Image.createRenderTarget(resX, resY, kha.Image.TextureFormat.L8); + image = kha.Image.createRenderTarget(resX, resY, kha.Image.TextureFormat.R8); Context.raw.nodePreviews.set(id, image); } diff --git a/armorpaint/Sources/arm/ui/TabLayers.hx b/armorpaint/Sources/arm/ui/TabLayers.hx index d006c673..63d73602 100644 --- a/armorpaint/Sources/arm/ui/TabLayers.hx +++ b/armorpaint/Sources/arm/ui/TabLayers.hx @@ -633,7 +633,7 @@ class TabLayers { if (l.fill_layer == null && l.isMask()) { ui.g.pipeline = UIView2D.pipe; #if krom_opengl - Krom.setPipeline(UIView2D.pipe.pipeline); + Krom.setPipeline(UIView2D.pipe.pipeline_); #end Krom.setInt(UIView2D.channelLocation, 1); } @@ -727,7 +727,7 @@ class TabLayers { var f = UIFiles.filename; if (f == "") f = tr("untitled"); if (!f.endsWith(".png")) f += ".png"; - Krom.writePng(path + Path.sep + f, l.texpaint.getPixels().getData(), l.texpaint.width, l.texpaint.height, 3); // RRR1 + Krom.writePng(path + Path.sep + f, l.texpaint.getPixels(), l.texpaint.width, l.texpaint.height, 3); // RRR1 }); } else { diff --git a/armorsculpt/Sources/arm/io/ExportObj.hx b/armorsculpt/Sources/arm/io/ExportObj.hx index e7f928a2..085ffb9e 100644 --- a/armorsculpt/Sources/arm/io/ExportObj.hx +++ b/armorsculpt/Sources/arm/io/ExportObj.hx @@ -1,15 +1,19 @@ package arm.io; -import haxe.io.BytesOutput; import js.lib.Int16Array; import iron.object.MeshObject; class ExportObj { + static function writeString(out: Array, str: String) { + for (i in 0...str.length) { + out.push(str.charCodeAt(i)); + } + } + public static function run(path: String, paintObjects: Array, applyDisplacement = false) { - var o = new BytesOutput(); - o.bigEndian = false; - o.writeString("# armorsculpt.org\n"); + var o: Array = []; + writeString(o, "# armorsculpt.org\n"); var texpaint = Project.layers[0].texpaint; var pixels = texpaint.getPixels(); @@ -59,18 +63,18 @@ class ExportObj { } } - o.writeString("o " + p.name + "\n"); + writeString(o, "o " + p.name + "\n"); for (i in 0...pi) { - o.writeString("v "); + writeString(o, "v "); var vx = posa2[i * 3] * sc + ""; - o.writeString(vx.substr(0, vx.indexOf(".") + 7)); - o.writeString(" "); + writeString(o, vx.substr(0, vx.indexOf(".") + 7)); + writeString(o, " "); var vy = posa2[i * 3 + 2] * sc + ""; - o.writeString(vy.substr(0, vy.indexOf(".") + 7)); - o.writeString(" "); + writeString(o, vy.substr(0, vy.indexOf(".") + 7)); + writeString(o, " "); var vz = -posa2[i * 3 + 1] * sc + ""; - o.writeString(vz.substr(0, vz.indexOf(".") + 7)); - o.writeString("\n"); + writeString(o, vz.substr(0, vz.indexOf(".") + 7)); + writeString(o, "\n"); } // var inda = mesh.index_arrays[0].values; @@ -78,19 +82,20 @@ class ExportObj { var pi1 = posmap.get(inda[i * 3 ]) + 1 + poff; var pi2 = posmap.get(inda[i * 3 + 1]) + 1 + poff; var pi3 = posmap.get(inda[i * 3 + 2]) + 1 + poff; - o.writeString("f "); - o.writeString(pi1 + ""); - o.writeString(" "); - o.writeString(pi2 + ""); - o.writeString(" "); - o.writeString(pi3 + ""); - o.writeString("\n"); + writeString(o, "f "); + writeString(o, pi1 + ""); + writeString(o, " "); + writeString(o, pi2 + ""); + writeString(o, " "); + writeString(o, pi3 + ""); + writeString(o, "\n"); } poff += pi; // } if (!path.endsWith(".obj")) path += ".obj"; - Krom.fileSaveBytes(path, o.getBytes().getData(), o.getBytes().length); + var b = js.lib.Uint8Array.from(o).buffer; + Krom.fileSaveBytes(path, b, b.byteLength); } } diff --git a/base/Sources/Main.hx b/base/Sources/Main.hx index 5c63a083..822015b3 100644 --- a/base/Sources/Main.hx +++ b/base/Sources/Main.hx @@ -1,6 +1,5 @@ package; -import kha.Window; import kha.System; import iron.object.Object; import iron.Scene; @@ -66,7 +65,7 @@ class Main { iron.App.y = arm.App.y; Config.init(); - System.start(Config.getOptions(), function(window: Window) { + System.start(Config.getOptions(), function() { if (Config.raw.layout == null) arm.App.initLayout(); Krom.setApplicationName(Manifest.title); iron.App.init(function() { diff --git a/base/Sources/arm/App.hx b/base/Sources/arm/App.hx index 94cde03c..76c10bea 100644 --- a/base/Sources/arm/App.hx +++ b/base/Sources/arm/App.hx @@ -142,8 +142,8 @@ class App { public function new() { Console.init(); - lastWindowWidth = System.windowWidth(); - lastWindowHeight = System.windowHeight(); + lastWindowWidth = System.width; + lastWindowHeight = System.height; System.notifyOnDropFiles(function(dropPath: String) { #if krom_linux @@ -186,12 +186,12 @@ class App { Translator.loadTranslations(Config.raw.locale); UIFiles.filename = tr("untitled"); #if (krom_android || krom_ios) - kha.Window.get().title = tr("untitled"); + System.title = tr("untitled"); #end // Baked font for fast startup if (Config.raw.locale == "en") { - font.font_ = Krom.g2_font_13(font.blob.bytes.getData()); + font.font_ = Krom.g2_font_13(font.blob); font.fontGlyphs = kha.Graphics2.fontGlyphs; } else font.init(); @@ -286,16 +286,16 @@ class App { var res = 0; if (UINodes.inst == null || UIBase.inst == null) { var sidebarw = Config.raw.layout == null ? UIBase.defaultSidebarW : Config.raw.layout[LayoutSidebarW]; - res = System.windowWidth() - sidebarw - UIToolbar.defaultToolbarW; + res = System.width - sidebarw - UIToolbar.defaultToolbarW; } else if (UINodes.inst.show || UIView2D.inst.show) { - res = System.windowWidth() - Config.raw.layout[LayoutSidebarW] - Config.raw.layout[LayoutNodesW] - UIToolbar.inst.toolbarw; + res = System.width - Config.raw.layout[LayoutSidebarW] - Config.raw.layout[LayoutNodesW] - UIToolbar.inst.toolbarw; } else if (UIBase.inst.show) { - res = System.windowWidth() - Config.raw.layout[LayoutSidebarW] - UIToolbar.inst.toolbarw; + res = System.width - Config.raw.layout[LayoutSidebarW] - UIToolbar.inst.toolbarw; } else { // Distract free - res = System.windowWidth(); + res = System.width; } if (UIBase.inst != null && Context.raw.viewIndex > -1) { res = Std.int(res / 2); @@ -318,7 +318,7 @@ class App { return RenderUtil.decalPreviewSize; } - var res = System.windowHeight(); + var res = System.height; if (UIBase.inst == null) { res -= UIHeader.defaultHeaderH * 2 + UIStatus.defaultStatusH; @@ -349,20 +349,20 @@ class App { public static function w(): Int { var res = 0; if (UINodes.inst == null) { - res = System.windowWidth(); + res = System.width; } else if (UINodes.inst.show || UIView2D.inst.show) { - res = System.windowWidth() - Config.raw.layout[LayoutNodesW]; + res = System.width - Config.raw.layout[LayoutNodesW]; } else { // Distract free - res = System.windowWidth(); + res = System.width; } return res > 0 ? res : 1; // App was minimized, force render path resize } public static function h(): Int { - var res = System.windowHeight(); + var res = System.height; if (UIBase.inst == null) { res -= UIHeader.defaultHeaderH * 2 + UIStatus.defaultStatusH; } @@ -389,17 +389,17 @@ class App { } public static function onResize() { - if (System.windowWidth() == 0 || System.windowHeight() == 0) return; + if (System.width == 0 || System.height == 0) return; - var ratioW = System.windowWidth() / lastWindowWidth; - lastWindowWidth = System.windowWidth(); - var ratioH = System.windowHeight() / lastWindowHeight; - lastWindowHeight = System.windowHeight(); + var ratioW = System.width / lastWindowWidth; + lastWindowWidth = System.width; + var ratioH = System.height / lastWindowHeight; + lastWindowHeight = System.height; Config.raw.layout[LayoutNodesW] = Std.int(Config.raw.layout[LayoutNodesW] * ratioW); #if (is_paint || is_sculpt) Config.raw.layout[LayoutSidebarH0] = Std.int(Config.raw.layout[LayoutSidebarH0] * ratioH); - Config.raw.layout[LayoutSidebarH1] = System.windowHeight() - Config.raw.layout[LayoutSidebarH0]; + Config.raw.layout[LayoutSidebarH1] = System.height - Config.raw.layout[LayoutSidebarH0]; #end resize(); @@ -411,16 +411,16 @@ class App { static function saveWindowRect() { #if (krom_windows || krom_linux || krom_darwin) - Config.raw.window_w = System.windowWidth(); - Config.raw.window_h = System.windowHeight(); - Config.raw.window_x = kha.Window.get().x; - Config.raw.window_y = kha.Window.get().y; + Config.raw.window_w = System.width; + Config.raw.window_h = System.height; + Config.raw.window_x = System.x; + Config.raw.window_y = System.y; Config.save(); #end } public static function resize() { - if (System.windowWidth() == 0 || System.windowHeight() == 0) return; + if (System.width == 0 || System.height == 0) return; var cam = Scene.active.camera; if (cam.data.raw.ortho != null) { @@ -727,7 +727,7 @@ class App { } static function render(g: kha.Graphics2) { - if (System.windowWidth() == 0 || System.windowHeight() == 0) return; + if (System.width == 0 || System.height == 0) return; if (Context.raw.frame == 2) { #if (is_paint || is_sculpt) @@ -882,19 +882,19 @@ class App { } public static function toggleFullscreen() { - if (kha.Window.get().mode == kha.Window.WindowMode.Windowed) { + if (System.mode == WindowMode.Windowed) { #if (krom_windows || krom_linux || krom_darwin) - Config.raw.window_w = System.windowWidth(); - Config.raw.window_h = System.windowHeight(); - Config.raw.window_x = kha.Window.get().x; - Config.raw.window_y = kha.Window.get().y; + Config.raw.window_w = System.width; + Config.raw.window_h = System.height; + Config.raw.window_x = System.x; + Config.raw.window_y = System.y; #end - kha.Window.get().mode = kha.Window.WindowMode.Fullscreen; + System.mode = WindowMode.Fullscreen; } else { - kha.Window.get().mode = kha.Window.WindowMode.Windowed; - kha.Window.get().resize(Config.raw.window_w, Config.raw.window_h); - kha.Window.get().move(Config.raw.window_x, Config.raw.window_y); + System.mode = WindowMode.Windowed; + System.resize(Config.raw.window_w, Config.raw.window_h); + System.move(Config.raw.window_x, Config.raw.window_y); } } @@ -943,8 +943,8 @@ class App { raw.layout = [ #if (is_paint || is_sculpt) Std.int(UIBase.defaultSidebarW * raw.window_scale), // LayoutSidebarW - Std.int(kha.System.windowHeight() / 2), // LayoutSidebarH0 - Std.int(kha.System.windowHeight() / 2), // LayoutSidebarH1 + Std.int(kha.System.height / 2), // LayoutSidebarH0 + Std.int(kha.System.height / 2), // LayoutSidebarH1 #end #if krom_ios @@ -1106,14 +1106,14 @@ class App { }); rts.get("texpaint_blend0").raw.width = Config.getTextureResX(); rts.get("texpaint_blend0").raw.height = Config.getTextureResY(); - rts.get("texpaint_blend0").image = Image.createRenderTarget(Config.getTextureResX(), Config.getTextureResY(), TextureFormat.L8); + rts.get("texpaint_blend0").image = Image.createRenderTarget(Config.getTextureResX(), Config.getTextureResY(), TextureFormat.R8); var _texpaint_blend1 = rts.get("texpaint_blend1").image; App.notifyOnNextFrame(function() { _texpaint_blend1.unload(); }); rts.get("texpaint_blend1").raw.width = Config.getTextureResX(); rts.get("texpaint_blend1").raw.height = Config.getTextureResY(); - rts.get("texpaint_blend1").image = Image.createRenderTarget(Config.getTextureResX(), Config.getTextureResY(), TextureFormat.L8); + rts.get("texpaint_blend1").image = Image.createRenderTarget(Config.getTextureResX(), Config.getTextureResY(), TextureFormat.R8); Context.raw.brushBlendDirty = true; if (rts.get("texpaint_blur") != null) { var _texpaint_blur = rts.get("texpaint_blur").image; @@ -1199,7 +1199,7 @@ class App { vs.add("col", VertexData.U8_4X_Normalized); pipeCopy8.inputLayout = [vs]; pipeCopy8.colorAttachmentCount = 1; - pipeCopy8.colorAttachments[0] = TextureFormat.L8; + pipeCopy8.colorAttachments[0] = TextureFormat.R8; pipeCopy8.compile(); pipeCopy128 = new PipelineState(); @@ -1228,7 +1228,7 @@ class App { vs.add("col", VertexData.U8_4X_Normalized); pipeInvert8.inputLayout = [vs]; pipeInvert8.colorAttachmentCount = 1; - pipeInvert8.colorAttachments[0] = TextureFormat.L8; + pipeInvert8.colorAttachments[0] = TextureFormat.R8; pipeInvert8.compile(); pipeApplyMask = new PipelineState(); @@ -1420,7 +1420,7 @@ class App { tempMaskImage = null; } if (tempMaskImage == null) { - tempMaskImage = Image.createRenderTarget(Config.getTextureResX(), Config.getTextureResY(), TextureFormat.L8); + tempMaskImage = Image.createRenderTarget(Config.getTextureResX(), Config.getTextureResY(), TextureFormat.R8); } } #end @@ -2196,9 +2196,9 @@ class App { } iron.RenderPath.active.renderTargets.get("texpaint_blend0").image.unload(); - iron.RenderPath.active.renderTargets.get("texpaint_blend0").image = Image.createRenderTarget(Config.getTextureResX(), Config.getTextureResY(), TextureFormat.L8); + iron.RenderPath.active.renderTargets.get("texpaint_blend0").image = Image.createRenderTarget(Config.getTextureResX(), Config.getTextureResY(), TextureFormat.R8); iron.RenderPath.active.renderTargets.get("texpaint_blend1").image.unload(); - iron.RenderPath.active.renderTargets.get("texpaint_blend1").image = Image.createRenderTarget(Config.getTextureResX(), Config.getTextureResY(), TextureFormat.L8); + iron.RenderPath.active.renderTargets.get("texpaint_blend1").image = Image.createRenderTarget(Config.getTextureResX(), Config.getTextureResY(), TextureFormat.R8); if (iron.RenderPath.active.renderTargets.get("texpaint_node") != null) { iron.RenderPath.active.renderTargets.remove("texpaint_node"); diff --git a/base/Sources/arm/Args.hx b/base/Sources/arm/Args.hx index 2ea62bcf..25d50fa2 100644 --- a/base/Sources/arm/Args.hx +++ b/base/Sources/arm/Args.hx @@ -162,8 +162,8 @@ class Args { file = "export_presets/" + BoxExport.files[BoxExport.files.indexOf(f)] + ".json"; } - iron.data.Data.getBlob(file, function(blob: kha.Blob) { - BoxExport.preset = haxe.Json.parse(blob.toString()); + iron.data.Data.getBlob(file, function(blob: js.lib.ArrayBuffer) { + BoxExport.preset = haxe.Json.parse(kha.System.bufferToString(blob)); iron.data.Data.deleteBlob("export_presets/" + file); }); diff --git a/base/Sources/arm/Camera.hx b/base/Sources/arm/Camera.hx index 62eb042f..cff37f5f 100644 --- a/base/Sources/arm/Camera.hx +++ b/base/Sources/arm/Camera.hx @@ -39,19 +39,19 @@ class Camera { if (Config.raw.wrap_mouse && controlsDown) { if (mouse.viewX < 0) { @:privateAccess mouse.x = mouse.lastX = iron.App.x() + iron.App.w(); - Krom.setMousePosition(0, Std.int(mouse.x), Std.int(mouse.y)); + Krom.setMousePosition(Std.int(mouse.x), Std.int(mouse.y)); } else if (mouse.viewX > iron.App.w()) { @:privateAccess mouse.x = mouse.lastX = iron.App.x(); - Krom.setMousePosition(0, Std.int(mouse.x), Std.int(mouse.y)); + Krom.setMousePosition(Std.int(mouse.x), Std.int(mouse.y)); } else if (mouse.viewY < 0) { @:privateAccess mouse.y = mouse.lastY = iron.App.y() + iron.App.h(); - Krom.setMousePosition(0, Std.int(mouse.x), Std.int(mouse.y)); + Krom.setMousePosition(Std.int(mouse.x), Std.int(mouse.y)); } else if (mouse.viewY > iron.App.h()) { @:privateAccess mouse.y = mouse.lastY = iron.App.y(); - Krom.setMousePosition(0, Std.int(mouse.x), Std.int(mouse.y)); + Krom.setMousePosition(Std.int(mouse.x), Std.int(mouse.y)); } } else { diff --git a/base/Sources/arm/Config.hx b/base/Sources/arm/Config.hx index a1a554ab..625fb0ec 100644 --- a/base/Sources/arm/Config.hx +++ b/base/Sources/arm/Config.hx @@ -2,9 +2,7 @@ package arm; import haxe.io.Bytes; import haxe.Json; -import kha.Display; -import kha.Window.WindowOptions; -import kha.Window.WindowMode; +import kha.System.WindowMode; import kha.System; import iron.data.Data; import zui.Zui; @@ -26,9 +24,9 @@ class Config { public static function load(done: Void->Void) { try { - Data.getBlob((Path.isProtected() ? Krom.savePath() : "") + "config.json", function(blob: kha.Blob) { + Data.getBlob((Path.isProtected() ? Krom.savePath() : "") + "config.json", function(blob: js.lib.ArrayBuffer) { configLoaded = true; - raw = Json.parse(blob.toString()); + raw = Json.parse(kha.System.bufferToString(blob)); done(); }); @@ -36,9 +34,9 @@ class Config { catch (e: Dynamic) { #if krom_linux try { // Protected directory - Data.getBlob(Krom.savePath() + "config.json", function(blob: kha.Blob) { + Data.getBlob(Krom.savePath() + "config.json", function(blob: js.lib.ArrayBuffer) { configLoaded = true; - raw = Json.parse(blob.toString()); + raw = Json.parse(kha.System.bufferToString(blob)); done(); }); } @@ -80,15 +78,14 @@ class Config { raw.window_x = -1; raw.window_y = -1; raw.window_scale = 1.0; - var disp = Display.primary; - if (disp.width >= 2560 && disp.height >= 1600) { + if (kha.System.displayWidth() >= 2560 && kha.System.displayHeight() >= 1600) { raw.window_scale = 2.0; } #if (krom_android || krom_ios || krom_darwin) raw.window_scale = 2.0; #end raw.window_vsync = true; - raw.window_frequency = disp.frequency; + raw.window_frequency = kha.System.displayFrequency(); raw.rp_bloom = false; raw.rp_gi = false; raw.rp_vignette = 0.2; @@ -125,26 +122,21 @@ class Config { public static function getOptions(): kha.SystemOptions { var windowMode = raw.window_mode == 0 ? WindowMode.Windowed : WindowMode.Fullscreen; - var windowFeatures = kha.Window.WindowFeatures.None; + var windowFeatures = kha.System.WindowFeatures.None; if (raw.window_resizable) windowFeatures |= FeatureResizable; if (raw.window_maximizable) windowFeatures |= FeatureMaximizable; if (raw.window_minimizable) windowFeatures |= FeatureMinimizable; var title = "untitled - " + Manifest.title; return { title: title, - window: { - width: raw.window_w, - height: raw.window_h, - x: raw.window_x, - y: raw.window_y, - mode: windowMode, - windowFeatures: windowFeatures - }, - framebuffer: { - samplesPerPixel: 1, - verticalSync: raw.window_vsync, - frequency: raw.window_frequency - } + width: raw.window_w, + height: raw.window_h, + x: raw.window_x, + y: raw.window_y, + mode: windowMode, + features: windowFeatures, + vsync: raw.window_vsync, + frequency: raw.window_frequency }; } @@ -194,8 +186,8 @@ class Config { keymap = App.defaultKeymap; } else { - Data.getBlob("keymap_presets/" + raw.keymap, function(blob: kha.Blob) { - keymap = Json.parse(blob.toString()); + Data.getBlob("keymap_presets/" + raw.keymap, function(blob: js.lib.ArrayBuffer) { + keymap = Json.parse(kha.System.bufferToString(blob)); // Fill in undefined keys with defaults for (field in Reflect.fields(App.defaultKeymap)) { if (!Reflect.hasField(keymap, field)) { @@ -277,8 +269,8 @@ class Config { App.theme = new zui.Zui.Theme(); } else { - Data.getBlob("themes/" + theme, function(b: kha.Blob) { - var parsed = Json.parse(b.toString()); + Data.getBlob("themes/" + theme, function(b: js.lib.ArrayBuffer) { + var parsed = Json.parse(kha.System.bufferToString(b)); App.theme = new zui.Zui.Theme(); for (key in Type.getInstanceFields(zui.Zui.Theme)) { if (key == "theme_") continue; diff --git a/base/Sources/arm/Console.hx b/base/Sources/arm/Console.hx index 52982e57..14eeae55 100644 --- a/base/Sources/arm/Console.hx +++ b/base/Sources/arm/Console.hx @@ -12,10 +12,10 @@ class Console { static function drawToast(s: String, g: kha.Graphics2) { g.color = 0x55000000; - g.fillRect(0, 0, kha.System.windowWidth(), kha.System.windowHeight()); + g.fillRect(0, 0, kha.System.width, kha.System.height); var scale = arm.App.getUIs()[0].SCALE(); - var x = kha.System.windowWidth() / 2; - var y = kha.System.windowHeight() - 200 * scale; + var x = kha.System.width / 2; + var y = kha.System.height - 200 * scale; g.fillRect(x - 200 * scale, y, 400 * scale, 80 * scale); g.font = App.font; g.fontSize = Std.int(22 * scale); diff --git a/base/Sources/arm/History.hx b/base/Sources/arm/History.hx index 7aff19a3..6e748b13 100644 --- a/base/Sources/arm/History.hx +++ b/base/Sources/arm/History.hx @@ -610,7 +610,7 @@ class History { static function push(name: String): TStep { #if (krom_windows || krom_linux || krom_darwin) var filename = Project.filepath == "" ? UIFiles.filename : Project.filepath.substring(Project.filepath.lastIndexOf(Path.sep) + 1, Project.filepath.length - 4); - kha.Window.get().title = filename + "* - " + Manifest.title; + kha.System.title = filename + "* - " + Manifest.title; #end if (Config.raw.touch_ui) { diff --git a/base/Sources/arm/Plugin.hx b/base/Sources/arm/Plugin.hx index 826c892d..08fff2e0 100644 --- a/base/Sources/arm/Plugin.hx +++ b/base/Sources/arm/Plugin.hx @@ -37,10 +37,10 @@ class Plugin { public static function start(plugin: String) { try { - iron.data.Data.getBlob("plugins/" + plugin, function(blob: kha.Blob) { + iron.data.Data.getBlob("plugins/" + plugin, function(blob: js.lib.ArrayBuffer) { pluginName = plugin; - // js.Syntax.code("(1, eval)({0})", blob.toString()); // Global scope - js.Syntax.code("eval({0})", blob.toString()); // Local scope + // js.Syntax.code("(1, eval)({0})", kha.System.bufferToString(blob)); // Global scope + js.Syntax.code("eval({0})", kha.System.bufferToString(blob)); // Local scope iron.data.Data.deleteBlob("plugins/" + plugin); }); } @@ -85,10 +85,6 @@ class CoreBridge { public static var ReflectField = Reflect.field; public static var ReflectSetField = Reflect.setField; public static var StdIs = Std.isOfType; - public static var Bytes = haxe.io.Bytes; - public static var BytesInput = haxe.io.BytesInput; - public static var BytesOutput = haxe.io.BytesOutput; - public static var Blob = kha.Blob; public static var Image = kha.Image; public static function colorFromFloats(r: Float, g: Float, b: Float, a: Float): kha.Color { return kha.Color.fromFloats(r, g, b, a); diff --git a/base/Sources/arm/Project.hx b/base/Sources/arm/Project.hx index cb7df821..48a6cbc3 100644 --- a/base/Sources/arm/Project.hx +++ b/base/Sources/arm/Project.hx @@ -1,7 +1,6 @@ package arm; import kha.System; -import kha.Window; import kha.Image; import zui.Zui; import zui.Zui.Nodes; @@ -37,9 +36,6 @@ import arm.data.MaterialSlot; import arm.io.ImportBlendMaterial; import arm.logic.NodesBrush; #end -#if is_lab -import kha.Blob; -#end class Project { @@ -66,7 +62,7 @@ class Project { public static var materials: Array = null; //// public static var nodes: Nodes; public static var canvas: TNodeCanvas; - public static var defaultCanvas: Blob = null; + public static var defaultCanvas: js.lib.ArrayBuffer = null; #end public static function projectOpen() { @@ -90,9 +86,9 @@ class Project { #if krom_ios var documentDirectory = Krom.saveDialog("", ""); documentDirectory = documentDirectory.substr(0, documentDirectory.length - 8); // Strip /'untitled' - filepath = documentDirectory + "/" + kha.Window.get().title + ".arm"; + filepath = documentDirectory + "/" + kha.System.title + ".arm"; #elseif krom_android - filepath = Krom.savePath() + "/" + kha.Window.get().title + ".arm"; + filepath = Krom.savePath() + "/" + kha.System.title + ".arm"; #else projectSaveAs(saveAndQuit); return; @@ -101,7 +97,7 @@ class Project { #if (krom_windows || krom_linux || krom_darwin) var filename = Project.filepath.substring(Project.filepath.lastIndexOf(Path.sep) + 1, Project.filepath.length - 4); - Window.get().title = filename + " - " + Manifest.title; + System.title = filename + " - " + Manifest.title; #end function _init() { @@ -159,7 +155,7 @@ class Project { public static function projectNew(resetLayers = true) { #if (krom_windows || krom_linux || krom_darwin) - Window.get().title = Manifest.title; + System.title = Manifest.title; #end filepath = ""; @@ -232,8 +228,8 @@ class Project { #end } else { - Data.getBlob("meshes/" + meshList[Context.raw.projectType] + ".arm", function(b: kha.Blob) { - raw = iron.system.ArmPack.decode(b.toBytes()).mesh_datas[0]; + Data.getBlob("meshes/" + meshList[Context.raw.projectType] + ".arm", function(b: js.lib.ArrayBuffer) { + raw = iron.system.ArmPack.decode(b).mesh_datas[0]; }); } diff --git a/base/Sources/arm/ProjectFormat.hx b/base/Sources/arm/ProjectFormat.hx index f2ce3078..44813cfa 100644 --- a/base/Sources/arm/ProjectFormat.hx +++ b/base/Sources/arm/ProjectFormat.hx @@ -18,15 +18,15 @@ import iron.data.SceneFormat; #if (is_paint || is_sculpt) @:optional public var brush_nodes: Array; - @:optional public var brush_icons: Array; + @:optional public var brush_icons: Array; @:optional public var material_nodes: Array; @:optional public var material_groups: Array; - @:optional public var material_icons: Array; + @:optional public var material_icons: Array; @:optional public var font_assets: Array; @:optional public var layer_datas: Array; @:optional public var mesh_datas: Array; @:optional public var mesh_assets: Array; - @:optional public var mesh_icons: Array; + @:optional public var mesh_icons: Array; #end #if is_paint @@ -38,7 +38,7 @@ import iron.data.SceneFormat; @:optional public var material: TNodeCanvas; @:optional public var material_groups: Array; @:optional public var mesh_data: TMeshData; - @:optional public var mesh_icon: haxe.io.Bytes; + @:optional public var mesh_icon: js.lib.ArrayBuffer; #end } @@ -50,7 +50,7 @@ import iron.data.SceneFormat; @:structInit class TPackedAsset { public var name: String; - public var bytes: haxe.io.Bytes; + public var bytes: js.lib.ArrayBuffer; } @:structInit class TSwatchColor { @@ -70,7 +70,7 @@ import iron.data.SceneFormat; public var name: String; public var res: Int; // Width pixels public var bpp: Int; // Bits per pixel - public var texpaint: haxe.io.Bytes; + public var texpaint: js.lib.ArrayBuffer; public var uv_scale: Float; public var uv_rot: Float; public var uv_type: Int; @@ -82,8 +82,8 @@ import iron.data.SceneFormat; public var parent: Int; public var visible: Bool; #if is_paint - public var texpaint_nor: haxe.io.Bytes; - public var texpaint_pack: haxe.io.Bytes; + public var texpaint_nor: js.lib.ArrayBuffer; + public var texpaint_pack: js.lib.ArrayBuffer; public var paint_base: Bool; public var paint_opac: Bool; public var paint_occ: Bool; diff --git a/base/Sources/arm/data/ConstData.hx b/base/Sources/arm/data/ConstData.hx index ff9145dc..e95a4e22 100644 --- a/base/Sources/arm/data/ConstData.hx +++ b/base/Sources/arm/data/ConstData.hx @@ -1,7 +1,6 @@ package arm.data; import kha.Image.TextureFormat; -import kha.Blob; import kha.Image; import iron.data.Data; import iron.system.ArmPack; @@ -12,10 +11,10 @@ class ConstData { public static function initLTC() { // Real-Time Polygonal-Light Shading with Linearly Transformed Cosines // https://eheitzresearch.wordpress.com/415-2/ - Data.getBlob("ltc_mat.arm", function(ltc_mat: Blob) { - Data.getBlob("ltc_mag.arm", function(ltc_mag: Blob) { - ltcMatTex = Image.fromBytes(ArmPack.decode(ltc_mat.toBytes()), 64, 64, TextureFormat.RGBA128); - ltcMagTex = Image.fromBytes(ArmPack.decode(ltc_mag.toBytes()), 64, 64, TextureFormat.A32); + Data.getBlob("ltc_mat.arm", function(ltc_mat: js.lib.ArrayBuffer) { + Data.getBlob("ltc_mag.arm", function(ltc_mag: js.lib.ArrayBuffer) { + ltcMatTex = Image.fromBytes(ArmPack.decode(ltc_mat), 64, 64, TextureFormat.RGBA128); + ltcMagTex = Image.fromBytes(ArmPack.decode(ltc_mag), 64, 64, TextureFormat.R32); }); }); } diff --git a/base/Sources/arm/format/BlendParser.hx b/base/Sources/arm/format/BlendParser.hx index 9f246d61..8789a0ca 100644 --- a/base/Sources/arm/format/BlendParser.hx +++ b/base/Sources/arm/format/BlendParser.hx @@ -3,18 +3,19 @@ // https://github.com/fschutt/mystery-of-the-blend-backup // https://web.archive.org/web/20170630054951/http://www.atmind.nl/blender/mystery_ot_blend.html // Usage: -// var bl = new BlendParser(blob:kha.Blob); +// var bl = new BlendParser(blob: DataView); // trace(bl.dir("Scene")); // var scenes = bl.get("Scene"); // trace(scenes[0].get("id").get("name")); package arm.format; -import kha.Blob; +import js.lib.ArrayBuffer; +import js.lib.DataView; class BlendParser { public var pos: Int; - var blob: Blob; + var view: DataView; // Header public var version: String; @@ -25,11 +26,11 @@ class BlendParser { public var dna: Dna = null; public var map = new Map>(); // Map blocks by memory address - public function new(blob: Blob) { - this.blob = blob; + public function new(buffer: ArrayBuffer) { + this.view = new DataView(buffer); this.pos = 0; if (readChars(7) != "BLENDER") { - this.blob = Blob.fromBytes(haxe.io.Bytes.ofData(Krom.inflate(blob.toBytes().getData(), false))); + this.view = new DataView(Krom.inflate(buffer, false)); this.pos = 0; if (readChars(7) != "BLENDER") return; } @@ -84,24 +85,12 @@ class BlendParser { // v - little endian, V - big endian littleEndian = readChar() == "v"; - if (littleEndian) { - read16 = read16LE; - read32 = read32LE; - read64 = read64LE; - readf32 = readf32LE; - } - else { - read16 = read16BE; - read32 = read32BE; - read64 = read64BE; - readf32 = readf32BE; - } version = readChars(3); // Reading file blocks // Header - data - while (pos < blob.length) { + while (pos < view.byteLength) { align(); var b = new Block(); @@ -184,74 +173,47 @@ class BlendParser { } public function read8(): Int { - var i = blob.readU8(pos); + var i = view.getUint8(pos); pos += 1; return i; } - public var read16: Void->Int; - public var read32: Void->Int; - public var read64: Void->haxe.Int64; - public var readf32: Void->Float; - - function read16LE(): Int { - var i = blob.readS16LE(pos); + public function read16(): Int { + var i = view.getInt16(pos, littleEndian); pos += 2; return i; } - function read32LE(): Int { - var i = blob.readS32LE(pos); + public function read32(): Int { + var i = view.getInt32(pos, littleEndian); pos += 4; return i; } - function read64LE(): haxe.Int64 { + public function read64(): haxe.Int64 { return haxe.Int64.make(read32(), read32()); } - function readf32LE(): Float { - var f = blob.readF32LE(pos); + public function readf32(): Float { + var f = view.getFloat32(pos, littleEndian); pos += 4; return f; } - function read16BE(): Int { - var i = blob.readS16BE(pos); - pos += 2; - return i; - } - - function read32BE(): Int { - var i = blob.readS32BE(pos); - pos += 4; - return i; - } - - function read64BE(): haxe.Int64 { - return haxe.Int64.make(read32(), read32()); - } - - function readf32BE(): Float { - var f = blob.readF32BE(pos); - pos += 4; - return f; - } - - public function read8array(len: Int): haxe.io.Int32Array { - var ar = new haxe.io.Int32Array(len); + public function read8array(len: Int): js.lib.Int32Array { + var ar = new js.lib.Int32Array(len); for (i in 0...len) ar[i] = read8(); return ar; } - public function read16array(len: Int): haxe.io.Int32Array { - var ar = new haxe.io.Int32Array(len); + public function read16array(len: Int): js.lib.Int32Array { + var ar = new js.lib.Int32Array(len); for (i in 0...len) ar[i] = read16(); return ar; } - public function read32array(len: Int): haxe.io.Int32Array { - var ar = new haxe.io.Int32Array(len); + public function read32array(len: Int): js.lib.Int32Array { + var ar = new js.lib.Int32Array(len); for (i in 0...len) ar[i] = read32(); return ar; } diff --git a/base/Sources/arm/format/ExrWriter.hx b/base/Sources/arm/format/ExrWriter.hx index aedd7c34..58c9daa4 100644 --- a/base/Sources/arm/format/ExrWriter.hx +++ b/base/Sources/arm/format/ExrWriter.hx @@ -5,236 +5,243 @@ package arm.format; class ExrWriter { - public function new(out: haxe.io.BytesOutput, width: Int, height: Int, src: haxe.io.Bytes, bits = 16, type = 1, off = 0) { - out.writeByte(0x76); // magic - out.writeByte(0x2f); - out.writeByte(0x31); - out.writeByte(0x01); - out.writeByte(2); // version, scanline - out.writeByte(0); - out.writeByte(0); - out.writeByte(0); - out.writeString("channels"); - out.writeByte(0); - out.writeString("chlist"); - out.writeByte(0); + static function writeString(out: Array, str: String) { + for (i in 0...str.length) { + out.push(str.charCodeAt(i)); + } + } - out.writeByte(55); - out.writeByte(0); - out.writeByte(0); - out.writeByte(0); + public static function run(width: Int, height: Int, src: js.lib.ArrayBuffer, bits = 16, type = 1, off = 0): js.lib.ArrayBuffer { + var out = []; + out.push(0x76); // magic + out.push(0x2f); + out.push(0x31); + out.push(0x01); + out.push(2); // version, scanline + out.push(0); + out.push(0); + out.push(0); + writeString(out, "channels"); + out.push(0); + writeString(out, "chlist"); + out.push(0); + + out.push(55); + out.push(0); + out.push(0); + out.push(0); var attrib = bits == 16 ? 1 : 2; // half, float - out.writeByte("B".code); // B - out.writeByte(0); + out.push("B".code); // B + out.push(0); - out.writeByte(attrib); - out.writeByte(0); - out.writeByte(0); - out.writeByte(0); + out.push(attrib); + out.push(0); + out.push(0); + out.push(0); - out.writeByte(0); - out.writeByte(0); - out.writeByte(0); - out.writeByte(0); + out.push(0); + out.push(0); + out.push(0); + out.push(0); - out.writeByte(1); - out.writeByte(0); - out.writeByte(0); - out.writeByte(0); + out.push(1); + out.push(0); + out.push(0); + out.push(0); - out.writeByte(1); - out.writeByte(0); - out.writeByte(0); - out.writeByte(0); + out.push(1); + out.push(0); + out.push(0); + out.push(0); - out.writeByte("G".code); // G - out.writeByte(0); + out.push("G".code); // G + out.push(0); - out.writeByte(attrib); - out.writeByte(0); - out.writeByte(0); - out.writeByte(0); + out.push(attrib); + out.push(0); + out.push(0); + out.push(0); - out.writeByte(0); - out.writeByte(0); - out.writeByte(0); - out.writeByte(0); + out.push(0); + out.push(0); + out.push(0); + out.push(0); - out.writeByte(1); - out.writeByte(0); - out.writeByte(0); - out.writeByte(0); + out.push(1); + out.push(0); + out.push(0); + out.push(0); - out.writeByte(1); - out.writeByte(0); - out.writeByte(0); - out.writeByte(0); + out.push(1); + out.push(0); + out.push(0); + out.push(0); - out.writeByte("R".code); // R - out.writeByte(0); + out.push("R".code); // R + out.push(0); - out.writeByte(attrib); - out.writeByte(0); - out.writeByte(0); - out.writeByte(0); + out.push(attrib); + out.push(0); + out.push(0); + out.push(0); - out.writeByte(0); - out.writeByte(0); - out.writeByte(0); - out.writeByte(0); + out.push(0); + out.push(0); + out.push(0); + out.push(0); - out.writeByte(1); - out.writeByte(0); - out.writeByte(0); - out.writeByte(0); + out.push(1); + out.push(0); + out.push(0); + out.push(0); - out.writeByte(1); - out.writeByte(0); - out.writeByte(0); - out.writeByte(0); + out.push(1); + out.push(0); + out.push(0); + out.push(0); - out.writeByte(0); + out.push(0); - out.writeString("compression"); - out.writeByte(0); - out.writeString("compression"); - out.writeByte(0); + writeString(out, "compression"); + out.push(0); + writeString(out, "compression"); + out.push(0); - out.writeByte(1); - out.writeByte(0); - out.writeByte(0); - out.writeByte(0); - out.writeByte(0); // no compression + out.push(1); + out.push(0); + out.push(0); + out.push(0); + out.push(0); // no compression - out.writeString("dataWindow"); - out.writeByte(0); - out.writeString("box2i"); - out.writeByte(0); + writeString(out, "dataWindow"); + out.push(0); + writeString(out, "box2i"); + out.push(0); - out.writeByte(16); - out.writeByte(0); - out.writeByte(0); - out.writeByte(0); + out.push(16); + out.push(0); + out.push(0); + out.push(0); - out.writeByte(0); - out.writeByte(0); - out.writeByte(0); - out.writeByte(0); + out.push(0); + out.push(0); + out.push(0); + out.push(0); - out.writeByte(0); - out.writeByte(0); - out.writeByte(0); - out.writeByte(0); + out.push(0); + out.push(0); + out.push(0); + out.push(0); var ww = width - 1; var hh = height - 1; - out.writeByte(ww & 0xff); - out.writeByte((ww >> 8) & 0xff); - out.writeByte((ww >> 16) & 0xff); - out.writeByte((ww >> 24) & 0xff); + out.push(ww & 0xff); + out.push((ww >> 8) & 0xff); + out.push((ww >> 16) & 0xff); + out.push((ww >> 24) & 0xff); - out.writeByte(hh & 0xff); - out.writeByte((hh >> 8) & 0xff); - out.writeByte((hh >> 16) & 0xff); - out.writeByte((hh >> 24) & 0xff); + out.push(hh & 0xff); + out.push((hh >> 8) & 0xff); + out.push((hh >> 16) & 0xff); + out.push((hh >> 24) & 0xff); - out.writeString("displayWindow"); - out.writeByte(0); - out.writeString("box2i"); - out.writeByte(0); + writeString(out, "displayWindow"); + out.push(0); + writeString(out, "box2i"); + out.push(0); - out.writeByte(16); - out.writeByte(0); - out.writeByte(0); - out.writeByte(0); + out.push(16); + out.push(0); + out.push(0); + out.push(0); - out.writeByte(0); - out.writeByte(0); - out.writeByte(0); - out.writeByte(0); + out.push(0); + out.push(0); + out.push(0); + out.push(0); - out.writeByte(0); - out.writeByte(0); - out.writeByte(0); - out.writeByte(0); + out.push(0); + out.push(0); + out.push(0); + out.push(0); - out.writeByte(ww & 0xff); - out.writeByte((ww >> 8) & 0xff); - out.writeByte((ww >> 16) & 0xff); - out.writeByte((ww >> 24) & 0xff); + out.push(ww & 0xff); + out.push((ww >> 8) & 0xff); + out.push((ww >> 16) & 0xff); + out.push((ww >> 24) & 0xff); - out.writeByte(hh & 0xff); - out.writeByte((hh >> 8) & 0xff); - out.writeByte((hh >> 16) & 0xff); - out.writeByte((hh >> 24) & 0xff); + out.push(hh & 0xff); + out.push((hh >> 8) & 0xff); + out.push((hh >> 16) & 0xff); + out.push((hh >> 24) & 0xff); - out.writeString("lineOrder"); - out.writeByte(0); - out.writeString("lineOrder"); - out.writeByte(0); + writeString(out, "lineOrder"); + out.push(0); + writeString(out, "lineOrder"); + out.push(0); - out.writeByte(1); - out.writeByte(0); - out.writeByte(0); - out.writeByte(0); - out.writeByte(0); // increasing Y + out.push(1); + out.push(0); + out.push(0); + out.push(0); + out.push(0); // increasing Y - out.writeString("pixelAspectRatio"); - out.writeByte(0); - out.writeString("float"); - out.writeByte(0); + writeString(out, "pixelAspectRatio"); + out.push(0); + writeString(out, "float"); + out.push(0); - out.writeByte(4); - out.writeByte(0); - out.writeByte(0); - out.writeByte(0); + out.push(4); + out.push(0); + out.push(0); + out.push(0); - out.writeByte(0); // 1.0f - out.writeByte(0); - out.writeByte(0x80); - out.writeByte(0x3f); + out.push(0); // 1.0f + out.push(0); + out.push(0x80); + out.push(0x3f); - out.writeString("screenWindowCenter"); - out.writeByte(0); + writeString(out, "screenWindowCenter"); + out.push(0); - out.writeString("v2f"); - out.writeByte(0); + writeString(out, "v2f"); + out.push(0); - out.writeByte(8); - out.writeByte(0); - out.writeByte(0); - out.writeByte(0); + out.push(8); + out.push(0); + out.push(0); + out.push(0); - out.writeByte(0); - out.writeByte(0); - out.writeByte(0); - out.writeByte(0); + out.push(0); + out.push(0); + out.push(0); + out.push(0); - out.writeByte(0); - out.writeByte(0); - out.writeByte(0); - out.writeByte(0); + out.push(0); + out.push(0); + out.push(0); + out.push(0); - out.writeString("screenWindowWidth"); - out.writeByte(0); + writeString(out, "screenWindowWidth"); + out.push(0); - out.writeString("float"); - out.writeByte(0); + writeString(out, "float"); + out.push(0); - out.writeByte(4); - out.writeByte(0); - out.writeByte(0); - out.writeByte(0); + out.push(4); + out.push(0); + out.push(0); + out.push(0); - out.writeByte(0); // 1.0f - out.writeByte(0); - out.writeByte(0x80); - out.writeByte(0x3f); + out.push(0); // 1.0f + out.push(0); + out.push(0x80); + out.push(0x3f); - out.writeByte(0); // end of header + out.push(0); // end of header var channels = 4; var byteSize = bits == 16 ? 2 : 4; @@ -246,35 +253,36 @@ class ExrWriter { // line offset table var ofs = kHeaderSize + kScanlineTableSize; for (y in 0...height) { - out.writeByte(ofs & 0xff); - out.writeByte((ofs >> 8) & 0xff); - out.writeByte((ofs >> 16) & 0xff); - out.writeByte((ofs >> 24) & 0xff); - out.writeByte(0); - out.writeByte(0); - out.writeByte(0); - out.writeByte(0); + out.push(ofs & 0xff); + out.push((ofs >> 8) & 0xff); + out.push((ofs >> 16) & 0xff); + out.push((ofs >> 24) & 0xff); + out.push(0); + out.push(0); + out.push(0); + out.push(0); ofs += fullRowSize; } // scanline data var stride = channels * byteSize; var pos = 0; + var srcView = new js.lib.DataView(src); function writeLine16(bytePos: Int) { for (x in 0...width) { - out.writeByte(src.get(bytePos )); - out.writeByte(src.get(bytePos + 1)); + out.push(srcView.getUint8(bytePos )); + out.push(srcView.getUint8(bytePos + 1)); bytePos += stride; } } function writeLine32(bytePos: Int) { for (x in 0...width) { - out.writeByte(src.get(bytePos )); - out.writeByte(src.get(bytePos + 1)); - out.writeByte(src.get(bytePos + 2)); - out.writeByte(src.get(bytePos + 3)); + out.push(srcView.getUint8(bytePos )); + out.push(srcView.getUint8(bytePos + 1)); + out.push(srcView.getUint8(bytePos + 2)); + out.push(srcView.getUint8(bytePos + 3)); bytePos += stride; } } @@ -297,18 +305,20 @@ class ExrWriter { for (y in 0...height) { // coordinate - out.writeByte(y & 0xff); - out.writeByte((y >> 8) & 0xff); - out.writeByte((y >> 16) & 0xff); - out.writeByte((y >> 24) & 0xff); + out.push(y & 0xff); + out.push((y >> 8) & 0xff); + out.push((y >> 16) & 0xff); + out.push((y >> 24) & 0xff); // data size - out.writeByte(pixelRowSize & 0xff); - out.writeByte((pixelRowSize >> 8) & 0xff); - out.writeByte((pixelRowSize >> 16) & 0xff); - out.writeByte((pixelRowSize >> 24) & 0xff); + out.push(pixelRowSize & 0xff); + out.push((pixelRowSize >> 8) & 0xff); + out.push((pixelRowSize >> 16) & 0xff); + out.push((pixelRowSize >> 24) & 0xff); // data writeData(off); pos += width * stride; } + + return js.lib.Uint8Array.from(out).buffer; } } diff --git a/base/Sources/arm/format/FbxBinaryParser.hx b/base/Sources/arm/format/FbxBinaryParser.hx index 46ef28b5..572e778c 100644 --- a/base/Sources/arm/format/FbxBinaryParser.hx +++ b/base/Sources/arm/format/FbxBinaryParser.hx @@ -5,14 +5,14 @@ import arm.format.FbxLibrary; class FbxBinaryParser { var pos: Int; - var blob: kha.Blob; + var view: js.lib.DataView; var version: Int; var is64: Bool; var root: FbxNode; - function new(blob: kha.Blob) { - this.blob = blob; + function new(view: js.lib.DataView) { + this.view = view; pos = 0; var magic = "Kaydara FBX Binary\x20\x20\x00\x1a\x00"; var valid = readChars(magic.length) == magic; @@ -26,8 +26,8 @@ class FbxBinaryParser { }; } - public static function parse(blob: kha.Blob): FbxNode { - return new FbxBinaryParser(blob).root; + public static function parse(view: js.lib.DataView): FbxNode { + return new FbxBinaryParser(view).root; } function parseArray(readVal: Void->Dynamic, isFloat = false): FbxProp { @@ -35,17 +35,17 @@ class FbxBinaryParser { var encoding = read32(); var compressedLen = read32(); var endPos = pos + compressedLen; - var _blob = blob; + var _view = view; if (encoding != 0) { pos += 2; - var input = blob.sub(pos, compressedLen).toBytes().getData(); - blob = kha.Blob.fromBytes(haxe.io.Bytes.ofData(Krom.inflate(input, true))); + var input = view.buffer.slice(pos, pos + compressedLen); + view = new js.lib.DataView(Krom.inflate(input, true)); pos = 0; } var res = isFloat ? parseArrayf(readVal, len) : parseArrayi(readVal, len); if (encoding != 0) { pos = endPos; - blob = _blob; + view = _view; } return res; } @@ -143,20 +143,19 @@ class FbxBinaryParser { } function read8(): Int { - var i = blob.readU8(pos); + var i = view.getUint8(pos); pos += 1; return i; } function read16(): Int { - var i = blob.readS16LE(pos); + var i = view.getInt16(pos, true); pos += 2; return i; } function read32(): Int { - var i = blob.bytes.getInt32(pos); - // var i = blob.readS32LE(pos); // Result sometimes off by 1? + var i = view.getInt32(pos, true); pos += 4; return i; } @@ -169,7 +168,7 @@ class FbxBinaryParser { } function readf32(): Float { - var f = blob.readF32LE(pos); + var f = view.getFloat32(pos, true); pos += 4; return f; } @@ -204,9 +203,9 @@ class FbxBinaryParser { return read8(); // return read8() == 1; } - function readBytes(len: Int): kha.Blob { - var b = blob.sub(pos, len); + function readBytes(len: Int): js.lib.DataView { + var v = new js.lib.DataView(view.buffer, pos, len); pos += len; - return b; + return v; } } diff --git a/base/Sources/arm/format/FbxParser.hx b/base/Sources/arm/format/FbxParser.hx index 54e2c34a..0f9ed088 100644 --- a/base/Sources/arm/format/FbxParser.hx +++ b/base/Sources/arm/format/FbxParser.hx @@ -33,13 +33,14 @@ class FbxParser { var current = 0; var binary = true; - public function new(blob: kha.Blob) { + public function new(buffer: js.lib.ArrayBuffer) { + var view = new js.lib.DataView(buffer); var magic = "Kaydara FBX Binary\x20\x20\x00\x1a\x00"; var s = ""; - for (i in 0...magic.length) s += String.fromCharCode(blob.readU8(i)); + for (i in 0...magic.length) s += String.fromCharCode(view.getUint8(i)); binary = s == magic; - var fbx = binary ? FbxBinaryParser.parse(blob) : Parser.parse(blob.toString()); + var fbx = binary ? FbxBinaryParser.parse(view) : Parser.parse(untyped String.fromCharCode.apply(null, new js.lib.Uint8Array(buffer))); var lib = new FbxLibrary(); try { lib.load(fbx); diff --git a/base/Sources/arm/io/ExportArm.hx b/base/Sources/arm/io/ExportArm.hx index c10d9927..af057d19 100644 --- a/base/Sources/arm/io/ExportArm.hx +++ b/base/Sources/arm/io/ExportArm.hx @@ -24,7 +24,7 @@ class ExportArm { var raw: TSceneFormat = { mesh_datas: mesh_datas }; var b = ArmPack.encode(raw); if (!path.endsWith(".arm")) path += ".arm"; - Krom.fileSaveBytes(path, b.getData(), b.length + 1); + Krom.fileSaveBytes(path, b, b.byteLength + 1); } public static function runProject() { @@ -196,8 +196,8 @@ class ExportArm { } #end - var bytes = ArmPack.encode(Project.raw); - Krom.fileSaveBytes(Project.filepath, bytes.getData(), bytes.length + 1); + var buffer = ArmPack.encode(Project.raw); + Krom.fileSaveBytes(Project.filepath, buffer, buffer.byteLength + 1); // Save to recent #if krom_ios @@ -277,9 +277,9 @@ class ExportArm { }; if (Context.raw.writeIconOnExport) { // Separate icon files - Krom.writePng(path.substr(0, path.length - 4) + "_icon.png", m.image.getPixels().getData(), m.image.width, m.image.height, 0); + Krom.writePng(path.substr(0, path.length - 4) + "_icon.png", m.image.getPixels(), m.image.width, m.image.height, 0); if (isCloud) { - Krom.writeJpg(path.substr(0, path.length - 4) + "_icon.jpg", m.image.getPixels().getData(), m.image.width, m.image.height, 0, 50); + Krom.writeJpg(path.substr(0, path.length - 4) + "_icon.jpg", m.image.getPixels(), m.image.width, m.image.height, 0, 50); } } @@ -287,19 +287,20 @@ class ExportArm { packAssets(raw, assets); } - var bytes = ArmPack.encode(raw); - Krom.fileSaveBytes(path, bytes.getData(), bytes.length + 1); + var buffer = ArmPack.encode(raw); + Krom.fileSaveBytes(path, buffer, buffer.byteLength + 1); } #end #if (krom_metal || krom_vulkan) - static function bgraSwap(bytes: haxe.io.Bytes) { - for (i in 0...Std.int(bytes.length / 4)) { - var r = bytes.get(i * 4); - bytes.set(i * 4, bytes.get(i * 4 + 2)); - bytes.set(i * 4 + 2, r); + static function bgraSwap(buffer: js.lib.ArrayBuffer) { + var view = new js.lib.DataView(buffer); + for (i in 0...Std.int(buffer.byteLength / 4)) { + var r = view.getUint8(i * 4); + view.setUint8(i * 4, view.getUint8(i * 4 + 2)); + view.setUint8(i * 4 + 2, r); } - return bytes; + return buffer; } #end @@ -335,15 +336,15 @@ class ExportArm { }; if (Context.raw.writeIconOnExport) { // Separate icon file - Krom.writePng(path.substr(0, path.length - 4) + "_icon.png", b.image.getPixels().getData(), b.image.width, b.image.height, 0); + Krom.writePng(path.substr(0, path.length - 4) + "_icon.png", b.image.getPixels(), b.image.width, b.image.height, 0); } if (Context.raw.packAssetsOnExport) { // Pack textures packAssets(raw, assets); } - var bytes = ArmPack.encode(raw); - Krom.fileSaveBytes(path, bytes.getData(), bytes.length + 1); + var buffer = ArmPack.encode(raw); + Krom.fileSaveBytes(path, buffer, buffer.byteLength + 1); } #end @@ -447,10 +448,9 @@ class ExportArm { tempImages.push(temp); raw.packed_assets.push({ name: assets[i].file, - bytes: Bytes.ofData(assets[i].file.endsWith(".jpg") ? - Krom.encodeJpg(temp.getPixels().getData(), temp.width, temp.height, 0, 80) : - Krom.encodePng(temp.getPixels().getData(), temp.width, temp.height, 0) - ) + bytes: assets[i].file.endsWith(".jpg") ? + Krom.encodeJpg(temp.getPixels(), temp.width, temp.height, 0, 80) : + Krom.encodePng(temp.getPixels(), temp.width, temp.height, 0) }); } } @@ -465,8 +465,8 @@ class ExportArm { version: Manifest.version, swatches: Project.raw.swatches }; - var bytes = ArmPack.encode(raw); - Krom.fileSaveBytes(path, bytes.getData(), bytes.length + 1); + var buffer = ArmPack.encode(raw); + Krom.fileSaveBytes(path, buffer, buffer.byteLength + 1); } static function vec3f32(v: iron.math.Vec4): js.lib.Float32Array { diff --git a/base/Sources/arm/io/ExportGpl.hx b/base/Sources/arm/io/ExportGpl.hx index fd46cb97..d28fd8a5 100644 --- a/base/Sources/arm/io/ExportGpl.hx +++ b/base/Sources/arm/io/ExportGpl.hx @@ -1,22 +1,20 @@ package arm.io; -import haxe.io.BytesOutput; import arm.ProjectFormat; class ExportGpl { public static function run(path: String, name: String, swatches: Array) { - var o = new BytesOutput(); - o.bigEndian = false; - o.writeString("GIMP Palette\n"); - o.writeString("Name: " + name + "\n"); - o.writeString("# armorpaint.org\n"); - o.writeString("#\n"); + var o = ""; + o += "GIMP Palette\n"; + o += "Name: " + name + "\n"; + o += "# armorpaint.org\n"; + o += "#\n"; for (swatch in swatches) { - o.writeString(Std.string(swatch.base.Rb) + " " + Std.string(swatch.base.Gb) + " " + Std.string(swatch.base.Bb) + "\n"); + o += Std.string(swatch.base.Rb) + " " + Std.string(swatch.base.Gb) + " " + Std.string(swatch.base.Bb) + "\n"; } - Krom.fileSaveBytes(path, o.getBytes().getData(), o.getBytes().length); + Krom.fileSaveBytes(path, kha.System.stringToBuffer(o), o.length); } } diff --git a/base/Sources/arm/io/ExportObj.hx b/base/Sources/arm/io/ExportObj.hx index 4a0bcf70..c9bdc43e 100644 --- a/base/Sources/arm/io/ExportObj.hx +++ b/base/Sources/arm/io/ExportObj.hx @@ -1,15 +1,19 @@ package arm.io; -import haxe.io.BytesOutput; import js.lib.Int16Array; import iron.object.MeshObject; class ExportObj { + static function writeString(out: Array, str: String) { + for (i in 0...str.length) { + out.push(str.charCodeAt(i)); + } + } + public static function run(path: String, paintObjects: Array, applyDisplacement = false) { - var o = new BytesOutput(); - o.bigEndian = false; - o.writeString("# armorpaint.org\n"); + var o: Array = []; + writeString(o, "# armorpaint.org\n"); var poff = 0; var noff = 0; @@ -102,31 +106,31 @@ class ExportObj { // } } - o.writeString("o " + p.name + "\n"); + writeString(o, "o " + p.name + "\n"); for (i in 0...pi) { - o.writeString("v "); - o.writeString(posa2[i * 3] * sc + ""); - o.writeString(" "); - o.writeString(posa2[i * 3 + 2] * sc + ""); - o.writeString(" "); - o.writeString(-posa2[i * 3 + 1] * sc + ""); - o.writeString("\n"); + writeString(o, "v "); + writeString(o, posa2[i * 3] * sc + ""); + writeString(o, " "); + writeString(o, posa2[i * 3 + 2] * sc + ""); + writeString(o, " "); + writeString(o, -posa2[i * 3 + 1] * sc + ""); + writeString(o, "\n"); } for (i in 0...ni) { - o.writeString("vn "); - o.writeString(nora2[i * 3] * inv + ""); - o.writeString(" "); - o.writeString(nora2[i * 3 + 2] * inv + ""); - o.writeString(" "); - o.writeString(-nora2[i * 3 + 1] * inv + ""); - o.writeString("\n"); + writeString(o, "vn "); + writeString(o, nora2[i * 3] * inv + ""); + writeString(o, " "); + writeString(o, nora2[i * 3 + 2] * inv + ""); + writeString(o, " "); + writeString(o, -nora2[i * 3 + 1] * inv + ""); + writeString(o, "\n"); } for (i in 0...ti) { - o.writeString("vt "); - o.writeString(texa2[i * 2] * inv + ""); - o.writeString(" "); - o.writeString(1.0 - texa2[i * 2 + 1] * inv + ""); - o.writeString("\n"); + writeString(o, "vt "); + writeString(o, texa2[i * 2] * inv + ""); + writeString(o, " "); + writeString(o, 1.0 - texa2[i * 2 + 1] * inv + ""); + writeString(o, "\n"); } var inda = mesh.index_arrays[0].values; @@ -140,25 +144,25 @@ class ExportObj { var ti1 = texmap.get(inda[i * 3 ]) + 1 + toff; var ti2 = texmap.get(inda[i * 3 + 1]) + 1 + toff; var ti3 = texmap.get(inda[i * 3 + 2]) + 1 + toff; - o.writeString("f "); - o.writeString(pi1 + ""); - o.writeString("/"); - o.writeString(ti1 + ""); - o.writeString("/"); - o.writeString(ni1 + ""); - o.writeString(" "); - o.writeString(pi2 + ""); - o.writeString("/"); - o.writeString(ti2 + ""); - o.writeString("/"); - o.writeString(ni2 + ""); - o.writeString(" "); - o.writeString(pi3 + ""); - o.writeString("/"); - o.writeString(ti3 + ""); - o.writeString("/"); - o.writeString(ni3 + ""); - o.writeString("\n"); + writeString(o, "f "); + writeString(o, pi1 + ""); + writeString(o, "/"); + writeString(o, ti1 + ""); + writeString(o, "/"); + writeString(o, ni1 + ""); + writeString(o, " "); + writeString(o, pi2 + ""); + writeString(o, "/"); + writeString(o, ti2 + ""); + writeString(o, "/"); + writeString(o, ni2 + ""); + writeString(o, " "); + writeString(o, pi3 + ""); + writeString(o, "/"); + writeString(o, ti3 + ""); + writeString(o, "/"); + writeString(o, ni3 + ""); + writeString(o, "\n"); } poff += pi; noff += ni; @@ -167,6 +171,7 @@ class ExportObj { if (!path.endsWith(".obj")) path += ".obj"; - Krom.fileSaveBytes(path, o.getBytes().getData(), o.getBytes().length); + var b = js.lib.Uint8Array.from(o).buffer; + Krom.fileSaveBytes(path, b, b.byteLength); } } diff --git a/base/Sources/arm/io/ExportTexture.hx b/base/Sources/arm/io/ExportTexture.hx index b09a7e70..4d4caf60 100644 --- a/base/Sources/arm/io/ExportTexture.hx +++ b/base/Sources/arm/io/ExportTexture.hx @@ -2,8 +2,6 @@ package arm.io; #if (is_paint || is_lab) -import haxe.io.Bytes; -import haxe.io.BytesOutput; import kha.Image; import arm.ui.UIFiles; import arm.ui.BoxExport; @@ -291,11 +289,11 @@ class ExportTexture { var texpaint_pack = arm.logic.BrushOutputNode.inst.texpaint_pack; #end - var pixpaint: Bytes = null; - var pixpaint_nor: Bytes = null; - var pixpaint_pack: Bytes = null; + var pixpaint: js.lib.ArrayBuffer = null; + var pixpaint_nor: js.lib.ArrayBuffer = null; + var pixpaint_pack: js.lib.ArrayBuffer = null; var preset = BoxExport.preset; - var pix: Bytes = null; + var pix: js.lib.ArrayBuffer = null; for (t in preset.textures) { for (c in t.channels) { @@ -334,26 +332,26 @@ class ExportTexture { writeTexture(path + Path.sep + f + tex_name + ext, pixpaint, 2, 3); } else { - if (pix == null) pix = Bytes.alloc(textureSizeX * textureSizeY * 4 * Std.int(bits / 8)); + if (pix == null) pix = new js.lib.ArrayBuffer(textureSizeX * textureSizeY * 4 * Std.int(bits / 8)); for (i in 0...4) { var c = t.channels[i]; - if (c == "base_r") copyChannel(pixpaint, 0, pix, i, t.color_space == "linear"); - else if (c == "base_g") copyChannel(pixpaint, 1, pix, i, t.color_space == "linear"); - else if (c == "base_b") copyChannel(pixpaint, 2, pix, i, t.color_space == "linear"); - else if (c == "height") copyChannel(pixpaint_pack, 3, pix, i, t.color_space == "linear"); - else if (c == "metal") copyChannel(pixpaint_pack, 2, pix, i, t.color_space == "linear"); - else if (c == "nor_r") copyChannel(pixpaint_nor, 0, pix, i, t.color_space == "linear"); - else if (c == "nor_g") copyChannel(pixpaint_nor, 1, pix, i, t.color_space == "linear"); - else if (c == "nor_g_directx") copyChannelInv(pixpaint_nor, 1, pix, i, t.color_space == "linear"); - else if (c == "nor_b") copyChannel(pixpaint_nor, 2, pix, i, t.color_space == "linear"); - else if (c == "occ") copyChannel(pixpaint_pack, 0, pix, i, t.color_space == "linear"); - else if (c == "opac") copyChannel(pixpaint, 3, pix, i, t.color_space == "linear"); - else if (c == "rough") copyChannel(pixpaint_pack, 1, pix, i, t.color_space == "linear"); - else if (c == "smooth") copyChannelInv(pixpaint_pack, 1, pix, i, t.color_space == "linear"); - else if (c == "emis") extractChannel(pixpaint_nor, 3, pix, i, 3, 1, t.color_space == "linear"); - else if (c == "subs") extractChannel(pixpaint_nor, 3, pix, i, 3, 2, t.color_space == "linear"); - else if (c == "0.0") setChannel(0, pix, i); - else if (c == "1.0") setChannel(255, pix, i); + if (c == "base_r") copyChannel(new js.lib.DataView(pixpaint), 0, new js.lib.DataView(pix), i, t.color_space == "linear"); + else if (c == "base_g") copyChannel(new js.lib.DataView(pixpaint), 1, new js.lib.DataView(pix), i, t.color_space == "linear"); + else if (c == "base_b") copyChannel(new js.lib.DataView(pixpaint), 2, new js.lib.DataView(pix), i, t.color_space == "linear"); + else if (c == "height") copyChannel(new js.lib.DataView(pixpaint_pack), 3, new js.lib.DataView(pix), i, t.color_space == "linear"); + else if (c == "metal") copyChannel(new js.lib.DataView(pixpaint_pack), 2, new js.lib.DataView(pix), i, t.color_space == "linear"); + else if (c == "nor_r") copyChannel(new js.lib.DataView(pixpaint_nor), 0, new js.lib.DataView(pix), i, t.color_space == "linear"); + else if (c == "nor_g") copyChannel(new js.lib.DataView(pixpaint_nor), 1, new js.lib.DataView(pix), i, t.color_space == "linear"); + else if (c == "nor_g_directx") copyChannelInv(new js.lib.DataView(pixpaint_nor), 1, new js.lib.DataView(pix), i, t.color_space == "linear"); + else if (c == "nor_b") copyChannel(new js.lib.DataView(pixpaint_nor), 2, new js.lib.DataView(pix), i, t.color_space == "linear"); + else if (c == "occ") copyChannel(new js.lib.DataView(pixpaint_pack), 0, new js.lib.DataView(pix), i, t.color_space == "linear"); + else if (c == "opac") copyChannel(new js.lib.DataView(pixpaint), 3, new js.lib.DataView(pix), i, t.color_space == "linear"); + else if (c == "rough") copyChannel(new js.lib.DataView(pixpaint_pack), 1, new js.lib.DataView(pix), i, t.color_space == "linear"); + else if (c == "smooth") copyChannelInv(new js.lib.DataView(pixpaint_pack), 1, new js.lib.DataView(pix), i, t.color_space == "linear"); + else if (c == "emis") extractChannel(new js.lib.DataView(pixpaint_nor), 3, new js.lib.DataView(pix), i, 3, 1, t.color_space == "linear"); + else if (c == "subs") extractChannel(new js.lib.DataView(pixpaint_nor), 3, new js.lib.DataView(pix), i, 3, 2, t.color_space == "linear"); + else if (c == "0.0") setChannel(0, new js.lib.DataView(pix), i); + else if (c == "1.0") setChannel(255, new js.lib.DataView(pix), i); } writeTexture(path + Path.sep + f + tex_name + ext, pix, 3); } @@ -365,7 +363,7 @@ class ExportTexture { @:privateAccess texpaint_pack.pixels = null; } - static function writeTexture(file: String, pixels: Bytes, type = 1, off = 0) { + static function writeTexture(file: String, pixels: js.lib.ArrayBuffer, type = 1, off = 0) { var resX = Config.getTextureResX(); var resY = Config.getTextureResY(); var bitsHandle = App.bitsHandle.position; @@ -393,49 +391,48 @@ class ExportTexture { } if (bits == 8 && Context.raw.formatType == FormatPng) { - Krom.writePng(file, pixels.getData(), resX, resY, format); + Krom.writePng(file, pixels, resX, resY, format); } else if (bits == 8 && Context.raw.formatType == FormatJpg) { - Krom.writeJpg(file, pixels.getData(), resX, resY, format, Std.int(Context.raw.formatQuality)); + Krom.writeJpg(file, pixels, resX, resY, format, Std.int(Context.raw.formatQuality)); } else { // Exr - var out = new BytesOutput(); - var writer = new arm.format.ExrWriter(out, resX, resY, pixels, bits, type, off); - Krom.fileSaveBytes(file, out.getBytes().getData(), out.getBytes().length); + var b = arm.format.ExrWriter.run(resX, resY, pixels, bits, type, off); + Krom.fileSaveBytes(file, b, b.byteLength); } } - static function copyChannel(from: Bytes, fromChannel: Int, to: Bytes, toChannel: Int, linear = true) { - for (i in 0...Std.int(to.length / 4)) { - to.set(i * 4 + toChannel, from.get(i * 4 + fromChannel)); + static function copyChannel(from: js.lib.DataView, fromChannel: Int, to: js.lib.DataView, toChannel: Int, linear = true) { + for (i in 0...Std.int(to.byteLength / 4)) { + to.setUint8(i * 4 + toChannel, from.getUint8(i * 4 + fromChannel)); } if (!linear) toSrgb(to, toChannel); } - static function copyChannelInv(from: Bytes, fromChannel: Int, to: Bytes, toChannel: Int, linear = true) { - for (i in 0...Std.int(to.length / 4)) { - to.set(i * 4 + toChannel, 255 - from.get(i * 4 + fromChannel)); + static function copyChannelInv(from: js.lib.DataView, fromChannel: Int, to: js.lib.DataView, toChannel: Int, linear = true) { + for (i in 0...Std.int(to.byteLength / 4)) { + to.setUint8(i * 4 + toChannel, 255 - from.getUint8(i * 4 + fromChannel)); } if (!linear) toSrgb(to, toChannel); } - static function extractChannel(from: Bytes, fromChannel: Int, to: Bytes, toChannel: Int, step: Int, mask: Int, linear = true) { - for (i in 0...Std.int(to.length / 4)) { - to.set(i * 4 + toChannel, from.get(i * 4 + fromChannel) % step == mask ? 255 : 0); + static function extractChannel(from: js.lib.DataView, fromChannel: Int, to: js.lib.DataView, toChannel: Int, step: Int, mask: Int, linear = true) { + for (i in 0...Std.int(to.byteLength / 4)) { + to.setUint8(i * 4 + toChannel, from.getUint8(i * 4 + fromChannel) % step == mask ? 255 : 0); } if (!linear) toSrgb(to, toChannel); } - static function setChannel(value: Int, to: Bytes, toChannel: Int, linear = true) { - for (i in 0...Std.int(to.length / 4)) { - to.set(i * 4 + toChannel, value); + static function setChannel(value: Int, to: js.lib.DataView, toChannel: Int, linear = true) { + for (i in 0...Std.int(to.byteLength / 4)) { + to.setUint8(i * 4 + toChannel, value); } if (!linear) toSrgb(to, toChannel); } - static function toSrgb(to: Bytes, toChannel: Int) { - for (i in 0...Std.int(to.length / 4)) { - to.set(i * 4 + toChannel, Std.int(Math.pow(to.get(i * 4 + toChannel) / 255, gamma) * 255)); + static function toSrgb(to: js.lib.DataView, toChannel: Int) { + for (i in 0...Std.int(to.byteLength / 4)) { + to.setUint8(i * 4 + toChannel, Std.int(Math.pow(to.getUint8(i * 4 + toChannel) / 255, gamma) * 255)); } } } diff --git a/base/Sources/arm/io/ImportArm.hx b/base/Sources/arm/io/ImportArm.hx index b9e01cd6..e6510d73 100644 --- a/base/Sources/arm/io/ImportArm.hx +++ b/base/Sources/arm/io/ImportArm.hx @@ -1,8 +1,5 @@ package arm.io; -import haxe.io.Bytes; -import kha.Window; -import kha.Blob; import kha.Image; import zui.Zui.Nodes; import zui.Zui.TNodeCanvas; @@ -38,8 +35,8 @@ import arm.shader.MakeMaterial; class ImportArm { public static function runProject(path: String) { - Data.getBlob(path, function(b: Blob) { - var project: TProjectFormat = ArmPack.decode(b.toBytes()); + Data.getBlob(path, function(b: js.lib.ArrayBuffer) { + var project: TProjectFormat = ArmPack.decode(b); #if (is_paint || is_sculpt) if (project.version != null && project.layer_datas == null) { @@ -71,9 +68,9 @@ class ImportArm { Project.filepath = path; UIFiles.filename = path.substring(path.lastIndexOf(Path.sep) + 1, path.lastIndexOf(".")); #if (krom_android || krom_ios) - Window.get().title = UIFiles.filename; + kha.System.title = UIFiles.filename; #else - Window.get().title = UIFiles.filename + " - " + Manifest.title; + kha.System.title = UIFiles.filename + " - " + Manifest.title; #end #if (is_paint || is_sculpt) @@ -218,14 +215,14 @@ class ImportArm { }); rts.get("texpaint_blend0").raw.width = Config.getTextureResX(); rts.get("texpaint_blend0").raw.height = Config.getTextureResY(); - rts.get("texpaint_blend0").image = Image.createRenderTarget(Config.getTextureResX(), Config.getTextureResY(), TextureFormat.L8, DepthStencilFormat.NoDepthAndStencil); + rts.get("texpaint_blend0").image = Image.createRenderTarget(Config.getTextureResX(), Config.getTextureResY(), TextureFormat.R8, DepthStencilFormat.NoDepthAndStencil); var _texpaint_blend1 = rts.get("texpaint_blend1").image; App.notifyOnNextFrame(function() { _texpaint_blend1.unload(); }); rts.get("texpaint_blend1").raw.width = Config.getTextureResX(); rts.get("texpaint_blend1").raw.height = Config.getTextureResY(); - rts.get("texpaint_blend1").image = Image.createRenderTarget(Config.getTextureResX(), Config.getTextureResY(), TextureFormat.L8, DepthStencilFormat.NoDepthAndStencil); + rts.get("texpaint_blend1").image = Image.createRenderTarget(Config.getTextureResX(), Config.getTextureResY(), TextureFormat.R8, DepthStencilFormat.NoDepthAndStencil); Context.raw.brushBlendDirty = true; } @@ -426,8 +423,8 @@ class ImportArm { } public static function runMaterial(path: String) { - Data.getBlob(path, function(b: Blob) { - var project: TProjectFormat = ArmPack.decode(b.toBytes()); + Data.getBlob(path, function(b: js.lib.ArrayBuffer) { + var project: TProjectFormat = ArmPack.decode(b); if (project.version == null) { Data.deleteBlob(path); return; } runMaterialFromProject(project, path); }); @@ -512,8 +509,8 @@ class ImportArm { } public static function runBrush(path: String) { - Data.getBlob(path, function(b: Blob) { - var project: TProjectFormat = ArmPack.decode(b.toBytes()); + Data.getBlob(path, function(b: js.lib.ArrayBuffer) { + var project: TProjectFormat = ArmPack.decode(b); if (project.version == null) { Data.deleteBlob(path); return; } runBrushFromProject(project, path); }); @@ -562,8 +559,8 @@ class ImportArm { #end public static function runSwatches(path: String, replaceExisting = false) { - Data.getBlob(path, function(b: Blob) { - var project: TProjectFormat = ArmPack.decode(b.toBytes()); + Data.getBlob(path, function(b: js.lib.ArrayBuffer) { + var project: TProjectFormat = ArmPack.decode(b); if (project.version == null) { Data.deleteBlob(path); return; } runSwatchesFromProject(project, path, replaceExisting); }); @@ -589,12 +586,12 @@ class ImportArm { static function makePink(abs: String) { Console.error(Strings.error2() + " " + abs); - var b = Bytes.alloc(4); - b.set(0, 255); - b.set(1, 0); - b.set(2, 255); - b.set(3, 255); - var pink = Image.fromBytes(b, 1, 1); + var b = new js.lib.Uint8Array(4); + b[0] = 255; + b[1] = 0; + b[2] = 255; + b[3] = 255; + var pink = Image.fromBytes(b.buffer, 1, 1); Data.cachedImages.set(abs, pink); } diff --git a/base/Sources/arm/io/ImportBlendMaterial.hx b/base/Sources/arm/io/ImportBlendMaterial.hx index 358b1950..361bc07b 100644 --- a/base/Sources/arm/io/ImportBlendMaterial.hx +++ b/base/Sources/arm/io/ImportBlendMaterial.hx @@ -1,6 +1,5 @@ package arm.io; -import kha.Blob; import iron.data.Data; import zui.Zui.Nodes; import zui.Zui.TNode; @@ -17,7 +16,7 @@ import arm.data.MaterialSlot; class ImportBlendMaterial { public static function run(path: String) { - Data.getBlob(path, function(b: Blob) { + Data.getBlob(path, function(b: js.lib.ArrayBuffer) { var bl = new BlendParser(b); if (bl.dna == null) { Console.error(Strings.error3()); diff --git a/base/Sources/arm/io/ImportBlendMesh.hx b/base/Sources/arm/io/ImportBlendMesh.hx index 8dea7409..18ebbf3a 100644 --- a/base/Sources/arm/io/ImportBlendMesh.hx +++ b/base/Sources/arm/io/ImportBlendMesh.hx @@ -1,6 +1,5 @@ package arm.io; -import kha.Blob; import js.lib.Uint32Array; import js.lib.Float32Array; import js.lib.Int16Array; @@ -14,7 +13,7 @@ class ImportBlendMesh { static inline var eps = 1.0 / 32767; public static function run(path: String, replaceExisting = true) { - Data.getBlob(path, function(b: Blob) { + Data.getBlob(path, function(b: js.lib.ArrayBuffer) { var bl = new BlendParser(b); if (bl.dna == null) { Console.error(Strings.error3()); diff --git a/base/Sources/arm/io/ImportEnvmap.hx b/base/Sources/arm/io/ImportEnvmap.hx index 74f21704..cd222627 100644 --- a/base/Sources/arm/io/ImportEnvmap.hx +++ b/base/Sources/arm/io/ImportEnvmap.hx @@ -125,7 +125,7 @@ class ImportEnvmap { // https://ndotl.wordpress.com/2015/03/07/pbr-cubemap-filtering // https://seblagarde.wordpress.com/2012/06/10/amd-cubemapgen-for-physically-based-rendering - static function getSphericalHarmonics(source: haxe.io.Bytes, sourceWidth: Int, sourceHeight: Int): Float32Array { + static function getSphericalHarmonics(source: js.lib.ArrayBuffer, sourceWidth: Int, sourceHeight: Int): Float32Array { var sh = new Float32Array(9 * 3 + 1); // Align to mult of 4 - 27->28 var accum = 0.0; var weight = 1.0; @@ -134,13 +134,14 @@ class ImportEnvmap { var weight3 = weight * 15 / 17; var weight4 = weight * 5 / 68; var weight5 = weight * 15 / 68; + var view = new js.lib.DataView(source); for (x in 0...sourceWidth) { for (y in 0...sourceHeight) { n = reverseEquirect(x / sourceWidth, y / sourceHeight); for (i in 0...3) { - var value = source.getFloat(((x + y * sourceWidth) * 16 + i * 4)); + var value = view.getFloat32(((x + y * sourceWidth) * 16 + i * 4), true); value = Math.pow(value, 1.0 / 2.2); sh[0 + i] += value * weight1; diff --git a/base/Sources/arm/io/ImportFbx.hx b/base/Sources/arm/io/ImportFbx.hx index 246d4c11..36bcd0b8 100644 --- a/base/Sources/arm/io/ImportFbx.hx +++ b/base/Sources/arm/io/ImportFbx.hx @@ -1,13 +1,12 @@ package arm.io; -import kha.Blob; import iron.data.Data; import arm.format.FbxParser; class ImportFbx { public static function run(path: String, replaceExisting = true) { - Data.getBlob(path, function(b: Blob) { + Data.getBlob(path, function(b: js.lib.ArrayBuffer) { FbxParser.parseTransform = Context.raw.parseTransform; FbxParser.parseVCols = Context.raw.parseVCols; var obj = new FbxParser(b); diff --git a/base/Sources/arm/io/ImportGpl.hx b/base/Sources/arm/io/ImportGpl.hx index 71411105..1960cf29 100644 --- a/base/Sources/arm/io/ImportGpl.hx +++ b/base/Sources/arm/io/ImportGpl.hx @@ -1,40 +1,39 @@ package arm.io; -import haxe.io.BytesInput; +import js.lib.ArrayBuffer; +import js.lib.DataView; import kha.Color; -import kha.Blob; import iron.data.Data; class ImportGpl { public static function run(path: String, replaceExisting: Bool) { - Data.getBlob(path, function(b: Blob) { + Data.getBlob(path, function(b: ArrayBuffer) { var swatches = []; - try { - var input = new BytesInput(b.bytes); - // GIMP's color palette importer: https://gitlab.gnome.org/GNOME/gimp/-/blob/gimp-2-10/app/core/gimppalette-load.c#L39 - if (!input.readLine().startsWith("GIMP Palette")) { - Console.error(tr("Not a valid GIMP color palette")); - return; - } - var delimiter = ~/\s+/ig; - while (true) { - var line = input.readLine(); - if (line.startsWith("Name:")) continue; - else if (line.startsWith("Columns:")) continue; - else if (line.startsWith("#")) continue; - else { - var tokens = delimiter.split(line); - if (tokens.length < 3) continue; - var swatch = Project.makeSwatch(Color.fromBytes(Std.parseInt(tokens[0]), Std.parseInt(tokens[1]), Std.parseInt(tokens[2]))); - swatches.push(swatch); - } + var str = kha.System.bufferToString(b); + var lines = str.split("\n"); + + var view = new DataView(b); + // GIMP's color palette importer: https://gitlab.gnome.org/GNOME/gimp/-/blob/gimp-2-10/app/core/gimppalette-load.c#L39 + if (!lines[0].startsWith("GIMP Palette")) { + Console.error(tr("Not a valid GIMP color palette")); + return; + } + + var delimiter = ~/\s+/ig; + for (line in lines) { + if (line.startsWith("Name:")) continue; + else if (line.startsWith("Columns:")) continue; + else if (line.startsWith("#")) continue; + else { + var tokens = delimiter.split(line); + if (tokens.length < 3) continue; + var swatch = Project.makeSwatch(Color.fromBytes(Std.parseInt(tokens[0]), Std.parseInt(tokens[1]), Std.parseInt(tokens[2]))); + swatches.push(swatch); } } - catch (e: haxe.io.Eof) { - // Is thrown if end of file is reached - } + if (replaceExisting) { Project.raw.swatches = []; diff --git a/base/Sources/arm/io/ImportObj.hx b/base/Sources/arm/io/ImportObj.hx index c10f61ab..aa37c5ac 100644 --- a/base/Sources/arm/io/ImportObj.hx +++ b/base/Sources/arm/io/ImportObj.hx @@ -1,6 +1,5 @@ package arm.io; -import kha.Blob; import iron.data.Data; class ImportObj { @@ -13,10 +12,10 @@ class ImportObj { i == SplitGroup ? "g".code : "u".code; // usemtl - Data.getBlob(path, function(b: Blob) { + Data.getBlob(path, function(b: js.lib.ArrayBuffer) { if (isUdim) { - var part = Krom.io_obj_parse(b.bytes.getData(), splitCode, 0, isUdim); + var part = Krom.io_obj_parse(b, splitCode, 0, isUdim); var name = part.name; for (i in 0...part.udims.length) { if (part.udims[i].length == 0) continue; @@ -29,10 +28,10 @@ class ImportObj { } else { var parts: Array = []; - var part = Krom.io_obj_parse(b.bytes.getData(), splitCode, 0, false); + var part = Krom.io_obj_parse(b, splitCode, 0, false); parts.push(part); while (part.has_next) { - part = Krom.io_obj_parse(b.bytes.getData(), splitCode, part.pos, false); + part = Krom.io_obj_parse(b, splitCode, part.pos, false); // This part does not contain faces (may contain lines only) if (part.inda.length == 0) { continue; diff --git a/base/Sources/arm/logic/ColorNode.hx b/base/Sources/arm/logic/ColorNode.hx index c0aa166c..a319bbcc 100644 --- a/base/Sources/arm/logic/ColorNode.hx +++ b/base/Sources/arm/logic/ColorNode.hx @@ -22,11 +22,12 @@ class ColorNode extends LogicNode { override function getAsImage(from: Int, done: kha.Image->Void) { if (inputs.length > 0) { inputs[0].getAsImage(done); return; } if (image != null) image.unload(); - var b = haxe.io.Bytes.alloc(16); - b.setFloat(0, value.x); - b.setFloat(4, value.y); - b.setFloat(8, value.z); - b.setFloat(12, value.w); + var b = new js.lib.ArrayBuffer(16); + var v = new js.lib.DataView(b); + v.setFloat32(0, value.x, true); + v.setFloat32(4, value.y, true); + v.setFloat32(8, value.z, true); + v.setFloat32(12, value.w, true); image = kha.Image.fromBytes(b, 1, 1, kha.Image.TextureFormat.RGBA128); done(image); } diff --git a/base/Sources/arm/logic/FloatNode.hx b/base/Sources/arm/logic/FloatNode.hx index f8d3a7ed..8dcbd242 100644 --- a/base/Sources/arm/logic/FloatNode.hx +++ b/base/Sources/arm/logic/FloatNode.hx @@ -24,11 +24,12 @@ class FloatNode extends LogicNode { override function getAsImage(from: Int, done: kha.Image->Void) { if (inputs.length > 0) { inputs[0].getAsImage(done); return; } if (image != null) image.unload(); - var b = haxe.io.Bytes.alloc(16); - b.setFloat(0, value); - b.setFloat(4, value); - b.setFloat(8, value); - b.setFloat(12, 1.0); + var b = new js.lib.ArrayBuffer(16); + var v = new js.lib.DataView(b); + v.setFloat32(0, value, true); + v.setFloat32(4, value, true); + v.setFloat32(8, value, true); + v.setFloat32(12, 1.0, true); image = kha.Image.fromBytes(b, 1, 1, kha.Image.TextureFormat.RGBA128); done(image); } diff --git a/base/Sources/arm/logic/VectorNode.hx b/base/Sources/arm/logic/VectorNode.hx index 55ec242d..3dc2d9d5 100644 --- a/base/Sources/arm/logic/VectorNode.hx +++ b/base/Sources/arm/logic/VectorNode.hx @@ -41,11 +41,12 @@ class VectorNode extends LogicNode { inputs[1].get(function(y: Float) { inputs[2].get(function(z: Float) { if (image != null) image.unload(); - var b = haxe.io.Bytes.alloc(16); - b.setFloat(0, untyped inputs[0].node.value); - b.setFloat(4, untyped inputs[1].node.value); - b.setFloat(8, untyped inputs[2].node.value); - b.setFloat(12, 1.0); + var b = new js.lib.ArrayBuffer(16); + var v = new js.lib.DataView(b); + v.setFloat32(0, untyped inputs[0].node.value, true); + v.setFloat32(4, untyped inputs[1].node.value, true); + v.setFloat32(8, untyped inputs[2].node.value, true); + v.setFloat32(12, 1.0, true); image = kha.Image.fromBytes(b, 1, 1, kha.Image.TextureFormat.RGBA128); done(image); }); diff --git a/base/Sources/arm/render/RenderPathBase.hx b/base/Sources/arm/render/RenderPathBase.hx index a1cd7c0e..83908af5 100644 --- a/base/Sources/arm/render/RenderPathBase.hx +++ b/base/Sources/arm/render/RenderPathBase.hx @@ -155,7 +155,7 @@ class RenderPathBase { } public static function isCached(): Bool { - if (System.windowWidth() == 0 || System.windowHeight() == 0) return true; + if (System.width == 0 || System.height == 0) return true; var mouse = Input.getMouse(); var mx = lastX; diff --git a/base/Sources/arm/render/RenderPathDeferred.hx b/base/Sources/arm/render/RenderPathDeferred.hx index d39ee922..087acbce 100644 --- a/base/Sources/arm/render/RenderPathDeferred.hx +++ b/base/Sources/arm/render/RenderPathDeferred.hx @@ -99,9 +99,10 @@ class RenderPathDeferred { t.height = 1; t.format = "R8"; var rt = new RenderTarget(t); - var b = haxe.io.Bytes.alloc(1); - b.set(0, 255); - rt.image = kha.Image.fromBytes(b, t.width, t.height, kha.Image.TextureFormat.L8); + var b = new js.lib.ArrayBuffer(1); + var v = new js.lib.DataView(b); + v.setUint8(0, 255); + rt.image = kha.Image.fromBytes(b, t.width, t.height, kha.Image.TextureFormat.R8); path.renderTargets.set(t.name, rt); } { @@ -111,11 +112,12 @@ class RenderPathDeferred { t.height = 1; t.format = "RGBA32"; var rt = new RenderTarget(t); - var b = haxe.io.Bytes.alloc(4); - b.set(0, 0); - b.set(1, 0); - b.set(2, 0); - b.set(3, 0); + var b = new js.lib.ArrayBuffer(4); + var v = new js.lib.DataView(b); + v.setUint8(0, 0); + v.setUint8(1, 0); + v.setUint8(2, 0); + v.setUint8(3, 0); rt.image = kha.Image.fromBytes(b, t.width, t.height, kha.Image.TextureFormat.RGBA32); path.renderTargets.set(t.name, rt); } diff --git a/base/Sources/arm/render/RenderPathRaytrace.hx b/base/Sources/arm/render/RenderPathRaytrace.hx index 4f810244..cfa9337e 100644 --- a/base/Sources/arm/render/RenderPathRaytrace.hx +++ b/base/Sources/arm/render/RenderPathRaytrace.hx @@ -148,12 +148,12 @@ class RenderPathRaytrace { Scene.active.embedData("bnoise_rank.k", function() {}); } - iron.data.Data.getBlob(shaderName, function(shader: kha.Blob) { + iron.data.Data.getBlob(shaderName, function(shader: js.lib.ArrayBuffer) { if (build) buildData(); var bnoise_sobol = Scene.active.embedded.get("bnoise_sobol.k"); var bnoise_scramble = Scene.active.embedded.get("bnoise_scramble.k"); var bnoise_rank = Scene.active.embedded.get("bnoise_rank.k"); - Krom.raytraceInit(shader.bytes.getData(), untyped vb.buffer, untyped ib.buffer, vb_scale); + Krom.raytraceInit(shader, vb.buffer_, ib.buffer_, vb_scale); }); } diff --git a/base/Sources/arm/ui/BoxExport.hx b/base/Sources/arm/ui/BoxExport.hx index c603a104..426a0e82 100644 --- a/base/Sources/arm/ui/BoxExport.hx +++ b/base/Sources/arm/ui/BoxExport.hx @@ -455,8 +455,8 @@ class BoxExport { static function parsePreset() { var file = "export_presets/" + files[hpreset.position] + ".json"; - iron.data.Data.getBlob(file, function(blob: kha.Blob) { - preset = haxe.Json.parse(blob.toString()); + iron.data.Data.getBlob(file, function(blob: js.lib.ArrayBuffer) { + preset = haxe.Json.parse(kha.System.bufferToString(blob)); iron.data.Data.deleteBlob("export_presets/" + file); }); } diff --git a/base/Sources/arm/ui/BoxPreferences.hx b/base/Sources/arm/ui/BoxPreferences.hx index 7ead9e74..535ed7bf 100644 --- a/base/Sources/arm/ui/BoxPreferences.hx +++ b/base/Sources/arm/ui/BoxPreferences.hx @@ -114,8 +114,8 @@ class BoxPreferences { } if (UIMenu.menuButton(ui, tr("Import..."))) { UIFiles.show("json", false, false, function(path: String) { - Data.getBlob(path, function(b: kha.Blob) { - var raw = Json.parse(b.toString()); + Data.getBlob(path, function(b: js.lib.ArrayBuffer) { + var raw = Json.parse(kha.System.bufferToString(b)); iron.App.notifyOnInit(function() { ui.t.ELEMENT_H = App.defaultElementH; Config.importFrom(raw); @@ -214,12 +214,12 @@ class BoxPreferences { if (worldColor != h.color) { worldColor = h.color; - var b = Bytes.alloc(4); - b.set(0, worldColor.Rb); - b.set(1, worldColor.Gb); - b.set(2, worldColor.Bb); - b.set(3, 255); - Context.raw.emptyEnvmap = kha.Image.fromBytes(b, 1, 1); + var b = new js.lib.Uint8Array(4); + b[0] = worldColor.Rb; + b[1] = worldColor.Gb; + b[2] = worldColor.Bb; + b[3] = 255; + Context.raw.emptyEnvmap = kha.Image.fromBytes(b.buffer, 1, 1); Context.raw.ddirty = 2; if (!Context.raw.showEnvmap) { iron.Scene.active.world.envmap = Context.raw.emptyEnvmap; @@ -633,8 +633,8 @@ plugin.drawUI = function(ui) { File.start(path); } if (UIMenu.menuButton(ui, tr("Edit in Script Tab"))) { - iron.data.Data.getBlob("plugins/" + f, function(blob: kha.Blob) { - TabScript.hscript.text = blob.toString(); + iron.data.Data.getBlob("plugins/" + f, function(blob: js.lib.ArrayBuffer) { + TabScript.hscript.text = kha.System.bufferToString(blob); iron.data.Data.deleteBlob("plugins/" + f); Console.info(tr("Script opened")); }); diff --git a/base/Sources/arm/ui/BoxProjects.hx b/base/Sources/arm/ui/BoxProjects.hx index 20a97ff5..1be27fd9 100644 --- a/base/Sources/arm/ui/BoxProjects.hx +++ b/base/Sources/arm/ui/BoxProjects.hx @@ -65,13 +65,13 @@ class BoxProjects { j = 0; } } - kha.Window.get().title = title; + kha.System.title = title; } ui.endSticky(); ui.separator(3, false); var slotw = Std.int(150 * ui.SCALE()); - var num = Std.int(kha.System.windowWidth() / slotw); + var num = Std.int(kha.System.width / slotw); var recent_projects = Config.raw.recent_projects; var show_asset_names = true; @@ -243,10 +243,10 @@ class BoxProjects { } static function alignToFullScreen() { - @:privateAccess UIBox.modalW = Std.int(kha.System.windowWidth() / App.uiBox.SCALE()); - @:privateAccess UIBox.modalH = Std.int(kha.System.windowHeight() / App.uiBox.SCALE()); - var appw = kha.System.windowWidth(); - var apph = kha.System.windowHeight(); + @:privateAccess UIBox.modalW = Std.int(kha.System.width / App.uiBox.SCALE()); + @:privateAccess UIBox.modalH = Std.int(kha.System.height / App.uiBox.SCALE()); + var appw = kha.System.width; + var apph = kha.System.height; var mw = appw; var mh = apph; UIBox.hwnd.dragX = Std.int(-appw / 2 + mw / 2); diff --git a/base/Sources/arm/ui/TabFonts.hx b/base/Sources/arm/ui/TabFonts.hx index 069bce73..cda4697d 100644 --- a/base/Sources/arm/ui/TabFonts.hx +++ b/base/Sources/arm/ui/TabFonts.hx @@ -32,7 +32,7 @@ class TabFonts { ui.endSticky(); ui.separator(3, false); - var statusw = kha.System.windowWidth() - UIToolbar.inst.toolbarw - Config.raw.layout[LayoutSidebarW]; + var statusw = kha.System.width - UIToolbar.inst.toolbarw - Config.raw.layout[LayoutSidebarW]; var slotw = Std.int(51 * ui.SCALE()); var num = Std.int(statusw / slotw); diff --git a/base/Sources/arm/ui/TabScript.hx b/base/Sources/arm/ui/TabScript.hx index b0ded9a4..74f57f1c 100644 --- a/base/Sources/arm/ui/TabScript.hx +++ b/base/Sources/arm/ui/TabScript.hx @@ -1,7 +1,6 @@ package arm.ui; import haxe.io.Bytes; -import kha.Blob; import zui.Zui; import iron.data.Data; import arm.sys.Path; @@ -37,8 +36,8 @@ class TabScript { } if (ui.button(tr("Import"))) { UIFiles.show("js", false, false, function(path: String) { - Data.getBlob(path, function(b: Blob) { - hscript.text = b.toString(); + Data.getBlob(path, function(b: js.lib.ArrayBuffer) { + hscript.text = kha.System.bufferToString(b); Data.deleteBlob(path); }); }); @@ -73,8 +72,8 @@ class TabScript { static function getTextColoring(): TTextColoring { if (textColoring == null) { - Data.getBlob("text_coloring.json", function(blob: Blob) { - textColoring = haxe.Json.parse(blob.toString()); + Data.getBlob("text_coloring.json", function(blob: js.lib.ArrayBuffer) { + textColoring = haxe.Json.parse(kha.System.bufferToString(blob)); textColoring.default_color = Std.int(textColoring.default_color); for (coloring in textColoring.colorings) coloring.color = Std.int(coloring.color); }); diff --git a/base/Sources/arm/ui/TabSwatches.hx b/base/Sources/arm/ui/TabSwatches.hx index 98a620c9..20751e53 100644 --- a/base/Sources/arm/ui/TabSwatches.hx +++ b/base/Sources/arm/ui/TabSwatches.hx @@ -11,12 +11,12 @@ class TabSwatches { public static function get_empty() { if (empty == null) { - var b = haxe.io.Bytes.alloc(4); - b.set(0, 255); - b.set(1, 255); - b.set(2, 255); - b.set(3, 255); - empty = kha.Image.fromBytes(b, 1, 1); + var b = new js.lib.Uint8Array(4); + b[0] = 255; + b[1] = 255; + b[2] = 255; + b[3] = 255; + empty = kha.Image.fromBytes(b.buffer, 1, 1); } return empty; } @@ -53,7 +53,7 @@ class TabSwatches { Project.importSwatches(false); } }, 2); - } + } if (ui.isHovered) ui.tooltip(tr("Import swatches")); if (ui.button(tr("Export"))) Project.exportSwatches(); diff --git a/base/Sources/arm/ui/TabTextures.hx b/base/Sources/arm/ui/TabTextures.hx index ccc14d6f..c8c4be3f 100644 --- a/base/Sources/arm/ui/TabTextures.hx +++ b/base/Sources/arm/ui/TabTextures.hx @@ -42,10 +42,10 @@ class TabTextures { if (Project.assets.length > 0) { #if (is_paint || is_sculpt) - var statusw = kha.System.windowWidth() - UIToolbar.inst.toolbarw - Config.raw.layout[LayoutSidebarW]; + var statusw = kha.System.width - UIToolbar.inst.toolbarw - Config.raw.layout[LayoutSidebarW]; #end #if is_lab - var statusw = kha.System.windowWidth(); + var statusw = kha.System.width; #end var slotw = Std.int(52 * ui.SCALE()); @@ -130,7 +130,7 @@ class TabTextures { var f = UIFiles.filename; if (f == "") f = tr("untitled"); if (!f.endsWith(".png")) f += ".png"; - Krom.writePng(path + Path.sep + f, target.getPixels().getData(), target.width, target.height, 0); + Krom.writePng(path + Path.sep + f, target.getPixels(), target.width, target.height, 0); target.unload(); }); }); diff --git a/base/Sources/arm/ui/UIBase.hx b/base/Sources/arm/ui/UIBase.hx index fe9995b1..cc1fc1b1 100644 --- a/base/Sources/arm/ui/UIBase.hx +++ b/base/Sources/arm/ui/UIBase.hx @@ -27,7 +27,6 @@ import arm.data.FontSlot; import arm.data.MaterialSlot; #end #if is_lab -import kha.Blob; import zui.Zui.Nodes; #end @@ -136,13 +135,13 @@ class UIBase { } if (Project.defaultCanvas == null) { // Synchronous - Data.getBlob("default_brush.arm", function(b: Blob) { + Data.getBlob("default_brush.arm", function(b: js.lib.ArrayBuffer) { Project.defaultCanvas = b; }); } Project.nodes = new Nodes(); - Project.canvas = iron.system.ArmPack.decode(Project.defaultCanvas.toBytes()); + Project.canvas = iron.system.ArmPack.decode(Project.defaultCanvas); Project.canvas.name = "Brush 1"; Context.parseBrushInputs(); @@ -156,20 +155,20 @@ class UIBase { } if (Context.raw.emptyEnvmap == null) { - var b = Bytes.alloc(4); - b.set(0, 8); - b.set(1, 8); - b.set(2, 8); - b.set(3, 255); - Context.raw.emptyEnvmap = Image.fromBytes(b, 1, 1); + var b = new js.lib.Uint8Array(4); + b[0] = 8; + b[1] = 8; + b[2] = 8; + b[3] = 255; + Context.raw.emptyEnvmap = Image.fromBytes(b.buffer, 1, 1); } if (Context.raw.previewEnvmap == null) { - var b = Bytes.alloc(4); - b.set(0, 0); - b.set(1, 0); - b.set(2, 0); - b.set(3, 255); - Context.raw.previewEnvmap = Image.fromBytes(b, 1, 1); + var b = new js.lib.Uint8Array(4); + b[0] = 0; + b[1] = 0; + b[2] = 0; + b[3] = 255; + Context.raw.previewEnvmap = Image.fromBytes(b.buffer, 1, 1); } var world = Scene.active.world; @@ -607,7 +606,7 @@ class UIBase { if (borderStarted == SideLeft) { Config.raw.layout[LayoutNodesW] -= Std.int(mouse.movementX); if (Config.raw.layout[LayoutNodesW] < 32) Config.raw.layout[LayoutNodesW] = 32; - else if (Config.raw.layout[LayoutNodesW] > System.windowWidth() * 0.7) Config.raw.layout[LayoutNodesW] = Std.int(System.windowWidth() * 0.7); + else if (Config.raw.layout[LayoutNodesW] > System.width * 0.7) Config.raw.layout[LayoutNodesW] = Std.int(System.width * 0.7); } else { // UINodes / UIView2D ratio Config.raw.layout[LayoutNodesH] -= Std.int(mouse.movementY); @@ -617,7 +616,7 @@ class UIBase { } else if (borderHandle_ptr == hwnds[TabStatus].ptr) { var my = Std.int(mouse.movementY); - if (Config.raw.layout[LayoutStatusH] - my >= UIStatus.defaultStatusH * Config.raw.window_scale && Config.raw.layout[LayoutStatusH] - my < System.windowHeight() * 0.7) { + if (Config.raw.layout[LayoutStatusH] - my >= UIStatus.defaultStatusH * Config.raw.window_scale && Config.raw.layout[LayoutStatusH] - my < System.height * 0.7) { Config.raw.layout[LayoutStatusH] -= my; } } @@ -625,7 +624,7 @@ class UIBase { if (borderStarted == SideLeft) { Config.raw.layout[LayoutSidebarW] -= Std.int(mouse.movementX); if (Config.raw.layout[LayoutSidebarW] < sidebarMiniW) Config.raw.layout[LayoutSidebarW] = sidebarMiniW; - else if (Config.raw.layout[LayoutSidebarW] > System.windowWidth() - sidebarMiniW) Config.raw.layout[LayoutSidebarW] = System.windowWidth() - sidebarMiniW; + else if (Config.raw.layout[LayoutSidebarW] > System.width - sidebarMiniW) Config.raw.layout[LayoutSidebarW] = System.width - sidebarMiniW; } else { var my = Std.int(mouse.movementY); @@ -646,7 +645,7 @@ class UIBase { if (borderStarted == SideLeft) { Config.raw.layout[LayoutNodesW] -= Std.int(mouse.movementX); if (Config.raw.layout[LayoutNodesW] < 32) Config.raw.layout[LayoutNodesW] = 32; - else if (Config.raw.layout[LayoutNodesW] > System.windowWidth() * 0.7) Config.raw.layout[LayoutNodesW] = Std.int(System.windowWidth() * 0.7); + else if (Config.raw.layout[LayoutNodesW] > System.width * 0.7) Config.raw.layout[LayoutNodesW] = Std.int(System.width * 0.7); } else { // UINodes / UIView2D ratio Config.raw.layout[LayoutNodesH] -= Std.int(mouse.movementY); @@ -656,7 +655,7 @@ class UIBase { } else if (borderHandle_ptr == hwnds[TabStatus].ptr) { var my = Std.int(mouse.movementY); - if (Config.raw.layout[LayoutStatusH] - my >= UIStatus.defaultStatusH * Config.raw.window_scale && Config.raw.layout[LayoutStatusH] - my < System.windowHeight() * 0.7) { + if (Config.raw.layout[LayoutStatusH] - my >= UIStatus.defaultStatusH * Config.raw.window_scale && Config.raw.layout[LayoutStatusH] - my < System.height * 0.7) { Config.raw.layout[LayoutStatusH] -= my; } } @@ -1123,7 +1122,7 @@ class UIBase { g.begin(false); } - if (!show || System.windowWidth() == 0 || System.windowHeight() == 0) return; + if (!show || System.width == 0 || System.height == 0) return; ui.inputEnabled = App.uiEnabled; @@ -1163,7 +1162,7 @@ class UIBase { // Tabs var mini = Config.raw.layout[LayoutSidebarW] <= sidebarMiniW; var expandButtonOffset = Config.raw.touch_ui ? Std.int(ui.ELEMENT_H() + ui.ELEMENT_OFFSET()) : 0; - tabx = System.windowWidth() - Config.raw.layout[LayoutSidebarW]; + tabx = System.width - Config.raw.layout[LayoutSidebarW]; var _SCROLL_W = ui.t.SCROLL_W; if (mini) ui.t.SCROLL_W = ui.t.SCROLL_MINI_W; @@ -1182,7 +1181,7 @@ class UIBase { if (Config.raw.touch_ui) { var width = Config.raw.layout[LayoutSidebarW]; var height = Std.int(ui.ELEMENT_H() + ui.ELEMENT_OFFSET()); - if (ui.window(Zui.handle("uibase_3"), System.windowWidth() - width, System.windowHeight() - height, width, height + 1)) { + if (ui.window(Zui.handle("uibase_3"), System.width - width, System.height - height, width, height + 1)) { ui._w = width; var _BUTTON_H = ui.t.BUTTON_H; var _BUTTON_COL = ui.t.BUTTON_COL; @@ -1200,7 +1199,7 @@ class UIBase { // Expand button if (Config.raw.layout[LayoutSidebarW] == 0) { var width = Std.int(ui.font.width(ui.fontSize, "<<") + 25 * ui.SCALE()); - if (ui.window(hminimized, System.windowWidth() - width, 0, width, Std.int(ui.ELEMENT_H() + ui.ELEMENT_OFFSET() + 1))) { + if (ui.window(hminimized, System.width - width, 0, width, Std.int(ui.ELEMENT_H() + ui.ELEMENT_OFFSET() + 1))) { ui._w = width; var _BUTTON_H = ui.t.BUTTON_H; var _BUTTON_COL = ui.t.BUTTON_COL; @@ -1240,8 +1239,8 @@ class UIBase { // Radius being scaled if (Context.raw.brushLocked) { - mx += Context.raw.lockStartedX - System.windowWidth() / 2; - my += Context.raw.lockStartedY - System.windowHeight() / 2; + mx += Context.raw.lockStartedX - System.width / 2; + my += Context.raw.lockStartedY - System.height / 2; } #if is_paint @@ -1318,8 +1317,8 @@ class UIBase { // Radius being scaled if (Context.raw.brushLocked) { - Context.raw.decalX += (Context.raw.lockStartedX - System.windowWidth() / 2) / App.w(); - Context.raw.decalY += (Context.raw.lockStartedY - System.windowHeight() / 2) / App.h(); + Context.raw.decalX += (Context.raw.lockStartedX - System.width / 2) / App.w(); + Context.raw.decalY += (Context.raw.lockStartedY - System.height / 2) / App.h(); } } diff --git a/base/Sources/arm/ui/UIBox.hx b/base/Sources/arm/ui/UIBox.hx index a94cd1bc..f5a54e3c 100644 --- a/base/Sources/arm/ui/UIBox.hx +++ b/base/Sources/arm/ui/UIBox.hx @@ -31,8 +31,8 @@ class UIBox { var inUse = ui.comboSelectedHandle_ptr != null; var isEscape = kb.started("escape"); if (draws > 2 && (ui.inputReleased || isEscape) && !inUse && !ui.isTyping) { - var appw = System.windowWidth(); - var apph = System.windowHeight(); + var appw = System.width; + var apph = System.height; var mw = Std.int(modalW * ui.SCALE()); var mh = Std.int(modalH * ui.SCALE()); var left = (appw / 2 - mw / 2) + hwnd.dragX; @@ -53,14 +53,14 @@ class UIBox { #else g.color = kha.Color.fromFloats(0, 0, 0, 0.5); #end - g.fillRect(0, 0, kha.System.windowWidth(), kha.System.windowHeight()); + g.fillRect(0, 0, kha.System.width, kha.System.height); } g.end(); var ui = App.uiBox; - var appw = System.windowWidth(); - var apph = System.windowHeight(); + var appw = System.width; + var apph = System.height; var mw = Std.int(modalW * ui.SCALE()); var mh = Std.int(modalH * ui.SCALE()); if (mw > appw) mw = appw; @@ -162,13 +162,13 @@ class UIBox { static function tweenIn() { iron.system.Tween.reset(); iron.system.Tween.to({target: UIBox, props: { tweenAlpha: 0.5 }, duration: 0.2, ease: iron.system.Tween.Ease.ExpoOut}); - UIBox.hwnd.dragY = Std.int(kha.System.windowHeight() / 2); + UIBox.hwnd.dragY = Std.int(kha.System.height / 2); iron.system.Tween.to({target: UIBox.hwnd, props: { dragY: 0 }, duration: 0.2, ease: iron.system.Tween.Ease.ExpoOut, tick: function() { App.redrawUI(); }}); } static function tweenOut() { iron.system.Tween.to({target: UIBox, props: { tweenAlpha: 0.0 }, duration: 0.2, ease: iron.system.Tween.Ease.ExpoIn, done: hideInternal}); - iron.system.Tween.to({target: UIBox.hwnd, props: { dragY: kha.System.windowHeight() / 2 }, duration: 0.2, ease: iron.system.Tween.Ease.ExpoIn}); + iron.system.Tween.to({target: UIBox.hwnd, props: { dragY: kha.System.height / 2 }, duration: 0.2, ease: iron.system.Tween.Ease.ExpoIn}); } #end diff --git a/base/Sources/arm/ui/UIFiles.hx b/base/Sources/arm/ui/UIFiles.hx index 03461978..ca76d007 100644 --- a/base/Sources/arm/ui/UIFiles.hx +++ b/base/Sources/arm/ui/UIFiles.hx @@ -228,8 +228,8 @@ class UIFiles { // TODO: implement native .arm parsing first #else - var bytes = Bytes.ofData(Krom.loadBlob(blobPath)); - var raw = ArmPack.decode(bytes); + var buffer = Krom.loadBlob(blobPath); + var raw = ArmPack.decode(buffer); if (raw.material_icons != null) { var bytesIcon = raw.material_icons[0]; icon = kha.Image.fromBytes(Lz4.decode(bytesIcon, 256 * 256 * 4), 256, 256); @@ -276,11 +276,12 @@ class UIFiles { if (Path.isTexture(f) && !isCloud) { var w = 50; if (iconMap == null) iconMap = []; - icon = iconMap.get(handle.text + Path.sep + f); + var handle = handle.text + Path.sep + f; + icon = iconMap.get(handle); if (icon == null) { var empty = iron.RenderPath.active.renderTargets.get("empty_black").image; - iconMap.set(handle.text + Path.sep + f, empty); - kha.Assets.loadImageFromPath(handle.text + Path.sep + f, false, function(image: kha.Image) { + iconMap.set(handle, empty); + iron.data.Data.getImage(handle, function(image: kha.Image) { iron.App.notifyOnInit(function() { if (App.pipeCopyRGB == null) App.makePipeCopyRGB(); var sw = image.width > image.height ? w : Std.int(1.0 * image.width / image.height * w); @@ -291,9 +292,9 @@ class UIFiles { icon.g2.drawScaledImage(image, 0, 0, sw, sh); icon.g2.pipeline = null; icon.g2.end(); - iconMap.set(handle.text + Path.sep + f, icon); + iconMap.set(handle, icon); UIBase.inst.hwnds[TabStatus].redraws = 3; - image.unload(); // The big image is not needed anymore + iron.data.Data.deleteImage(handle); // The big image is not needed anymore }); }); } diff --git a/base/Sources/arm/ui/UIHeader.hx b/base/Sources/arm/ui/UIHeader.hx index 5ad77b19..dd077e65 100644 --- a/base/Sources/arm/ui/UIHeader.hx +++ b/base/Sources/arm/ui/UIHeader.hx @@ -40,9 +40,9 @@ class UIHeader { var nodesw = (UINodes.inst.show || UIView2D.inst.show) ? Config.raw.layout[LayoutNodesW] : 0; #if is_lab - var ww = System.windowWidth() - nodesw; + var ww = System.width - nodesw; #else - var ww = System.windowWidth() - UIToolbar.inst.toolbarw - Config.raw.layout[LayoutSidebarW] - nodesw; + var ww = System.width - UIToolbar.inst.toolbarw - Config.raw.layout[LayoutSidebarW] - nodesw; #end if (ui.window(headerHandle, iron.App.x(), headerh, ww, headerh)) { diff --git a/base/Sources/arm/ui/UIMenu.hx b/base/Sources/arm/ui/UIMenu.hx index f380cd6f..d83f6fae 100644 --- a/base/Sources/arm/ui/UIMenu.hx +++ b/base/Sources/arm/ui/UIMenu.hx @@ -562,21 +562,21 @@ class UIMenu { public static function fitToScreen() { // Prevent the menu going out of screen var menuW = App.defaultElementW * App.uiMenu.SCALE() * 2.3; - if (menuX + menuW > System.windowWidth()) { + if (menuX + menuW > System.width) { if (menuX - menuW > 0) { menuX = Std.int(menuX - menuW); } else { - menuX = Std.int(System.windowWidth() - menuW); + menuX = Std.int(System.width - menuW); } } var menuH = Std.int(menuElements * 30 * App.uiMenu.SCALE()); // ui.t.ELEMENT_H - if (menuY + menuH > System.windowHeight()) { + if (menuY + menuH > System.height) { if (menuY - menuH > 0) { menuY = Std.int(menuY - menuH); } else { - menuY = System.windowHeight() - menuH; + menuY = System.height - menuH; } menuX += 1; // Move out of mouse focus } diff --git a/base/Sources/arm/ui/UIMenubar.hx b/base/Sources/arm/ui/UIMenubar.hx index 966ad554..9b43aea1 100644 --- a/base/Sources/arm/ui/UIMenubar.hx +++ b/base/Sources/arm/ui/UIMenubar.hx @@ -101,10 +101,10 @@ class UIMenubar { var nodesw = (UINodes.inst.show || UIView2D.inst.show) ? Config.raw.layout[LayoutNodesW] : 0; #if (is_paint || is_sculpt) - var ww = System.windowWidth() - Config.raw.layout[LayoutSidebarW] - menubarw - nodesw; + var ww = System.width - Config.raw.layout[LayoutSidebarW] - menubarw - nodesw; var panelx = (iron.App.x() - UIToolbar.inst.toolbarw) + menubarw; #else - var ww = System.windowWidth() - menubarw - nodesw; + var ww = System.width - menubarw - nodesw; var panelx = (iron.App.x()) + menubarw; #end diff --git a/base/Sources/arm/ui/UINodes.hx b/base/Sources/arm/ui/UINodes.hx index 36f77dd6..3e3fb52f 100644 --- a/base/Sources/arm/ui/UINodes.hx +++ b/base/Sources/arm/ui/UINodes.hx @@ -379,19 +379,19 @@ class UINodes { if (Config.raw.wrap_mouse && parent.controlsDown) { if (ui.inputX < ui._windowX) { @:privateAccess ui.inputX = ui._windowX + ui._windowW; - Krom.setMousePosition(0, Std.int(ui.inputX), Std.int(ui.inputY)); + Krom.setMousePosition(Std.int(ui.inputX), Std.int(ui.inputY)); } else if (ui.inputX > ui._windowX + ui._windowW) { @:privateAccess ui.inputX = ui._windowX; - Krom.setMousePosition(0, Std.int(ui.inputX), Std.int(ui.inputY)); + Krom.setMousePosition(Std.int(ui.inputX), Std.int(ui.inputY)); } else if (ui.inputY < ui._windowY) { @:privateAccess ui.inputY = ui._windowY + ui._windowH; - Krom.setMousePosition(0, Std.int(ui.inputX), Std.int(ui.inputY)); + Krom.setMousePosition(Std.int(ui.inputX), Std.int(ui.inputY)); } else if (ui.inputY > ui._windowY + ui._windowH) { @:privateAccess ui.inputY = ui._windowY; - Krom.setMousePosition(0, Std.int(ui.inputX), Std.int(ui.inputY)); + Krom.setMousePosition(Std.int(ui.inputX), Std.int(ui.inputY)); } } @@ -716,7 +716,7 @@ class UINodes { } releaseLink = ui.inputReleased; - if (!show || System.windowWidth() == 0 || System.windowHeight() == 0) return; + if (!show || System.width == 0 || System.height == 0) return; ui.inputEnabled = App.uiEnabled; @@ -924,7 +924,7 @@ class UINodes { if (singleChannel) { ui.g.pipeline = UIView2D.pipe; #if krom_opengl - Krom.setPipeline(UIView2D.pipe.pipeline); + Krom.setPipeline(UIView2D.pipe.pipeline_); #end Krom.setInt(UIView2D.channelLocation, 1); } diff --git a/base/Sources/arm/ui/UIStatus.hx b/base/Sources/arm/ui/UIStatus.hx index 5a717805..0bb9df01 100644 --- a/base/Sources/arm/ui/UIStatus.hx +++ b/base/Sources/arm/ui/UIStatus.hx @@ -19,11 +19,11 @@ class UIStatus { var statush = Config.raw.layout[LayoutStatusH]; #if (is_paint || is_sculpt) - if (ui.window(UIBase.inst.hwnds[TabStatus], iron.App.x(), System.windowHeight() - statush, System.windowWidth() - UIToolbar.inst.toolbarw - Config.raw.layout[LayoutSidebarW], statush)) { + if (ui.window(UIBase.inst.hwnds[TabStatus], iron.App.x(), System.height - statush, System.width - UIToolbar.inst.toolbarw - Config.raw.layout[LayoutSidebarW], statush)) { #end #if is_lab - if (ui.window(UIBase.inst.hwnds[TabStatus], iron.App.x(), System.windowHeight() - statush, System.windowWidth(), statush)) { + if (ui.window(UIBase.inst.hwnds[TabStatus], iron.App.x(), System.height - statush, System.width, statush)) { #end ui._y += 2; diff --git a/base/Sources/arm/ui/UIToolbar.hx b/base/Sources/arm/ui/UIToolbar.hx index e3fb6b5a..49cd5d5b 100644 --- a/base/Sources/arm/ui/UIToolbar.hx +++ b/base/Sources/arm/ui/UIToolbar.hx @@ -49,7 +49,7 @@ class UIToolbar { } toolbarw = Std.int(toolbarw * ui.SCALE()); - if (ui.window(toolbarHandle, 0, UIHeader.headerh, toolbarw, System.windowHeight() - UIHeader.headerh)) { + if (ui.window(toolbarHandle, 0, UIHeader.headerh, toolbarw, System.height - UIHeader.headerh)) { ui._y -= 4 * ui.SCALE(); ui.imageScrollAlign = false; @@ -202,8 +202,8 @@ class UIToolbar { }, 0); // First draw out of screen, then align the menu based on menu height - UIMenu.menuX = -kha.System.windowWidth(); - UIMenu.menuY = -kha.System.windowHeight(); + UIMenu.menuX = -kha.System.width; + UIMenu.menuY = -kha.System.height; } @:access(zui.Zui) diff --git a/base/Sources/arm/ui/UIView2D.hx b/base/Sources/arm/ui/UIView2D.hx index 17819cad..76579348 100644 --- a/base/Sources/arm/ui/UIView2D.hx +++ b/base/Sources/arm/ui/UIView2D.hx @@ -60,7 +60,7 @@ class UIView2D { pipe.inputLayout = [vs]; pipe.blendSource = BlendingFactor.BlendOne; pipe.blendDestination = BlendingFactor.BlendZero; - pipe.colorWriteMaskAlpha = false; + pipe.colorWriteMasksAlpha[0] = false; pipe.compile(); channelLocation = pipe.getConstantLocation("channel"); #end @@ -91,7 +91,7 @@ class UIView2D { #end if (!show) return; - if (System.windowWidth() == 0 || System.windowHeight() == 0) return; + if (System.width == 0 || System.height == 0) return; if (Context.raw.pdirty >= 0) hwnd.redraws = 2; // Paint was active @@ -113,8 +113,8 @@ class UIView2D { ui.begin(g); var headerh = Config.raw.layout[LayoutHeader] == 1 ? UIHeader.headerh * 2 : UIHeader.headerh; - var apph = System.windowHeight() - Config.raw.layout[LayoutStatusH] + headerh; - wh = System.windowHeight() - Config.raw.layout[LayoutStatusH]; + var apph = System.height - Config.raw.layout[LayoutStatusH] + headerh; + wh = System.height - Config.raw.layout[LayoutStatusH]; if (UINodes.inst.show) { wh -= Config.raw.layout[LayoutNodesH]; @@ -219,7 +219,7 @@ class UIView2D { ui.g.imageScaleQuality = kha.Graphics2.ImageScaleQuality.Low; } #if krom_opengl - Krom.setPipeline(pipe.pipeline); + Krom.setPipeline(pipe.pipeline_); #end Krom.setInt(channelLocation, channel); } @@ -257,7 +257,7 @@ class UIView2D { g2.begin(false); g2.drawScaledImage(tex, -x, -y, tw, th); g2.end(); - var a = texpaint_picker.getPixels(); + var a = new js.lib.DataView(texpaint_picker.getPixels()); #if (krom_metal || krom_vulkan) var i0 = 2; var i1 = 1; @@ -267,9 +267,9 @@ class UIView2D { var i1 = 1; var i2 = 2; #end - Context.raw.pickedColor.base.Rb = a.get(i0); - Context.raw.pickedColor.base.Gb = a.get(i1); - Context.raw.pickedColor.base.Bb = a.get(i2); + Context.raw.pickedColor.base.Rb = a.getUint8(i0); + Context.raw.pickedColor.base.Gb = a.getUint8(i1); + Context.raw.pickedColor.base.Bb = a.getUint8(i2); UIHeader.inst.headerHandle.redraws = 2; }); } diff --git a/base/Sources/arm/util/MeshUtil.hx b/base/Sources/arm/util/MeshUtil.hx index df97dfa6..163e9d0d 100644 --- a/base/Sources/arm/util/MeshUtil.hx +++ b/base/Sources/arm/util/MeshUtil.hx @@ -330,6 +330,7 @@ class MeshUtil { public static function applyDisplacement(texpaint_pack: kha.Image, strength = 0.1, uvScale = 1.0) { var height = texpaint_pack.getPixels(); + var heightView = new js.lib.DataView(height); var res = texpaint_pack.width; var o = Project.paintObjects[0]; var g = o.data.geom; @@ -340,7 +341,7 @@ class MeshUtil { var y = Std.int(vertices.getInt16((i * l + 7) * 2, true) / 32767 * res); var xx = Std.int(x * uvScale) % res; var yy = Std.int(y * uvScale) % res; - var h = (1.0 - height.get((yy * res + xx) * 4 + 3) / 255) * strength; + var h = (1.0 - heightView.getUint8((yy * res + xx) * 4 + 3) / 255) * strength; vertices.setInt16((i * l ) * 2, vertices.getInt16((i * l ) * 2, true) - Std.int(vertices.getInt16((i * l + 4) * 2, true) * h), true); vertices.setInt16((i * l + 1) * 2, vertices.getInt16((i * l + 1) * 2, true) - Std.int(vertices.getInt16((i * l + 5) * 2, true) * h), true); vertices.setInt16((i * l + 2) * 2, vertices.getInt16((i * l + 2) * 2, true) - Std.int(vertices.getInt16((i * l + 3) * 2, true) * h), true); diff --git a/base/Sources/arm/util/RenderUtil.hx b/base/Sources/arm/util/RenderUtil.hx index 1ee33b9c..9847356a 100644 --- a/base/Sources/arm/util/RenderUtil.hx +++ b/base/Sources/arm/util/RenderUtil.hx @@ -183,7 +183,7 @@ class RenderUtil { #if krom_metal Context.raw.textToolImage = Image.createRenderTarget(texW, texW, TextureFormat.RGBA32); #else - Context.raw.textToolImage = Image.createRenderTarget(texW, texW, TextureFormat.L8); + Context.raw.textToolImage = Image.createRenderTarget(texW, texW, TextureFormat.R8); #end } var g2 = Context.raw.textToolImage.g2; diff --git a/base/Sources/arm/util/UVUtil.hx b/base/Sources/arm/util/UVUtil.hx index 17b47c7e..d8f9811b 100644 --- a/base/Sources/arm/util/UVUtil.hx +++ b/base/Sources/arm/util/UVUtil.hx @@ -16,7 +16,7 @@ class UVUtil { public static var dilatemapCached = false; public static var uvislandmap: Image = null; public static var uvislandmapCached = false; - static var dilateBytes: haxe.io.Bytes = null; + static var dilateBytes: js.lib.ArrayBuffer = null; static var pipeDilate: PipelineState = null; public static function cacheUVMap() { @@ -105,7 +105,7 @@ class UVUtil { if (dilatemapCached) return; if (dilatemap == null) { - dilatemap = Image.createRenderTarget(Config.getTextureResX(), Config.getTextureResY(), kha.Image.TextureFormat.L8); + dilatemap = Image.createRenderTarget(Config.getTextureResX(), Config.getTextureResY(), kha.Image.TextureFormat.R8); } if (pipeDilate == null) { @@ -123,7 +123,7 @@ class UVUtil { pipeDilate.inputLayout = [vs]; pipeDilate.depthWrite = false; pipeDilate.depthMode = CompareMode.Always; - pipeDilate.colorAttachments[0] = kha.Image.TextureFormat.L8; + pipeDilate.colorAttachments[0] = kha.Image.TextureFormat.R8; pipeDilate.compile(); // dilateTexUnpack = pipeDilate.getConstantLocation("texUnpack"); } @@ -157,15 +157,17 @@ class UVUtil { var h = 2048; // Config.getTextureResY() var x = Std.int(Context.raw.uvxPicked * w); var y = Std.int(Context.raw.uvyPicked * h); - var bytes = haxe.io.Bytes.alloc(w * h); + var bytes = new js.lib.ArrayBuffer(w * h); + var view = new js.lib.DataView(bytes); var coords: Array = [{ x: x, y: y }]; var r = Std.int(dilatemap.width / w); function check(c: TCoord) { if (c.x < 0 || c.x >= w || c.y < 0 || c.y >= h) return; - if (bytes.get(c.y * w + c.x) == 255) return; - if (dilateBytes.get(c.y * r * dilatemap.width + c.x * r) == 0) return; - bytes.set(c.y * w + c.x, 255); + if (view.getUint8(c.y * w + c.x) == 255) return; + var dilateView = new js.lib.DataView(dilateBytes); + if (dilateView.getUint8(c.y * r * dilatemap.width + c.x * r) == 0) return; + view.setUint8(c.y * w + c.x, 255); coords.push({ x: c.x + 1, y: c.y }); coords.push({ x: c.x - 1, y: c.y }); coords.push({ x: c.x, y: c.y + 1 }); @@ -179,7 +181,7 @@ class UVUtil { if (uvislandmap != null) { uvislandmap.unload(); } - uvislandmap = Image.fromBytes(bytes, w, h, kha.Image.TextureFormat.L8); + uvislandmap = Image.fromBytes(bytes, w, h, kha.Image.TextureFormat.R8); uvislandmapCached = true; } } diff --git a/base/project.js b/base/project.js index e55cde56..0b6b09f1 100644 --- a/base/project.js +++ b/base/project.js @@ -42,6 +42,14 @@ flags.on_c_project_created = async function(c_project, platform, graphics) { else if (platform === 'linux') { // patchelf --set-rpath . ArmorLab c_project.addLib("onnxruntime -L" + flags.dirname + "/../" + dir + "/onnx/linux"); + // c_project.addLib("onnxruntime_providers_cuda"); + // c_project.addLib("onnxruntime_providers_shared"); + // c_project.addLib("cublasLt"); + // c_project.addLib("cublas"); + // c_project.addLib("cudart"); + // c_project.addLib("cudnn"); + // c_project.addLib("cufft"); + // c_project.addLib("curand"); } else if (platform === 'osx') { c_project.addLib("../" + dir + "/onnx/macos/libonnxruntime.1.14.1.dylib"); diff --git a/misc/pad/Sources/Main.hx b/misc/pad/Sources/Main.hx index 02fa8100..99c2b4a1 100644 --- a/misc/pad/Sources/Main.hx +++ b/misc/pad/Sources/Main.hx @@ -73,7 +73,7 @@ class Main { } }; - System.start(ops, function(window: Window) { + System.start(ops, function() { kha.Assets.loadFontFromPath("data/font_mono.ttf", function(font: kha.Font) { kha.Assets.loadBlobFromPath("data/themes/dark.json", function(blob_theme: kha.Blob) { kha.Assets.loadBlobFromPath("data/text_coloring.json", function(blob_coloring: kha.Blob) { @@ -158,15 +158,15 @@ class Main { static function render(framebuffer: kha.Framebuffer): Void { var g = framebuffer.g2; - storage.window_w = System.windowWidth(); - storage.window_h = System.windowHeight(); + storage.window_w = System.width; + storage.window_h = System.height; storage.window_x = Krom.windowX(0); storage.window_y = Krom.windowY(0); if (ui.inputDX != 0 || ui.inputDY != 0) Krom.setMouseCursor(0); // Arrow ui.begin(g); - if (ui.window(sidebar_handle, 0, 0, storage.sidebar_w, System.windowHeight(), false)) { + if (ui.window(sidebar_handle, 0, 0, storage.sidebar_w, System.height, false)) { var _BUTTON_TEXT_COL = ui.t.BUTTON_TEXT_COL; ui.t.BUTTON_TEXT_COL = ui.t.ACCENT_COL; if (storage.project != "") { @@ -178,12 +178,12 @@ class Main { ui.t.BUTTON_TEXT_COL = _BUTTON_TEXT_COL; } - ui.fill(System.windowWidth() - minimap_w, 0, minimap_w, ui.ELEMENT_H() + ui.ELEMENT_OFFSET() + 1, ui.t.SEPARATOR_COL); - ui.fill(storage.sidebar_w, 0, 1, System.windowHeight(), ui.t.SEPARATOR_COL); + ui.fill(System.width - minimap_w, 0, minimap_w, ui.ELEMENT_H() + ui.ELEMENT_OFFSET() + 1, ui.t.SEPARATOR_COL); + ui.fill(storage.sidebar_w, 0, 1, System.height, ui.t.SEPARATOR_COL); var editor_updated = false; - if (ui.window(editor_handle, storage.sidebar_w + 1, 0, System.windowWidth() - storage.sidebar_w - minimap_w, System.windowHeight(), false)) { + if (ui.window(editor_handle, storage.sidebar_w + 1, 0, System.width - storage.sidebar_w - minimap_w, System.height, false)) { editor_updated = true; var htab = Zui.handle("main_0", { position: 0 }); var file_name = storage.file.substring(storage.file.lastIndexOf("/") + 1); @@ -216,7 +216,7 @@ class Main { } // Minimap controls - var minimap_x = System.windowWidth() - minimap_w; + var minimap_x = System.width - minimap_w; var minimap_y = window_header_h + 1; var redraw = false; if (ui.inputStarted && hit_test(ui.inputX, ui.inputY, minimap_x + 5, minimap_y, minimap_w, minimap_h)) { @@ -278,8 +278,8 @@ class Main { } static function draw_minimap() { - if (minimap_h != System.windowHeight()) { - minimap_h = System.windowHeight(); + if (minimap_h != System.height) { + minimap_h = System.height; if (minimap != null) minimap.unload(); minimap = kha.Image.createRenderTarget(minimap_w, minimap_h); } @@ -310,7 +310,7 @@ class Main { // Current position var visibleArea = outOfScreen > 0 ? minimap_h : minimap_full_h; minimap.g2.color = 0x11ffffff; - minimap_box_h = Std.int((System.windowHeight() - window_header_h) / ui.ELEMENT_H() * 2); + minimap_box_h = Std.int((System.height - window_header_h) / ui.ELEMENT_H() * 2); minimap.g2.fillRect(0, scrollProgress * visibleArea, minimap_w, minimap_box_h); minimap.g2.end(); }