From 7a8604c8c84d45ac18fae62d1ff64c8a0205512a Mon Sep 17 00:00:00 2001 From: luboslenco Date: Fri, 8 Mar 2024 21:36:48 +0100 Subject: [PATCH] Format --- .github/ISSUE_TEMPLATE/bug_report.md | 9 +- armorlab/Sources/MakeMaterial.ts | 2 +- armorlab/Sources/RenderPathPaint.ts | 24 +- armorlab/Sources/UINodesExt.ts | 26 +- armorlab/Sources/nodes/InpaintNode.ts | 14 +- armorlab/Sources/nodes/PhotoToPBRNode.ts | 4 +- armorlab/Sources/nodes/RGBNode.ts | 2 +- armorlab/Sources/nodes/TextToPhotoNode.ts | 4 +- armorlab/Sources/nodes/TilingNode.ts | 2 +- armorlab/Sources/nodes/UpscaleNode.ts | 2 +- armorlab/Sources/nodes/VarianceNode.ts | 2 +- armorpaint/Sources/ImportFolder.ts | 56 +- armorpaint/Sources/MakeBake.ts | 18 +- armorpaint/Sources/MakeBlur.ts | 4 +- armorpaint/Sources/MakeBrush.ts | 10 +- armorpaint/Sources/MakeClone.ts | 14 +- armorpaint/Sources/MakeDiscard.ts | 2 +- armorpaint/Sources/MakeMaterial.ts | 130 +- armorpaint/Sources/MakeMesh.ts | 124 +- armorpaint/Sources/MakeMeshPreview.ts | 46 +- armorpaint/Sources/MakeNodePreview.ts | 16 +- armorpaint/Sources/MakePaint.ts | 102 +- armorpaint/Sources/MakeParticle.ts | 10 +- armorpaint/Sources/MakeTexcoord.ts | 20 +- armorpaint/Sources/NodesBrush.ts | 6 +- armorpaint/Sources/RenderPathPaint.ts | 382 +-- armorpaint/Sources/RenderPathPreview.ts | 22 +- armorpaint/Sources/SlotBrush.ts | 8 +- armorpaint/Sources/SlotFont.ts | 6 +- armorpaint/Sources/SlotLayer.ts | 316 +-- armorpaint/Sources/SlotMaterial.ts | 36 +- armorpaint/Sources/TabLayers.ts | 452 ++-- armorpaint/Sources/nodes/BrushOutputNode.ts | 48 +- armorpaint/Sources/nodes/InputNode.ts | 78 +- armorsculpt/Sources/ImportMesh.ts | 8 +- armorsculpt/Sources/MakeMaterial.ts | 4 +- armorsculpt/Sources/TabLayers.ts | 20 +- armorsculpt/Sources/nodes/BrushOutputNode.ts | 10 +- base/Sources/Args.ts | 190 -- base/Sources/Base.ts | 2276 ------------------ base/Sources/BoxExport.ts | 100 +- base/Sources/BoxPreferences.ts | 186 +- base/Sources/BoxProjects.ts | 28 +- base/Sources/Camera.ts | 48 +- base/Sources/Config.ts | 60 +- base/Sources/Console.ts | 12 +- base/Sources/Context.ts | 40 +- base/Sources/ExportArm.ts | 94 +- base/Sources/ExportTexture.ts | 216 +- base/Sources/File.ts | 18 +- base/Sources/Geom.ts | 64 +- base/Sources/Gizmo.ts | 94 +- base/Sources/History.ts | 76 +- base/Sources/ImportArm.ts | 94 +- base/Sources/ImportAsset.ts | 14 +- base/Sources/ImportBlendMaterial.ts | 2 +- base/Sources/ImportBlendMesh.ts | 8 +- base/Sources/ImportEnvmap.ts | 16 +- base/Sources/ImportFont.ts | 8 +- base/Sources/ImportKeymap.ts | 4 +- base/Sources/ImportMesh.ts | 10 +- base/Sources/ImportPlugin.ts | 4 +- base/Sources/ImportTexture.ts | 10 +- base/Sources/ImportTheme.ts | 4 +- base/Sources/LineDraw.ts | 14 +- base/Sources/MakeVoxel.ts | 12 +- base/Sources/ParserBlend.ts | 102 +- base/Sources/ParserExr.ts | 50 +- base/Sources/ParserLogic.ts | 36 +- base/Sources/ParserMaterial.ts | 2 +- base/Sources/PhysicsBody.ts | 64 +- base/Sources/PhysicsWorld.ts | 104 +- base/Sources/Project.ts | 74 +- base/Sources/RenderPathBase.ts | 54 +- base/Sources/RenderPathRaytrace.ts | 20 +- base/Sources/RenderPathRaytraceBake.ts | 22 +- base/Sources/TabBrowser.ts | 56 +- base/Sources/TabBrushes.ts | 12 +- base/Sources/TabFonts.ts | 6 +- base/Sources/TabMaterials.ts | 78 +- base/Sources/TabScript.ts | 4 +- base/Sources/TabSwatches.ts | 34 +- base/Sources/TabTextures.ts | 42 +- base/Sources/Translator.ts | 40 +- base/Sources/UIBase.ts | 236 +- base/Sources/UIBox.ts | 20 +- base/Sources/UIFiles.ts | 98 +- base/Sources/UIHeader.ts | 200 +- base/Sources/UIMenu.ts | 150 +- base/Sources/UIMenubar.ts | 16 +- base/Sources/UINodes.ts | 274 +-- base/Sources/UIToolbar.ts | 52 +- base/Sources/UIView2D.ts | 62 +- base/Sources/UniformsExt.ts | 38 +- base/Sources/UtilMesh.ts | 62 +- base/Sources/UtilRender.ts | 120 +- base/Sources/UtilUV.ts | 12 +- base/Sources/Viewport.ts | 2 +- base/Sources/args.ts | 187 ++ base/Sources/base.ts | 2273 +++++++++++++++++ base/Sources/main.ts | 14 +- 101 files changed, 5173 insertions(+), 5184 deletions(-) delete mode 100644 base/Sources/Args.ts delete mode 100644 base/Sources/Base.ts create mode 100644 base/Sources/args.ts create mode 100644 base/Sources/base.ts diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 82ab7a5b..5553280b 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -7,21 +7,20 @@ assignees: '' --- - **ArmorPaint version:** - + -**OS/device including version:** - +**OS / GPU model:** **Issue description:** - **Steps to reproduce:** + diff --git a/armorlab/Sources/MakeMaterial.ts b/armorlab/Sources/MakeMaterial.ts index 88307177..18aaec79 100644 --- a/armorlab/Sources/MakeMaterial.ts +++ b/armorlab/Sources/MakeMaterial.ts @@ -113,7 +113,7 @@ class MakeMaterial { } static deleteContext = (c: shader_context_t) => { - Base.notifyOnNextFrame(() => { // Ensure pipeline is no longer in use + base_notifyOnNextFrame(() => { // Ensure pipeline is no longer in use shader_context_delete(c); }); } diff --git a/armorlab/Sources/RenderPathPaint.ts b/armorlab/Sources/RenderPathPaint.ts index 596ef1bb..1bfda80b 100644 --- a/armorlab/Sources/RenderPathPaint.ts +++ b/armorlab/Sources/RenderPathPaint.ts @@ -167,7 +167,7 @@ class RenderPathPaint { let canvas = UINodes.getCanvas(true); let inpaint = nodes.nodesSelectedId.length > 0 && zui_get_node(canvas.nodes, nodes.nodesSelectedId[0]).type == "InpaintNode"; - if (!Base.uiEnabled || Base.isDragging || !inpaint) { + if (!base_uiEnabled || base_isDragging || !inpaint) { return; } @@ -184,24 +184,24 @@ class RenderPathPaint { static drawCursor = (mx: f32, my: f32, radius: f32, tintR = 1.0, tintG = 1.0, tintB = 1.0) => { let plane = scene_get_child(".Plane").ext; let geom = plane.data; - if (Base.pipeCursor == null) Base.makeCursorPipe(); + if (base_pipeCursor == null) base_makeCursorPipe(); render_path_set_target(""); - g4_set_pipeline(Base.pipeCursor); + g4_set_pipeline(base_pipeCursor); let img = Res.get("cursor.k"); - g4_set_tex(Base.cursorTex, img); + g4_set_tex(base_cursorTex, img); let gbuffer0 = render_path_render_targets.get("gbuffer0")._image; - g4_set_tex_depth(Base.cursorGbufferD, gbuffer0); - g4_set_float2(Base.cursorMouse, mx, my); - g4_set_float2(Base.cursorTexStep, 1 / gbuffer0.width, 1 / gbuffer0.height); - g4_set_float(Base.cursorRadius, radius); + g4_set_tex_depth(base_cursorGbufferD, gbuffer0); + g4_set_float2(base_cursorMouse, mx, my); + g4_set_float2(base_cursorTexStep, 1 / gbuffer0.width, 1 / gbuffer0.height); + g4_set_float(base_cursorRadius, radius); let right = vec4_normalize(camera_object_right_world(scene_camera)); - g4_set_float3(Base.cursorCameraRight, right.x, right.y, right.z); - g4_set_float3(Base.cursorTint, tintR, tintG, tintB); - g4_set_mat(Base.cursorVP, scene_camera.vp); + g4_set_float3(base_cursorCameraRight, right.x, right.y, right.z); + g4_set_float3(base_cursorTint, tintR, tintG, tintB); + g4_set_mat(base_cursorVP, scene_camera.vp); let helpMat = mat4_identity(); mat4_get_inv(helpMat, scene_camera.vp); - g4_set_mat(Base.cursorInvVP, helpMat); + g4_set_mat(base_cursorInvVP, helpMat); ///if (krom_metal || krom_vulkan) g4_set_vertex_buffer(mesh_data_get(geom, [{name: "tex", data: "short2norm"}])); ///else diff --git a/armorlab/Sources/UINodesExt.ts b/armorlab/Sources/UINodesExt.ts index e8547aad..ae7e7e70 100644 --- a/armorlab/Sources/UINodesExt.ts +++ b/armorlab/Sources/UINodesExt.ts @@ -28,7 +28,7 @@ class UINodesExt { } } - Base.notifyOnNextFrame(() => { + base_notifyOnNextFrame(() => { let timer = time_time(); ParserLogic.parse(Project.canvas); @@ -53,15 +53,15 @@ class UINodesExt { g2_end(); } - if (Base.pipeCopy == null) Base.makePipe(); - if (Base.pipeCopyA == null) Base.makePipeCopyA(); + if (base_pipeCopy == null) base_makePipe(); + if (base_pipeCopyA == null) base_makePipeCopyA(); if (const_data_screen_aligned_vb == null) const_data_create_screen_aligned_data(); let texpaint_pack = render_path_render_targets.get("texpaint_pack")._image; if (texocc != null) { g2_begin(texpaint_pack); - g2_set_pipeline(Base.pipeCopyR); + g2_set_pipeline(base_pipeCopyR); g2_draw_scaled_image(texocc, 0, 0, Config.getTextureResX(), Config.getTextureResY()); g2_set_pipeline(null); g2_end(); @@ -69,7 +69,7 @@ class UINodesExt { if (texrough != null) { g2_begin(texpaint_pack); - g2_set_pipeline(Base.pipeCopyG); + g2_set_pipeline(base_pipeCopyG); g2_draw_scaled_image(texrough, 0, 0, Config.getTextureResX(), Config.getTextureResY()); g2_set_pipeline(null); g2_end(); @@ -77,8 +77,8 @@ class UINodesExt { if (texheight != null) { g4_begin(texpaint_pack); - g4_set_pipeline(Base.pipeCopyA); - g4_set_tex(Base.pipeCopyATex, texheight); + g4_set_pipeline(base_pipeCopyA); + g4_set_tex(base_pipeCopyATex, texheight); g4_set_vertex_buffer(const_data_screen_aligned_vb); g4_set_index_buffer(const_data_screen_aligned_ib); g4_draw(); @@ -107,9 +107,9 @@ class UINodesExt { // Apply displacement if (Config.raw.displace_strength > 0) { tasks++; - Base.notifyOnNextFrame(() => { + base_notifyOnNextFrame(() => { Console.progress(tr("Apply Displacement")); - Base.notifyOnNextFrame(() => { + base_notifyOnNextFrame(() => { let uv_scale = scene_meshes[0].data.scale_tex * Context.raw.brushScale; UtilMesh.applyDisplacement(texpaint_pack, 0.05 * Config.raw.displace_strength, uv_scale); UtilMesh.calcNormals(); @@ -135,12 +135,12 @@ class UINodesExt { ui._y = 2 + startY; ///if (krom_android || krom_ios) - zui_combo(Base.resHandle, ["2K", "4K"], tr("Resolution")); + zui_combo(base_resHandle, ["2K", "4K"], tr("Resolution")); ///else - zui_combo(Base.resHandle, ["2K", "4K", "8K", "16K"], tr("Resolution")); + zui_combo(base_resHandle, ["2K", "4K", "8K", "16K"], tr("Resolution")); ///end - if (Base.resHandle.changed) { - Base.onLayersResized(); + if (base_resHandle.changed) { + base_onLayersResized(); } ui._x += ew + 3; ui._y = 2 + startY; diff --git a/armorlab/Sources/nodes/InpaintNode.ts b/armorlab/Sources/nodes/InpaintNode.ts index d3807738..3f0e4411 100644 --- a/armorlab/Sources/nodes/InpaintNode.ts +++ b/armorlab/Sources/nodes/InpaintNode.ts @@ -24,7 +24,7 @@ class InpaintNode extends LogicNode { if (InpaintNode.mask == null) { InpaintNode.mask = image_create_render_target(Config.getTextureResX(), Config.getTextureResY(), tex_format_t.R8); - Base.notifyOnNextFrame(() => { + base_notifyOnNextFrame(() => { g4_begin(InpaintNode.mask); g4_clear(color_from_floats(1.0, 1.0, 1.0, 1.0)); g4_end(); @@ -54,7 +54,7 @@ class InpaintNode extends LogicNode { this.inputs[0].getAsImage((source: image_t) => { Console.progress(tr("Processing") + " - " + tr("Inpaint")); - Base.notifyOnNextFrame(() => { + base_notifyOnNextFrame(() => { g2_begin(InpaintNode.image); g2_draw_scaled_image(source, 0, 0, Config.getTextureResX(), Config.getTextureResY()); g2_end(); @@ -65,14 +65,14 @@ class InpaintNode extends LogicNode { } override getCachedImage = (): image_t => { - Base.notifyOnNextFrame(() => { + base_notifyOnNextFrame(() => { this.inputs[0].getAsImage((source: image_t) => { - if (Base.pipeCopy == null) Base.makePipe(); + if (base_pipeCopy == null) base_makePipe(); if (const_data_screen_aligned_vb == null) const_data_create_screen_aligned_data(); g4_begin(InpaintNode.image); - g4_set_pipeline(Base.pipeInpaintPreview); - g4_set_tex(Base.tex0InpaintPreview, source); - g4_set_tex(Base.texaInpaintPreview, InpaintNode.mask); + g4_set_pipeline(base_pipeInpaintPreview); + g4_set_tex(base_tex0InpaintPreview, source); + g4_set_tex(base_texaInpaintPreview, InpaintNode.mask); g4_set_vertex_buffer(const_data_screen_aligned_vb); g4_set_index_buffer(const_data_screen_aligned_ib); g4_draw(); diff --git a/armorlab/Sources/nodes/PhotoToPBRNode.ts b/armorlab/Sources/nodes/PhotoToPBRNode.ts index b0c6f971..8b2b16eb 100644 --- a/armorlab/Sources/nodes/PhotoToPBRNode.ts +++ b/armorlab/Sources/nodes/PhotoToPBRNode.ts @@ -39,7 +39,7 @@ class PhotoToPBRNode extends LogicNode { PhotoToPBRNode.cachedSource = source; Console.progress(tr("Processing") + " - " + tr("Photo to PBR")); - Base.notifyOnNextFrame(() => { + base_notifyOnNextFrame(() => { let tileFloats: Float32Array[] = []; let tilesX = Math.floor(Config.getTextureResX() / PhotoToPBRNode.tileW); let tilesY = Math.floor(Config.getTextureResY() / PhotoToPBRNode.tileW); @@ -145,7 +145,7 @@ class PhotoToPBRNode extends LogicNode { g2_begin(PhotoToPBRNode.images[from]); g2_draw_image(temp2, x * PhotoToPBRNode.tileW, y * PhotoToPBRNode.tileW); g2_end(); - Base.notifyOnNextFrame(() => { + base_notifyOnNextFrame(() => { image_unload(temp2); }); } diff --git a/armorlab/Sources/nodes/RGBNode.ts b/armorlab/Sources/nodes/RGBNode.ts index 825dcf4f..9fb5611a 100644 --- a/armorlab/Sources/nodes/RGBNode.ts +++ b/armorlab/Sources/nodes/RGBNode.ts @@ -9,7 +9,7 @@ class RGBNode extends LogicNode { override getAsImage = (from: i32, done: (img: image_t)=>void) => { if (this.image != null) { - Base.notifyOnNextFrame(() => { + base_notifyOnNextFrame(() => { image_unload(this.image); }); } diff --git a/armorlab/Sources/nodes/TextToPhotoNode.ts b/armorlab/Sources/nodes/TextToPhotoNode.ts index 8c077fb2..c08d00ea 100644 --- a/armorlab/Sources/nodes/TextToPhotoNode.ts +++ b/armorlab/Sources/nodes/TextToPhotoNode.ts @@ -45,7 +45,7 @@ class TextToPhotoNode extends LogicNode { static textEncoder = (prompt: string, inpaintLatents: Float32Array, done: (a: Float32Array, b: Float32Array)=>void) => { Console.progress(tr("Processing") + " - " + tr("Text to Photo")); - Base.notifyOnNextFrame(() => { + base_notifyOnNextFrame(() => { let words = prompt.replaceAll("\n", " ").replaceAll(",", " , ").replaceAll(" ", " ").trim().split(" "); for (let i = 0; i < words.length; ++i) { TextToPhotoNode.text_input_ids[i + 1] = TextToPhotoNode.vocab[words[i].toLowerCase() + ""]; @@ -194,7 +194,7 @@ class TextToPhotoNode extends LogicNode { static vaeDecoder = (latents: Float32Array, upscale: bool, done: (img: image_t)=>void) => { Console.progress(tr("Processing") + " - " + tr("Text to Photo")); - Base.notifyOnNextFrame(() => { + base_notifyOnNextFrame(() => { for (let i = 0; i < latents.length; ++i) { latents[i] = 1.0 / 0.18215 * latents[i]; } diff --git a/armorlab/Sources/nodes/TilingNode.ts b/armorlab/Sources/nodes/TilingNode.ts index 4c086410..810c8d9e 100644 --- a/armorlab/Sources/nodes/TilingNode.ts +++ b/armorlab/Sources/nodes/TilingNode.ts @@ -35,7 +35,7 @@ class TilingNode extends LogicNode { g2_end(); Console.progress(tr("Processing") + " - " + tr("Tiling")); - Base.notifyOnNextFrame(() => { + base_notifyOnNextFrame(() => { let _done = (image: image_t) => { this.result = image; done(image); diff --git a/armorlab/Sources/nodes/UpscaleNode.ts b/armorlab/Sources/nodes/UpscaleNode.ts index d8f1681b..a3e0ee6b 100644 --- a/armorlab/Sources/nodes/UpscaleNode.ts +++ b/armorlab/Sources/nodes/UpscaleNode.ts @@ -14,7 +14,7 @@ class UpscaleNode extends LogicNode { UpscaleNode.image = _image; Console.progress(tr("Processing") + " - " + tr("Upscale")); - Base.notifyOnNextFrame(() => { + base_notifyOnNextFrame(() => { UpscaleNode.loadBlob(() => { if (UpscaleNode.image.width < Config.getTextureResX()) { UpscaleNode.image = UpscaleNode.esrgan(UpscaleNode.image); diff --git a/armorlab/Sources/nodes/VarianceNode.ts b/armorlab/Sources/nodes/VarianceNode.ts index ddd5d1be..7283a84c 100644 --- a/armorlab/Sources/nodes/VarianceNode.ts +++ b/armorlab/Sources/nodes/VarianceNode.ts @@ -41,7 +41,7 @@ class VarianceNode extends LogicNode { } Console.progress(tr("Processing") + " - " + tr("Variance")); - Base.notifyOnNextFrame(() => { + base_notifyOnNextFrame(() => { let vae_encoder_blob: ArrayBuffer = data_get_blob("models/sd_vae_encoder.quant.onnx"); let latents_buf = krom_ml_inference(vae_encoder_blob, [f32a.buffer], [[1, 3, 512, 512]], [1, 4, 64, 64], Config.raw.gpu_inference); let latents = new Float32Array(latents_buf); diff --git a/armorpaint/Sources/ImportFolder.ts b/armorpaint/Sources/ImportFolder.ts index 05109e65..38bb1d50 100644 --- a/armorpaint/Sources/ImportFolder.ts +++ b/armorpaint/Sources/ImportFolder.ts @@ -2,24 +2,24 @@ class ImportFolder { static run = (path: string) => { - let files = File.read_directory(path); - let mapbase = ""; - let mapopac = ""; - let mapnor = ""; - let mapocc = ""; - let maprough = ""; - let mapmet = ""; - let mapheight = ""; + let files: string[] = File.read_directory(path); + let mapbase: string = ""; + let mapopac: string = ""; + let mapnor: string = ""; + let mapocc: string = ""; + let maprough: string = ""; + let mapmet: string = ""; + let mapheight: string = ""; - let foundTexture = false; + let found_texture: bool = false; // Import maps for (let f of files) { if (!Path.is_texture(f)) continue; // TODO: handle -albedo - let base = f.substr(0, f.lastIndexOf(".")).toLowerCase(); - let valid = false; + let base: string = f.substr(0, f.lastIndexOf(".")).toLowerCase(); + let valid: bool = false; if (mapbase == "" && Path.is_base_color_tex(base)) { mapbase = f; valid = true; @@ -51,11 +51,11 @@ class ImportFolder { if (valid) { ImportTexture.run(path + Path.sep + f, false); - foundTexture = true; + found_texture = true; } } - if (!foundTexture) { + if (!found_texture) { Console.info(tr("Folder does not contain textures")); return; } @@ -63,9 +63,9 @@ class ImportFolder { // Create material Context.raw.material = SlotMaterial.create(Project.materials[0].data); Project.materials.push(Context.raw.material); - let nodes = Context.raw.material.nodes; - let canvas = Context.raw.material.canvas; - let dirs = path.split(Path.sep); + let nodes: zui_nodes_t = Context.raw.material.nodes; + let canvas: zui_node_canvas_t = Context.raw.material.canvas; + let dirs: string[] = path.split(Path.sep); canvas.name = dirs[dirs.length - 1]; let nout: zui_node_t = null; for (let n of canvas.nodes) { @@ -82,35 +82,35 @@ class ImportFolder { } // Place nodes - let pos = 0; - let startY = 100; - let nodeH = 164; + let pos: i32 = 0; + let start_y: i32 = 100; + let node_h: i32 = 164; if (mapbase != "") { - ImportFolder.place_image_node(nodes, canvas, mapbase, startY + nodeH * pos, nout.id, 0); + ImportFolder.place_image_node(nodes, canvas, mapbase, start_y + node_h * pos, nout.id, 0); pos++; } if (mapopac != "") { - ImportFolder.place_image_node(nodes, canvas, mapopac, startY + nodeH * pos, nout.id, 1); + ImportFolder.place_image_node(nodes, canvas, mapopac, start_y + node_h * pos, nout.id, 1); pos++; } if (mapocc != "") { - ImportFolder.place_image_node(nodes, canvas, mapocc, startY + nodeH * pos, nout.id, 2); + ImportFolder.place_image_node(nodes, canvas, mapocc, start_y + node_h * pos, nout.id, 2); pos++; } if (maprough != "") { - ImportFolder.place_image_node(nodes, canvas, maprough, startY + nodeH * pos, nout.id, 3); + ImportFolder.place_image_node(nodes, canvas, maprough, start_y + node_h * pos, nout.id, 3); pos++; } if (mapmet != "") { - ImportFolder.place_image_node(nodes, canvas, mapmet, startY + nodeH * pos, nout.id, 4); + ImportFolder.place_image_node(nodes, canvas, mapmet, start_y + node_h * pos, nout.id, 4); pos++; } if (mapnor != "") { - ImportFolder.place_image_node(nodes, canvas, mapnor, startY + nodeH * pos, nout.id, 5); + ImportFolder.place_image_node(nodes, canvas, mapnor, start_y + node_h * pos, nout.id, 5); pos++; } if (mapheight != "") { - ImportFolder.place_image_node(nodes, canvas, mapheight, startY + nodeH * pos, nout.id, 7); + ImportFolder.place_image_node(nodes, canvas, mapheight, start_y + node_h * pos, nout.id, 7); pos++; } @@ -121,8 +121,8 @@ class ImportFolder { } static place_image_node = (nodes: zui_nodes_t, canvas: zui_node_canvas_t, asset: string, ny: i32, to_id: i32, to_socket: i32) => { - let n = NodesMaterial.create_node("TEX_IMAGE"); - n.buttons[0].default_value = Base.get_asset_index(asset); + let n: zui_node_t = NodesMaterial.create_node("TEX_IMAGE"); + n.buttons[0].default_value = base_get_asset_index(asset); n.x = 72; n.y = ny; let l: zui_node_link_t = { id: zui_get_link_id(canvas.links), from_id: n.id, from_socket: 0, to_id: to_id, to_socket: to_socket }; diff --git a/armorpaint/Sources/MakeBake.ts b/armorpaint/Sources/MakeBake.ts index 42b9d50a..f49f61f0 100644 --- a/armorpaint/Sources/MakeBake.ts +++ b/armorpaint/Sources/MakeBake.ts @@ -23,12 +23,12 @@ class MakeBake { NodeShader.add_uniform(frag, 'sampler3D voxels'); NodeShader.add_function(frag, ShaderFunctions.str_trace_ao); frag.n = true; - let strength = Context.raw.bake_ao_strength; - let radius = Context.raw.bake_ao_radius; - let offset = Context.raw.bake_ao_offset; + let strength: f32 = Context.raw.bake_ao_strength; + let radius: f32 = Context.raw.bake_ao_radius; + let offset: f32 = Context.raw.bake_ao_offset; NodeShader.write(frag, `float ao = traceAO(voxpos, n, ${radius}, ${offset}) * ${strength};`); if (Context.raw.bake_axis != bake_axis_t.XYZ) { - let axis = MakeBake.axis_string(Context.raw.bake_axis); + let axis: string = MakeBake.axis_string(Context.raw.bake_axis); NodeShader.write(frag, `ao *= dot(n, ${axis});`); } NodeShader.write(frag, 'ao = 1.0 - ao;'); @@ -36,10 +36,10 @@ class MakeBake { ///end } else if (Context.raw.bake_type == bake_type_t.CURVATURE) { - let pass = ParserMaterial.bake_passthrough; - let strength = pass ? ParserMaterial.bake_passthrough_strength : Context.raw.bake_curv_strength + ""; - let radius = pass ? ParserMaterial.bake_passthrough_radius : Context.raw.bake_curv_radius + ""; - let offset = pass ? ParserMaterial.bake_passthrough_offset : Context.raw.bake_curv_offset + ""; + let pass: bool = ParserMaterial.bake_passthrough; + let strength: string = pass ? ParserMaterial.bake_passthrough_strength : Context.raw.bake_curv_strength + ""; + let radius: string = pass ? ParserMaterial.bake_passthrough_radius : Context.raw.bake_curv_radius + ""; + let offset: string = pass ? ParserMaterial.bake_passthrough_offset : Context.raw.bake_curv_offset + ""; strength = `float(${strength})`; radius = `float(${radius})`; offset = `float(${offset})`; @@ -49,7 +49,7 @@ class MakeBake { NodeShader.write(frag, 'float curvature = max(dot(dx, dx), dot(dy, dy));'); NodeShader.write(frag, 'curvature = clamp(pow(curvature, (1.0 / ' + radius + ') * 0.25) * ' + strength + ' * 2.0 + ' + offset + ' / 10.0, 0.0, 1.0);'); if (Context.raw.bake_axis != bake_axis_t.XYZ) { - let axis = MakeBake.axis_string(Context.raw.bake_axis); + let axis: string = MakeBake.axis_string(Context.raw.bake_axis); NodeShader.write(frag, `curvature *= dot(n, ${axis});`); } NodeShader.write(frag, 'fragColor[0] = vec4(curvature, curvature, curvature, 1.0);'); diff --git a/armorpaint/Sources/MakeBlur.ts b/armorpaint/Sources/MakeBlur.ts index 654c5cb0..f97152c0 100644 --- a/armorpaint/Sources/MakeBlur.ts +++ b/armorpaint/Sources/MakeBlur.ts @@ -15,8 +15,8 @@ class MakeBlur { NodeShader.write(frag, 'vec3 nortan = vec3(0.0, 0.0, 0.0);'); NodeShader.write(frag, 'float height = 0.0;'); NodeShader.write(frag, 'float mat_opacity = 1.0;'); - let isMask = SlotLayer.is_mask(Context.raw.layer); - if (isMask) { + let is_mask: bool = SlotLayer.is_mask(Context.raw.layer); + if (is_mask) { NodeShader.write(frag, 'float opacity = 1.0;'); } else { diff --git a/armorpaint/Sources/MakeBrush.ts b/armorpaint/Sources/MakeBrush.ts index e85891d9..8bc464e8 100644 --- a/armorpaint/Sources/MakeBrush.ts +++ b/armorpaint/Sources/MakeBrush.ts @@ -7,9 +7,9 @@ class MakeBrush { if (Context.raw.tool == workspace_tool_t.PARTICLE) return; - let fillLayer = Context.raw.layer.fill_layer != null; - let decal = Context.raw.tool == workspace_tool_t.DECAL || Context.raw.tool == workspace_tool_t.TEXT; - if (decal && !fillLayer) NodeShader.write(frag, 'if (decalMask.z > 0.0) {'); + let fill_layer: bool = Context.raw.layer.fill_layer != null; + let decal: bool = Context.raw.tool == workspace_tool_t.DECAL || Context.raw.tool == workspace_tool_t.TEXT; + if (decal && !fill_layer) NodeShader.write(frag, 'if (decalMask.z > 0.0) {'); if (Config.raw.brush_3d) { ///if (krom_direct3d11 || krom_direct3d12 || krom_metal || krom_vulkan) @@ -41,7 +41,7 @@ class MakeBrush { if (Config.raw.brush_angle_reject && !Context.raw.xray) { NodeShader.write(frag, 'if (planeDist < -0.01) discard;'); frag.n = true; - let angle = Context.raw.brush_angle_reject_dot; + let angle: f32 = Context.raw.brush_angle_reject_dot; NodeShader.write(frag, `if (dot(wn, n) < ${angle}) discard;`); } } @@ -89,6 +89,6 @@ class MakeBrush { NodeShader.write(frag, 'if (dist > brushRadius) discard;'); - if (decal && !fillLayer) NodeShader.write(frag, '}'); + if (decal && !fill_layer) NodeShader.write(frag, '}'); } } diff --git a/armorpaint/Sources/MakeClone.ts b/armorpaint/Sources/MakeClone.ts index e826aecb..464cf546 100644 --- a/armorpaint/Sources/MakeClone.ts +++ b/armorpaint/Sources/MakeClone.ts @@ -10,13 +10,13 @@ class MakeClone { ///end NodeShader.write(frag, 'vec3 texpaint_pack_sample = textureLod(texpaint_pack_undo, texCoordInp, 0.0).rgb;'); - let base = 'textureLod(texpaint_undo, texCoordInp, 0.0).rgb'; - let rough = 'texpaint_pack_sample.g'; - let met = 'texpaint_pack_sample.b'; - let occ = 'texpaint_pack_sample.r'; - let nortan = 'textureLod(texpaint_nor_undo, texCoordInp, 0.0).rgb'; - let height = '0.0'; - let opac = '1.0'; + let base: string = 'textureLod(texpaint_undo, texCoordInp, 0.0).rgb'; + let rough: string = 'texpaint_pack_sample.g'; + let met: string = 'texpaint_pack_sample.b'; + let occ: string = 'texpaint_pack_sample.r'; + let nortan: string = 'textureLod(texpaint_nor_undo, texCoordInp, 0.0).rgb'; + let height: string = '0.0'; + let opac: string = '1.0'; NodeShader.write(frag, `vec3 basecol = ${base};`); NodeShader.write(frag, `float roughness = ${rough};`); NodeShader.write(frag, `float metallic = ${met};`); diff --git a/armorpaint/Sources/MakeDiscard.ts b/armorpaint/Sources/MakeDiscard.ts index 0a842c4e..c5746689 100644 --- a/armorpaint/Sources/MakeDiscard.ts +++ b/armorpaint/Sources/MakeDiscard.ts @@ -44,7 +44,7 @@ class MakeDiscard { NodeShader.write(frag, 'picker_sample_tc.y = 1.0 - picker_sample_tc.y;'); ///end NodeShader.add_uniform(frag, 'sampler2D texpaint_nor_undo', '_texpaint_nor_undo'); - let matid = Context.raw.materialid_picked / 255; + let matid: i32 = Context.raw.materialid_picked / 255; NodeShader.write(frag, `if (${matid} != textureLod(texpaint_nor_undo, picker_sample_tc, 0.0).a) discard;`); } } diff --git a/armorpaint/Sources/MakeMaterial.ts b/armorpaint/Sources/MakeMaterial.ts index 27f43a3b..d60c9e0c 100644 --- a/armorpaint/Sources/MakeMaterial.ts +++ b/armorpaint/Sources/MakeMaterial.ts @@ -1,12 +1,12 @@ class MakeMaterial { - static defaultScon: shader_context_t = null; - static defaultMcon: material_context_t = null; + static default_scon: shader_context_t = null; + static default_mcon: material_context_t = null; - static heightUsed = false; - static emisUsed = false; - static subsUsed = false; + static height_used = false; + static emis_used = false; + static subs_used = false; static get_mout = (): bool => { for (let n of UINodes.get_canvas_material().nodes) if (n.type == "OUTPUT_MATERIAL_PBR") return true; @@ -14,7 +14,7 @@ class MakeMaterial { } static parse_mesh_material = () => { - let m = Project.materials[0].data; + let m: material_data_t = Project.materials[0].data; for (let c of m._.shader._.contexts) { if (c.name == "mesh") { @@ -26,10 +26,10 @@ class MakeMaterial { } if (MakeMesh.layer_pass_count > 1) { - let i = 0; + let i: i32 = 0; while (i < m._.shader._.contexts.length) { - let c = m._.shader._.contexts[i]; - for (let j = 1; j < MakeMesh.layer_pass_count; ++j) { + let c: shader_context_t = m._.shader._.contexts[i]; + for (let j: i32 = 1; j < MakeMesh.layer_pass_count; ++j) { if (c.name == "mesh" + j) { array_remove(m._.shader.contexts, c); array_remove(m._.shader._.contexts, c); @@ -43,8 +43,8 @@ class MakeMaterial { i = 0; while (i < m._.contexts.length) { - let c = m._.contexts[i]; - for (let j = 1; j < MakeMesh.layer_pass_count; ++j) { + let c: material_context_t = m._.contexts[i]; + for (let j: i32 = 1; j < MakeMesh.layer_pass_count; ++j) { if (c.name == "mesh" + j) { array_remove(m.contexts, c); array_remove(m._.contexts, c); @@ -56,11 +56,11 @@ class MakeMaterial { } } - let con = MakeMesh.run({ name: "Material", canvas: null }); + let con: NodeShaderContextRaw = MakeMesh.run({ name: "Material", canvas: null }); let scon: shader_context_t = shader_context_create(con.data); scon._.override_context = {}; if (con.frag.shared_samplers.length > 0) { - let sampler = con.frag.shared_samplers[0]; + let sampler: string = con.frag.shared_samplers[0]; scon._.override_context.shared_sampler = sampler.substr(sampler.lastIndexOf(" ") + 1); } if (!Context.raw.texture_filter) { @@ -69,12 +69,12 @@ class MakeMaterial { m._.shader.contexts.push(scon); m._.shader._.contexts.push(scon); - for (let i = 1; i < MakeMesh.layer_pass_count; ++i) { - let con = MakeMesh.run({ name: "Material", canvas: null }, i); + for (let i: i32 = 1; i < MakeMesh.layer_pass_count; ++i) { + let con: NodeShaderContextRaw = MakeMesh.run({ name: "Material", canvas: null }, i); let scon: shader_context_t = shader_context_create(con.data); scon._.override_context = {}; if (con.frag.shared_samplers.length > 0) { - let sampler = con.frag.shared_samplers[0]; + let sampler: string = con.frag.shared_samplers[0]; scon._.override_context.shared_sampler = sampler.substr(sampler.lastIndexOf(" ") + 1); } if (!Context.raw.texture_filter) { @@ -101,7 +101,7 @@ class MakeMaterial { } static parse_particle_material = () => { - let m = Context.raw.particle_material; + let m: material_data_t = Context.raw.particle_material; let sc: shader_context_t = null; for (let c of m._.shader._.contexts) { if (c.name == "mesh") { @@ -113,7 +113,7 @@ class MakeMaterial { array_remove(m._.shader.contexts, sc); array_remove(m._.shader._.contexts, sc); } - let con = MakeParticle.run({ name: "MaterialParticle", canvas: null }); + let con: NodeShaderContextRaw = MakeParticle.run({ name: "MaterialParticle", canvas: null }); if (sc != null) MakeMaterial.delete_context(sc); sc = shader_context_create(con.data); m._.shader.contexts.push(sc); @@ -123,7 +123,7 @@ class MakeMaterial { static parse_mesh_preview_material = (md: material_data_t = null) => { if (!MakeMaterial.get_mout()) return; - let m = md == null ? Project.materials[0].data : md; + let m: material_data_t = md == null ? Project.materials[0].data : md; let scon: shader_context_t = null; for (let c of m._.shader._.contexts) { if (c.name == "mesh") { @@ -138,9 +138,9 @@ class MakeMaterial { let mcon: material_context_t = { name: "mesh", bind_textures: [] }; let sd: material_t = { name: "Material", canvas: null }; - let con = MakeMeshPreview.run(sd, mcon); + let con: NodeShaderContextRaw = MakeMeshPreview.run(sd, mcon); - for (let i = 0; i < m._.contexts.length; ++i) { + for (let i: i32 = 0; i < m._.contexts.length; ++i) { if (m._.contexts[i].name == "mesh") { m._.contexts[i] = material_context_create(mcon); break; @@ -149,11 +149,11 @@ class MakeMaterial { if (scon != null) MakeMaterial.delete_context(scon); - let compileError = false; + let compile_error: bool = false; let _scon: shader_context_t = shader_context_create(con.data); - if (_scon == null) compileError = true; + if (_scon == null) compile_error = true; scon = _scon; - if (compileError) return; + if (compile_error) return; m._.shader.contexts.push(scon); m._.shader._.contexts.push(scon); @@ -161,7 +161,7 @@ class MakeMaterial { ///if arm_voxels static make_voxel = (m: material_data_t) => { - let rebuild = MakeMaterial.heightUsed; + let rebuild: bool = MakeMaterial.height_used; if (Config.raw.rp_gi != false && rebuild) { let scon: shader_context_t = null; for (let c of m._.shader._.contexts) { @@ -175,24 +175,24 @@ class MakeMaterial { } ///end - static parse_paint_material = (bakePreviews = true) => { + static parse_paint_material = (bake_previews = true) => { if (!MakeMaterial.get_mout()) return; - if (bakePreviews) { - let current = _g2_current; + if (bake_previews) { + let current: image_t = _g2_current; if (current != null) g2_end(); MakeMaterial.bake_node_previews(); if (current != null) g2_begin(current); } - let m = Project.materials[0].data; + let m: material_data_t = Project.materials[0].data; // let scon: TShaderContext = null; // let mcon: TMaterialContext = null; for (let c of m._.shader._.contexts) { if (c.name == "paint") { array_remove(m._.shader.contexts, c); array_remove(m._.shader._.contexts, c); - if (c != MakeMaterial.defaultScon) MakeMaterial.delete_context(c); + if (c != MakeMaterial.default_scon) MakeMaterial.delete_context(c); break; } } @@ -206,14 +206,14 @@ class MakeMaterial { let sdata: material_t = { name: "Material", canvas: UINodes.get_canvas_material() }; let tmcon: material_context_t = { name: "paint", bind_textures: [] }; - let con = MakePaint.run(sdata, tmcon); + let con: NodeShaderContextRaw = MakePaint.run(sdata, tmcon); - let compileError = false; + let compile_error: bool = false; let scon: shader_context_t; let _scon: shader_context_t = shader_context_create(con.data); - if (_scon == null) compileError = true; + if (_scon == null) compile_error = true; scon = _scon; - if (compileError) return; + if (compile_error) return; scon._.override_context = {}; scon._.override_context.addressing = "repeat"; let mcon: material_context_t = material_context_create(tmcon); @@ -223,8 +223,8 @@ class MakeMaterial { m.contexts.push(mcon); m._.contexts.push(mcon); - if (MakeMaterial.defaultScon == null) MakeMaterial.defaultScon = scon; - if (MakeMaterial.defaultMcon == null) MakeMaterial.defaultMcon = mcon; + if (MakeMaterial.default_scon == null) MakeMaterial.default_scon = scon; + if (MakeMaterial.default_mcon == null) MakeMaterial.default_mcon = mcon; } static bake_node_previews = () => { @@ -233,8 +233,8 @@ class MakeMaterial { MakeMaterial.traverse_nodes(UINodes.get_canvas_material().nodes, null, []); for (let key of Context.raw.node_previews.keys()) { if (Context.raw.node_previews_used.indexOf(key) == -1) { - let image = Context.raw.node_previews.get(key); - Base.notify_on_next_frame(function() { image_unload(image); }); + let image: image_t = Context.raw.node_previews.get(key); + base_notify_on_next_frame(function() { image_unload(image); }); Context.raw.node_previews.delete(key); } } @@ -258,11 +258,11 @@ class MakeMaterial { static bake_node_preview = (node: zui_node_t, group: zui_node_canvas_t, parents: zui_node_t[]) => { if (node.type == "BLUR") { - let id = ParserMaterial.node_name(node, parents); - let image = Context.raw.node_previews.get(id); + let id: string = ParserMaterial.node_name(node, parents); + let image: image_t = Context.raw.node_previews.get(id); Context.raw.node_previews_used.push(id); - let resX = Math.floor(Config.get_texture_res_x() / 4); - let resY = Math.floor(Config.get_texture_res_y() / 4); + let resX: i32 = Math.floor(Config.get_texture_res_x() / 4); + let resY: i32 = Math.floor(Config.get_texture_res_y() / 4); if (image == null || image.width != resX || image.height != resY) { if (image != null) image_unload(image); image = image_create_render_target(resX, resY); @@ -274,11 +274,11 @@ class MakeMaterial { ParserMaterial.blur_passthrough = false; } else if (node.type == "DIRECT_WARP") { - let id = ParserMaterial.node_name(node, parents); - let image = Context.raw.node_previews.get(id); + let id: string = ParserMaterial.node_name(node, parents); + let image: image_t = Context.raw.node_previews.get(id); Context.raw.node_previews_used.push(id); - let resX = Math.floor(Config.get_texture_res_x()); - let resY = Math.floor(Config.get_texture_res_y()); + let resX: i32 = Math.floor(Config.get_texture_res_x()); + let resY: i32 = Math.floor(Config.get_texture_res_y()); if (image == null || image.width != resX || image.height != resY) { if (image != null) image_unload(image); image = image_create_render_target(resX, resY); @@ -290,24 +290,24 @@ class MakeMaterial { ParserMaterial.warp_passthrough = false; } else if (node.type == "BAKE_CURVATURE") { - let id = ParserMaterial.node_name(node, parents); - let image = Context.raw.node_previews.get(id); + let id: string = ParserMaterial.node_name(node, parents); + let image: image_t = Context.raw.node_previews.get(id); Context.raw.node_previews_used.push(id); - let resX = Math.floor(Config.get_texture_res_x()); - let resY = Math.floor(Config.get_texture_res_y()); + let resX: i32 = Math.floor(Config.get_texture_res_x()); + let resY: i32 = Math.floor(Config.get_texture_res_y()); if (image == null || image.width != resX || image.height != resY) { if (image != null) image_unload(image); image = image_create_render_target(resX, resY, tex_format_t.R8); Context.raw.node_previews.set(id, image); } - if (RenderPathPaint.liveLayer == null) { - RenderPathPaint.liveLayer = SlotLayer.create("_live"); + if (RenderPathPaint.live_layer == null) { + RenderPathPaint.live_layer = SlotLayer.create("_live"); } - let _space = UIHeader.worktab.position; - let _tool = Context.raw.tool; - let _bakeType = Context.raw.bake_type; + let _space: i32 = UIHeader.worktab.position; + let _tool: workspace_tool_t = Context.raw.tool; + let _bake_type: bake_type_t = Context.raw.bake_type; UIHeader.worktab.position = space_type_t.SPACE3D; Context.raw.tool = workspace_tool_t.BAKE; Context.raw.bake_type = bake_type_t.CURVATURE; @@ -330,11 +330,11 @@ class MakeMaterial { UIHeader.worktab.position = _space; Context.raw.tool = _tool; - Context.raw.bake_type = _bakeType; + Context.raw.bake_type = _bake_type; MakeMaterial.parse_paint_material(false); - let rts = render_path_render_targets; - let texpaint_live = rts.get("texpaint_live"); + let rts: Map = render_path_render_targets; + let texpaint_live: render_target_t = rts.get("texpaint_live"); g2_begin(image); g2_draw_image(texpaint_live._image, 0, 0); @@ -346,13 +346,13 @@ class MakeMaterial { if (node.outputs.length == 0) return null; let sdata: material_t = { name: "Material", canvas: UINodes.get_canvas_material() }; let mcon_raw: material_context_t = { name: "mesh", bind_textures: [] }; - let con = MakeNodePreview.run(sdata, mcon_raw, node, group, parents); - let compileError = false; + let con: NodeShaderContextRaw = MakeNodePreview.run(sdata, mcon_raw, node, group, parents); + let compile_error: bool = false; let scon: shader_context_t; let _scon: shader_context_t = shader_context_create(con.data); - if (_scon == null) compileError = true; + if (_scon == null) compile_error = true; scon = _scon; - if (compileError) return null; + if (compile_error) return null; let mcon: material_context_t = material_context_create(mcon_raw); return { scon: scon, mcon: mcon }; } @@ -475,17 +475,17 @@ class MakeMaterial { } static get_displace_strength = (): f32 => { - let sc = Context.main_object().base.transform.scale.x; + let sc: f32 = Context.main_object().base.transform.scale.x; return Config.raw.displace_strength * 0.02 * sc; } static voxelgi_half_extents = (): string => { - let ext = Context.raw.vxao_ext; + let ext: f32 = Context.raw.vxao_ext; return `const vec3 voxelgiHalfExtents = vec3(${ext}, ${ext}, ${ext});`; } static delete_context = (c: shader_context_t) => { - Base.notify_on_next_frame(() => { // Ensure pipeline is no longer in use + base_notify_on_next_frame(() => { // Ensure pipeline is no longer in use shader_context_delete(c); }); } diff --git a/armorpaint/Sources/MakeMesh.ts b/armorpaint/Sources/MakeMesh.ts index 19d0c019..13438ee3 100644 --- a/armorpaint/Sources/MakeMesh.ts +++ b/armorpaint/Sources/MakeMesh.ts @@ -4,8 +4,8 @@ class MakeMesh { static layer_pass_count = 1; static run = (data: material_t, layerPass = 0): NodeShaderContextRaw => { - let context_id = layerPass == 0 ? "mesh" : "mesh" + layerPass; - let con_mesh = NodeShaderContext.create(data, { + let context_id: string = layerPass == 0 ? "mesh" : "mesh" + layerPass; + let con_mesh: NodeShaderContextRaw = NodeShaderContext.create(data, { name: context_id, depth_write: layerPass == 0 ? true : false, compare_mode: layerPass == 0 ? "less" : "equal", @@ -15,8 +15,8 @@ class MakeMesh { depth_attachment: "DEPTH32" }); - let vert = NodeShaderContext.make_vert(con_mesh); - let frag = NodeShaderContext.make_frag(con_mesh); + let vert: NodeShaderRaw = NodeShaderContext.make_vert(con_mesh); + let frag: NodeShaderRaw = NodeShaderContext.make_frag(con_mesh); frag.ins = vert.outs; NodeShader.add_out(vert, 'vec2 texCoord'); @@ -26,35 +26,35 @@ class MakeMesh { NodeShader.add_uniform(vert, 'mat4 prevWVP', '_prev_world_view_proj_matrix'); vert.wposition = true; - let textureCount = 0; - let displaceStrength = MakeMaterial.get_displace_strength(); - if (MakeMaterial.heightUsed && displaceStrength > 0.0) { + let texture_count: i32 = 0; + let displace_strength: f32 = MakeMaterial.get_displace_strength(); + if (MakeMaterial.height_used && displace_strength > 0.0) { vert.n = true; NodeShader.write(vert, 'float height = 0.0;'); - let numLayers = 0; + let num_layers: i32 = 0; for (let l of Project.layers) { - if (!SlotLayer.is_visible(l) || !l.paintHeight || !SlotLayer.is_layer(l)) continue; - if (numLayers > 16) break; - numLayers++; - textureCount++; + if (!SlotLayer.is_visible(l) || !l.paint_height || !SlotLayer.is_layer(l)) continue; + if (num_layers > 16) break; + num_layers++; + texture_count++; NodeShader.add_uniform(vert, 'sampler2D texpaint_pack_vert' + l.id, '_texpaint_pack_vert' + l.id); NodeShader.write(vert, 'height += textureLod(texpaint_pack_vert' + l.id + ', tex, 0.0).a;'); - let masks = SlotLayer.get_masks(l); + let masks: SlotLayerRaw[] = SlotLayer.get_masks(l); if (masks != null) { for (let m of masks) { if (!SlotLayer.is_visible(m)) continue; - textureCount++; + texture_count++; NodeShader.add_uniform(vert, 'sampler2D texpaint_vert' + m.id, '_texpaint_vert' + m.id); NodeShader.write(vert, 'height *= textureLod(texpaint_vert' + m.id + ', tex, 0.0).r;'); } } } - NodeShader.write(vert, `wposition += wnormal * vec3(height, height, height) * vec3(${displaceStrength}, ${displaceStrength}, ${displaceStrength});`); + NodeShader.write(vert, `wposition += wnormal * vec3(height, height, height) * vec3(${displace_strength}, ${displace_strength}, ${displace_strength});`); } NodeShader.write(vert, 'gl_Position = mul(vec4(wposition.xyz, 1.0), VP);'); NodeShader.write(vert, 'texCoord = tex;'); - if (MakeMaterial.heightUsed && displaceStrength > 0) { + if (MakeMaterial.height_used && displace_strength > 0) { NodeShader.add_uniform(vert, 'mat4 invW', '_inv_world_matrix'); NodeShader.write(vert, 'prevwvpposition = mul(mul(vec4(wposition, 1.0), invW), prevWVP);'); } @@ -67,7 +67,7 @@ class MakeMesh { NodeShader.add_function(frag, ShaderFunctions.str_pack_float_int16); if (Context.raw.tool == workspace_tool_t.COLORID) { - textureCount++; + texture_count++; NodeShader.add_uniform(frag, 'sampler2D texcolorid', '_texcolorid'); NodeShader.write(frag, 'fragColor[0] = vec4(n.xy, 1.0, packFloatInt16(0.0, uint(0)));'); NodeShader.write(frag, 'vec3 idcol = pow(textureLod(texcolorid, texCoord, 0.0).rgb, vec3(2.2, 2.2, 2.2));'); @@ -111,7 +111,7 @@ class MakeMesh { NodeShader.write(frag, 'vec4 texpaint_pack_sample;'); NodeShader.write(frag, 'float texpaint_opac;'); - if (MakeMaterial.heightUsed) { + if (MakeMaterial.height_used) { NodeShader.write(frag, 'float height0 = 0.0;'); NodeShader.write(frag, 'float height1 = 0.0;'); NodeShader.write(frag, 'float height2 = 0.0;'); @@ -119,20 +119,20 @@ class MakeMesh { } if (Context.raw.draw_wireframe) { - textureCount++; + texture_count++; NodeShader.add_uniform(frag, 'sampler2D texuvmap', '_texuvmap'); } if (Context.raw.viewport_mode == viewport_mode_t.MASK && SlotLayer.get_masks(Context.raw.layer) != null) { for (let m of SlotLayer.get_masks(Context.raw.layer)) { if (!SlotLayer.is_visible(m)) continue; - textureCount++; + texture_count++; NodeShader.add_uniform(frag, 'sampler2D texpaint_view_mask' + m.id, '_texpaint' + Project.layers.indexOf(m)); } } if (Context.raw.viewport_mode == viewport_mode_t.LIT && Context.raw.render_mode == render_mode_t.FORWARD) { - textureCount += 4; + texture_count += 4; NodeShader.add_uniform(frag, 'sampler2D senvmapBrdf', "$brdf.k"); NodeShader.add_uniform(frag, 'sampler2D senvmapRadiance', '_envmap_radiance'); NodeShader.add_uniform(frag, 'sampler2D sltcMat', '_ltcMat'); @@ -142,18 +142,18 @@ class MakeMesh { // Get layers for this pass MakeMesh.layer_pass_count = 1; let layers: SlotLayerRaw[] = []; - let startCount = textureCount; - let isMaterialTool = Context.raw.tool == workspace_tool_t.MATERIAL; + let start_count: i32 = texture_count; + let is_material_tool: bool = Context.raw.tool == workspace_tool_t.MATERIAL; for (let l of Project.layers) { - if (isMaterialTool && l != Context.raw.layer) continue; + if (is_material_tool && l != Context.raw.layer) continue; if (!SlotLayer.is_layer(l) || !SlotLayer.is_visible(l)) continue; - let count = 3; - let masks = SlotLayer.get_masks(l); + let count: i32 = 3; + let masks: SlotLayerRaw[] = SlotLayer.get_masks(l); if (masks != null) count += masks.length; - textureCount += count; - if (textureCount >= MakeMesh.get_max_textures()) { - textureCount = startCount + count + 3; // gbuffer0_copy, gbuffer1_copy, gbuffer2_copy + texture_count += count; + if (texture_count >= MakeMesh.get_max_textures()) { + texture_count = start_count + count + 3; // gbuffer0_copy, gbuffer1_copy, gbuffer2_copy MakeMesh.layer_pass_count++; } if (layerPass == MakeMesh.layer_pass_count - 1) { @@ -161,22 +161,22 @@ class MakeMesh { } } - let lastPass = layerPass == MakeMesh.layer_pass_count - 1; + let last_pass: bool = layerPass == MakeMesh.layer_pass_count - 1; for (let l of layers) { if (SlotLayer.get_object_mask(l) > 0) { NodeShader.add_uniform(frag, 'int uid', '_uid'); if (SlotLayer.get_object_mask(l) > Project.paint_objects.length) { // Atlas - let visibles = Project.get_atlas_objects(SlotLayer.get_object_mask(l)); + let visibles: mesh_object_t[] = Project.get_atlas_objects(SlotLayer.get_object_mask(l)); NodeShader.write(frag, 'if ('); - for (let i = 0; i < visibles.length; ++i) { + for (let i: i32 = 0; i < visibles.length; ++i) { if (i > 0) NodeShader.write(frag, ' || '); NodeShader.write(frag, `${visibles[i].base.uid} == uid`); } NodeShader.write(frag, ') {'); } else { // Object mask - let uid = Project.paint_objects[SlotLayer.get_object_mask(l) - 1].base.uid; + let uid: i32 = Project.paint_objects[SlotLayer.get_object_mask(l) - 1].base.uid; NodeShader.write(frag, `if (${uid} == uid) {`); } } @@ -190,17 +190,17 @@ class MakeMesh { // } // ///end - let masks = SlotLayer.get_masks(l); + let masks: SlotLayerRaw[] = SlotLayer.get_masks(l); if (masks != null) { - let hasVisible = false; + let has_visible: bool = false; for (let m of masks) { if (SlotLayer.is_visible(m)) { - hasVisible = true; + has_visible = true; break; } } - if (hasVisible) { - let texpaint_mask = 'texpaint_mask' + l.id; + if (has_visible) { + let texpaint_mask: string = 'texpaint_mask' + l.id; NodeShader.write(frag, `float ${texpaint_mask} = 0.0;`); for (let m of masks) { if (!SlotLayer.is_visible(m)) continue; @@ -218,7 +218,7 @@ class MakeMesh { NodeShader.write(frag, `texpaint_opac *= ${SlotLayer.get_opacity(l)};`); } - if (l.paintBase) { + if (l.paint_base) { if (l == Project.layers[0]) { NodeShader.write(frag, 'basecol = texpaint_sample.rgb * texpaint_opac;'); } @@ -227,16 +227,16 @@ class MakeMesh { } } - if (l.paintNor || MakeMaterial.emisUsed) { + if (l.paint_nor || MakeMaterial.emis_used) { NodeShader.add_shared_sampler(frag, 'sampler2D texpaint_nor' + l.id); NodeShader.write(frag, 'texpaint_nor_sample = textureLodShared(texpaint_nor' + l.id + ', texCoord, 0.0);'); - if (MakeMaterial.emisUsed) { + if (MakeMaterial.emis_used) { NodeShader.write(frag, 'if (texpaint_opac > 0.0) matid = texpaint_nor_sample.a;'); } - if (l.paintNor) { - if (l.paintNorBlend) { + if (l.paint_nor) { + if (l.paint_nor_blend) { // Whiteout blend NodeShader.write(frag, '{'); NodeShader.write(frag, 'vec3 n1 = ntex * vec3(2.0, 2.0, 2.0) - vec3(1.0, 1.0, 1.0);'); @@ -250,21 +250,21 @@ class MakeMesh { } } - if (l.paintOcc || l.paintRough || l.paintMet || (l.paintHeight && MakeMaterial.heightUsed)) { + if (l.paint_occ || l.paint_rough || l.paint_met || (l.paint_height && MakeMaterial.height_used)) { NodeShader.add_shared_sampler(frag, 'sampler2D texpaint_pack' + l.id); NodeShader.write(frag, 'texpaint_pack_sample = textureLodShared(texpaint_pack' + l.id + ', texCoord, 0.0);'); - if (l.paintOcc) { + if (l.paint_occ) { NodeShader.write(frag, 'occlusion = mix(occlusion, texpaint_pack_sample.r, texpaint_opac);'); } - if (l.paintRough) { + if (l.paint_rough) { NodeShader.write(frag, 'roughness = mix(roughness, texpaint_pack_sample.g, texpaint_opac);'); } - if (l.paintMet) { + if (l.paint_met) { NodeShader.write(frag, 'metallic = mix(metallic, texpaint_pack_sample.b, texpaint_opac);'); } - if (l.paintHeight && MakeMaterial.heightUsed) { - let assign = l.paintHeightBlend ? "+=" : "="; + if (l.paint_height && MakeMaterial.height_used) { + let assign: string = l.paint_height_blend ? "+=" : "="; NodeShader.write(frag, `height ${assign} texpaint_pack_sample.a * texpaint_opac;`); NodeShader.write(frag, '{'); NodeShader.add_uniform(frag, 'vec2 texpaintSize', '_texpaintSize'); @@ -282,7 +282,7 @@ class MakeMesh { } } - if (lastPass && Context.raw.draw_texels) { + if (last_pass && Context.raw.draw_texels) { NodeShader.add_uniform(frag, 'vec2 texpaintSize', '_texpaintSize'); NodeShader.write(frag, 'vec2 texel0 = texCoord * texpaintSize * 0.01;'); NodeShader.write(frag, 'vec2 texel1 = texCoord * texpaintSize * 0.1;'); @@ -292,11 +292,11 @@ class MakeMesh { NodeShader.write(frag, 'basecol *= max(float(mod(int(texel2.x), 2.0) == mod(int(texel2.y), 2.0)), 0.9);'); } - if (lastPass && Context.raw.draw_wireframe) { + if (last_pass && Context.raw.draw_wireframe) { NodeShader.write(frag, 'basecol *= 1.0 - textureLod(texuvmap, texCoord, 0.0).r;'); } - if (MakeMaterial.heightUsed) { + if (MakeMaterial.height_used) { NodeShader.write(frag, 'if (height > 0.0) {'); // NodeShader.write(frag, 'float height_dx = dFdx(height * 16.0);'); // NodeShader.write(frag, 'float height_dy = dFdy(height * 16.0);'); @@ -309,7 +309,7 @@ class MakeMesh { NodeShader.write(frag, '}'); } - if (!lastPass) { + if (!last_pass) { NodeShader.write(frag, 'fragColor[0] = vec4(basecol, opacity);'); NodeShader.write(frag, 'fragColor[1] = vec4(ntex, matid);'); NodeShader.write(frag, 'fragColor[2] = vec4(occlusion, roughness, metallic, height);'); @@ -334,7 +334,7 @@ class MakeMesh { NodeShader.write(frag, 'basecol = pow(basecol, vec3(2.2, 2.2, 2.2));'); if (Context.raw.viewport_shader != null) { - let color = Context.raw.viewport_shader(frag); + let color: string = Context.raw.viewport_shader(frag); NodeShader.write(frag, `fragColor[1] = vec4(${color}, 1.0);`); } else if (Context.raw.render_mode == render_mode_t.FORWARD && Context.raw.viewport_mode != viewport_mode_t.PATH_TRACE) { @@ -383,29 +383,29 @@ class MakeMesh { NodeShader.write(frag, 'fragColor[1] = vec4(direct + indirect, 1.0);'); } else { // Deferred, Pathtraced - if (MakeMaterial.emisUsed) NodeShader.write(frag, 'if (int(matid * 255.0) % 3 == 1) basecol *= 10.0;'); // Boost for bloom + if (MakeMaterial.emis_used) NodeShader.write(frag, 'if (int(matid * 255.0) % 3 == 1) basecol *= 10.0;'); // Boost for bloom NodeShader.write(frag, 'fragColor[1] = vec4(basecol, occlusion);'); } } - else if (Context.raw.viewport_mode == viewport_mode_t.BASE_COLOR && Context.raw.layer.paintBase) { + else if (Context.raw.viewport_mode == viewport_mode_t.BASE_COLOR && Context.raw.layer.paint_base) { NodeShader.write(frag, 'fragColor[1] = vec4(basecol, 1.0);'); } - else if (Context.raw.viewport_mode == viewport_mode_t.NORMAL_MAP && Context.raw.layer.paintNor) { + else if (Context.raw.viewport_mode == viewport_mode_t.NORMAL_MAP && Context.raw.layer.paint_nor) { NodeShader.write(frag, 'fragColor[1] = vec4(ntex.rgb, 1.0);'); } - else if (Context.raw.viewport_mode == viewport_mode_t.OCCLUSION && Context.raw.layer.paintOcc) { + else if (Context.raw.viewport_mode == viewport_mode_t.OCCLUSION && Context.raw.layer.paint_occ) { NodeShader.write(frag, 'fragColor[1] = vec4(vec3(occlusion, occlusion, occlusion), 1.0);'); } - else if (Context.raw.viewport_mode == viewport_mode_t.ROUGHNESS && Context.raw.layer.paintRough) { + else if (Context.raw.viewport_mode == viewport_mode_t.ROUGHNESS && Context.raw.layer.paint_rough) { NodeShader.write(frag, 'fragColor[1] = vec4(vec3(roughness, roughness, roughness), 1.0);'); } - else if (Context.raw.viewport_mode == viewport_mode_t.METALLIC && Context.raw.layer.paintMet) { + else if (Context.raw.viewport_mode == viewport_mode_t.METALLIC && Context.raw.layer.paint_met) { NodeShader.write(frag, 'fragColor[1] = vec4(vec3(metallic, metallic, metallic), 1.0);'); } - else if (Context.raw.viewport_mode == viewport_mode_t.OPACITY && Context.raw.layer.paintOpac) { + else if (Context.raw.viewport_mode == viewport_mode_t.OPACITY && Context.raw.layer.paint_opac) { NodeShader.write(frag, 'fragColor[1] = vec4(vec3(texpaint_sample.a, texpaint_sample.a, texpaint_sample.a), 1.0);'); } - else if (Context.raw.viewport_mode == viewport_mode_t.HEIGHT && Context.raw.layer.paintHeight) { + else if (Context.raw.viewport_mode == viewport_mode_t.HEIGHT && Context.raw.layer.paint_height) { NodeShader.write(frag, 'fragColor[1] = vec4(vec3(height, height, height), 1.0);'); } else if (Context.raw.viewport_mode == viewport_mode_t.EMISSION) { diff --git a/armorpaint/Sources/MakeMeshPreview.ts b/armorpaint/Sources/MakeMeshPreview.ts index 118e1bd9..9625df14 100644 --- a/armorpaint/Sources/MakeMeshPreview.ts +++ b/armorpaint/Sources/MakeMeshPreview.ts @@ -4,8 +4,8 @@ class MakeMeshPreview { static opacity_discard_decal: f32 = 0.05; static run = (data: material_t, matcon: material_context_t): NodeShaderContextRaw => { - let context_id = "mesh"; - let con_mesh = NodeShaderContext.create(data, { + let context_id: string = "mesh"; + let con_mesh: NodeShaderContextRaw = NodeShaderContext.create(data, { name: context_id, depth_write: true, compare_mode: "less", @@ -15,13 +15,13 @@ class MakeMeshPreview { depth_attachment: "DEPTH32" }); - let vert = NodeShaderContext.make_vert(con_mesh); - let frag = NodeShaderContext.make_frag(con_mesh); + let vert: NodeShaderRaw = NodeShaderContext.make_vert(con_mesh); + let frag: NodeShaderRaw = NodeShaderContext.make_frag(con_mesh); frag.ins = vert.outs; - let pos = "pos"; + let pos: string = "pos"; ///if arm_skin - let skin = mesh_data_get_vertex_array(Context.raw.paint_object.data, "bone") != null; + let skin: bool = mesh_data_get_vertex_array(Context.raw.paint_object.data, "bone") != null; if (skin) { pos = "spos"; NodeShaderContext.add_elem(con_mesh, "bone", 'short4norm'); @@ -43,26 +43,26 @@ class MakeMeshPreview { NodeShader.add_uniform(vert, 'mat4 WVP', '_world_view_proj_matrix'); NodeShader.write_attrib(vert, `gl_Position = mul(vec4(${pos}.xyz, 1.0), WVP);`); - let brushScale = (Context.raw.brush_scale * Context.raw.brush_nodes_scale) + ""; + let brush_scale: string = (Context.raw.brush_scale * Context.raw.brush_nodes_scale) + ""; NodeShader.add_out(vert, 'vec2 texCoord'); - NodeShader.write_attrib(vert, `texCoord = tex * float(${brushScale});`); + NodeShader.write_attrib(vert, `texCoord = tex * float(${brush_scale});`); - let decal = Context.raw.decal_preview; + let decal: bool = Context.raw.decal_preview; ParserMaterial.sample_keep_aspect = decal; - ParserMaterial.sample_uv_scale = brushScale; - ParserMaterial.parse_height = MakeMaterial.heightUsed; + ParserMaterial.sample_uv_scale = brush_scale; + ParserMaterial.parse_height = MakeMaterial.height_used; ParserMaterial.parse_height_as_channel = true; - let sout = ParserMaterial.parse(UINodes.get_canvas_material(), con_mesh, vert, frag, matcon); + let sout: shader_out_t = ParserMaterial.parse(UINodes.get_canvas_material(), con_mesh, vert, frag, matcon); ParserMaterial.parse_height = false; ParserMaterial.parse_height_as_channel = false; ParserMaterial.sample_keep_aspect = false; - let base = sout.out_basecol; - let rough = sout.out_roughness; - let met = sout.out_metallic; - let occ = sout.out_occlusion; - let opac = sout.out_opacity; - let height = sout.out_height; - let nortan = ParserMaterial.out_normaltan; + let base: string = sout.out_basecol; + let rough: string = sout.out_roughness; + let met: string = sout.out_metallic; + let occ: string = sout.out_occlusion; + let opac: string = sout.out_opacity; + let height: string = sout.out_height; + let nortan: string = ParserMaterial.out_normaltan; NodeShader.write(frag, `vec3 basecol = pow(${base}, vec3(2.2, 2.2, 2.2));`); NodeShader.write(frag, `float roughness = ${rough};`); NodeShader.write(frag, `float metallic = ${met};`); @@ -75,7 +75,7 @@ class MakeMeshPreview { // NodeShader.write(vert, `float vheight = ${height};`); // NodeShader.add_out(vert, 'float height'); // NodeShader.write(vert, 'height = vheight;'); - // let displaceStrength = 0.1; + // let displaceStrength: f32 = 0.1; // if (MakeMaterial.heightUsed && displaceStrength > 0.0) { // NodeShader.write(vert, `vec3 pos2 = ${pos}.xyz + vec3(nor.xy, pos.w) * vec3(${height}, ${height}, ${height}) * vec3(${displaceStrength}, ${displaceStrength}, ${displaceStrength});`); // NodeShader.write(vert, 'gl_Position = mul(vec4(pos2.xyz, 1.0), WVP);'); @@ -84,11 +84,11 @@ class MakeMeshPreview { if (decal) { if (Context.raw.tool == workspace_tool_t.TEXT) { NodeShader.add_uniform(frag, 'sampler2D textexttool', '_textexttool'); - NodeShader.write(frag, `opacity *= textureLod(textexttool, texCoord / float(${brushScale}), 0.0).r;`); + NodeShader.write(frag, `opacity *= textureLod(textexttool, texCoord / float(${brush_scale}), 0.0).r;`); } } if (decal) { - let opac = MakeMeshPreview.opacity_discard_decal; + let opac: f32 = MakeMeshPreview.opacity_discard_decal; NodeShader.write(frag, `if (opacity < ${opac}) discard;`); } @@ -99,7 +99,7 @@ class MakeMeshPreview { NodeShader.add_function(frag, ShaderFunctions.str_cotangent_frame); NodeShader.add_function(frag, ShaderFunctions.str_octahedron_wrap); - if (MakeMaterial.heightUsed) { + if (MakeMaterial.height_used) { NodeShader.write(frag, 'if (height > 0.0) {'); NodeShader.write(frag, 'float height_dx = dFdx(height * 2.0);'); NodeShader.write(frag, 'float height_dy = dFdy(height * 2.0);'); diff --git a/armorpaint/Sources/MakeNodePreview.ts b/armorpaint/Sources/MakeNodePreview.ts index 86cc4887..951fd45e 100644 --- a/armorpaint/Sources/MakeNodePreview.ts +++ b/armorpaint/Sources/MakeNodePreview.ts @@ -2,8 +2,8 @@ class MakeNodePreview { static run = (data: material_t, matcon: material_context_t, node: zui_node_t, group: zui_node_canvas_t, parents: zui_node_t[]): NodeShaderContextRaw => { - let context_id = "mesh"; - let con_mesh = NodeShaderContext.create(data, { + let context_id: string = "mesh"; + let con_mesh: NodeShaderContextRaw = NodeShaderContext.create(data, { name: context_id, depth_write: false, compare_mode: "always", @@ -13,8 +13,8 @@ class MakeNodePreview { }); con_mesh.allow_vcols = true; - let vert = NodeShaderContext.make_vert(con_mesh); - let frag = NodeShaderContext.make_frag(con_mesh); + let vert: NodeShaderRaw = NodeShaderContext.make_vert(con_mesh); + let frag: NodeShaderRaw = NodeShaderContext.make_frag(con_mesh); frag.ins = vert.outs; NodeShader.write_attrib(vert, 'gl_Position = vec4(pos.xy * 3.0, 0.0, 1.0);'); // Pos unpack @@ -33,9 +33,7 @@ class MakeNodePreview { ParserMaterial.push_group(group); ParserMaterial.parents = parents; } - let links = ParserMaterial.links; - let nodes = Context.raw.material.nodes; - + let links: zui_node_link_t[] = ParserMaterial.links; let link: zui_node_link_t = { id: zui_get_link_id(links), from_id: node.id, from_socket: Context.raw.node_preview_socket, to_id: -1, to_socket: -1 }; links.push(link); @@ -46,9 +44,9 @@ class MakeNodePreview { ParserMaterial.matcon = matcon; ParserMaterial.transform_color_space = false; - let res = ParserMaterial.write_result(link); + let res: string = ParserMaterial.write_result(link); ParserMaterial.transform_color_space = true; - let st = node.outputs[link.from_socket].type; + let st: string = node.outputs[link.from_socket].type; if (st != "RGB" && st != "RGBA" && st != "VECTOR") { res = ParserMaterial.to_vec3(res); } diff --git a/armorpaint/Sources/MakePaint.ts b/armorpaint/Sources/MakePaint.ts index fc2ff35d..bf2182e3 100644 --- a/armorpaint/Sources/MakePaint.ts +++ b/armorpaint/Sources/MakePaint.ts @@ -12,9 +12,9 @@ class MakePaint { } static run = (data: material_t, matcon: material_context_t): NodeShaderContextRaw => { - let context_id = "paint"; + let context_id: string = "paint"; - let con_paint = NodeShaderContext.create(data, { + let con_paint: NodeShaderContextRaw = NodeShaderContext.create(data, { name: context_id, depth_write: false, compare_mode: "always", // TODO: align texcoords winding order @@ -35,8 +35,8 @@ class MakePaint { con_paint.data.color_writes_alpha = [true, true, true, true]; con_paint.allow_vcols = mesh_data_get_vertex_array(Context.raw.paint_object.data, 'col') != null; - let vert = NodeShaderContext.make_vert(con_paint); - let frag = NodeShaderContext.make_frag(con_paint); + let vert: NodeShaderRaw = NodeShaderContext.make_vert(con_paint); + let frag: NodeShaderRaw = NodeShaderContext.make_frag(con_paint); frag.ins = vert.outs; ///if (krom_direct3d12 || krom_vulkan || krom_metal) @@ -62,9 +62,9 @@ class MakePaint { return con_paint; } - let faceFill = Context.raw.tool == workspace_tool_t.FILL && Context.raw.fill_type_handle.position == fill_type_t.FACE; - let uvIslandFill = Context.raw.tool == workspace_tool_t.FILL && Context.raw.fill_type_handle.position == fill_type_t.UV_ISLAND; - let decal = Context.raw.tool == workspace_tool_t.DECAL || Context.raw.tool == workspace_tool_t.TEXT; + let face_fill: bool = Context.raw.tool == workspace_tool_t.FILL && Context.raw.fill_type_handle.position == fill_type_t.FACE; + let uv_island_fill: bool = Context.raw.tool == workspace_tool_t.FILL && Context.raw.fill_type_handle.position == fill_type_t.UV_ISLAND; + let decal: bool = Context.raw.tool == workspace_tool_t.DECAL || Context.raw.tool == workspace_tool_t.TEXT; ///if (krom_direct3d11 || krom_direct3d12 || krom_metal || krom_vulkan) NodeShader.write(vert, 'vec2 tpos = vec2(tex.x * 2.0 - 1.0, (1.0 - tex.y) * 2.0 - 1.0);'); @@ -74,8 +74,8 @@ class MakePaint { NodeShader.write(vert, 'gl_Position = vec4(tpos, 0.0, 1.0);'); - let decalLayer = Context.raw.layer.fill_layer != null && Context.raw.layer.uvType == uv_type_t.PROJECT; - if (decalLayer) { + let decal_layer: bool = Context.raw.layer.fill_layer != null && Context.raw.layer.uv_type == uv_type_t.PROJECT; + if (decal_layer) { NodeShader.add_uniform(vert, 'mat4 WVP', '_decalLayerMatrix'); } else { @@ -89,8 +89,8 @@ class MakePaint { NodeShader.write_attrib(frag, 'sp.y = 1.0 - sp.y;'); NodeShader.write_attrib(frag, 'sp.z -= 0.0001;'); // small bias - let uvType = Context.raw.layer.fill_layer != null ? Context.raw.layer.uvType : Context.raw.brush_paint; - if (uvType == uv_type_t.PROJECT) frag.ndcpos = true; + let uv_type: uv_type_t = Context.raw.layer.fill_layer != null ? Context.raw.layer.uv_type : Context.raw.brush_paint; + if (uv_type == uv_type_t.PROJECT) frag.ndcpos = true; NodeShader.add_uniform(frag, 'vec4 inp', '_inputBrush'); NodeShader.add_uniform(frag, 'vec4 inplast', '_inputBrushLast'); @@ -115,16 +115,16 @@ class MakePaint { Context.raw.tool == workspace_tool_t.PARTICLE || decal) { - let depthReject = !Context.raw.xray; - if (Config.raw.brush_3d && !Config.raw.brush_depth_reject) depthReject = false; + let depth_reject: bool = !Context.raw.xray; + if (Config.raw.brush_3d && !Config.raw.brush_depth_reject) depth_reject = false; // TODO: sp.z needs to take height channel into account - let particle = Context.raw.tool == workspace_tool_t.PARTICLE; + let particle: bool = Context.raw.tool == workspace_tool_t.PARTICLE; if (Config.raw.brush_3d && !decal && !particle) { - if (MakeMaterial.heightUsed || Context.raw.sym_x || Context.raw.sym_y || Context.raw.sym_z) depthReject = false; + if (MakeMaterial.height_used || Context.raw.sym_x || Context.raw.sym_y || Context.raw.sym_z) depth_reject = false; } - if (depthReject) { + if (depth_reject) { ///if (krom_direct3d11 || krom_direct3d12 || krom_metal || krom_vulkan) NodeShader.write(frag, 'if (sp.z > textureLod(gbufferD, sp.xy, 0.0).r + 0.0005) discard;'); ///else @@ -136,8 +136,8 @@ class MakePaint { } else { // Fill, Bake NodeShader.write(frag, 'float dist = 0.0;'); - let angleFill = Context.raw.tool == workspace_tool_t.FILL && Context.raw.fill_type_handle.position == fill_type_t.ANGLE; - if (angleFill) { + let angle_fill: bool = Context.raw.tool == workspace_tool_t.FILL && Context.raw.fill_type_handle.position == fill_type_t.ANGLE; + if (angle_fill) { NodeShader.add_function(frag, ShaderFunctions.str_octahedron_wrap); NodeShader.add_uniform(frag, 'sampler2D gbuffer0'); NodeShader.write(frag, 'vec2 g0 = textureLod(gbuffer0, inp.xy, 0.0).rg;'); @@ -146,11 +146,11 @@ class MakePaint { NodeShader.write(frag, 'wn.xy = wn.z >= 0.0 ? g0.xy : octahedronWrap(g0.xy);'); NodeShader.write(frag, 'wn = normalize(wn);'); frag.n = true; - let angle = Context.raw.brush_angle_reject_dot; + let angle: f32 = Context.raw.brush_angle_reject_dot; NodeShader.write(frag, `if (dot(wn, n) < ${angle}) discard;`); } - let stencilFill = Context.raw.tool == workspace_tool_t.FILL && Context.raw.brush_stencil_image != null; - if (stencilFill) { + let stencil_fill: bool = Context.raw.tool == workspace_tool_t.FILL && Context.raw.brush_stencil_image != null; + if (stencil_fill) { ///if (krom_direct3d11 || krom_direct3d12 || krom_metal || krom_vulkan) NodeShader.write(frag, 'if (sp.z > textureLod(gbufferD, sp.xy, 0.0).r + 0.0005) discard;'); ///else @@ -159,16 +159,16 @@ class MakePaint { } } - if (Context.raw.colorid_picked || faceFill || uvIslandFill) { + if (Context.raw.colorid_picked || face_fill || uv_island_fill) { NodeShader.add_out(vert, 'vec2 texCoordPick'); NodeShader.write(vert, 'texCoordPick = tex;'); if (Context.raw.colorid_picked) { MakeDiscard.color_id(vert, frag); } - if (faceFill) { + if (face_fill) { MakeDiscard.face(vert, frag); } - else if (uvIslandFill) { + else if (uv_island_fill) { MakeDiscard.uv_island(vert, frag); } } @@ -198,24 +198,24 @@ class MakePaint { ParserMaterial.parse_subsurface = Context.raw.material.paint_subs; ParserMaterial.parse_height = Context.raw.material.paint_height; ParserMaterial.parse_height_as_channel = true; - let uvType = Context.raw.layer.fill_layer != null ? Context.raw.layer.uvType : Context.raw.brush_paint; - ParserMaterial.triplanar = uvType == uv_type_t.TRIPLANAR && !decal; + let uv_type: uv_type_t = Context.raw.layer.fill_layer != null ? Context.raw.layer.uv_type : Context.raw.brush_paint; + ParserMaterial.triplanar = uv_type == uv_type_t.TRIPLANAR && !decal; ParserMaterial.sample_keep_aspect = decal; ParserMaterial.sample_uv_scale = 'brushScale'; - let sout = ParserMaterial.parse(UINodes.get_canvas_material(), con_paint, vert, frag, matcon); + let sout: shader_out_t = ParserMaterial.parse(UINodes.get_canvas_material(), con_paint, vert, frag, matcon); ParserMaterial.parse_emission = false; ParserMaterial.parse_subsurface = false; ParserMaterial.parse_height_as_channel = false; ParserMaterial.parse_height = false; - let base = sout.out_basecol; - let rough = sout.out_roughness; - let met = sout.out_metallic; - let occ = sout.out_occlusion; - let nortan = ParserMaterial.out_normaltan; - let height = sout.out_height; - let opac = sout.out_opacity; - let emis = sout.out_emission; - let subs = sout.out_subsurface; + let base: string = sout.out_basecol; + let rough: string = sout.out_roughness; + let met: string = sout.out_metallic; + let occ: string = sout.out_occlusion; + let nortan: string = ParserMaterial.out_normaltan; + let height: string = sout.out_height; + let opac: string = sout.out_opacity; + let emis: string = sout.out_emission; + let subs: string = sout.out_subsurface; NodeShader.write(frag, `vec3 basecol = ${base};`); NodeShader.write(frag, `float roughness = ${rough};`); NodeShader.write(frag, `float metallic = ${met};`); @@ -233,13 +233,13 @@ class MakePaint { if (Context.raw.material.paint_subs) { NodeShader.write(frag, `float subs = ${subs};`); } - if (parseFloat(height) != 0.0 && !MakeMaterial.heightUsed) { - MakeMaterial.heightUsed = true; + if (parseFloat(height) != 0.0 && !MakeMaterial.height_used) { + MakeMaterial.height_used = true; // Height used for the first time, also rebuild vertex shader return MakePaint.run(data, matcon); } - if (parseFloat(emis) != 0.0) MakeMaterial.emisUsed = true; - if (parseFloat(subs) != 0.0) MakeMaterial.subsUsed = true; + if (parseFloat(emis) != 0.0) MakeMaterial.emis_used = true; + if (parseFloat(subs) != 0.0) MakeMaterial.subs_used = true; } if (Context.raw.brush_mask_image != null && Context.raw.tool == workspace_tool_t.DECAL) { @@ -297,7 +297,7 @@ class MakePaint { NodeShader.write(frag, 'if (brushDirection.z == 0.0) discard;'); NodeShader.write(frag, 'pa_mask = vec2(pa_mask.x * brushDirection.x - pa_mask.y * brushDirection.y, pa_mask.x * brushDirection.y + pa_mask.y * brushDirection.x);'); } - let angle = Context.raw.brush_angle + Context.raw.brush_nodes_angle; + let angle: f32 = Context.raw.brush_angle + Context.raw.brush_nodes_angle; if (angle != 0.0) { NodeShader.add_uniform(frag, 'vec2 brushAngle', '_brushAngle'); NodeShader.write(frag, 'pa_mask.xy = vec2(pa_mask.x * brushAngle.x - pa_mask.y * brushAngle.y, pa_mask.x * brushAngle.y + pa_mask.y * brushAngle.x);'); @@ -340,12 +340,12 @@ class MakePaint { NodeShader.add_uniform(frag, 'sampler2D texpaint_undo', '_texpaint_undo'); NodeShader.write(frag, 'vec4 sample_undo = textureLod(texpaint_undo, sample_tc, 0.0);'); - let matid = Context.raw.material.id / 255; + let matid: f32 = Context.raw.material.id / 255; if (Context.raw.picker_mask_handle.position == picker_mask_t.MATERIAL) { matid = Context.raw.materialid_picked / 255; // Keep existing material id in place when mask is set } - let matidString = ParserMaterial.vec1(matid * 3.0); - NodeShader.write(frag, `float matid = ${matidString};`); + let matid_string: string = ParserMaterial.vec1(matid * 3.0); + NodeShader.write(frag, `float matid = ${matid_string};`); // matid % 3 == 0 - normal, 1 - emission, 2 - subsurface if (Context.raw.material.paint_emis) { @@ -361,9 +361,9 @@ class MakePaint { NodeShader.write(frag, '}'); } - let isMask = SlotLayer.is_mask(Context.raw.layer); - let layered = Context.raw.layer != Project.layers[0]; - if (layered && !isMask) { + let is_mask: bool = SlotLayer.is_mask(Context.raw.layer); + let layered: bool = Context.raw.layer != Project.layers[0]; + if (layered && !is_mask) { if (Context.raw.tool == workspace_tool_t.ERASER) { NodeShader.write(frag, 'fragColor[0] = vec4(mix(sample_undo.rgb, vec3(0.0, 0.0, 0.0), str), sample_undo.a - str);'); NodeShader.write(frag, 'nortan = vec3(0.5, 0.5, 1.0);'); @@ -385,8 +385,8 @@ class MakePaint { } NodeShader.write(frag, 'fragColor[1] = vec4(nortan, matid);'); - let height = "0.0"; - if (Context.raw.material.paint_height && MakeMaterial.heightUsed) { + let height: string = "0.0"; + if (Context.raw.material.paint_height && MakeMaterial.height_used) { height = "height"; } @@ -412,7 +412,7 @@ class MakePaint { NodeShader.write(frag, 'vec4 sample_pack_undo = textureLod(texpaint_pack_undo, sample_tc, 0.0);'); NodeShader.write(frag, 'fragColor[0] = vec4(' + MakeMaterial.blend_mode(frag, Context.raw.brush_blending, 'sample_undo.rgb', 'basecol', 'str') + ', max(str, sample_undo.a));'); NodeShader.write(frag, 'fragColor[1] = vec4(mix(sample_nor_undo.rgb, nortan, str), matid);'); - if (Context.raw.material.paint_height && MakeMaterial.heightUsed) { + if (Context.raw.material.paint_height && MakeMaterial.height_used) { NodeShader.write(frag, 'fragColor[2] = mix(sample_pack_undo, vec4(occlusion, roughness, metallic, height), str);'); } else { @@ -449,7 +449,7 @@ class MakePaint { } // Base color only as mask - if (isMask) { + if (is_mask) { // TODO: Apply opacity into base // NodeShader.write(frag, 'fragColor[0].rgb *= fragColor[0].a;'); con_paint.data.color_writes_green[0] = false; diff --git a/armorpaint/Sources/MakeParticle.ts b/armorpaint/Sources/MakeParticle.ts index 6b83d13e..8499a76e 100644 --- a/armorpaint/Sources/MakeParticle.ts +++ b/armorpaint/Sources/MakeParticle.ts @@ -2,8 +2,8 @@ class MakeParticle { static run = (data: material_t): NodeShaderContextRaw => { - let context_id = "mesh"; - let con_part = NodeShaderContext.create(data, { + let context_id: string = "mesh"; + let con_part: NodeShaderContextRaw = NodeShaderContext.create(data, { name: context_id, depth_write: false, compare_mode: "always", @@ -12,8 +12,8 @@ class MakeParticle { color_attachments: ["R8"] }); - let vert = NodeShaderContext.make_vert(con_part); - let frag = NodeShaderContext.make_frag(con_part); + let vert: NodeShaderRaw = NodeShaderContext.make_vert(con_part); + let frag: NodeShaderRaw = NodeShaderContext.make_frag(con_part); frag.ins = vert.outs; NodeShader.write_attrib(vert, 'vec4 spos = vec4(pos.xyz, 1.0);'); @@ -25,7 +25,7 @@ class MakeParticle { NodeShader.add_uniform(vert, 'mat4 pd', '_particle_data'); - let str_tex_hash = "float fhash(int n) { return fract(sin(float(n)) * 43758.5453); }\n"; + let str_tex_hash: string = "float fhash(int n) { return fract(sin(float(n)) * 43758.5453); }\n"; NodeShader.add_function(vert, str_tex_hash); NodeShader.add_out(vert, 'float p_age'); NodeShader.write(vert, 'p_age = pd[3][3] - float(gl_InstanceID) * pd[0][1];'); diff --git a/armorpaint/Sources/MakeTexcoord.ts b/armorpaint/Sources/MakeTexcoord.ts index 9f5a17b9..4fbe98d9 100644 --- a/armorpaint/Sources/MakeTexcoord.ts +++ b/armorpaint/Sources/MakeTexcoord.ts @@ -3,17 +3,17 @@ class MakeTexcoord { static run = (vert: NodeShaderRaw, frag: NodeShaderRaw) => { - let fillLayer = Context.raw.layer.fill_layer != null; - let uvType = fillLayer ? Context.raw.layer.uvType : Context.raw.brush_paint; - let decal = Context.raw.tool == workspace_tool_t.DECAL || Context.raw.tool == workspace_tool_t.TEXT; - let angle = Context.raw.brush_angle + Context.raw.brush_nodes_angle; - let uvAngle = fillLayer ? Context.raw.layer.angle : angle; + let fill_layer: bool = Context.raw.layer.fill_layer != null; + let uv_type: uv_type_t = fill_layer ? Context.raw.layer.uv_type : Context.raw.brush_paint; + let decal: bool = Context.raw.tool == workspace_tool_t.DECAL || Context.raw.tool == workspace_tool_t.TEXT; + let angle: f32 = Context.raw.brush_angle + Context.raw.brush_nodes_angle; + let uvAngle: f32 = fill_layer ? Context.raw.layer.angle : angle; - if (uvType == uv_type_t.PROJECT || decal) { // TexCoords - project + if (uv_type == uv_type_t.PROJECT || decal) { // TexCoords - project NodeShader.add_uniform(frag, 'float brushScale', '_brushScale'); NodeShader.write_attrib(frag, 'vec2 uvsp = sp.xy;'); - if (fillLayer) { // Decal layer + if (fill_layer) { // Decal layer NodeShader.write_attrib(frag, 'if (uvsp.x < 0.0 || uvsp.y < 0.0 || uvsp.x > 1.0 || uvsp.y > 1.0) discard;'); if (uvAngle != 0.0) { @@ -23,8 +23,8 @@ class MakeTexcoord { frag.n = true; NodeShader.add_uniform(frag, 'vec3 decalLayerNor', '_decalLayerNor'); - let dotAngle = Context.raw.brush_angle_reject_dot; - NodeShader.write(frag, `if (abs(dot(n, decalLayerNor) - 1.0) > ${dotAngle}) discard;`); + let dot_angle: f32 = Context.raw.brush_angle_reject_dot; + NodeShader.write(frag, `if (abs(dot(n, decalLayerNor) - 1.0) > ${dot_angle}) discard;`); frag.wposition = true; NodeShader.add_uniform(frag, 'vec3 decalLayerLoc', '_decalLayerLoc'); @@ -66,7 +66,7 @@ class MakeTexcoord { NodeShader.write_attrib(frag, 'vec2 texCoord = uvsp * brushScale;'); } - else if (uvType == uv_type_t.UVMAP) { // TexCoords - uvmap + else if (uv_type == uv_type_t.UVMAP) { // TexCoords - uvmap NodeShader.add_uniform(vert, 'float brushScale', '_brushScale'); NodeShader.add_out(vert, 'vec2 texCoord'); NodeShader.write(vert, 'texCoord = tex * brushScale;'); diff --git a/armorpaint/Sources/NodesBrush.ts b/armorpaint/Sources/NodesBrush.ts index 4e63f272..8213d0c8 100644 --- a/armorpaint/Sources/NodesBrush.ts +++ b/armorpaint/Sources/NodesBrush.ts @@ -30,9 +30,9 @@ class NodesBrush { for (let c of NodesBrush.list) { for (let n of c) { if (n.type == nodeType) { - let canvas = Context.raw.brush.canvas; - let nodes = Context.raw.brush.nodes; - let node = UINodes.make_node(n, nodes, canvas); + let canvas: zui_node_canvas_t = Context.raw.brush.canvas; + let nodes: zui_nodes_t = Context.raw.brush.nodes; + let node: zui_node_t = UINodes.make_node(n, nodes, canvas); canvas.nodes.push(node); return node; } diff --git a/armorpaint/Sources/RenderPathPaint.ts b/armorpaint/Sources/RenderPathPaint.ts index ba9278d6..c94dc4b1 100644 --- a/armorpaint/Sources/RenderPathPaint.ts +++ b/armorpaint/Sources/RenderPathPaint.ts @@ -1,31 +1,31 @@ class RenderPathPaint { - static liveLayer: SlotLayerRaw = null; - static liveLayerDrawn = 0; - static liveLayerLocked = false; - static dilated = true; - static initVoxels = true; // Bake AO - static pushUndoLast: bool; + static live_layer: SlotLayerRaw = null; + static live_layer_drawn: i32 = 0; + static live_layer_locked: bool = false; + static dilated: bool = true; + static init_voxels: bool = true; // Bake AO + static push_undo_last: bool; static painto: mesh_object_t = null; static planeo: mesh_object_t = null; static visibles: bool[] = null; - static mergedObjectVisible = false; - static savedFov = 0.0; - static baking = false; + static merged_object_visible: bool = false; + static saved_fov: f32 = 0.0; + static baking: bool = false; static _texpaint: render_target_t; static _texpaint_nor: render_target_t; static _texpaint_pack: render_target_t; static _texpaint_undo: render_target_t; static _texpaint_nor_undo: render_target_t; static _texpaint_pack_undo: render_target_t; - static lastX = -1.0; - static lastY = -1.0; + static last_x: f32 = -1.0; + static last_y: f32 = -1.0; static init = () => { { - let t = render_target_create(); + let t: render_target_t = render_target_create(); t.name = "texpaint_blend0"; t.width = Config.get_texture_res_x(); t.height = Config.get_texture_res_y(); @@ -33,7 +33,7 @@ class RenderPathPaint { render_path_create_render_target(t); } { - let t = render_target_create(); + let t: render_target_t = render_target_create(); t.name = "texpaint_blend1"; t.width = Config.get_texture_res_x(); t.height = Config.get_texture_res_y(); @@ -41,7 +41,7 @@ class RenderPathPaint { render_path_create_render_target(t); } { - let t = render_target_create(); + let t: render_target_t = render_target_create(); t.name = "texpaint_colorid"; t.width = 1; t.height = 1; @@ -49,7 +49,7 @@ class RenderPathPaint { render_path_create_render_target(t); } { - let t = render_target_create(); + let t: render_target_t = render_target_create(); t.name = "texpaint_picker"; t.width = 1; t.height = 1; @@ -57,7 +57,7 @@ class RenderPathPaint { render_path_create_render_target(t); } { - let t = render_target_create(); + let t: render_target_t = render_target_create(); t.name = "texpaint_nor_picker"; t.width = 1; t.height = 1; @@ -65,7 +65,7 @@ class RenderPathPaint { render_path_create_render_target(t); } { - let t = render_target_create(); + let t: render_target_t = render_target_create(); t.name = "texpaint_pack_picker"; t.width = 1; t.height = 1; @@ -73,7 +73,7 @@ class RenderPathPaint { render_path_create_render_target(t); } { - let t = render_target_create(); + let t: render_target_t = render_target_create(); t.name = "texpaint_uv_picker"; t.width = 1; t.height = 1; @@ -81,7 +81,7 @@ class RenderPathPaint { render_path_create_render_target(t); } { - let t = render_target_create(); + let t: render_target_t = render_target_create(); t.name = "texpaint_posnortex_picker0"; t.width = 1; t.height = 1; @@ -89,7 +89,7 @@ class RenderPathPaint { render_path_create_render_target(t); } { - let t = render_target_create(); + let t: render_target_t = render_target_create(); t.name = "texpaint_posnortex_picker1"; t.width = 1; t.height = 1; @@ -105,15 +105,15 @@ class RenderPathPaint { } static commands_paint = (dilation = true) => { - let tid = Context.raw.layer.id; + let tid: i32 = Context.raw.layer.id; if (Context.raw.pdirty > 0) { ///if arm_physics - let particlePhysics = Context.raw.particle_physics; + let particle_physics: bool = Context.raw.particle_physics; ///else - let particlePhysics = false; + let particle_physics: bool = false; ///end - if (Context.raw.tool == workspace_tool_t.PARTICLE && !particlePhysics) { + if (Context.raw.tool == workspace_tool_t.PARTICLE && !particle_physics) { render_path_set_target("texparticle"); render_path_clear_target(0x00000000); render_path_bind_target("_main", "gbufferD"); @@ -151,10 +151,10 @@ class RenderPathPaint { render_path_bind_target("gbuffer2", "gbuffer2"); render_path_bind_target("_main", "gbufferD"); render_path_draw_meshes("paint"); - let texpaint_posnortex_picker0 = render_path_render_targets.get("texpaint_posnortex_picker0")._image; - let texpaint_posnortex_picker1 = render_path_render_targets.get("texpaint_posnortex_picker1")._image; - let a = new DataView(image_get_pixels(texpaint_posnortex_picker0)); - let b = new DataView(image_get_pixels(texpaint_posnortex_picker1)); + let texpaint_posnortex_picker0: image_t = render_path_render_targets.get("texpaint_posnortex_picker0")._image; + let texpaint_posnortex_picker1: image_t = render_path_render_targets.get("texpaint_posnortex_picker1")._image; + let a: DataView = new DataView(image_get_pixels(texpaint_posnortex_picker0)); + let b: DataView = new DataView(image_get_pixels(texpaint_posnortex_picker1)); Context.raw.posx_picked = a.getFloat32(0, true); Context.raw.posy_picked = a.getFloat32(4, true); Context.raw.posz_picked = a.getFloat32(8, true); @@ -168,24 +168,24 @@ class RenderPathPaint { render_path_set_target("texpaint_picker", ["texpaint_nor_picker", "texpaint_pack_picker", "texpaint_uv_picker"]); render_path_bind_target("gbuffer2", "gbuffer2"); tid = Context.raw.layer.id; - let useLiveLayer = Context.raw.tool == workspace_tool_t.MATERIAL; - if (useLiveLayer) RenderPathPaint.use_live_layer(true); + let use_live_layer: bool = Context.raw.tool == workspace_tool_t.MATERIAL; + if (use_live_layer) RenderPathPaint.use_live_layer(true); render_path_bind_target("texpaint" + tid, "texpaint"); render_path_bind_target("texpaint_nor" + tid, "texpaint_nor"); render_path_bind_target("texpaint_pack" + tid, "texpaint_pack"); render_path_draw_meshes("paint"); - if (useLiveLayer) RenderPathPaint.use_live_layer(false); + if (use_live_layer) RenderPathPaint.use_live_layer(false); UIHeader.header_handle.redraws = 2; UIBase.hwnds[2].redraws = 2; - let texpaint_picker = render_path_render_targets.get("texpaint_picker")._image; - let texpaint_nor_picker = render_path_render_targets.get("texpaint_nor_picker")._image; - let texpaint_pack_picker = render_path_render_targets.get("texpaint_pack_picker")._image; - let texpaint_uv_picker = render_path_render_targets.get("texpaint_uv_picker")._image; - let a = new DataView(image_get_pixels(texpaint_picker)); - let b = new DataView(image_get_pixels(texpaint_nor_picker)); - let c = new DataView(image_get_pixels(texpaint_pack_picker)); - let d = new DataView(image_get_pixels(texpaint_uv_picker)); + let texpaint_picker: image_t = render_path_render_targets.get("texpaint_picker")._image; + let texpaint_nor_picker: image_t = render_path_render_targets.get("texpaint_nor_picker")._image; + let texpaint_pack_picker: image_t = render_path_render_targets.get("texpaint_pack_picker")._image; + let texpaint_uv_picker: image_t = render_path_render_targets.get("texpaint_uv_picker")._image; + let a: DataView = new DataView(image_get_pixels(texpaint_picker)); + let b: DataView = new DataView(image_get_pixels(texpaint_nor_picker)); + let c: DataView = new DataView(image_get_pixels(texpaint_pack_picker)); + let d: DataView = new DataView(image_get_pixels(texpaint_uv_picker)); if (Context.raw.color_picker_callback != null) { Context.raw.color_picker_callback(Context.raw.picked_color); @@ -193,15 +193,15 @@ class RenderPathPaint { // Picked surface values ///if (krom_metal || krom_vulkan) - let i0 = 2; - let i1 = 1; - let i2 = 0; + let i0: i32 = 2; + let i1: i32 = 1; + let i2: i32 = 0; ///else - let i0 = 0; - let i1 = 1; - let i2 = 2; + let i0: i32 = 0; + let i1: i32 = 1; + let i2: i32 = 2; ///end - let i3 = 3; + let i3: i32 = 3; Context.raw.picked_color.base = color_set_rb(Context.raw.picked_color.base, a.getUint8(i0)); Context.raw.picked_color.base = color_set_gb(Context.raw.picked_color.base, a.getUint8(i1)); Context.raw.picked_color.base = color_set_bb(Context.raw.picked_color.base, a.getUint8(i2)); @@ -218,7 +218,7 @@ class RenderPathPaint { // Pick material if (Context.raw.picker_select_material && Context.raw.color_picker_callback == null) { // matid % 3 == 0 - normal, 1 - emission, 2 - subsurface - let matid = Math.floor((b.getUint8(3) - (b.getUint8(3) % 3)) / 3); + let matid: i32 = Math.floor((b.getUint8(3) - (b.getUint8(3) % 3)) / 3); for (let m of Project.materials) { if (m.id == matid) { Context.set_material(m); @@ -232,9 +232,9 @@ class RenderPathPaint { else { ///if arm_voxels if (Context.raw.tool == workspace_tool_t.BAKE && Context.raw.bake_type == bake_type_t.AO) { - if (RenderPathPaint.initVoxels) { - RenderPathPaint.initVoxels = false; - let _rp_gi = Config.raw.rp_gi; + if (RenderPathPaint.init_voxels) { + RenderPathPaint.init_voxels = false; + let _rp_gi: bool = Config.raw.rp_gi; Config.raw.rp_gi = true; RenderPathBase.init_voxels(); Config.raw.rp_gi = _rp_gi; @@ -248,7 +248,7 @@ class RenderPathPaint { } ///end - let texpaint = "texpaint" + tid; + let texpaint: string = "texpaint" + tid; if (Context.raw.tool == workspace_tool_t.BAKE && Context.raw.brush_time == time_delta()) { // Clear to black on bake start render_path_set_target(texpaint); @@ -258,9 +258,9 @@ class RenderPathPaint { render_path_set_target("texpaint_blend1"); render_path_bind_target("texpaint_blend0", "tex"); render_path_draw_shader("shader_datas/copy_pass/copyR8_pass"); - let isMask = SlotLayer.is_mask(Context.raw.layer); - if (isMask) { - let ptid = Context.raw.layer.parent.id; + let is_mask: bool = SlotLayer.is_mask(Context.raw.layer); + if (is_mask) { + let ptid: i32 = Context.raw.layer.parent.id; if (SlotLayer.is_group(Context.raw.layer.parent)) { // Group mask for (let c of SlotLayer.get_children(Context.raw.layer.parent)) { ptid = c.id; @@ -287,11 +287,11 @@ class RenderPathPaint { } // Read texcoords from gbuffer - let readTC = (Context.raw.tool == workspace_tool_t.FILL && Context.raw.fill_type_handle.position == fill_type_t.FACE) || - Context.raw.tool == workspace_tool_t.CLONE || - Context.raw.tool == workspace_tool_t.BLUR || - Context.raw.tool == workspace_tool_t.SMUDGE; - if (readTC) { + let read_tc: bool = (Context.raw.tool == workspace_tool_t.FILL && Context.raw.fill_type_handle.position == fill_type_t.FACE) || + Context.raw.tool == workspace_tool_t.CLONE || + Context.raw.tool == workspace_tool_t.BLUR || + Context.raw.tool == workspace_tool_t.SMUDGE; + if (read_tc) { render_path_bind_target("gbuffer2", "gbuffer2"); } @@ -306,8 +306,8 @@ class RenderPathPaint { t.format = "RGBA32"; render_path_create_render_target(t); } - let blurs = Math.round(Context.raw.bake_curv_smooth); - for (let i = 0; i < blurs; ++i) { + let blurs: i32 = Math.round(Context.raw.bake_curv_smooth); + for (let i: i32 = 0; i < blurs; ++i) { render_path_set_target("texpaint_blur"); render_path_bind_target(texpaint, "tex"); render_path_draw_shader("shader_datas/copy_pass/copy_pass"); @@ -324,7 +324,7 @@ class RenderPathPaint { ///end ///if is_sculpt - let texpaint = "texpaint" + tid; + let texpaint: string = "texpaint" + tid; render_path_set_target("texpaint_blend1"); render_path_bind_target("texpaint_blend0", "tex"); render_path_draw_shader("shader_datas/copy_pass/copyR8_pass"); @@ -336,26 +336,26 @@ class RenderPathPaint { render_path_bind_target("texpaint_blend1", "paintmask"); // Read texcoords from gbuffer - let readTC = (Context.raw.tool == workspace_tool_t.FILL && Context.raw.fill_type_handle.position == fill_type_t.FACE) || - Context.raw.tool == workspace_tool_t.CLONE || - Context.raw.tool == workspace_tool_t.BLUR || - Context.raw.tool == workspace_tool_t.SMUDGE; - if (readTC) { + let read_tc: bool = (Context.raw.tool == workspace_tool_t.FILL && Context.raw.fill_type_handle.position == fill_type_t.FACE) || + Context.raw.tool == workspace_tool_t.CLONE || + Context.raw.tool == workspace_tool_t.BLUR || + Context.raw.tool == workspace_tool_t.SMUDGE; + if (read_tc) { render_path_bind_target("gbuffer2", "gbuffer2"); } render_path_bind_target("gbuffer0_undo", "gbuffer0_undo"); - let materialContexts: material_context_t[] = []; - let shaderContexts: shader_context_t[] = []; - let mats = Project.paint_objects[0].materials; - mesh_object_get_contexts(Project.paint_objects[0], "paint", mats, materialContexts, shaderContexts); + let material_contexts: material_context_t[] = []; + let shader_contexts: shader_context_t[] = []; + let mats: material_data_t[] = Project.paint_objects[0].materials; + mesh_object_get_contexts(Project.paint_objects[0], "paint", mats, material_contexts, shader_contexts); - let cc_context = shaderContexts[0]; + let cc_context: shader_context_t = shader_contexts[0]; if (const_data_screen_aligned_vb == null) const_data_create_screen_aligned_data(); g4_set_pipeline(cc_context._.pipe_state); uniforms_set_context_consts(cc_context,_render_path_bind_params); uniforms_set_obj_consts(cc_context, Project.paint_objects[0].base); - uniforms_set_material_consts(cc_context, materialContexts[0]); + uniforms_set_material_consts(cc_context, material_contexts[0]); g4_set_vertex_buffer(const_data_screen_aligned_vb); g4_set_index_buffer(const_data_screen_aligned_ib); g4_draw(); @@ -365,8 +365,8 @@ class RenderPathPaint { } static use_live_layer = (use: bool) => { - let tid = Context.raw.layer.id; - let hid = History.undo_i - 1 < 0 ? Config.raw.undo_steps - 1 : History.undo_i - 1; + let tid: i32 = Context.raw.layer.id; + let hid: i32 = History.undo_i - 1 < 0 ? Config.raw.undo_steps - 1 : History.undo_i - 1; if (use) { RenderPathPaint._texpaint = render_path_render_targets.get("texpaint" + tid); RenderPathPaint._texpaint_undo = render_path_render_targets.get("texpaint_undo" + hid); @@ -393,11 +393,11 @@ class RenderPathPaint { render_path_render_targets.set("texpaint_pack" + tid, RenderPathPaint._texpaint_pack); } } - RenderPathPaint.liveLayerLocked = use; + RenderPathPaint.live_layer_locked = use; } static commands_live_brush = () => { - let tool = Context.raw.tool; + let tool: workspace_tool_t = Context.raw.tool; if (tool != workspace_tool_t.BRUSH && tool != workspace_tool_t.ERASER && tool != workspace_tool_t.CLONE && @@ -408,13 +408,13 @@ class RenderPathPaint { return; } - if (RenderPathPaint.liveLayerLocked) return; + if (RenderPathPaint.live_layer_locked) return; - if (RenderPathPaint.liveLayer == null) { - RenderPathPaint.liveLayer = SlotLayer.create("_live"); + if (RenderPathPaint.live_layer == null) { + RenderPathPaint.live_layer = SlotLayer.create("_live"); } - let tid = Context.raw.layer.id; + let tid: i32 = Context.raw.layer.id; if (SlotLayer.is_mask(Context.raw.layer)) { render_path_set_target("texpaint_live"); render_path_bind_target("texpaint" + tid, "tex"); @@ -430,18 +430,18 @@ class RenderPathPaint { RenderPathPaint.use_live_layer(true); - RenderPathPaint.liveLayerDrawn = 2; + RenderPathPaint.live_layer_drawn = 2; UIView2D.hwnd.redraws = 2; - let _x = Context.raw.paint_vec.x; - let _y = Context.raw.paint_vec.y; + let _x: f32 = Context.raw.paint_vec.x; + let _y: f32 = Context.raw.paint_vec.y; if (Context.raw.brush_locked) { Context.raw.paint_vec.x = (Context.raw.lock_started_x - app_x()) / app_w(); Context.raw.paint_vec.y = (Context.raw.lock_started_y - app_y()) / app_h(); } - let _lastX = Context.raw.last_paint_vec_x; - let _lastY = Context.raw.last_paint_vec_y; - let _pdirty = Context.raw.pdirty; + let _last_x: f32 = Context.raw.last_paint_vec_x; + let _last_y: f32 = Context.raw.last_paint_vec_y; + let _pdirty: i32 = Context.raw.pdirty; Context.raw.last_paint_vec_x = Context.raw.paint_vec.x; Context.raw.last_paint_vec_y = Context.raw.paint_vec.y; if (Operator.shortcut(Config.keymap.brush_ruler)) { @@ -457,67 +457,67 @@ class RenderPathPaint { Context.raw.paint_vec.x = _x; Context.raw.paint_vec.y = _y; - Context.raw.last_paint_vec_x = _lastX; - Context.raw.last_paint_vec_y = _lastY; + Context.raw.last_paint_vec_x = _last_x; + Context.raw.last_paint_vec_y = _last_y; Context.raw.pdirty = _pdirty; Context.raw.brush_blend_dirty = true; } static commands_cursor = () => { if (!Config.raw.brush_3d) return; - let decal = Context.raw.tool == workspace_tool_t.DECAL || Context.raw.tool == workspace_tool_t.TEXT; - let decalMask = decal && Operator.shortcut(Config.keymap.decal_mask, ShortcutType.ShortcutDown); - let tool = Context.raw.tool; + let decal: bool = Context.raw.tool == workspace_tool_t.DECAL || Context.raw.tool == workspace_tool_t.TEXT; + let decal_mask: bool = decal && Operator.shortcut(Config.keymap.decal_mask, ShortcutType.ShortcutDown); + let tool: workspace_tool_t = Context.raw.tool; if (tool != workspace_tool_t.BRUSH && tool != workspace_tool_t.ERASER && tool != workspace_tool_t.CLONE && tool != workspace_tool_t.BLUR && tool != workspace_tool_t.SMUDGE && tool != workspace_tool_t.PARTICLE && - !decalMask) { + !decal_mask) { return; } - let fillLayer = Context.raw.layer.fill_layer != null; - let groupLayer = SlotLayer.is_group(Context.raw.layer); - if (!Base.ui_enabled || Base.is_dragging || fillLayer || groupLayer) { + let fill_layer: bool = Context.raw.layer.fill_layer != null; + let group_layer: bool = SlotLayer.is_group(Context.raw.layer); + if (!base_ui_enabled || base_is_dragging || fill_layer || group_layer) { return; } - let mx = Context.raw.paint_vec.x; - let my = 1.0 - Context.raw.paint_vec.y; + let mx: f32 = Context.raw.paint_vec.x; + let my: f32 = 1.0 - Context.raw.paint_vec.y; if (Context.raw.brush_locked) { mx = (Context.raw.lock_started_x - app_x()) / app_w(); my = 1.0 - (Context.raw.lock_started_y - app_y()) / app_h(); } - let radius = decalMask ? Context.raw.brush_decal_mask_radius : Context.raw.brush_radius; + let radius: f32 = decal_mask ? Context.raw.brush_decal_mask_radius : Context.raw.brush_radius; RenderPathPaint.draw_cursor(mx, my, Context.raw.brush_nodes_radius * radius / 3.4); } static draw_cursor = (mx: f32, my: f32, radius: f32, tintR = 1.0, tintG = 1.0, tintB = 1.0) => { let plane: mesh_object_t = scene_get_child(".Plane").ext; - let geom = plane.data; + let geom: mesh_data_t = plane.data; - if (Base.pipe_cursor == null) Base.make_cursor_pipe(); + if (base_pipe_cursor == null) base_make_cursor_pipe(); render_path_set_target(""); - g4_set_pipeline(Base.pipe_cursor); - let decal = Context.raw.tool == workspace_tool_t.DECAL || Context.raw.tool == workspace_tool_t.TEXT; - let decalMask = decal && Operator.shortcut(Config.keymap.decal_mask, ShortcutType.ShortcutDown); - let img = (decal && !decalMask) ? Context.raw.decal_image : Res.get("cursor.k"); - g4_set_tex(Base.cursor_tex, img); - let gbuffer0 = render_path_render_targets.get("gbuffer0")._image; - g4_set_tex_depth(Base.cursor_gbufferd, gbuffer0); - g4_set_float2(Base.cursor_mouse, mx, my); - g4_set_float2(Base.cursor_tex_step, 1 / gbuffer0.width, 1 / gbuffer0.height); - g4_set_float(Base.cursor_radius, radius); - let right = vec4_normalize(camera_object_right_world(scene_camera)); - g4_set_float3(Base.cursor_camera_right, right.x, right.y, right.z); - g4_set_float3(Base.cursor_tint, tintR, tintG, tintB); - g4_set_mat(Base.cursor_vp, scene_camera.vp); - let helpMat = mat4_identity(); - mat4_get_inv(helpMat, scene_camera.vp); - g4_set_mat(Base.cursor_inv_vp, helpMat); + g4_set_pipeline(base_pipe_cursor); + let decal: bool = Context.raw.tool == workspace_tool_t.DECAL || Context.raw.tool == workspace_tool_t.TEXT; + let decal_mask: bool = decal && Operator.shortcut(Config.keymap.decal_mask, ShortcutType.ShortcutDown); + let img: image_t = (decal && !decal_mask) ? Context.raw.decal_image : Res.get("cursor.k"); + g4_set_tex(base_cursor_tex, img); + let gbuffer0: image_t = render_path_render_targets.get("gbuffer0")._image; + g4_set_tex_depth(base_cursor_gbufferd, gbuffer0); + g4_set_float2(base_cursor_mouse, mx, my); + g4_set_float2(base_cursor_tex_step, 1 / gbuffer0.width, 1 / gbuffer0.height); + g4_set_float(base_cursor_radius, radius); + let right: vec4_t = vec4_normalize(camera_object_right_world(scene_camera)); + g4_set_float3(base_cursor_camera_right, right.x, right.y, right.z); + g4_set_float3(base_cursor_tint, tintR, tintG, tintB); + g4_set_mat(base_cursor_vp, scene_camera.vp); + let help_mat: mat4_t = mat4_identity(); + mat4_get_inv(help_mat, scene_camera.vp); + g4_set_mat(base_cursor_inv_vp, help_mat); ///if (krom_metal || krom_vulkan) g4_set_vertex_buffer(mesh_data_get(geom, [{name: "tex", data: "short2norm"}])); ///else @@ -533,10 +533,10 @@ class RenderPathPaint { static commands_symmetry = () => { if (Context.raw.sym_x || Context.raw.sym_y || Context.raw.sym_z) { Context.raw.ddirty = 2; - let t = Context.raw.paint_object.base.transform; - let sx = t.scale.x; - let sy = t.scale.y; - let sz = t.scale.z; + let t: transform_t = Context.raw.paint_object.base.transform; + let sx: f32 = t.scale.x; + let sy: f32 = t.scale.y; + let sz: f32 = t.scale.z; if (Context.raw.sym_x) { vec4_set(t.scale, -sx, sy, sz); transform_build_matrix(t); @@ -579,24 +579,24 @@ class RenderPathPaint { static paint_enabled = (): bool => { ///if is_paint - let fillLayer = Context.raw.layer.fill_layer != null && Context.raw.tool != workspace_tool_t.PICKER && Context.raw.tool != workspace_tool_t.MATERIAL && Context.raw.tool != workspace_tool_t.COLORID; + let fill_layer: bool = Context.raw.layer.fill_layer != null && Context.raw.tool != workspace_tool_t.PICKER && Context.raw.tool != workspace_tool_t.MATERIAL && Context.raw.tool != workspace_tool_t.COLORID; ///end ///if is_sculpt - let fillLayer = Context.raw.layer.fill_layer != null && Context.raw.tool != workspace_tool_t.PICKER && Context.raw.tool != workspace_tool_t.MATERIAL; + let fill_layer: bool = Context.raw.layer.fill_layer != null && Context.raw.tool != workspace_tool_t.PICKER && Context.raw.tool != workspace_tool_t.MATERIAL; ///end - let groupLayer = SlotLayer.is_group(Context.raw.layer); - return !fillLayer && !groupLayer && !Context.raw.foreground_event; + let group_layer: bool = SlotLayer.is_group(Context.raw.layer); + return !fill_layer && !group_layer && !Context.raw.foreground_event; } static live_brush_dirty = () => { - let mx = RenderPathPaint.lastX; - let my = RenderPathPaint.lastY; - RenderPathPaint.lastX = mouse_view_x(); - RenderPathPaint.lastY = mouse_view_y(); + let mx: f32 = RenderPathPaint.last_x; + let my: f32 = RenderPathPaint.last_y; + RenderPathPaint.last_x = mouse_view_x(); + RenderPathPaint.last_y = mouse_view_y(); if (Config.raw.brush_live && Context.raw.pdirty <= 0) { - let moved = (mx != RenderPathPaint.lastX || my != RenderPathPaint.lastY) && (Context.in_viewport() || Context.in_2d_view()); + let moved: bool = (mx != RenderPathPaint.last_x || my != RenderPathPaint.last_y) && (Context.in_viewport() || Context.in_2d_view()); if (moved || Context.raw.brush_locked) { Context.raw.rdirty = 2; } @@ -615,7 +615,7 @@ class RenderPathPaint { if (!RenderPathPaint.paint_enabled()) return; ///if is_paint - RenderPathPaint.pushUndoLast = History.push_undo; + RenderPathPaint.push_undo_last = History.push_undo; ///end if (History.push_undo && History.undo_layers != null) { @@ -642,7 +642,7 @@ class RenderPathPaint { RenderPathPaint.set_plane_mesh(); } - if (RenderPathPaint.liveLayerDrawn > 0) RenderPathPaint.liveLayerDrawn--; + if (RenderPathPaint.live_layer_drawn > 0) RenderPathPaint.live_layer_drawn--; if (Config.raw.brush_live && Context.raw.pdirty <= 0 && Context.raw.ddirty <= 0 && Context.raw.brush_time == 0) { // Depth is unchanged, draw before gbuffer gets updated @@ -678,7 +678,7 @@ class RenderPathPaint { if (Context.raw.tool == workspace_tool_t.BAKE) { ///if (krom_direct3d12 || krom_vulkan || krom_metal) - let isRaytracedBake = (Context.raw.bake_type == bake_type_t.AO || + let is_raytraced_bake: bool = (Context.raw.bake_type == bake_type_t.AO || Context.raw.bake_type == bake_type_t.LIGHTMAP || Context.raw.bake_type == bake_type_t.BENT_NORMAL || Context.raw.bake_type == bake_type_t.THICKNESS); @@ -687,60 +687,60 @@ class RenderPathPaint { if (Context.raw.bake_type == bake_type_t.NORMAL || Context.raw.bake_type == bake_type_t.HEIGHT || Context.raw.bake_type == bake_type_t.DERIVATIVE) { if (!RenderPathPaint.baking && Context.raw.pdirty > 0) { RenderPathPaint.baking = true; - let _bakeType = Context.raw.bake_type; + let _bake_type: bake_type_t = Context.raw.bake_type; Context.raw.bake_type = Context.raw.bake_type == bake_type_t.NORMAL ? bake_type_t.NORMAL_OBJECT : bake_type_t.POSITION; // Bake high poly data MakeMaterial.parse_paint_material(); - let _paintObject = Context.raw.paint_object; - let highPoly = Project.paint_objects[Context.raw.bake_high_poly]; - let _visible = highPoly.base.visible; - highPoly.base.visible = true; - Context.select_paint_object(highPoly); + let _paint_object: mesh_object_t = Context.raw.paint_object; + let high_poly: mesh_object_t = Project.paint_objects[Context.raw.bake_high_poly]; + let _visible: bool = high_poly.base.visible; + high_poly.base.visible = true; + Context.select_paint_object(high_poly); RenderPathPaint.commands_paint(); - highPoly.base.visible = _visible; - if (RenderPathPaint.pushUndoLast) History.paint(); - Context.select_paint_object(_paintObject); + high_poly.base.visible = _visible; + if (RenderPathPaint.push_undo_last) History.paint(); + Context.select_paint_object(_paint_object); - let _renderFinal = () => { - Context.raw.bake_type = _bakeType; + let _render_final = () => { + Context.raw.bake_type = _bake_type; MakeMaterial.parse_paint_material(); Context.raw.pdirty = 1; RenderPathPaint.commands_paint(); Context.raw.pdirty = 0; RenderPathPaint.baking = false; } - let _renderDeriv = () => { + let _render_deriv = () => { Context.raw.bake_type = bake_type_t.HEIGHT; MakeMaterial.parse_paint_material(); Context.raw.pdirty = 1; RenderPathPaint.commands_paint(); Context.raw.pdirty = 0; - if (RenderPathPaint.pushUndoLast) History.paint(); - app_notify_on_init(_renderFinal); + if (RenderPathPaint.push_undo_last) History.paint(); + app_notify_on_init(_render_final); } - let bakeType = Context.raw.bake_type as bake_type_t; - app_notify_on_init(bakeType == bake_type_t.DERIVATIVE ? _renderDeriv : _renderFinal); + let bake_type: bake_type_t = Context.raw.bake_type as bake_type_t; + app_notify_on_init(bake_type == bake_type_t.DERIVATIVE ? _render_deriv : _render_final); } } else if (Context.raw.bake_type == bake_type_t.OBJECTID) { - let _layerFilter = Context.raw.layer_filter; - let _paintObject = Context.raw.paint_object; - let isMerged = Context.raw.merged_object != null; - let _visible = isMerged && Context.raw.merged_object.base.visible; + let _layer_filter: i32 = Context.raw.layer_filter; + let _paint_object: mesh_object_t = Context.raw.paint_object; + let is_merged: bool = Context.raw.merged_object != null; + let _visible: bool = is_merged && Context.raw.merged_object.base.visible; Context.raw.layer_filter = 1; - if (isMerged) Context.raw.merged_object.base.visible = false; + if (is_merged) Context.raw.merged_object.base.visible = false; for (let p of Project.paint_objects) { Context.select_paint_object(p); RenderPathPaint.commands_paint(); } - Context.raw.layer_filter = _layerFilter; - Context.select_paint_object(_paintObject); - if (isMerged) Context.raw.merged_object.base.visible = _visible; + Context.raw.layer_filter = _layer_filter; + Context.select_paint_object(_paint_object); + if (is_merged) Context.raw.merged_object.base.visible = _visible; } ///if (krom_direct3d12 || krom_vulkan || krom_metal) - else if (isRaytracedBake) { - let dirty = RenderPathRaytraceBake.commands(MakeMaterial.parse_paint_material); + else if (is_raytraced_bake) { + let dirty: bool = RenderPathRaytraceBake.commands(MakeMaterial.parse_paint_material); if (dirty) UIHeader.header_handle.redraws = 2; if (Config.raw.dilate == dilate_type_t.INSTANT) { // && Context.raw.pdirty == 1 RenderPathPaint.dilate(true, false); @@ -788,38 +788,38 @@ class RenderPathPaint { p.base.visible = false; } if (Context.raw.merged_object != null) { - RenderPathPaint.mergedObjectVisible = Context.raw.merged_object.base.visible; + RenderPathPaint.merged_object_visible = Context.raw.merged_object.base.visible; Context.raw.merged_object.base.visible = false; } - let cam = scene_camera; + let cam: camera_object_t = scene_camera; mat4_set_from(Context.raw.saved_camera, cam.base.transform.local); - RenderPathPaint.savedFov = cam.data.fov; + RenderPathPaint.saved_fov = cam.data.fov; Viewport.update_camera_type(camera_type_t.PERSPECTIVE); - let m = mat4_identity(); + let m: mat4_t = mat4_identity(); mat4_translate(m, 0, 0, 0.5); transform_set_matrix(cam.base.transform, m); - cam.data.fov = Base.default_fov; + cam.data.fov = base_default_fov; camera_object_build_proj(cam); camera_object_build_mat(cam); - let tw = 0.95 * UIView2D.pan_scale; - let tx = UIView2D.pan_x / UIView2D.ww; - let ty = UIView2D.pan_y / app_h(); + let tw: f32 = 0.95 * UIView2D.pan_scale; + let tx: f32 = UIView2D.pan_x / UIView2D.ww; + let ty: f32 = UIView2D.pan_y / app_h(); mat4_set_identity(m); mat4_scale(m, vec4_create(tw, tw, 1)); mat4_set_loc(m, vec4_create(tx, ty, 0)); - let m2 = mat4_identity(); + let m2: mat4_t = mat4_identity(); mat4_get_inv(m2, scene_camera.vp); mat4_mult_mat(m, m2); - let tiled = UIView2D.tiled_show; + let tiled: bool = UIView2D.tiled_show; if (tiled && scene_get_child(".PlaneTiled") == null) { // 3x3 planes - let posa = [32767,0,-32767,0,10922,0,-10922,0,10922,0,-32767,0,10922,0,-10922,0,-10922,0,10922,0,-10922,0,-10922,0,-10922,0,10922,0,-32767,0,32767,0,-32767,0,10922,0,10922,0,10922,0,-10922,0,32767,0,-10922,0,10922,0,32767,0,10922,0,10922,0,32767,0,10922,0,10922,0,-10922,0,-10922,0,-32767,0,10922,0,-32767,0,-10922,0,32767,0,-10922,0,10922,0,10922,0,10922,0,-10922,0,-10922,0,-32767,0,-32767,0,-10922,0,-32767,0,-32767,0,10922,0,-32767,0,-10922,0,-10922,0,-10922,0,-32767,0,32767,0,-32767,0,32767,0,-10922,0,10922,0,-10922,0,10922,0,-10922,0,10922,0,10922,0,-10922,0,10922,0,-10922,0,10922,0,-10922,0,32767,0,-32767,0,32767,0,10922,0,10922,0,10922,0,32767,0,-10922,0,32767,0,32767,0,10922,0,32767,0,32767,0,10922,0,32767,0,-10922,0,-10922,0,-10922,0,10922,0,-32767,0,10922,0,32767,0,-10922,0,32767,0,10922,0,10922,0,10922,0,-10922,0,-32767,0,-10922,0,-10922,0,-32767,0,-10922,0,10922,0,-32767,0,10922,0,-10922,0,-10922,0,-10922,0]; - let nora = [0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767]; - let texa = [32767,32767,0,0,0,32767,32767,32767,0,0,0,32767,32767,32767,0,0,0,32767,32767,32767,0,0,0,32767,32767,32767,0,0,0,32767,32767,32767,0,0,0,32767,32767,32767,0,0,0,32767,32767,32767,0,0,0,32767,32767,32767,0,0,0,32767,32767,32767,32767,0,0,0,32767,32767,32767,0,0,0,32767,32767,32767,0,0,0,32767,32767,32767,0,0,0,32767,32767,32767,0,0,0,32767,32767,32767,0,0,0,32767,32767,32767,0,0,0,32767,32767,32767,0,0,0,32767,32767,32767,0,0,0]; - let inda = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53]; + let posa: i32[] = [32767,0,-32767,0,10922,0,-10922,0,10922,0,-32767,0,10922,0,-10922,0,-10922,0,10922,0,-10922,0,-10922,0,-10922,0,10922,0,-32767,0,32767,0,-32767,0,10922,0,10922,0,10922,0,-10922,0,32767,0,-10922,0,10922,0,32767,0,10922,0,10922,0,32767,0,10922,0,10922,0,-10922,0,-10922,0,-32767,0,10922,0,-32767,0,-10922,0,32767,0,-10922,0,10922,0,10922,0,10922,0,-10922,0,-10922,0,-32767,0,-32767,0,-10922,0,-32767,0,-32767,0,10922,0,-32767,0,-10922,0,-10922,0,-10922,0,-32767,0,32767,0,-32767,0,32767,0,-10922,0,10922,0,-10922,0,10922,0,-10922,0,10922,0,10922,0,-10922,0,10922,0,-10922,0,10922,0,-10922,0,32767,0,-32767,0,32767,0,10922,0,10922,0,10922,0,32767,0,-10922,0,32767,0,32767,0,10922,0,32767,0,32767,0,10922,0,32767,0,-10922,0,-10922,0,-10922,0,10922,0,-32767,0,10922,0,32767,0,-10922,0,32767,0,10922,0,10922,0,10922,0,-10922,0,-32767,0,-10922,0,-10922,0,-32767,0,-10922,0,10922,0,-32767,0,10922,0,-10922,0,-10922,0,-10922,0]; + let nora: i32[] = [0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767,0,-32767]; + let texa: i32[] = [32767,32767,0,0,0,32767,32767,32767,0,0,0,32767,32767,32767,0,0,0,32767,32767,32767,0,0,0,32767,32767,32767,0,0,0,32767,32767,32767,0,0,0,32767,32767,32767,0,0,0,32767,32767,32767,0,0,0,32767,32767,32767,0,0,0,32767,32767,32767,32767,0,0,0,32767,32767,32767,0,0,0,32767,32767,32767,0,0,0,32767,32767,32767,0,0,0,32767,32767,32767,0,0,0,32767,32767,32767,0,0,0,32767,32767,32767,0,0,0,32767,32767,32767,0,0,0,32767,32767,32767,0,0,0]; + let inda: i32[] = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53]; let raw: mesh_data_t = { name: ".PlaneTiled", vertex_arrays: [ @@ -835,7 +835,7 @@ class RenderPathPaint { }; let md: mesh_data_t = mesh_data_create(raw); let materials: material_data_t[] = scene_get_child(".Plane").ext.materials; - let o = scene_add_mesh_object(md, materials); + let o: mesh_object_t = scene_add_mesh_object(md, materials); o.base.name = ".PlaneTiled"; } @@ -843,8 +843,8 @@ class RenderPathPaint { RenderPathPaint.planeo.base.visible = true; Context.raw.paint_object = RenderPathPaint.planeo; - let v = vec4_create(); - let sx = vec4_len(vec4_set(v, m.m[0], m.m[1], m.m[2])); + let v: vec4_t = vec4_create(); + let sx: f32 = vec4_len(vec4_set(v, m.m[0], m.m[1], m.m[2])); quat_from_euler(RenderPathPaint.planeo.base.transform.rot, -Math.PI / 2, 0, 0); vec4_set(RenderPathPaint.planeo.base.transform.scale, sx, 1.0, sx); RenderPathPaint.planeo.base.transform.scale.z *= Config.get_texture_res_y() / Config.get_texture_res_x(); @@ -856,15 +856,15 @@ class RenderPathPaint { Context.raw.paint2d_view = false; RenderPathPaint.planeo.base.visible = false; vec4_set(RenderPathPaint.planeo.base.transform.loc, 0.0, 0.0, 0.0); - for (let i = 0; i < Project.paint_objects.length; ++i) { + for (let i: i32 = 0; i < Project.paint_objects.length; ++i) { Project.paint_objects[i].base.visible = RenderPathPaint.visibles[i]; } if (Context.raw.merged_object != null) { - Context.raw.merged_object.base.visible = RenderPathPaint.mergedObjectVisible; + Context.raw.merged_object.base.visible = RenderPathPaint.merged_object_visible; } Context.raw.paint_object = RenderPathPaint.painto; transform_set_matrix(scene_camera.base.transform, Context.raw.saved_camera); - scene_camera.data.fov = RenderPathPaint.savedFov; + scene_camera.data.fov = RenderPathPaint.saved_fov; Viewport.update_camera_type(Context.raw.camera_type); camera_object_build_proj(scene_camera); camera_object_build_mat(scene_camera); @@ -874,13 +874,13 @@ class RenderPathPaint { static bind_layers = () => { ///if is_paint - let isLive = Config.raw.brush_live && RenderPathPaint.liveLayerDrawn > 0; - let isMaterialTool = Context.raw.tool == workspace_tool_t.MATERIAL; - if (isLive || isMaterialTool) RenderPathPaint.use_live_layer(true); + let is_live: bool = Config.raw.brush_live && RenderPathPaint.live_layer_drawn > 0; + let is_material_tool: bool = Context.raw.tool == workspace_tool_t.MATERIAL; + if (is_live || is_material_tool) RenderPathPaint.use_live_layer(true); ///end - for (let i = 0; i < Project.layers.length; ++i) { - let l = Project.layers[i]; + for (let i: i32 = 0; i < Project.layers.length; ++i) { + let l: SlotLayerRaw = Project.layers[i]; render_path_bind_target("texpaint" + l.id, "texpaint" + l.id); ///if is_paint @@ -894,9 +894,9 @@ class RenderPathPaint { static unbind_layers = () => { ///if is_paint - let isLive = Config.raw.brush_live && RenderPathPaint.liveLayerDrawn > 0; - let isMaterialTool = Context.raw.tool == workspace_tool_t.MATERIAL; - if (isLive || isMaterialTool) RenderPathPaint.use_live_layer(false); + let is_live: bool = Config.raw.brush_live && RenderPathPaint.live_layer_drawn > 0; + let is_material_tool: bool = Context.raw.tool == workspace_tool_t.MATERIAL; + if (is_live || is_material_tool) RenderPathPaint.use_live_layer(false); ///end } @@ -904,10 +904,10 @@ class RenderPathPaint { ///if is_paint if (Config.raw.dilate_radius > 0 && !Context.raw.paint2d) { UtilUV.cache_dilate_map(); - Base.make_temp_img(); - let tid = Context.raw.layer.id; + base_make_temp_img(); + let tid: i32 = Context.raw.layer.id; if (base) { - let texpaint = "texpaint"; + let texpaint: string = "texpaint"; render_path_set_target("temptex0"); render_path_bind_target(texpaint + tid, "tex"); render_path_draw_shader("shader_datas/copy_pass/copy_pass"); diff --git a/armorpaint/Sources/RenderPathPreview.ts b/armorpaint/Sources/RenderPathPreview.ts index b3a6d378..a1194be9 100644 --- a/armorpaint/Sources/RenderPathPreview.ts +++ b/armorpaint/Sources/RenderPathPreview.ts @@ -4,7 +4,7 @@ class RenderPathPreview { static init = () => { { - let t = render_target_create(); + let t: render_target_t = render_target_create(); t.name = "texpreview"; t.width = 1; t.height = 1; @@ -12,7 +12,7 @@ class RenderPathPreview { render_path_create_render_target(t); } { - let t = render_target_create(); + let t: render_target_t = render_target_create(); t.name = "texpreview_icon"; t.width = 1; t.height = 1; @@ -23,7 +23,7 @@ class RenderPathPreview { render_path_create_depth_buffer("mmain", "DEPTH24"); { - let t = render_target_create(); + let t: render_target_t = render_target_create(); t.name = "mtex"; t.width = Math.floor(UtilRender.material_preview_size * 2.0); t.height = Math.floor(UtilRender.material_preview_size * 2.0); @@ -36,7 +36,7 @@ class RenderPathPreview { } { - let t = render_target_create(); + let t: render_target_t = render_target_create(); t.name = "mgbuffer0"; t.width = Math.floor(UtilRender.material_preview_size * 2.0); t.height = Math.floor(UtilRender.material_preview_size * 2.0); @@ -47,7 +47,7 @@ class RenderPathPreview { } { - let t = render_target_create(); + let t: render_target_t = render_target_create(); t.name = "mgbuffer1"; t.width = Math.floor(UtilRender.material_preview_size * 2.0); t.height = Math.floor(UtilRender.material_preview_size * 2.0); @@ -57,7 +57,7 @@ class RenderPathPreview { } { - let t = render_target_create(); + let t: render_target_t = render_target_create(); t.name = "mgbuffer2"; t.width = Math.floor(UtilRender.material_preview_size * 2.0); t.height = Math.floor(UtilRender.material_preview_size * 2.0); @@ -97,10 +97,10 @@ class RenderPathPreview { render_path_set_depth_from("mtex", "mgbuffer1"); // Unbind depth ///end - let framebuffer = "texpreview"; - let selectedMat = Context.raw.material; - render_path_render_targets.get("texpreview")._image = selectedMat.image; - render_path_render_targets.get("texpreview_icon")._image = selectedMat.image_icon; + let framebuffer: string = "texpreview"; + let selected_mat: SlotMaterialRaw = Context.raw.material; + render_path_render_targets.get("texpreview")._image = selected_mat.image; + render_path_render_targets.get("texpreview_icon")._image = selected_mat.image_icon; render_path_set_target(framebuffer); render_path_bind_target("mtex", "tex"); @@ -141,7 +141,7 @@ class RenderPathPreview { render_path_set_depth_from("tex", "gbuffer1"); // Unbind depth ///end - let framebuffer = "texpreview"; + let framebuffer: string = "texpreview"; render_path_render_targets.get("texpreview")._image = Context.raw.decal_image; render_path_set_target(framebuffer); diff --git a/armorpaint/Sources/SlotBrush.ts b/armorpaint/Sources/SlotBrush.ts index e965c609..5a15db72 100644 --- a/armorpaint/Sources/SlotBrush.ts +++ b/armorpaint/Sources/SlotBrush.ts @@ -1,18 +1,18 @@ class SlotBrushRaw { - nodes = zui_nodes_create(); + nodes: zui_nodes_t = zui_nodes_create(); canvas: zui_node_canvas_t; image: image_t = null; // 200px image_icon: image_t = null; // 50px - preview_ready = false; - id = 0; + preview_ready: bool = false; + id: i32 = 0; } class SlotBrush { static default_canvas: ArrayBuffer = null; static create(c: zui_node_canvas_t = null): SlotBrushRaw { - let raw = new SlotBrushRaw(); + let raw: SlotBrushRaw = new SlotBrushRaw(); for (let brush of Project.brushes) if (brush.id >= raw.id) raw.id = brush.id + 1; if (c == null) { diff --git a/armorpaint/Sources/SlotFont.ts b/armorpaint/Sources/SlotFont.ts index f47ada70..0b401381 100644 --- a/armorpaint/Sources/SlotFont.ts +++ b/armorpaint/Sources/SlotFont.ts @@ -1,8 +1,8 @@ class SlotFontRaw { image: image_t = null; // 200px - preview_ready = false; - id = 0; + preview_ready: bool = false; + id: i32 = 0; font: g2_font_t; name: string; file: string; @@ -11,7 +11,7 @@ class SlotFontRaw { class SlotFont { static create(name: string, font: g2_font_t, file = ""): SlotFontRaw { - let raw = new SlotFontRaw(); + let raw: SlotFontRaw = new SlotFontRaw(); for (let slot of Project.fonts) if (slot.id >= raw.id) raw.id = slot.id + 1; raw.name = name; raw.font = font; diff --git a/armorpaint/Sources/SlotLayer.ts b/armorpaint/Sources/SlotLayer.ts index 903b2af3..ded9efa3 100644 --- a/armorpaint/Sources/SlotLayer.ts +++ b/armorpaint/Sources/SlotLayer.ts @@ -1,9 +1,9 @@ class SlotLayerRaw { - id = 0; + id: i32 = 0; name: string; - ext = ""; - visible = true; + ext: string = ""; + visible: bool = true; parent: SlotLayerRaw = null; // Group (for layers) or layer (for masks) texpaint: image_t = null; // Base or mask @@ -13,32 +13,32 @@ class SlotLayerRaw { texpaint_preview: image_t = null; // Layer preview ///end - maskOpacity = 1.0; // Opacity mask + mask_opacity: f32 = 1.0; // Opacity mask fill_layer: SlotMaterialRaw = null; - show_panel = true; + show_panel: bool = true; blending = blend_type_t.MIX; - objectMask = 0; - scale = 1.0; - angle = 0.0; - uvType = uv_type_t.UVMAP; - paintBase = true; - paintOpac = true; - paintOcc = true; - paintRough = true; - paintMet = true; - paintNor = true; - paintNorBlend = true; - paintHeight = true; - paintHeightBlend = true; - paintEmis = true; - paintSubs = true; - decalMat = mat4_identity(); // Decal layer + object_mask: i32 = 0; + scale: f32 = 1.0; + angle: f32 = 0.0; + uv_type = uv_type_t.UVMAP; + paint_base: bool = true; + paint_opac: bool = true; + paint_occ: bool = true; + paint_rough: bool = true; + paint_met: bool = true; + paint_nor: bool = true; + paint_nor_blend: bool = true; + paint_height: bool = true; + paint_height_blend: bool = true; + paint_emis: bool = true; + paint_subs: bool = true; + decal_mat: mat4_t = mat4_identity(); // Decal layer } class SlotLayer { static create(ext = "", type = layer_slot_type_t.LAYER, parent: SlotLayerRaw = null): SlotLayerRaw { - let raw = new SlotLayerRaw(); + let raw: SlotLayerRaw = new SlotLayerRaw(); if (ext == "") { raw.id = 0; for (let l of Project.layers) if (l.id >= raw.id) raw.id = l.id + 1; @@ -53,17 +53,17 @@ class SlotLayer { else if (type == layer_slot_type_t.LAYER) { raw.name = "Layer " + (raw.id + 1); ///if is_paint - let format = Base.bits_handle.position == texture_bits_t.BITS8 ? "RGBA32" : - Base.bits_handle.position == texture_bits_t.BITS16 ? "RGBA64" : - "RGBA128"; + let format: string = base_bits_handle.position == texture_bits_t.BITS8 ? "RGBA32" : + base_bits_handle.position == texture_bits_t.BITS16 ? "RGBA64" : + "RGBA128"; ///end ///if is_sculpt - let format = "RGBA128"; + let format: string = "RGBA128"; ///end { - let t = render_target_create(); + let t: render_target_t = render_target_create(); t.name = "texpaint" + ext; t.width = Config.get_texture_res_x(); t.height = Config.get_texture_res_y(); @@ -73,7 +73,7 @@ class SlotLayer { ///if is_paint { - let t = render_target_create(); + let t: render_target_t = render_target_create(); t.name = "texpaint_nor" + ext; t.width = Config.get_texture_res_x(); t.height = Config.get_texture_res_y(); @@ -81,7 +81,7 @@ class SlotLayer { raw.texpaint_nor = render_path_create_render_target(t)._image; } { - let t = render_target_create(); + let t: render_target_t = render_target_create(); t.name = "texpaint_pack" + ext; t.width = Config.get_texture_res_x(); t.height = Config.get_texture_res_y(); @@ -96,11 +96,11 @@ class SlotLayer { ///if is_paint else { // Mask raw.name = "Mask " + (raw.id + 1); - let format = "RGBA32"; // Full bits for undo support, R8 is used + let format: string = "RGBA32"; // Full bits for undo support, R8 is used raw.blending = blend_type_t.ADD; { - let t = render_target_create(); + let t: render_target_t = render_target_create(); t.name = "texpaint" + ext; t.width = Config.get_texture_res_x(); t.height = Config.get_texture_res_y(); @@ -119,17 +119,17 @@ class SlotLayer { SlotLayer.unload(raw); if (SlotLayer.is_layer(raw)) { - let masks = SlotLayer.get_masks(raw, false); // Prevents deleting group masks + let masks: SlotLayerRaw[] = SlotLayer.get_masks(raw, false); // Prevents deleting group masks if (masks != null) for (let m of masks) SlotLayer.delete(m); } else if (SlotLayer.is_group(raw)) { - let children = SlotLayer.get_children(raw); + let children: SlotLayerRaw[] = SlotLayer.get_children(raw); if (children != null) for (let c of children) SlotLayer.delete(c); - let masks = SlotLayer.get_masks(raw); + let masks: SlotLayerRaw[] = SlotLayer.get_masks(raw); if (masks != null) for (let m of masks) SlotLayer.delete(m); } - let lpos = Project.layers.indexOf(raw); + let lpos: i32 = Project.layers.indexOf(raw); array_remove(Project.layers, raw); // Undo can remove base layer and then restore it from undo layers if (Project.layers.length > 0) { @@ -142,11 +142,11 @@ class SlotLayer { static unload = (raw: SlotLayerRaw) => { if (SlotLayer.is_group(raw)) return; - let _texpaint = raw.texpaint; + let _texpaint: image_t = raw.texpaint; ///if is_paint - let _texpaint_nor = raw.texpaint_nor; - let _texpaint_pack = raw.texpaint_pack; - let _texpaint_preview = raw.texpaint_preview; + let _texpaint_nor: image_t = raw.texpaint_nor; + let _texpaint_pack: image_t = raw.texpaint_pack; + let _texpaint_preview: image_t = raw.texpaint_preview; ///end let _next = () => { @@ -157,7 +157,7 @@ class SlotLayer { image_unload(_texpaint_preview); ///end } - Base.notify_on_next_frame(_next); + base_notify_on_next_frame(_next); render_path_render_targets.delete("texpaint" + raw.ext); ///if is_paint @@ -172,12 +172,12 @@ class SlotLayer { if ((SlotLayer.is_layer(raw) || SlotLayer.is_mask(raw)) && (SlotLayer.is_layer(other) || SlotLayer.is_mask(other))) { render_path_render_targets.get("texpaint" + raw.ext)._image = other.texpaint; render_path_render_targets.get("texpaint" + other.ext)._image = raw.texpaint; - let _texpaint = raw.texpaint; + let _texpaint: image_t = raw.texpaint; raw.texpaint = other.texpaint; other.texpaint = _texpaint; ///if is_paint - let _texpaint_preview = raw.texpaint_preview; + let _texpaint_preview: image_t = raw.texpaint_preview; raw.texpaint_preview = other.texpaint_preview; other.texpaint_preview = _texpaint_preview; ///end @@ -189,8 +189,8 @@ class SlotLayer { render_path_render_targets.get("texpaint_pack" + raw.ext)._image = other.texpaint_pack; render_path_render_targets.get("texpaint_nor" + other.ext)._image = raw.texpaint_nor; render_path_render_targets.get("texpaint_pack" + other.ext)._image = raw.texpaint_pack; - let _texpaint_nor = raw.texpaint_nor; - let _texpaint_pack = raw.texpaint_pack; + let _texpaint_nor: image_t = raw.texpaint_nor; + let _texpaint_pack: image_t = raw.texpaint_pack; raw.texpaint_nor = other.texpaint_nor; raw.texpaint_pack = other.texpaint_pack; other.texpaint_nor = _texpaint_nor; @@ -199,7 +199,7 @@ class SlotLayer { ///end } - static clear = (raw: SlotLayerRaw, baseColor = 0x00000000, baseImage: image_t = null, occlusion = 1.0, roughness = Base.default_rough, metallic = 0.0) => { + static clear = (raw: SlotLayerRaw, baseColor = 0x00000000, baseImage: image_t = null, occlusion = 1.0, roughness = base_default_rough, metallic = 0.0) => { g4_begin(raw.texpaint); g4_clear(baseColor); // Base g4_end(); @@ -225,18 +225,18 @@ class SlotLayer { } static invert_mask = (raw: SlotLayerRaw) => { - if (Base.pipe_invert8 == null) Base.make_pipe(); - let inverted = image_create_render_target(raw.texpaint.width, raw.texpaint.height, tex_format_t.RGBA32); + if (base_pipe_invert8 == null) base_make_pipe(); + let inverted: image_t = image_create_render_target(raw.texpaint.width, raw.texpaint.height, tex_format_t.RGBA32); g2_begin(inverted); - g2_set_pipeline(Base.pipe_invert8); + g2_set_pipeline(base_pipe_invert8); g2_draw_image(raw.texpaint, 0, 0); g2_set_pipeline(null); g2_end(); - let _texpaint = raw.texpaint; + let _texpaint: image_t = raw.texpaint; let _next = () => { image_unload(_texpaint); } - Base.notify_on_next_frame(_next); + base_notify_on_next_frame(_next); raw.texpaint = render_path_render_targets.get("texpaint" + raw.id)._image = inverted; Context.raw.layer_preview_dirty = true; Context.raw.ddirty = 3; @@ -248,36 +248,36 @@ class SlotLayer { } if (SlotLayer.is_group(raw.parent)) { for (let c of SlotLayer.get_children(raw.parent)) { - Base.apply_mask(c, raw); + base_apply_mask(c, raw); } } else { - Base.apply_mask(raw.parent, raw); + base_apply_mask(raw.parent, raw); } SlotLayer.delete(raw); } static duplicate = (raw: SlotLayerRaw): SlotLayerRaw => { - let layers = Project.layers; - let i = layers.indexOf(raw) + 1; - let l = SlotLayer.create("", SlotLayer.is_layer(raw) ? layer_slot_type_t.LAYER : SlotLayer.is_mask(raw) ? layer_slot_type_t.MASK : layer_slot_type_t.GROUP, raw.parent); + let layers: SlotLayerRaw[] = Project.layers; + let i: i32 = layers.indexOf(raw) + 1; + let l: SlotLayerRaw = SlotLayer.create("", SlotLayer.is_layer(raw) ? layer_slot_type_t.LAYER : SlotLayer.is_mask(raw) ? layer_slot_type_t.MASK : layer_slot_type_t.GROUP, raw.parent); layers.splice(i, 0, l); - if (Base.pipe_merge == null) Base.make_pipe(); + if (base_pipe_merge == null) base_make_pipe(); if (SlotLayer.is_layer(raw)) { g2_begin(l.texpaint); - g2_set_pipeline(Base.pipe_copy); + g2_set_pipeline(base_pipe_copy); g2_draw_image(raw.texpaint, 0, 0); g2_set_pipeline(null); g2_end(); ///if is_paint g2_begin(l.texpaint_nor); - g2_set_pipeline(Base.pipe_copy); + g2_set_pipeline(base_pipe_copy); g2_draw_image(raw.texpaint_nor, 0, 0); g2_set_pipeline(null); g2_end(); g2_begin(l.texpaint_pack); - g2_set_pipeline(Base.pipe_copy); + g2_set_pipeline(base_pipe_copy); g2_draw_image(raw.texpaint_pack, 0, 0); g2_set_pipeline(null); g2_end(); @@ -285,7 +285,7 @@ class SlotLayer { } else if (SlotLayer.is_mask(raw)) { g2_begin(l.texpaint); - g2_set_pipeline(Base.pipe_copy8); + g2_set_pipeline(base_pipe_copy8); g2_draw_image(raw.texpaint, 0, 0); g2_set_pipeline(null); g2_end(); @@ -294,75 +294,75 @@ class SlotLayer { ///if is_paint g2_begin(l.texpaint_preview); g2_clear(0x00000000); - g2_set_pipeline(Base.pipe_copy); + g2_set_pipeline(base_pipe_copy); g2_draw_scaled_image(raw.texpaint_preview, 0, 0, raw.texpaint_preview.width, raw.texpaint_preview.height); g2_set_pipeline(null); g2_end(); ///end l.visible = raw.visible; - l.maskOpacity = raw.maskOpacity; + l.mask_opacity = raw.mask_opacity; l.fill_layer = raw.fill_layer; - l.objectMask = raw.objectMask; + l.object_mask = raw.object_mask; l.blending = raw.blending; - l.uvType = raw.uvType; + l.uv_type = raw.uv_type; l.scale = raw.scale; l.angle = raw.angle; - l.paintBase = raw.paintBase; - l.paintOpac = raw.paintOpac; - l.paintOcc = raw.paintOcc; - l.paintRough = raw.paintRough; - l.paintMet = raw.paintMet; - l.paintNor = raw.paintNor; - l.paintNorBlend = raw.paintNorBlend; - l.paintHeight = raw.paintHeight; - l.paintHeightBlend = raw.paintHeightBlend; - l.paintEmis = raw.paintEmis; - l.paintSubs = raw.paintSubs; + l.paint_base = raw.paint_base; + l.paint_opac = raw.paint_opac; + l.paint_occ = raw.paint_occ; + l.paint_rough = raw.paint_rough; + l.paint_met = raw.paint_met; + l.paint_nor = raw.paint_nor; + l.paint_nor_blend = raw.paint_nor_blend; + l.paint_height = raw.paint_height; + l.paint_height_blend = raw.paint_height_blend; + l.paint_emis = raw.paint_emis; + l.paint_subs = raw.paint_subs; return l; } static resize_and_set_bits = (raw: SlotLayerRaw) => { - let resX = Config.get_texture_res_x(); - let resY = Config.get_texture_res_y(); - let rts = render_path_render_targets; - if (Base.pipe_merge == null) Base.make_pipe(); + let res_x: i32 = Config.get_texture_res_x(); + let res_y: i32 = Config.get_texture_res_y(); + let rts: map_t = render_path_render_targets; + if (base_pipe_merge == null) base_make_pipe(); if (SlotLayer.is_layer(raw)) { ///if is_paint - let format = Base.bits_handle.position == texture_bits_t.BITS8 ? tex_format_t.RGBA32 : - Base.bits_handle.position == texture_bits_t.BITS16 ? tex_format_t.RGBA64 : - tex_format_t.RGBA128; + let format: tex_format_t = base_bits_handle.position == texture_bits_t.BITS8 ? tex_format_t.RGBA32 : + base_bits_handle.position == texture_bits_t.BITS16 ? tex_format_t.RGBA64 : + tex_format_t.RGBA128; ///end ///if is_sculpt - let format = tex_format_t.RGBA128; + let format: tex_format_t = tex_format_t.RGBA128; ///end - let _texpaint = raw.texpaint; - raw.texpaint = image_create_render_target(resX, resY, format); + let _texpaint: image_t = raw.texpaint; + raw.texpaint = image_create_render_target(res_x, res_y, format); g2_begin(raw.texpaint); - g2_set_pipeline(Base.pipe_copy); - g2_draw_scaled_image(_texpaint, 0, 0, resX, resY); + g2_set_pipeline(base_pipe_copy); + g2_draw_scaled_image(_texpaint, 0, 0, res_x, res_y); g2_set_pipeline(null); g2_end(); ///if is_paint - let _texpaint_nor = raw.texpaint_nor; - let _texpaint_pack = raw.texpaint_pack; - raw.texpaint_nor = image_create_render_target(resX, resY, format); - raw.texpaint_pack = image_create_render_target(resX, resY, format); + let _texpaint_nor: image_t = raw.texpaint_nor; + let _texpaint_pack: image_t = raw.texpaint_pack; + raw.texpaint_nor = image_create_render_target(res_x, res_y, format); + raw.texpaint_pack = image_create_render_target(res_x, res_y, format); g2_begin(raw.texpaint_nor); - g2_set_pipeline(Base.pipe_copy); - g2_draw_scaled_image(_texpaint_nor, 0, 0, resX, resY); + g2_set_pipeline(base_pipe_copy); + g2_draw_scaled_image(_texpaint_nor, 0, 0, res_x, res_y); g2_set_pipeline(null); g2_end(); g2_begin(raw.texpaint_pack); - g2_set_pipeline(Base.pipe_copy); - g2_draw_scaled_image(_texpaint_pack, 0, 0, resX, resY); + g2_set_pipeline(base_pipe_copy); + g2_draw_scaled_image(_texpaint_pack, 0, 0, res_x, res_y); g2_set_pipeline(null); g2_end(); ///end @@ -374,7 +374,7 @@ class SlotLayer { image_unload(_texpaint_pack); ///end } - Base.notify_on_next_frame(_next); + base_notify_on_next_frame(_next); rts.get("texpaint" + raw.ext)._image = raw.texpaint; ///if is_paint @@ -383,19 +383,19 @@ class SlotLayer { ///end } else if (SlotLayer.is_mask(raw)) { - let _texpaint = raw.texpaint; - raw.texpaint = image_create_render_target(resX, resY, tex_format_t.RGBA32); + let _texpaint: image_t = raw.texpaint; + raw.texpaint = image_create_render_target(res_x, res_y, tex_format_t.RGBA32); g2_begin(raw.texpaint); - g2_set_pipeline(Base.pipe_copy8); - g2_draw_scaled_image(_texpaint, 0, 0, resX, resY); + g2_set_pipeline(base_pipe_copy8); + g2_draw_scaled_image(_texpaint, 0, 0, res_x, res_y); g2_set_pipeline(null); g2_end(); let _next = () => { image_unload(_texpaint); } - Base.notify_on_next_frame(_next); + base_notify_on_next_frame(_next); rts.get("texpaint" + raw.ext)._image = raw.texpaint; } @@ -404,13 +404,13 @@ class SlotLayer { static to_fill_layer = (raw: SlotLayerRaw) => { Context.set_layer(raw); raw.fill_layer = Context.raw.material; - Base.update_fill_layer(); + base_update_fill_layer(); let _next = () => { MakeMaterial.parse_paint_material(); Context.raw.layer_preview_dirty = true; UIBase.hwnds[tab_area_t.SIDEBAR0].redraws = 2; } - Base.notify_on_next_frame(_next); + base_notify_on_next_frame(_next); } static to_paint_layer = (raw: SlotLayerRaw) => { @@ -495,13 +495,13 @@ class SlotLayer { } static get_opacity = (raw: SlotLayerRaw): f32 => { - let f = raw.maskOpacity; - if (SlotLayer.is_layer(raw) && raw.parent != null) f *= raw.parent.maskOpacity; + let f: f32 = raw.mask_opacity; + if (SlotLayer.is_layer(raw) && raw.parent != null) f *= raw.parent.mask_opacity; return f; } static get_object_mask = (raw: SlotLayerRaw): i32 => { - return SlotLayer.is_mask(raw) ? raw.parent.objectMask : raw.objectMask; + return SlotLayer.is_mask(raw) ? raw.parent.object_mask : raw.object_mask; } static is_layer = (raw: SlotLayerRaw): bool => { @@ -557,54 +557,54 @@ class SlotLayer { } static can_move = (raw: SlotLayerRaw, to: i32): bool => { - let oldIndex = Project.layers.indexOf(raw); + let old_index: i32 = Project.layers.indexOf(raw); - let delta = to - oldIndex; // If delta > 0 the layer is moved up, otherwise down + let delta: i32 = to - old_index; // If delta > 0 the layer is moved up, otherwise down if (to < 0 || to > Project.layers.length - 1 || delta == 0) return false; // If the layer is moved up, all layers between the old position and the new one move one down. // The layers above the new position stay where they are. // If the new position is on top or on bottom no upper resp. lower layer exists. - let newUpperLayer = delta > 0 ? (to < Project.layers.length - 1 ? Project.layers[to + 1] : null) : Project.layers[to]; + let new_upper_layer: SlotLayerRaw = delta > 0 ? (to < Project.layers.length - 1 ? Project.layers[to + 1] : null) : Project.layers[to]; // Group or layer is collapsed so we check below and update the upper layer. - if (newUpperLayer != null && !newUpperLayer.show_panel) { - let children = SlotLayer.get_recursive_children(newUpperLayer); + if (new_upper_layer != null && !new_upper_layer.show_panel) { + let children: SlotLayerRaw[] = SlotLayer.get_recursive_children(new_upper_layer); to -= children != null ? children.length : 0; - delta = to - oldIndex; - newUpperLayer = delta > 0 ? (to < Project.layers.length - 1 ? Project.layers[to + 1] : null) : Project.layers[to]; + delta = to - old_index; + new_upper_layer = delta > 0 ? (to < Project.layers.length - 1 ? Project.layers[to + 1] : null) : Project.layers[to]; } - let newLowerLayer = delta > 0 ? Project.layers[to] : (to > 0 ? Project.layers[to - 1] : null); + let new_lower_layer: SlotLayerRaw = delta > 0 ? Project.layers[to] : (to > 0 ? Project.layers[to - 1] : null); if (SlotLayer.is_mask(raw)) { // Masks can not be on top. - if (newUpperLayer == null) return false; + if (new_upper_layer == null) return false; // Masks should not be placed below a collapsed group. This condition can be savely removed. - if (SlotLayer.is_in_group(newUpperLayer) && !SlotLayer.get_containing_group(newUpperLayer).show_panel) return false; + if (SlotLayer.is_in_group(new_upper_layer) && !SlotLayer.get_containing_group(new_upper_layer).show_panel) return false; // Masks should not be placed below a collapsed layer. This condition can be savely removed. - if (SlotLayer.is_mask(newUpperLayer) && !newUpperLayer.parent.show_panel) return false; + if (SlotLayer.is_mask(new_upper_layer) && !new_upper_layer.parent.show_panel) return false; } if (SlotLayer.is_layer(raw)) { // Layers can not be moved directly below its own mask(s). - if (newUpperLayer != null && SlotLayer.is_mask(newUpperLayer) && newUpperLayer.parent == raw) return false; + if (new_upper_layer != null && SlotLayer.is_mask(new_upper_layer) && new_upper_layer.parent == raw) return false; // Layers can not be placed above a mask as the mask would be reparented. - if (newLowerLayer != null && SlotLayer.is_mask(newLowerLayer)) return false; + if (new_lower_layer != null && SlotLayer.is_mask(new_lower_layer)) return false; } // Currently groups can not be nested. Thus valid positions for groups are: if (SlotLayer.is_group(raw)) { // At the top. - if (newUpperLayer == null) return true; + if (new_upper_layer == null) return true; // NOT below its own children. - if (SlotLayer.get_containing_group(newUpperLayer) == raw) return false; + if (SlotLayer.get_containing_group(new_upper_layer) == raw) return false; // At the bottom. - if (newLowerLayer == null) return true; + if (new_lower_layer == null) return true; // Above a group. - if (SlotLayer.is_group(newLowerLayer)) return true; + if (SlotLayer.is_group(new_lower_layer)) return true; // Above a non-grouped layer. - if (SlotLayer.is_layer(newLowerLayer) && !SlotLayer.is_in_group(newLowerLayer)) return true; + if (SlotLayer.is_layer(new_lower_layer) && !SlotLayer.is_in_group(new_lower_layer)) return true; else return false; } @@ -616,17 +616,17 @@ class SlotLayer { return; } - let pointers = TabLayers.init_layer_map(); - let oldIndex = Project.layers.indexOf(raw); - let delta = to - oldIndex; - let newUpperLayer = delta > 0 ? (to < Project.layers.length - 1 ? Project.layers[to + 1] : null) : Project.layers[to]; + let pointers: map_t = TabLayers.init_layer_map(); + let old_index: i32 = Project.layers.indexOf(raw); + let delta: i32 = to - old_index; + let new_upper_layer: SlotLayerRaw = delta > 0 ? (to < Project.layers.length - 1 ? Project.layers[to + 1] : null) : Project.layers[to]; // Group or layer is collapsed so we check below and update the upper layer. - if (newUpperLayer != null && !newUpperLayer.show_panel) { - let children = SlotLayer.get_recursive_children(newUpperLayer); + if (new_upper_layer != null && !new_upper_layer.show_panel) { + let children: SlotLayerRaw[] = SlotLayer.get_recursive_children(new_upper_layer); to -= children != null ? children.length : 0; - delta = to - oldIndex; - newUpperLayer = delta > 0 ? (to < Project.layers.length - 1 ? Project.layers[to + 1] : null) : Project.layers[to]; + delta = to - old_index; + new_upper_layer = delta > 0 ? (to < Project.layers.length - 1 ? Project.layers[to + 1] : null) : Project.layers[to]; } Context.set_layer(raw); @@ -637,52 +637,52 @@ class SlotLayer { Project.layers.splice(to, 0, raw); if (SlotLayer.is_layer(raw)) { - let oldParent = raw.parent; + let old_parent: SlotLayerRaw = raw.parent; - if (newUpperLayer == null) + if (new_upper_layer == null) raw.parent = null; // Placed on top. - else if (SlotLayer.is_in_group(newUpperLayer) && !SlotLayer.get_containing_group(newUpperLayer).show_panel) + else if (SlotLayer.is_in_group(new_upper_layer) && !SlotLayer.get_containing_group(new_upper_layer).show_panel) raw.parent = null; // Placed below a collapsed group. - else if (SlotLayer.is_layer(newUpperLayer)) - raw.parent = newUpperLayer.parent; // Placed below a layer, use the same parent. - else if (SlotLayer.is_group(newUpperLayer)) - raw.parent = newUpperLayer; // Placed as top layer in a group. - else if (SlotLayer.is_group_mask(newUpperLayer)) - raw.parent = newUpperLayer.parent; // Placed in a group below the lowest group mask. - else if (SlotLayer.is_layer_mask(newUpperLayer)) - raw.parent = SlotLayer.get_containing_group(newUpperLayer); // Either the group the mask belongs to or null. + else if (SlotLayer.is_layer(new_upper_layer)) + raw.parent = new_upper_layer.parent; // Placed below a layer, use the same parent. + else if (SlotLayer.is_group(new_upper_layer)) + raw.parent = new_upper_layer; // Placed as top layer in a group. + else if (SlotLayer.is_group_mask(new_upper_layer)) + raw.parent = new_upper_layer.parent; // Placed in a group below the lowest group mask. + else if (SlotLayer.is_layer_mask(new_upper_layer)) + raw.parent = SlotLayer.get_containing_group(new_upper_layer); // Either the group the mask belongs to or null. // Layers can have masks as children. These have to be moved, too. - let layerMasks = SlotLayer.get_masks(raw, false); - if (layerMasks != null) { - for (let idx = 0; idx < layerMasks.length; ++idx) { - let mask = layerMasks[idx]; + let layer_masks: SlotLayerRaw[] = SlotLayer.get_masks(raw, false); + if (layer_masks != null) { + for (let idx: i32 = 0; idx < layer_masks.length; ++idx) { + let mask: SlotLayerRaw = layer_masks[idx]; array_remove(Project.layers, mask); // If the masks are moved down each step increases the index below the layer by one. - Project.layers.splice(delta > 0 ? oldIndex + delta - 1 : oldIndex + delta + idx, 0, mask); + Project.layers.splice(delta > 0 ? old_index + delta - 1 : old_index + delta + idx, 0, mask); } } // The layer is the last layer in the group, remove it. Notice that this might remove group masks. - if (oldParent != null && SlotLayer.get_children(oldParent) == null) - SlotLayer.delete(oldParent); + if (old_parent != null && SlotLayer.get_children(old_parent) == null) + SlotLayer.delete(old_parent); } else if (SlotLayer.is_mask(raw)) { // Precondition newUpperLayer != null, ensured in canMove. - if (SlotLayer.is_layer(newUpperLayer) || SlotLayer.is_group(newUpperLayer)) - raw.parent = newUpperLayer; - else if (SlotLayer.is_mask(newUpperLayer)) { // Group mask or layer mask. - raw.parent = newUpperLayer.parent; + if (SlotLayer.is_layer(new_upper_layer) || SlotLayer.is_group(new_upper_layer)) + raw.parent = new_upper_layer; + else if (SlotLayer.is_mask(new_upper_layer)) { // Group mask or layer mask. + raw.parent = new_upper_layer.parent; } } else if (SlotLayer.is_group(raw)) { - let children = SlotLayer.get_recursive_children(raw); + let children: SlotLayerRaw[] = SlotLayer.get_recursive_children(raw); if (children != null) { - for (let idx = 0; idx < children.length; ++idx) { - let child = children[idx]; + for (let idx: i32 = 0; idx < children.length; ++idx) { + let child: SlotLayerRaw = children[idx]; array_remove(Project.layers, child); // If the children are moved down each step increases the index below the layer by one. - Project.layers.splice(delta > 0 ? oldIndex + delta - 1 : oldIndex + delta + idx, 0, child); + Project.layers.splice(delta > 0 ? old_index + delta - 1 : old_index + delta + idx, 0, child); } } } diff --git a/armorpaint/Sources/SlotMaterial.ts b/armorpaint/Sources/SlotMaterial.ts index 32646f6b..8592c497 100644 --- a/armorpaint/Sources/SlotMaterial.ts +++ b/armorpaint/Sources/SlotMaterial.ts @@ -1,36 +1,36 @@ class SlotMaterialRaw { - nodes = zui_nodes_create(); + nodes: zui_nodes_t = zui_nodes_create(); canvas: zui_node_canvas_t; image: image_t = null; image_icon: image_t = null; - preview_ready = false; + preview_ready: bool = false; data: material_data_t; - id = 0; + id: i32 = 0; - paint_base = true; - paint_opac = true; - paint_occ = true; - paint_rough = true; - paint_met = true; - paint_nor = true; - paint_height = true; - paint_emis = true; - paint_subs = true; + paint_base: bool = true; + paint_opac: bool = true; + paint_occ: bool = true; + paint_rough: bool = true; + paint_met: bool = true; + paint_nor: bool = true; + paint_height: bool = true; + paint_emis: bool = true; + paint_subs: bool = true; } class SlotMaterial { static default_canvas: ArrayBuffer = null; static create(m: material_data_t = null, c: zui_node_canvas_t = null): SlotMaterialRaw { - let raw = new SlotMaterialRaw(); + let raw: SlotMaterialRaw = new SlotMaterialRaw(); for (let mat of Project.materials) if (mat.id >= raw.id) raw.id = mat.id + 1; raw.data = m; - let w = UtilRender.material_preview_size; - let wIcon = 50; + let w: i32 = UtilRender.material_preview_size; + let w_icon: i32 = 50; raw.image = image_create_render_target(w, w); - raw.image_icon = image_create_render_target(wIcon, wIcon); + raw.image_icon = image_create_render_target(w_icon, w_icon); if (c == null) { if (SlotMaterial.default_canvas == null) { // Synchronous @@ -56,12 +56,12 @@ class SlotMaterial { image_unload(raw.image); image_unload(raw.image_icon); } - Base.notify_on_next_frame(_next); + base_notify_on_next_frame(_next); } static delete = (raw: SlotMaterialRaw) => { SlotMaterial.unload(raw); - let mpos = Project.materials.indexOf(raw); + let mpos: i32 = Project.materials.indexOf(raw); array_remove(Project.materials, this); if (Project.materials.length > 0) { Context.set_material(Project.materials[mpos > 0 ? mpos - 1 : 0]); diff --git a/armorpaint/Sources/TabLayers.ts b/armorpaint/Sources/TabLayers.ts index bc0e2f5a..03bcd1c1 100644 --- a/armorpaint/Sources/TabLayers.ts +++ b/armorpaint/Sources/TabLayers.ts @@ -1,20 +1,20 @@ class TabLayers { - static layer_name_edit = -1; - static layer_name_handle = zui_handle_create(); - static show_context_menu = false; + static layer_name_edit: i32 = -1; + static layer_name_handle: zui_handle_t = zui_handle_create(); + static show_context_menu: bool = false; static draw = (htab: zui_handle_t) => { - let mini = Config.raw.layout[layout_size_t.SIDEBAR_W] <= UIBase.sidebar_mini_w; + let mini: bool = Config.raw.layout[layout_size_t.SIDEBAR_W] <= UIBase.sidebar_mini_w; mini ? TabLayers.draw_mini(htab) : TabLayers.draw_full(htab); } static draw_mini = (htab: zui_handle_t) => { - let ui = UIBase.ui; + let ui: zui_t = UIBase.ui; zui_set_hovered_tab_name(tr("Layers")); - let _ELEMENT_H = ui.t.ELEMENT_H; + let _ELEMENT_H: i32 = ui.t.ELEMENT_H; ui.t.ELEMENT_H = Math.floor(UIBase.sidebar_mini_w / 2 / zui_SCALE(ui)); zui_begin_sticky(); @@ -34,7 +34,7 @@ class TabLayers { } static draw_full = (htab: zui_handle_t) => { - let ui = UIBase.ui; + let ui: zui_t = UIBase.ui; if (zui_tab(htab, tr("Layers"))) { zui_begin_sticky(); zui_row([1 / 4, 1 / 4, 1 / 2]); @@ -52,7 +52,7 @@ class TabLayers { } static button_2d_view = () => { - let ui = UIBase.ui; + let ui: zui_t = UIBase.ui; if (zui_button(tr("2D View"))) { UIBase.show_2d_view(view_2d_type_t.LAYER); } @@ -60,19 +60,19 @@ class TabLayers { } static draw_slots = (mini: bool) => { - for (let i = 0; i < Project.layers.length; ++i) { + for (let i: i32 = 0; i < Project.layers.length; ++i) { if (i >= Project.layers.length) break; // Layer was deleted - let j = Project.layers.length - 1 - i; - let l = Project.layers[j]; + let j: i32 = Project.layers.length - 1 - i; + let l: SlotLayerRaw = Project.layers[j]; TabLayers.draw_layer_slot(l, j, mini); } } static highlight_odd_lines = () => { - let ui = UIBase.ui; - let step = ui.t.ELEMENT_H * 2; - let fullH = ui._window_h - UIBase.hwnds[0].scroll_offset; - for (let i = 0; i < Math.floor(fullH / step); ++i) { + let ui: zui_t = UIBase.ui; + let step: i32 = ui.t.ELEMENT_H * 2; + let full_h: i32 = ui._window_h - UIBase.hwnds[0].scroll_offset; + for (let i: i32 = 0; i < Math.floor(full_h / step); ++i) { if (i % 2 == 0) { zui_fill(0, i * step, (ui._w / zui_SCALE(ui) - 2), step, ui.t.WINDOW_BG_COL - 0x00040404); } @@ -80,58 +80,57 @@ class TabLayers { } static button_new = (text: string) => { - let ui = UIBase.ui; if (zui_button(text)) { UIMenu.draw((ui: zui_t) => { - let l = Context.raw.layer; + let l: SlotLayerRaw = Context.raw.layer; if (UIMenu.menu_button(ui, tr("Paint Layer"))) { - Base.new_layer(); + base_new_layer(); History.new_layer(); } if (UIMenu.menu_button(ui, tr("Fill Layer"))) { - Base.create_fill_layer(uv_type_t.UVMAP); + base_create_fill_layer(uv_type_t.UVMAP); } if (UIMenu.menu_button(ui, tr("Decal Layer"))) { - Base.create_fill_layer(uv_type_t.PROJECT); + base_create_fill_layer(uv_type_t.PROJECT); } if (UIMenu.menu_button(ui, tr("Black Mask"))) { if (SlotLayer.is_mask(l)) Context.set_layer(l.parent); - // let l = Context.raw.layer; + // let l: SlotLayerRaw = Context.raw.layer; - let m = Base.new_mask(false, l); + let m: SlotLayerRaw = base_new_mask(false, l); let _next = () => { SlotLayer.clear(m, 0x00000000); } - Base.notify_on_next_frame(_next); + base_notify_on_next_frame(_next); Context.raw.layer_preview_dirty = true; History.new_black_mask(); - Base.update_fill_layers(); + base_update_fill_layers(); } if (UIMenu.menu_button(ui, tr("White Mask"))) { if (SlotLayer.is_mask(l)) Context.set_layer(l.parent); - // let l = Context.raw.layer; + // let l: SlotLayerRaw = Context.raw.layer; - let m = Base.new_mask(false, l); + let m: SlotLayerRaw = base_new_mask(false, l); let _next = () => { SlotLayer.clear(m, 0xffffffff); } - Base.notify_on_next_frame(_next); + base_notify_on_next_frame(_next); Context.raw.layer_preview_dirty = true; History.new_white_mask(); - Base.update_fill_layers(); + base_update_fill_layers(); } if (UIMenu.menu_button(ui, tr("Fill Mask"))) { if (SlotLayer.is_mask(l)) Context.set_layer(l.parent); - // let l = Context.raw.layer; + // let l: SlotLayerRaw = Context.raw.layer; - let m = Base.new_mask(false, l); + let m: SlotLayerRaw = base_new_mask(false, l); let _init = () => { SlotLayer.to_fill_layer(m); } app_notify_on_init(_init); Context.raw.layer_preview_dirty = true; History.new_fill_mask(); - Base.update_fill_layers(); + base_update_fill_layers(); } ui.enabled = !SlotLayer.is_group(Context.raw.layer) && !SlotLayer.is_in_group(Context.raw.layer); if (UIMenu.menu_button(ui, tr("Group"))) { @@ -139,8 +138,8 @@ class TabLayers { if (SlotLayer.is_layer_mask(l)) l = l.parent; - let pointers = TabLayers.init_layer_map(); - let group = Base.new_group(); + let pointers: map_t = TabLayers.init_layer_map(); + let group = base_new_group(); Context.set_layer(l); array_remove(Project.layers, group); Project.layers.splice(Project.layers.indexOf(l) + 1, 0, group); @@ -155,15 +154,14 @@ class TabLayers { } static combo_filter = () => { - let ui = UIBase.ui; - let ar = [tr("All")]; + let ar: string[] = [tr("All")]; for (let p of Project.paint_objects) ar.push(p.base.name); - let atlases = Project.get_used_atlases(); + let atlases: string[] = Project.get_used_atlases(); if (atlases != null) for (let a of atlases) ar.push(a); - let filterHandle = zui_handle("tablayers_0"); - filterHandle.position = Context.raw.layer_filter; - Context.raw.layer_filter = zui_combo(filterHandle, ar, tr("Filter"), false, zui_align_t.LEFT); - if (filterHandle.changed) { + let filter_handle: zui_handle_t = zui_handle("tablayers_0"); + filter_handle.position = Context.raw.layer_filter; + Context.raw.layer_filter = zui_combo(filter_handle, ar, tr("Filter"), false, zui_align_t.LEFT); + if (filter_handle.changed) { for (let p of Project.paint_objects) { p.base.visible = Context.raw.layer_filter == 0 || p.base.name == ar[Context.raw.layer_filter] || Project.is_atlas_object(p); } @@ -175,7 +173,7 @@ class TabLayers { for (let p of Project.paint_objects) if (p.base.visible) visibles.push(p); UtilMesh.merge_mesh(visibles); } - Base.set_object_mask(); + base_set_object_mask(); UtilUV.uvmap_cached = false; Context.raw.ddirty = 2; ///if (krom_direct3d12 || krom_vulkan || krom_metal) @@ -187,7 +185,7 @@ class TabLayers { static remap_layer_pointers = (nodes: zui_node_t[], pointerMap: Map) => { for (let n of nodes) { if (n.type == "LAYER" || n.type == "LAYER_MASK") { - let i = n.buttons[0].default_value; + let i: any = n.buttons[0].default_value; if (pointerMap.has(i)) { n.buttons[0].default_value = pointerMap.get(i); } @@ -197,7 +195,7 @@ class TabLayers { static init_layer_map = (): Map => { let res: Map = new Map(); - for (let i = 0; i < Project.layers.length; ++i) res.set(Project.layers[i], i); + for (let i: i32 = 0; i < Project.layers.length; ++i) res.set(Project.layers[i], i); return res; } @@ -208,14 +206,14 @@ class TabLayers { } static set_drag_layer = (layer: SlotLayerRaw, offX: f32, offY: f32) => { - Base.drag_off_x = offX; - Base.drag_off_y = offY; - Base.drag_layer = layer; + base_drag_off_x = offX; + base_drag_off_y = offY; + base_drag_layer = layer; Context.raw.drag_dest = Project.layers.indexOf(layer); } static draw_layer_slot = (l: SlotLayerRaw, i: i32, mini: bool) => { - let ui = UIBase.ui; + let ui: zui_t = UIBase.ui; if (Context.raw.layer_filter > 0 && SlotLayer.get_object_mask(l) > 0 && @@ -230,21 +228,21 @@ class TabLayers { return; } - let step = ui.t.ELEMENT_H; - let checkw = (ui._window_w / 100 * 8) / zui_SCALE(ui); + let step: i32 = ui.t.ELEMENT_H; + let checkw: f32 = (ui._window_w / 100 * 8) / zui_SCALE(ui); // Highlight drag destination - let absy = ui._window_y + ui._y; - if (Base.is_dragging && Base.drag_layer != null && Context.in_layers()) { + let absy: f32 = ui._window_y + ui._y; + if (base_is_dragging && base_drag_layer != null && Context.in_layers()) { if (mouse_y > absy + step && mouse_y < absy + step * 3) { - let down = Project.layers.indexOf(Base.drag_layer) >= i; + let down: bool = Project.layers.indexOf(base_drag_layer) >= i; Context.raw.drag_dest = down ? i : i - 1; - let ls = Project.layers; - let dest = Context.raw.drag_dest; - let toGroup = down ? dest > 0 && ls[dest - 1].parent != null && ls[dest - 1].parent.show_panel : dest < ls.length && ls[dest].parent != null && ls[dest].parent.show_panel; - let nestedGroup = SlotLayer.is_group(Base.drag_layer) && toGroup; - if (!nestedGroup) { + let ls: SlotLayerRaw[] = Project.layers; + let dest: i32 = Context.raw.drag_dest; + let to_group: bool = down ? dest > 0 && ls[dest - 1].parent != null && ls[dest - 1].parent.show_panel : dest < ls.length && ls[dest].parent != null && ls[dest].parent.show_panel; + let nested_group: bool = SlotLayer.is_group(base_drag_layer) && to_group; + if (!nested_group) { if (SlotLayer.can_move(Context.raw.layer, Context.raw.drag_dest)) { zui_fill(checkw, step * 2, (ui._window_w / zui_SCALE(ui) - 2) - checkw, 2 * zui_SCALE(ui), ui.t.HIGHLIGHT_COL); } @@ -257,7 +255,7 @@ class TabLayers { } } } - if (Base.is_dragging && (Base.drag_material != null || Base.drag_swatch != null) && Context.in_layers()) { + if (base_is_dragging && (base_drag_material != null || base_drag_swatch != null) && Context.in_layers()) { if (mouse_y > absy + step && mouse_y < absy + step * 3) { Context.raw.drag_dest = i; if (TabLayers.can_drop_new_layer(i)) @@ -283,9 +281,9 @@ class TabLayers { let ui = UIBase.ui; zui_row([1, 1]); - let uix = ui._x; - let uiy = ui._y; - let state = TabLayers.draw_layer_icon(l, i, uix, uiy, true); + let uix: f32 = ui._x; + let uiy: f32 = ui._y; + let state: zui_state_t = TabLayers.draw_layer_icon(l, i, uix, uiy, true); TabLayers.handle_layer_icon_state(l, i, state, uix, uiy); zui_end_element(); @@ -294,12 +292,12 @@ class TabLayers { } static draw_layer_slot_full = (l: SlotLayerRaw, i: i32) => { - let ui = UIBase.ui; + let ui: zui_t = UIBase.ui; - let step = ui.t.ELEMENT_H; + let step: i32 = ui.t.ELEMENT_H; - let hasPanel = SlotLayer.is_group(l) || (SlotLayer.is_layer(l) && SlotLayer.get_masks(l, false) != null); - if (hasPanel) { + let has_panel: bool = SlotLayer.is_group(l) || (SlotLayer.is_layer(l) && SlotLayer.get_masks(l, false) != null); + if (has_panel) { zui_row([8 / 100, 16 / 100, 36 / 100, 30 / 100, 10 / 100]); } else { @@ -307,15 +305,15 @@ class TabLayers { } // Draw eye icon - let icons = Res.get("icons.k"); - let r = Res.tile18(icons, l.visible ? 0 : 1, 0); - let center = (step / 2) * zui_SCALE(ui); + let icons: image_t = Res.get("icons.k"); + let r: rect_t = Res.tile18(icons, l.visible ? 0 : 1, 0); + let center: f32 = (step / 2) * zui_SCALE(ui); ui._x += 2; ui._y += 3; ui._y += center; - let col = ui.t.ACCENT_SELECT_COL; - let parentHidden = l.parent != null && (!l.parent.visible || (l.parent.parent != null && !l.parent.parent.visible)); - if (parentHidden) col -= 0x99000000; + let col: i32 = ui.t.ACCENT_SELECT_COL; + let parent_hidden: bool = l.parent != null && (!l.parent.visible || (l.parent.parent != null && !l.parent.parent.visible)); + if (parent_hidden) col -= 0x99000000; if (zui_image(icons, col, -1.0, r.x, r.y, r.w, r.h) == zui_state_t.RELEASED) { TabLayers.layer_toggle_visible(l); @@ -328,8 +326,8 @@ class TabLayers { ui.image_invert_y = l.fill_layer != null; ///end - let uix = ui._x; - let uiy = ui._y; + let uix: f32 = ui._x; + let uiy: f32 = ui._y; ui._x += 2; ui._y += 3; if (l.parent != null) { @@ -337,7 +335,7 @@ class TabLayers { if (l.parent.parent != null) ui._x += 10 * zui_SCALE(ui); } - let state = TabLayers.draw_layer_icon(l, i, uix, uiy, false); + let state: zui_state_t = TabLayers.draw_layer_icon(l, i, uix, uiy, false); ui._x -= 2; ui._y -= 3; @@ -373,7 +371,7 @@ class TabLayers { } } - let state = zui_text(l.name); + let state: zui_state_t = zui_text(l.name); if (state == zui_state_t.RELEASED) { if (time_time() - Context.raw.select_time < 0.25) { TabLayers.layer_name_edit = l.id; @@ -383,9 +381,9 @@ class TabLayers { Context.raw.select_time = time_time(); } - let inFocus = ui.input_x > ui._window_x && ui.input_x < ui._window_x + ui._window_w && - ui.input_y > ui._window_y && ui.input_y < ui._window_y + ui._window_h; - if (inFocus && ui.is_delete_down && TabLayers.can_delete(Context.raw.layer)) { + let in_focus: bool = ui.input_x > ui._window_x && ui.input_x < ui._window_x + ui._window_w && + ui.input_y > ui._window_y && ui.input_y < ui._window_y + ui._window_h; + if (in_focus && ui.is_delete_down && TabLayers.can_delete(Context.raw.layer)) { ui.is_delete_down = false; let _init = () => { TabLayers.delete_layer(Context.raw.layer); @@ -415,11 +413,11 @@ class TabLayers { } } - if (hasPanel) { + if (has_panel) { ui._y += center; - let layerPanel = zui_nest(zui_handle("tablayers_1"), l.id); - layerPanel.selected = l.show_panel; - l.show_panel = zui_panel(layerPanel, "", true, false, false); + let layer_panel: zui_handle_t = zui_nest(zui_handle("tablayers_1"), l.id); + layer_panel.selected = l.show_panel; + l.show_panel = zui_panel(layer_panel, "", true, false, false); ui._y -= center; } @@ -447,35 +445,35 @@ class TabLayers { } static combo_object = (ui: zui_t, l: SlotLayerRaw, label = false): zui_handle_t => { - let ar = [tr("Shared")]; + let ar: string[] = [tr("Shared")]; for (let p of Project.paint_objects) ar.push(p.base.name); - let atlases = Project.get_used_atlases(); + let atlases: string[] = Project.get_used_atlases(); if (atlases != null) for (let a of atlases) ar.push(a); - let objectHandle = zui_nest(zui_handle("tablayers_2"), l.id); - objectHandle.position = l.objectMask; - l.objectMask = zui_combo(objectHandle, ar, tr("Object"), label, zui_align_t.LEFT); - if (objectHandle.changed) { + let object_handle: zui_handle_t = zui_nest(zui_handle("tablayers_2"), l.id); + object_handle.position = l.object_mask; + l.object_mask = zui_combo(object_handle, ar, tr("Object"), label, zui_align_t.LEFT); + if (object_handle.changed) { Context.set_layer(l); MakeMaterial.parse_mesh_material(); if (l.fill_layer != null) { // Fill layer let _init = () => { Context.raw.material = l.fill_layer; SlotLayer.clear(l); - Base.update_fill_layers(); + base_update_fill_layers(); } app_notify_on_init(_init); } else { - Base.set_object_mask(); + base_set_object_mask(); } } - return objectHandle; + return object_handle; } static combo_blending = (ui: zui_t, l: SlotLayerRaw, label = false): zui_handle_t => { - let blendingHandle = zui_nest(zui_handle("tablayers_3"), l.id); - blendingHandle.position = l.blending; - zui_combo(blendingHandle, [ + let blending_handle: zui_handle_t = zui_nest(zui_handle("tablayers_3"), l.id); + blending_handle.position = l.blending; + zui_combo(blending_handle, [ tr("Mix"), tr("Darken"), tr("Multiply"), @@ -495,13 +493,13 @@ class TabLayers { tr("Color"), tr("Value"), ], tr("Blending"), label); - if (blendingHandle.changed) { + if (blending_handle.changed) { Context.set_layer(l); History.layer_blending(); - l.blending = blendingHandle.position; + l.blending = blending_handle.position; MakeMaterial.parse_mesh_material(); } - return blendingHandle; + return blending_handle; } static layer_toggle_visible = (l: SlotLayerRaw) => { @@ -511,8 +509,8 @@ class TabLayers { } static draw_layer_highlight = (l: SlotLayerRaw, mini: bool) => { - let ui = UIBase.ui; - let step = ui.t.ELEMENT_H; + let ui: zui_t = UIBase.ui; + let step: i32 = ui.t.ELEMENT_H; // Separator line zui_fill(0, 0, (ui._w / zui_SCALE(ui) - 2), 1 * zui_SCALE(ui), ui.t.SEPARATOR_COL); @@ -529,13 +527,13 @@ class TabLayers { } static handle_layer_icon_state = (l: SlotLayerRaw, i: i32, state: zui_state_t, uix: f32, uiy: f32) => { - let ui = UIBase.ui; + let ui: zui_t = UIBase.ui; ///if is_paint - let texpaint_preview = l.texpaint_preview; + let texpaint_preview: image_t = l.texpaint_preview; ///end ///if is_sculpt - let texpaint_preview = l.texpaint; + let texpaint_preview: image_t = l.texpaint; ///end TabLayers.show_context_menu = false; @@ -575,39 +573,39 @@ class TabLayers { } static draw_layer_icon = (l: SlotLayerRaw, i: i32, uix: f32, uiy: f32, mini: bool) => { - let ui = UIBase.ui; - let icons = Res.get("icons.k"); - let iconH = (zui_ELEMENT_H(ui) - (mini ? 2 : 3)) * 2; + let ui: zui_t = UIBase.ui; + let icons: image_t = Res.get("icons.k"); + let icon_h: i32 = (zui_ELEMENT_H(ui) - (mini ? 2 : 3)) * 2; if (mini && zui_SCALE(ui) > 1) { ui._x -= 1 * zui_SCALE(ui); } if (l.parent != null) { - ui._x += (iconH - iconH * 0.9) / 2; - iconH *= 0.9; + ui._x += (icon_h - icon_h * 0.9) / 2; + icon_h *= 0.9; if (l.parent.parent != null) { - ui._x += (iconH - iconH * 0.9) / 2; - iconH *= 0.9; + ui._x += (icon_h - icon_h * 0.9) / 2; + icon_h *= 0.9; } } if (!SlotLayer.is_group(l)) { ///if is_paint - let texpaint_preview = l.texpaint_preview; + let texpaint_preview: image_t = l.texpaint_preview; ///end ///if is_sculpt - let texpaint_preview = l.texpaint; + let texpaint_preview: image_t = l.texpaint; ///end - let icon = l.fill_layer == null ? texpaint_preview : l.fill_layer.image_icon; + let icon: image_t = l.fill_layer == null ? texpaint_preview : l.fill_layer.image_icon; if (l.fill_layer == null) { // Checker - let r = Res.tile50(icons, 4, 1); - let _x = ui._x; - let _y = ui._y; - let _w = ui._w; - zui_image(icons, 0xffffffff, iconH, r.x, r.y, r.w, r.h); + let r: rect_t = Res.tile50(icons, 4, 1); + let _x: f32 = ui._x; + let _y: f32 = ui._y; + let _w: f32 = ui._w; + zui_image(icons, 0xffffffff, icon_h, r.x, r.y, r.w, r.h); ui.cur_ratio--; ui._x = _x; ui._y = _y; @@ -621,19 +619,19 @@ class TabLayers { krom_g4_set_int(UIView2D.channel_location, 1); } - let state = zui_image(icon, 0xffffffff, iconH); + let state: zui_state_t = zui_image(icon, 0xffffffff, icon_h); if (l.fill_layer == null && SlotLayer.is_mask(l)) { g2_set_pipeline(null); } // Draw layer numbers when selecting a layer via keyboard shortcut - let isTyping = ui.is_typing || UIView2D.ui.is_typing || UINodes.ui.is_typing; - if (!isTyping) { + let is_typing: bool = ui.is_typing || UIView2D.ui.is_typing || UINodes.ui.is_typing; + if (!is_typing) { if (i < 9 && Operator.shortcut(Config.keymap.select_layer, ShortcutType.ShortcutDown)) { - let number = String(i + 1) ; - let width = g2_font_width(ui.font, ui.font_size, number) + 10; - let height = g2_font_height(ui.font, ui.font_size); + let number: string = String(i + 1) ; + let width: i32 = g2_font_width(ui.font, ui.font_size, number) + 10; + let height: i32 = g2_font_height(ui.font, ui.font_size); g2_set_color(ui.t.TEXT_COL); g2_fill_rect(uix, uiy, width, height); g2_set_color(ui.t.ACCENT_COL); @@ -644,15 +642,15 @@ class TabLayers { return state; } else { // Group - let folderClosed = Res.tile50(icons, 2, 1); - let folderOpen = Res.tile50(icons, 8, 1); - let folder = l.show_panel ? folderOpen : folderClosed; - return zui_image(icons, ui.t.LABEL_COL - 0x00202020, iconH, folder.x, folder.y, folder.w, folder.h); + let folder_closed: rect_t = Res.tile50(icons, 2, 1); + let folder_open: rect_t = Res.tile50(icons, 8, 1); + let folder: rect_t = l.show_panel ? folder_open : folder_closed; + return zui_image(icons, ui.t.LABEL_COL - 0x00202020, icon_h, folder.x, folder.y, folder.w, folder.h); } } static can_merge_down = (l: SlotLayerRaw) : bool => { - let index = Project.layers.indexOf(l); + let index: i32 = Project.layers.indexOf(l); // Lowest layer if (index == 0) return false; // Lowest layer that has masks @@ -665,7 +663,7 @@ class TabLayers { } static draw_layer_context_menu = (l: SlotLayerRaw, mini: bool) => { - let add = 0; + let add: i32 = 0; if (l.fill_layer == null) add += 1; // Clear if (l.fill_layer != null && !SlotLayer.is_mask(l)) add += 3; @@ -676,16 +674,16 @@ class TabLayers { if (!SlotLayer.is_group(l)) add += 1; if (SlotLayer.is_layer(l)) add += 1; } - let menuElements = SlotLayer.is_group(l) ? 7 : (19 + add); + let menu_elements: i32 = SlotLayer.is_group(l) ? 7 : (19 + add); UIMenu.draw((ui: zui_t) => { if (mini) { - let visibleHandle = zui_handle("tablayers_4"); - visibleHandle.selected = l.visible; + let visible_handle: zui_handle_t = zui_handle("tablayers_4"); + visible_handle.selected = l.visible; UIMenu.menu_fill(ui); - zui_check(visibleHandle, tr("Visible")); - if (visibleHandle.changed) { + zui_check(visible_handle, tr("Visible")); + if (visible_handle.changed) { TabLayers.layer_toggle_visible(l); UIMenu.keep_open = true; } @@ -707,7 +705,7 @@ class TabLayers { if (UIMenu.menu_button(ui, tr("Export"))) { if (SlotLayer.is_mask(l)) { UIFiles.show("png", true, false, (path: string) => { - let f = UIFiles.filename; + let f: string = UIFiles.filename; if (f == "") f = tr("untitled"); if (!f.endsWith(".png")) f += ".png"; krom_write_png(path + Path.sep + f, image_get_pixels(l.texpaint), l.texpaint.width, l.texpaint.height, 3); // RRR1 @@ -722,17 +720,17 @@ class TabLayers { } if (!SlotLayer.is_group(l)) { - let toFillString = SlotLayer.is_layer(l) ? tr("To Fill Layer") : tr("To Fill Mask"); - let toPaintString = SlotLayer.is_layer(l) ? tr("To Paint Layer") : tr("To Paint Mask"); + let to_fill_string: string = SlotLayer.is_layer(l) ? tr("To Fill Layer") : tr("To Fill Mask"); + let to_paint_string: string = SlotLayer.is_layer(l) ? tr("To Paint Layer") : tr("To Paint Mask"); - if (l.fill_layer == null && UIMenu.menu_button(ui, toFillString)) { + if (l.fill_layer == null && UIMenu.menu_button(ui, to_fill_string)) { let _init = () => { SlotLayer.is_layer(l) ? History.to_fill_layer() : History.to_fill_mask(); SlotLayer.to_fill_layer(l); } app_notify_on_init(_init); } - if (l.fill_layer != null && UIMenu.menu_button(ui, toPaintString)) { + if (l.fill_layer != null && UIMenu.menu_button(ui, to_paint_string)) { let _init = () => { SlotLayer.is_layer(l) ? History.to_paint_layer() : History.to_paint_mask(); SlotLayer.to_paint_layer(l); @@ -790,7 +788,7 @@ class TabLayers { } if (SlotLayer.is_group(l) && UIMenu.menu_button(ui, tr("Merge Group"))) { let _init = () => { - Base.merge_group(l); + base_merge_group(l); } app_notify_on_init(_init); } @@ -799,7 +797,7 @@ class TabLayers { let _init = () => { Context.set_layer(l); History.merge_layers(); - Base.merge_down(); + base_merge_down(); if (Context.raw.layer.fill_layer != null) SlotLayer.to_paint_layer(Context.raw.layer); } app_notify_on_init(_init); @@ -809,19 +807,19 @@ class TabLayers { let _init = () => { Context.set_layer(l); History.duplicate_layer(); - Base.duplicate_layer(l); + base_duplicate_layer(l); } app_notify_on_init(_init); } UIMenu.menu_fill(ui); UIMenu.menu_align(ui); - let layerOpacHandle = zui_nest(zui_handle("tablayers_5"), l.id); - layerOpacHandle.value = l.maskOpacity; - zui_slider(layerOpacHandle, tr("Opacity"), 0.0, 1.0, true); - if (layerOpacHandle.changed) { + let layer_opac_handle: zui_handle_t = zui_nest(zui_handle("tablayers_5"), l.id); + layer_opac_handle.value = l.mask_opacity; + zui_slider(layer_opac_handle, tr("Opacity"), 0.0, 1.0, true); + if (layer_opac_handle.changed) { if (ui.input_started) History.layer_opacity(); - l.maskOpacity = layerOpacHandle.value; + l.mask_opacity = layer_opac_handle.value; MakeMaterial.parse_mesh_material(); UIMenu.keep_open = true; } @@ -829,20 +827,20 @@ class TabLayers { if (!SlotLayer.is_group(l)) { UIMenu.menu_fill(ui); UIMenu.menu_align(ui); - let resHandleChangedLast = Base.res_handle.changed; + let res_handle_changed_last: bool = base_res_handle.changed; ///if (krom_android || krom_ios) - let ar = ["128", "256", "512", "1K", "2K", "4K"]; + let ar: string[] = ["128", "256", "512", "1K", "2K", "4K"]; ///else - let ar = ["128", "256", "512", "1K", "2K", "4K", "8K", "16K"]; + let ar: string[] = ["128", "256", "512", "1K", "2K", "4K", "8K", "16K"]; ///end - let _y = ui._y; - Base.res_handle.value = Base.res_handle.position; - Base.res_handle.position = Math.floor(zui_slider(Base.res_handle, ar[Base.res_handle.position], 0, ar.length - 1, false, 1, false, zui_align_t.LEFT, false)); - if (Base.res_handle.changed) { + let _y: i32 = ui._y; + base_res_handle.value = base_res_handle.position; + base_res_handle.position = Math.floor(zui_slider(base_res_handle, ar[base_res_handle.position], 0, ar.length - 1, false, 1, false, zui_align_t.LEFT, false)); + if (base_res_handle.changed) { UIMenu.keep_open = true; } - if (resHandleChangedLast && !Base.res_handle.changed) { - Base.on_layers_resized(); + if (res_handle_changed_last && !base_res_handle.changed) { + base_on_layers_resized(); } ui._y = _y; zui_draw_string(tr("Res"), null, 0, zui_align_t.RIGHT); @@ -851,12 +849,12 @@ class TabLayers { UIMenu.menu_fill(ui); UIMenu.menu_align(ui); ///if (krom_android || krom_ios) - zui_inline_radio(Base.bits_handle, ["8bit"]); + zui_inline_radio(base_bits_handle, ["8bit"]); ///else - zui_inline_radio(Base.bits_handle, ["8bit", "16bit", "32bit"]); + zui_inline_radio(base_bits_handle, ["8bit", "16bit", "32bit"]); ///end - if (Base.bits_handle.changed) { - app_notify_on_init(Base.set_layer_bits); + if (base_bits_handle.changed) { + app_notify_on_init(base_set_layer_bits); UIMenu.keep_open = true; } } @@ -864,14 +862,14 @@ class TabLayers { if (l.fill_layer != null) { UIMenu.menu_fill(ui); UIMenu.menu_align(ui); - let scaleHandle = zui_nest(zui_handle("tablayers_6"), l.id); - scaleHandle.value = l.scale; - l.scale = zui_slider(scaleHandle, tr("UV Scale"), 0.0, 5.0, true); - if (scaleHandle.changed) { + let scale_handle: zui_handle_t = zui_nest(zui_handle("tablayers_6"), l.id); + scale_handle.value = l.scale; + l.scale = zui_slider(scale_handle, tr("UV Scale"), 0.0, 5.0, true); + if (scale_handle.changed) { Context.set_material(l.fill_layer); Context.set_layer(l); let _init = () => { - Base.update_fill_layers(); + base_update_fill_layers(); } app_notify_on_init(_init); UIMenu.keep_open = true; @@ -879,15 +877,15 @@ class TabLayers { UIMenu.menu_fill(ui); UIMenu.menu_align(ui); - let angleHandle = zui_nest(zui_handle("tablayers_7"), l.id); - angleHandle.value = l.angle; - l.angle = zui_slider(angleHandle, tr("Angle"), 0.0, 360, true, 1); - if (angleHandle.changed) { + let angle_handle: zui_handle_t = zui_nest(zui_handle("tablayers_7"), l.id); + angle_handle.value = l.angle; + l.angle = zui_slider(angle_handle, tr("Angle"), 0.0, 360, true, 1); + if (angle_handle.changed) { Context.set_material(l.fill_layer); Context.set_layer(l); MakeMaterial.parse_paint_material(); let _init = () => { - Base.update_fill_layers(); + base_update_fill_layers(); } app_notify_on_init(_init); UIMenu.keep_open = true; @@ -895,15 +893,15 @@ class TabLayers { UIMenu.menu_fill(ui); UIMenu.menu_align(ui); - let uvTypeHandle = zui_nest(zui_handle("tablayers_8"), l.id); - uvTypeHandle.position = l.uvType; - l.uvType = zui_inline_radio(uvTypeHandle, [tr("UV Map"), tr("Triplanar"), tr("Project")], zui_align_t.LEFT); - if (uvTypeHandle.changed) { + let uv_type_handle: zui_handle_t = zui_nest(zui_handle("tablayers_8"), l.id); + uv_type_handle.position = l.uv_type; + l.uv_type = zui_inline_radio(uv_type_handle, [tr("UV Map"), tr("Triplanar"), tr("Project")], zui_align_t.LEFT); + if (uv_type_handle.changed) { Context.set_material(l.fill_layer); Context.set_layer(l); MakeMaterial.parse_paint_material(); let _init = () => { - Base.update_fill_layers(); + base_update_fill_layers(); } app_notify_on_init(_init); UIMenu.keep_open = true; @@ -911,66 +909,66 @@ class TabLayers { } if (!SlotLayer.is_group(l)) { - let baseHandle = zui_nest(zui_handle("tablayers_9"), l.id); - let opacHandle = zui_nest(zui_handle("tablayers_10"), l.id); - let norHandle = zui_nest(zui_handle("tablayers_11"), l.id); - let norBlendHandle = zui_nest(zui_handle("tablayers_12"), l.id); - let occHandle = zui_nest(zui_handle("tablayers_13"), l.id); - let roughHandle = zui_nest(zui_handle("tablayers_14"), l.id); - let metHandle = zui_nest(zui_handle("tablayers_15"), l.id); - let heightHandle = zui_nest(zui_handle("tablayers_16"), l.id); - let heightBlendHandle = zui_nest(zui_handle("tablayers_17"), l.id); - let emisHandle = zui_nest(zui_handle("tablayers_18"), l.id); - let subsHandle = zui_nest(zui_handle("tablayers_19"), l.id); - baseHandle.selected = l.paintBase; - opacHandle.selected = l.paintOpac; - norHandle.selected = l.paintNor; - norBlendHandle.selected = l.paintNorBlend; - occHandle.selected = l.paintOcc; - roughHandle.selected = l.paintRough; - metHandle.selected = l.paintMet; - heightHandle.selected = l.paintHeight; - heightBlendHandle.selected = l.paintHeightBlend; - emisHandle.selected = l.paintEmis; - subsHandle.selected = l.paintSubs; + let base_handle: zui_handle_t = zui_nest(zui_handle("tablayers_9"), l.id); + let opac_handle: zui_handle_t = zui_nest(zui_handle("tablayers_10"), l.id); + let nor_handle: zui_handle_t = zui_nest(zui_handle("tablayers_11"), l.id); + let nor_blend_handle: zui_handle_t = zui_nest(zui_handle("tablayers_12"), l.id); + let occ_handle: zui_handle_t = zui_nest(zui_handle("tablayers_13"), l.id); + let rough_handle: zui_handle_t = zui_nest(zui_handle("tablayers_14"), l.id); + let met_handle: zui_handle_t = zui_nest(zui_handle("tablayers_15"), l.id); + let height_handle: zui_handle_t = zui_nest(zui_handle("tablayers_16"), l.id); + let height_blend_handle: zui_handle_t = zui_nest(zui_handle("tablayers_17"), l.id); + let emis_handle: zui_handle_t = zui_nest(zui_handle("tablayers_18"), l.id); + let subs_handle: zui_handle_t = zui_nest(zui_handle("tablayers_19"), l.id); + base_handle.selected = l.paint_base; + opac_handle.selected = l.paint_opac; + nor_handle.selected = l.paint_nor; + nor_blend_handle.selected = l.paint_nor_blend; + occ_handle.selected = l.paint_occ; + rough_handle.selected = l.paint_rough; + met_handle.selected = l.paint_met; + height_handle.selected = l.paint_height; + height_blend_handle.selected = l.paint_height_blend; + emis_handle.selected = l.paint_emis; + subs_handle.selected = l.paint_subs; UIMenu.menu_fill(ui); - l.paintBase = zui_check(baseHandle, tr("Base Color")); + l.paint_base = zui_check(base_handle, tr("Base Color")); UIMenu.menu_fill(ui); - l.paintOpac = zui_check(opacHandle, tr("Opacity")); + l.paint_opac = zui_check(opac_handle, tr("Opacity")); UIMenu.menu_fill(ui); - l.paintNor = zui_check(norHandle, tr("Normal")); + l.paint_nor = zui_check(nor_handle, tr("Normal")); UIMenu.menu_fill(ui); - l.paintNorBlend = zui_check(norBlendHandle, tr("Normal Blending")); + l.paint_nor_blend = zui_check(nor_blend_handle, tr("Normal Blending")); UIMenu.menu_fill(ui); - l.paintOcc = zui_check(occHandle, tr("Occlusion")); + l.paint_occ = zui_check(occ_handle, tr("Occlusion")); UIMenu.menu_fill(ui); - l.paintRough = zui_check(roughHandle, tr("Roughness")); + l.paint_rough = zui_check(rough_handle, tr("Roughness")); UIMenu.menu_fill(ui); - l.paintMet = zui_check(metHandle, tr("Metallic")); + l.paint_met = zui_check(met_handle, tr("Metallic")); UIMenu.menu_fill(ui); - l.paintHeight = zui_check(heightHandle, tr("Height")); + l.paint_height = zui_check(height_handle, tr("Height")); UIMenu.menu_fill(ui); - l.paintHeightBlend = zui_check(heightBlendHandle, tr("Height Blending")); + l.paint_height_blend = zui_check(height_blend_handle, tr("Height Blending")); UIMenu.menu_fill(ui); - l.paintEmis = zui_check(emisHandle, tr("Emission")); + l.paint_emis = zui_check(emis_handle, tr("Emission")); UIMenu.menu_fill(ui); - l.paintSubs = zui_check(subsHandle, tr("Subsurface")); - if (baseHandle.changed || - opacHandle.changed || - norHandle.changed || - norBlendHandle.changed || - occHandle.changed || - roughHandle.changed || - metHandle.changed || - heightHandle.changed || - heightBlendHandle.changed || - emisHandle.changed || - subsHandle.changed) { + l.paint_subs = zui_check(subs_handle, tr("Subsurface")); + if (base_handle.changed || + opac_handle.changed || + nor_handle.changed || + nor_blend_handle.changed || + occ_handle.changed || + rough_handle.changed || + met_handle.changed || + height_handle.changed || + height_blend_handle.changed || + emis_handle.changed || + subs_handle.changed) { MakeMaterial.parse_mesh_material(); UIMenu.keep_open = true; } } - }, menuElements); + }, menu_elements); } static make_mask_preview_rgba32 = (l: SlotLayerRaw) => { @@ -994,7 +992,7 @@ class TabLayers { } static delete_layer = (l: SlotLayerRaw) => { - let pointers = TabLayers.init_layer_map(); + let pointers: map_t = TabLayers.init_layer_map(); if (SlotLayer.is_layer(l) && SlotLayer.has_masks(l, false)) { for (let m of SlotLayer.get_masks(l, false)) { @@ -1031,12 +1029,12 @@ class TabLayers { if (SlotLayer.is_mask(l)) { Context.raw.layer = l.parent; - Base.update_fill_layers(); + base_update_fill_layers(); } // Remove empty group if (SlotLayer.is_in_group(l) && SlotLayer.get_children(SlotLayer.get_containing_group(l)) == null) { - let g = SlotLayer.get_containing_group(l); + let g: SlotLayerRaw = SlotLayer.get_containing_group(l); // Maybe some group masks are left if (SlotLayer.has_masks(g)) { for (let m of SlotLayer.get_masks(g)) { @@ -1054,19 +1052,19 @@ class TabLayers { } static can_delete = (l: SlotLayerRaw) => { - let numLayers = 0; + let num_layers: i32 = 0; if (SlotLayer.is_mask(l)) return true; for (let slot of Project.layers) { - if (SlotLayer.is_layer(slot)) ++numLayers; + if (SlotLayer.is_layer(slot)) ++num_layers; } // All layers are in one group - if (SlotLayer.is_group(l) && SlotLayer.get_children(l).length == numLayers) return false; + if (SlotLayer.is_group(l) && SlotLayer.get_children(l).length == num_layers) return false; // Do not delete last layer - return numLayers > 1; + return num_layers > 1; } static can_drop_new_layer = (position: i32) => { diff --git a/armorpaint/Sources/nodes/BrushOutputNode.ts b/armorpaint/Sources/nodes/BrushOutputNode.ts index 55afab27..d3801d34 100644 --- a/armorpaint/Sources/nodes/BrushOutputNode.ts +++ b/armorpaint/Sources/nodes/BrushOutputNode.ts @@ -1,7 +1,7 @@ class BrushOutputNode extends LogicNode { - Directional = false; // button 0 + Directional: bool = false; // button 0 constructor() { super(); @@ -10,8 +10,8 @@ class BrushOutputNode extends LogicNode { } parse_inputs = () => { - let lastMask = Context.raw.brush_mask_image; - let lastStencil = Context.raw.brush_stencil_image; + let last_mask: image_t = Context.raw.brush_mask_image; + let last_stencil: image_t = Context.raw.brush_stencil_image; let input0: any; let input1: any; @@ -44,8 +44,8 @@ class BrushOutputNode extends LogicNode { Context.raw.brush_mask_image_is_alpha = opac.endsWith(".a"); opac = opac.substr(0, opac.lastIndexOf(".")); Context.raw.brush_nodes_opacity = 1.0; - let index = Project.asset_names.indexOf(opac); - let asset = Project.assets[index]; + let index: i32 = Project.asset_names.indexOf(opac); + let asset: asset_t = Project.assets[index]; Context.raw.brush_mask_image = Project.get_image(asset); } else { @@ -60,16 +60,16 @@ class BrushOutputNode extends LogicNode { if (typeof stencil == "string") { Context.raw.brush_stencil_image_is_alpha = stencil.endsWith(".a"); stencil = stencil.substr(0, stencil.lastIndexOf(".")); - let index = Project.asset_names.indexOf(stencil); - let asset = Project.assets[index]; + let index: i32 = Project.asset_names.indexOf(stencil); + let asset: asset_t = Project.assets[index]; Context.raw.brush_stencil_image = Project.get_image(asset); } else { Context.raw.brush_stencil_image = null; } - if (lastMask != Context.raw.brush_mask_image || - lastStencil != Context.raw.brush_stencil_image) { + if (last_mask != Context.raw.brush_mask_image || + last_stencil != Context.raw.brush_stencil_image) { MakeMaterial.parse_paint_material(); } @@ -77,11 +77,11 @@ class BrushOutputNode extends LogicNode { } run = (from: i32) => { - let left = 0.0; - let right = 1.0; + let left: f32 = 0.0; + let right: f32 = 1.0; if (Context.raw.paint2d) { left = 1.0; - right = (Context.raw.split_view ? 2.0 : 1.0) + UIView2D.ww / Base.w(); + right = (Context.raw.split_view ? 2.0 : 1.0) + UIView2D.ww / base_w(); } // First time init @@ -91,36 +91,36 @@ class BrushOutputNode extends LogicNode { } // Do not paint over fill layer - let fillLayer = Context.raw.layer.fill_layer != null && Context.raw.tool != workspace_tool_t.PICKER && Context.raw.tool != workspace_tool_t.MATERIAL && Context.raw.tool != workspace_tool_t.COLORID; + let fill_layer: bool = Context.raw.layer.fill_layer != null && Context.raw.tool != workspace_tool_t.PICKER && Context.raw.tool != workspace_tool_t.MATERIAL && Context.raw.tool != workspace_tool_t.COLORID; // Do not paint over groups - let groupLayer = SlotLayer.is_group(Context.raw.layer); + let group_layer: bool = SlotLayer.is_group(Context.raw.layer); // Paint bounds if (Context.raw.paint_vec.x > left && Context.raw.paint_vec.x < right && Context.raw.paint_vec.y > 0 && Context.raw.paint_vec.y < 1 && - !fillLayer && - !groupLayer && + !fill_layer && + !group_layer && (SlotLayer.is_visible(Context.raw.layer) || Context.raw.paint2d) && !UIBase.ui.is_hovered && - !Base.is_dragging && - !Base.is_resizing && - !Base.is_scrolling() && - !Base.is_combo_selected()) { + !base_is_dragging && + !base_is_resizing && + !base_is_scrolling() && + !base_is_combo_selected()) { // Set color pick - let down = mouse_down() || pen_down(); + let down: bool = mouse_down() || pen_down(); if (down && Context.raw.tool == workspace_tool_t.COLORID && Project.assets.length > 0) { Context.raw.colorid_picked = true; UIToolbar.toolbar_handle.redraws = 1; } // Prevent painting the same spot - let sameSpot = Context.raw.paint_vec.x == Context.raw.last_paint_x && Context.raw.paint_vec.y == Context.raw.last_paint_y; - let lazy = Context.raw.tool == workspace_tool_t.BRUSH && Context.raw.brush_lazy_radius > 0; - if (down && (sameSpot || lazy)) { + let same_spot: bool = Context.raw.paint_vec.x == Context.raw.last_paint_x && Context.raw.paint_vec.y == Context.raw.last_paint_y; + let lazy: bool = Context.raw.tool == workspace_tool_t.BRUSH && Context.raw.brush_lazy_radius > 0; + if (down && (same_spot || lazy)) { Context.raw.painted++; } else { diff --git a/armorpaint/Sources/nodes/InputNode.ts b/armorpaint/Sources/nodes/InputNode.ts index 2d90bdec..d83f2187 100644 --- a/armorpaint/Sources/nodes/InputNode.ts +++ b/armorpaint/Sources/nodes/InputNode.ts @@ -1,19 +1,19 @@ class InputNode extends LogicNode { - static coords = vec4_create(); + static coords: vec4_t = vec4_create(); - static startX = 0.0; - static startY = 0.0; + static startX: f32 = 0.0; + static startY: f32 = 0.0; // Brush ruler - static lockBegin = false; - static lockX = false; - static lockY = false; - static lockStartX = 0.0; - static lockStartY = 0.0; + static lock_begin: bool = false; + static lock_x: bool = false; + static lock_y: bool = false; + static lock_start_x: f32 = 0.0; + static lock_start_y: f32 = 0.0; - static registered = false; + static registered: bool = false; constructor() { super(); @@ -26,27 +26,27 @@ class InputNode extends LogicNode { update = () => { if (Context.raw.split_view) { - Context.raw.view_index = mouse_view_x() > Base.w() / 2 ? 1 : 0; + Context.raw.view_index = mouse_view_x() > base_w() / 2 ? 1 : 0; } - let decal = Context.raw.tool == workspace_tool_t.DECAL || Context.raw.tool == workspace_tool_t.TEXT; - let decalMask = decal && Operator.shortcut(Config.keymap.decal_mask + "+" + Config.keymap.action_paint, ShortcutType.ShortcutDown); + let decal: bool = Context.raw.tool == workspace_tool_t.DECAL || Context.raw.tool == workspace_tool_t.TEXT; + let decal_mask: bool = decal && Operator.shortcut(Config.keymap.decal_mask + "+" + Config.keymap.action_paint, ShortcutType.ShortcutDown); - let lazyPaint = Context.raw.brush_lazy_radius > 0 && + let lazy_paint: bool = Context.raw.brush_lazy_radius > 0 && (Operator.shortcut(Config.keymap.action_paint, ShortcutType.ShortcutDown) || Operator.shortcut(Config.keymap.brush_ruler + "+" + Config.keymap.action_paint, ShortcutType.ShortcutDown) || - decalMask); + decal_mask); - let paintX = mouse_view_x() / app_w(); - let paintY = mouse_view_y() / app_h(); + let paint_x: f32 = mouse_view_x() / app_w(); + let paint_y: f32 = mouse_view_y() / app_h(); if (mouse_started()) { InputNode.startX = mouse_view_x() / app_w(); InputNode.startY = mouse_view_y() / app_h(); } if (pen_down()) { - paintX = pen_view_x() / app_w(); - paintY = pen_view_y() / app_h(); + paint_x = pen_view_x() / app_w(); + paint_y = pen_view_y() / app_h(); } if (pen_started()) { InputNode.startX = pen_view_x() / app_w(); @@ -54,48 +54,48 @@ class InputNode extends LogicNode { } if (Operator.shortcut(Config.keymap.brush_ruler + "+" + Config.keymap.action_paint, ShortcutType.ShortcutDown)) { - if (InputNode.lockX) paintX = InputNode.startX; - if (InputNode.lockY) paintY = InputNode.startY; + if (InputNode.lock_x) paint_x = InputNode.startX; + if (InputNode.lock_y) paint_y = InputNode.startY; } if (Context.raw.brush_lazy_radius > 0) { - Context.raw.brush_lazy_x = paintX; - Context.raw.brush_lazy_y = paintY; + Context.raw.brush_lazy_x = paint_x; + Context.raw.brush_lazy_y = paint_y; } - if (!lazyPaint) { - InputNode.coords.x = paintX; - InputNode.coords.y = paintY; + if (!lazy_paint) { + InputNode.coords.x = paint_x; + InputNode.coords.y = paint_y; } if (Context.raw.split_view) { Context.raw.view_index = -1; } - if (InputNode.lockBegin) { - let dx = Math.abs(InputNode.lockStartX - mouse_view_x()); - let dy = Math.abs(InputNode.lockStartY - mouse_view_y()); + if (InputNode.lock_begin) { + let dx: f32 = Math.abs(InputNode.lock_start_x - mouse_view_x()); + let dy: f32 = Math.abs(InputNode.lock_start_y - mouse_view_y()); if (dx > 1 || dy > 1) { - InputNode.lockBegin = false; - dx > dy ? InputNode.lockY = true : InputNode.lockX = true; + InputNode.lock_begin = false; + dx > dy ? InputNode.lock_y = true : InputNode.lock_x = true; } } if (keyboard_started(Config.keymap.brush_ruler)) { - InputNode.lockStartX = mouse_view_x(); - InputNode.lockStartY = mouse_view_y(); - InputNode.lockBegin = true; + InputNode.lock_start_x = mouse_view_x(); + InputNode.lock_start_y = mouse_view_y(); + InputNode.lock_begin = true; } else if (keyboard_released(Config.keymap.brush_ruler)) { - InputNode.lockX = InputNode.lockY = InputNode.lockBegin = false; + InputNode.lock_x = InputNode.lock_y = InputNode.lock_begin = false; } if (Context.raw.brush_lazy_radius > 0) { - let v1 = vec4_create(Context.raw.brush_lazy_x * app_w(), Context.raw.brush_lazy_y * app_h(), 0.0); - let v2 = vec4_create(InputNode.coords.x * app_w(), InputNode.coords.y * app_h(), 0.0); - let d = vec4_dist(v1, v2); - let r = Context.raw.brush_lazy_radius * 85; + let v1: vec4_t = vec4_create(Context.raw.brush_lazy_x * app_w(), Context.raw.brush_lazy_y * app_h(), 0.0); + let v2: vec4_t = vec4_create(InputNode.coords.x * app_w(), InputNode.coords.y * app_h(), 0.0); + let d: f32 = vec4_dist(v1, v2); + let r: f32 = Context.raw.brush_lazy_radius * 85; if (d > r) { - let v3 = vec4_create(); + let v3: vec4_t = vec4_create(); vec4_sub_vecs(v3, v2, v1); vec4_normalize(v3, ); vec4_mult(v3, 1.0 - Context.raw.brush_lazy_step); diff --git a/armorsculpt/Sources/ImportMesh.ts b/armorsculpt/Sources/ImportMesh.ts index f548bf66..f08089a0 100644 --- a/armorsculpt/Sources/ImportMesh.ts +++ b/armorsculpt/Sources/ImportMesh.ts @@ -99,8 +99,8 @@ class ImportMesh { let l = Project.layers.pop(); SlotLayer.unload(l); } - Base.newLayer(false); - app_notify_on_init(Base.initLayers); + base_newLayer(false); + app_notify_on_init(base_initLayers); History.reset(); } @@ -118,7 +118,7 @@ class ImportMesh { // Wait for addMesh calls to finish app_notify_on_init(ImportMesh.finishImport); - Base.notifyOnNextFrame(() => { + base_notifyOnNextFrame(() => { let f32 = new Float32Array(Config.getTextureResX() * Config.getTextureResY() * 4); for (let i = 0; i < Math.floor(mesh.inda.length); ++i) { let index = mesh.inda[i]; @@ -130,7 +130,7 @@ class ImportMesh { let imgmesh = image_from_bytes(f32.buffer, Config.getTextureResX(), Config.getTextureResY(), tex_format_t.RGBA128); let texpaint = Project.layers[0].texpaint; g2_begin(texpaint); - g2_set_pipeline(Base.pipeCopy128); + g2_set_pipeline(base_pipeCopy128); g2_draw_scaled_image(imgmesh, 0, 0, Config.getTextureResX(), Config.getTextureResY()); g2_set_pipeline(null); g2_end(); diff --git a/armorsculpt/Sources/MakeMaterial.ts b/armorsculpt/Sources/MakeMaterial.ts index 6baf6aaf..2e15fbd1 100644 --- a/armorsculpt/Sources/MakeMaterial.ts +++ b/armorsculpt/Sources/MakeMaterial.ts @@ -229,7 +229,7 @@ class MakeMaterial { for (let key of Context.raw.nodePreviews.keys()) { if (Context.raw.nodePreviewsUsed.indexOf(key) == -1) { let image = Context.raw.nodePreviews.get(key); - Base.notifyOnNextFrame(function() { image_unload(image); }); + base_notifyOnNextFrame(function() { image_unload(image); }); Context.raw.nodePreviews.delete(key); } } @@ -317,7 +317,7 @@ class MakeMaterial { } static deleteContext = (c: shader_context_t) => { - Base.notifyOnNextFrame(() => { // Ensure pipeline is no longer in use + base_notifyOnNextFrame(() => { // Ensure pipeline is no longer in use shader_context_delete(c); }); } diff --git a/armorsculpt/Sources/TabLayers.ts b/armorsculpt/Sources/TabLayers.ts index 71e9c658..66d9bb93 100644 --- a/armorsculpt/Sources/TabLayers.ts +++ b/armorsculpt/Sources/TabLayers.ts @@ -75,7 +75,7 @@ class TabLayers { UIMenu.draw((ui: zui_t) => { let l = Context.raw.layer; if (UIMenu.menu_button(ui, tr("Paint Layer"))) { - Base.new_layer(); + base_base_new_layer(); History.new_layer(); } }, 1); @@ -114,9 +114,9 @@ class TabLayers { } static setDragLayer = (layer: SlotLayerRaw, offX: f32, offY: f32) => { - Base.drag_off_x = offX; - Base.drag_off_y = offY; - Base.drag_layer = layer; + base_base_drag_off_x = offX; + base_base_drag_off_y = offY; + base_base_drag_layer = layer; Context.raw.drag_dest = Project.layers.indexOf(layer); } @@ -141,15 +141,15 @@ class TabLayers { // Highlight drag destination let absy = ui._window_y + ui._y; - if (Base.is_dragging && Base.drag_layer != null && Context.in_layers()) { + if (base_base_is_dragging && base_base_drag_layer != null && Context.in_layers()) { if (mouse_y > absy + step && mouse_y < absy + step * 3) { - let down = Project.layers.indexOf(Base.drag_layer) >= i; + let down = Project.layers.indexOf(base_base_drag_layer) >= i; Context.raw.drag_dest = down ? i : i - 1; let ls = Project.layers; let dest = Context.raw.drag_dest; let toGroup = down ? dest > 0 && ls[dest - 1].parent != null && ls[dest - 1].parent.show_panel : dest < ls.length && ls[dest].parent != null && ls[dest].parent.show_panel; - let nestedGroup = SlotLayer.is_group(Base.drag_layer) && toGroup; + let nestedGroup = SlotLayer.is_group(base_base_drag_layer) && toGroup; if (!nestedGroup) { if (SlotLayer.can_move(Context.raw.layer, Context.raw.drag_dest)) { zui_fill(checkw, step * 2, (ui._window_w / zui_SCALE(ui) - 2) - checkw, 2 * zui_SCALE(ui), ui.t.HIGHLIGHT_COL); @@ -163,7 +163,7 @@ class TabLayers { } } } - if (Base.is_dragging && (Base.drag_material != null || Base.drag_swatch != null) && Context.in_layers()) { + if (base_base_is_dragging && (base_base_drag_material != null || base_base_drag_swatch != null) && Context.in_layers()) { if (mouse_y > absy + step && mouse_y < absy + step * 3) { Context.raw.drag_dest = i; if (TabLayers.can_drop_new_layer(i)) @@ -338,8 +338,8 @@ class TabLayers { static comboObject = (ui: zui_t, l: SlotLayerRaw, label = false): zui_handle_t => { let ar = [tr("Shared")]; let objectHandle = zui_nest(zui_handle("tablayers_2"), l.id); - objectHandle.position = l.objectMask; - l.objectMask = zui_combo(objectHandle, ar, tr("Object"), label, zui_align_t.LEFT); + objectHandle.position = l.object_mask; + l.object_mask = zui_combo(objectHandle, ar, tr("Object"), label, zui_align_t.LEFT); return objectHandle; } diff --git a/armorsculpt/Sources/nodes/BrushOutputNode.ts b/armorsculpt/Sources/nodes/BrushOutputNode.ts index 7f0465b7..7ae3fc07 100644 --- a/armorsculpt/Sources/nodes/BrushOutputNode.ts +++ b/armorsculpt/Sources/nodes/BrushOutputNode.ts @@ -75,7 +75,7 @@ class BrushOutputNode extends LogicNode { let right = 1.0; if (Context.raw.paint2d) { left = 1.0; - right = (Context.raw.splitView ? 2.0 : 1.0) + UIView2D.ww / Base.w(); + right = (Context.raw.splitView ? 2.0 : 1.0) + UIView2D.ww / base_w(); } // First time init @@ -99,10 +99,10 @@ class BrushOutputNode extends LogicNode { !groupLayer && (SlotLayer.isVisible(Context.raw.layer) || Context.raw.paint2d) && !UIBase.ui.is_hovered && - !Base.isDragging && - !Base.isResizing && - !Base.isScrolling() && - !Base.isComboSelected()) { + !base_isDragging && + !base_isResizing && + !base_isScrolling() && + !base_isComboSelected()) { let down = mouse_down() || pen_down(); diff --git a/base/Sources/Args.ts b/base/Sources/Args.ts deleted file mode 100644 index 20e28054..00000000 --- a/base/Sources/Args.ts +++ /dev/null @@ -1,190 +0,0 @@ - -class Args { - - static use_args: bool = false; - static asset_path: string = ""; - static background: bool = false; - ///if (is_paint || is_lab) - static export_textures: bool = false; - static export_textures_type: string = ""; - static export_textures_preset: string = ""; - static export_textures_path: string = ""; - ///end - ///if (is_paint || is_sculpt) - static reimport_mesh: bool = false; - static export_mesh: bool = false; - static export_mesh_path: string = ""; - ///end - ///if is_paint - static export_material: bool = false; - static export_material_path: string = ""; - ///end - - static parse() { - if (krom_get_arg_count() > 1) { - Args.use_args = true; - - let i: i32 = 0; - while (i < krom_get_arg_count()) { - // Process each arg - let current_arg: string = krom_get_arg(i); - - if (Path.is_project(current_arg)) { - Project.filepath = current_arg; - } - else if (current_arg == "--b" || current_arg == "--background") { - Args.background = true; - } - - ///if (is_paint || is_lab) - else if (Path.is_texture(current_arg)) { - Args.asset_path = current_arg; - } - else if (current_arg == "--export-textures" && (i + 3) <= krom_get_arg_count()) { - Args.export_textures = true; - ++i; - Args.export_textures_type = krom_get_arg(i); - ++i; - Args.export_textures_preset = krom_get_arg(i); - ++i; - Args.export_textures_path = krom_get_arg(i); - } - ///end - - ///if (is_paint || is_sculpt) - else if (current_arg == "--reload-mesh") { - Args.reimport_mesh = true; - } - else if (current_arg == "--export-mesh" && (i + 1) <= krom_get_arg_count()) { - Args.export_mesh = true; - ++i; - Args.export_mesh_path = krom_get_arg(i); - } - else if (Path.is_mesh(current_arg) || (i > 1 && !current_arg.startsWith("-") && Path.is_folder(current_arg))) { - Args.asset_path = current_arg; - } - ///end - - ///if is_paint - else if (current_arg == "--export-material" && (i + 1) <= krom_get_arg_count()) { - Args.export_material = true; - ++i; - Args.export_material_path = krom_get_arg(i); - } - ///end - - ++i; - } - } - } - - static run() { - if (Args.use_args) { - app_notify_on_init(() => { - if (Project.filepath != "") { - ImportArm.run_project(Project.filepath); - } - else if (Args.asset_path != "") { - ImportAsset.run(Args.asset_path, -1, -1, false); - ///if is_paint - if (Path.is_texture(Args.asset_path)) { - UIBase.show_2d_view(view_2d_type_t.ASSET); - } - ///end - } - ///if (is_paint || is_sculpt) - else if (Args.reimport_mesh) { - Project.reimport_mesh(); - } - ///end - - ///if (is_paint || is_lab) - if (Args.export_textures) { - if (Args.export_textures_type == "png" || - Args.export_textures_type == "jpg" || - Args.export_textures_type == "exr16" || - Args.export_textures_type == "exr32") { - if (Path.is_folder(Args.export_textures_path)) { - // Applying the correct format type from args - if (Args.export_textures_type == "png") { - ///if is_paint - Base.bits_handle.position = texture_bits_t.BITS8; - ///end - Context.raw.format_type = texture_ldr_format_t.PNG; - } - else if (Args.export_textures_type == "jpg") { - ///if is_paint - Base.bits_handle.position = texture_bits_t.BITS8; - ///end - Context.raw.format_type = texture_ldr_format_t.JPG; - } - else if (Args.export_textures_type == "exr16") { - ///if is_paint - Base.bits_handle.position = texture_bits_t.BITS16; - ///end - } - else if (Args.export_textures_type == "exr32") { - ///if is_paint - Base.bits_handle.position = texture_bits_t.BITS32; - ///end - } - - ///if is_paint - Context.raw.layers_export = export_mode_t.VISIBLE; - ///end - - // Get export preset and apply the correct one from args - BoxExport.files = File.read_directory(Path.data() + Path.sep + "export_presets"); - for (let i: i32 = 0; i < BoxExport.files.length; ++i) { - BoxExport.files[i] = BoxExport.files[i].substr(0, BoxExport.files[i].length - 5); // Strip .json - } - - let file: string = "export_presets/" + BoxExport.files[0] + ".json"; - for (let f of BoxExport.files) if (f == Args.export_textures_preset) { - file = "export_presets/" + BoxExport.files[BoxExport.files.indexOf(f)] + ".json"; - } - - let blob: ArrayBuffer = data_get_blob(file); - BoxExport.preset = JSON.parse(sys_buffer_to_string(blob)); - data_delete_blob("export_presets/" + file); - - // Export queue - app_notify_on_init(() => { - ExportTexture.run(Args.export_textures_path); - }); - } - else { - krom_log(tr("Invalid export directory")); - } - } - else { - krom_log(tr("Invalid texture type")); - } - } - ///end - - ///if (is_paint || is_sculpt) - else if (Args.export_mesh) { - if (Path.is_folder(Args.export_mesh_path)) { - let f: string = UIFiles.filename; - if (f == "") f = tr("untitled"); - ExportMesh.run(Args.export_mesh_path + Path.sep + f, null, false); - } - else { - krom_log(tr("Invalid export directory")); - } - } - ///end - - ///if is_paint - else if (Args.export_material) { - Context.raw.write_icon_on_export = true; - ExportArm.run_material(Args.export_material_path); - } - ///end - - if (Args.background) sys_stop(); - }); - } - } -} diff --git a/base/Sources/Base.ts b/base/Sources/Base.ts deleted file mode 100644 index 6301e426..00000000 --- a/base/Sources/Base.ts +++ /dev/null @@ -1,2276 +0,0 @@ - -class Base { - - static ui_enabled: bool = true; - static is_dragging: bool = false; - static is_resizing: bool = false; - static drag_asset: asset_t = null; - static drag_swatch: swatch_color_t = null; - static drag_file: string = null; - static drag_file_icon: image_t = null; - static drag_tint = 0xffffffff; - static drag_size: i32 = -1; - static drag_rect: rect_t = null; - static drag_off_x: f32 = 0.0; - static drag_off_y: f32 = 0.0; - static drag_start: f32 = 0.0; - static drop_x: f32 = 0.0; - static drop_y: f32 = 0.0; - static font: g2_font_t = null; - static theme: theme_t; - static color_wheel: image_t; - static color_wheel_gradient: image_t; - static ui_box: zui_t; - static ui_menu: zui_t; - static default_element_w: i32 = 100; - static default_element_h: i32 = 28; - static default_font_size: i32 = 13; - static res_handle: zui_handle_t = zui_handle_create(); - static bits_handle: zui_handle_t = zui_handle_create(); - static drop_paths: string[] = []; - static appx: i32 = 0; - static appy: i32 = 0; - static last_window_width: i32 = 0; - static last_window_height: i32 = 0; - ///if (is_paint || is_sculpt) - static drag_material: SlotMaterialRaw = null; - static drag_layer: SlotLayerRaw = null; - ///end - - static pipe_copy: pipeline_t; - static pipe_copy8: pipeline_t; - static pipe_copy128: pipeline_t; - static pipe_copyBGRA: pipeline_t; - static pipe_copyRGB: pipeline_t = null; - ///if (is_paint || is_sculpt) - static pipe_merge: pipeline_t = null; - static pipe_merge_r: pipeline_t = null; - static pipe_merge_g: pipeline_t = null; - static pipe_merge_b: pipeline_t = null; - static pipe_merge_a: pipeline_t = null; - static pipe_invert8: pipeline_t; - static pipe_apply_mask: pipeline_t; - static pipe_merge_mask: pipeline_t; - static pipe_colorid_to_mask: pipeline_t; - static tex0: kinc_tex_unit_t; - static tex1: kinc_tex_unit_t; - static texmask: kinc_tex_unit_t; - static texa: kinc_tex_unit_t; - static opac: kinc_const_loc_t; - static blending: kinc_const_loc_t; - static tex0_mask: kinc_tex_unit_t; - static texa_mask: kinc_tex_unit_t; - static tex0_merge_mask: kinc_tex_unit_t; - static texa_merge_mask: kinc_tex_unit_t; - static tex_colorid: kinc_tex_unit_t; - static texpaint_colorid: kinc_tex_unit_t; - static opac_merge_mask: kinc_const_loc_t; - static blending_merge_mask: kinc_const_loc_t; - static temp_mask_image: image_t = null; - ///end - ///if is_lab - static pipe_copy_r: pipeline_t; - static pipe_copy_g: pipeline_t; - static pipe_copy_b: pipeline_t; - static pipe_copy_a: pipeline_t; - static pipe_copy_a_tex: kinc_tex_unit_t; - static pipe_inpaint_preview: pipeline_t; - static tex0_inpaint_preview: kinc_tex_unit_t; - static texa_inpaint_preview: kinc_tex_unit_t; - ///end - static temp_image: image_t = null; - static expa: image_t = null; - static expb: image_t = null; - static expc: image_t = null; - static pipe_cursor: pipeline_t; - static cursor_vp: kinc_const_loc_t; - static cursor_inv_vp: kinc_const_loc_t; - static cursor_mouse: kinc_const_loc_t; - static cursor_tex_step: kinc_const_loc_t; - static cursor_radius: kinc_const_loc_t; - static cursor_camera_right: kinc_const_loc_t; - static cursor_tint: kinc_const_loc_t; - static cursor_tex: kinc_tex_unit_t; - static cursor_gbufferd: kinc_tex_unit_t; - - ///if (is_paint || is_sculpt) - static default_base: f32 = 0.5; - static default_rough: f32 = 0.4; - ///if (krom_android || krom_ios) - static max_layers: i32 = 18; - ///else - static max_layers: i32 = 255; - ///end - ///end - static default_fov: f32 = 0.69; - - constructor() { - Base.last_window_width = sys_width(); - Base.last_window_height = sys_height(); - - sys_notify_on_drop_files((dropPath: string) => { - ///if krom_linux - dropPath = decodeURIComponent(dropPath); - ///end - dropPath = trim_end(dropPath); - Base.drop_paths.push(dropPath); - }); - - sys_notify_on_app_state( - () => { // Foreground - Context.raw.foreground_event = true; - Context.raw.last_paint_x = -1; - Context.raw.last_paint_y = -1; - }, - () => {}, // Resume - () => {}, // Pause - () => { // Background - // Release keys after alt-tab / win-tab - keyboard_up_listener(key_code_t.ALT); - keyboard_up_listener(key_code_t.WIN); - }, - () => { // Shutdown - ///if (krom_android || krom_ios) - Project.project_save(); - ///end - } - ); - - krom_set_save_and_quit_callback(Base.save_and_quit_callback); - - let f: g2_font_t = data_get_font("font.ttf"); - let imageColorWheel: image_t = data_get_image("color_wheel.k"); - let imageColorWheelGradient: image_t = data_get_image("color_wheel_gradient.k"); - - Base.font = f; - Config.load_theme(Config.raw.theme, false); - Base.default_element_w = Base.theme.ELEMENT_W; - Base.default_font_size = Base.theme.FONT_SIZE; - Translator.load_translations(Config.raw.locale); - UIFiles.filename = tr("untitled"); - ///if (krom_android || krom_ios) - sys_title_set(tr("untitled")); - ///end - - // Baked font for fast startup - if (Config.raw.locale == "en") { - Base.font.font_ = krom_g2_font_13(Base.font.blob); - Base.font.glyphs = _g2_font_glyphs; - } - else g2_font_init(Base.font); - - Base.color_wheel = imageColorWheel; - Base.color_wheel_gradient = imageColorWheelGradient; - zui_set_enum_texts(Base.enum_texts); - zui_tr = tr; - Base.ui_box = zui_create({ theme: Base.theme, font: f, scale_factor: Config.raw.window_scale, color_wheel: Base.color_wheel, black_white_gradient: Base.color_wheel_gradient }); - Base.ui_menu = zui_create({ theme: Base.theme, font: f, scale_factor: Config.raw.window_scale, color_wheel: Base.color_wheel, black_white_gradient: Base.color_wheel_gradient }); - Base.default_element_h = Base.ui_menu.t.ELEMENT_H; - - // Init plugins - if (Config.raw.plugins != null) { - for (let plugin of Config.raw.plugins) { - Plugin.start(plugin); - } - } - - Args.parse(); - - new Camera(); - new UIBase(); - new UINodes(); - new UIView2D(); - - ///if is_lab - RandomNode.setSeed(Math.floor(time_time() * 4294967295)); - ///end - - app_notify_on_update(Base.update); - app_notify_on_render_2d(UIView2D.render); - app_notify_on_update(UIView2D.update); - ///if (is_paint || is_sculpt) - app_notify_on_render_2d(UIBase.render_cursor); - ///end - app_notify_on_update(UINodes.update); - app_notify_on_render_2d(UINodes.render); - app_notify_on_update(UIBase.update); - app_notify_on_render_2d(UIBase.render); - app_notify_on_update(Camera.update); - app_notify_on_render_2d(Base.render); - - ///if (is_paint || is_sculpt) - Base.appx = UIToolbar.toolbar_w; - ///end - ///if is_lab - Base.appx = 0; - ///end - - Base.appy = UIHeader.headerh; - if (Config.raw.layout[layout_size_t.HEADER] == 1) Base.appy += UIHeader.headerh; - let cam: camera_object_t = scene_camera; - cam.data.fov = Math.floor(cam.data.fov * 100) / 100; - camera_object_build_proj(cam); - - Args.run(); - - ///if (krom_android || krom_ios) - let hasProjects: bool = Config.raw.recent_projects.length > 0; - ///else - let hasProjects: bool = true; - ///end - - if (Config.raw.splash_screen && hasProjects) { - BoxProjects.show(); - } - } - - static save_and_quit_callback = (save: bool) => { - Base.save_window_rect(); - if (save) Project.project_save(true); - else sys_stop(); - } - - ///if (is_paint || is_sculpt) - static w = (): i32 => { - // Drawing material preview - if (Context.raw.material_preview) { - return UtilRender.material_preview_size; - } - - // Drawing decal preview - if (Context.raw.decal_preview) { - return UtilRender.decal_preview_size; - } - - let res: i32 = 0; - if (Config.raw.layout == null) { - let sidebarw: i32 = UIBase.default_sidebar_w; - res = sys_width() - sidebarw - UIToolbar.default_toolbar_w; - } - else if (UINodes.show || UIView2D.show) { - res = sys_width() - Config.raw.layout[layout_size_t.SIDEBAR_W] - Config.raw.layout[layout_size_t.NODES_W] - UIToolbar.toolbar_w; - } - else if (UIBase.show) { - res = sys_width() - Config.raw.layout[layout_size_t.SIDEBAR_W] - UIToolbar.toolbar_w; - } - else { // Distract free - res = sys_width(); - } - if (Context.raw.view_index > -1) { - res = Math.floor(res / 2); - } - if (Context.raw.paint2d_view) { - res = UIView2D.ww; - } - - return res > 0 ? res : 1; // App was minimized, force render path resize - } - - static h = (): i32 => { - // Drawing material preview - if (Context.raw.material_preview) { - return UtilRender.material_preview_size; - } - - // Drawing decal preview - if (Context.raw.decal_preview) { - return UtilRender.decal_preview_size; - } - - let res: i32 = sys_height(); - - if (Config.raw.layout == null) { - res -= UIHeader.default_header_h * 2 + UIStatus.default_status_h; - - ///if (krom_android || krom_ios) - let layoutHeader: i32 = 0; - ///else - let layoutHeader: i32 = 1; - ///end - if (layoutHeader == 0) { - res += UIHeader.headerh; - } - } - else if (UIBase.show && res > 0) { - let statush: i32 = Config.raw.layout[layout_size_t.STATUS_H]; - res -= Math.floor(UIHeader.default_header_h * 2 * Config.raw.window_scale) + statush; - - if (Config.raw.layout[layout_size_t.HEADER] == 0) { - res += UIHeader.headerh; - } - } - - return res > 0 ? res : 1; // App was minimized, force render path resize - } - ///end - - ///if is_lab - static w = (): i32 => { - let res: i32 = 0; - if (UINodes == null) { - res = sys_width(); - } - else if (UINodes.show || UIView2D.show) { - res = sys_width() - Config.raw.layout[layout_size_t.NODES_W]; - } - else { // Distract free - res = sys_width(); - } - - return res > 0 ? res : 1; // App was minimized, force render path resize - } - - static h = (): i32 => { - let res: i32 = sys_height(); - if (UIBase == null) { - res -= UIHeader.default_header_h * 2 + UIStatus.default_status_h; - } - else if (res > 0) { - let statush: i32 = Config.raw.layout[layout_size_t.STATUS_H]; - res -= Math.floor(UIHeader.default_header_h * 2 * Config.raw.window_scale) + statush; - } - - return res > 0 ? res : 1; // App was minimized, force render path resize - } - ///end - - static x = (): i32 => { - ///if (is_paint || is_sculpt) - return Context.raw.view_index == 1 ? Base.appx + Base.w() : Base.appx; - ///end - ///if is_lab - return Base.appx; - ///end - } - - static y = (): i32 => { - return Base.appy; - } - - static on_resize = () => { - if (sys_width() == 0 || sys_height() == 0) return; - - let ratioW: f32 = sys_width() / Base.last_window_width; - Base.last_window_width = sys_width(); - let ratioH: f32 = sys_height() / Base.last_window_height; - Base.last_window_height = sys_height(); - - Config.raw.layout[layout_size_t.NODES_W] = Math.floor(Config.raw.layout[layout_size_t.NODES_W] * ratioW); - ///if (is_paint || is_sculpt) - Config.raw.layout[layout_size_t.SIDEBAR_H0] = Math.floor(Config.raw.layout[layout_size_t.SIDEBAR_H0] * ratioH); - Config.raw.layout[layout_size_t.SIDEBAR_H1] = sys_height() - Config.raw.layout[layout_size_t.SIDEBAR_H0]; - ///end - - Base.resize(); - - ///if (krom_linux || krom_darwin) - Base.save_window_rect(); - ///end - } - - static save_window_rect = () => { - ///if (krom_windows || krom_linux || krom_darwin) - Config.raw.window_w = sys_width(); - Config.raw.window_h = sys_height(); - Config.raw.window_x = sys_x(); - Config.raw.window_y = sys_y(); - Config.save(); - ///end - } - - static resize = () => { - if (sys_width() == 0 || sys_height() == 0) return; - - let cam: camera_object_t = scene_camera; - if (cam.data.ortho != null) { - cam.data.ortho[2] = -2 * (app_h() / app_w()); - cam.data.ortho[3] = 2 * (app_h() / app_w()); - } - camera_object_build_proj(cam); - - if (Context.raw.camera_type == camera_type_t.ORTHOGRAPHIC) { - Viewport.update_camera_type(Context.raw.camera_type); - } - - Context.raw.ddirty = 2; - - if (UIBase.show) { - ///if (is_paint || is_sculpt) - Base.appx = UIToolbar.toolbar_w; - ///end - ///if is_lab - Base.appx = 0; - ///end - Base.appy = UIHeader.headerh * 2; - if (Config.raw.layout[layout_size_t.HEADER] == 0) { - Base.appy -= UIHeader.headerh; - } - } - else { - Base.appx = 0; - Base.appy = 0; - } - - if (UINodes.grid != null) { - let _grid: image_t = UINodes.grid; - let _next = () => { - image_unload(_grid); - } - Base.notify_on_next_frame(_next); - UINodes.grid = null; - } - - Base.redraw_ui(); - } - - static redraw_ui = () => { - UIHeader.header_handle.redraws = 2; - UIBase.hwnds[tab_area_t.STATUS].redraws = 2; - UIMenubar.menu_handle.redraws = 2; - UIMenubar.workspace_handle.redraws = 2; - UINodes.hwnd.redraws = 2; - UIBox.hwnd.redraws = 2; - UIView2D.hwnd.redraws = 2; - if (Context.raw.ddirty < 0) Context.raw.ddirty = 0; // Redraw viewport - ///if (is_paint || is_sculpt) - UIBase.hwnds[tab_area_t.SIDEBAR0].redraws = 2; - UIBase.hwnds[tab_area_t.SIDEBAR1].redraws = 2; - UIToolbar.toolbar_handle.redraws = 2; - if (Context.raw.split_view) Context.raw.ddirty = 1; - ///end - } - - static update = () => { - if (mouse_movement_x != 0 || mouse_movement_y != 0) { - krom_set_mouse_cursor(0); // Arrow - } - - ///if (is_paint || is_sculpt) - let hasDrag: bool = Base.drag_asset != null || Base.drag_material != null || Base.drag_layer != null || Base.drag_file != null || Base.drag_swatch != null; - ///end - ///if is_lab - let hasDrag: bool = Base.drag_asset != null || Base.drag_file != null || Base.drag_swatch != null; - ///end - - if (Config.raw.touch_ui) { - // Touch and hold to activate dragging - if (Base.drag_start < 0.2) { - if (hasDrag && mouse_down()) Base.drag_start += time_real_delta(); - else Base.drag_start = 0; - hasDrag = false; - } - if (mouse_released()) { - Base.drag_start = 0; - } - let moved: bool = Math.abs(mouse_movement_x) > 1 && Math.abs(mouse_movement_y) > 1; - if ((mouse_released() || moved) && !hasDrag) { - Base.drag_asset = null; - Base.drag_swatch = null; - Base.drag_file = null; - Base.drag_file_icon = null; - Base.is_dragging = false; - ///if (is_paint || is_sculpt) - Base.drag_material = null; - Base.drag_layer = null; - ///end - } - // Disable touch scrolling while dragging is active - zui_set_touch_scroll(!Base.is_dragging); - } - - if (hasDrag && (mouse_movement_x != 0 || mouse_movement_y != 0)) { - Base.is_dragging = true; - } - if (mouse_released() && hasDrag) { - if (Base.drag_asset != null) { - if (Context.in_nodes()) { // Create image texture - UINodes.accept_asset_drag(Project.assets.indexOf(Base.drag_asset)); - } - else if (Context.in_viewport()) { - if (Base.drag_asset.file.toLowerCase().endsWith(".hdr")) { - let image: image_t = Project.get_image(Base.drag_asset); - ImportEnvmap.run(Base.drag_asset.file, image); - } - } - ///if (is_paint || is_sculpt) - else if (Context.in_layers() || Context.in_2d_view()) { // Create mask - Base.create_image_mask(Base.drag_asset); - } - ///end - Base.drag_asset = null; - } - else if (Base.drag_swatch != null) { - if (Context.in_nodes()) { // Create RGB node - UINodes.accept_swatch_drag(Base.drag_swatch); - } - else if (Context.in_swatches()) { - TabSwatches.accept_swatch_drag(Base.drag_swatch); - } - ///if (is_paint || is_sculpt) - else if (Context.in_materials()) { - TabMaterials.accept_swatch_drag(Base.drag_swatch); - } - else if (Context.in_viewport()) { - let color: i32 = Base.drag_swatch.base; - color = color_set_ab(color, Base.drag_swatch.opacity * 255); - Base.create_color_layer(color, Base.drag_swatch.occlusion, Base.drag_swatch.roughness, Base.drag_swatch.metallic); - } - else if (Context.in_layers() && TabLayers.can_drop_new_layer(Context.raw.drag_dest)) { - let color: i32 = Base.drag_swatch.base; - color = color_set_ab(color, Base.drag_swatch.opacity * 255); - Base.create_color_layer(color, Base.drag_swatch.occlusion, Base.drag_swatch.roughness, Base.drag_swatch.metallic, Context.raw.drag_dest); - } - ///end - - Base.drag_swatch = null; - } - else if (Base.drag_file != null) { - if (!Context.in_browser()) { - Base.drop_x = mouse_x; - Base.drop_y = mouse_y; - - ///if (is_paint || is_sculpt) - let materialCount: i32 = Project.materials.length; - ImportAsset.run(Base.drag_file, Base.drop_x, Base.drop_y, true, true, () => { - // Asset was material - if (Project.materials.length > materialCount) { - Base.drag_material = Context.raw.material; - Base.material_dropped(); - } - }); - ///end - - ///if is_lab - ImportAsset.run(Base.drag_file, Base.drop_x, Base.drop_y); - ///end - } - Base.drag_file = null; - Base.drag_file_icon = null; - } - ///if (is_paint || is_sculpt) - else if (Base.drag_material != null) { - Base.material_dropped(); - } - else if (Base.drag_layer != null) { - if (Context.in_nodes()) { - UINodes.accept_layer_drag(Project.layers.indexOf(Base.drag_layer)); - } - else if (Context.in_layers() && Base.is_dragging) { - SlotLayer.move(Base.drag_layer, Context.raw.drag_dest); - MakeMaterial.parse_mesh_material(); - } - Base.drag_layer = null; - } - ///end - - krom_set_mouse_cursor(0); // Arrow - Base.is_dragging = false; - } - if (Context.raw.color_picker_callback != null && (mouse_released() || mouse_released("right"))) { - Context.raw.color_picker_callback = null; - Context.select_tool(Context.raw.color_picker_previous_tool); - } - - Base.handle_drop_paths(); - - ///if (is_paint || is_sculpt) - ///if krom_windows - let isPicker: bool = Context.raw.tool == workspace_tool_t.PICKER || Context.raw.tool == workspace_tool_t.MATERIAL; - let decal: bool = Context.raw.tool == workspace_tool_t.DECAL || Context.raw.tool == workspace_tool_t.TEXT; - zui_set_always_redraw_window(!Context.raw.cache_draws || - UIMenu.show || - UIBox.show || - Base.is_dragging || - isPicker || - decal || - UIView2D.show || - !Config.raw.brush_3d || - Context.raw.frame < 3); - ///end - ///end - - if (zui_always_redraw_window() && Context.raw.ddirty < 0) Context.raw.ddirty = 0; - } - - ///if (is_paint || is_sculpt) - static material_dropped = () => { - // Material drag and dropped onto viewport or layers tab - if (Context.in_viewport()) { - let uvType: uv_type_t = keyboard_down("control") ? uv_type_t.PROJECT : uv_type_t.UVMAP; - let decalMat: mat4_t = uvType == uv_type_t.PROJECT ? UtilRender.get_decal_mat() : null; - Base.create_fill_layer(uvType, decalMat); - } - if (Context.in_layers() && TabLayers.can_drop_new_layer(Context.raw.drag_dest)) { - let uvType: uv_type_t = keyboard_down("control") ? uv_type_t.PROJECT : uv_type_t.UVMAP; - let decalMat: mat4_t = uvType == uv_type_t.PROJECT ? UtilRender.get_decal_mat() : null; - Base.create_fill_layer(uvType, decalMat, Context.raw.drag_dest); - } - else if (Context.in_nodes()) { - UINodes.accept_material_drag(Project.materials.indexOf(Base.drag_material)); - } - Base.drag_material = null; - } - ///end - - static handle_drop_paths = () => { - if (Base.drop_paths.length > 0) { - ///if (krom_linux || krom_darwin) - let wait: bool = !mouse_moved; // Mouse coords not updated during drag - ///else - let wait: bool = false; - ///end - if (!wait) { - Base.drop_x = mouse_x; - Base.drop_y = mouse_y; - let dropPath: string = Base.drop_paths.shift(); - ImportAsset.run(dropPath, Base.drop_x, Base.drop_y); - } - } - } - - ///if (is_paint || is_sculpt) - static get_drag_background = (): rect_t => { - let icons: image_t = Res.get("icons.k"); - if (Base.drag_layer != null && !SlotLayer.is_group(Base.drag_layer) && Base.drag_layer.fill_layer == null) { - return Res.tile50(icons, 4, 1); - } - return null; - } - ///end - - static get_drag_image = (): image_t => { - Base.drag_tint = 0xffffffff; - Base.drag_size = -1; - Base.drag_rect = null; - if (Base.drag_asset != null) { - return Project.get_image(Base.drag_asset); - } - if (Base.drag_swatch != null) { - Base.drag_tint = Base.drag_swatch.base; - Base.drag_size = 26; - return TabSwatches.empty; - } - if (Base.drag_file != null) { - if (Base.drag_file_icon != null) return Base.drag_file_icon; - let icons: image_t = Res.get("icons.k"); - Base.drag_rect = Base.drag_file.indexOf(".") > 0 ? Res.tile50(icons, 3, 1) : Res.tile50(icons, 2, 1); - Base.drag_tint = UIBase.ui.t.HIGHLIGHT_COL; - return icons; - } - - ///if is_paint - if (Base.drag_material != null) { - return Base.drag_material.image_icon; - } - if (Base.drag_layer != null && SlotLayer.is_group(Base.drag_layer)) { - let icons: image_t = Res.get("icons.k"); - let folderClosed: rect_t = Res.tile50(icons, 2, 1); - let folderOpen: rect_t = Res.tile50(icons, 8, 1); - Base.drag_rect = Base.drag_layer.show_panel ? folderOpen : folderClosed; - Base.drag_tint = UIBase.ui.t.LABEL_COL - 0x00202020; - return icons; - } - if (Base.drag_layer != null && SlotLayer.is_mask(Base.drag_layer) && Base.drag_layer.fill_layer == null) { - TabLayers.make_mask_preview_rgba32(Base.drag_layer); - return Context.raw.mask_preview_rgba32; - } - if (Base.drag_layer != null) { - return Base.drag_layer.fill_layer != null ? Base.drag_layer.fill_layer.image_icon : Base.drag_layer.texpaint_preview; - } - ///end - - return null; - } - - static render = () => { - if (sys_width() == 0 || sys_height() == 0) return; - - if (Context.raw.frame == 2) { - ///if (is_paint || is_sculpt) - UtilRender.make_material_preview(); - UIBase.hwnds[tab_area_t.SIDEBAR1].redraws = 2; - ///end - - MakeMaterial.parse_mesh_material(); - MakeMaterial.parse_paint_material(); - Context.raw.ddirty = 0; - - ///if (is_paint || is_sculpt) - if (History.undo_layers == null) { - History.undo_layers = []; - for (let i: i32 = 0; i < Config.raw.undo_steps; ++i) { - let l: SlotLayerRaw = SlotLayer.create("_undo" + History.undo_layers.length); - History.undo_layers.push(l); - } - } - ///end - - // Default workspace - if (Config.raw.workspace != 0) { - UIHeader.worktab.position = Config.raw.workspace; - UIMenubar.workspace_handle.redraws = 2; - UIHeader.worktab.changed = true; - } - - // Default camera controls - Context.raw.camera_controls = Config.raw.camera_controls; - - ///if is_lab - Base.notify_on_next_frame(() => { - Base.notify_on_next_frame(() => { - TabMeshes.set_default_mesh(".Sphere"); - }); - }); - ///end - - ///if is_sculpt - Base.notify_on_next_frame(() => { - Base.notify_on_next_frame(() => { - Context.raw.project_type = project_model_t.SPHERE; - Project.project_new(); - }); - }); - ///end - } - else if (Context.raw.frame == 3) { - Context.raw.ddirty = 3; - } - Context.raw.frame++; - - if (Base.is_dragging) { - krom_set_mouse_cursor(1); // Hand - let img: image_t = Base.get_drag_image(); - - ///if (is_paint || is_sculpt) - let scaleFactor: f32 = zui_SCALE(UIBase.ui); - ///end - ///if is_lab - let scaleFactor: f32 = zui_SCALE(Base.ui_box); - ///end - - let size: f32 = (Base.drag_size == -1 ? 50 : Base.drag_size) * scaleFactor; - let ratio: f32 = size / img.width; - let h: f32 = img.height * ratio; - - ///if (is_lab || krom_direct3d11 || krom_direct3d12 || krom_metal || krom_vulkan) - let inv: i32 = 0; - ///else - let inv: i32 = (Base.drag_material != null || (Base.drag_layer != null && Base.drag_layer.fill_layer != null)) ? h : 0; - ///end - - g2_set_color(Base.drag_tint); - - ///if (is_paint || is_sculpt) - let bgRect: rect_t = Base.get_drag_background(); - if (bgRect != null) { - g2_draw_scaled_sub_image(Res.get("icons.k"), bgRect.x, bgRect.y, bgRect.w, bgRect.h, mouse_x + Base.drag_off_x, mouse_y + Base.drag_off_y + inv, size, h - inv * 2); - } - ///end - - Base.drag_rect == null ? - g2_draw_scaled_image(img, mouse_x + Base.drag_off_x, mouse_y + Base.drag_off_y + inv, size, h - inv * 2) : - g2_draw_scaled_sub_image(img, Base.drag_rect.x, Base.drag_rect.y, Base.drag_rect.w, Base.drag_rect.h, mouse_x + Base.drag_off_x, mouse_y + Base.drag_off_y + inv, size, h - inv * 2); - g2_set_color(0xffffffff); - } - - let usingMenu: bool = UIMenu.show && mouse_y > UIHeader.headerh; - Base.ui_enabled = !UIBox.show && !usingMenu && !Base.is_combo_selected(); - if (UIBox.show) UIBox.render(); - if (UIMenu.show) UIMenu.render(); - - // Save last pos for continuos paint - Context.raw.last_paint_vec_x = Context.raw.paint_vec.x; - Context.raw.last_paint_vec_y = Context.raw.paint_vec.y; - - ///if (krom_android || krom_ios) - // No mouse move events for touch, re-init last paint position on touch start - if (!mouse_down()) { - Context.raw.last_paint_x = -1; - Context.raw.last_paint_y = -1; - } - ///end - } - - static enum_texts = (nodeType: string): string[] => { - ///if (is_paint || is_sculpt) - if (nodeType == "TEX_IMAGE") { - return Project.asset_names.length > 0 ? Project.asset_names : [""]; - } - if (nodeType == "LAYER" || nodeType == "LAYER_MASK") { - let layerNames: string[] = []; - for (let l of Project.layers) layerNames.push(l.name); - return layerNames; - } - if (nodeType == "MATERIAL") { - let materialNames: string[] = []; - for (let m of Project.materials) materialNames.push(m.canvas.name); - return materialNames; - } - ///end - - ///if is_lab - if (nodeType == "ImageTextureNode") { - return Project.asset_names.length > 0 ? Project.asset_names : [""]; - } - ///end - - return null; - } - - static get_asset_index = (fileName: string): i32 => { - let i: i32 = Project.asset_names.indexOf(fileName); - return i >= 0 ? i : 0; - } - - static notify_on_next_frame = (f: ()=>void) => { - let _render = () => { - app_notify_on_init(() => { - let _update = () => { - app_notify_on_init(f); - app_remove_update(_update); - } - app_notify_on_update(_update); - }); - app_remove_render(_render); - } - app_notify_on_render(_render); - } - - static toggle_fullscreen = () => { - if (sys_mode() == window_mode_t.WINDOWED) { - ///if (krom_windows || krom_linux || krom_darwin) - Config.raw.window_w = sys_width(); - Config.raw.window_h = sys_height(); - Config.raw.window_x = sys_x(); - Config.raw.window_y = sys_y(); - ///end - sys_mode_set(window_mode_t.FULLSCREEN); - } - else { - sys_mode_set(window_mode_t.WINDOWED); - sys_resize(Config.raw.window_w, Config.raw.window_h); - sys_move(Config.raw.window_x, Config.raw.window_y); - } - } - - static is_scrolling = (): bool => { - for (let ui of Base.get_uis()) if (ui.is_scrolling) return true; - return false; - } - - static is_combo_selected = (): bool => { - for (let ui of Base.get_uis()) if (ui.combo_selected_handle_ptr != 0) return true; - return false; - } - - static get_uis = (): zui_t[] => { - return [Base.ui_box, Base.ui_menu, UIBase.ui, UINodes.ui, UIView2D.ui]; - } - - static is_decal_layer = (): bool => { - ///if is_paint - let isPaint: bool = Context.raw.tool != workspace_tool_t.MATERIAL && Context.raw.tool != workspace_tool_t.BAKE; - return isPaint && Context.raw.layer.fill_layer != null && Context.raw.layer.uvType == uv_type_t.PROJECT; - ///end - - ///if (is_sculpt || is_lab) - return false; - ///end - } - - static redraw_status = () => { - UIBase.hwnds[tab_area_t.STATUS].redraws = 2; - } - - static redraw_console = () => { - let statush: i32 = Config.raw.layout[layout_size_t.STATUS_H]; - if (UIBase.ui != null && statush > UIStatus.default_status_h * zui_SCALE(UIBase.ui)) { - UIBase.hwnds[tab_area_t.STATUS].redraws = 2; - } - } - - static init_layout = () => { - let show2d: bool = (UINodes != null && UINodes.show) || (UIView2D != null && UIView2D.show); - - let raw: config_t = Config.raw; - raw.layout = [ - ///if (is_paint || is_sculpt) - Math.floor(UIBase.default_sidebar_w * raw.window_scale), // LayoutSidebarW - Math.floor(sys_height() / 2), // LayoutSidebarH0 - Math.floor(sys_height() / 2), // LayoutSidebarH1 - ///end - - ///if krom_ios - show2d ? Math.floor((app_w() + raw.layout[layout_size_t.NODES_W]) * 0.473) : Math.floor(app_w() * 0.473), // LayoutNodesW - ///elseif krom_android - show2d ? Math.floor((app_w() + raw.layout[layout_size_t.NODES_W]) * 0.473) : Math.floor(app_w() * 0.473), - ///else - show2d ? Math.floor((app_w() + raw.layout[layout_size_t.NODES_W]) * 0.515) : Math.floor(app_w() * 0.515), // Align with ui header controls - ///end - - Math.floor(app_h() / 2), // LayoutNodesH - Math.floor(UIStatus.default_status_h * raw.window_scale), // LayoutStatusH - - ///if (krom_android || krom_ios) - 0, // LayoutHeader - ///else - 1, - ///end - ]; - - raw.layout_tabs = [ - ///if (is_paint || is_sculpt) - 0, - 0, - ///end - 0 - ]; - } - - static init_config = () => { - let raw: config_t = Config.raw; - raw.recent_projects = []; - raw.bookmarks = []; - raw.plugins = []; - ///if (krom_android || krom_ios) - raw.keymap = "touch.json"; - ///else - raw.keymap = "default.json"; - ///end - raw.theme = "default.json"; - raw.server = "https://armorpaint.fra1.digitaloceanspaces.com"; - raw.undo_steps = 4; - raw.pressure_radius = true; - raw.pressure_sensitivity = 1.0; - raw.camera_zoom_speed = 1.0; - raw.camera_pan_speed = 1.0; - raw.camera_rotation_speed = 1.0; - raw.zoom_direction = zoom_direction_t.VERTICAL; - ///if (is_paint || is_sculpt) - raw.displace_strength = 0.0; - ///else - raw.displace_strength = 1.0; - ///end - raw.wrap_mouse = false; - ///if is_paint - raw.workspace = space_type_t.SPACE3D; - ///end - ///if is_sculpt - raw.workspace = space_type_t.SPACE3D; - ///end - ///if is_lab - raw.workspace = space_type_t.SPACE2D; - ///end - ///if (krom_android || krom_ios) - raw.camera_controls = camera_controls_t.ROTATE; - ///else - raw.camera_controls = camera_controls_t.ORBIT; - ///end - raw.layer_res = texture_res_t.RES2048; - ///if (krom_android || krom_ios) - raw.touch_ui = true; - raw.splash_screen = true; - ///else - raw.touch_ui = false; - raw.splash_screen = false; - ///end - ///if (is_paint || is_sculpt) - raw.node_preview = true; - ///else - raw.node_preview = false; - ///end - - ///if (is_paint || is_sculpt) - raw.pressure_hardness = true; - raw.pressure_angle = false; - raw.pressure_opacity = false; - ///if (krom_vulkan || krom_ios) - raw.material_live = false; - ///else - raw.material_live = true; - ///end - raw.brush_3d = true; - raw.brush_depth_reject = true; - raw.brush_angle_reject = true; - raw.brush_live = false; - raw.show_asset_names = false; - ///end - - ///if is_paint - raw.dilate = dilate_type_t.INSTANT; - raw.dilate_radius = 2; - ///end - - ///if is_lab - raw.gpu_inference = true; - ///end - } - - static init_layers = () => { - ///if (is_paint || is_sculpt) - SlotLayer.clear(Project.layers[0], color_from_floats(Base.default_base, Base.default_base, Base.default_base, 1.0)); - ///end - - ///if is_lab - let texpaint: image_t = render_path_render_targets.get("texpaint")._image; - let texpaint_nor: image_t = render_path_render_targets.get("texpaint_nor")._image; - let texpaint_pack: image_t = render_path_render_targets.get("texpaint_pack")._image; - g2_begin(texpaint); - g2_draw_scaled_image(Res.get("placeholder.k"), 0, 0, Config.get_texture_res_x(), Config.get_texture_res_y()); // Base - g2_end(); - g4_begin(texpaint_nor); - g4_clear(color_from_floats(0.5, 0.5, 1.0, 0.0)); // Nor - g4_end(); - g4_begin(texpaint_pack); - g4_clear(color_from_floats(1.0, 0.4, 0.0, 0.0)); // Occ, rough, met - g4_end(); - let texpaint_nor_empty: image_t = render_path_render_targets.get("texpaint_nor_empty")._image; - let texpaint_pack_empty: image_t = render_path_render_targets.get("texpaint_pack_empty")._image; - g4_begin(texpaint_nor_empty); - g4_clear(color_from_floats(0.5, 0.5, 1.0, 0.0)); // Nor - g4_end(); - g4_begin(texpaint_pack_empty); - g4_clear(color_from_floats(1.0, 0.4, 0.0, 0.0)); // Occ, rough, met - g4_end(); - ///end - } - - ///if (is_paint || is_sculpt) - static resize_layers = () => { - let C: config_t = Config.raw; - if (Base.res_handle.position >= Math.floor(texture_res_t.RES16384)) { // Save memory for >=16k - C.undo_steps = 1; - if (Context.raw.undo_handle != null) { - Context.raw.undo_handle.value = C.undo_steps; - } - while (History.undo_layers.length > C.undo_steps) { - let l: SlotLayerRaw = History.undo_layers.pop(); - Base.notify_on_next_frame(() => { - SlotLayer.unload(l); - }); - } - } - for (let l of Project.layers) SlotLayer.resize_and_set_bits(l); - for (let l of History.undo_layers) SlotLayer.resize_and_set_bits(l); - let rts: map_t = render_path_render_targets; - let _texpaint_blend0: image_t = rts.get("texpaint_blend0")._image; - Base.notify_on_next_frame(() => { - image_unload(_texpaint_blend0); - }); - rts.get("texpaint_blend0").width = Config.get_texture_res_x(); - rts.get("texpaint_blend0").height = Config.get_texture_res_y(); - rts.get("texpaint_blend0")._image = image_create_render_target(Config.get_texture_res_x(), Config.get_texture_res_y(), tex_format_t.R8); - let _texpaint_blend1: image_t = rts.get("texpaint_blend1")._image; - Base.notify_on_next_frame(() => { - image_unload(_texpaint_blend1); - }); - rts.get("texpaint_blend1").width = Config.get_texture_res_x(); - rts.get("texpaint_blend1").height = Config.get_texture_res_y(); - rts.get("texpaint_blend1")._image = image_create_render_target(Config.get_texture_res_x(), Config.get_texture_res_y(), tex_format_t.R8); - Context.raw.brush_blend_dirty = true; - if (rts.get("texpaint_blur") != null) { - let _texpaint_blur: image_t = rts.get("texpaint_blur")._image; - Base.notify_on_next_frame(() => { - image_unload(_texpaint_blur); - }); - let sizeX: f32 = Math.floor(Config.get_texture_res_x() * 0.95); - let sizeY: f32 = Math.floor(Config.get_texture_res_y() * 0.95); - rts.get("texpaint_blur").width = sizeX; - rts.get("texpaint_blur").height = sizeY; - rts.get("texpaint_blur")._image = image_create_render_target(sizeX, sizeY); - } - if (RenderPathPaint.liveLayer != null) SlotLayer.resize_and_set_bits(RenderPathPaint.liveLayer); - ///if (krom_direct3d12 || krom_vulkan || krom_metal) - RenderPathRaytrace.ready = false; // Rebuild baketex - ///end - Context.raw.ddirty = 2; - } - - static set_layer_bits = () => { - for (let l of Project.layers) SlotLayer.resize_and_set_bits(l); - for (let l of History.undo_layers) SlotLayer.resize_and_set_bits(l); - } - - static make_merge_pipe = (red: bool, green: bool, blue: bool, alpha: bool): pipeline_t => { - let pipe: pipeline_t = g4_pipeline_create(); - pipe.vertex_shader = sys_get_shader("pass.vert"); - pipe.fragment_shader = sys_get_shader("layer_merge.frag"); - let vs: vertex_struct_t = g4_vertex_struct_create(); - g4_vertex_struct_add(vs, "pos", vertex_data_t.F32_2X); - pipe.input_layout = [vs]; - pipe.color_write_masks_red = [red]; - pipe.color_write_masks_green = [green]; - pipe.color_write_masks_blue = [blue]; - pipe.color_write_masks_alpha = [alpha]; - g4_pipeline_compile(pipe); - return pipe; - } - ///end - - static make_pipe = () => { - ///if (is_paint || is_sculpt) - Base.pipe_merge = Base.make_merge_pipe(true, true, true, true); - Base.pipe_merge_r = Base.make_merge_pipe(true, false, false, false); - Base.pipe_merge_g = Base.make_merge_pipe(false, true, false, false); - Base.pipe_merge_b = Base.make_merge_pipe(false, false, true, false); - Base.pipe_merge_a = Base.make_merge_pipe(false, false, false, true); - Base.tex0 =g4_pipeline_get_tex_unit(Base.pipe_merge, "tex0"); // Always binding texpaint.a for blending - Base.tex1 =g4_pipeline_get_tex_unit(Base.pipe_merge, "tex1"); - Base.texmask =g4_pipeline_get_tex_unit(Base.pipe_merge, "texmask"); - Base.texa =g4_pipeline_get_tex_unit(Base.pipe_merge, "texa"); - Base.opac =g4_pipeline_get_const_loc(Base.pipe_merge, "opac"); - Base.blending =g4_pipeline_get_const_loc(Base.pipe_merge, "blending"); - ///end - - { - Base.pipe_copy = g4_pipeline_create(); - Base.pipe_copy.vertex_shader = sys_get_shader("layer_view.vert"); - Base.pipe_copy.fragment_shader = sys_get_shader("layer_copy.frag"); - let vs: vertex_struct_t = g4_vertex_struct_create(); - g4_vertex_struct_add(vs, "pos", vertex_data_t.F32_3X); - g4_vertex_struct_add(vs, "tex", vertex_data_t.F32_2X); - g4_vertex_struct_add(vs, "col", vertex_data_t.U8_4X_NORM); - Base.pipe_copy.input_layout = [vs]; - g4_pipeline_compile(Base.pipe_copy); - } - - { - Base.pipe_copyBGRA = g4_pipeline_create(); - Base.pipe_copyBGRA.vertex_shader = sys_get_shader("layer_view.vert"); - Base.pipe_copyBGRA.fragment_shader = sys_get_shader("layer_copy_bgra.frag"); - let vs: vertex_struct_t = g4_vertex_struct_create(); - g4_vertex_struct_add(vs, "pos", vertex_data_t.F32_3X); - g4_vertex_struct_add(vs, "tex", vertex_data_t.F32_2X); - g4_vertex_struct_add(vs, "col", vertex_data_t.U8_4X_NORM); - Base.pipe_copyBGRA.input_layout = [vs]; - g4_pipeline_compile(Base.pipe_copyBGRA); - } - - ///if (krom_metal || krom_vulkan || krom_direct3d12) - { - Base.pipe_copy8 = g4_pipeline_create(); - Base.pipe_copy8.vertex_shader = sys_get_shader("layer_view.vert"); - Base.pipe_copy8.fragment_shader = sys_get_shader("layer_copy.frag"); - let vs: vertex_struct_t = g4_vertex_struct_create(); - g4_vertex_struct_add(vs, "pos", vertex_data_t.F32_3X); - g4_vertex_struct_add(vs, "tex", vertex_data_t.F32_2X); - g4_vertex_struct_add(vs, "col", vertex_data_t.U8_4X_NORM); - Base.pipe_copy8.input_layout = [vs]; - Base.pipe_copy8.color_attachment_count = 1; - Base.pipe_copy8.color_attachments[0] = tex_format_t.R8; - g4_pipeline_compile(Base.pipe_copy8); - } - - { - Base.pipe_copy128 = g4_pipeline_create(); - Base.pipe_copy128.vertex_shader = sys_get_shader("layer_view.vert"); - Base.pipe_copy128.fragment_shader = sys_get_shader("layer_copy.frag"); - let vs: vertex_struct_t = g4_vertex_struct_create(); - g4_vertex_struct_add(vs, "pos", vertex_data_t.F32_3X); - g4_vertex_struct_add(vs, "tex", vertex_data_t.F32_2X); - g4_vertex_struct_add(vs, "col", vertex_data_t.U8_4X_NORM); - Base.pipe_copy128.input_layout = [vs]; - Base.pipe_copy128.color_attachment_count = 1; - Base.pipe_copy128.color_attachments[0] = tex_format_t.RGBA128; - g4_pipeline_compile(Base.pipe_copy128); - } - ///else - Base.pipe_copy8 = Base.pipe_copy; - Base.pipe_copy128 = Base.pipe_copy; - ///end - - ///if (is_paint || is_sculpt) - { - Base.pipe_invert8 = g4_pipeline_create(); - Base.pipe_invert8.vertex_shader = sys_get_shader("layer_view.vert"); - Base.pipe_invert8.fragment_shader = sys_get_shader("layer_invert.frag"); - let vs: vertex_struct_t = g4_vertex_struct_create(); - g4_vertex_struct_add(vs, "pos", vertex_data_t.F32_3X); - g4_vertex_struct_add(vs, "tex", vertex_data_t.F32_2X); - g4_vertex_struct_add(vs, "col", vertex_data_t.U8_4X_NORM); - Base.pipe_invert8.input_layout = [vs]; - Base.pipe_invert8.color_attachment_count = 1; - Base.pipe_invert8.color_attachments[0] = tex_format_t.R8; - g4_pipeline_compile(Base.pipe_invert8); - } - - { - Base.pipe_apply_mask = g4_pipeline_create(); - Base.pipe_apply_mask.vertex_shader = sys_get_shader("pass.vert"); - Base.pipe_apply_mask.fragment_shader = sys_get_shader("mask_apply.frag"); - let vs: vertex_struct_t = g4_vertex_struct_create(); - g4_vertex_struct_add(vs, "pos", vertex_data_t.F32_2X); - Base.pipe_apply_mask.input_layout = [vs]; - g4_pipeline_compile(Base.pipe_apply_mask); - Base.tex0_mask = g4_pipeline_get_tex_unit(Base.pipe_apply_mask, "tex0"); - Base.texa_mask = g4_pipeline_get_tex_unit(Base.pipe_apply_mask, "texa"); - } - - { - Base.pipe_merge_mask = g4_pipeline_create(); - Base.pipe_merge_mask.vertex_shader = sys_get_shader("pass.vert"); - Base.pipe_merge_mask.fragment_shader = sys_get_shader("mask_merge.frag"); - let vs: vertex_struct_t = g4_vertex_struct_create(); - g4_vertex_struct_add(vs, "pos", vertex_data_t.F32_2X); - Base.pipe_merge_mask.input_layout = [vs]; - g4_pipeline_compile(Base.pipe_merge_mask); - Base.tex0_merge_mask = g4_pipeline_get_tex_unit(Base.pipe_merge_mask, "tex0"); - Base.texa_merge_mask = g4_pipeline_get_tex_unit(Base.pipe_merge_mask, "texa"); - Base.opac_merge_mask = g4_pipeline_get_const_loc(Base.pipe_merge_mask, "opac"); - Base.blending_merge_mask = g4_pipeline_get_const_loc(Base.pipe_merge_mask, "blending"); - } - - { - Base.pipe_colorid_to_mask = g4_pipeline_create(); - Base.pipe_colorid_to_mask.vertex_shader = sys_get_shader("pass.vert"); - Base.pipe_colorid_to_mask.fragment_shader = sys_get_shader("mask_colorid.frag"); - let vs: vertex_struct_t = g4_vertex_struct_create(); - g4_vertex_struct_add(vs, "pos", vertex_data_t.F32_2X); - Base.pipe_colorid_to_mask.input_layout = [vs]; - g4_pipeline_compile(Base.pipe_colorid_to_mask); - Base.texpaint_colorid = g4_pipeline_get_tex_unit(Base.pipe_colorid_to_mask, "texpaint_colorid"); - Base.tex_colorid = g4_pipeline_get_tex_unit(Base.pipe_colorid_to_mask, "texcolorid"); - } - ///end - - ///if is_lab - { - Base.pipe_copy_r = g4_pipeline_create(); - Base.pipe_copy_r.vertex_shader = sys_get_shader("layer_view.vert"); - Base.pipe_copy_r.fragment_shader = sys_get_shader("layer_copy.frag"); - let vs: vertex_struct_t = g4_vertex_struct_create(); - g4_vertex_struct_add(vs, "pos", vertex_data_t.F32_3X); - g4_vertex_struct_add(vs, "tex", vertex_data_t.F32_2X); - g4_vertex_struct_add(vs, "col", vertex_data_t.U8_4X_NORM); - Base.pipe_copy_r.input_layout = [vs]; - Base.pipe_copy_r.color_write_masks_green = [false]; - Base.pipe_copy_r.color_write_masks_blue = [false]; - Base.pipe_copy_r.color_write_masks_alpha = [false]; - g4_pipeline_compile(Base.pipe_copy_r); - } - - { - Base.pipe_copy_g = g4_pipeline_create(); - Base.pipe_copy_g.vertex_shader = sys_get_shader("layer_view.vert"); - Base.pipe_copy_g.fragment_shader = sys_get_shader("layer_copy.frag"); - let vs: vertex_struct_t = g4_vertex_struct_create(); - g4_vertex_struct_add(vs, "pos", vertex_data_t.F32_3X); - g4_vertex_struct_add(vs, "tex", vertex_data_t.F32_2X); - g4_vertex_struct_add(vs, "col", vertex_data_t.U8_4X_NORM); - Base.pipe_copy_g.input_layout = [vs]; - Base.pipe_copy_g.color_write_masks_red = [false]; - Base.pipe_copy_g.color_write_masks_blue = [false]; - Base.pipe_copy_g.color_write_masks_alpha = [false]; - g4_pipeline_compile(Base.pipe_copy_g); - } - - { - Base.pipe_copy_b = g4_pipeline_create(); - Base.pipe_copy_b.vertex_shader = sys_get_shader("layer_view.vert"); - Base.pipe_copy_b.fragment_shader = sys_get_shader("layer_copy.frag"); - let vs: vertex_struct_t = g4_vertex_struct_create(); - g4_vertex_struct_add(vs, "pos", vertex_data_t.F32_3X); - g4_vertex_struct_add(vs, "tex", vertex_data_t.F32_2X); - g4_vertex_struct_add(vs, "col", vertex_data_t.U8_4X_NORM); - Base.pipe_copy_b.input_layout = [vs]; - Base.pipe_copy_b.color_write_masks_red = [false]; - Base.pipe_copy_b.color_write_masks_green = [false]; - Base.pipe_copy_b.color_write_masks_alpha = [false]; - g4_pipeline_compile(Base.pipe_copy_b); - } - - { - Base.pipe_inpaint_preview = g4_pipeline_create(); - Base.pipe_inpaint_preview.vertex_shader = sys_get_shader("pass.vert"); - Base.pipe_inpaint_preview.fragment_shader = sys_get_shader("inpaint_preview.frag"); - let vs: vertex_struct_t = g4_vertex_struct_create(); - g4_vertex_struct_add(vs, "pos", vertex_data_t.F32_2X); - Base.pipe_inpaint_preview.input_layout = [vs]; - g4_pipeline_compile(Base.pipe_inpaint_preview); - Base.tex0_inpaint_preview = g4_pipeline_get_tex_unit(Base.pipe_inpaint_preview, "tex0"); - Base.texa_inpaint_preview = g4_pipeline_get_tex_unit(Base.pipe_inpaint_preview, "texa"); - } - ///end - } - - static make_pipe_copy_rgb = () => { - Base.pipe_copyRGB = g4_pipeline_create(); - Base.pipe_copyRGB.vertex_shader = sys_get_shader("layer_view.vert"); - Base.pipe_copyRGB.fragment_shader = sys_get_shader("layer_copy.frag"); - let vs: vertex_struct_t = g4_vertex_struct_create(); - g4_vertex_struct_add(vs, "pos", vertex_data_t.F32_3X); - g4_vertex_struct_add(vs, "tex", vertex_data_t.F32_2X); - g4_vertex_struct_add(vs, "col", vertex_data_t.U8_4X_NORM); - Base.pipe_copyRGB.input_layout = [vs]; - Base.pipe_copyRGB.color_write_masks_alpha = [false]; - g4_pipeline_compile(Base.pipe_copyRGB); - } - - ///if is_lab - static make_pipe_copy_a = () => { - Base.pipe_copy_a = g4_pipeline_create(); - Base.pipe_copy_a.vertex_shader = sys_get_shader("pass.vert"); - Base.pipe_copy_a.fragment_shader = sys_get_shader("layer_copy_rrrr.frag"); - let vs: vertex_struct_t = g4_vertex_struct_create(); - g4_vertex_struct_add(vs, "pos", vertex_data_t.F32_2X); - Base.pipe_copy_a.input_layout = [vs]; - Base.pipe_copy_a.color_write_masks_red = [false]; - Base.pipe_copy_a.color_write_masks_green = [false]; - Base.pipe_copy_a.color_write_masks_blue = [false]; - g4_pipeline_compile(Base.pipe_copy_a); - Base.pipe_copy_a_tex = g4_pipeline_get_tex_unit(Base.pipe_copy_a, "tex"); - } - ///end - - static make_cursor_pipe = () => { - Base.pipe_cursor = g4_pipeline_create(); - Base.pipe_cursor.vertex_shader = sys_get_shader("cursor.vert"); - Base.pipe_cursor.fragment_shader = sys_get_shader("cursor.frag"); - let vs: vertex_struct_t = g4_vertex_struct_create(); - ///if (krom_metal || krom_vulkan) - g4_vertex_struct_add(vs, "tex", vertex_data_t.I16_2X_NORM); - ///else - g4_vertex_struct_add(vs, "pos", vertex_data_t.I16_4X_NORM); - g4_vertex_struct_add(vs, "nor", vertex_data_t.I16_2X_NORM); - g4_vertex_struct_add(vs, "tex", vertex_data_t.I16_2X_NORM); - ///end - Base.pipe_cursor.input_layout = [vs]; - Base.pipe_cursor.blend_source = blend_factor_t.SOURCE_ALPHA; - Base.pipe_cursor.blend_dest = blend_factor_t.INV_SOURCE_ALPHA; - Base.pipe_cursor.depth_write = false; - Base.pipe_cursor.depth_mode = compare_mode_t.ALWAYS; - g4_pipeline_compile(Base.pipe_cursor); - Base.cursor_vp = g4_pipeline_get_const_loc(Base.pipe_cursor, "VP"); - Base.cursor_inv_vp = g4_pipeline_get_const_loc(Base.pipe_cursor, "invVP"); - Base.cursor_mouse = g4_pipeline_get_const_loc(Base.pipe_cursor, "mouse"); - Base.cursor_tex_step = g4_pipeline_get_const_loc(Base.pipe_cursor, "texStep"); - Base.cursor_radius = g4_pipeline_get_const_loc(Base.pipe_cursor, "radius"); - Base.cursor_camera_right = g4_pipeline_get_const_loc(Base.pipe_cursor, "cameraRight"); - Base.cursor_tint = g4_pipeline_get_const_loc(Base.pipe_cursor, "tint"); - Base.cursor_gbufferd = g4_pipeline_get_tex_unit(Base.pipe_cursor, "gbufferD"); - Base.cursor_tex = g4_pipeline_get_tex_unit(Base.pipe_cursor, "tex"); - } - - static make_temp_img = () => { - ///if (is_paint || is_sculpt) - let l: SlotLayerRaw = Project.layers[0]; - ///end - ///if is_lab - let l: any = BrushOutputNode.inst; - ///end - - if (Base.temp_image != null && (Base.temp_image.width != l.texpaint.width || Base.temp_image.height != l.texpaint.height || Base.temp_image.format != l.texpaint.format)) { - let _temptex0: render_target_t = render_path_render_targets.get("temptex0"); - Base.notify_on_next_frame(() => { - render_target_unload(_temptex0); - }); - render_path_render_targets.delete("temptex0"); - Base.temp_image = null; - } - if (Base.temp_image == null) { - ///if (is_paint || is_sculpt) - let format: string = Base.bits_handle.position == texture_bits_t.BITS8 ? "RGBA32" : - Base.bits_handle.position == texture_bits_t.BITS16 ? "RGBA64" : - "RGBA128"; - ///end - ///if is_lab - let format: string = "RGBA32"; - ///end - - let t: render_target_t = render_target_create(); - t.name = "temptex0"; - t.width = l.texpaint.width; - t.height = l.texpaint.height; - t.format = format; - let rt: render_target_t = render_path_create_render_target(t); - Base.temp_image = rt._image; - } - } - - ///if (is_paint || is_sculpt) - static make_temp_mask_img = () => { - if (Base.temp_mask_image != null && (Base.temp_mask_image.width != Config.get_texture_res_x() || Base.temp_mask_image.height != Config.get_texture_res_y())) { - let _tempMaskImage: image_t = Base.temp_mask_image; - Base.notify_on_next_frame(() => { - image_unload(_tempMaskImage); - }); - Base.temp_mask_image = null; - } - if (Base.temp_mask_image == null) { - Base.temp_mask_image = image_create_render_target(Config.get_texture_res_x(), Config.get_texture_res_y(), tex_format_t.R8); - } - } - ///end - - static make_export_img = () => { - ///if (is_paint || is_sculpt) - let l: SlotLayerRaw = Project.layers[0]; - ///end - ///if is_lab - let l: any = BrushOutputNode.inst; - ///end - - if (Base.expa != null && (Base.expa.width != l.texpaint.width || Base.expa.height != l.texpaint.height || Base.expa.format != l.texpaint.format)) { - let _expa: image_t = Base.expa; - let _expb: image_t = Base.expb; - let _expc: image_t = Base.expc; - Base.notify_on_next_frame(() => { - image_unload(_expa); - image_unload(_expb); - image_unload(_expc); - }); - Base.expa = null; - Base.expb = null; - Base.expc = null; - render_path_render_targets.delete("expa"); - render_path_render_targets.delete("expb"); - render_path_render_targets.delete("expc"); - } - if (Base.expa == null) { - ///if (is_paint || is_sculpt) - let format: string = Base.bits_handle.position == texture_bits_t.BITS8 ? "RGBA32" : - Base.bits_handle.position == texture_bits_t.BITS16 ? "RGBA64" : - "RGBA128"; - ///end - ///if is_lab - let format: string = "RGBA32"; - ///end - - { - let t: render_target_t = render_target_create(); - t.name = "expa"; - t.width = l.texpaint.width; - t.height = l.texpaint.height; - t.format = format; - let rt: render_target_t = render_path_create_render_target(t); - Base.expa = rt._image; - } - - { - let t: render_target_t = render_target_create(); - t.name = "expb"; - t.width = l.texpaint.width; - t.height = l.texpaint.height; - t.format = format; - let rt: render_target_t = render_path_create_render_target(t); - Base.expb = rt._image; - } - - { - let t: render_target_t = render_target_create(); - t.name = "expc"; - t.width = l.texpaint.width; - t.height = l.texpaint.height; - t.format = format; - let rt: render_target_t = render_path_create_render_target(t); - Base.expc = rt._image; - } - } - } - - ///if (is_paint || is_sculpt) - static duplicate_layer = (l: SlotLayerRaw) => { - if (!SlotLayer.is_group(l)) { - let newLayer: SlotLayerRaw = SlotLayer.duplicate(l); - Context.set_layer(newLayer); - let masks: SlotLayerRaw[] = SlotLayer.get_masks(l, false); - if (masks != null) { - for (let m of masks) { - m = SlotLayer.duplicate(m); - m.parent = newLayer; - array_remove(Project.layers, m); - Project.layers.splice(Project.layers.indexOf(newLayer), 0, m); - } - } - Context.set_layer(newLayer); - } - else { - let newGroup: SlotLayerRaw = Base.new_group(); - array_remove(Project.layers, newGroup); - Project.layers.splice(Project.layers.indexOf(l) + 1, 0, newGroup); - // group.show_panel = true; - for (let c of SlotLayer.get_children(l)) { - let masks: SlotLayerRaw[] = SlotLayer.get_masks(c, false); - let newLayer: SlotLayerRaw = SlotLayer.duplicate(c); - newLayer.parent = newGroup; - array_remove(Project.layers, newLayer); - Project.layers.splice(Project.layers.indexOf(newGroup), 0, newLayer); - if (masks != null) { - for (let m of masks) { - let newMask: SlotLayerRaw = SlotLayer.duplicate(m); - newMask.parent = newLayer; - array_remove(Project.layers, newMask); - Project.layers.splice(Project.layers.indexOf(newLayer), 0, newMask); - } - } - } - let groupMasks: SlotLayerRaw[] = SlotLayer.get_masks(l); - if (groupMasks != null) { - for (let m of groupMasks) { - let newMask: SlotLayerRaw = SlotLayer.duplicate(m); - newMask.parent = newGroup; - array_remove(Project.layers, newMask); - Project.layers.splice(Project.layers.indexOf(newGroup), 0, newMask); - } - } - Context.set_layer(newGroup); - } - } - - static apply_masks = (l: SlotLayerRaw) => { - let masks: SlotLayerRaw[] = SlotLayer.get_masks(l); - - if (masks != null) { - for (let i: i32 = 0; i < masks.length - 1; ++i) { - Base.merge_layer(masks[i + 1], masks[i]); - SlotLayer.delete(masks[i]); - } - SlotLayer.apply_mask(masks[masks.length - 1]); - Context.raw.layer_preview_dirty = true; - } - } - - static merge_down = () => { - let l1: SlotLayerRaw = Context.raw.layer; - - if (SlotLayer.is_group(l1)) { - l1 = Base.merge_group(l1); - } - else if (SlotLayer.has_masks(l1)) { // It is a layer - Base.apply_masks(l1); - Context.set_layer(l1); - } - - let l0: SlotLayerRaw = Project.layers[Project.layers.indexOf(l1) - 1]; - - if (SlotLayer.is_group(l0)) { - l0 = Base.merge_group(l0); - } - else if (SlotLayer.has_masks(l0)) { // It is a layer - Base.apply_masks(l0); - Context.set_layer(l0); - } - - Base.merge_layer(l0, l1); - SlotLayer.delete(l1); - Context.set_layer(l0); - Context.raw.layer_preview_dirty = true; - } - - static merge_group = (l: SlotLayerRaw) => { - if (!SlotLayer.is_group(l)) return null; - - let children: SlotLayerRaw[] = SlotLayer.get_children(l); - - if (children.length == 1 && SlotLayer.has_masks(children[0], false)) { - Base.apply_masks(children[0]); - } - - for (let i: i32 = 0; i < children.length - 1; ++i) { - Context.set_layer(children[children.length - 1 - i]); - History.merge_layers(); - Base.merge_down(); - } - - // Now apply the group masks - let masks: SlotLayerRaw[] = SlotLayer.get_masks(l); - if (masks != null) { - for (let i: i32 = 0; i < masks.length - 1; ++i) { - Base.merge_layer(masks[i + 1], masks[i]); - SlotLayer.delete(masks[i]); - } - Base.apply_mask(children[0], masks[masks.length - 1]); - } - - children[0].parent = null; - children[0].name = l.name; - if (children[0].fill_layer != null) SlotLayer.to_paint_layer(children[0]); - SlotLayer.delete(l); - return children[0]; - } - - static merge_layer = (l0 : SlotLayerRaw, l1: SlotLayerRaw, use_mask: bool = false) => { - if (!l1.visible || SlotLayer.is_group(l1)) return; - - if (Base.pipe_merge == null) Base.make_pipe(); - Base.make_temp_img(); - if (const_data_screen_aligned_vb == null) const_data_create_screen_aligned_data(); - - g2_begin(Base.temp_image); // Copy to temp - g2_set_pipeline(Base.pipe_copy); - g2_draw_image(l0.texpaint, 0, 0); - g2_set_pipeline(null); - g2_end(); - - let empty: image_t = render_path_render_targets.get("empty_white")._image; - let mask: image_t = empty; - let l1masks: SlotLayerRaw[] = use_mask ? SlotLayer.get_masks(l1) : null; - if (l1masks != null) { - // for (let i: i32 = 1; i < l1masks.length - 1; ++i) { - // mergeLayer(l1masks[i + 1], l1masks[i]); - // } - mask = l1masks[0].texpaint; - } - - if (SlotLayer.is_mask(l1)) { - g4_begin(l0.texpaint); - g4_set_pipeline(Base.pipe_merge_mask); - g4_set_tex(Base.tex0_merge_mask, l1.texpaint); - g4_set_tex(Base.texa_merge_mask, Base.temp_image); - g4_set_float(Base.opac_merge_mask, SlotLayer.get_opacity(l1)); - g4_set_int(Base.blending_merge_mask, l1.blending); - g4_set_vertex_buffer(const_data_screen_aligned_vb); - g4_set_index_buffer(const_data_screen_aligned_ib); - g4_draw(); - g4_end(); - } - - if (SlotLayer.is_layer(l1)) { - if (l1.paintBase) { - g4_begin(l0.texpaint); - g4_set_pipeline(Base.pipe_merge); - g4_set_tex(Base.tex0, l1.texpaint); - g4_set_tex(Base.tex1, empty); - g4_set_tex(Base.texmask, mask); - g4_set_tex(Base.texa, Base.temp_image); - g4_set_float(Base.opac, SlotLayer.get_opacity(l1)); - g4_set_int(Base.blending, l1.blending); - g4_set_vertex_buffer(const_data_screen_aligned_vb); - g4_set_index_buffer(const_data_screen_aligned_ib); - g4_draw(); - g4_end(); - } - - ///if is_paint - g2_begin(Base.temp_image); - g2_set_pipeline(Base.pipe_copy); - g2_draw_image(l0.texpaint_nor, 0, 0); - g2_set_pipeline(null); - g2_end(); - - if (l1.paintNor) { - g4_begin(l0.texpaint_nor); - g4_set_pipeline(Base.pipe_merge); - g4_set_tex(Base.tex0, l1.texpaint); - g4_set_tex(Base.tex1, l1.texpaint_nor); - g4_set_tex(Base.texmask, mask); - g4_set_tex(Base.texa, Base.temp_image); - g4_set_float(Base.opac, SlotLayer.get_opacity(l1)); - g4_set_int(Base.blending, l1.paintNorBlend ? -2 : -1); - g4_set_vertex_buffer(const_data_screen_aligned_vb); - g4_set_index_buffer(const_data_screen_aligned_ib); - g4_draw(); - g4_end(); - } - - g2_begin(Base.temp_image); - g2_set_pipeline(Base.pipe_copy); - g2_draw_image(l0.texpaint_pack, 0, 0); - g2_set_pipeline(null); - g2_end(); - - if (l1.paintOcc || l1.paintRough || l1.paintMet || l1.paintHeight) { - if (l1.paintOcc && l1.paintRough && l1.paintMet && l1.paintHeight) { - Base.commands_merge_pack(Base.pipe_merge, l0.texpaint_pack, l1.texpaint, l1.texpaint_pack, SlotLayer.get_opacity(l1), mask, l1.paintHeightBlend ? -3 : -1); - } - else { - if (l1.paintOcc) Base.commands_merge_pack(Base.pipe_merge_r, l0.texpaint_pack, l1.texpaint, l1.texpaint_pack, SlotLayer.get_opacity(l1), mask); - if (l1.paintRough) Base.commands_merge_pack(Base.pipe_merge_g, l0.texpaint_pack, l1.texpaint, l1.texpaint_pack, SlotLayer.get_opacity(l1), mask); - if (l1.paintMet) Base.commands_merge_pack(Base.pipe_merge_b, l0.texpaint_pack, l1.texpaint, l1.texpaint_pack, SlotLayer.get_opacity(l1), mask); - } - } - ///end - } - } - - static flatten = (heightToNormal: bool = false, layers: SlotLayerRaw[] = null): any => { - if (layers == null) layers = Project.layers; - Base.make_temp_img(); - Base.make_export_img(); - if (Base.pipe_merge == null) Base.make_pipe(); - if (const_data_screen_aligned_vb == null) const_data_create_screen_aligned_data(); - let empty: image_t = render_path_render_targets.get("empty_white")._image; - - // Clear export layer - g4_begin(Base.expa); - g4_clear(color_from_floats(0.0, 0.0, 0.0, 0.0)); - g4_end(); - g4_begin(Base.expb); - g4_clear(color_from_floats(0.5, 0.5, 1.0, 0.0)); - g4_end(); - g4_begin(Base.expc); - g4_clear(color_from_floats(1.0, 0.0, 0.0, 0.0)); - g4_end(); - - // Flatten layers - for (let l1 of layers) { - if (!SlotLayer.is_visible(l1)) continue; - if (!SlotLayer.is_layer(l1)) continue; - - let mask: image_t = empty; - let l1masks: SlotLayerRaw[] = SlotLayer.get_masks(l1); - if (l1masks != null) { - if (l1masks.length > 1) { - Base.make_temp_mask_img(); - g2_begin(Base.temp_mask_image); - g2_clear(0x00000000); - g2_end(); - let l1: any = { texpaint: Base.temp_mask_image }; - for (let i: i32 = 0; i < l1masks.length; ++i) { - Base.merge_layer(l1, l1masks[i]); - } - mask = Base.temp_mask_image; - } - else mask = l1masks[0].texpaint; - } - - if (l1.paintBase) { - g2_begin(Base.temp_image); // Copy to temp - g2_set_pipeline(Base.pipe_copy); - g2_draw_image(Base.expa, 0, 0); - g2_set_pipeline(null); - g2_end(); - - g4_begin(Base.expa); - g4_set_pipeline(Base.pipe_merge); - g4_set_tex(Base.tex0, l1.texpaint); - g4_set_tex(Base.tex1, empty); - g4_set_tex(Base.texmask, mask); - g4_set_tex(Base.texa, Base.temp_image); - g4_set_float(Base.opac, SlotLayer.get_opacity(l1)); - g4_set_int(Base.blending, layers.length > 1 ? l1.blending : 0); - g4_set_vertex_buffer(const_data_screen_aligned_vb); - g4_set_index_buffer(const_data_screen_aligned_ib); - g4_draw(); - g4_end(); - } - - ///if is_paint - if (l1.paintNor) { - g2_begin(Base.temp_image); - g2_set_pipeline(Base.pipe_copy); - g2_draw_image(Base.expb, 0, 0); - g2_set_pipeline(null); - g2_end(); - - g4_begin(Base.expb); - g4_set_pipeline(Base.pipe_merge); - g4_set_tex(Base.tex0, l1.texpaint); - g4_set_tex(Base.tex1, l1.texpaint_nor); - g4_set_tex(Base.texmask, mask); - g4_set_tex(Base.texa, Base.temp_image); - g4_set_float(Base.opac, SlotLayer.get_opacity(l1)); - g4_set_int(Base.blending, l1.paintNorBlend ? -2 : -1); - g4_set_vertex_buffer(const_data_screen_aligned_vb); - g4_set_index_buffer(const_data_screen_aligned_ib); - g4_draw(); - g4_end(); - } - - if (l1.paintOcc || l1.paintRough || l1.paintMet || l1.paintHeight) { - g2_begin(Base.temp_image); - g2_set_pipeline(Base.pipe_copy); - g2_draw_image(Base.expc, 0, 0); - g2_set_pipeline(null); - g2_end(); - - if (l1.paintOcc && l1.paintRough && l1.paintMet && l1.paintHeight) { - Base.commands_merge_pack(Base.pipe_merge, Base.expc, l1.texpaint, l1.texpaint_pack, SlotLayer.get_opacity(l1), mask, l1.paintHeightBlend ? -3 : -1); - } - else { - if (l1.paintOcc) Base.commands_merge_pack(Base.pipe_merge_r, Base.expc, l1.texpaint, l1.texpaint_pack, SlotLayer.get_opacity(l1), mask); - if (l1.paintRough) Base.commands_merge_pack(Base.pipe_merge_g, Base.expc, l1.texpaint, l1.texpaint_pack, SlotLayer.get_opacity(l1), mask); - if (l1.paintMet) Base.commands_merge_pack(Base.pipe_merge_b, Base.expc, l1.texpaint, l1.texpaint_pack, SlotLayer.get_opacity(l1), mask); - } - } - ///end - } - - ///if krom_metal - // Flush command list - g2_begin(Base.expa); - g2_end(); - g2_begin(Base.expb); - g2_end(); - g2_begin(Base.expc); - g2_end(); - ///end - - let l0: any = { texpaint: Base.expa, texpaint_nor: Base.expb, texpaint_pack: Base.expc }; - - // Merge height map into normal map - if (heightToNormal && MakeMaterial.heightUsed) { - - g2_begin(Base.temp_image); - g2_set_pipeline(Base.pipe_copy); - g2_draw_image(l0.texpaint_nor, 0, 0); - g2_set_pipeline(null); - g2_end(); - - g4_begin(l0.texpaint_nor); - g4_set_pipeline(Base.pipe_merge); - g4_set_tex(Base.tex0, Base.temp_image); - g4_set_tex(Base.tex1, l0.texpaint_pack); - g4_set_tex(Base.texmask, empty); - g4_set_tex(Base.texa, empty); - g4_set_float(Base.opac, 1.0); - g4_set_int(Base.blending, -4); - g4_set_vertex_buffer(const_data_screen_aligned_vb); - g4_set_index_buffer(const_data_screen_aligned_ib); - g4_draw(); - g4_end(); - } - - return l0; - } - - static apply_mask = (l: SlotLayerRaw, m: SlotLayerRaw) => { - if (!SlotLayer.is_layer(l) || !SlotLayer.is_mask(m)) return; - - if (Base.pipe_merge == null) Base.make_pipe(); - Base.make_temp_img(); - - // Copy layer to temp - g2_begin(Base.temp_image); - g2_set_pipeline(Base.pipe_copy); - g2_draw_image(l.texpaint, 0, 0); - g2_set_pipeline(null); - g2_end(); - - // Apply mask - if (const_data_screen_aligned_vb == null) const_data_create_screen_aligned_data(); - g4_begin(l.texpaint); - g4_set_pipeline(Base.pipe_apply_mask); - g4_set_tex(Base.tex0_mask, Base.temp_image); - g4_set_tex(Base.texa_mask, m.texpaint); - g4_set_vertex_buffer(const_data_screen_aligned_vb); - g4_set_index_buffer(const_data_screen_aligned_ib); - g4_draw(); - g4_end(); - } - - static commands_merge_pack = (pipe: pipeline_t, i0: image_t, i1: image_t, i1pack: image_t, i1maskOpacity: f32, i1texmask: image_t, i1blending: i32 = -1) => { - g4_begin(i0); - g4_set_pipeline(pipe); - g4_set_tex(Base.tex0, i1); - g4_set_tex(Base.tex1, i1pack); - g4_set_tex(Base.texmask, i1texmask); - g4_set_tex(Base.texa, Base.temp_image); - g4_set_float(Base.opac, i1maskOpacity); - g4_set_int(Base.blending, i1blending); - g4_set_vertex_buffer(const_data_screen_aligned_vb); - g4_set_index_buffer(const_data_screen_aligned_ib); - g4_draw(); - g4_end(); - } - - static is_fill_material = (): bool => { - ///if is_paint - if (Context.raw.tool == workspace_tool_t.MATERIAL) return true; - ///end - - let m: SlotMaterialRaw = Context.raw.material; - for (let l of Project.layers) if (l.fill_layer == m) return true; - return false; - } - - static update_fill_layers = () => { - let _layer: SlotLayerRaw = Context.raw.layer; - let _tool: workspace_tool_t = Context.raw.tool; - let _fillType: i32 = Context.raw.fill_type_handle.position; - let current: image_t = null; - - ///if is_paint - if (Context.raw.tool == workspace_tool_t.MATERIAL) { - if (RenderPathPaint.liveLayer == null) { - RenderPathPaint.liveLayer = SlotLayer.create("_live"); - } - - current = _g2_current; - if (current != null) g2_end(); - - Context.raw.tool = workspace_tool_t.FILL; - Context.raw.fill_type_handle.position = fill_type_t.OBJECT; - MakeMaterial.parse_paint_material(false); - Context.raw.pdirty = 1; - RenderPathPaint.use_live_layer(true); - RenderPathPaint.commands_paint(false); - RenderPathPaint.dilate(true, true); - RenderPathPaint.use_live_layer(false); - Context.raw.tool = _tool; - Context.raw.fill_type_handle.position = _fillType; - Context.raw.pdirty = 0; - Context.raw.rdirty = 2; - - if (current != null) g2_begin(current); - return; - } - ///end - - let hasFillLayer: bool = false; - let hasFillMask: bool = false; - for (let l of Project.layers) if (SlotLayer.is_layer(l) && l.fill_layer == Context.raw.material) hasFillLayer = true; - for (let l of Project.layers) if (SlotLayer.is_mask(l) && l.fill_layer == Context.raw.material) hasFillMask = true; - - if (hasFillLayer || hasFillMask) { - current = _g2_current; - if (current != null) g2_end(); - Context.raw.pdirty = 1; - Context.raw.tool = workspace_tool_t.FILL; - Context.raw.fill_type_handle.position = fill_type_t.OBJECT; - - if (hasFillLayer) { - let first: bool = true; - for (let l of Project.layers) { - if (SlotLayer.is_layer(l) && l.fill_layer == Context.raw.material) { - Context.raw.layer = l; - if (first) { - first = false; - MakeMaterial.parse_paint_material(false); - } - Base.set_object_mask(); - SlotLayer.clear(l); - RenderPathPaint.commands_paint(false); - RenderPathPaint.dilate(true, true); - } - } - } - if (hasFillMask) { - let first: bool = true; - for (let l of Project.layers) { - if (SlotLayer.is_mask(l) && l.fill_layer == Context.raw.material) { - Context.raw.layer = l; - if (first) { - first = false; - MakeMaterial.parse_paint_material(false); - } - Base.set_object_mask(); - SlotLayer.clear(l); - RenderPathPaint.commands_paint(false); - RenderPathPaint.dilate(true, true); - } - } - } - - Context.raw.pdirty = 0; - Context.raw.ddirty = 2; - Context.raw.rdirty = 2; - Context.raw.layers_preview_dirty = true; // Repaint all layer previews as multiple layers might have changed. - if (current != null) g2_begin(current); - Context.raw.layer = _layer; - Base.set_object_mask(); - Context.raw.tool = _tool; - Context.raw.fill_type_handle.position = _fillType; - MakeMaterial.parse_paint_material(false); - } - } - - static update_fill_layer = (parse_paint: bool = true) => { - let current: image_t = _g2_current; - if (current != null) g2_end(); - - let _tool: workspace_tool_t = Context.raw.tool; - let _fillType: i32 = Context.raw.fill_type_handle.position; - Context.raw.tool = workspace_tool_t.FILL; - Context.raw.fill_type_handle.position = fill_type_t.OBJECT; - Context.raw.pdirty = 1; - - SlotLayer.clear(Context.raw.layer); - - if (parse_paint) MakeMaterial.parse_paint_material(false); - RenderPathPaint.commands_paint(false); - RenderPathPaint.dilate(true, true); - - Context.raw.rdirty = 2; - Context.raw.tool = _tool; - Context.raw.fill_type_handle.position = _fillType; - if (current != null) g2_begin(current); - } - - static set_object_mask = () => { - ///if is_sculpt - return; - ///end - - let ar: string[] = [tr("None")]; - for (let p of Project.paint_objects) ar.push(p.base.name); - - let mask: i32 = Context.object_mask_used() ? SlotLayer.get_object_mask(Context.raw.layer) : 0; - if (Context.layer_filter_used()) mask = Context.raw.layer_filter; - if (mask > 0) { - if (Context.raw.merged_object != null) { - Context.raw.merged_object.base.visible = false; - } - let o: mesh_object_t = Project.paint_objects[0]; - for (let p of Project.paint_objects) { - if (p.base.name == ar[mask]) { - o = p; - break; - } - } - Context.select_paint_object(o); - } - else { - let isAtlas: bool = SlotLayer.get_object_mask(Context.raw.layer) > 0 && SlotLayer.get_object_mask(Context.raw.layer) <= Project.paint_objects.length; - if (Context.raw.merged_object == null || isAtlas || Context.raw.merged_object_is_atlas) { - let visibles: mesh_object_t[] = isAtlas ? Project.get_atlas_objects(SlotLayer.get_object_mask(Context.raw.layer)) : null; - UtilMesh.merge_mesh(visibles); - } - Context.select_paint_object(Context.main_object()); - Context.raw.paint_object.skip_context = "paint"; - Context.raw.merged_object.base.visible = true; - } - UtilUV.dilatemap_cached = false; - } - - static new_layer = (clear: bool = true, position: i32 = -1): SlotLayerRaw => { - if (Project.layers.length > Base.max_layers) return null; - let l: SlotLayerRaw = SlotLayer.create(); - l.objectMask = Context.raw.layer_filter; - if (position == -1) { - if (SlotLayer.is_mask(Context.raw.layer)) Context.set_layer(Context.raw.layer.parent); - Project.layers.splice(Project.layers.indexOf(Context.raw.layer) + 1, 0, l); - } - else { - Project.layers.splice(position, 0, l); - } - - Context.set_layer(l); - let li: i32 = Project.layers.indexOf(Context.raw.layer); - if (li > 0) { - let below: SlotLayerRaw = Project.layers[li - 1]; - if (SlotLayer.is_layer(below)) { - Context.raw.layer.parent = below.parent; - } - } - if (clear) app_notify_on_init(() => { SlotLayer.clear(l); }); - Context.raw.layer_preview_dirty = true; - return l; - } - - static new_mask = (clear: bool = true, parent: SlotLayerRaw, position: i32 = -1): SlotLayerRaw => { - if (Project.layers.length > Base.max_layers) return null; - let l: SlotLayerRaw = SlotLayer.create("", layer_slot_type_t.MASK, parent); - if (position == -1) position = Project.layers.indexOf(parent); - Project.layers.splice(position, 0, l); - Context.set_layer(l); - if (clear) app_notify_on_init(() => { SlotLayer.clear(l); }); - Context.raw.layer_preview_dirty = true; - return l; - } - - static new_group = (): SlotLayerRaw => { - if (Project.layers.length > Base.max_layers) return null; - let l: SlotLayerRaw = SlotLayer.create("", layer_slot_type_t.GROUP); - Project.layers.push(l); - Context.set_layer(l); - return l; - } - - static create_fill_layer = (uvType: uv_type_t = uv_type_t.UVMAP, decalMat: mat4_t = null, position: i32 = -1) => { - let _init = () => { - let l: SlotLayerRaw = Base.new_layer(false, position); - History.new_layer(); - l.uvType = uvType; - if (decalMat != null) l.decalMat = decalMat; - l.objectMask = Context.raw.layer_filter; - History.to_fill_layer(); - SlotLayer.to_fill_layer(l); - } - app_notify_on_init(_init); - } - - static create_image_mask = (asset: asset_t) => { - let l: SlotLayerRaw = Context.raw.layer; - if (SlotLayer.is_mask(l) || SlotLayer.is_group(l)) { - return; - } - - History.new_layer(); - let m: SlotLayerRaw = Base.new_mask(false, l); - SlotLayer.clear(m, 0x00000000, Project.get_image(asset)); - Context.raw.layer_preview_dirty = true; - } - - static create_color_layer = (baseColor: i32, occlusion: f32 = 1.0, roughness: f32 = Base.default_rough, metallic: f32 = 0.0, position: i32 = -1) => { - let _init = () => { - let l: SlotLayerRaw = Base.new_layer(false, position); - History.new_layer(); - l.uvType = uv_type_t.UVMAP; - l.objectMask = Context.raw.layer_filter; - SlotLayer.clear(l, baseColor, null, occlusion, roughness, metallic); - } - app_notify_on_init(_init); - } - - static on_layers_resized = () => { - app_notify_on_init(() => { - Base.resize_layers(); - let _layer: SlotLayerRaw = Context.raw.layer; - let _material: SlotMaterialRaw = Context.raw.material; - for (let l of Project.layers) { - if (l.fill_layer != null) { - Context.raw.layer = l; - Context.raw.material = l.fill_layer; - Base.update_fill_layer(); - } - } - Context.raw.layer = _layer; - Context.raw.material = _material; - MakeMaterial.parse_paint_material(); - }); - UtilUV.uvmap = null; - UtilUV.uvmap_cached = false; - UtilUV.trianglemap = null; - UtilUV.trianglemap_cached = false; - UtilUV.dilatemap_cached = false; - ///if (krom_direct3d12 || krom_vulkan || krom_metal) - RenderPathRaytrace.ready = false; - ///end - } - ///end - - ///if is_lab - static flatten = (heightToNormal: bool = false): any => { - let texpaint: image_t = BrushOutputNode.inst.texpaint; - let texpaint_nor: image_t = BrushOutputNode.inst.texpaint_nor; - let texpaint_pack: image_t = BrushOutputNode.inst.texpaint_pack; - - let nodes: zui_nodes_t = UINodes.get_nodes(); - let canvas: zui_node_canvas_t = UINodes.get_canvas(true); - if (nodes.nodesSelectedId.length > 0) { - let node: zui_node_t = zui_get_node(canvas.nodes, nodes.nodesSelectedId[0]); - let brushNode: LogicNode = ParserLogic.get_logic_node(node); - if (brushNode != null && brushNode.get_cached_image() != null) { - texpaint = brushNode.get_cached_image(); - texpaint_nor = render_path_render_targets.get("texpaint_nor_empty")._image; - texpaint_pack = render_path_render_targets.get("texpaint_pack_empty")._image; - } - } - - return { texpaint: texpaint, texpaint_nor: texpaint_nor, texpaint_pack: texpaint_pack }; - } - - static on_layers_resized = () => { - image_unload(BrushOutputNode.inst.texpaint); - BrushOutputNode.inst.texpaint = render_path_render_targets.get("texpaint")._image = image_create_render_target(Config.get_texture_res_x(), Config.get_texture_res_y()); - image_unload(BrushOutputNode.inst.texpaint_nor); - BrushOutputNode.inst.texpaint_nor = render_path_render_targets.get("texpaint_nor")._image = image_create_render_target(Config.get_texture_res_x(), Config.get_texture_res_y()); - image_unload(BrushOutputNode.inst.texpaint_pack); - BrushOutputNode.inst.texpaint_pack = render_path_render_targets.get("texpaint_pack")._image = image_create_render_target(Config.get_texture_res_x(), Config.get_texture_res_y()); - - if (InpaintNode.image != null) { - image_unload(InpaintNode.image); - InpaintNode.image = null; - image_unload(InpaintNode.mask); - InpaintNode.mask = null; - InpaintNode.init(); - } - - if (PhotoToPBRNode.images != null) { - for (let image of PhotoToPBRNode.images) image_unload(image); - PhotoToPBRNode.images = null; - PhotoToPBRNode.init(); - } - - if (TilingNode.image != null) { - image_unload(TilingNode.image); - TilingNode.image = null; - TilingNode.init(); - } - - image_unload(render_path_render_targets.get("texpaint_blend0")._image); - render_path_render_targets.get("texpaint_blend0")._image = image_create_render_target(Config.get_texture_res_x(), Config.get_texture_res_y(), tex_format_t.R8); - image_unload(render_path_render_targets.get("texpaint_blend1")._image); - render_path_render_targets.get("texpaint_blend1")._image = image_create_render_target(Config.get_texture_res_x(), Config.get_texture_res_y(), tex_format_t.R8); - - if (render_path_render_targets.get("texpaint_node") != null) { - render_path_render_targets.delete("texpaint_node"); - } - if (render_path_render_targets.get("texpaint_node_target") != null) { - render_path_render_targets.delete("texpaint_node_target"); - } - - Base.notify_on_next_frame(() => { - Base.init_layers(); - }); - - ///if (krom_direct3d12 || krom_vulkan || krom_metal) - RenderPathRaytrace.ready = false; - ///end - } - ///end - - static default_keymap: any = { - action_paint: "left", - action_rotate: "alt+left", - action_pan: "alt+middle", - action_zoom: "alt+right", - rotate_light: "shift+middle", - rotate_envmap: "ctrl+middle", - set_clone_source: "alt", - stencil_transform: "ctrl", - stencil_hide: "z", - brush_radius: "f", - brush_radius_decrease: "[", - brush_radius_increase: "]", - brush_ruler: "shift", - file_new: "ctrl+n", - file_open: "ctrl+o", - file_open_recent: "ctrl+shift+o", - file_save: "ctrl+s", - file_save_as: "ctrl+shift+s", - file_reimport_mesh: "ctrl+r", - file_reimport_textures: "ctrl+shift+r", - file_import_assets: "ctrl+i", - file_export_textures: "ctrl+e", - file_export_textures_as: "ctrl+shift+e", - edit_undo: "ctrl+z", - edit_redo: "ctrl+shift+z", - edit_prefs: "ctrl+k", - view_reset: "0", - view_front: "1", - view_back: "ctrl+1", - view_right: "3", - view_left: "ctrl+3", - view_top: "7", - view_bottom: "ctrl+7", - view_camera_type: "5", - view_orbit_left: "4", - view_orbit_right: "6", - view_orbit_up: "8", - view_orbit_down: "2", - view_orbit_opposite: "9", - view_zoom_in: "", - view_zoom_out: "", - view_distract_free: "f11", - viewport_mode: "ctrl+m", - toggle_node_editor: "tab", - toggle_2d_view: "shift+tab", - toggle_browser: "`", - node_search: "space", - operator_search: "space", - ///if (is_paint || is_sculpt) - decal_mask: "ctrl", - select_material: "shift+number", - select_layer: "alt+number", - brush_opacity: "shift+f", - brush_angle: "alt+f", - tool_brush: "b", - tool_eraser: "e", - tool_fill: "g", - tool_decal: "d", - tool_text: "t", - tool_clone: "l", - tool_blur: "u", - tool_smudge: "m", - tool_particle: "p", - tool_colorid: "c", - tool_picker: "v", - tool_bake: "k", - tool_gizmo: "", - tool_material: "", - swap_brush_eraser: "", - ///end - }; -} diff --git a/base/Sources/BoxExport.ts b/base/Sources/BoxExport.ts index 89134722..fbad39af 100644 --- a/base/Sources/BoxExport.ts +++ b/base/Sources/BoxExport.ts @@ -60,71 +60,71 @@ class BoxExport { ///end ///if (is_paint || is_lab) - static tab_export_textures = (ui: zui_t, title: string, bakeMaterial: bool = false) => { - let tabVertical: bool = Config.raw.touch_ui; - if (zui_tab(BoxExport.htab, title, tabVertical)) { + static tab_export_textures = (ui: zui_t, title: string, bake_material: bool = false) => { + let tab_vertical: bool = Config.raw.touch_ui; + if (zui_tab(BoxExport.htab, title, tab_vertical)) { zui_row([0.5, 0.5]); ///if is_paint ///if (krom_android || krom_ios) - zui_combo(Base.res_handle, ["128", "256", "512", "1K", "2K", "4K"], tr("Resolution"), true); + zui_combo(base_res_handle, ["128", "256", "512", "1K", "2K", "4K"], tr("Resolution"), true); ///else - zui_combo(Base.res_handle, ["128", "256", "512", "1K", "2K", "4K", "8K", "16K"], tr("Resolution"), true); + zui_combo(base_res_handle, ["128", "256", "512", "1K", "2K", "4K", "8K", "16K"], tr("Resolution"), true); ///end ///end ///if is_lab ///if (krom_android || krom_ios) - zui_combo(Base.res_handle, ["2K", "4K"], tr("Resolution"), true); + zui_combo(base_res_handle, ["2K", "4K"], tr("Resolution"), true); ///else - zui_combo(Base.res_handle, ["2K", "4K", "8K", "16K"], tr("Resolution"), true); + zui_combo(base_res_handle, ["2K", "4K", "8K", "16K"], tr("Resolution"), true); ///end ///end - if (Base.res_handle.changed) { - Base.on_layers_resized(); + if (base_res_handle.changed) { + base_on_layers_resized(); } ///if (is_lab || krom_android || krom_ios) - zui_combo(Base.bits_handle, ["8bit"], tr("Color"), true); + zui_combo(base_bits_handle, ["8bit"], tr("Color"), true); ///else - zui_combo(Base.bits_handle, ["8bit", "16bit", "32bit"], tr("Color"), true); + zui_combo(base_bits_handle, ["8bit", "16bit", "32bit"], tr("Color"), true); ///end ///if is_paint - if (Base.bits_handle.changed) { - app_notify_on_init(Base.set_layer_bits); + if (base_bits_handle.changed) { + app_notify_on_init(base_set_layer_bits); } ///end zui_row([0.5, 0.5]); - if (Base.bits_handle.position == texture_bits_t.BITS8) { + if (base_bits_handle.position == texture_bits_t.BITS8) { Context.raw.format_type = zui_combo(zui_handle("boxexport_0", { position: Context.raw.format_type }), ["png", "jpg"], tr("Format"), true); } else { Context.raw.format_type = zui_combo(zui_handle("boxexport_1", { position: Context.raw.format_type }), ["exr"], tr("Format"), true); } - ui.enabled = Context.raw.format_type == texture_ldr_format_t.JPG && Base.bits_handle.position == texture_bits_t.BITS8; + ui.enabled = Context.raw.format_type == texture_ldr_format_t.JPG && base_bits_handle.position == texture_bits_t.BITS8; Context.raw.format_quality = zui_slider(zui_handle("boxexport_2", { value: Context.raw.format_quality }), tr("Quality"), 0.0, 100.0, true, 1); ui.enabled = true; ///if is_paint zui_row([0.5, 0.5]); - ui.enabled = !bakeMaterial; - let layersExportHandle: zui_handle_t = zui_handle("boxexport_3"); - layersExportHandle.position = Context.raw.layers_export; - Context.raw.layers_export = zui_combo(layersExportHandle, [tr("Visible"), tr("Selected"), tr("Per Object"), tr("Per Udim Tile")], tr("Layers"), true); + ui.enabled = !bake_material; + let layers_export_handle: zui_handle_t = zui_handle("boxexport_3"); + layers_export_handle.position = Context.raw.layers_export; + Context.raw.layers_export = zui_combo(layers_export_handle, [tr("Visible"), tr("Selected"), tr("Per Object"), tr("Per Udim Tile")], tr("Layers"), true); ui.enabled = true; ///end zui_combo(BoxExport.hpreset, BoxExport.files, tr("Preset"), true); if (BoxExport.hpreset.changed) BoxExport.preset = null; - let layersDestinationHandle: zui_handle_t = zui_handle("boxexport_4"); - layersDestinationHandle.position = Context.raw.layers_destination; - Context.raw.layers_destination = zui_combo(layersDestinationHandle, [tr("Disk"), tr("Packed")], tr("Destination"), true); + let layers_destination_handle: zui_handle_t = zui_handle("boxexport_4"); + layers_destination_handle.position = Context.raw.layers_destination; + Context.raw.layers_destination = zui_combo(layers_destination_handle, [tr("Disk"), tr("Packed")], tr("Destination"), true); zui_end_element(); @@ -138,7 +138,7 @@ class BoxExport { Context.raw.texture_export_path = "/"; let _init = () => { ///if is_paint - ExportTexture.run(Context.raw.texture_export_path, bakeMaterial); + ExportTexture.run(Context.raw.texture_export_path, bake_material); ///end ///if is_lab ExportTexture.run(Context.raw.texture_export_path); @@ -147,13 +147,13 @@ class BoxExport { app_notify_on_init(_init); } else { - let filters = Base.bits_handle.position != texture_bits_t.BITS8 ? "exr" : Context.raw.format_type == texture_ldr_format_t.PNG ? "png" : "jpg"; + let filters = base_bits_handle.position != texture_bits_t.BITS8 ? "exr" : Context.raw.format_type == texture_ldr_format_t.PNG ? "png" : "jpg"; UIFiles.show(filters, true, false, (path: string) => { Context.raw.texture_export_path = path; let doExport = () => { let _init = () => { ///if is_paint - ExportTexture.run(Context.raw.texture_export_path, bakeMaterial); + ExportTexture.run(Context.raw.texture_export_path, bake_material); ///end ///if is_lab ExportTexture.run(Context.raw.texture_export_path); @@ -162,9 +162,9 @@ class BoxExport { app_notify_on_init(_init); } ///if (krom_android || krom_ios) - Base.notify_on_next_frame(() => { + base_notify_on_next_frame(() => { Console.toast(tr("Exporting textures")); - Base.notify_on_next_frame(doExport); + base_notify_on_next_frame(doExport); }); ///else doExport(); @@ -177,8 +177,8 @@ class BoxExport { } static tab_presets = (ui: zui_t) => { - let tabVertical: bool = Config.raw.touch_ui; - if (zui_tab(BoxExport.htab, tr("Presets"), tabVertical)) { + let tab_vertical: bool = Config.raw.touch_ui; + if (zui_tab(BoxExport.htab, tr("Presets"), tab_vertical)) { zui_row([3 / 5, 1 / 5, 1 / 5]); zui_combo(BoxExport.hpreset, BoxExport.files, tr("Preset")); @@ -186,15 +186,15 @@ class BoxExport { if (zui_button(tr("New"))) { UIBox.show_custom((ui: zui_t) => { - let tabVertical: bool = Config.raw.touch_ui; - if (zui_tab(zui_handle("boxexport_5"), tr("New Preset"), tabVertical)) { + let tab_vertical: bool = Config.raw.touch_ui; + if (zui_tab(zui_handle("boxexport_5"), tr("New Preset"), tab_vertical)) { zui_row([0.5, 0.5]); - let presetName: string = zui_text_input(zui_handle("boxexport_6", { text: "new_preset" }), tr("Name")); + let preset_name: string = zui_text_input(zui_handle("boxexport_6", { text: "new_preset" }), tr("Name")); if (zui_button(tr("OK")) || ui.is_return_down) { - BoxExport.new_preset(presetName); + BoxExport.new_preset(preset_name); BoxExport.fetch_presets(); BoxExport.preset = null; - BoxExport.hpreset.position = BoxExport.files.indexOf(presetName); + BoxExport.hpreset.position = BoxExport.files.indexOf(preset_name); UIBox.hide(); BoxExport.htab.position = 1; // Presets BoxExport.show_textures(); @@ -208,8 +208,8 @@ class BoxExport { path = path.toLowerCase(); if (path.endsWith(".json")) { let filename: string = path.substr(path.lastIndexOf(Path.sep) + 1); - let dstPath: string = Path.data() + Path.sep + "export_presets" + Path.sep + filename; - File.copy(path, dstPath); // Copy to presets folder + let dst_path: string = Path.data() + Path.sep + "export_presets" + Path.sep + filename; + File.copy(path, dst_path); // Copy to presets folder BoxExport.fetch_presets(); BoxExport.preset = null; BoxExport.hpreset.position = BoxExport.files.indexOf(filename.substr(0, filename.length - 5)); // Strip .json @@ -290,8 +290,8 @@ class BoxExport { ///if is_paint static tab_atlases = (ui: zui_t) => { - let tabVertical: bool = Config.raw.touch_ui; - if (zui_tab(BoxExport.htab, tr("Atlases"), tabVertical)) { + let tab_vertical: bool = Config.raw.touch_ui; + if (zui_tab(BoxExport.htab, tr("Atlases"), tab_vertical)) { if (Project.atlas_objects == null || Project.atlas_objects.length != Project.paint_objects.length) { Project.atlas_objects = []; Project.atlas_names = []; @@ -320,8 +320,8 @@ class BoxExport { } static tab_export_mesh = (ui: zui_t, htab: zui_handle_t) => { - let tabVertical: bool = Config.raw.touch_ui; - if (zui_tab(htab, tr("Export Mesh"), tabVertical)) { + let tab_vertical: bool = Config.raw.touch_ui; + if (zui_tab(htab, tr("Export Mesh"), tab_vertical)) { zui_row([1 / 2, 1 / 2]); @@ -331,12 +331,12 @@ class BoxExport { for (let p of Project.paint_objects) ar.push(p.base.name); zui_combo(BoxExport.export_mesh_handle, ar, tr("Meshes"), true); - let applyDisplacement: bool = zui_check(zui_handle("boxexport_10"), tr("Apply Displacement")); + let apply_displacement: bool = zui_check(zui_handle("boxexport_10"), tr("Apply Displacement")); let tris: i32 = 0; let pos: i32 = BoxExport.export_mesh_handle.position; - let paintObjects: mesh_object_t[] = pos == 0 ? Project.paint_objects : [Project.paint_objects[pos - 1]]; - for (let po of paintObjects) { + let paint_objects: mesh_object_t[] = pos == 0 ? Project.paint_objects : [Project.paint_objects[pos - 1]]; + for (let po of paint_objects) { for (let inda of po.data.index_arrays) { tris += Math.floor(inda.values.length / 3); } @@ -357,12 +357,12 @@ class BoxExport { ///end if (f == "") f = tr("untitled"); let doExport = () => { - ExportMesh.run(path + Path.sep + f, BoxExport.export_mesh_handle.position == 0 ? null : [Project.paint_objects[BoxExport.export_mesh_handle.position - 1]], applyDisplacement); + ExportMesh.run(path + Path.sep + f, BoxExport.export_mesh_handle.position == 0 ? null : [Project.paint_objects[BoxExport.export_mesh_handle.position - 1]], apply_displacement); } ///if (krom_android || krom_ios) - Base.notify_on_next_frame(() => { + base_notify_on_next_frame(() => { Console.toast(tr("Exporting mesh")); - Base.notify_on_next_frame(doExport); + base_notify_on_next_frame(doExport); }); ///else doExport(); @@ -376,8 +376,8 @@ class BoxExport { static show_material = () => { UIBox.show_custom((ui: zui_t) => { let htab: zui_handle_t = zui_handle("boxexport_11"); - let tabVertical: bool = Config.raw.touch_ui; - if (zui_tab(htab, tr("Export Material"), tabVertical)) { + let tab_vertical: bool = Config.raw.touch_ui; + if (zui_tab(htab, tr("Export Material"), tab_vertical)) { let h1: zui_handle_t = zui_handle("boxexport_12"); let h2: zui_handle_t = zui_handle("boxexport_13"); h1.selected = Context.raw.pack_assets_on_export; @@ -405,8 +405,8 @@ class BoxExport { static show_brush = () => { UIBox.show_custom((ui: zui_t) => { let htab: zui_handle_t = zui_handle("boxexport_14"); - let tabVertical: bool = Config.raw.touch_ui; - if (zui_tab(htab, tr("Export Brush"), tabVertical)) { + let tab_vertical: bool = Config.raw.touch_ui; + if (zui_tab(htab, tr("Export Brush"), tab_vertical)) { let h1: zui_handle_t = zui_handle("boxexport_15"); let h2: zui_handle_t = zui_handle("boxexport_16"); h1.selected = Context.raw.pack_assets_on_export; diff --git a/base/Sources/BoxPreferences.ts b/base/Sources/BoxPreferences.ts index 0a167952..fc60451d 100644 --- a/base/Sources/BoxPreferences.ts +++ b/base/Sources/BoxPreferences.ts @@ -19,12 +19,12 @@ class BoxPreferences { BoxPreferences.locales = Translator.get_supported_locales(); } - let localeHandle: zui_handle_t = zui_handle("boxpreferences_0", { position: BoxPreferences.locales.indexOf(Config.raw.locale) }); - zui_combo(localeHandle, BoxPreferences.locales, tr("Language"), true); - if (localeHandle.changed) { - let localeCode: string = BoxPreferences.locales[localeHandle.position]; - Config.raw.locale = localeCode; - Translator.load_translations(localeCode); + let locale_handle: zui_handle_t = zui_handle("boxpreferences_0", { position: BoxPreferences.locales.indexOf(Config.raw.locale) }); + zui_combo(locale_handle, BoxPreferences.locales, tr("Language"), true); + if (locale_handle.changed) { + let locale_code: string = BoxPreferences.locales[locale_handle.position]; + Config.raw.locale = locale_code; + Translator.load_translations(locale_code); UIBase.tag_ui_redraw(); } @@ -47,10 +47,10 @@ class BoxPreferences { hspeed = zui_handle("boxpreferences_4", { value: Config.raw.camera_pan_speed }); Config.raw.camera_pan_speed = zui_slider(hspeed, tr("Camera Pan Speed"), 0.1, 4.0, true); - let zoomDirectionHandle: zui_handle_t = zui_handle("boxpreferences_5", { position: Config.raw.zoom_direction }); - zui_combo(zoomDirectionHandle, [tr("Vertical"), tr("Vertical Inverted"), tr("Horizontal"), tr("Horizontal Inverted"), tr("Vertical and Horizontal"), tr("Vertical and Horizontal Inverted")], tr("Direction to Zoom"), true); - if (zoomDirectionHandle.changed) { - Config.raw.zoom_direction = zoomDirectionHandle.position; + let zoom_direction_handle: zui_handle_t = zui_handle("boxpreferences_5", { position: Config.raw.zoom_direction }); + zui_combo(zoom_direction_handle, [tr("Vertical"), tr("Vertical Inverted"), tr("Horizontal"), tr("Horizontal Inverted"), tr("Vertical and Horizontal"), tr("Vertical and Horizontal Inverted")], tr("Direction to Zoom"), true); + if (zoom_direction_handle.changed) { + Config.raw.zoom_direction = zoom_direction_handle.position; } Config.raw.wrap_mouse = zui_check(zui_handle("boxpreferences_6", { selected: Config.raw.wrap_mouse }), tr("Wrap Mouse")); @@ -80,7 +80,7 @@ class BoxPreferences { Config.raw.splash_screen = zui_check(zui_handle("boxpreferences_10", { selected: Config.raw.splash_screen }), tr("Splash Screen")); // Zui.text("Node Editor"); - // let gridSnap: bool = Zui.check(Zui.handle("boxpreferences_11", { selected: false }), "Grid Snap"); + // let grid_snap: bool = Zui.check(Zui.handle("boxpreferences_11", { selected: false }), "Grid Snap"); zui_end_element(); zui_row([0.5, 0.5]); @@ -88,7 +88,7 @@ class BoxPreferences { UIMenu.draw((ui: zui_t) => { if (UIMenu.menu_button(ui, tr("Confirm"))) { app_notify_on_init(() => { - ui.t.ELEMENT_H = Base.default_element_h; + ui.t.ELEMENT_H = base_default_element_h; Config.restore(); BoxPreferences.set_scale(); if (BoxPreferences.files_plugin != null) for (let f of BoxPreferences.files_plugin) Plugin.stop(f); @@ -103,7 +103,7 @@ class BoxPreferences { let b: ArrayBuffer = data_get_blob(path); let raw: config_t = JSON.parse(sys_buffer_to_string(b)); app_notify_on_init(() => { - ui.t.ELEMENT_H = Base.default_element_h; + ui.t.ELEMENT_H = base_default_element_h; Config.import_from(raw); BoxPreferences.set_scale(); MakeMaterial.parse_mesh_material(); @@ -116,7 +116,7 @@ class BoxPreferences { if (zui_button(tr("Reset Layout")) && !UIMenu.show) { UIMenu.draw((ui: zui_t) => { if (UIMenu.menu_button(ui, tr("Confirm"))) { - Base.init_layout(); + base_init_layout(); Config.save(); } }, 1); @@ -143,14 +143,14 @@ class BoxPreferences { UIBox.show_custom((ui: zui_t) => { if (zui_tab(zui_handle("boxpreferences_13"), tr("New Theme"))) { zui_row([0.5, 0.5]); - let themeName: string = zui_text_input(zui_handle("boxpreferences_14", { text: "new_theme" }), tr("Name")); + let theme_name: string = zui_text_input(zui_handle("boxpreferences_14", { text: "new_theme" }), tr("Name")); if (zui_button(tr("OK")) || ui.is_return_down) { - let template: string = JSON.stringify(Base.theme); - if (!themeName.endsWith(".json")) themeName += ".json"; - let path: string = Path.data() + Path.sep + "themes" + Path.sep + themeName; + let template: string = JSON.stringify(base_theme); + if (!theme_name.endsWith(".json")) theme_name += ".json"; + let path: string = Path.data() + Path.sep + "themes" + Path.sep + theme_name; krom_file_save_bytes(path, sys_string_to_buffer(template)); BoxPreferences.fetch_themes(); // Refresh file list - Config.raw.theme = themeName; + Config.raw.theme = theme_name; BoxPreferences.theme_handle.position = BoxPreferences.get_theme_index(); UIBox.hide(); BoxPreferences.htab.position = 1; // Themes @@ -170,14 +170,14 @@ class BoxPreferences { UIFiles.show("json", true, false, (path: string) => { path += Path.sep + UIFiles.filename; if (!path.endsWith(".json")) path += ".json"; - krom_file_save_bytes(path, sys_string_to_buffer(JSON.stringify(Base.theme))); + krom_file_save_bytes(path, sys_string_to_buffer(JSON.stringify(base_theme))); }); } zui_end_sticky(); let i: i32 = 0; - let theme: any = Base.theme; + let theme: any = base_theme; let hlist: zui_handle_t = zui_handle("boxpreferences_15"); // Viewport color @@ -256,7 +256,7 @@ class BoxPreferences { } if (ui.changed) { - for (let ui of Base.get_uis()) { + for (let ui of base_get_uis()) { ui.elements_baked = false; } } @@ -292,81 +292,81 @@ class BoxPreferences { Config.raw.dilate_radius = Math.floor(zui_slider(zui_handle("boxpreferences_17", { value: Config.raw.dilate_radius }), tr("Dilate Radius"), 0.0, 16.0, true, 1)); if (ui.is_hovered) zui_tooltip(tr("Dilate painted textures to prevent seams")); - let dilateHandle: zui_handle_t = zui_handle("boxpreferences_18", { position: Config.raw.dilate }); - zui_combo(dilateHandle, [tr("Instant"), tr("Delayed")], tr("Dilate"), true); - if (dilateHandle.changed) { - Config.raw.dilate = dilateHandle.position; + let dilate_handle: zui_handle_t = zui_handle("boxpreferences_18", { position: Config.raw.dilate }); + zui_combo(dilate_handle, [tr("Instant"), tr("Delayed")], tr("Dilate"), true); + if (dilate_handle.changed) { + Config.raw.dilate = dilate_handle.position; } ///end ///if is_lab - let workspaceHandle: zui_handle_t = zui_handle("boxpreferences_19", { position: Config.raw.workspace }); - zui_combo(workspaceHandle, [tr("3D View"), tr("2D View")], tr("Default Workspace"), true); - if (workspaceHandle.changed) { - Config.raw.workspace = workspaceHandle.position; + let workspace_handle: zui_handle_t = zui_handle("boxpreferences_19", { position: Config.raw.workspace }); + zui_combo(workspace_handle, [tr("3D View"), tr("2D View")], tr("Default Workspace"), true); + if (workspace_handle.changed) { + Config.raw.workspace = workspace_handle.position; } ///end - let cameraControlsHandle: zui_handle_t = zui_handle("boxpreferences_20", { position: Config.raw.camera_controls }); - zui_combo(cameraControlsHandle, [tr("Orbit"), tr("Rotate"), tr("Fly")], tr("Default Camera Controls"), true); - if (cameraControlsHandle.changed) { - Config.raw.camera_controls = cameraControlsHandle.position; + let camera_controls_handle: zui_handle_t = zui_handle("boxpreferences_20", { position: Config.raw.camera_controls }); + zui_combo(camera_controls_handle, [tr("Orbit"), tr("Rotate"), tr("Fly")], tr("Default Camera Controls"), true); + if (camera_controls_handle.changed) { + Config.raw.camera_controls = camera_controls_handle.position; } - let layerResHandle: zui_handle_t = zui_handle("boxpreferences_21", { position: Config.raw.layer_res }); + let layer_res_handle: zui_handle_t = zui_handle("boxpreferences_21", { position: Config.raw.layer_res }); ///if is_paint ///if (krom_android || krom_ios) - zui_combo(layerResHandle, ["128", "256", "512", "1K", "2K", "4K"], tr("Default Layer Resolution"), true); + zui_combo(layer_res_handle, ["128", "256", "512", "1K", "2K", "4K"], tr("Default Layer Resolution"), true); ///else - zui_combo(layerResHandle, ["128", "256", "512", "1K", "2K", "4K", "8K"], tr("Default Layer Resolution"), true); + zui_combo(layer_res_handle, ["128", "256", "512", "1K", "2K", "4K", "8K"], tr("Default Layer Resolution"), true); ///end ///end ///if is_lab ///if (krom_android || krom_ios) - zui_combo(layerResHandle, ["2K", "4K"], tr("Default Layer Resolution"), true); + zui_combo(layer_res_handle, ["2K", "4K"], tr("Default Layer Resolution"), true); ///else - zui_combo(layerResHandle, ["2K", "4K", "8K", "16K"], tr("Default Layer Resolution"), true); + zui_combo(layer_res_handle, ["2K", "4K", "8K", "16K"], tr("Default Layer Resolution"), true); ///end ///end - if (layerResHandle.changed) { - Config.raw.layer_res = layerResHandle.position; + if (layer_res_handle.changed) { + Config.raw.layer_res = layer_res_handle.position; } - let serverHandle: zui_handle_t = zui_handle("boxpreferences_22", { text: Config.raw.server }); - Config.raw.server = zui_text_input(serverHandle, tr("Cloud Server")); + let server_handle: zui_handle_t = zui_handle("boxpreferences_22", { text: Config.raw.server }); + Config.raw.server = zui_text_input(server_handle, tr("Cloud Server")); ///if (is_paint || is_sculpt) - let materialLiveHandle: zui_handle_t = zui_handle("boxpreferences_23", {selected: Config.raw.material_live }); - Config.raw.material_live = zui_check(materialLiveHandle, tr("Live Material Preview")); + let material_live_handle: zui_handle_t = zui_handle("boxpreferences_23", {selected: Config.raw.material_live }); + Config.raw.material_live = zui_check(material_live_handle, tr("Live Material Preview")); if (ui.is_hovered) zui_tooltip(tr("Instantly update material preview on node change")); - let brushLiveHandle: zui_handle_t = zui_handle("boxpreferences_24", { selected: Config.raw.brush_live }); - Config.raw.brush_live = zui_check(brushLiveHandle, tr("Live Brush Preview")); + let brush_live_handle: zui_handle_t = zui_handle("boxpreferences_24", { selected: Config.raw.brush_live }); + Config.raw.brush_live = zui_check(brush_live_handle, tr("Live Brush Preview")); if (ui.is_hovered) zui_tooltip(tr("Draw live brush preview in viewport")); - if (brushLiveHandle.changed) Context.raw.ddirty = 2; + if (brush_live_handle.changed) Context.raw.ddirty = 2; - let brush3dHandle: zui_handle_t = zui_handle("boxpreferences_25", { selected: Config.raw.brush_3d }); - Config.raw.brush_3d = zui_check(brush3dHandle, tr("3D Cursor")); - if (brush3dHandle.changed) MakeMaterial.parse_paint_material(); + let brush_3d_handle: zui_handle_t = zui_handle("boxpreferences_25", { selected: Config.raw.brush_3d }); + Config.raw.brush_3d = zui_check(brush_3d_handle, tr("3D Cursor")); + if (brush_3d_handle.changed) MakeMaterial.parse_paint_material(); ui.enabled = Config.raw.brush_3d; - let brushDepthRejectHandle: zui_handle_t = zui_handle("boxpreferences_26", { selected: Config.raw.brush_depth_reject }); - Config.raw.brush_depth_reject = zui_check(brushDepthRejectHandle, tr("Depth Reject")); - if (brushDepthRejectHandle.changed) MakeMaterial.parse_paint_material(); + let brush_depth_reject_handle: zui_handle_t = zui_handle("boxpreferences_26", { selected: Config.raw.brush_depth_reject }); + Config.raw.brush_depth_reject = zui_check(brush_depth_reject_handle, tr("Depth Reject")); + if (brush_depth_reject_handle.changed) MakeMaterial.parse_paint_material(); zui_row([0.5, 0.5]); - let brushAngleRejectHandle: zui_handle_t = zui_handle("boxpreferences_27", { selected: Config.raw.brush_angle_reject }); - Config.raw.brush_angle_reject = zui_check(brushAngleRejectHandle, tr("Angle Reject")); - if (brushAngleRejectHandle.changed) MakeMaterial.parse_paint_material(); + let brush_angle_reject_handle: zui_handle_t = zui_handle("boxpreferences_27", { selected: Config.raw.brush_angle_reject }); + Config.raw.brush_angle_reject = zui_check(brush_angle_reject_handle, tr("Angle Reject")); + if (brush_angle_reject_handle.changed) MakeMaterial.parse_paint_material(); if (!Config.raw.brush_angle_reject) ui.enabled = false; - let angleDotHandle: zui_handle_t = zui_handle("boxpreferences_28", { value: Context.raw.brush_angle_reject_dot }); - Context.raw.brush_angle_reject_dot = zui_slider(angleDotHandle, tr("Angle"), 0.0, 1.0, true); - if (angleDotHandle.changed) { + let angle_dot_handle: zui_handle_t = zui_handle("boxpreferences_28", { value: Context.raw.brush_angle_reject_dot }); + Context.raw.brush_angle_reject_dot = zui_slider(angle_dot_handle, tr("Angle"), 0.0, 1.0, true); + if (angle_dot_handle.changed) { MakeMaterial.parse_paint_material(); } ui.enabled = true; @@ -378,14 +378,14 @@ class BoxPreferences { ///end } - let penName: string; + let pen_name: string; ///if krom_ios - penName = tr("Pencil"); + pen_name = tr("Pencil"); ///else - penName = tr("Pen"); + pen_name = tr("Pen"); ///end - if (zui_tab(BoxPreferences.htab, penName, true)) { + if (zui_tab(BoxPreferences.htab, pen_name, true)) { zui_text(tr("Pressure controls")); Config.raw.pressure_radius = zui_check(zui_handle("boxpreferences_30", { selected: Config.raw.pressure_radius }), tr("Brush Radius")); Config.raw.pressure_sensitivity = zui_slider(zui_handle("boxpreferences_31", { value: Config.raw.pressure_sensitivity }), tr("Sensitivity"), 0.0, 10.0, true); @@ -415,17 +415,17 @@ class BoxPreferences { if (zui_tab(BoxPreferences.htab, tr("Viewport"), true)) { ///if (krom_direct3d12 || krom_vulkan || krom_metal) - let hpathtracemode: zui_handle_t = zui_handle("boxpreferences_40", { position: Context.raw.pathtrace_mode }); - Context.raw.pathtrace_mode = zui_combo(hpathtracemode, [tr("Core"), tr("Full")], tr("Path Tracer"), true); - if (hpathtracemode.changed) { + let hpathtrace_mode: zui_handle_t = zui_handle("boxpreferences_40", { position: Context.raw.pathtrace_mode }); + Context.raw.pathtrace_mode = zui_combo(hpathtrace_mode, [tr("Core"), tr("Full")], tr("Path Tracer"), true); + if (hpathtrace_mode.changed) { RenderPathRaytrace.ready = false; } ///end - let hrendermode: zui_handle_t = zui_handle("boxpreferences_41", { position: Context.raw.render_mode }); - Context.raw.render_mode = zui_combo(hrendermode, [tr("Full"), tr("Mobile")], tr("Renderer"), true); - if (hrendermode.changed) { + let hrender_mode: zui_handle_t = zui_handle("boxpreferences_41", { position: Context.raw.render_mode }); + Context.raw.render_mode = zui_combo(hrender_mode, [tr("Full"), tr("Mobile")], tr("Renderer"), true); + if (hrender_mode.changed) { Context.set_render_path(); } @@ -471,20 +471,20 @@ class BoxPreferences { // if (h.changed) Context.raw.ddirty = 2; let cam: camera_object_t = scene_camera; - let camRaw: camera_data_t = cam.data; + let cam_raw: camera_data_t = cam.data; let near_handle: zui_handle_t = zui_handle("boxpreferences_47"); let far_handle: zui_handle_t = zui_handle("boxpreferences_48"); - near_handle.value = Math.floor(camRaw.near_plane * 1000) / 1000; - far_handle.value = Math.floor(camRaw.far_plane * 100) / 100; - camRaw.near_plane = zui_slider(near_handle, tr("Clip Start"), 0.001, 1.0, true); - camRaw.far_plane = zui_slider(far_handle, tr("Clip End"), 50.0, 100.0, true); + near_handle.value = Math.floor(cam_raw.near_plane * 1000) / 1000; + far_handle.value = Math.floor(cam_raw.far_plane * 100) / 100; + cam_raw.near_plane = zui_slider(near_handle, tr("Clip Start"), 0.001, 1.0, true); + cam_raw.far_plane = zui_slider(far_handle, tr("Clip End"), 50.0, 100.0, true); if (near_handle.changed || far_handle.changed) { camera_object_build_proj(cam); } - let dispHandle: zui_handle_t = zui_handle("boxpreferences_49", { value: Config.raw.displace_strength }); - Config.raw.displace_strength = zui_slider(dispHandle, tr("Displacement Strength"), 0.0, 10.0, true); - if (dispHandle.changed) { + let disp_handle: zui_handle_t = zui_handle("boxpreferences_49", { value: Config.raw.displace_strength }); + Config.raw.displace_strength = zui_slider(disp_handle, tr("Displacement Strength"), 0.0, 10.0, true); + if (disp_handle.changed) { Context.raw.ddirty = 2; MakeMaterial.parse_mesh_material(); } @@ -510,14 +510,14 @@ class BoxPreferences { UIBox.show_custom((ui: zui_t) => { if (zui_tab(zui_handle("boxpreferences_51"), tr("New Keymap"))) { zui_row([0.5, 0.5]); - let keymapName: string = zui_text_input(zui_handle("boxpreferences_52", { text: "new_keymap" }), tr("Name")); + let keymap_name: string = zui_text_input(zui_handle("boxpreferences_52", { text: "new_keymap" }), tr("Name")); if (zui_button(tr("OK")) || ui.is_return_down) { - let template: string = JSON.stringify(Base.default_keymap); - if (!keymapName.endsWith(".json")) keymapName += ".json"; - let path: string = Path.data() + Path.sep + "keymap_presets" + Path.sep + keymapName; + let template: string = JSON.stringify(base_default_keymap); + if (!keymap_name.endsWith(".json")) keymap_name += ".json"; + let path: string = Path.data() + Path.sep + "keymap_presets" + Path.sep + keymap_name; krom_file_save_bytes(path, sys_string_to_buffer(template)); BoxPreferences.fetch_keymaps(); // Refresh file list - Config.raw.keymap = keymapName; + Config.raw.keymap = keymap_name; BoxPreferences.preset_handle.position = BoxPreferences.get_preset_index(); UIBox.hide(); BoxPreferences.htab.position = 5; // Keymap @@ -564,7 +564,7 @@ class BoxPreferences { UIBox.show_custom((ui: zui_t) => { if (zui_tab(zui_handle("boxpreferences_54"), tr("New Plugin"))) { zui_row([0.5, 0.5]); - let pluginName: string = zui_text_input(zui_handle("boxpreferences_55", { text: "new_plugin" }), tr("Name")); + let plugin_name: string = zui_text_input(zui_handle("boxpreferences_55", { text: "new_plugin" }), tr("Name")); if (zui_button(tr("OK")) || ui.is_return_down) { let template: string = `let plugin = Plugin.create(); @@ -577,8 +577,8 @@ plugin.drawUI = (ui) { => } } `; - if (!pluginName.endsWith(".js")) pluginName += ".js"; - let path: string = Path.data() + Path.sep + "plugins" + Path.sep + pluginName; + if (!plugin_name.endsWith(".js")) plugin_name += ".js"; + let path: string = Path.data() + Path.sep + "plugins" + Path.sep + plugin_name; krom_file_save_bytes(path, sys_string_to_buffer(template)); BoxPreferences.files_plugin = null; // Refresh file list UIBox.hide(); @@ -602,15 +602,15 @@ plugin.drawUI = (ui) { => if (Config.raw.plugins == null) Config.raw.plugins = []; let h: zui_handle_t = zui_handle("boxpreferences_56", { selected: false }); for (let f of BoxPreferences.files_plugin) { - let isJs: bool = f.endsWith(".js"); - if (!isJs) continue; + let is_js: bool = f.endsWith(".js"); + if (!is_js) continue; let enabled: bool = Config.raw.plugins.indexOf(f) >= 0; h.selected = enabled; - let tag: string = isJs ? f.split(".")[0] : f; + let tag: string = is_js ? f.split(".")[0] : f; zui_check(h, tag); if (h.changed && h.selected != enabled) { h.selected ? Config.enable_plugin(f) : Config.disable_plugin(f); - Base.redraw_ui(); + base_redraw_ui(); } if (ui.is_hovered && ui.input_released_r) { UIMenu.draw((ui: zui_t) => { @@ -681,9 +681,9 @@ plugin.drawUI = (ui) { => UIBase.set_icon_scale(); zui_set_scale(UINodes.ui, scale); zui_set_scale(UIView2D.ui, scale); - zui_set_scale(Base.ui_box, scale); - zui_set_scale(Base.ui_menu, scale); - Base.resize(); + zui_set_scale(base_ui_box, scale); + zui_set_scale(base_ui_menu, scale); + base_resize(); ///if (is_paint || is_sculpt) Config.raw.layout[layout_size_t.SIDEBAR_W] = Math.floor(UIBase.default_sidebar_w * scale); UIToolbar.toolbar_w = Math.floor(UIToolbar.default_toolbar_w * scale); diff --git a/base/Sources/BoxProjects.ts b/base/Sources/BoxProjects.ts index cb21530c..f729468a 100644 --- a/base/Sources/BoxProjects.ts +++ b/base/Sources/BoxProjects.ts @@ -91,18 +91,18 @@ class BoxProjects { let path: string = recent_projects[i]; ///if krom_ios - let documentDirectory: string = krom_save_dialog("", ""); - documentDirectory = documentDirectory.substr(0, documentDirectory.length - 8); // Strip /'untitled' - path = documentDirectory + path; + let document_directory: string = krom_save_dialog("", ""); + document_directory = document_directory.substr(0, document_directory.length - 8); // Strip /'untitled' + path = document_directory + path; ///end - let iconPath: string = path.substr(0, path.length - 4) + "_icon.png"; + let icon_path: string = path.substr(0, path.length - 4) + "_icon.png"; if (BoxProjects.icon_map == null) BoxProjects.icon_map = new Map(); - let icon: image_t = BoxProjects.icon_map.get(iconPath); + let icon: image_t = BoxProjects.icon_map.get(icon_path); if (icon == null) { - let image: image_t = data_get_image(iconPath); + let image: image_t = data_get_image(icon_path); icon = image; - BoxProjects.icon_map.set(iconPath, icon); + BoxProjects.icon_map.set(icon_path, icon); } let uix: i32 = ui._x; @@ -123,9 +123,9 @@ class BoxProjects { } ///if (krom_android || krom_ios) - Base.notify_on_next_frame(() => { + base_notify_on_next_frame(() => { Console.toast(tr("Opening project")); - Base.notify_on_next_frame(doImport); + base_notify_on_next_frame(doImport); }); ///else doImport(); @@ -139,9 +139,9 @@ class BoxProjects { if (UIMenu.menu_button(ui, tr("Delete"))) { app_notify_on_init(() => { File.delete(path); - File.delete(iconPath); - let dataPath: string = path.substr(0, path.length - 4); - File.delete(dataPath); + File.delete(icon_path); + let data_path: string = path.substr(0, path.length - 4); + File.delete(data_path); recent_projects.splice(i, 1); }); } @@ -237,8 +237,8 @@ class BoxProjects { } static align_to_fullscreen = () => { - UIBox.modalw = Math.floor(sys_width() / zui_SCALE(Base.ui_box)); - UIBox.modalh = Math.floor(sys_height() / zui_SCALE(Base.ui_box)); + UIBox.modalw = Math.floor(sys_width() / zui_SCALE(base_ui_box)); + UIBox.modalh = Math.floor(sys_height() / zui_SCALE(base_ui_box)); let appw: i32 = sys_width(); let apph: i32 = sys_height(); let mw: i32 = appw; diff --git a/base/Sources/Camera.ts b/base/Sources/Camera.ts index d16da43d..efdbb8d3 100644 --- a/base/Sources/Camera.ts +++ b/base/Sources/Camera.ts @@ -43,9 +43,9 @@ class Camera { } } - let modifKey: bool = keyboard_down("alt") || keyboard_down("shift") || keyboard_down("control"); - let modif: bool = modifKey || Config.keymap.action_rotate == "middle"; - let defaultKeymap: bool = Config.raw.keymap == "default.json"; + let modif_key: bool = keyboard_down("alt") || keyboard_down("shift") || keyboard_down("control"); + let modif: bool = modif_key || Config.keymap.action_rotate == "middle"; + let default_keymap: bool = Config.raw.keymap == "default.json"; if (Operator.shortcut(Config.keymap.action_rotate, ShortcutType.ShortcutStarted) || Operator.shortcut(Config.keymap.action_zoom, ShortcutType.ShortcutStarted) || @@ -54,7 +54,7 @@ class Camera { Operator.shortcut(Config.keymap.rotate_light, ShortcutType.ShortcutStarted) || (mouse_started("right") && !modif) || (mouse_started("middle") && !modif) || - (mouse_wheel_delta != 0 && !modifKey)) { + (mouse_wheel_delta != 0 && !modif_key)) { Camera.controls_down = true; } else if (!Operator.shortcut(Config.keymap.action_rotate, ShortcutType.ShortcutDown) && @@ -64,16 +64,16 @@ class Camera { !Operator.shortcut(Config.keymap.rotate_light, ShortcutType.ShortcutDown) && !(mouse_down("right") && !modif) && !(mouse_down("middle") && !modif) && - (mouse_wheel_delta == 0 && !modifKey)) { + (mouse_wheel_delta == 0 && !modif_key)) { Camera.controls_down = false; } - if (_input_occupied || !Base.ui_enabled || Base.is_dragging || Base.is_scrolling() || Base.is_combo_selected() || !Camera.controls_down) { + if (_input_occupied || !base_ui_enabled || base_is_dragging || base_is_scrolling() || base_is_combo_selected() || !Camera.controls_down) { return; } let controls: camera_controls_t = Context.raw.camera_controls; - if (controls == camera_controls_t.ORBIT && (Operator.shortcut(Config.keymap.action_rotate, ShortcutType.ShortcutDown) || (mouse_down("right") && !modif && defaultKeymap))) { + if (controls == camera_controls_t.ORBIT && (Operator.shortcut(Config.keymap.action_rotate, ShortcutType.ShortcutDown) || (mouse_down("right") && !modif && default_keymap))) { Camera.redraws = 2; let dist: f32 = Camera.distance(); transform_move(camera.base.transform, camera_object_look_world(camera), dist); @@ -84,7 +84,7 @@ class Camera { } transform_move(camera.base.transform, camera_object_look_world(camera), -dist); } - else if (controls == camera_controls_t.ROTATE && (Operator.shortcut(Config.keymap.action_rotate, ShortcutType.ShortcutDown) || (mouse_down("right") && !modif && defaultKeymap))) { + else if (controls == camera_controls_t.ROTATE && (Operator.shortcut(Config.keymap.action_rotate, ShortcutType.ShortcutDown) || (mouse_down("right") && !modif && default_keymap))) { Camera.redraws = 2; let t: transform_t = Context.main_object().base.transform; let up: vec4_t = vec4_normalize(transform_up(t)); @@ -98,7 +98,7 @@ class Camera { } if (controls == camera_controls_t.ROTATE || controls == camera_controls_t.ORBIT) { - Camera.pan_action(modif, defaultKeymap); + Camera.pan_action(modif, default_keymap); if (Operator.shortcut(Config.keymap.action_zoom, ShortcutType.ShortcutDown)) { Camera.redraws = 2; @@ -107,7 +107,7 @@ class Camera { transform_move(camera.base.transform, camera_object_look(camera), f); } - if (mouse_wheel_delta != 0 && !modifKey) { + if (mouse_wheel_delta != 0 && !modif_key) { Camera.redraws = 2; let f: f32 = mouse_wheel_delta * (-0.1); f *= Camera.get_camera_zoom_speed(); @@ -115,27 +115,27 @@ class Camera { } } else if (controls == camera_controls_t.FLY && mouse_down("right")) { - let moveForward: bool = keyboard_down("w") || keyboard_down("up") || mouse_wheel_delta < 0; - let moveBackward: bool = keyboard_down("s") || keyboard_down("down") || mouse_wheel_delta > 0; - let strafeLeft: bool = keyboard_down("a") || keyboard_down("left"); - let strafeRight: bool = keyboard_down("d") || keyboard_down("right"); - let strafeUp: bool = keyboard_down("e"); - let strafeDown: bool = keyboard_down("q"); + let move_forward: bool = keyboard_down("w") || keyboard_down("up") || mouse_wheel_delta < 0; + let move_backward: bool = keyboard_down("s") || keyboard_down("down") || mouse_wheel_delta > 0; + let strafe_left: bool = keyboard_down("a") || keyboard_down("left"); + let strafe_right: bool = keyboard_down("d") || keyboard_down("right"); + let strafe_up: bool = keyboard_down("e"); + let strafe_down: bool = keyboard_down("q"); let fast: f32 = keyboard_down("shift") ? 2.0 : (keyboard_down("alt") ? 0.5 : 1.0); if (mouse_wheel_delta != 0) { fast *= Math.abs(mouse_wheel_delta) * 4.0; } - if (moveForward || moveBackward || strafeRight || strafeLeft || strafeUp || strafeDown) { + if (move_forward || move_backward || strafe_right || strafe_left || strafe_up || strafe_down) { Camera.ease += time_delta() * 15; if (Camera.ease > 1.0) Camera.ease = 1.0; vec4_set(Camera.dir, 0, 0, 0); - if (moveForward) vec4_add_f(Camera.dir, camera_object_look(camera).x, camera_object_look(camera).y, camera_object_look(camera).z); - if (moveBackward) vec4_add_f(Camera.dir, -camera_object_look(camera).x, -camera_object_look(camera).y, -camera_object_look(camera).z); - if (strafeRight) vec4_add_f(Camera.dir, camera_object_right(camera).x, camera_object_right(camera).y, camera_object_right(camera).z); - if (strafeLeft) vec4_add_f(Camera.dir, -camera_object_right(camera).x, -camera_object_right(camera).y, -camera_object_right(camera).z); - if (strafeUp) vec4_add_f(Camera.dir, 0, 0, 1); - if (strafeDown) vec4_add_f(Camera.dir, 0, 0, -1); + if (move_forward) vec4_add_f(Camera.dir, camera_object_look(camera).x, camera_object_look(camera).y, camera_object_look(camera).z); + if (move_backward) vec4_add_f(Camera.dir, -camera_object_look(camera).x, -camera_object_look(camera).y, -camera_object_look(camera).z); + if (strafe_right) vec4_add_f(Camera.dir, camera_object_right(camera).x, camera_object_right(camera).y, camera_object_right(camera).z); + if (strafe_left) vec4_add_f(Camera.dir, -camera_object_right(camera).x, -camera_object_right(camera).y, -camera_object_right(camera).z); + if (strafe_up) vec4_add_f(Camera.dir, 0, 0, 1); + if (strafe_down) vec4_add_f(Camera.dir, 0, 0, -1); } else { Camera.ease -= time_delta() * 20.0 * Camera.ease; @@ -143,7 +143,7 @@ class Camera { } - let d: f32 = time_delta() * fast * Camera.ease * 2.0 * ((moveForward || moveBackward) ? Config.raw.camera_zoom_speed : Config.raw.camera_pan_speed); + let d: f32 = time_delta() * fast * Camera.ease * 2.0 * ((move_forward || move_backward) ? Config.raw.camera_zoom_speed : Config.raw.camera_pan_speed); if (d > 0.0) { transform_move(camera.base.transform, Camera.dir, d); if (Context.raw.camera_type == camera_type_t.ORTHOGRAPHIC) { diff --git a/base/Sources/Config.ts b/base/Sources/Config.ts index 2f2ef669..e029405c 100644 --- a/base/Sources/Config.ts +++ b/base/Sources/Config.ts @@ -84,7 +84,7 @@ class Config { Config.raw.rp_supersample = 1.0; Config.raw.version = manifest_version; Config.raw.sha = Config.get_sha(); - Base.init_config(); + base_init_config(); } else { // Upgrade config format created by older ArmorPaint build @@ -102,7 +102,7 @@ class Config { zui_set_touch_scroll(Config.raw.touch_ui); zui_set_touch_hold(Config.raw.touch_ui); zui_set_touch_tooltip(Config.raw.touch_ui); - Base.res_handle.position = Config.raw.layer_res; + base_res_handle.position = Config.raw.layer_res; Config.load_keymap(); } @@ -121,11 +121,11 @@ class Config { } static get_options = (): kinc_sys_ops_t => { - let windowMode: window_mode_t = Config.raw.window_mode == 0 ? window_mode_t.WINDOWED : window_mode_t.FULLSCREEN; - let windowFeatures: window_features_t = window_features_t.NONE; - if (Config.raw.window_resizable) windowFeatures |= window_features_t.RESIZABLE; - if (Config.raw.window_maximizable) windowFeatures |= window_features_t.MAXIMIZABLE; - if (Config.raw.window_minimizable) windowFeatures |= window_features_t.MINIMIZABLE; + let window_mode: window_mode_t = Config.raw.window_mode == 0 ? window_mode_t.WINDOWED : window_mode_t.FULLSCREEN; + let window_features: window_features_t = window_features_t.NONE; + if (Config.raw.window_resizable) window_features |= window_features_t.RESIZABLE; + if (Config.raw.window_maximizable) window_features |= window_features_t.MAXIMIZABLE; + if (Config.raw.window_minimizable) window_features |= window_features_t.MINIMIZABLE; let title: string = "untitled - " + manifest_title; return { title: title, @@ -133,8 +133,8 @@ class Config { height: Config.raw.window_h, x: Config.raw.window_x, y: Config.raw.window_y, - mode: windowMode, - features: windowFeatures, + mode: window_mode, + features: window_features, vsync: Config.raw.window_vsync, frequency: Config.raw.window_frequency }; @@ -146,7 +146,7 @@ class Config { let _layout: i32[] = Config.raw.layout; Config.init(); Config.raw.layout = _layout; - Base.init_layout(); + base_init_layout(); Translator.load_translations(Config.raw.locale); Config.apply_config(); Config.load_theme(Config.raw.theme); @@ -160,7 +160,7 @@ class Config { Config.raw.version = _version; zui_children = new Map(); // Reset ui handles Config.load_keymap(); - Base.init_layout(); + base_init_layout(); Translator.load_translations(Config.raw.locale); Config.apply_config(); Config.load_theme(Config.raw.theme); @@ -183,16 +183,16 @@ class Config { static load_keymap = () => { if (Config.raw.keymap == "default.json") { // Built-in default - Config.keymap = Base.default_keymap; + Config.keymap = base_default_keymap; } else { let blob: ArrayBuffer = data_get_blob("keymap_presets/" + Config.raw.keymap); Config.keymap = JSON.parse(sys_buffer_to_string(blob)); // Fill in undefined keys with defaults - for (let field in Base.default_keymap) { + for (let field in base_default_keymap) { if (!(field in Config.keymap)) { - let adefaultKeymap: any = Base.default_keymap; - Config.keymap[field] = adefaultKeymap[field]; + let adefault_keymap: any = base_default_keymap; + Config.keymap[field] = adefault_keymap[field]; } } } @@ -222,7 +222,7 @@ class Config { } static get_texture_res = (): i32 => { - let res: i32 = Base.res_handle.position; + let res: i32 = base_res_handle.position; return res == texture_res_t.RES128 ? 128 : res == texture_res_t.RES256 ? 256 : res == texture_res_t.RES512 ? 512 : @@ -254,39 +254,39 @@ class Config { static load_theme = (theme: string, tagRedraw: bool = true) => { if (theme == "default.json") { // Built-in default - Base.theme = zui_theme_create(); + base_theme = zui_theme_create(); } else { let b: ArrayBuffer = data_get_blob("themes/" + theme); let parsed: any = JSON.parse(sys_buffer_to_string(b)); - Base.theme = zui_theme_create(); - for (let key in Base.theme) { + base_theme = zui_theme_create(); + for (let key in base_theme) { if (key == "theme_") continue; if (key.startsWith("set_")) continue; if (key.startsWith("get_")) key = key.substr(4); - let atheme: any = Base.theme; + let atheme: any = base_theme; atheme[key] = parsed[key]; } } - Base.theme.FILL_WINDOW_BG = true; + base_theme.FILL_WINDOW_BG = true; if (tagRedraw) { - for (let ui of Base.get_uis()) ui.t = Base.theme; + for (let ui of base_get_uis()) ui.t = base_theme; UIBase.tag_ui_redraw(); } if (Config.raw.touch_ui) { // Enlarge elements - Base.theme.FULL_TABS = true; - Base.theme.ELEMENT_H = 24 + 6; - Base.theme.BUTTON_H = 22 + 6; - Base.theme.FONT_SIZE = 13 + 2; - Base.theme.ARROW_SIZE = 5 + 2; - Base.theme.CHECK_SIZE = 15 + 4; - Base.theme.CHECK_SELECT_SIZE = 8 + 2; + base_theme.FULL_TABS = true; + base_theme.ELEMENT_H = 24 + 6; + base_theme.BUTTON_H = 22 + 6; + base_theme.FONT_SIZE = 13 + 2; + base_theme.ARROW_SIZE = 5 + 2; + base_theme.CHECK_SIZE = 15 + 4; + base_theme.CHECK_SELECT_SIZE = 8 + 2; Config.button_align = zui_align_t.LEFT; Config.button_spacing = ""; } else { - Base.theme.FULL_TABS = false; + base_theme.FULL_TABS = false; Config.button_align = zui_align_t.LEFT; Config.button_spacing = Config.default_button_spacing; } diff --git a/base/Sources/Console.ts b/base/Sources/Console.ts index 74a4b1a1..d7625e14 100644 --- a/base/Sources/Console.ts +++ b/base/Sources/Console.ts @@ -10,11 +10,11 @@ class Console { static draw_toast = (s: string) => { g2_set_color(0x55000000); g2_fill_rect(0, 0, sys_width(), sys_height()); - let scale: f32 = zui_SCALE(Base.get_uis()[0]); + let scale: f32 = zui_SCALE(base_get_uis()[0]); let x: f32 = sys_width() / 2; let y: f32 = sys_height() - 200 * scale; g2_fill_rect(x - 200 * scale, y, 400 * scale, 80 * scale); - g2_set_font(Base.font); + g2_set_font(base_font); g2_set_font_size(Math.floor(22 * scale)); g2_set_color(0xffffffff); g2_draw_string(s, x - g2_font_width(_g2_font, _g2_font_size, s) / 2, y + 40 * scale - g2_font_height(_g2_font, _g2_font_size) / 2); @@ -24,7 +24,7 @@ class Console { // Show a popup message let _render = () => { Console.draw_toast(s); - Base.notify_on_next_frame(() => { + base_notify_on_next_frame(() => { app_remove_render_2d(_render); }); } @@ -52,7 +52,7 @@ class Console { Console.message_timer = 5.0; Console.message = s; Console.message_color = 0x00000000; - Base.redraw_status(); + base_redraw_status(); Console.console_trace(s); } @@ -60,7 +60,7 @@ class Console { Console.message_timer = 8.0; Console.message = s; Console.message_color = 0xffaa0000; - Base.redraw_status(); + base_redraw_status(); Console.console_trace(s); } @@ -69,7 +69,7 @@ class Console { } static console_trace = (v: any) => { - Base.redraw_console(); + base_redraw_console(); Console.last_traces.unshift(String(v)); if (Console.last_traces.length > 100) Console.last_traces.pop(); } diff --git a/base/Sources/Context.ts b/base/Sources/Context.ts index a8d31087..f051bea6 100644 --- a/base/Sources/Context.ts +++ b/base/Sources/Context.ts @@ -34,7 +34,7 @@ class Context { let _next = () => { UtilRender.make_decal_preview(); } - Base.notify_on_next_frame(_next); + base_notify_on_next_frame(_next); } } @@ -78,7 +78,7 @@ class Context { let current: image_t = _g2_current; if (current != null) g2_end(); - Base.set_object_mask(); + base_set_object_mask(); MakeMaterial.parse_mesh_material(); MakeMaterial.parse_paint_material(); @@ -94,9 +94,9 @@ class Context { MakeMaterial.parse_paint_material(); MakeMaterial.parse_mesh_material(); Context.raw.ddirty = 3; - let _viewportMode: viewport_mode_t = Context.raw.viewport_mode; + let _viewport_mode: viewport_mode_t = Context.raw.viewport_mode; Context.raw.viewport_mode = -1 as viewport_mode_t; - Context.set_viewport_mode(_viewportMode); + Context.set_viewport_mode(_viewport_mode); ///if (is_paint || is_sculpt) Context.init_tool(); @@ -130,7 +130,7 @@ class Context { } else if (Context.raw.tool == workspace_tool_t.MATERIAL) { - Base.update_fill_layers(); + base_update_fill_layers(); Context.main_object().skip_context = null; } @@ -339,7 +339,7 @@ class Context { let nodes: zui_nodes_t = UINodes.get_nodes(); let canvas: zui_node_canvas_t = UINodes.get_canvas(true); - let inpaint: bool = nodes.nodesSelectedId.length > 0 && zui_get_node(canvas.nodes, nodes.nodesSelectedId[0]).type == "InpaintNode"; + let inpaint: bool = nodes.nodes_selected_id.length > 0 && zui_get_node(canvas.nodes, nodes.nodes_selected_id[0]).type == "InpaintNode"; // Paint bounds if (inpaint && @@ -347,16 +347,16 @@ class Context { Context.raw.paint_vec.x < right && Context.raw.paint_vec.y > 0 && Context.raw.paint_vec.y < 1 && - !Base.is_dragging && - !Base.is_resizing && - !Base.is_scrolling() && - !Base.is_combo_selected()) { + !base_is_dragging && + !base_is_resizing && + !base_is_scrolling() && + !base_is_combo_selected()) { let down: bool = mouse_down() || pen_down(); // Prevent painting the same spot - let sameSpot: bool = Context.raw.paint_vec.x == Context.raw.last_paint_x && Context.raw.paint_vec.y == Context.raw.last_paint_y; - if (down && sameSpot) { + let same_spot: bool = Context.raw.paint_vec.x == Context.raw.last_paint_x && Context.raw.paint_vec.y == Context.raw.last_paint_y; + if (down && same_spot) { Context.raw.painted++; } else { @@ -386,16 +386,16 @@ class Context { } static update = () => { - let paintX: f32 = mouse_view_x() / app_w(); - let paintY: f32 = mouse_view_y() / app_h(); + let paint_x: f32 = mouse_view_x() / app_w(); + let paint_y: f32 = mouse_view_y() / app_h(); if (mouse_started()) { Context.raw.start_x = mouse_view_x() / app_w(); Context.raw.start_y = mouse_view_y() / app_h(); } if (pen_down()) { - paintX = pen_view_x() / app_w(); - paintY = pen_view_y() / app_h(); + paint_x = pen_view_x() / app_w(); + paint_y = pen_view_y() / app_h(); } if (pen_started()) { Context.raw.start_x = pen_view_x() / app_w(); @@ -403,12 +403,12 @@ class Context { } if (Operator.shortcut(Config.keymap.brush_ruler + "+" + Config.keymap.action_paint, ShortcutType.ShortcutDown)) { - if (Context.raw.lock_x) paintX = Context.raw.start_x; - if (Context.raw.lock_y) paintY = Context.raw.start_y; + if (Context.raw.lock_x) paint_x = Context.raw.start_x; + if (Context.raw.lock_y) paint_y = Context.raw.start_y; } - Context.raw.coords.x = paintX; - Context.raw.coords.y = paintY; + Context.raw.coords.x = paint_x; + Context.raw.coords.y = paint_y; if (Context.raw.lock_begin) { let dx: i32 = Math.abs(Context.raw.lock_start_x - mouse_view_x()); diff --git a/base/Sources/ExportArm.ts b/base/Sources/ExportArm.ts index 0912c640..5adb73db 100644 --- a/base/Sources/ExportArm.ts +++ b/base/Sources/ExportArm.ts @@ -53,8 +53,8 @@ class ExportArm { let font_files: string[] = ExportArm.fonts_to_files(Project.filepath, Project.fonts); let mesh_files: string[] = ExportArm.meshes_to_files(Project.filepath); - let bitsPos: i32 = Base.bits_handle.position; - let bpp: i32 = bitsPos == texture_bits_t.BITS8 ? 8 : bitsPos == texture_bits_t.BITS16 ? 16 : 32; + let bits_pos: i32 = base_bits_handle.position; + let bpp: i32 = bits_pos == texture_bits_t.BITS8 ? 8 : bits_pos == texture_bits_t.BITS16 ? 16 : 32; let ld: layer_data_t[] = []; for (let l of Project.layers) { @@ -65,28 +65,28 @@ class ExportArm { texpaint: l.texpaint != null ? lz4_encode(image_get_pixels(l.texpaint)) : null, uv_scale: l.scale, uv_rot: l.angle, - uv_type: l.uvType, - decal_mat: l.uvType == uv_type_t.PROJECT ? mat4_to_f32_array(l.decalMat) : null, - opacity_mask: l.maskOpacity, + uv_type: l.uv_type, + decal_mat: l.uv_type == uv_type_t.PROJECT ? mat4_to_f32_array(l.decal_mat) : null, + opacity_mask: l.mask_opacity, fill_layer: l.fill_layer != null ? Project.materials.indexOf(l.fill_layer) : -1, - object_mask: l.objectMask, + object_mask: l.object_mask, blending: l.blending, parent: l.parent != null ? Project.layers.indexOf(l.parent) : -1, visible: l.visible, ///if is_paint texpaint_nor: l.texpaint_nor != null ? lz4_encode(image_get_pixels(l.texpaint_nor)) : null, texpaint_pack: l.texpaint_pack != null ? lz4_encode(image_get_pixels(l.texpaint_pack)) : null, - paint_base: l.paintBase, - paint_opac: l.paintOpac, - paint_occ: l.paintOcc, - paint_rough: l.paintRough, - paint_met: l.paintMet, - paint_nor: l.paintNor, - paint_nor_blend: l.paintNorBlend, - paint_height: l.paintHeight, - paint_height_blend: l.paintHeightBlend, - paint_emis: l.paintEmis, - paint_subs: l.paintSubs + paint_base: l.paint_base, + paint_opac: l.paint_opac, + paint_occ: l.paint_occ, + paint_rough: l.paint_rough, + paint_met: l.paint_met, + paint_nor: l.paint_nor, + paint_nor_blend: l.paint_nor_blend, + paint_height: l.paint_height, + paint_height_blend: l.paint_height_blend, + paint_emis: l.paint_emis, + paint_subs: l.paint_subs ///end }); } @@ -94,9 +94,9 @@ class ExportArm { let packed_assets: packed_asset_t[] = (Project.raw.packed_assets == null || Project.raw.packed_assets.length == 0) ? null : Project.raw.packed_assets; ///if krom_ios - let sameDrive: bool = false; + let same_drive: bool = false; ///else - let sameDrive: bool = Project.raw.envmap != null ? Project.filepath.charAt(0) == Project.raw.envmap.charAt(0) : true; + let same_drive: bool = Project.raw.envmap != null ? Project.filepath.charAt(0) == Project.raw.envmap.charAt(0) : true; ///end Project.raw = { @@ -105,7 +105,7 @@ class ExportArm { assets: texture_files, packed_assets: packed_assets, swatches: Project.raw.swatches, - envmap: Project.raw.envmap != null ? (sameDrive ? Path.to_relative(Project.filepath, Project.raw.envmap) : Project.raw.envmap) : null, + envmap: Project.raw.envmap != null ? (same_drive ? Path.to_relative(Project.filepath, Project.raw.envmap) : Project.raw.envmap) : null, envmap_strength: scene_world.strength, camera_world: mat4_to_f32_array(scene_camera.base.transform.local), camera_origin: ExportArm.vec3f32(Camera.origins[0]), @@ -161,7 +161,7 @@ class ExportArm { ///if (krom_metal || krom_vulkan) ExportArm.bgra_swap(mesh_icon_pixels); ///end - Base.notify_on_next_frame(() => { + base_notify_on_next_frame(() => { image_unload(mesh_icon); }); // Project.raw.mesh_icons = @@ -174,8 +174,8 @@ class ExportArm { ///end ///if (is_paint || is_sculpt) - let isPacked: bool = Project.filepath.endsWith("_packed_.arm"); - if (isPacked) { // Pack textures + let is_packed: bool = Project.filepath.endsWith("_packed_.arm"); + if (is_packed) { // Pack textures ExportArm.pack_assets(Project.raw, Project.assets); } ///end @@ -208,7 +208,7 @@ class ExportArm { static export_node = (n: zui_node_t, assets: asset_t[] = null) => { if (n.type == ExportArm.texture_node_name()) { let index: i32 = n.buttons[0].default_value; - n.buttons[0].data = Base.enum_texts(n.type)[index]; + n.buttons[0].data = base_enum_texts(n.type)[index]; if (assets != null) { let asset: asset_t = Project.assets[index]; @@ -240,8 +240,8 @@ class ExportArm { mnodes.push(c); let texture_files: string[] = ExportArm.assets_to_files(path, assets); - let isCloud: bool = path.endsWith("_cloud_.arm"); - if (isCloud) path = string_replace_all(path, "_cloud_", ""); + let is_cloud: bool = path.endsWith("_cloud_.arm"); + if (is_cloud) path = string_replace_all(path, "_cloud_", ""); let packed_assets: packed_asset_t[] = null; if (!Context.raw.pack_assets_on_export) { packed_assets = ExportArm.get_packed_assets(path, texture_files); @@ -251,7 +251,7 @@ class ExportArm { version: manifest_version, material_nodes: mnodes, material_groups: mgroups, - material_icons: isCloud ? null : + material_icons: is_cloud ? null : ///if (krom_metal || krom_vulkan) [lz4_encode(ExportArm.bgra_swap(image_get_pixels(m.image)))], ///else @@ -263,7 +263,7 @@ class ExportArm { if (Context.raw.write_icon_on_export) { // Separate icon files krom_write_png(path.substr(0, path.length - 4) + "_icon.png", image_get_pixels(m.image), m.image.width, m.image.height, 0); - if (isCloud) { + if (is_cloud) { krom_write_jpg(path.substr(0, path.length - 4) + "_icon.jpg", image_get_pixels(m.image), m.image.width, m.image.height, 0, 50); } } @@ -300,8 +300,8 @@ class ExportArm { bnodes.push(c); let texture_files: string[] = ExportArm.assets_to_files(path, assets); - let isCloud: bool = path.endsWith("_cloud_.arm"); - if (isCloud) path = string_replace_all(path, "_cloud_", ""); + let is_cloud: bool = path.endsWith("_cloud_.arm"); + if (is_cloud) path = string_replace_all(path, "_cloud_", ""); let packed_assets: packed_asset_t[] = null; if (!Context.raw.pack_assets_on_export) { packed_assets = ExportArm.get_packed_assets(path, texture_files); @@ -310,7 +310,7 @@ class ExportArm { let raw: project_format_t = { version: manifest_version, brush_nodes: bnodes, - brush_icons: isCloud ? null : + brush_icons: is_cloud ? null : ///if (krom_metal || krom_vulkan) [lz4_encode(ExportArm.bgra_swap(image_get_pixels(b.image)))], ///else @@ -337,12 +337,12 @@ class ExportArm { let texture_files: string[] = []; for (let a of assets) { ///if krom_ios - let sameDrive: bool = false; + let same_drive: bool = false; ///else - let sameDrive: bool = projectPath.charAt(0) == a.file.charAt(0); + let same_drive: bool = projectPath.charAt(0) == a.file.charAt(0); ///end // Convert image path from absolute to relative - if (sameDrive) { + if (same_drive) { texture_files.push(Path.to_relative(projectPath, a.file)); } else { @@ -357,12 +357,12 @@ class ExportArm { let mesh_files: string[] = []; for (let file of Project.mesh_assets) { ///if krom_ios - let sameDrive: bool = false; + let same_drive: bool = false; ///else - let sameDrive: bool = projectPath.charAt(0) == file.charAt(0); + let same_drive: bool = projectPath.charAt(0) == file.charAt(0); ///end // Convert mesh path from absolute to relative - if (sameDrive) { + if (same_drive) { mesh_files.push(Path.to_relative(projectPath, file)); } else { @@ -377,12 +377,12 @@ class ExportArm { for (let i = 1; i { - for (let image of tempImages) image_unload(image); + base_notify_on_next_frame(() => { + for (let image of temp_images) image_unload(image); }); } diff --git a/base/Sources/ExportTexture.ts b/base/Sources/ExportTexture.ts index d5080131..88afe97e 100644 --- a/base/Sources/ExportTexture.ts +++ b/base/Sources/ExportTexture.ts @@ -5,64 +5,64 @@ class ExportTexture { static gamma: f32 = 1.0 / 2.2; - static run = (path: string, bakeMaterial: bool = false) => { + static run = (path: string, bake_material: bool = false) => { ///if is_paint - if (bakeMaterial) { + if (bake_material) { ExportTexture.run_bake_material(path); } else if (Context.raw.layers_export == export_mode_t.PER_UDIM_TILE) { - let udimTiles: string[] = []; + let udim_tiles: string[] = []; for (let l of Project.layers) { if (SlotLayer.get_object_mask(l) > 0) { let name: string = Project.paint_objects[SlotLayer.get_object_mask(l) - 1].base.name; if (name.substr(name.length - 5, 2) == ".1") { // tile.1001 - udimTiles.push(name.substr(name.length - 5)); + udim_tiles.push(name.substr(name.length - 5)); } } } - if (udimTiles.length > 0) { - for (let udimTile of udimTiles) ExportTexture.run_layers(path, Project.layers, udimTile); + if (udim_tiles.length > 0) { + for (let udim_tile of udim_tiles) ExportTexture.run_layers(path, Project.layers, udim_tile); } else ExportTexture.run_layers(path, Project.layers); } else if (Context.raw.layers_export == export_mode_t.PER_OBJECT) { - let objectNames: string[] = []; + let object_names: string[] = []; for (let l of Project.layers) { if (SlotLayer.get_object_mask(l) > 0) { let name: string = Project.paint_objects[SlotLayer.get_object_mask(l) - 1].base.name; - if (objectNames.indexOf(name) == -1) { - objectNames.push(name); + if (object_names.indexOf(name) == -1) { + object_names.push(name); } } } - if (objectNames.length > 0) { - for (let name of objectNames) ExportTexture.run_layers(path, Project.layers, name); + if (object_names.length > 0) { + for (let name of object_names) ExportTexture.run_layers(path, Project.layers, name); } else ExportTexture.run_layers(path, Project.layers); } else { // Visible or selected - let atlasExport: bool = false; + let atlas_export: bool = false; if (Project.atlas_objects != null) { for (let i: i32 = 1; i < Project.atlas_objects.length; ++i) { if (Project.atlas_objects[i - 1] != Project.atlas_objects[i]) { - atlasExport = true; + atlas_export = true; break; } } } - if (atlasExport) { - for (let atlasIndex: i32 = 0; atlasIndex < Project.atlas_objects.length; ++atlasIndex) { + if (atlas_export) { + for (let atlas_index: i32 = 0; atlas_index < Project.atlas_objects.length; ++atlas_index) { let layers: SlotLayerRaw[] = []; - for (let objectIndex: i32 = 0; objectIndex < Project.atlas_objects.length; ++objectIndex) { - if (Project.atlas_objects[objectIndex] == atlasIndex) { + for (let object_index: i32 = 0; object_index < Project.atlas_objects.length; ++object_index) { + if (Project.atlas_objects[object_index] == atlas_index) { for (let l of Project.layers) { - if (SlotLayer.get_object_mask(l) == 0 /* shared object */ || SlotLayer.get_object_mask(l) - 1 == objectIndex) layers.push(l); + if (SlotLayer.get_object_mask(l) == 0 /* shared object */ || SlotLayer.get_object_mask(l) - 1 == object_index) layers.push(l); } } } if (layers.length > 0) { - ExportTexture.run_layers(path, layers, Project.atlas_names[atlasIndex]); + ExportTexture.run_layers(path, layers, Project.atlas_names[atlas_index]); } } } @@ -86,14 +86,14 @@ class ExportTexture { ///if is_paint static run_bake_material = (path: string) => { - if (RenderPathPaint.liveLayer == null) { - RenderPathPaint.liveLayer = SlotLayer.create("_live"); + if (RenderPathPaint.live_layer == null) { + RenderPathPaint.live_layer = SlotLayer.create("_live"); } let _tool: workspace_tool_t = Context.raw.tool; Context.raw.tool = workspace_tool_t.FILL; MakeMaterial.parse_paint_material(); - let _paintObject: mesh_object_t = Context.raw.paint_object; + let _paint_object: mesh_object_t = Context.raw.paint_object; let planeo: mesh_object_t = scene_get_child(".Plane").ext; planeo.base.visible = true; Context.raw.paint_object = planeo; @@ -105,166 +105,166 @@ class ExportTexture { MakeMaterial.parse_paint_material(); Context.raw.pdirty = 0; planeo.base.visible = false; - Context.raw.paint_object = _paintObject; + Context.raw.paint_object = _paint_object; - ExportTexture.run_layers(path, [RenderPathPaint.liveLayer], "", true); + ExportTexture.run_layers(path, [RenderPathPaint.live_layer], "", true); } ///end ///if is_paint - static run_layers = (path: string, layers: SlotLayerRaw[], objectName: string = "", bakeMaterial: bool = false) => { + static run_layers = (path: string, layers: SlotLayerRaw[], object_name: string = "", bake_material: bool = false) => { ///end ///if is_lab - static run_layers = (path: string, layers: any[], objectName: string = "") => { + static run_layers = (path: string, layers: any[], object_name: string = "") => { ///end - let textureSizeX: i32 = Config.get_texture_res_x(); - let textureSizeY: i32 = Config.get_texture_res_y(); + let texture_size_x: i32 = Config.get_texture_res_x(); + let texture_size_y: i32 = Config.get_texture_res_y(); ///if (krom_android || krom_ios) let f: string = sys_title(); ///else let f: string = UIFiles.filename; ///end if (f == "") f = tr("untitled"); - let formatType: texture_ldr_format_t = Context.raw.format_type; - let bits: i32 = Base.bits_handle.position == texture_bits_t.BITS8 ? 8 : 16; - let ext: string = bits == 16 ? ".exr" : formatType == texture_ldr_format_t.PNG ? ".png" : ".jpg"; + let format_type: texture_ldr_format_t = Context.raw.format_type; + let bits: i32 = base_bits_handle.position == texture_bits_t.BITS8 ? 8 : 16; + let ext: string = bits == 16 ? ".exr" : format_type == texture_ldr_format_t.PNG ? ".png" : ".jpg"; if (f.endsWith(ext)) f = f.substr(0, f.length - 4); ///if is_paint - let isUdim: bool = Context.raw.layers_export == export_mode_t.PER_UDIM_TILE; - if (isUdim) ext = objectName + ext; + let is_udim: bool = Context.raw.layers_export == export_mode_t.PER_UDIM_TILE; + if (is_udim) ext = object_name + ext; - Base.make_temp_img(); - Base.make_export_img(); - if (Base.pipe_merge == null) Base.make_pipe(); + base_make_temp_img(); + base_make_export_img(); + if (base_pipe_merge == null) base_make_pipe(); if (const_data_screen_aligned_vb == null) const_data_create_screen_aligned_data(); let empty: image_t = render_path_render_targets.get("empty_white")._image; // Append object mask name - let exportSelected: bool = Context.raw.layers_export == export_mode_t.SELECTED; - if (exportSelected && SlotLayer.get_object_mask(layers[0]) > 0) { + let export_selected: bool = Context.raw.layers_export == export_mode_t.SELECTED; + if (export_selected && SlotLayer.get_object_mask(layers[0]) > 0) { f += "_" + Project.paint_objects[SlotLayer.get_object_mask(layers[0]) - 1].base.name; } - if (!isUdim && !exportSelected && objectName != "") { - f += "_" + objectName; + if (!is_udim && !export_selected && object_name != "") { + f += "_" + object_name; } // Clear export layer - g4_begin(Base.expa); + g4_begin(base_expa); g4_clear(color_from_floats(0.0, 0.0, 0.0, 0.0)); g4_end(); - g4_begin(Base.expb); + g4_begin(base_expb); g4_clear(color_from_floats(0.5, 0.5, 1.0, 0.0)); g4_end(); - g4_begin(Base.expc); + g4_begin(base_expc); g4_clear(color_from_floats(1.0, 0.0, 0.0, 0.0)); g4_end(); // Flatten layers for (let l1 of layers) { - if (!exportSelected && !SlotLayer.is_visible(l1)) continue; + if (!export_selected && !SlotLayer.is_visible(l1)) continue; if (!SlotLayer.is_layer(l1)) continue; - if (objectName != "" && SlotLayer.get_object_mask(l1) > 0) { - if (isUdim && !Project.paint_objects[SlotLayer.get_object_mask(l1) - 1].base.name.endsWith(objectName)) continue; - let perObject: bool = Context.raw.layers_export == export_mode_t.PER_OBJECT; - if (perObject && Project.paint_objects[SlotLayer.get_object_mask(l1) - 1].base.name != objectName) continue; + if (object_name != "" && SlotLayer.get_object_mask(l1) > 0) { + if (is_udim && !Project.paint_objects[SlotLayer.get_object_mask(l1) - 1].base.name.endsWith(object_name)) continue; + let per_object: bool = Context.raw.layers_export == export_mode_t.PER_OBJECT; + if (per_object && Project.paint_objects[SlotLayer.get_object_mask(l1) - 1].base.name != object_name) continue; } let mask: image_t = empty; let l1masks: SlotLayerRaw[] = SlotLayer.get_masks(l1); - if (l1masks != null && !bakeMaterial) { + if (l1masks != null && !bake_material) { if (l1masks.length > 1) { - Base.make_temp_mask_img(); - g2_begin(Base.temp_mask_image); + base_make_temp_mask_img(); + g2_begin(base_temp_mask_image); g2_clear(0x00000000); g2_end(); - let l1: any = { texpaint: Base.temp_mask_image }; + let l1: any = { texpaint: base_temp_mask_image }; for (let i: i32 = 0; i < l1masks.length; ++i) { - Base.merge_layer(l1, l1masks[i]); + base_merge_layer(l1, l1masks[i]); } - mask = Base.temp_mask_image; + mask = base_temp_mask_image; } else mask = l1masks[0].texpaint; } - if (l1.paintBase) { - g2_begin(Base.temp_image); // Copy to temp - g2_set_pipeline(Base.pipe_copy); - g2_draw_image(Base.expa, 0, 0); + if (l1.paint_base) { + g2_begin(base_temp_image); // Copy to temp + g2_set_pipeline(base_pipe_copy); + g2_draw_image(base_expa, 0, 0); g2_set_pipeline(null); g2_end(); - g4_begin(Base.expa); - g4_set_pipeline(Base.pipe_merge); - g4_set_tex(Base.tex0, l1.texpaint); - g4_set_tex(Base.tex1, empty); - g4_set_tex(Base.texmask, mask); - g4_set_tex(Base.texa, Base.temp_image); - g4_set_float(Base.opac, SlotLayer.get_opacity(l1)); - g4_set_int(Base.blending, layers.length > 1 ? l1.blending : 0); + g4_begin(base_expa); + g4_set_pipeline(base_pipe_merge); + g4_set_tex(base_tex0, l1.texpaint); + g4_set_tex(base_tex1, empty); + g4_set_tex(base_texmask, mask); + g4_set_tex(base_texa, base_temp_image); + g4_set_float(base_opac, SlotLayer.get_opacity(l1)); + g4_set_int(base_blending, layers.length > 1 ? l1.blending : 0); g4_set_vertex_buffer(const_data_screen_aligned_vb); g4_set_index_buffer(const_data_screen_aligned_ib); g4_draw(); g4_end(); } - if (l1.paintNor) { - g2_begin(Base.temp_image); - g2_set_pipeline(Base.pipe_copy); - g2_draw_image(Base.expb, 0, 0); + if (l1.paint_nor) { + g2_begin(base_temp_image); + g2_set_pipeline(base_pipe_copy); + g2_draw_image(base_expb, 0, 0); g2_set_pipeline(null); g2_end(); - g4_begin(Base.expb); - g4_set_pipeline(Base.pipe_merge); - g4_set_tex(Base.tex0, l1.texpaint); - g4_set_tex(Base.tex1, l1.texpaint_nor); - g4_set_tex(Base.texmask, mask); - g4_set_tex(Base.texa, Base.temp_image); - g4_set_float(Base.opac, SlotLayer.get_opacity(l1)); - g4_set_int(Base.blending, l1.paintNorBlend ? -2 : -1); + g4_begin(base_expb); + g4_set_pipeline(base_pipe_merge); + g4_set_tex(base_tex0, l1.texpaint); + g4_set_tex(base_tex1, l1.texpaint_nor); + g4_set_tex(base_texmask, mask); + g4_set_tex(base_texa, base_temp_image); + g4_set_float(base_opac, SlotLayer.get_opacity(l1)); + g4_set_int(base_blending, l1.paint_nor_blend ? -2 : -1); g4_set_vertex_buffer(const_data_screen_aligned_vb); g4_set_index_buffer(const_data_screen_aligned_ib); g4_draw(); g4_end(); } - if (l1.paintOcc || l1.paintRough || l1.paintMet || l1.paintHeight) { - g2_begin(Base.temp_image); - g2_set_pipeline(Base.pipe_copy); - g2_draw_image(Base.expc, 0, 0); + if (l1.paint_occ || l1.paint_rough || l1.paint_met || l1.paint_height) { + g2_begin(base_temp_image); + g2_set_pipeline(base_pipe_copy); + g2_draw_image(base_expc, 0, 0); g2_set_pipeline(null); g2_end(); - if (l1.paintOcc && l1.paintRough && l1.paintMet && l1.paintHeight) { - Base.commands_merge_pack(Base.pipe_merge, Base.expc, l1.texpaint, l1.texpaint_pack, SlotLayer.get_opacity(l1), mask, l1.paintHeightBlend ? -3 : -1); + if (l1.paint_occ && l1.paint_rough && l1.paint_met && l1.paint_height) { + base_commands_merge_pack(base_pipe_merge, base_expc, l1.texpaint, l1.texpaint_pack, SlotLayer.get_opacity(l1), mask, l1.paint_height_blend ? -3 : -1); } else { - if (l1.paintOcc) Base.commands_merge_pack(Base.pipe_merge_r, Base.expc, l1.texpaint, l1.texpaint_pack, SlotLayer.get_opacity(l1), mask); - if (l1.paintRough) Base.commands_merge_pack(Base.pipe_merge_g, Base.expc, l1.texpaint, l1.texpaint_pack, SlotLayer.get_opacity(l1), mask); - if (l1.paintMet) Base.commands_merge_pack(Base.pipe_merge_b, Base.expc, l1.texpaint, l1.texpaint_pack, SlotLayer.get_opacity(l1), mask); + if (l1.paint_occ) base_commands_merge_pack(base_pipe_merge_r, base_expc, l1.texpaint, l1.texpaint_pack, SlotLayer.get_opacity(l1), mask); + if (l1.paint_rough) base_commands_merge_pack(base_pipe_merge_g, base_expc, l1.texpaint, l1.texpaint_pack, SlotLayer.get_opacity(l1), mask); + if (l1.paint_met) base_commands_merge_pack(base_pipe_merge_b, base_expc, l1.texpaint, l1.texpaint_pack, SlotLayer.get_opacity(l1), mask); } } } ///if krom_metal // Flush command list - g2_begin(Base.expa); + g2_begin(base_expa); g2_end(); - g2_begin(Base.expb); + g2_begin(base_expb); g2_end(); - g2_begin(Base.expc); + g2_begin(base_expc); g2_end(); ///end ///end ///if is_paint - let texpaint: image_t = Base.expa; - let texpaint_nor: image_t = Base.expb; - let texpaint_pack: image_t = Base.expc; + let texpaint: image_t = base_expa; + let texpaint_nor: image_t = base_expb; + let texpaint_pack: image_t = base_expc; ///end ///if is_lab @@ -290,7 +290,7 @@ class ExportTexture { for (let t of preset.textures) { let c: string[] = t.channels; let tex_name = t.name != "" ? "_" + t.name : ""; - let singleChannel: bool = c[0] == c[1] && c[1] == c[2] && c[3] == "1.0"; + let single_channel: bool = c[0] == c[1] && c[1] == c[2] && c[3] == "1.0"; if (c[0] == "base_r" && c[1] == "base_g" && c[2] == "base_b" && c[3] == "1.0" && t.color_space == "linear") { ExportTexture.write_texture(path + Path.sep + f + tex_name + ext, pixpaint, 1); } @@ -300,23 +300,23 @@ class ExportTexture { else if (c[0] == "occ" && c[1] == "rough" && c[2] == "metal" && c[3] == "1.0" && t.color_space == "linear") { ExportTexture.write_texture(path + Path.sep + f + tex_name + ext, pixpaint_pack, 1); } - else if (singleChannel && c[0] == "occ" && t.color_space == "linear") { + else if (single_channel && c[0] == "occ" && t.color_space == "linear") { ExportTexture.write_texture(path + Path.sep + f + tex_name + ext, pixpaint_pack, 2, 0); } - else if (singleChannel && c[0] == "rough" && t.color_space == "linear") { + else if (single_channel && c[0] == "rough" && t.color_space == "linear") { ExportTexture.write_texture(path + Path.sep + f + tex_name + ext, pixpaint_pack, 2, 1); } - else if (singleChannel && c[0] == "metal" && t.color_space == "linear") { + else if (single_channel && c[0] == "metal" && t.color_space == "linear") { ExportTexture.write_texture(path + Path.sep + f + tex_name + ext, pixpaint_pack, 2, 2); } - else if (singleChannel && c[0] == "height" && t.color_space == "linear") { + else if (single_channel && c[0] == "height" && t.color_space == "linear") { ExportTexture.write_texture(path + Path.sep + f + tex_name + ext, pixpaint_pack, 2, 3); } - else if (singleChannel && c[0] == "opac" && t.color_space == "linear") { + else if (single_channel && c[0] == "opac" && t.color_space == "linear") { ExportTexture.write_texture(path + Path.sep + f + tex_name + ext, pixpaint, 2, 3); } else { - if (pix == null) pix = new ArrayBuffer(textureSizeX * textureSizeY * 4 * Math.floor(bits / 8)); + if (pix == null) pix = new ArrayBuffer(texture_size_x * texture_size_y * 4 * Math.floor(bits / 8)); for (let i: i32 = 0; i < 4; ++i) { let c: string = t.channels[i]; if (c == "base_r") ExportTexture.copy_channel(new DataView(pixpaint), 0, new DataView(pix), i, t.color_space == "linear"); @@ -348,10 +348,10 @@ class ExportTexture { } static write_texture = (file: string, pixels: ArrayBuffer, type: i32 = 1, off: i32 = 0) => { - let resX: i32 = Config.get_texture_res_x(); - let resY: i32 = Config.get_texture_res_y(); - let bitsHandle: i32 = Base.bits_handle.position; - let bits: i32 = bitsHandle == texture_bits_t.BITS8 ? 8 : bitsHandle == texture_bits_t.BITS16 ? 16 : 32; + let res_x: i32 = Config.get_texture_res_x(); + let res_y: i32 = Config.get_texture_res_y(); + let bits_handle: i32 = base_bits_handle.position; + let bits: i32 = bits_handle == texture_bits_t.BITS8 ? 8 : bits_handle == texture_bits_t.BITS16 ? 16 : 32; let format: i32 = 0; // RGBA if (type == 1) format = 2; // RGB1 if (type == 2 && off == 0) format = 3; // RRR1 @@ -360,7 +360,7 @@ class ExportTexture { if (type == 2 && off == 3) format = 6; // AAA1 if (Context.raw.layers_destination == export_destination_t.PACKED) { - let image: image_t = image_from_bytes(pixels, resX, resY); + let image: image_t = image_from_bytes(pixels, res_x, res_y); data_cached_images.set(file, image); let ar: string[] = file.split(Path.sep); let name: string = ar[ar.length - 1]; @@ -375,13 +375,13 @@ class ExportTexture { } if (bits == 8 && Context.raw.format_type == texture_ldr_format_t.PNG) { - krom_write_png(file, pixels, resX, resY, format); + krom_write_png(file, pixels, res_x, res_y, format); } else if (bits == 8 && Context.raw.format_type == texture_ldr_format_t.JPG) { - krom_write_jpg(file, pixels, resX, resY, format, Math.floor(Context.raw.format_quality)); + krom_write_jpg(file, pixels, res_x, res_y, format, Math.floor(Context.raw.format_quality)); } else { // Exr - let b: ArrayBuffer = ParserExr.run(resX, resY, pixels, bits, type, off); + let b: ArrayBuffer = ParserExr.run(res_x, res_y, pixels, bits, type, off); krom_file_save_bytes(file, b, b.byteLength); } } diff --git a/base/Sources/File.ts b/base/Sources/File.ts index 9ee2041c..797a229b 100644 --- a/base/Sources/File.ts +++ b/base/Sources/File.ts @@ -16,7 +16,7 @@ class File { // static let internal: Map = null; // .apk contents // ///end - static read_directory = (path: string, foldersOnly: bool = false): string[] => { + static read_directory = (path: string, folders_only: bool = false): string[] => { if (path.startsWith("cloud")) { let files: string[] = File.cloud != null ? File.cloud.get(string_replace_all(path, "\\", "/")) : null; return files != null ? files : []; @@ -34,15 +34,15 @@ class File { // } // if (internal.exists(path)) return internal.get(path); // ///end - return krom_read_directory(path, foldersOnly).split("\n"); + return krom_read_directory(path, folders_only).split("\n"); } static create_directory = (path: string) => { krom_sys_command(File.cmd_mkdir + ' "' + path + '"'); } - static copy = (srcPath: string, dstPath: string) => { - krom_sys_command(File.cmd_copy + ' "' + srcPath + '" "' + dstPath + '"'); + static copy = (srcPath: string, dst_path: string) => { + krom_sys_command(File.cmd_copy + ' "' + srcPath + '" "' + dst_path + '"'); } static start = (path: string) => { @@ -110,9 +110,9 @@ class File { return; } - let fileDir: string = dest.substr(0, dest.lastIndexOf(Path.sep)); - if (File.read_directory(fileDir)[0] == "") { - File.create_directory(fileDir); + let file_dir: string = dest.substr(0, dest.lastIndexOf(Path.sep)); + if (File.read_directory(file_dir)[0] == "") { + File.create_directory(file_dir); } ///if krom_windows path = string_replace_all(path, "\\", "/"); @@ -180,8 +180,8 @@ class File { } } - let isTruncated: bool = str.indexOf("true") > -1; - if (isTruncated) { + let is_truncated: bool = str.indexOf("true") > -1; + if (is_truncated) { let pos_start: i32 = str.indexOf(""); pos_start += 23; let pos_end: i32 = str.indexOf("", pos_start); diff --git a/base/Sources/Geom.ts b/base/Sources/Geom.ts index aa742324..0e6c8be4 100644 --- a/base/Sources/Geom.ts +++ b/base/Sources/Geom.ts @@ -10,20 +10,20 @@ class Geom { mesh.hasNext = false; // Pack positions to (-1, 1) range - let halfX: f32 = size_x / 2; - let halfY: f32 = size_y / 2; - mesh.scalePos = Math.max(halfX, halfY); + let half_x: f32 = size_x / 2; + let half_y: f32 = size_y / 2; + mesh.scalePos = Math.max(half_x, half_y); let inv: f32 = (1 / mesh.scalePos) * 32767; mesh.posa = new Int16Array(verts_x * verts_y * 4); mesh.nora = new Int16Array(verts_x * verts_y * 2); mesh.texa = new Int16Array(verts_x * verts_y * 2); mesh.inda = new Uint32Array((verts_x - 1) * (verts_y - 1) * 6); - let stepX: f32 = size_x / (verts_x - 1); - let stepY: f32 = size_y / (verts_y - 1); + let step_x: f32 = size_x / (verts_x - 1); + let step_y: f32 = size_y / (verts_y - 1); for (let i: i32 = 0; i < verts_x * verts_y; ++i) { - let x: f32 = (i % verts_x) * stepX - halfX; - let y: f32 = Math.floor(i / verts_x) * stepY - halfY; + let x: f32 = (i % verts_x) * step_x - half_x; + let y: f32 = Math.floor(i / verts_x) * step_y - half_y; mesh.posa[i * 4 ] = Math.floor(x * inv); mesh.posa[i * 4 + 1] = Math.floor(y * inv); mesh.posa[i * 4 + 2] = 0; @@ -49,7 +49,7 @@ class Geom { return mesh; } - static make_uv_sphere(radius: f32 = 1.0, widthSegments: i32 = 32, heightSegments: i32 = 16, stretchUV: bool = true, uvScale: f32 = 1.0): raw_mesh_t { + static make_uv_sphere(radius: f32 = 1.0, widthSegments: i32 = 32, heightSegments: i32 = 16, stretch_uv: bool = true, uvScale: f32 = 1.0): raw_mesh_t { let mesh: raw_mesh_t = {}; mesh.scalePos = 1.0; @@ -63,28 +63,28 @@ class Geom { let inv: f32 = (1 / mesh.scalePos) * 32767; let pi2: f32 = Math.PI * 2; - let widthVerts: i32 = widthSegments + 1; - let heightVerts: i32 = heightSegments + 1; - mesh.posa = new Int16Array(widthVerts * heightVerts * 4); - mesh.nora = new Int16Array(widthVerts * heightVerts * 2); - mesh.texa = new Int16Array(widthVerts * heightVerts * 2); + let width_verts: i32 = widthSegments + 1; + let height_verts: i32 = heightSegments + 1; + mesh.posa = new Int16Array(width_verts * height_verts * 4); + mesh.nora = new Int16Array(width_verts * height_verts * 2); + mesh.texa = new Int16Array(width_verts * height_verts * 2); mesh.inda = new Uint32Array(widthSegments * heightSegments * 6 - widthSegments * 6); let nor: vec4_t = vec4_create(); let pos: i32 = 0; - for (let y: i32 = 0; y < heightVerts; ++y) { + for (let y: i32 = 0; y < height_verts; ++y) { let v: f32 = y / heightSegments; - let vFlip: f32 = 1.0 - v; - if (!stretchUV) vFlip /= 2; - let uOff: f32 = y == 0 ? 0.5 / widthSegments : y == heightSegments ? -0.5 / widthSegments : 0.0; - for (let x: i32 = 0; x < widthVerts; ++x) { + let v_flip: f32 = 1.0 - v; + if (!stretch_uv) v_flip /= 2; + let u_off: f32 = y == 0 ? 0.5 / widthSegments : y == heightSegments ? -0.5 / widthSegments : 0.0; + for (let x: i32 = 0; x < width_verts; ++x) { let u: f32 = x / widthSegments; - let uPI2: f32 = u * pi2; - let vPI: f32 = v * Math.PI; - let vPIsin: f32 = Math.sin(vPI); - let vx: f32 = -radius * Math.cos(uPI2) * vPIsin; - let vy: f32 = radius * Math.sin(uPI2) * vPIsin; - let vz: f32 = -radius * Math.cos(vPI); + let u_pi2: f32 = u * pi2; + let v_pi: f32 = v * Math.PI; + let v_pi_sin: f32 = Math.sin(v_pi); + let vx: f32 = -radius * Math.cos(u_pi2) * v_pi_sin; + let vy: f32 = radius * Math.sin(u_pi2) * v_pi_sin; + let vz: f32 = -radius * Math.cos(v_pi); let i4: i32 = pos * 4; let i2: i32 = pos * 2; mesh.posa[i4 ] = Math.floor(vx * inv); @@ -94,28 +94,28 @@ class Geom { mesh.posa[i4 + 3] = Math.floor(nor.z * 32767); mesh.nora[i2 ] = Math.floor(nor.x * 32767); mesh.nora[i2 + 1] = Math.floor(nor.y * 32767); - mesh.texa[i2 ] = (Math.floor((u + uOff) * 32767) - 1) % 32767; - mesh.texa[i2 + 1] = (Math.floor(vFlip * 32767) - 1) % 32767; + mesh.texa[i2 ] = (Math.floor((u + u_off) * 32767) - 1) % 32767; + mesh.texa[i2 + 1] = (Math.floor(v_flip * 32767) - 1) % 32767; pos++; } } pos = 0; - let heightSegments1: i32 = heightSegments - 1; + let height_segments1: i32 = heightSegments - 1; for (let y: i32 = 0; y < heightSegments; ++y) { for (let x: i32 = 0; x < widthSegments; ++x) { let x1: i32 = x + 1; let y1: i32 = y + 1; - let a: f32 = y * widthVerts + x1; - let b: f32 = y * widthVerts + x; - let c: f32 = y1 * widthVerts + x; - let d: f32 = y1 * widthVerts + x1; + let a: f32 = y * width_verts + x1; + let b: f32 = y * width_verts + x; + let c: f32 = y1 * width_verts + x; + let d: f32 = y1 * width_verts + x1; if (y > 0) { mesh.inda[pos++] = a; mesh.inda[pos++] = b; mesh.inda[pos++] = d; } - if (y < heightSegments1) { + if (y < height_segments1) { mesh.inda[pos++] = b; mesh.inda[pos++] = c; mesh.inda[pos++] = d; diff --git a/base/Sources/Gizmo.ts b/base/Sources/Gizmo.ts index 8744d69c..19fc8b92 100644 --- a/base/Sources/Gizmo.ts +++ b/base/Sources/Gizmo.ts @@ -9,26 +9,26 @@ class Gizmo { static q0: quat_t = quat_create(); static update = () => { - let isObject: bool = Context.raw.tool == workspace_tool_t.GIZMO; - let isDecal: bool = Base.is_decal_layer(); + let is_object: bool = Context.raw.tool == workspace_tool_t.GIZMO; + let is_decal: bool = base_is_decal_layer(); let gizmo: object_t = Context.raw.gizmo; let hide: bool = Operator.shortcut(Config.keymap.stencil_hide, ShortcutType.ShortcutDown); - gizmo.visible = (isObject || isDecal) && !hide; + gizmo.visible = (is_object || is_decal) && !hide; if (!gizmo.visible) return; - let paintObject: object_t = Context.raw.paint_object.base; + let paint_object: object_t = Context.raw.paint_object.base; ///if is_forge if (Context.raw.selected_object != null) { - paintObject = Context.raw.selected_object; + paint_object = Context.raw.selected_object; } ///end - if (isObject) { - vec4_set_from(gizmo.transform.loc, paintObject.transform.loc); + if (is_object) { + vec4_set_from(gizmo.transform.loc, paint_object.transform.loc); } - else if (isDecal) { - vec4_set(gizmo.transform.loc, Context.raw.layer.decalMat.m[12], Context.raw.layer.decalMat.m[13], Context.raw.layer.decalMat.m[14]); + else if (is_decal) { + vec4_set(gizmo.transform.loc, Context.raw.layer.decal_mat.m[12], Context.raw.layer.decal_mat.m[13], Context.raw.layer.decal_mat.m[14]); } let cam: camera_object_t = scene_camera; let fov: f32 = cam.data.fov; @@ -46,103 +46,103 @@ class Gizmo { transform_build_matrix(gizmo.transform); // Scene control - if (isObject) { + if (is_object) { if (Context.raw.translate_x || Context.raw.translate_y || Context.raw.translate_z || Context.raw.scale_x || Context.raw.scale_y || Context.raw.scale_z || Context.raw.rotate_x || Context.raw.rotate_y || Context.raw.rotate_z) { if (Context.raw.translate_x) { - paintObject.transform.loc.x = Context.raw.gizmo_drag; + paint_object.transform.loc.x = Context.raw.gizmo_drag; } else if (Context.raw.translate_y) { - paintObject.transform.loc.y = Context.raw.gizmo_drag; + paint_object.transform.loc.y = Context.raw.gizmo_drag; } else if (Context.raw.translate_z) { - paintObject.transform.loc.z = Context.raw.gizmo_drag; + paint_object.transform.loc.z = Context.raw.gizmo_drag; } else if (Context.raw.scale_x) { - paintObject.transform.scale.x += Context.raw.gizmo_drag - Context.raw.gizmo_drag_last; + paint_object.transform.scale.x += Context.raw.gizmo_drag - Context.raw.gizmo_drag_last; } else if (Context.raw.scale_y) { - paintObject.transform.scale.y += Context.raw.gizmo_drag - Context.raw.gizmo_drag_last; + paint_object.transform.scale.y += Context.raw.gizmo_drag - Context.raw.gizmo_drag_last; } else if (Context.raw.scale_z) { - paintObject.transform.scale.z += Context.raw.gizmo_drag - Context.raw.gizmo_drag_last; + paint_object.transform.scale.z += Context.raw.gizmo_drag - Context.raw.gizmo_drag_last; } else if (Context.raw.rotate_x) { quat_from_axis_angle(Gizmo.q0, vec4_x_axis(), Context.raw.gizmo_drag - Context.raw.gizmo_drag_last); - quat_mult(paintObject.transform.rot, Gizmo.q0); + quat_mult(paint_object.transform.rot, Gizmo.q0); } else if (Context.raw.rotate_y) { quat_from_axis_angle(Gizmo.q0, vec4_y_axis(), Context.raw.gizmo_drag - Context.raw.gizmo_drag_last); - quat_mult(paintObject.transform.rot, Gizmo.q0); + quat_mult(paint_object.transform.rot, Gizmo.q0); } else if (Context.raw.rotate_z) { quat_from_axis_angle(Gizmo.q0, vec4_z_axis(), Context.raw.gizmo_drag - Context.raw.gizmo_drag_last); - quat_mult(paintObject.transform.rot, Gizmo.q0); + quat_mult(paint_object.transform.rot, Gizmo.q0); } Context.raw.gizmo_drag_last = Context.raw.gizmo_drag; - transform_build_matrix(paintObject.transform); + transform_build_matrix(paint_object.transform); ///if arm_physics - let pb: any = (paintObject as any).physicsBody; + let pb: any = (paint_object as any).physicsBody; if (pb != null) pb.syncTransform(); ///end } } // Decal layer control - else if (isDecal) { + else if (is_decal) { if (Context.raw.translate_x || Context.raw.translate_y || Context.raw.translate_z || Context.raw.scale_x || Context.raw.scale_y || Context.raw.scale_z || Context.raw.rotate_x || Context.raw.rotate_y || Context.raw.rotate_z) { if (Context.raw.translate_x) { - Context.raw.layer.decalMat.m[12] = Context.raw.gizmo_drag; + Context.raw.layer.decal_mat.m[12] = Context.raw.gizmo_drag; } else if (Context.raw.translate_y) { - Context.raw.layer.decalMat.m[13] = Context.raw.gizmo_drag; + Context.raw.layer.decal_mat.m[13] = Context.raw.gizmo_drag; } else if (Context.raw.translate_z) { - Context.raw.layer.decalMat.m[14] = Context.raw.gizmo_drag; + Context.raw.layer.decal_mat.m[14] = Context.raw.gizmo_drag; } else if (Context.raw.scale_x) { - mat4_decompose(Context.raw.layer.decalMat, Gizmo.v, Gizmo.q, Gizmo.v0); + mat4_decompose(Context.raw.layer.decal_mat, Gizmo.v, Gizmo.q, Gizmo.v0); Gizmo.v0.x += Context.raw.gizmo_drag - Context.raw.gizmo_drag_last; - mat4_compose(Context.raw.layer.decalMat, Gizmo.v, Gizmo.q, Gizmo.v0); + mat4_compose(Context.raw.layer.decal_mat, Gizmo.v, Gizmo.q, Gizmo.v0); } else if (Context.raw.scale_y) { - mat4_decompose(Context.raw.layer.decalMat, Gizmo.v, Gizmo.q, Gizmo.v0); + mat4_decompose(Context.raw.layer.decal_mat, Gizmo.v, Gizmo.q, Gizmo.v0); Gizmo.v0.y += Context.raw.gizmo_drag - Context.raw.gizmo_drag_last; - mat4_compose(Context.raw.layer.decalMat, Gizmo.v, Gizmo.q, Gizmo.v0); + mat4_compose(Context.raw.layer.decal_mat, Gizmo.v, Gizmo.q, Gizmo.v0); } else if (Context.raw.scale_z) { - mat4_decompose(Context.raw.layer.decalMat, Gizmo.v, Gizmo.q, Gizmo.v0); + mat4_decompose(Context.raw.layer.decal_mat, Gizmo.v, Gizmo.q, Gizmo.v0); Gizmo.v0.z += Context.raw.gizmo_drag - Context.raw.gizmo_drag_last; - mat4_compose(Context.raw.layer.decalMat, Gizmo.v, Gizmo.q, Gizmo.v0); + mat4_compose(Context.raw.layer.decal_mat, Gizmo.v, Gizmo.q, Gizmo.v0); } else if (Context.raw.rotate_x) { - mat4_decompose(Context.raw.layer.decalMat, Gizmo.v, Gizmo.q, Gizmo.v0); + mat4_decompose(Context.raw.layer.decal_mat, Gizmo.v, Gizmo.q, Gizmo.v0); quat_from_axis_angle(Gizmo.q0, vec4_x_axis(), -Context.raw.gizmo_drag + Context.raw.gizmo_drag_last); quat_mult_quats(Gizmo.q, Gizmo.q0, Gizmo.q); - mat4_compose(Context.raw.layer.decalMat, Gizmo.v, Gizmo.q, Gizmo.v0); + mat4_compose(Context.raw.layer.decal_mat, Gizmo.v, Gizmo.q, Gizmo.v0); } else if (Context.raw.rotate_y) { - mat4_decompose(Context.raw.layer.decalMat, Gizmo.v, Gizmo.q, Gizmo.v0); + mat4_decompose(Context.raw.layer.decal_mat, Gizmo.v, Gizmo.q, Gizmo.v0); quat_from_axis_angle(Gizmo.q0, vec4_y_axis(), -Context.raw.gizmo_drag + Context.raw.gizmo_drag_last); quat_mult_quats(Gizmo.q, Gizmo.q0, Gizmo.q); - mat4_compose(Context.raw.layer.decalMat, Gizmo.v, Gizmo.q, Gizmo.v0); + mat4_compose(Context.raw.layer.decal_mat, Gizmo.v, Gizmo.q, Gizmo.v0); } else if (Context.raw.rotate_z) { - mat4_decompose(Context.raw.layer.decalMat, Gizmo.v, Gizmo.q, Gizmo.v0); + mat4_decompose(Context.raw.layer.decal_mat, Gizmo.v, Gizmo.q, Gizmo.v0); quat_from_axis_angle(Gizmo.q0, vec4_z_axis(), Context.raw.gizmo_drag - Context.raw.gizmo_drag_last); quat_mult_quats(Gizmo.q, Gizmo.q0, Gizmo.q); - mat4_compose(Context.raw.layer.decalMat, Gizmo.v, Gizmo.q, Gizmo.v0); + mat4_compose(Context.raw.layer.decal_mat, Gizmo.v, Gizmo.q, Gizmo.v0); } Context.raw.gizmo_drag_last = Context.raw.gizmo_drag; if (Context.raw.material != Context.raw.layer.fill_layer) { Context.set_material(Context.raw.layer.fill_layer); } - Base.update_fill_layer(Context.raw.gizmo_started); + base_update_fill_layer(Context.raw.gizmo_started); } } Context.raw.gizmo_started = false; - if (mouse_started("left") && paintObject.name != "Scene") { + if (mouse_started("left") && paint_object.name != "Scene") { // Translate, scale let trs: transform_t[] = [ Context.raw.gizmo_translate_x.transform, @@ -193,12 +193,12 @@ class Gizmo { if (Context.raw.translate_x || Context.raw.translate_y || Context.raw.translate_z || Context.raw.scale_x || Context.raw.scale_y || Context.raw.scale_z || Context.raw.rotate_x || Context.raw.rotate_y || Context.raw.rotate_z) { Context.raw.rdirty = 2; - if (isObject) { - let t: transform_t = paintObject.transform; + if (is_object) { + let t: transform_t = paint_object.transform; vec4_set(Gizmo.v, transform_world_x(t), transform_world_y(t), transform_world_z(t)); } - else if (isDecal) { - vec4_set(Gizmo.v, Context.raw.layer.decalMat.m[12], Context.raw.layer.decalMat.m[13], Context.raw.layer.decalMat.m[14]); + else if (is_decal) { + vec4_set(Gizmo.v, Context.raw.layer.decal_mat.m[12], Context.raw.layer.decal_mat.m[13], Context.raw.layer.decal_mat.m[14]); } if (Context.raw.translate_x || Context.raw.scale_x) { @@ -226,7 +226,7 @@ class Gizmo { let hit: vec4_t = raycast_plane_intersect(vec4_x_axis(), Gizmo.v, mouse_view_x(), mouse_view_y(), scene_camera); if (hit != null) { if (Context.raw.gizmo_started) { - mat4_decompose(Context.raw.layer.decalMat, Gizmo.v, Gizmo.q, Gizmo.v0); + mat4_decompose(Context.raw.layer.decal_mat, Gizmo.v, Gizmo.q, Gizmo.v0); Context.raw.gizmo_offset = Math.atan2(hit.y - Gizmo.v.y, hit.z - Gizmo.v.z); } Context.raw.gizmo_drag = Math.atan2(hit.y - Gizmo.v.y, hit.z - Gizmo.v.z) - Context.raw.gizmo_offset; @@ -236,7 +236,7 @@ class Gizmo { let hit: vec4_t = raycast_plane_intersect(vec4_y_axis(), Gizmo.v, mouse_view_x(), mouse_view_y(), scene_camera); if (hit != null) { if (Context.raw.gizmo_started) { - mat4_decompose(Context.raw.layer.decalMat, Gizmo.v, Gizmo.q, Gizmo.v0); + mat4_decompose(Context.raw.layer.decal_mat, Gizmo.v, Gizmo.q, Gizmo.v0); Context.raw.gizmo_offset = Math.atan2(hit.z - Gizmo.v.z, hit.x - Gizmo.v.x); } Context.raw.gizmo_drag = Math.atan2(hit.z - Gizmo.v.z, hit.x - Gizmo.v.x) - Context.raw.gizmo_offset; @@ -246,7 +246,7 @@ class Gizmo { let hit: vec4_t = raycast_plane_intersect(vec4_z_axis(), Gizmo.v, mouse_view_x(), mouse_view_y(), scene_camera); if (hit != null) { if (Context.raw.gizmo_started) { - mat4_decompose(Context.raw.layer.decalMat, Gizmo.v, Gizmo.q, Gizmo.v0); + mat4_decompose(Context.raw.layer.decal_mat, Gizmo.v, Gizmo.q, Gizmo.v0); Context.raw.gizmo_offset = Math.atan2(hit.y - Gizmo.v.y, hit.x - Gizmo.v.x); } Context.raw.gizmo_drag = Math.atan2(hit.y - Gizmo.v.y, hit.x - Gizmo.v.x) - Context.raw.gizmo_offset; @@ -261,7 +261,7 @@ class Gizmo { ///end } - _input_occupied = (Context.raw.translate_x || Context.raw.translate_y || Context.raw.translate_z || Context.raw.scale_x || Context.raw.scale_y || Context.raw.scale_z || Context.raw.rotate_x || Context.raw.rotate_y || Context.raw.rotate_z) && mouse_view_x() < Base.w(); + _input_occupied = (Context.raw.translate_x || Context.raw.translate_y || Context.raw.translate_z || Context.raw.scale_x || Context.raw.scale_y || Context.raw.scale_z || Context.raw.rotate_x || Context.raw.rotate_y || Context.raw.rotate_z) && mouse_view_x() < base_w(); } } diff --git a/base/Sources/History.ts b/base/Sources/History.ts index fc4d2fbe..53662555 100644 --- a/base/Sources/History.ts +++ b/base/Sources/History.ts @@ -43,14 +43,14 @@ class History { History.undo_i = History.undo_i - 1 < 0 ? Config.raw.undo_steps - 1 : History.undo_i - 1; let lay: SlotLayerRaw = History.undo_layers[History.undo_i]; SlotLayer.swap(l, lay); - l.maskOpacity = step.layer_opacity; + l.mask_opacity = step.layer_opacity; l.blending = step.layer_blending; - l.objectMask = step.layer_object; + l.object_mask = step.layer_object; MakeMaterial.parse_mesh_material(); // Undo at least second time in order to avoid empty groups if (step.layer_type == layer_slot_type_t.GROUP) { - Base.notify_on_next_frame(() => { + base_notify_on_next_frame(() => { // 1. Undo deleting group masks let n: i32 = 1; while (History.steps[active - n].layer_type == layer_slot_type_t.MASK) { @@ -103,39 +103,39 @@ class History { lay = History.undo_layers[History.undo_i]; SlotLayer.swap(Context.raw.layer, lay); - Context.raw.layer.maskOpacity = step.layer_opacity; + Context.raw.layer.mask_opacity = step.layer_opacity; Context.raw.layer.blending = step.layer_blending; - Context.raw.layer.objectMask = step.layer_object; + Context.raw.layer.object_mask = step.layer_object; Context.raw.layers_preview_dirty = true; MakeMaterial.parse_mesh_material(); } else if (step.name == tr("Apply Mask")) { // First restore the layer(s) - let maskPosition: i32 = step.layer; - let currentLayer: SlotLayerRaw = null; + let mask_pos: i32 = step.layer; + let current_layer: SlotLayerRaw = null; // The layer at the old mask position is a mask, i.e. the layer had multiple masks before. - if (SlotLayer.is_mask(Project.layers[maskPosition])) { - currentLayer = Project.layers[maskPosition].parent; + if (SlotLayer.is_mask(Project.layers[mask_pos])) { + current_layer = Project.layers[mask_pos].parent; } - else if (SlotLayer.is_layer(Project.layers[maskPosition]) || SlotLayer.is_group(Project.layers[maskPosition])) { - currentLayer = Project.layers[maskPosition]; + else if (SlotLayer.is_layer(Project.layers[mask_pos]) || SlotLayer.is_group(Project.layers[mask_pos])) { + current_layer = Project.layers[mask_pos]; } - let layersToRestore: SlotLayerRaw[] = SlotLayer.is_group(currentLayer) ? SlotLayer.get_children(currentLayer) : [currentLayer]; - layersToRestore.reverse(); + let layers_to_restore: SlotLayerRaw[] = SlotLayer.is_group(current_layer) ? SlotLayer.get_children(current_layer) : [current_layer]; + layers_to_restore.reverse(); - for (let layer of layersToRestore) { + for (let layer of layers_to_restore) { // Replace the current layer's content with the old one Context.raw.layer = layer; History.undo_i = History.undo_i - 1 < 0 ? Config.raw.undo_steps - 1 : History.undo_i - 1; - let oldLayer: SlotLayerRaw = History.undo_layers[History.undo_i]; - SlotLayer.swap(Context.raw.layer, oldLayer); + let old_layer: SlotLayerRaw = History.undo_layers[History.undo_i]; + SlotLayer.swap(Context.raw.layer, old_layer); } // Now restore the applied mask History.undo_i = History.undo_i - 1 < 0 ? Config.raw.undo_steps - 1 : History.undo_i - 1; let mask: SlotLayerRaw = History.undo_layers[History.undo_i]; - Base.new_mask(false, currentLayer, maskPosition); + base_new_mask(false, current_layer, mask_pos); SlotLayer.swap(Context.raw.layer, mask); Context.raw.layers_preview_dirty = true; Context.set_layer(Context.raw.layer); @@ -152,7 +152,7 @@ class History { let lay: SlotLayerRaw = History.undo_layers[History.undo_i]; Context.set_layer(Project.layers[step.layer]); SlotLayer.swap(Context.raw.layer, lay); - Base.new_mask(false, Context.raw.layer); + base_new_mask(false, Context.raw.layer); SlotLayer.swap(Context.raw.layer, lay); Context.raw.layer_preview_dirty = true; } @@ -170,8 +170,8 @@ class History { } else if (step.name == tr("Layer Opacity")) { Context.set_layer(Project.layers[step.layer]); - let t: f32 = Context.raw.layer.maskOpacity; - Context.raw.layer.maskOpacity = step.layer_opacity; + let t: f32 = Context.raw.layer.mask_opacity; + Context.raw.layer.mask_opacity = step.layer_opacity; step.layer_opacity = t; MakeMaterial.parse_mesh_material(); } @@ -247,17 +247,17 @@ class History { let l: SlotLayerRaw = SlotLayer.create("", step.layer_type, parent); Project.layers.splice(step.layer, 0, l); if (step.name == tr("New Black Mask")) { - Base.notify_on_next_frame(() => { + base_notify_on_next_frame(() => { SlotLayer.clear(l, 0x00000000); }); } else if (step.name == tr("New White Mask")) { - Base.notify_on_next_frame(() => { + base_notify_on_next_frame(() => { SlotLayer.clear(l, 0xffffffff); }); } else if (step.name == tr("New Fill Mask")) { - Base.notify_on_next_frame(() => { + base_notify_on_next_frame(() => { Context.raw.material = Project.materials[step.material]; SlotLayer.to_fill_layer(l); }); @@ -267,7 +267,7 @@ class History { } else if (step.name == tr("New Group")) { let l: SlotLayerRaw = Project.layers[step.layer - 1]; - let group: SlotLayerRaw = Base.new_group(); + let group: SlotLayerRaw = base_new_group(); array_remove(Project.layers, group); Project.layers.splice(step.layer, 0, group); l.parent = group; @@ -285,7 +285,7 @@ class History { while (History.steps[active + n].layer_type == layer_slot_type_t.MASK) { ++n; } - Base.notify_on_next_frame(() => { + base_notify_on_next_frame(() => { for (let i: i32 = 0; i < n; ++i) History.redo(); }); } @@ -299,9 +299,9 @@ class History { else if (step.name == tr("Duplicate Layer")) { Context.raw.layer = Project.layers[step.layer]; let _next = () => { - Base.duplicate_layer(Context.raw.layer); + base_duplicate_layer(Context.raw.layer); } - Base.notify_on_next_frame(_next); + base_notify_on_next_frame(_next); } else if (step.name == tr("Order Layers")) { let target: SlotLayerRaw = Project.layers[step.prev_order]; @@ -311,7 +311,7 @@ class History { else if (step.name == tr("Merge Layers")) { Context.raw.layer = Project.layers[step.layer + 1]; app_notify_on_init(History.redo_merge_layers); - app_notify_on_init(Base.merge_down); + app_notify_on_init(base_merge_down); } else if (step.name == tr("Apply Mask")) { Context.raw.layer = Project.layers[step.layer]; @@ -328,7 +328,7 @@ class History { Context.set_layer(Context.raw.layer); Context.raw.layers_preview_dirty = true; } - Base.notify_on_next_frame(_next); + base_notify_on_next_frame(_next); } else if (step.name == tr("Invert Mask")) { let _next = () => { @@ -341,7 +341,7 @@ class History { let lay: SlotLayerRaw = History.undo_layers[History.undo_i]; Context.set_layer(Project.layers[step.layer]); SlotLayer.swap(Context.raw.layer, lay); - Base.new_mask(false, lay); + base_new_mask(false, lay); SlotLayer.swap(Context.raw.layer, lay); Context.raw.layer_preview_dirty = true; History.undo_i = (History.undo_i + 1) % Config.raw.undo_steps; @@ -360,8 +360,8 @@ class History { } else if (step.name == tr("Layer Opacity")) { Context.set_layer(Project.layers[step.layer]); - let t: f32 = Context.raw.layer.maskOpacity; - Context.raw.layer.maskOpacity = step.layer_opacity; + let t: f32 = Context.raw.layer.mask_opacity; + Context.raw.layer.mask_opacity = step.layer_opacity; step.layer_opacity = t; MakeMaterial.parse_mesh_material(); } @@ -451,8 +451,8 @@ class History { ///if (is_paint || is_sculpt) static paint = () => { - let isMask: bool = SlotLayer.is_mask(Context.raw.layer); - History.copy_to_undo(Context.raw.layer.id, History.undo_i, isMask); + let is_mask: bool = SlotLayer.is_mask(Context.raw.layer); + History.copy_to_undo(Context.raw.layer.id, History.undo_i, is_mask); History.push_undo = false; History.push(tr(UIToolbar.tool_names[Context.raw.tool])); @@ -620,8 +620,8 @@ class History { object: opos, material: mpos, brush: bpos, - layer_opacity: Context.raw.layer.maskOpacity, - layer_object: Context.raw.layer.objectMask, + layer_opacity: Context.raw.layer.mask_opacity, + layer_object: Context.raw.layer.object_mask, layer_blending: Context.raw.layer.blending }); ///end @@ -656,8 +656,8 @@ class History { } static swap_active = () => { - let undoLayer: SlotLayerRaw = History.undo_layers[History.undo_i]; - SlotLayer.swap(undoLayer, Context.raw.layer); + let undo_layer: SlotLayerRaw = History.undo_layers[History.undo_i]; + SlotLayer.swap(undo_layer, Context.raw.layer); History.undo_i = (History.undo_i + 1) % Config.raw.undo_steps; } diff --git a/base/Sources/ImportArm.ts b/base/Sources/ImportArm.ts index 3c48746c..98af0ddd 100644 --- a/base/Sources/ImportArm.ts +++ b/base/Sources/ImportArm.ts @@ -22,16 +22,16 @@ class ImportArm { return; } - let importAsMesh: bool = project.version == null; + let import_as_mesh: bool = project.version == null; Context.raw.layers_preview_dirty = true; Context.raw.layer_filter = 0; ///end ///if is_lab - let importAsMesh: bool = true; + let import_as_mesh: bool = true; ///end - Project.project_new(importAsMesh); + Project.project_new(import_as_mesh); Project.filepath = path; UIFiles.filename = path.substring(path.lastIndexOf(Path.sep) + 1, path.lastIndexOf(".")); ///if (krom_android || krom_ios) @@ -42,7 +42,7 @@ class ImportArm { ///if (is_paint || is_sculpt) // Import as mesh instead - if (importAsMesh) { + if (import_as_mesh) { ImportArm.run_mesh(project); return; } @@ -63,10 +63,10 @@ class ImportArm { ///if (is_paint || is_sculpt) let l0: layer_data_t = project.layer_datas[0]; - Base.res_handle.position = Config.get_texture_res_pos(l0.res); - let bitsPos: texture_bits_t = l0.bpp == 8 ? texture_bits_t.BITS8 : l0.bpp == 16 ? texture_bits_t.BITS16 : texture_bits_t.BITS32; - Base.bits_handle.position = bitsPos; - let bytesPerPixel: i32 = Math.floor(l0.bpp / 8); + base_res_handle.position = Config.get_texture_res_pos(l0.res); + let bits_pos: texture_bits_t = l0.bpp == 8 ? texture_bits_t.BITS8 : l0.bpp == 16 ? texture_bits_t.BITS16 : texture_bits_t.BITS32; + base_bits_handle.position = bits_pos; + let bytes_per_pixel: i32 = Math.floor(l0.bpp / 8); let format: tex_format_t = l0.bpp == 8 ? tex_format_t.RGBA32 : l0.bpp == 16 ? tex_format_t.RGBA64 : tex_format_t.RGBA128; ///end @@ -103,8 +103,8 @@ class ImportArm { if (data_cached_images.get(abs) == null && !File.exists(abs)) { ImportArm.make_pink(abs); } - let hdrAsEnvmap: bool = abs.endsWith(".hdr") && Project.raw.envmap == abs; - ImportTexture.run(abs, hdrAsEnvmap); + let hdr_as_envmap: bool = abs.endsWith(".hdr") && Project.raw.envmap == abs; + ImportTexture.run(abs, hdr_as_envmap); } ///if (is_paint || is_sculpt) @@ -174,14 +174,14 @@ class ImportArm { if (History.undo_layers != null) for (let l of History.undo_layers) SlotLayer.resize_and_set_bits(l); let rts: map_t = render_path_render_targets; let _texpaint_blend0: image_t = rts.get("texpaint_blend0")._image; - Base.notify_on_next_frame(() => { + base_notify_on_next_frame(() => { image_unload(_texpaint_blend0); }); rts.get("texpaint_blend0").width = Config.get_texture_res_x(); rts.get("texpaint_blend0").height = Config.get_texture_res_y(); rts.get("texpaint_blend0")._image = image_create_render_target(Config.get_texture_res_x(), Config.get_texture_res_y(), tex_format_t.R8, depth_format_t.NO_DEPTH); let _texpaint_blend1: image_t = rts.get("texpaint_blend1")._image; - Base.notify_on_next_frame(() => { + base_notify_on_next_frame(() => { image_unload(_texpaint_blend1); }); rts.get("texpaint_blend1").width = Config.get_texture_res_x(); @@ -194,22 +194,22 @@ class ImportArm { Project.layers = []; for (let i: i32 = 0; i < project.layer_datas.length; ++i) { let ld: layer_data_t = project.layer_datas[i]; - let isGroup: bool = ld.texpaint == null; + let is_group: bool = ld.texpaint == null; ///if is_paint - let isMask: bool = ld.texpaint != null && ld.texpaint_nor == null; + let is_mask: bool = ld.texpaint != null && ld.texpaint_nor == null; ///end ///if is_sculpt - let isMask: bool = false; + let is_mask: bool = false; ///end - let l: SlotLayerRaw = SlotLayer.create("", isGroup ? layer_slot_type_t.GROUP : isMask ? layer_slot_type_t.MASK : layer_slot_type_t.LAYER); + let l: SlotLayerRaw = SlotLayer.create("", is_group ? layer_slot_type_t.GROUP : is_mask ? layer_slot_type_t.MASK : layer_slot_type_t.LAYER); if (ld.name != null) l.name = ld.name; l.visible = ld.visible; Project.layers.push(l); - if (!isGroup) { - if (Base.pipe_merge == null) Base.make_pipe(); + if (!is_group) { + if (base_pipe_merge == null) base_make_pipe(); let _texpaint: image_t = null; @@ -218,35 +218,35 @@ class ImportArm { let _texpaint_pack: image_t = null; ///end - if (isMask) { + if (is_mask) { _texpaint = image_from_bytes(lz4_decode(ld.texpaint, ld.res * ld.res * 4), ld.res, ld.res, tex_format_t.RGBA32); g2_begin(l.texpaint); - // g2_set_pipeline(Base.pipeCopy8); - g2_set_pipeline(project.is_bgra ? Base.pipe_copyBGRA : Base.pipe_copy); // Full bits for undo support, R8 is used + // g2_set_pipeline(base_pipe_copy8); + g2_set_pipeline(project.is_bgra ? base_pipe_copy_bgra : base_pipe_copy); // Full bits for undo support, R8 is used g2_draw_image(_texpaint, 0, 0); g2_set_pipeline(null); g2_end(); } else { // Layer // TODO: create render target from bytes - _texpaint = image_from_bytes(lz4_decode(ld.texpaint, ld.res * ld.res * 4 * bytesPerPixel), ld.res, ld.res, format); + _texpaint = image_from_bytes(lz4_decode(ld.texpaint, ld.res * ld.res * 4 * bytes_per_pixel), ld.res, ld.res, format); g2_begin(l.texpaint); - g2_set_pipeline(project.is_bgra ? Base.pipe_copyBGRA : Base.pipe_copy); + g2_set_pipeline(project.is_bgra ? base_pipe_copy_bgra : base_pipe_copy); g2_draw_image(_texpaint, 0, 0); g2_set_pipeline(null); g2_end(); ///if is_paint - _texpaint_nor = image_from_bytes(lz4_decode(ld.texpaint_nor, ld.res * ld.res * 4 * bytesPerPixel), ld.res, ld.res, format); + _texpaint_nor = image_from_bytes(lz4_decode(ld.texpaint_nor, ld.res * ld.res * 4 * bytes_per_pixel), ld.res, ld.res, format); g2_begin(l.texpaint_nor); - g2_set_pipeline(project.is_bgra ? Base.pipe_copyBGRA : Base.pipe_copy); + g2_set_pipeline(project.is_bgra ? base_pipe_copy_bgra : base_pipe_copy); g2_draw_image(_texpaint_nor, 0, 0); g2_set_pipeline(null); g2_end(); - _texpaint_pack = image_from_bytes(lz4_decode(ld.texpaint_pack, ld.res * ld.res * 4 * bytesPerPixel), ld.res, ld.res, format); + _texpaint_pack = image_from_bytes(lz4_decode(ld.texpaint_pack, ld.res * ld.res * 4 * bytes_per_pixel), ld.res, ld.res, format); g2_begin(l.texpaint_pack); - g2_set_pipeline(project.is_bgra ? Base.pipe_copyBGRA : Base.pipe_copy); + g2_set_pipeline(project.is_bgra ? base_pipe_copy_bgra : base_pipe_copy); g2_draw_image(_texpaint_pack, 0, 0); g2_set_pipeline(null); g2_end(); @@ -255,27 +255,27 @@ class ImportArm { l.scale = ld.uv_scale; l.angle = ld.uv_rot; - l.uvType = ld.uv_type; - if (ld.decal_mat != null) l.decalMat = mat4_from_f32_array(ld.decal_mat); - l.maskOpacity = ld.opacity_mask; - l.objectMask = ld.object_mask; + l.uv_type = ld.uv_type; + if (ld.decal_mat != null) l.decal_mat = mat4_from_f32_array(ld.decal_mat); + l.mask_opacity = ld.opacity_mask; + l.object_mask = ld.object_mask; l.blending = ld.blending; ///if is_paint - l.paintBase = ld.paint_base; - l.paintOpac = ld.paint_opac; - l.paintOcc = ld.paint_occ; - l.paintRough = ld.paint_rough; - l.paintMet = ld.paint_met; - l.paintNor = ld.paint_nor; - l.paintNorBlend = ld.paint_nor_blend != null ? ld.paint_nor_blend : true; // TODO: deprecated - l.paintHeight = ld.paint_height; - l.paintHeightBlend = ld.paint_height_blend != null ? ld.paint_height_blend : true; // TODO: deprecated - l.paintEmis = ld.paint_emis; - l.paintSubs = ld.paint_subs; + l.paint_base = ld.paint_base; + l.paint_opac = ld.paint_opac; + l.paint_occ = ld.paint_occ; + l.paint_rough = ld.paint_rough; + l.paint_met = ld.paint_met; + l.paint_nor = ld.paint_nor; + l.paint_nor_blend = ld.paint_nor_blend != null ? ld.paint_nor_blend : true; // TODO: deprecated + l.paint_height = ld.paint_height; + l.paint_height_blend = ld.paint_height_blend != null ? ld.paint_height_blend : true; // TODO: deprecated + l.paint_emis = ld.paint_emis; + l.paint_subs = ld.paint_subs; ///end - Base.notify_on_next_frame(() => { + base_notify_on_next_frame(() => { image_unload(_texpaint); ///if is_paint if (_texpaint_nor != null) image_unload(_texpaint_nor); @@ -333,8 +333,8 @@ class ImportArm { for (let i: i32 = 0; i < project.layer_datas.length; ++i) { let ld: layer_data_t = project.layer_datas[i]; let l: SlotLayerRaw = Project.layers[i]; - let isGroup: bool = ld.texpaint == null; - if (!isGroup) { + let is_group: bool = ld.texpaint == null; + if (!is_group) { l.fill_layer = ld.fill_layer > -1 ? Project.materials[ld.fill_layer] : null; } } @@ -377,7 +377,7 @@ class ImportArm { UtilMesh.merge_mesh(); Viewport.scale_to_bounds(); } - app_notify_on_init(Base.init_layers); + app_notify_on_init(base_init_layers); History.reset(); } @@ -559,7 +559,7 @@ class ImportArm { static init_nodes = (nodes: zui_node_t[]) => { for (let node of nodes) { if (node.type == ImportArm.texture_node_name()) { - node.buttons[0].default_value = Base.get_asset_index(node.buttons[0].data); + node.buttons[0].default_value = base_get_asset_index(node.buttons[0].data); node.buttons[0].data = ""; } } diff --git a/base/Sources/ImportAsset.ts b/base/Sources/ImportAsset.ts index cf262fe1..190bab87 100644 --- a/base/Sources/ImportAsset.ts +++ b/base/Sources/ImportAsset.ts @@ -4,7 +4,7 @@ class ImportAsset { static run = (path: string, dropX: f32 = -1.0, dropY: f32 = -1.0, showBox: bool = true, hdrAsEnvmap: bool = true, done: ()=>void = null) => { if (path.startsWith("cloud")) { - let doCacheCloud = () => { + let do_cache_cloud = () => { File.cache_cloud(path, (abs: string) => { if (abs == null) return; ImportAsset.run(abs, dropX, dropY, showBox, hdrAsEnvmap, done); @@ -12,12 +12,12 @@ class ImportAsset { } ///if (krom_android || krom_ios) - Base.notify_on_next_frame(() => { + base_notify_on_next_frame(() => { Console.toast(tr("Downloading")); - Base.notify_on_next_frame(doCacheCloud); + base_notify_on_next_frame(do_cache_cloud); }); ///else - doCacheCloud(); + do_cache_cloud(); ///end return; @@ -33,14 +33,14 @@ class ImportAsset { let x0: i32 = UINodes.wx; let x1: i32 = UINodes.wx + UINodes.ww; if (UINodes.show && dropX > x0 && dropX < x1) { - let assetIndex: i32 = 0; + let asset_index: i32 = 0; for (let i: i32 = 0; i < Project.assets.length; ++i) { if (Project.assets[i].file == path) { - assetIndex = i; + asset_index = i; break; } } - UINodes.accept_asset_drag(assetIndex); + UINodes.accept_asset_drag(asset_index); UINodes.get_nodes().nodesDrag = false; UINodes.hwnd.redraws = 2; } diff --git a/base/Sources/ImportBlendMaterial.ts b/base/Sources/ImportBlendMaterial.ts index d4bfaa9b..44c43e6a 100644 --- a/base/Sources/ImportBlendMaterial.ts +++ b/base/Sources/ImportBlendMaterial.ts @@ -111,7 +111,7 @@ class ImportBlendMaterial { ImportTexture.run(file); let ar: string[] = file.split(Path.sep); let filename: string = ar[ar.length - 1]; - n.buttons[0].default_value = Base.get_asset_index(filename); + n.buttons[0].default_value = base_get_asset_index(filename); } else if (search == "valtorgb") { let ramp: any = BlHandle.get(node, "storage", 0, "ColorBand"); diff --git a/base/Sources/ImportBlendMesh.ts b/base/Sources/ImportBlendMesh.ts index 4b778e4d..4c100336 100644 --- a/base/Sources/ImportBlendMesh.ts +++ b/base/Sources/ImportBlendMesh.ts @@ -418,12 +418,12 @@ class ImportBlendMesh { } // Pack positions to (-1, 1) range - let scalePos: f32 = 0.0; + let scale_pos: f32 = 0.0; for (let i: i32 = 0; i < posa32.length; ++i) { let f: f32 = Math.abs(posa32[i]); - if (scalePos < f) scalePos = f; + if (scale_pos < f) scale_pos = f; } - let inv: f32 = 1 / scalePos; + let inv: f32 = 1 / scale_pos; for (let i: i32 = 0; i < Math.floor(posa32.length / 3); ++i) { posa[i * 4 ] = Math.floor(posa32[i * 3 ] * 32767 * inv); posa[i * 4 + 1] = Math.floor(posa32[i * 3 + 1] * 32767 * inv); @@ -437,7 +437,7 @@ class ImportBlendMesh { cola: cola, inda: inda, name: name, - scalePos: scalePos, + scalePos: scale_pos, scaleTes: 1.0 }; diff --git a/base/Sources/ImportEnvmap.ts b/base/Sources/ImportEnvmap.ts index 2a6d8db1..ee40143d 100644 --- a/base/Sources/ImportEnvmap.ts +++ b/base/Sources/ImportEnvmap.ts @@ -41,25 +41,25 @@ class ImportEnvmap { // Down-scale to 1024x512 g2_begin(ImportEnvmap.radiance); - g2_set_pipeline(Base.pipe_copy128); + g2_set_pipeline(base_pipe_copy128); g2_draw_scaled_image(image, 0, 0, 1024, 512); g2_set_pipeline(null); g2_end(); - let radiancePixels: buffer_t = image_get_pixels(ImportEnvmap.radiance); + let radiance_pixels: buffer_t = image_get_pixels(ImportEnvmap.radiance); if (ImportEnvmap.radiance_cpu != null) { - let _radianceCpu: image_t = ImportEnvmap.radiance_cpu; - Base.notify_on_next_frame(() => { - image_unload(_radianceCpu); + let _radiance_cpu: image_t = ImportEnvmap.radiance_cpu; + base_notify_on_next_frame(() => { + image_unload(_radiance_cpu); }); } - ImportEnvmap.radiance_cpu = image_from_bytes(radiancePixels, ImportEnvmap.radiance.width, ImportEnvmap.radiance.height, tex_format_t.RGBA128); + ImportEnvmap.radiance_cpu = image_from_bytes(radiance_pixels, ImportEnvmap.radiance.width, ImportEnvmap.radiance.height, tex_format_t.RGBA128); // Radiance if (ImportEnvmap.mips_cpu != null) { for (let mip of ImportEnvmap.mips_cpu) { let _mip: image_t = mip; - Base.notify_on_next_frame(() => { + base_notify_on_next_frame(() => { ///if (!krom_direct3d12) // TODO: crashes after 50+ imports image_unload(_mip); ///end @@ -74,7 +74,7 @@ class ImportEnvmap { image_set_mipmaps(ImportEnvmap.radiance_cpu, ImportEnvmap.mips_cpu); // Irradiance - scene_world._.irradiance = ImportEnvmap.get_spherical_harmonics(radiancePixels, ImportEnvmap.radiance.width, ImportEnvmap.radiance.height); + scene_world._.irradiance = ImportEnvmap.get_spherical_harmonics(radiance_pixels, ImportEnvmap.radiance.width, ImportEnvmap.radiance.height); // World scene_world.strength = 1.0; diff --git a/base/Sources/ImportFont.ts b/base/Sources/ImportFont.ts index de610fc9..c3401787 100644 --- a/base/Sources/ImportFont.ts +++ b/base/Sources/ImportFont.ts @@ -13,18 +13,18 @@ class ImportFont { let font: g2_font_t = data_get_font(path); g2_font_init(font); // Make sure font_ is ready let count: i32 = krom_g2_font_count(font.font_); - let fontSlots: SlotFontRaw[] = []; + let font_slots: SlotFontRaw[] = []; for (let i: i32 = 0; i < count; ++i) { let ar: string[] = path.split(Path.sep); let name: string = ar[ar.length - 1]; let f: g2_font_t = g2_font_clone(font); g2_font_set_font_index(f, i); - let fontSlot: SlotFontRaw = SlotFont.create(name, f, path); - fontSlots.push(fontSlot); + let font_slot: SlotFontRaw = SlotFont.create(name, f, path); + font_slots.push(font_slot); } let _init = () => { - for (let f of fontSlots) { + for (let f of font_slots) { Context.raw.font = f; Project.fonts.push(f); UtilRender.make_font_preview(); diff --git a/base/Sources/ImportKeymap.ts b/base/Sources/ImportKeymap.ts index 354e3627..5434a89e 100644 --- a/base/Sources/ImportKeymap.ts +++ b/base/Sources/ImportKeymap.ts @@ -8,8 +8,8 @@ class ImportKeymap { } let filename: string = path.substr(path.lastIndexOf(Path.sep) + 1); - let dstPath: string = Path.data() + Path.sep + "keymap_presets" + Path.sep + filename; - File.copy(path, dstPath); // Copy to preset folder + let dst_path: string = Path.data() + Path.sep + "keymap_presets" + Path.sep + filename; + File.copy(path, dst_path); // Copy to preset folder BoxPreferences.fetch_keymaps(); // Refresh file list BoxPreferences.preset_handle.position = BoxPreferences.get_preset_index(); Console.info(tr("Keymap imported:") + " " + filename); diff --git a/base/Sources/ImportMesh.ts b/base/Sources/ImportMesh.ts index 557c2d0f..cc68721c 100644 --- a/base/Sources/ImportMesh.ts +++ b/base/Sources/ImportMesh.ts @@ -144,15 +144,15 @@ class ImportMesh { let l: SlotLayerRaw = Project.layers.pop(); SlotLayer.unload(l); } - Base.new_layer(false); - app_notify_on_init(Base.init_layers); + base_new_layer(false); + app_notify_on_init(base_init_layers); History.reset(); } ///end // Wait for addMesh calls to finish if (ImportMesh.meshes_to_unwrap != null) { - Base.notify_on_next_frame(ImportMesh.finish_import); + base_notify_on_next_frame(ImportMesh.finish_import); } else { app_notify_on_init(ImportMesh.finish_import); @@ -169,11 +169,11 @@ class ImportMesh { if (ImportMesh.meshes_to_unwrap == null) { ImportMesh.meshes_to_unwrap = []; } - let firstUnwrapDone = (mesh: any) => { + let first_unwrap_done = (mesh: any) => { ImportMesh._make_mesh(mesh); for (let mesh of ImportMesh.meshes_to_unwrap) Project.unwrap_mesh_box(mesh, ImportMesh._add_mesh, true); } - Project.unwrap_mesh_box(mesh, firstUnwrapDone); + Project.unwrap_mesh_box(mesh, first_unwrap_done); } else { ImportMesh._make_mesh(mesh); diff --git a/base/Sources/ImportPlugin.ts b/base/Sources/ImportPlugin.ts index a8b1033b..18888461 100644 --- a/base/Sources/ImportPlugin.ts +++ b/base/Sources/ImportPlugin.ts @@ -8,8 +8,8 @@ class ImportPlugin { } let filename: string = path.substr(path.lastIndexOf(Path.sep) + 1); - let dstPath: string = Path.data() + Path.sep + "plugins" + Path.sep + filename; - File.copy(path, dstPath); // Copy to plugin folder + let dst_path: string = Path.data() + Path.sep + "plugins" + Path.sep + filename; + File.copy(path, dst_path); // Copy to plugin folder BoxPreferences.files_plugin = null; // Refresh file list Console.info(tr("Plugin imported:") + " " + filename); } diff --git a/base/Sources/ImportTexture.ts b/base/Sources/ImportTexture.ts index 27e893e2..e5f8cd57 100644 --- a/base/Sources/ImportTexture.ts +++ b/base/Sources/ImportTexture.ts @@ -1,7 +1,7 @@ class ImportTexture { - static run = (path: string, hdrAsEnvmap: bool = true) => { + static run = (path: string, hdr_as_envmap: bool = true) => { if (!Path.is_texture(path)) { if (!Context.enable_import_plugin(path)) { Console.error(Strings.error1()); @@ -13,9 +13,9 @@ class ImportTexture { // Already imported if (a.file == path) { // Set as envmap - if (hdrAsEnvmap && path.toLowerCase().endsWith(".hdr")) { + if (hdr_as_envmap && path.toLowerCase().endsWith(".hdr")) { let image: image_t = data_get_image(path); - Base.notify_on_next_frame(() => { // Make sure file browser process did finish + base_notify_on_next_frame(() => { // Make sure file browser process did finish ImportEnvmap.run(path, image); }); } @@ -42,8 +42,8 @@ class ImportTexture { Console.info(tr("Texture imported:") + " " + name); // Set as envmap - if (hdrAsEnvmap && path.toLowerCase().endsWith(".hdr")) { - Base.notify_on_next_frame(() => { // Make sure file browser process did finish + if (hdr_as_envmap && path.toLowerCase().endsWith(".hdr")) { + base_notify_on_next_frame(() => { // Make sure file browser process did finish ImportEnvmap.run(path, image); }); } diff --git a/base/Sources/ImportTheme.ts b/base/Sources/ImportTheme.ts index 1279377a..1456a009 100644 --- a/base/Sources/ImportTheme.ts +++ b/base/Sources/ImportTheme.ts @@ -8,8 +8,8 @@ class ImportTheme { } let filename: string = path.substr(path.lastIndexOf(Path.sep) + 1); - let dstPath: string = Path.data() + Path.sep + "themes" + Path.sep + filename; - File.copy(path, dstPath); // Copy to preset folder + let dst_path: string = Path.data() + Path.sep + "themes" + Path.sep + filename; + File.copy(path, dst_path); // Copy to preset folder BoxPreferences.fetch_themes(); // Refresh file list Config.raw.theme = filename; BoxPreferences.theme_handle.position = BoxPreferences.get_theme_index(); diff --git a/base/Sources/LineDraw.ts b/base/Sources/LineDraw.ts index d2100116..ba215fb0 100644 --- a/base/Sources/LineDraw.ts +++ b/base/Sources/LineDraw.ts @@ -136,14 +136,14 @@ class LineDraw { LineDraw.camera_look = mat4_get_loc(camera.base.transform.world); vec4_sub(LineDraw.camera_look, LineDraw.mid_point); - let lineWidth: vec4_t = vec4_cross(LineDraw.camera_look, LineDraw.mid_line); - vec4_normalize(lineWidth); - vec4_mult(lineWidth, LineDraw.strength); + let line_width: vec4_t = vec4_cross(LineDraw.camera_look, LineDraw.mid_line); + vec4_normalize(line_width); + vec4_mult(line_width, LineDraw.strength); - vec4_add(vec4_set(LineDraw.corner1, x1, y1, z1), lineWidth); - vec4_sub(vec4_set(LineDraw.corner2, x1, y1, z1), lineWidth); - vec4_sub(vec4_set(LineDraw.corner3, x2, y2, z2), lineWidth); - vec4_add(vec4_set(LineDraw.corner4, x2, y2, z2), lineWidth); + vec4_add(vec4_set(LineDraw.corner1, x1, y1, z1), line_width); + vec4_sub(vec4_set(LineDraw.corner2, x1, y1, z1), line_width); + vec4_sub(vec4_set(LineDraw.corner3, x2, y2, z2), line_width); + vec4_add(vec4_set(LineDraw.corner4, x2, y2, z2), line_width); let i: i32 = LineDraw.lines * 24; // 4 * 6 (structure len) LineDraw.add_vb_data(i, [LineDraw.corner1.x, LineDraw.corner1.y, LineDraw.corner1.z, color_get_rb(LineDraw.color) / 255, color_get_gb(LineDraw.color) / 255, color_get_ab(LineDraw.color) / 255]); diff --git a/base/Sources/MakeVoxel.ts b/base/Sources/MakeVoxel.ts index 51d76737..7aae8058 100644 --- a/base/Sources/MakeVoxel.ts +++ b/base/Sources/MakeVoxel.ts @@ -8,8 +8,8 @@ class MakeVoxel { g4_vertex_struct_add(structure, "nor", vertex_data_t.I16_2X_NORM); g4_vertex_struct_add(structure, "tex", vertex_data_t.I16_2X_NORM); - let pipeState: pipeline_t = data._.pipe_state; - pipeState.input_layout = [structure]; + let pipe_state: pipeline_t = data._.pipe_state; + pipe_state.input_layout = [structure]; data.vertex_elements = [ {name: "pos", data: "short4norm"}, {name: "nor", data: "short2norm"}, @@ -28,13 +28,13 @@ class MakeVoxel { // ///end let ds: f32 = MakeMaterial.get_displace_strength(); - pipeState.vertex_shader = g4_shader_from_source(MakeVoxel.voxel_source(), shader_type_t.VERTEX); + pipe_state.vertex_shader = g4_shader_from_source(MakeVoxel.voxel_source(), shader_type_t.VERTEX); - g4_pipeline_compile(pipeState); + g4_pipeline_compile(pipe_state); data.constants = [{ name: "W", type: "mat4", link: "_world_matrix" }, { name: "N", type: "mat3", link: "_normal_matrix" }]; - data._.constants = [g4_pipeline_get_const_loc(pipeState, "W"), g4_pipeline_get_const_loc(pipeState, "N")]; + data._.constants = [g4_pipeline_get_const_loc(pipe_state, "W"), g4_pipeline_get_const_loc(pipe_state, "N")]; data.texture_units = [{ name: "texpaint_pack" }, { name: "voxels", image_uniform: true }]; - data._.tex_units = [g4_pipeline_get_tex_unit(pipeState, "texpaint_pack"), g4_pipeline_get_tex_unit(pipeState, "voxels")]; + data._.tex_units = [g4_pipeline_get_tex_unit(pipe_state, "texpaint_pack"), g4_pipeline_get_tex_unit(pipe_state, "voxels")]; } static voxel_source = (): string => { diff --git a/base/Sources/ParserBlend.ts b/base/Sources/ParserBlend.ts index 71726cda..13b00f7f 100644 --- a/base/Sources/ParserBlend.ts +++ b/base/Sources/ParserBlend.ts @@ -39,14 +39,14 @@ class ParserBlend { static dir = (raw: BlendRaw, type: string): string[] => { // Return structure fields - let typeIndex: i32 = ParserBlend.get_type_index(raw.dna, type); - if (typeIndex == -1) return null; - let ds: DnaStruct = ParserBlend.get_struct(raw.dna, typeIndex); + let type_index: i32 = ParserBlend.get_type_index(raw.dna, type); + if (type_index == -1) return null; + let ds: DnaStruct = ParserBlend.get_struct(raw.dna, type_index); let fields: string[] = []; for (let i: i32 = 0; i < ds.field_names.length; ++i) { - let nameIndex: i32 = ds.field_names[i]; - let typeIndex: i32 = ds.field_types[i]; - fields.push(raw.dna.types[typeIndex] + " " + raw.dna.names[nameIndex]); + let name_index: i32 = ds.field_names[i]; + let type_index: i32 = ds.field_types[i]; + fields.push(raw.dna.types[type_index] + " " + raw.dna.names[name_index]); } return fields; } @@ -54,12 +54,12 @@ class ParserBlend { static get = (raw: BlendRaw, type: string): BlHandleRaw[] => { if (raw.dna == null) return null; // Return all structures of type - let typeIndex: i32 = ParserBlend.get_type_index(raw.dna, type); - if (typeIndex == -1) return null; - let ds: DnaStruct = ParserBlend.get_struct(raw.dna, typeIndex); + let type_index: i32 = ParserBlend.get_type_index(raw.dna, type); + if (type_index == -1) return null; + let ds: DnaStruct = ParserBlend.get_struct(raw.dna, type_index); let handles: BlHandleRaw[] = []; for (let b of raw.blocks) { - if (raw.dna.structs[b.sdna_index].type == typeIndex) { + if (raw.dna.structs[b.sdna_index].type == type_index) { let h: BlHandleRaw = new BlHandleRaw(); handles.push(h); h.block = b; @@ -122,37 +122,37 @@ class ParserBlend { ParserBlend.read_chars(raw, 4); // SDNA ParserBlend.read_chars(raw, 4); // NAME - let namesCount: i32 = ParserBlend.read_i32(raw); - for (let i: i32 = 0; i < namesCount; ++i) { + let names_count: i32 = ParserBlend.read_i32(raw); + for (let i: i32 = 0; i < names_count; ++i) { raw.dna.names.push(ParserBlend.read_string(raw)); } ParserBlend.align(raw); ParserBlend.read_chars(raw, 4); // TYPE - let typesCount: i32 = ParserBlend.read_i32(raw); - for (let i: i32 = 0; i < typesCount; ++i) { + let types_count: i32 = ParserBlend.read_i32(raw); + for (let i: i32 = 0; i < types_count; ++i) { raw.dna.types.push(ParserBlend.read_string(raw)); } ParserBlend.align(raw); ParserBlend.read_chars(raw, 4); // TLEN - for (let i: i32 = 0; i < typesCount; ++i) { + for (let i: i32 = 0; i < types_count; ++i) { raw.dna.types_length.push(ParserBlend.read_i16(raw)); } ParserBlend.align(raw); ParserBlend.read_chars(raw, 4); // STRC - let structCount: i32 = ParserBlend.read_i32(raw); - for (let i: i32 = 0; i < structCount; ++i) { + let struct_count: i32 = ParserBlend.read_i32(raw); + for (let i: i32 = 0; i < struct_count; ++i) { let ds: DnaStruct = new DnaStruct(); raw.dna.structs.push(ds); ds.dna = raw.dna; ds.type = ParserBlend.read_i16(raw); - let fieldCount: i32 = ParserBlend.read_i16(raw); - if (fieldCount > 0) { + let field_count: i32 = ParserBlend.read_i16(raw); + if (field_count > 0) { ds.field_types = []; ds.field_names = []; - for (let j: i32 = 0; j < fieldCount; ++j) { + for (let j: i32 = 0; j < field_count; ++j) { ds.field_types.push(ParserBlend.read_i16(raw)); ds.field_names.push(ParserBlend.read_i16(raw)); } @@ -282,13 +282,13 @@ class BlHandleRaw { class BlHandle { static get_size = (raw: BlHandleRaw, index: i32): i32 => { - let nameIndex: i32 = raw.ds.field_names[index]; - let typeIndex: i32 = raw.ds.field_types[index]; + let name_index: i32 = raw.ds.field_names[index]; + let type_index: i32 = raw.ds.field_types[index]; let dna: Dna = raw.ds.dna; - let n: string = dna.names[nameIndex]; + let n: string = dna.names[name_index]; let size: i32 = 0; if (n.indexOf("*") >= 0) size = raw.block.blend.pointer_size; - else size = dna.types_length[typeIndex]; + else size = dna.types_length[type_index]; if (n.indexOf("[") > 0) size *= BlHandle.get_array_len(n); return size; } @@ -307,49 +307,49 @@ class BlHandle { // Return raw type or structure let dna: Dna = raw.ds.dna; for (let i: i32 = 0; i < raw.ds.field_names.length; ++i) { - let nameIndex: i32 = raw.ds.field_names[i]; - let dnaName: string = dna.names[nameIndex]; - if (name == BlHandle.base_name(dnaName)) { - let typeIndex: i32 = raw.ds.field_types[i]; - let type: string = dna.types[typeIndex]; - let newOffset: i32 = raw.offset; - for (let j: i32 = 0; j < i; ++j) newOffset += BlHandle.get_size(raw, j); + let name_index: i32 = raw.ds.field_names[i]; + let dna_name: string = dna.names[name_index]; + if (name == BlHandle.base_name(dna_name)) { + let type_index: i32 = raw.ds.field_types[i]; + let type: string = dna.types[type_index]; + let new_offset: i32 = raw.offset; + for (let j: i32 = 0; j < i; ++j) new_offset += BlHandle.get_size(raw, j); // Cast void * to type if (asType != null) { for (let i: i32 = 0; i < dna.types.length; ++i) { if (dna.types[i] == asType) { - typeIndex = i; + type_index = i; break; } } } // Raw type - if (typeIndex < 12) { + if (type_index < 12) { let blend: BlendRaw = raw.block.blend; - blend.pos = raw.block.pos + newOffset; - let isArray: bool = dnaName.charAt(dnaName.length - 1) == "]"; - let len: i32 = isArray ? (arrayLen > 0 ? arrayLen : this.get_array_len(dnaName)) : 1; + blend.pos = raw.block.pos + new_offset; + let is_array: bool = dna_name.charAt(dna_name.length - 1) == "]"; + let len: i32 = is_array ? (arrayLen > 0 ? arrayLen : this.get_array_len(dna_name)) : 1; switch (type) { - case "int": return isArray ? ParserBlend.read_i32array(blend, len) : ParserBlend.read_i32(blend); - case "char": return isArray ? ParserBlend.read_string(blend) : ParserBlend.read_i8(blend); - case "uchar": return isArray ? ParserBlend.read_i8array(blend, len) : ParserBlend.read_i8(blend); - case "short": return isArray ? ParserBlend.read_i16array(blend, len) : ParserBlend.read_i16(blend); - case "ushort": return isArray ? ParserBlend.read_i16array(blend, len) : ParserBlend.read_i16(blend); - case "float": return isArray ? ParserBlend.read_f32array(blend, len) : ParserBlend.read_f32(blend); + case "int": return is_array ? ParserBlend.read_i32array(blend, len) : ParserBlend.read_i32(blend); + case "char": return is_array ? ParserBlend.read_string(blend) : ParserBlend.read_i8(blend); + case "uchar": return is_array ? ParserBlend.read_i8array(blend, len) : ParserBlend.read_i8(blend); + case "short": return is_array ? ParserBlend.read_i16array(blend, len) : ParserBlend.read_i16(blend); + case "ushort": return is_array ? ParserBlend.read_i16array(blend, len) : ParserBlend.read_i16(blend); + case "float": return is_array ? ParserBlend.read_f32array(blend, len) : ParserBlend.read_f32(blend); case "double": return 0; //ParserBlend.readf64(blend); - case "long": return isArray ? ParserBlend.read_i32array(blend, len) : ParserBlend.read_i32(blend); - case "ulong": return isArray ? ParserBlend.read_i32array(blend, len) : ParserBlend.read_i32(blend); + case "long": return is_array ? ParserBlend.read_i32array(blend, len) : ParserBlend.read_i32(blend); + case "ulong": return is_array ? ParserBlend.read_i32array(blend, len) : ParserBlend.read_i32(blend); case "int64_t": return ParserBlend.read_i64(blend); case "uint64_t": return ParserBlend.read_i64(blend); - case "void": if (dnaName.charAt(0) == "*") { return ParserBlend.read_i64(blend); }; + case "void": if (dna_name.charAt(0) == "*") { return ParserBlend.read_i64(blend); }; } } // Structure let h: BlHandleRaw = new BlHandleRaw(); - h.ds = ParserBlend.get_struct(dna, typeIndex); - let isPointer: bool = dnaName.charAt(0) == "*"; - if (isPointer) { - raw.block.blend.pos = raw.block.pos + newOffset; + h.ds = ParserBlend.get_struct(dna, type_index); + let is_pointer: bool = dna_name.charAt(0) == "*"; + if (is_pointer) { + raw.block.blend.pos = raw.block.pos + new_offset; let addr: any = ParserBlend.read_pointer(raw.block.blend); if (raw.block.blend.map.has(addr)) { h.block = raw.block.blend.map.get(addr); @@ -359,9 +359,9 @@ class BlHandle { } else { h.block = raw.block; - h.offset = newOffset; + h.offset = new_offset; } - h.offset += dna.types_length[typeIndex] * index; + h.offset += dna.types_length[type_index] * index; return h; } } diff --git a/base/Sources/ParserExr.ts b/base/Sources/ParserExr.ts index 8e914e32..8e9416ee 100644 --- a/base/Sources/ParserExr.ts +++ b/base/Sources/ParserExr.ts @@ -243,14 +243,14 @@ class ParserExr { out.push(0); // end of header let channels: i32 = 4; - let byteSize: i32 = bits == 16 ? 2 : 4; - let kHeaderSize: i32 = out.length; - let kScanlineTableSize: i32 = 8 * height; - let pixelRowSize: i32 = width * 3 * byteSize; - let fullRowSize: i32 = pixelRowSize + 8; + let byte_size: i32 = bits == 16 ? 2 : 4; + let k_header_size: i32 = out.length; + let k_scanline_table_size: i32 = 8 * height; + let pixel_row_size: i32 = width * 3 * byte_size; + let full_row_size: i32 = pixel_row_size + 8; // line offset table - let ofs: i32 = kHeaderSize + kScanlineTableSize; + let ofs: i32 = k_header_size + k_scanline_table_size; for (let y: i32 = 0; y < height; ++y) { out.push(ofs & 0xff); out.push((ofs >> 8) & 0xff); @@ -260,15 +260,15 @@ class ParserExr { out.push(0); out.push(0); out.push(0); - ofs += fullRowSize; + ofs += full_row_size; } // scanline data - let stride: i32 = channels * byteSize; + let stride: i32 = channels * byte_size; let pos: i32 = 0; let srcView: DataView = new DataView(src); - let writeLine16 = (bytePos: i32) => { + let write_line16 = (bytePos: i32) => { for (let x: i32 = 0; x < width; ++x) { out.push(srcView.getUint8(bytePos )); out.push(srcView.getUint8(bytePos + 1)); @@ -276,7 +276,7 @@ class ParserExr { } } - let writeLine32 = (bytePos: i32) => { + let write_line32 = (bytePos: i32) => { for (let x: i32 = 0; x < width; ++x) { out.push(srcView.getUint8(bytePos )); out.push(srcView.getUint8(bytePos + 1)); @@ -286,21 +286,21 @@ class ParserExr { } } - let writeLine = bits == 16 ? writeLine16 : writeLine32; + let write_line = bits == 16 ? write_line16 : write_line32; - let writeBGR = (off: i32) => { - writeLine(pos + byteSize * 2); - writeLine(pos + byteSize); - writeLine(pos); + let write_bgr = (off: i32) => { + write_line(pos + byte_size * 2); + write_line(pos + byte_size); + write_line(pos); } - let writeSingle = (off: i32) => { - writeLine(pos + off * byteSize); - writeLine(pos + off * byteSize); - writeLine(pos + off * byteSize); + let write_single = (off: i32) => { + write_line(pos + off * byte_size); + write_line(pos + off * byte_size); + write_line(pos + off * byte_size); } - let writeData = type == 1 ? writeBGR : writeSingle; + let write_data = type == 1 ? write_bgr : write_single; for (let y: i32 = 0; y < height; ++y) { // coordinate @@ -309,12 +309,12 @@ class ParserExr { out.push((y >> 16) & 0xff); out.push((y >> 24) & 0xff); // data size - out.push(pixelRowSize & 0xff); - out.push((pixelRowSize >> 8) & 0xff); - out.push((pixelRowSize >> 16) & 0xff); - out.push((pixelRowSize >> 24) & 0xff); + out.push(pixel_row_size & 0xff); + out.push((pixel_row_size >> 8) & 0xff); + out.push((pixel_row_size >> 16) & 0xff); + out.push((pixel_row_size >> 24) & 0xff); // data - writeData(off); + write_data(off); pos += width * stride; } diff --git a/base/Sources/ParserLogic.ts b/base/Sources/ParserLogic.ts index 68d85608..5db49d0d 100644 --- a/base/Sources/ParserLogic.ts +++ b/base/Sources/ParserLogic.ts @@ -1,21 +1,21 @@ class ParserLogic { - static customNodes: Map = new Map(); + static custom_nodes: Map = new Map(); static nodes: zui_node_t[]; static links: zui_node_link_t[]; static parsed_nodes: string[] = null; static parsed_labels: Map = null; - static nodeMap: Map; - static rawMap: Map; + static node_map: Map; + static raw_map: Map; static get_logic_node = (node: zui_node_t): LogicNode => { - return ParserLogic.nodeMap.get(ParserLogic.node_name(node)); + return ParserLogic.node_map.get(ParserLogic.node_name(node)); } static get_raw_node = (node: LogicNode): zui_node_t => { - return ParserLogic.rawMap.get(node); + return ParserLogic.raw_map.get(node); } static get_node = (id: i32): zui_node_t => { @@ -66,8 +66,8 @@ class ParserLogic { ParserLogic.parsed_nodes = []; ParserLogic.parsed_labels = new Map(); - ParserLogic.nodeMap = new Map(); - ParserLogic.rawMap = new Map(); + ParserLogic.node_map = new Map(); + ParserLogic.raw_map = new Map(); let root_nodes: zui_node_t[] = ParserLogic.get_root_nodes(canvas); for (let node of root_nodes) ParserLogic.build_node(node); @@ -86,15 +86,15 @@ class ParserLogic { // Create node let v: any = ParserLogic.create_class_instance(node.type, []); - ParserLogic.nodeMap.set(name, v); - ParserLogic.rawMap.set(v, node); + ParserLogic.node_map.set(name, v); + ParserLogic.raw_map.set(v, node); // Expose button values in node class for (let b of node.buttons) { if (b.type == "ENUM") { // let arrayData: bool = Array.isArray(b.data); - let arrayData: bool = b.data.length > 1; - let texts: string[] = arrayData ? b.data : zui_enum_texts_js(node.type); + let array_data: bool = b.data.length > 1; + let texts: string[] = array_data ? b.data : zui_enum_texts_js(node.type); v[b.name] = texts[b.default_value]; } else { @@ -110,7 +110,7 @@ class ParserLogic { // Is linked - find node let l: zui_node_link_t = ParserLogic.get_input_link(inp); if (l != null) { - inp_node = ParserLogic.nodeMap.get(ParserLogic.build_node(ParserLogic.get_node(l.from_id))); + inp_node = ParserLogic.node_map.get(ParserLogic.build_node(ParserLogic.get_node(l.from_id))); inp_from = l.from_socket; } // Not linked - create node with default values @@ -124,21 +124,21 @@ class ParserLogic { // Create outputss for (let out of node.outputs) { - let outNodes: LogicNode[] = []; + let out_nodes: LogicNode[] = []; let ls: zui_node_link_t[] = ParserLogic.get_output_links(out); if (ls != null && ls.length > 0) { for (let l of ls) { let n: zui_node_t = ParserLogic.get_node(l.to_id); let out_name: string = ParserLogic.build_node(n); - outNodes.push(ParserLogic.nodeMap.get(out_name)); + out_nodes.push(ParserLogic.node_map.get(out_name)); } } // Not linked - create node with default values else { - outNodes.push(ParserLogic.build_default_node(out)); + out_nodes.push(ParserLogic.build_default_node(out)); } // Add outputs - v.add_outputs(outNodes); + v.add_outputs(out_nodes); } return name; @@ -196,9 +196,9 @@ class ParserLogic { } static create_class_instance = (className: string, args: any[]): any => { - if (ParserLogic.customNodes.get(className) != null) { + if (ParserLogic.custom_nodes.get(className) != null) { let node: LogicNode = new LogicNode(); - node.get = (from: i32) => { return ParserLogic.customNodes.get(className)(node, from); } + node.get = (from: i32) => { return ParserLogic.custom_nodes.get(className)(node, from); } return node; } let dynamic_class: any = eval(`${className}`); diff --git a/base/Sources/ParserMaterial.ts b/base/Sources/ParserMaterial.ts index 0028bbda..03b85cbc 100644 --- a/base/Sources/ParserMaterial.ts +++ b/base/Sources/ParserMaterial.ts @@ -1870,7 +1870,7 @@ class ParserMaterial { } static make_texture = (image_node: zui_node_t, tex_name: string, matname: string = null): bind_tex_t => { - let filepath: string = ParserMaterial.enum_data(Base.enum_texts(image_node.type)[image_node.buttons[0].default_value]); + let filepath: string = ParserMaterial.enum_data(base_enum_texts(image_node.type)[image_node.buttons[0].default_value]); if (filepath == "" || filepath.indexOf(".") == -1) { return null; } diff --git a/base/Sources/PhysicsBody.ts b/base/Sources/PhysicsBody.ts index 47352ced..aeda70c7 100644 --- a/base/Sources/PhysicsBody.ts +++ b/base/Sources/PhysicsBody.ts @@ -109,49 +109,49 @@ class PhysicsBody { pb.btshape = new Ammo.btSphereShape(PhysicsBody.with_margin(pb, transform.dim.x / 2)); } else if (pb.shape == shape_type_t.CONVEX_HULL) { - let shapeConvex: Ammo.btConvexHullShape = PhysicsBody.fill_convex_hull(pb, transform.scale, pb.collision_margin); - pb.btshape = shapeConvex; + let shape_convex: Ammo.btConvexHullShape = PhysicsBody.fill_convex_hull(pb, transform.scale, pb.collision_margin); + pb.btshape = shape_convex; } else if (pb.shape == shape_type_t.CONE) { - let coneZ: Ammo.btConeShapeZ = new Ammo.btConeShapeZ( + let cone_z: Ammo.btConeShapeZ = new Ammo.btConeShapeZ( PhysicsBody.with_margin(pb, transform.dim.x / 2), // Radius PhysicsBody.with_margin(pb, transform.dim.z)); // Height - let cone: Ammo.btConeShape = coneZ; + let cone: Ammo.btConeShape = cone_z; pb.btshape = cone; } else if (pb.shape == shape_type_t.CYLINDER) { PhysicsWorld.vec1.setX(PhysicsBody.with_margin(pb, transform.dim.x / 2)); PhysicsWorld.vec1.setY(PhysicsBody.with_margin(pb, transform.dim.y / 2)); PhysicsWorld.vec1.setZ(PhysicsBody.with_margin(pb, transform.dim.z / 2)); - let cylZ: Ammo.btCylinderShapeZ = new Ammo.btCylinderShapeZ(PhysicsWorld.vec1); - let cyl: Ammo.btCylinderShape = cylZ; + let cyl_z: Ammo.btCylinderShapeZ = new Ammo.btCylinderShapeZ(PhysicsWorld.vec1); + let cyl: Ammo.btCylinderShape = cyl_z; pb.btshape = cyl; } else if (pb.shape == shape_type_t.CAPSULE) { let r: f32 = transform.dim.x / 2; - let capsZ: Ammo.btCapsuleShapeZ = new Ammo.btCapsuleShapeZ( + let caps_z: Ammo.btCapsuleShapeZ = new Ammo.btCapsuleShapeZ( PhysicsBody.with_margin(pb, r), // Radius PhysicsBody.with_margin(pb, transform.dim.z - r * 2)); // Distance between 2 sphere centers - let caps: Ammo.btCapsuleShape = capsZ; + let caps: Ammo.btCapsuleShape = caps_z; pb.btshape = caps; } else if (pb.shape == shape_type_t.MESH) { - let meshInterface: Ammo.btTriangleMesh = PhysicsBody.fill_triangle_mesh(pb, transform.scale); + let mesh_interface: Ammo.btTriangleMesh = PhysicsBody.fill_triangle_mesh(pb, transform.scale); if (pb.mass > 0) { - let shapeGImpact: Ammo.btGImpactMeshShape = new Ammo.btGImpactMeshShape(meshInterface); - shapeGImpact.updateBound(); - let shapeConcave: Ammo.btConcaveShape = shapeGImpact; - pb.btshape = shapeConcave; + let shape_gimpact: Ammo.btGImpactMeshShape = new Ammo.btGImpactMeshShape(mesh_interface); + shape_gimpact.updateBound(); + let shape_concave: Ammo.btConcaveShape = shape_gimpact; + pb.btshape = shape_concave; if (!PhysicsBody.gimpact_registered) { PhysicsBody.gimpact_registered = true; new Ammo.GImpactCollisionAlgorithm().registerAlgorithm(physics.dispatcher); } } else { - let shapeBvh: Ammo.btBvhTriangleMeshShape = new Ammo.btBvhTriangleMeshShape(meshInterface, true, true); - let shapeTri: Ammo.btTriangleMeshShape = shapeBvh; - let shapeConcave: Ammo.btConcaveShape = shapeTri; - pb.btshape = shapeConcave; + let shape_bvh: Ammo.btBvhTriangleMeshShape = new Ammo.btBvhTriangleMeshShape(mesh_interface, true, true); + let shape_tri: Ammo.btTriangleMeshShape = shape_bvh; + let shape_concave: Ammo.btConcaveShape = shape_tri; + pb.btshape = shape_concave; } } else if (pb.shape == shape_type_t.TERRAIN) { @@ -165,8 +165,8 @@ class PhysicsBody { } let slice: i32 = Math.floor(Math.sqrt(length)); // Assuming square terrain data let axis: i32 = 2; // z - let dataType: i32 = 5; // u8 - pb.btshape = new Ammo.btHeightfieldTerrainShape(slice, slice, PhysicsBody.ammo_array, 1 / 255, 0, 1, axis, dataType, false); + let data_type: i32 = 5; // u8 + pb.btshape = new Ammo.btHeightfieldTerrainShape(slice, slice, PhysicsBody.ammo_array, 1 / 255, 0, 1, axis, data_type, false); PhysicsBody.vec1.setX(transform.dim.x / slice); PhysicsBody.vec1.setY(transform.dim.y / slice); PhysicsBody.vec1.setZ(transform.dim.z); @@ -192,8 +192,8 @@ class PhysicsBody { if (pb.mass > 0) { pb.btshape.calculateLocalInertia(pb.mass, inertia); } - let bodyCI: Ammo.btRigidBodyConstructionInfo = new Ammo.btRigidBodyConstructionInfo(pb.mass, pb.motion_state, pb.btshape, inertia); - pb.body = new Ammo.btRigidBody(bodyCI); + let body_ci: Ammo.btRigidBodyConstructionInfo = new Ammo.btRigidBodyConstructionInfo(pb.mass, pb.motion_state, pb.btshape, inertia); + pb.body = new Ammo.btRigidBody(body_ci); pb.body.setFriction(pb.friction); if (pb.shape == shape_type_t.SPHERE || pb.shape == shape_type_t.CYLINDER || pb.shape == shape_type_t.CONE || pb.shape == shape_type_t.CAPSULE) { @@ -226,7 +226,7 @@ class PhysicsBody { // notifyOnRemove(removeFromWorld); - Ammo.destroy(bodyCI); + Ammo.destroy(body_ci); } static physics_update = (pb: PhysicsBodyRaw) => { @@ -343,9 +343,9 @@ class PhysicsBody { PhysicsBody.vec1.setY(v.y / pb.body_scale_y); PhysicsBody.vec1.setZ(v.z / pb.body_scale_z); pb.btshape.setLocalScaling(PhysicsBody.vec1); - let worldDyn: Ammo.btDynamicsWorld = PhysicsWorld.active.world; - let worldCol: Ammo.btCollisionWorld = worldDyn; - worldCol.updateSingleAabb(pb.body); + let world_dyn: Ammo.btDynamicsWorld = PhysicsWorld.active.world; + let world_col: Ammo.btCollisionWorld = world_dyn; + world_col.updateSingleAabb(pb.body); } static sync_transform = (pb: PhysicsBodyRaw) => { @@ -403,14 +403,14 @@ class PhysicsBody { static fill_triangle_mesh = (pb: PhysicsBodyRaw, scale: vec4_t): Ammo.btTriangleMesh => { // Check whether shape already exists let data: any = pb.object.ext.data; - let triangleMesh: Ammo.btTriangleMesh = PhysicsBody.triangle_mesh_cache.get(data); - if (triangleMesh != null) { + let triangle_mesh: Ammo.btTriangleMesh = PhysicsBody.triangle_mesh_cache.get(data); + if (triangle_mesh != null) { PhysicsBody.users_cache.set(data, PhysicsBody.users_cache.get(data) + 1); - return triangleMesh; + return triangle_mesh; } - triangleMesh = new Ammo.btTriangleMesh(true, true); - PhysicsBody.triangle_mesh_cache.set(data, triangleMesh); + triangle_mesh = new Ammo.btTriangleMesh(true, true); + PhysicsBody.triangle_mesh_cache.set(data, triangle_mesh); PhysicsBody.users_cache.set(data, 1); let positions: i16_array_t = mesh_data_get_vertex_array(data, 'pos').values; @@ -435,10 +435,10 @@ class PhysicsBody { PhysicsBody.vec3.setX(positions[ar[i * 3 + 2] * 4 ] * sx); PhysicsBody.vec3.setY(positions[ar[i * 3 + 2] * 4 + 1] * sy); PhysicsBody.vec3.setZ(positions[ar[i * 3 + 2] * 4 + 2] * sz); - triangleMesh.addTriangle(PhysicsBody.vec1, PhysicsBody.vec2, PhysicsBody.vec3); + triangle_mesh.addTriangle(PhysicsBody.vec1, PhysicsBody.vec2, PhysicsBody.vec3); } } - return triangleMesh; + return triangle_mesh; } static delete = (pb: PhysicsBodyRaw) => { diff --git a/base/Sources/PhysicsWorld.ts b/base/Sources/PhysicsWorld.ts index c11f19a2..71c5c95c 100644 --- a/base/Sources/PhysicsWorld.ts +++ b/base/Sources/PhysicsWorld.ts @@ -5,10 +5,10 @@ class PhysicsWorldRaw { world: Ammo.btDiscreteDynamicsWorld; dispatcher: Ammo.btCollisionDispatcher; contacts: pair_t[] = []; - bodyMap: Map = new Map(); - timeScale: f32 = 1.0; - timeStep: f32 = 1 / 60; - maxSteps: i32 = 1; + body_map: Map = new Map(); + time_scale: f32 = 1.0; + time_step: f32 = 1 / 60; + max_steps: i32 = 1; } class PhysicsWorld { @@ -36,15 +36,15 @@ class PhysicsWorld { } static reset = (pw: PhysicsWorldRaw) => { - for (let body of pw.bodyMap.values()) PhysicsWorld.remove_body(pw, body); + for (let body of pw.body_map.values()) PhysicsWorld.remove_body(pw, body); } static init = (pw: PhysicsWorldRaw) => { let broadphase: Ammo.btDbvtBroadphase = new Ammo.btDbvtBroadphase(); - let collisionConfiguration: Ammo.btDefaultCollisionConfiguration = new Ammo.btDefaultCollisionConfiguration(); - pw.dispatcher = new Ammo.btCollisionDispatcher(collisionConfiguration); + let collision_conf: Ammo.btDefaultCollisionConfiguration = new Ammo.btDefaultCollisionConfiguration(); + pw.dispatcher = new Ammo.btCollisionDispatcher(collision_conf); let solver: Ammo.btSequentialImpulseConstraintSolver = new Ammo.btSequentialImpulseConstraintSolver(); - pw.world = new Ammo.btDiscreteDynamicsWorld(pw.dispatcher, broadphase, solver, collisionConfiguration); + pw.world = new Ammo.btDiscreteDynamicsWorld(pw.dispatcher, broadphase, solver, collision_conf); PhysicsWorld.set_gravity(pw, vec4_create(0, 0, -9.81)); } @@ -55,14 +55,14 @@ class PhysicsWorld { static add_body = (pw: PhysicsWorldRaw, pb: PhysicsBodyRaw) => { pw.world.addRigidBody(pb.body, pb.group, pb.mask); - pw.bodyMap.set(pb.id, pb); + pw.body_map.set(pb.id, pb); } static remove_body = (pw: PhysicsWorldRaw, pb: PhysicsBodyRaw) => { if (pb.destroyed) return; pb.destroyed = true; if (pw.world != null) pw.world.removeRigidBody(pb.body); - pw.bodyMap.delete(pb.id); + pw.body_map.delete(pb.id); PhysicsBody.delete(pb); } @@ -72,8 +72,8 @@ class PhysicsWorld { for (let i: i32 = 0; i < pw.contacts.length; ++i) { let c: pair_t = pw.contacts[i]; let pb: PhysicsBodyRaw = null; - if (c.a == pb.body.userIndex) pb = pw.bodyMap.get(c.b); - else if (c.b == pb.body.userIndex) pb = pw.bodyMap.get(c.a); + if (c.a == pb.body.userIndex) pb = pw.body_map.get(c.b); + else if (c.b == pb.body.userIndex) pb = pw.body_map.get(c.a); if (pb != null && res.indexOf(pb) == -1) res.push(pb); } return res; @@ -91,40 +91,40 @@ class PhysicsWorld { } static late_update = (pw: PhysicsWorldRaw) => { - let t: f32 = time_delta() * pw.timeScale; + let t: f32 = time_delta() * pw.time_scale; if (t == 0.0) return; // Simulation paused - pw.world.stepSimulation(pw.timeStep, pw.maxSteps, t); + pw.world.stepSimulation(pw.time_step, pw.max_steps, t); PhysicsWorld.update_contacts(pw); - for (let body of pw.bodyMap.values()) PhysicsBody.physics_update(body); + for (let body of pw.body_map.values()) PhysicsBody.physics_update(body); } static update_contacts = (pw: PhysicsWorldRaw) => { pw.contacts = []; let disp: Ammo.btDispatcher = pw.dispatcher; - let numManifolds: i32 = disp.getNumManifolds(); + let num_manifolds: i32 = disp.getNumManifolds(); - for (let i: i32 = 0; i < numManifolds; ++i) { - let contactManifold: Ammo.btPersistentManifold = disp.getManifoldByIndexInternal(i); - let body0: Ammo.btRigidBody = Ammo.btRigidBody.prototype.upcast(contactManifold.getBody0()); - let body1: Ammo.btRigidBody = Ammo.btRigidBody.prototype.upcast(contactManifold.getBody1()); + for (let i: i32 = 0; i < num_manifolds; ++i) { + let contact_manifold: Ammo.btPersistentManifold = disp.getManifoldByIndexInternal(i); + let body0: Ammo.btRigidBody = Ammo.btRigidBody.prototype.upcast(contact_manifold.getBody0()); + let body1: Ammo.btRigidBody = Ammo.btRigidBody.prototype.upcast(contact_manifold.getBody1()); - let numContacts: i32 = contactManifold.getNumContacts(); + let num_contacts: i32 = contact_manifold.getNumContacts(); let pt: Ammo.btManifoldPoint = null; - let posA: Ammo.btVector3 = null; - let posB: Ammo.btVector3 = null; + let pos_a: Ammo.btVector3 = null; + let pos_b: Ammo.btVector3 = null; let nor: Ammo.btVector3 = null; - for (let j: i32 = 0; j < numContacts; ++j) { - pt = contactManifold.getContactPoint(j); - posA = pt.get_m_positionWorldOnA(); - posB = pt.get_m_positionWorldOnB(); + for (let j: i32 = 0; j < num_contacts; ++j) { + pt = contact_manifold.getContactPoint(j); + pos_a = pt.get_m_positionWorldOnA(); + pos_b = pt.get_m_positionWorldOnB(); nor = pt.get_m_normalWorldOnB(); let cp: pair_t = { a: body0.userIndex, b: body1.userIndex, - posA: vec4_create(posA.x(), posA.y(), posA.z()), - posB: vec4_create(posB.x(), posB.y(), posB.z()), - normOnB: vec4_create(nor.x(), nor.y(), nor.z()), + pos_a: vec4_create(pos_a.x(), pos_a.y(), pos_a.z()), + pos_b: vec4_create(pos_b.x(), pos_b.y(), pos_b.z()), + norm_on_b: vec4_create(nor.x(), nor.y(), nor.z()), impulse: pt.getAppliedImpulse(), distance: pt.getDistance() }; @@ -144,40 +144,40 @@ class PhysicsWorld { } static ray_cast = (pw: PhysicsWorldRaw, from: vec4_t, to: vec4_t, group: i32 = 0x00000001, mask: i32 = 0xffffffff): hit_t => { - let rayFrom: Ammo.btVector3 = PhysicsWorld.vec1; - let rayTo: Ammo.btVector3 = PhysicsWorld.vec2; - rayFrom.setValue(from.x, from.y, from.z); - rayTo.setValue(to.x, to.y, to.z); + let ray_from: Ammo.btVector3 = PhysicsWorld.vec1; + let ray_to: Ammo.btVector3 = PhysicsWorld.vec2; + ray_from.setValue(from.x, from.y, from.z); + ray_to.setValue(to.x, to.y, to.z); - let rayCallback: Ammo.ClosestRayResultCallback = new Ammo.ClosestRayResultCallback(rayFrom, rayTo); + let ray_callback: Ammo.ClosestRayResultCallback = new Ammo.ClosestRayResultCallback(ray_from, ray_to); - rayCallback.set_m_collisionFilterGroup(group); - rayCallback.set_m_collisionFilterMask(mask); + ray_callback.set_m_collisionFilterGroup(group); + ray_callback.set_m_collisionFilterMask(mask); - let worldDyn: Ammo.btDynamicsWorld = pw.world; - let worldCol: Ammo.btCollisionWorld = worldDyn; - worldCol.rayTest(rayFrom, rayTo, rayCallback); + let world_dyn: Ammo.btDynamicsWorld = pw.world; + let world_col: Ammo.btCollisionWorld = world_dyn; + world_col.rayTest(ray_from, ray_to, ray_callback); let pb: PhysicsBodyRaw = null; - let hitInfo: hit_t = null; + let hit_info: hit_t = null; - let rc: Ammo.RayResultCallback = rayCallback; + let rc: Ammo.RayResultCallback = ray_callback; if (rc.hasHit()) { - let co: Ammo.btCollisionObject = rayCallback.get_m_collisionObject(); + let co: Ammo.btCollisionObject = ray_callback.get_m_collisionObject(); let body: Ammo.btRigidBody = Ammo.btRigidBody.prototype.upcast(co); - let hit: Ammo.btVector3 = rayCallback.get_m_hitPointWorld(); + let hit: Ammo.btVector3 = ray_callback.get_m_hitPointWorld(); vec4_set(PhysicsWorld.v1, hit.x(), hit.y(), hit.z()); - let norm: Ammo.btVector3 = rayCallback.get_m_hitNormalWorld(); + let norm: Ammo.btVector3 = ray_callback.get_m_hitNormalWorld(); vec4_set(PhysicsWorld.v2, norm.x(), norm.y(), norm.z()); - pb = pw.bodyMap.get(body.userIndex); - hitInfo = { + pb = pw.body_map.get(body.userIndex); + hit_info = { body: pb, pos: PhysicsWorld.v1, normal: PhysicsWorld.v2 }; } - Ammo.destroy(rayCallback); - return hitInfo; + Ammo.destroy(ray_callback); + return hit_info; } } @@ -190,9 +190,9 @@ type hit_t = { type pair_t = { a?: i32; b?: i32; - posA?: vec4_t; - posB?: vec4_t; - normOnB?: vec4_t; + pos_a?: vec4_t; + pos_b?: vec4_t; + norm_on_b?: vec4_t; impulse?: f32; distance?: f32; }; diff --git a/base/Sources/Project.ts b/base/Sources/Project.ts index 1a4c5435..f0a9f3b5 100644 --- a/base/Sources/Project.ts +++ b/base/Sources/Project.ts @@ -46,9 +46,9 @@ class Project { static project_save = (saveAndQuit: bool = false) => { if (Project.filepath == "") { ///if krom_ios - let documentDirectory: string = krom_save_dialog("", ""); - documentDirectory = documentDirectory.substr(0, documentDirectory.length - 8); // Strip /'untitled' - Project.filepath = documentDirectory + "/" + sys_title() + ".arm"; + let document_directory: string = krom_save_dialog("", ""); + document_directory = document_directory.substr(0, document_directory.length - 8); // Strip /'untitled' + Project.filepath = document_directory + "/" + sys_title() + ".arm"; ///elseif krom_android Project.filepath = krom_save_path() + "/" + sys_title() + ".arm"; ///else @@ -168,7 +168,7 @@ class Project { raw = ImportMesh.raw_mesh(mesh); ///if is_sculpt - Base.notify_on_next_frame(() => { + base_notify_on_next_frame(() => { let f32a: Float32Array = new Float32Array(Config.get_texture_res_x() * Config.get_texture_res_y() * 4); for (let i: i32 = 0; i < Math.floor(mesh.inda.length); ++i) { let index: i32 = mesh.inda[i]; @@ -181,7 +181,7 @@ class Project { let imgmesh: image_t = image_from_bytes(f32a.buffer, Config.get_texture_res_x(), Config.get_texture_res_y(), tex_format_t.RGBA128); let texpaint: image_t = Project.layers[0].texpaint; g2_begin(texpaint); - g2_set_pipeline(Base.pipe_copy128); + g2_set_pipeline(base_pipe_copy128); g2_draw_scaled_image(imgmesh, 0, 0, Config.get_texture_res_x(), Config.get_texture_res_y()); g2_set_pipeline(null); g2_end(); @@ -239,7 +239,7 @@ class Project { Project.brushes = [SlotBrush.create()]; Context.raw.brush = Project.brushes[0]; - Project.fonts = [SlotFont.create("default.ttf", Base.font)]; + Project.fonts = [SlotFont.create("default.ttf", base_font)]; Context.raw.font = Project.fonts[0]; ///end @@ -272,17 +272,17 @@ class Project { if (resetLayers) { ///if (is_paint || is_sculpt) - let aspectRatioChanged: bool = Project.layers[0].texpaint.width != Config.get_texture_res_x() || Project.layers[0].texpaint.height != Config.get_texture_res_y(); + let aspect_ratio_changed: bool = Project.layers[0].texpaint.width != Config.get_texture_res_x() || Project.layers[0].texpaint.height != Config.get_texture_res_y(); while (Project.layers.length > 0) SlotLayer.unload(Project.layers.pop()); let layer: SlotLayerRaw = SlotLayer.create(); Project.layers.push(layer); Context.set_layer(layer); - if (aspectRatioChanged) { - app_notify_on_init(Base.resize_layers); + if (aspect_ratio_changed) { + app_notify_on_init(base_resize_layers); } ///end - app_notify_on_init(Base.init_layers); + app_notify_on_init(base_init_layers); } if (current != null) g2_begin(current); @@ -321,10 +321,10 @@ class Project { if (Path.is_texture(path)) { // Import texture ImportAsset.run(path); - let assetIndex: i32 = 0; + let asset_index: i32 = 0; for (let i: i32 = 0; i < Project.assets.length; ++i) { if (Project.assets[i].file == path) { - assetIndex = i; + asset_index = i; break; } } @@ -337,7 +337,7 @@ class Project { let n: zui_node_t = NodesBrush.create_node("TEX_IMAGE"); n.x = 83; n.y = 340; - n.buttons[0].default_value = assetIndex; + n.buttons[0].default_value = asset_index; let links: zui_node_link_t[] = Context.raw.brush.canvas.links; links.push({ id: zui_get_link_id(links), @@ -377,8 +377,8 @@ class Project { ///end UIBox.show_custom((ui: zui_t) => { - let tabVertical: bool = Config.raw.touch_ui; - if (zui_tab(zui_handle("project_3"), tr("Import Mesh"), tabVertical)) { + let tab_vertical: bool = Config.raw.touch_ui; + if (zui_tab(zui_handle("project_3"), tr("Import Mesh"), tab_vertical)) { if (path.toLowerCase().endsWith(".obj")) { Context.raw.split_by = zui_combo(zui_handle("project_4"), [ @@ -409,7 +409,7 @@ class Project { } if (zui_button(tr("Import")) || ui.is_return_down) { UIBox.hide(); - let doImport = () => { + let do_import = () => { ///if (is_paint || is_sculpt) ImportMesh.run(path, clearLayers, replaceExisting); ///end @@ -419,12 +419,12 @@ class Project { if (done != null) done(); } ///if (krom_android || krom_ios) - Base.notify_on_next_frame(() => { + base_notify_on_next_frame(() => { Console.toast(tr("Importing mesh")); - Base.notify_on_next_frame(doImport); + base_notify_on_next_frame(do_import); }); ///else - doImport(); + do_import(); ///end } if (zui_button(tr("?"))) { @@ -444,8 +444,8 @@ class Project { static unwrap_mesh_box = (mesh: any, done: (a: any)=>void, skipUI: bool = false) => { UIBox.show_custom((ui: zui_t) => { - let tabVertical: bool = Config.raw.touch_ui; - if (zui_tab(zui_handle("project_7"), tr("Unwrap Mesh"), tabVertical)) { + let tab_vertical: bool = Config.raw.touch_ui; + if (zui_tab(zui_handle("project_7"), tr("Unwrap Mesh"), tab_vertical)) { let unwrapPlugins: string[] = []; if (BoxPreferences.files_plugin == null) { @@ -458,7 +458,7 @@ class Project { } unwrapPlugins.push("equirect"); - let unwrapBy: i32 = zui_combo(zui_handle("project_8"), unwrapPlugins, tr("Plugin"), true); + let unwrap_by: i32 = zui_combo(zui_handle("project_8"), unwrapPlugins, tr("Plugin"), true); zui_row([0.5, 0.5]); if (zui_button(tr("Cancel"))) { @@ -466,12 +466,12 @@ class Project { } if (zui_button(tr("Unwrap")) || ui.is_return_down || skipUI) { UIBox.hide(); - let doUnwrap = () => { - if (unwrapBy == unwrapPlugins.length - 1) { + let do_unwrap = () => { + if (unwrap_by == unwrapPlugins.length - 1) { UtilMesh.equirect_unwrap(mesh); } else { - let f: string = unwrapPlugins[unwrapBy]; + let f: string = unwrapPlugins[unwrap_by]; if (Config.raw.plugins.indexOf(f) == -1) { Config.enable_plugin(f); Console.info(f + " " + tr("plugin enabled")); @@ -481,12 +481,12 @@ class Project { done(mesh); } ///if (krom_android || krom_ios) - Base.notify_on_next_frame(() => { + base_notify_on_next_frame(() => { Console.toast(tr("Unwrapping mesh")); - Base.notify_on_next_frame(doUnwrap); + base_notify_on_next_frame(do_unwrap); }); ///else - doUnwrap(); + do_unwrap(); ///end } } @@ -519,7 +519,7 @@ class Project { let i: i32 = Project.assets.indexOf(asset); data_delete_image(asset.file); Project.asset_map.delete(asset.id); - let oldAsset: asset_t = Project.assets[i]; + let old_asset: asset_t = Project.assets[i]; Project.assets.splice(i, 1); Project.asset_names.splice(i, 1); ImportTexture.run(asset.file); @@ -527,7 +527,7 @@ class Project { Project.asset_names.splice(i, 0, Project.asset_names.pop()); ///if (is_paint || is_sculpt) - if (Context.raw.texture == oldAsset) Context.raw.texture = Project.assets[i]; + if (Context.raw.texture == old_asset) Context.raw.texture = Project.assets[i]; ///end let _next = () => { @@ -538,7 +538,7 @@ class Project { UIBase.hwnds[tab_area_t.SIDEBAR1].redraws = 2; ///end } - Base.notify_on_next_frame(_next); + base_notify_on_next_frame(_next); } if (!File.exists(asset.file)) { let filters: string = Path.texture_formats.join(","); @@ -568,16 +568,16 @@ class Project { static is_atlas_object = (p: mesh_object_t): bool => { if (Context.raw.layer_filter <= Project.paint_objects.length) return false; - let atlasName: string = Project.get_used_atlases()[Context.raw.layer_filter - Project.paint_objects.length - 1]; - let atlasI: i32 = Project.atlas_names.indexOf(atlasName); - return atlasI == Project.atlas_objects[Project.paint_objects.indexOf(p)]; + let atlas_name: string = Project.get_used_atlases()[Context.raw.layer_filter - Project.paint_objects.length - 1]; + let atlas_i: i32 = Project.atlas_names.indexOf(atlas_name); + return atlas_i == Project.atlas_objects[Project.paint_objects.indexOf(p)]; } static get_atlas_objects = (objectMask: i32): mesh_object_t[] => { - let atlasName: string = Project.get_used_atlases()[objectMask - Project.paint_objects.length - 1]; - let atlasI: i32 = Project.atlas_names.indexOf(atlasName); + let atlas_name: string = Project.get_used_atlases()[objectMask - Project.paint_objects.length - 1]; + let atlas_i: i32 = Project.atlas_names.indexOf(atlas_name); let visibles: mesh_object_t[] = []; - for (let i: i32 = 0; i < Project.paint_objects.length; ++i) if (Project.atlas_objects[i] == atlasI) visibles.push(Project.paint_objects[i]); + for (let i: i32 = 0; i < Project.paint_objects.length; ++i) if (Project.atlas_objects[i] == atlas_i) visibles.push(Project.paint_objects[i]); return visibles; } ///end diff --git a/base/Sources/RenderPathBase.ts b/base/Sources/RenderPathBase.ts index d2f3ee57..9d4ad6c2 100644 --- a/base/Sources/RenderPathBase.ts +++ b/base/Sources/RenderPathBase.ts @@ -95,7 +95,7 @@ class RenderPathBase { } else { // Set current viewport - Context.raw.view_index = mouse_view_x() > Base.w() / 2 ? 1 : 0; + Context.raw.view_index = mouse_view_x() > base_w() / 2 ? 1 : 0; } let cam: camera_object_t = scene_camera; @@ -117,8 +117,8 @@ class RenderPathBase { } // Match projection matrix jitter - let skipTaa: bool = Context.raw.split_view || ((Context.raw.tool == workspace_tool_t.CLONE || Context.raw.tool == workspace_tool_t.BLUR || Context.raw.tool == workspace_tool_t.SMUDGE) && Context.raw.pdirty > 0); - scene_camera.frame = skipTaa ? 0 : RenderPathBase.taa_frame; + let skip_taa: bool = Context.raw.split_view || ((Context.raw.tool == workspace_tool_t.CLONE || Context.raw.tool == workspace_tool_t.BLUR || Context.raw.tool == workspace_tool_t.SMUDGE) && Context.raw.pdirty > 0); + scene_camera.frame = skip_taa ? 0 : RenderPathBase.taa_frame; camera_object_proj_jitter(scene_camera); camera_object_build_mat(scene_camera); } @@ -181,11 +181,11 @@ class RenderPathBase { ///if (krom_direct3d12 || krom_vulkan || krom_metal) if (Context.raw.viewport_mode == viewport_mode_t.PATH_TRACE) { ///if is_paint - let useLiveLayer: bool = Context.raw.tool == workspace_tool_t.MATERIAL; + let use_live_layer: bool = Context.raw.tool == workspace_tool_t.MATERIAL; ///else - let useLiveLayer: bool = false; + let use_live_layer: bool = false; ///end - RenderPathRaytrace.draw(useLiveLayer); + RenderPathRaytrace.draw(use_live_layer); return; } ///end @@ -200,13 +200,13 @@ class RenderPathBase { if (RenderPathBase.bloom_mipmaps == null) { RenderPathBase.bloom_mipmaps = []; - let prevScale: f32 = 1.0; + let prev_scale: f32 = 1.0; for (let i: i32 = 0; i < 10; ++i) { let t: render_target_t = render_target_create(); t.name = "bloom_mip_" + i; t.width = 0; t.height = 0; - t.scale = (prevScale *= 0.5); + t.scale = (prev_scale *= 0.5); t.format = "RGBA64"; RenderPathBase.bloom_mipmaps.push(render_path_create_render_target(t)); } @@ -215,24 +215,24 @@ class RenderPathBase { render_path_load_shader("shader_datas/bloom_pass/bloom_upsample_pass"); } - let bloomRadius: f32 = 6.5; - let minDim: f32 = Math.min(render_path_current_w,render_path_current_h); - let logMinDim: f32 = Math.max(1.0, Math.log2(minDim) + (bloomRadius - 8.0)); - let numMips: i32 = Math.floor(logMinDim); - RenderPathBase.bloom_sample_scale = 0.5 + logMinDim - numMips; + let bloom_radius: f32 = 6.5; + let min_dim: f32 = Math.min(render_path_current_w,render_path_current_h); + let log_min_dim: f32 = Math.max(1.0, Math.log2(min_dim) + (bloom_radius - 8.0)); + let num_mips: i32 = Math.floor(log_min_dim); + RenderPathBase.bloom_sample_scale = 0.5 + log_min_dim - num_mips; - for (let i: i32 = 0; i < numMips; ++i) { + for (let i: i32 = 0; i < num_mips; ++i) { RenderPathBase.bloom_current_mip = i; render_path_set_target(RenderPathBase.bloom_mipmaps[i].name); render_path_clear_target(); render_path_bind_target(i == 0 ? tex : RenderPathBase.bloom_mipmaps[i - 1].name, "tex"); render_path_draw_shader("shader_datas/bloom_pass/bloom_downsample_pass"); } - for (let i: i32 = 0; i < numMips; ++i) { - let mipLevel: i32 = numMips - 1 - i; - RenderPathBase.bloom_current_mip = mipLevel; - render_path_set_target(mipLevel == 0 ? tex : RenderPathBase.bloom_mipmaps[mipLevel - 1].name); - render_path_bind_target(RenderPathBase.bloom_mipmaps[mipLevel].name, "tex"); + for (let i: i32 = 0; i < num_mips; ++i) { + let mip_level: i32 = num_mips - 1 - i; + RenderPathBase.bloom_current_mip = mip_level; + render_path_set_target(mip_level == 0 ? tex : RenderPathBase.bloom_mipmaps[mip_level - 1].name); + render_path_bind_target(RenderPathBase.bloom_mipmaps[mip_level].name, "tex"); render_path_draw_shader("shader_datas/bloom_pass/bloom_upsample_pass"); } } @@ -252,11 +252,11 @@ class RenderPathBase { ///if (krom_direct3d12 || krom_vulkan || krom_metal) ///if is_paint - let useLiveLayer: bool = Context.raw.tool == workspace_tool_t.MATERIAL; + let use_live_layer: bool = Context.raw.tool == workspace_tool_t.MATERIAL; ///else - let useLiveLayer: bool = false; + let use_live_layer: bool = false; ///end - Context.raw.viewport_mode == viewport_mode_t.PATH_TRACE ? RenderPathRaytrace.draw(useLiveLayer) : drawCommands(); + Context.raw.viewport_mode == viewport_mode_t.PATH_TRACE ? RenderPathRaytrace.draw(use_live_layer) : drawCommands(); ///else drawCommands(); ///end @@ -277,7 +277,7 @@ class RenderPathBase { render_path_set_target(""); render_path_set_viewport(RenderPathBase.voxels_res, RenderPathBase.voxels_res); render_path_bind_target("voxels", "voxels"); - if (MakeMaterial.heightUsed) { + if (MakeMaterial.height_used) { let tid: i32 = 0; // Project.layers[0].id; render_path_bind_target("texpaint_pack" + tid, "texpaint_pack"); } @@ -469,8 +469,8 @@ class RenderPathBase { render_path_bind_target("gbuffer2", "sveloc"); render_path_draw_shader("shader_datas/smaa_neighborhood_blend/smaa_neighborhood_blend"); - let skipTaa: bool = Context.raw.split_view; - if (skipTaa) { + let skip_taa: bool = Context.raw.split_view; + if (skip_taa) { render_path_set_target("taa"); render_path_bind_target(current, "tex"); render_path_draw_shader("shader_datas/copy_pass/copy_pass"); @@ -533,8 +533,8 @@ class RenderPathBase { } let hide: bool = Operator.shortcut(Config.keymap.stencil_hide, ShortcutType.ShortcutDown) || keyboard_down("control"); - let isDecal: bool = Base.is_decal_layer(); - if (isDecal && !hide) LineDraw.render(Context.raw.layer.decalMat); + let is_decal: bool = base_is_decal_layer(); + if (is_decal && !hide) LineDraw.render(Context.raw.layer.decal_mat); } static make_gbuffer_copy_textures = () => { diff --git a/base/Sources/RenderPathRaytrace.ts b/base/Sources/RenderPathRaytrace.ts index 0bd331dd..1feeb321 100644 --- a/base/Sources/RenderPathRaytrace.ts +++ b/base/Sources/RenderPathRaytrace.ts @@ -47,21 +47,21 @@ class RenderPathRaytrace { } let probe: world_data_t = scene_world; - let savedEnvmap: image_t = Context.raw.show_envmap_blur ? probe._.radiance_mipmaps[0] : Context.raw.saved_envmap; + let saved_envmap: image_t = Context.raw.show_envmap_blur ? probe._.radiance_mipmaps[0] : Context.raw.saved_envmap; - if (RenderPathRaytrace.last_envmap != savedEnvmap) { - RenderPathRaytrace.last_envmap = savedEnvmap; + if (RenderPathRaytrace.last_envmap != saved_envmap) { + RenderPathRaytrace.last_envmap = saved_envmap; let bnoise_sobol: image_t = scene_embedded.get("bnoise_sobol.k"); let bnoise_scramble: image_t = scene_embedded.get("bnoise_scramble.k"); let bnoise_rank: image_t = scene_embedded.get("bnoise_rank.k"); - let l: any = Base.flatten(true); - krom_raytrace_set_textures(l.texpaint, l.texpaint_nor, l.texpaint_pack, savedEnvmap.texture_, bnoise_sobol.texture_, bnoise_scramble.texture_, bnoise_rank.texture_); + let l: any = base_flatten(true); + krom_raytrace_set_textures(l.texpaint, l.texpaint_nor, l.texpaint_pack, saved_envmap.texture_, bnoise_sobol.texture_, bnoise_scramble.texture_, bnoise_rank.texture_); } ///if is_lab - let l: any = Base.flatten(true); + let l: any = base_flatten(true); if (l.texpaint != RenderPathRaytrace.last_texpaint) { RenderPathRaytrace.last_texpaint = l.texpaint; @@ -69,12 +69,12 @@ class RenderPathRaytrace { let bnoise_scramble: image_t = scene_embedded.get("bnoise_scramble.k"); let bnoise_rank: image_t = scene_embedded.get("bnoise_rank.k"); - krom_raytrace_set_textures(l.texpaint, l.texpaint_nor, l.texpaint_pack, savedEnvmap.texture_, bnoise_sobol.texture_, bnoise_scramble.texture_, bnoise_rank.texture_); + krom_raytrace_set_textures(l.texpaint, l.texpaint_nor, l.texpaint_pack, saved_envmap.texture_, bnoise_sobol.texture_, bnoise_scramble.texture_, bnoise_rank.texture_); } ///end if (Context.raw.pdirty > 0 || RenderPathRaytrace.dirty > 0) { - Base.flatten(true); + base_flatten(true); } let cam: camera_object_t = scene_camera; @@ -163,8 +163,8 @@ class RenderPathRaytrace { } static draw = (useLiveLayer: bool) => { - let isLive: bool = Config.raw.brush_live && RenderPathPaint.liveLayerDrawn > 0; - if (Context.raw.ddirty > 1 || Context.raw.pdirty > 0 || isLive) RenderPathRaytrace.frame = 0; + let is_live: bool = Config.raw.brush_live && RenderPathPaint.live_layer_drawn > 0; + if (Context.raw.ddirty > 1 || Context.raw.pdirty > 0 || is_live) RenderPathRaytrace.frame = 0; ///if krom_metal // Delay path tracing additional samples while painting diff --git a/base/Sources/RenderPathRaytraceBake.ts b/base/Sources/RenderPathRaytraceBake.ts index c21c5318..86ae0da7 100644 --- a/base/Sources/RenderPathRaytraceBake.ts +++ b/base/Sources/RenderPathRaytraceBake.ts @@ -52,18 +52,18 @@ class RenderPathRaytraceBake { render_path_create_render_target(t); } - let _bakeType: bake_type_t = Context.raw.bake_type; + let _bake_type: bake_type_t = Context.raw.bake_type; Context.raw.bake_type = bake_type_t.INIT; parsePaintMaterial(); render_path_set_target("baketex0"); render_path_clear_target(0x00000000); // Pixels with alpha of 0.0 are skipped during raytracing render_path_set_target("baketex0", ["baketex1"]); render_path_draw_meshes("paint"); - Context.raw.bake_type = _bakeType; + Context.raw.bake_type = _bake_type; let _next = () => { parsePaintMaterial(); } - Base.notify_on_next_frame(_next); + base_notify_on_next_frame(_next); RenderPathRaytrace.raytrace_init(RenderPathRaytraceBake.get_bake_shader_name(), rebuild); @@ -75,9 +75,9 @@ class RenderPathRaytraceBake { Context.update_envmap(); } let probe: world_data_t = scene_world; - let savedEnvmap: image_t = Context.raw.show_envmap_blur ? probe._.radiance_mipmaps[0] : Context.raw.saved_envmap; - if (RenderPathRaytrace.last_envmap != savedEnvmap || RenderPathRaytraceBake.last_layer != Context.raw.layer.texpaint) { - RenderPathRaytrace.last_envmap = savedEnvmap; + let saved_envmap: image_t = Context.raw.show_envmap_blur ? probe._.radiance_mipmaps[0] : Context.raw.saved_envmap; + if (RenderPathRaytrace.last_envmap != saved_envmap || RenderPathRaytraceBake.last_layer != Context.raw.layer.texpaint) { + RenderPathRaytrace.last_envmap = saved_envmap; RenderPathRaytraceBake.last_layer = Context.raw.layer.texpaint; let baketex0: image_t = render_path_render_targets.get("baketex0")._image; @@ -86,7 +86,7 @@ class RenderPathRaytraceBake { let bnoise_scramble: image_t = scene_embedded.get("bnoise_scramble.k"); let bnoise_rank: image_t = scene_embedded.get("bnoise_rank.k"); let texpaint_undo: image_t = render_path_render_targets.get("texpaint_undo" + History.undo_i)._image; - krom_raytrace_set_textures(baketex0, baketex1, texpaint_undo, savedEnvmap.texture_, bnoise_sobol.texture_, bnoise_scramble.texture_, bnoise_rank.texture_); + krom_raytrace_set_textures(baketex0, baketex1, texpaint_undo, saved_envmap.texture_, bnoise_sobol.texture_, bnoise_scramble.texture_, bnoise_rank.texture_); } if (Context.raw.brush_time > 0) { @@ -112,13 +112,13 @@ class RenderPathRaytraceBake { render_path_draw_shader("shader_datas/copy_pass/copy_pass"); ///if krom_metal - let samplesPerFrame: i32 = 4; + let samples_per_frame: i32 = 4; ///else - let samplesPerFrame: i32 = 64; + let samples_per_frame: i32 = 64; ///end - RenderPathRaytraceBake.rays_pix = RenderPathRaytrace.frame * samplesPerFrame; - RenderPathRaytraceBake.rays_counter += samplesPerFrame; + RenderPathRaytraceBake.rays_pix = RenderPathRaytrace.frame * samples_per_frame; + RenderPathRaytraceBake.rays_counter += samples_per_frame; RenderPathRaytraceBake.rays_timer += time_real_delta(); if (RenderPathRaytraceBake.rays_timer >= 1) { RenderPathRaytraceBake.rays_sec = RenderPathRaytraceBake.rays_counter; diff --git a/base/Sources/TabBrowser.ts b/base/Sources/TabBrowser.ts index e61de832..c5d02795 100644 --- a/base/Sources/TabBrowser.ts +++ b/base/Sources/TabBrowser.ts @@ -21,19 +21,19 @@ class TabBrowser { Config.raw.bookmarks = []; } - let bookmarksW: i32 = Math.floor(100 * zui_SCALE(ui)); + let bookmarks_w: i32 = Math.floor(100 * zui_SCALE(ui)); if (TabBrowser.hpath.text == "" && Config.raw.bookmarks.length > 0) { // Init to first bookmark TabBrowser.hpath.text = Config.raw.bookmarks[0]; } zui_begin_sticky(); - let step: i32 = (1 - bookmarksW / ui._w); + let step: i32 = (1 - bookmarks_w / ui._w); if (TabBrowser.hsearch.text != "") { - zui_row([bookmarksW / ui._w, step * 0.73, step * 0.07, step * 0.17, step * 0.03]); + zui_row([bookmarks_w / ui._w, step * 0.73, step * 0.07, step * 0.17, step * 0.03]); } else { - zui_row([bookmarksW / ui._w, step * 0.73, step * 0.07, step * 0.2]); + zui_row([bookmarks_w / ui._w, step * 0.73, step * 0.07, step * 0.2]); } if (zui_button("+")) { @@ -60,9 +60,9 @@ class TabBrowser { ///end let refresh: bool = false; - let inFocus: bool = ui.input_x > ui._window_x && ui.input_x < ui._window_x + ui._window_w && + let in_focus: bool = ui.input_x > ui._window_x && ui.input_x < ui._window_x + ui._window_w && ui.input_y > ui._window_y && ui.input_y < ui._window_y + ui._window_h; - if (zui_button(tr("Refresh")) || (inFocus && ui.is_key_pressed && ui.key == key_code_t.F5)) { + if (zui_button(tr("Refresh")) || (in_focus && ui.is_key_pressed && ui.key == key_code_t.F5)) { refresh = true; } TabBrowser.hsearch.text = zui_text_input(TabBrowser.hsearch, tr("Search"), zui_align_t.LEFT, true, true); @@ -81,11 +81,11 @@ class TabBrowser { TabBrowser.last_path = TabBrowser.hpath.text; let _y: f32 = ui._y; - ui._x = bookmarksW; - ui._w -= bookmarksW; + ui._x = bookmarks_w; + ui._w -= bookmarks_w; UIFiles.file_browser(ui, TabBrowser.hpath, false, true, TabBrowser.hsearch.text, refresh, (file: string) => { - let fileName: string = file.substr(file.lastIndexOf(Path.sep) + 1); - if (fileName != "..") { + let file_name: string = file.substr(file.lastIndexOf(Path.sep) + 1); + if (file_name != "..") { UIMenu.draw((ui: zui_t) => { if (UIMenu.menu_button(ui, tr("Import"))) { ImportAsset.run(file); @@ -93,16 +93,16 @@ class TabBrowser { if (Path.is_texture(file)) { if (UIMenu.menu_button(ui, tr("Set as Envmap"))) { ImportAsset.run(file, -1.0, -1.0, true, true, () => { - Base.notify_on_next_frame(() => { - let assetIndex: i32 = -1; + base_notify_on_next_frame(() => { + let asset_index: i32 = -1; for (let i: i32 = 0; i < Project.assets.length; ++i) { if (Project.assets[i].file == file) { - assetIndex = i; + asset_index = i; break; } } - if (assetIndex != -1) { - ImportEnvmap.run(file, Project.get_image(Project.assets[assetIndex])); + if (asset_index != -1) { + ImportEnvmap.run(file, Project.get_image(Project.assets[asset_index])); } }); }); @@ -111,16 +111,16 @@ class TabBrowser { ///if (is_paint || is_sculpt) if (UIMenu.menu_button(ui, tr("Set as Mask"))) { ImportAsset.run(file, -1.0, -1.0, true, true, () => { - Base.notify_on_next_frame(() => { - let assetIndex: i32 = -1; + base_notify_on_next_frame(() => { + let asset_index: i32 = -1; for (let i: i32 = 0; i < Project.assets.length; ++i) { if (Project.assets[i].file == file) { - assetIndex = i; + asset_index = i; break; } } - if (assetIndex != -1) { - Base.create_image_mask(Project.assets[assetIndex]); + if (asset_index != -1) { + base_create_image_mask(Project.assets[asset_index]); } }); }); @@ -130,16 +130,16 @@ class TabBrowser { ///if is_paint if (UIMenu.menu_button(ui, tr("Set as Color ID Map"))) { ImportAsset.run(file, -1.0, -1.0, true, true, () => { - Base.notify_on_next_frame(() => { - let assetIndex: i32 = -1; + base_notify_on_next_frame(() => { + let asset_index: i32 = -1; for (let i: i32 = 0; i < Project.assets.length; ++i) { if (Project.assets[i].file == file) { - assetIndex = i; + asset_index = i; break; } } - if (assetIndex != -1) { - Context.raw.colorid_handle.position = assetIndex; + if (asset_index != -1) { + Context.raw.colorid_handle.position = asset_index; Context.raw.colorid_picked = false; UIToolbar.toolbar_handle.redraws = 1; if (Context.raw.tool == workspace_tool_t.COLORID) { @@ -171,10 +171,10 @@ class TabBrowser { if (TabBrowser.hpath.text.endsWith("." + manifest_title.toLowerCase())) TabBrowser.known = false; ///end - let bottomY: i32 = ui._y; + let bottom_y: i32 = ui._y; ui._x = 0; ui._y = _y; - ui._w = bookmarksW; + ui._w = bookmarks_w; if (zui_button(tr("Cloud"), zui_align_t.LEFT)) { TabBrowser.hpath.text = "cloud"; @@ -218,7 +218,7 @@ class TabBrowser { } } - if (ui._y < bottomY) ui._y = bottomY; + if (ui._y < bottom_y) ui._y = bottom_y; } } } diff --git a/base/Sources/TabBrushes.ts b/base/Sources/TabBrushes.ts index 45b5492c..377a7660 100644 --- a/base/Sources/TabBrushes.ts +++ b/base/Sources/TabBrushes.ts @@ -45,7 +45,7 @@ class TabBrushes { continue; } let img: image_t = zui_SCALE(ui) > 1 ? Project.brushes[i].image : Project.brushes[i].image_icon; - let imgFull: image_t = Project.brushes[i].image; + let img_full: image_t = Project.brushes[i].image; if (Context.raw.brush == Project.brushes[i]) { // Zui.fill(1, -2, img.width + 3, img.height + 3, ui.t.HIGHLIGHT_COL); // TODO @@ -100,7 +100,7 @@ class TabBrushes { } if (ui.is_hovered) { - if (imgFull == null) { + if (img_full == null) { app_notify_on_init(() => { let _brush: SlotBrushRaw = Context.raw.brush; Context.raw.brush = Project.brushes[i]; @@ -110,7 +110,7 @@ class TabBrushes { }); } else { - zui_tooltip_image(imgFull); + zui_tooltip_image(img_full); zui_tooltip(Project.brushes[i].canvas.name); } } @@ -130,9 +130,9 @@ class TabBrushes { ui._y += 6; } - let inFocus: bool = ui.input_x > ui._window_x && ui.input_x < ui._window_x + ui._window_w && - ui.input_y > ui._window_y && ui.input_y < ui._window_y + ui._window_h; - if (inFocus && ui.is_delete_down && Project.brushes.length > 1) { + let in_focus: bool = ui.input_x > ui._window_x && ui.input_x < ui._window_x + ui._window_w && + ui.input_y > ui._window_y && ui.input_y < ui._window_y + ui._window_h; + if (in_focus && ui.is_delete_down && Project.brushes.length > 1) { ui.is_delete_down = false; TabBrushes.delete_brush(Context.raw.brush); } diff --git a/base/Sources/TabFonts.ts b/base/Sources/TabFonts.ts index cada87cf..5efd8884 100644 --- a/base/Sources/TabFonts.ts +++ b/base/Sources/TabFonts.ts @@ -125,9 +125,9 @@ class TabFonts { ui._y += 6; } - let inFocus: bool = ui.input_x > ui._window_x && ui.input_x < ui._window_x + ui._window_w && - ui.input_y > ui._window_y && ui.input_y < ui._window_y + ui._window_h; - if (inFocus && ui.is_delete_down && Project.fonts.length > 1 && Context.raw.font.file != "") { + let in_focus: bool = ui.input_x > ui._window_x && ui.input_x < ui._window_x + ui._window_w && + ui.input_y > ui._window_y && ui.input_y < ui._window_y + ui._window_h; + if (in_focus && ui.is_delete_down && Project.fonts.length > 1 && Context.raw.font.file != "") { ui.is_delete_down = false; TabFonts.delete_font(Context.raw.font); } diff --git a/base/Sources/TabMaterials.ts b/base/Sources/TabMaterials.ts index 410fd79d..cc8c22d2 100644 --- a/base/Sources/TabMaterials.ts +++ b/base/Sources/TabMaterials.ts @@ -104,8 +104,8 @@ class TabMaterials { zui_image(Res.get("icons.k"), 0xffffffff, -1.0, tile, tile, tile, tile); // Draw material numbers when selecting a material via keyboard shortcut - let isTyping: bool = ui.is_typing || UIView2D.ui.is_typing || UINodes.ui.is_typing; - if (!isTyping) { + let is_typing: bool = ui.is_typing || UIView2D.ui.is_typing || UINodes.ui.is_typing; + if (!is_typing) { if (i < 9 && Operator.shortcut(Config.keymap.select_material, ShortcutType.ShortcutDown)) { let number: string = String(i + 1); let width: i32 = g2_font_width(ui.font, ui.font_size, number) + 10; @@ -124,20 +124,20 @@ class TabMaterials { ///if is_paint if (Context.raw.tool == workspace_tool_t.MATERIAL) { let _init = () => { - Base.update_fill_layers(); + base_update_fill_layers(); } app_notify_on_init(_init); } ///end } - Base.drag_off_x = -(mouse_x - uix - ui._window_x - 3); - Base.drag_off_y = -(mouse_y - uiy - ui._window_y + 1); - Base.drag_material = Context.raw.material; + base_drag_off_x = -(mouse_x - uix - ui._window_x - 3); + base_drag_off_y = -(mouse_y - uiy - ui._window_y + 1); + base_drag_material = Context.raw.material; // Double click to show nodes if (time_time() - Context.raw.select_time < 0.25) { UIBase.show_material_nodes(); - Base.drag_material = null; - Base.is_dragging = false; + base_drag_material = null; + base_is_dragging = false; } Context.raw.select_time = time_time(); } @@ -152,7 +152,7 @@ class TabMaterials { if (UIMenu.menu_button(ui, tr("To Fill Layer"))) { Context.select_material(i); - Base.create_fill_layer(); + base_create_fill_layer(); } if (UIMenu.menu_button(ui, tr("Export"))) { @@ -183,42 +183,42 @@ class TabMaterials { TabMaterials.delete_material(m); } - let baseHandle: zui_handle_t = zui_nest(zui_handle("tabmaterials_0"), m.id, {selected: m.paint_base}); - let opacHandle: zui_handle_t = zui_nest(zui_handle("tabmaterials_1"), m.id, {selected: m.paint_opac}); - let norHandle: zui_handle_t = zui_nest(zui_handle("tabmaterials_2"), m.id, {selected: m.paint_nor}); - let occHandle: zui_handle_t = zui_nest(zui_handle("tabmaterials_3"), m.id, {selected: m.paint_occ}); - let roughHandle: zui_handle_t = zui_nest(zui_handle("tabmaterials_4"), m.id, {selected: m.paint_rough}); - let metHandle: zui_handle_t = zui_nest(zui_handle("tabmaterials_5"), m.id, {selected: m.paint_met}); - let heightHandle: zui_handle_t = zui_nest(zui_handle("tabmaterials_6"), m.id, {selected: m.paint_height}); - let emisHandle: zui_handle_t = zui_nest(zui_handle("tabmaterials_7"), m.id, {selected: m.paint_emis}); - let subsHandle: zui_handle_t = zui_nest(zui_handle("tabmaterials_8"), m.id, {selected: m.paint_subs}); + let base_handle: zui_handle_t = zui_nest(zui_handle("tabmaterials_0"), m.id, {selected: m.paint_base}); + let opac_handle: zui_handle_t = zui_nest(zui_handle("tabmaterials_1"), m.id, {selected: m.paint_opac}); + let nor_handle: zui_handle_t = zui_nest(zui_handle("tabmaterials_2"), m.id, {selected: m.paint_nor}); + let occ_handle: zui_handle_t = zui_nest(zui_handle("tabmaterials_3"), m.id, {selected: m.paint_occ}); + let rough_handle: zui_handle_t = zui_nest(zui_handle("tabmaterials_4"), m.id, {selected: m.paint_rough}); + let met_handle: zui_handle_t = zui_nest(zui_handle("tabmaterials_5"), m.id, {selected: m.paint_met}); + let height_handle: zui_handle_t = zui_nest(zui_handle("tabmaterials_6"), m.id, {selected: m.paint_height}); + let emis_handle: zui_handle_t = zui_nest(zui_handle("tabmaterials_7"), m.id, {selected: m.paint_emis}); + let subs_handle: zui_handle_t = zui_nest(zui_handle("tabmaterials_8"), m.id, {selected: m.paint_subs}); UIMenu.menu_fill(ui); - m.paint_base = zui_check(baseHandle, tr("Base Color")); + m.paint_base = zui_check(base_handle, tr("Base Color")); UIMenu.menu_fill(ui); - m.paint_opac = zui_check(opacHandle, tr("Opacity")); + m.paint_opac = zui_check(opac_handle, tr("Opacity")); UIMenu.menu_fill(ui); - m.paint_nor = zui_check(norHandle, tr("Normal")); + m.paint_nor = zui_check(nor_handle, tr("Normal")); UIMenu.menu_fill(ui); - m.paint_occ = zui_check(occHandle, tr("Occlusion")); + m.paint_occ = zui_check(occ_handle, tr("Occlusion")); UIMenu.menu_fill(ui); - m.paint_rough = zui_check(roughHandle, tr("Roughness")); + m.paint_rough = zui_check(rough_handle, tr("Roughness")); UIMenu.menu_fill(ui); - m.paint_met = zui_check(metHandle, tr("Metallic")); + m.paint_met = zui_check(met_handle, tr("Metallic")); UIMenu.menu_fill(ui); - m.paint_height = zui_check(heightHandle, tr("Height")); + m.paint_height = zui_check(height_handle, tr("Height")); UIMenu.menu_fill(ui); - m.paint_emis = zui_check(emisHandle, tr("Emission")); + m.paint_emis = zui_check(emis_handle, tr("Emission")); UIMenu.menu_fill(ui); - m.paint_subs = zui_check(subsHandle, tr("Subsurface")); - if (baseHandle.changed || - opacHandle.changed || - norHandle.changed || - occHandle.changed || - roughHandle.changed || - metHandle.changed || - heightHandle.changed || - emisHandle.changed || - subsHandle.changed) { + m.paint_subs = zui_check(subs_handle, tr("Subsurface")); + if (base_handle.changed || + opac_handle.changed || + nor_handle.changed || + occ_handle.changed || + rough_handle.changed || + met_handle.changed || + height_handle.changed || + emis_handle.changed || + subs_handle.changed) { MakeMaterial.parse_paint_material(); UIMenu.keep_open = true; } @@ -252,9 +252,9 @@ class TabMaterials { ///end } - let inFocus: bool = ui.input_x > ui._window_x && ui.input_x < ui._window_x + ui._window_w && - ui.input_y > ui._window_y && ui.input_y < ui._window_y + ui._window_h; - if (inFocus && ui.is_delete_down && Project.materials.length > 1) { + let in_focus: bool = ui.input_x > ui._window_x && ui.input_x < ui._window_x + ui._window_w && + ui.input_y > ui._window_y && ui.input_y < ui._window_y + ui._window_h; + if (in_focus && ui.is_delete_down && Project.materials.length > 1) { ui.is_delete_down = false; TabMaterials.delete_material(Context.raw.material); } diff --git a/base/Sources/TabScript.ts b/base/Sources/TabScript.ts index 86ab14e3..8d0a6292 100644 --- a/base/Sources/TabScript.ts +++ b/base/Sources/TabScript.ts @@ -47,7 +47,7 @@ class TabScript { zui_end_sticky(); let _font: g2_font_t = ui.font; - let _fontSize: i32 = ui.font_size; + let _font_size: i32 = ui.font_size; let f: g2_font_t = data_get_font("font_mono.ttf"); zui_set_font(ui, f); ui.font_size = Math.floor(15 * zui_SCALE(ui)); @@ -59,7 +59,7 @@ class TabScript { zui_set_text_area_scroll_past_end(false); zui_set_text_area_coloring(null); zui_set_font(ui, _font); - ui.font_size = _fontSize; + ui.font_size = _font_size; } } diff --git a/base/Sources/TabSwatches.ts b/base/Sources/TabSwatches.ts index 9b97bab3..fedc156c 100644 --- a/base/Sources/TabSwatches.ts +++ b/base/Sources/TabSwatches.ts @@ -71,7 +71,7 @@ class TabSwatches { let slotw: i32 = Math.floor(26 * zui_SCALE(ui)); let num: i32 = Math.floor(ui._w / (slotw + 3)); - let dragPositionSet: bool = false; + let drag_pos_set: bool = false; let uix: f32 = 0.0; let uiy: f32 = 0.0; @@ -99,7 +99,7 @@ class TabSwatches { uiy = ui._y; // Draw the drag position indicator - if (Base.drag_swatch != null && TabSwatches.drag_pos == i) { + if (base_drag_swatch != null && TabSwatches.drag_pos == i) { zui_fill(-1, -2 , 2, 32, ui.t.HIGHLIGHT_COL); } @@ -108,13 +108,13 @@ class TabSwatches { if (state == zui_state_t.STARTED) { Context.set_swatch(Project.raw.swatches[i]); - Base.drag_off_x = -(mouse_x - uix - ui._window_x - 2 * slotw); - Base.drag_off_y = -(mouse_y - uiy - ui._window_y + 1); - Base.drag_swatch = Context.raw.swatch; + base_drag_off_x = -(mouse_x - uix - ui._window_x - 2 * slotw); + base_drag_off_y = -(mouse_y - uiy - ui._window_y + 1); + base_drag_swatch = Context.raw.swatch; } else if (state == zui_state_t.HOVERED) { TabSwatches.drag_pos = (mouse_x > uix + ui._window_x + slotw / 2) ? i + 1 : i; // Switch to the next position if the mouse crosses the swatch rectangle center - dragPositionSet = true; + drag_pos_set = true; } else if (state == zui_state_t.RELEASED) { if (time_time() - Context.raw.select_time < 0.25) { @@ -191,7 +191,7 @@ class TabSwatches { else if (UIMenu.menu_button(ui, tr("Create Color Layer"))) { let color: i32 = Project.raw.swatches[i].base; color = color_set_ab(color, Project.raw.swatches[i].opacity * 255); - Base.create_color_layer(color, Project.raw.swatches[i].occlusion, Project.raw.swatches[i].roughness, Project.raw.swatches[i].metallic); + base_create_color_layer(color, Project.raw.swatches[i].occlusion, Project.raw.swatches[i].roughness, Project.raw.swatches[i].metallic); } ///end }, add); @@ -207,20 +207,20 @@ class TabSwatches { } // Draw the rightmost line next to the last swatch - if (Base.drag_swatch != null && TabSwatches.drag_pos == Project.raw.swatches.length) { + if (base_drag_swatch != null && TabSwatches.drag_pos == Project.raw.swatches.length) { ui._x = uix; // Reset the position because otherwise it would start in the row below ui._y = uiy; zui_fill(28, -2, 2, 32, ui.t.HIGHLIGHT_COL); } // Currently there is no valid dragPosition so reset it - if (!dragPositionSet) { + if (!drag_pos_set) { TabSwatches.drag_pos = -1; } - let inFocus: bool = ui.input_x > ui._window_x && ui.input_x < ui._window_x + ui._window_w && - ui.input_y > ui._window_y && ui.input_y < ui._window_y + ui._window_h; - if (inFocus && ui.is_delete_down && Project.raw.swatches.length > 1) { + let in_focus: bool = ui.input_x > ui._window_x && ui.input_x < ui._window_x + ui._window_w && + ui.input_y > ui._window_y && ui.input_y < ui._window_y + ui._window_h; + if (in_focus && ui.is_delete_down && Project.raw.swatches.length > 1) { ui.is_delete_down = false; TabSwatches.delete_swatch(Context.raw.swatch); } @@ -231,16 +231,16 @@ class TabSwatches { // No valid position available if (TabSwatches.drag_pos == -1) return; - let swatchPosition: i32 = Project.raw.swatches.indexOf(swatch); + let swatch_pos: i32 = Project.raw.swatches.indexOf(swatch); // A new swatch from color picker - if (swatchPosition == -1) { + if (swatch_pos == -1) { Project.raw.swatches.splice(TabSwatches.drag_pos, 0, swatch); } - else if (Math.abs(swatchPosition - TabSwatches.drag_pos) > 0) { // Existing swatch is reordered + else if (Math.abs(swatch_pos - TabSwatches.drag_pos) > 0) { // Existing swatch is reordered array_remove(Project.raw.swatches, swatch); // If the new position is after the old one, decrease by one because the swatch has been deleted - let newPosition: i32 = TabSwatches.drag_pos - swatchPosition > 0 ? TabSwatches.drag_pos -1 : TabSwatches.drag_pos; - Project.raw.swatches.splice(newPosition, 0, swatch); + let new_pos: i32 = TabSwatches.drag_pos - swatch_pos > 0 ? TabSwatches.drag_pos -1 : TabSwatches.drag_pos; + Project.raw.swatches.splice(new_pos, 0, swatch); } } diff --git a/base/Sources/TabTextures.ts b/base/Sources/TabTextures.ts index 67f2519e..584eab0e 100644 --- a/base/Sources/TabTextures.ts +++ b/base/Sources/TabTextures.ts @@ -64,9 +64,9 @@ class TabTextures { let uiy: f32 = ui._y; let sw: i32 = img.height < img.width ? img.height : 0; if (zui_image(img, 0xffffffff, slotw, 0, 0, sw, sw) == zui_state_t.STARTED && ui.input_y > ui._window_y) { - Base.drag_off_x = -(mouse_x - uix - ui._window_x - 3); - Base.drag_off_y = -(mouse_y - uiy - ui._window_y + 1); - Base.drag_asset = asset; + base_drag_off_x = -(mouse_x - uix - ui._window_x - 3); + base_drag_off_y = -(mouse_y - uiy - ui._window_y + 1); + base_drag_asset = asset; Context.raw.texture = asset; if (time_time() - Context.raw.select_time < 0.25) UIBase.show_2d_view(view_2d_type_t.ASSET); @@ -89,11 +89,11 @@ class TabTextures { ui._y = _uiy; } - let isPacked: bool = Project.raw.packed_assets != null && Project.packed_asset_exists(Project.raw.packed_assets, asset.file); + let is_packed: bool = Project.raw.packed_assets != null && Project.packed_asset_exists(Project.raw.packed_assets, asset.file); if (ui.is_hovered) { zui_tooltip_image(img, 256); - zui_tooltip(asset.name + (isPacked ? " " + tr("(packed)") : "")); + zui_tooltip(asset.name + (is_packed ? " " + tr("(packed)") : "")); } if (ui.is_hovered && ui.input_released_r) { @@ -102,30 +102,30 @@ class TabTextures { let count: i32 = 0; ///if (is_paint || is_sculpt) - count = isPacked ? 6 : 8; + count = is_packed ? 6 : 8; ///end ///if is_lab - count = isPacked ? 6 : 6; + count = is_packed ? 6 : 6; ///end UIMenu.draw((ui: zui_t) => { if (UIMenu.menu_button(ui, tr("Export"))) { UIFiles.show("png", true, false, (path: string) => { - Base.notify_on_next_frame(() => { + base_notify_on_next_frame(() => { ///if (is_paint || is_sculpt) - if (Base.pipe_merge == null) Base.make_pipe(); + if (base_pipe_merge == null) base_make_pipe(); ///end ///if is_lab - if (Base.pipe_copy == null) Base.make_pipe(); + if (base_pipe_copy == null) base_make_pipe(); ///end let target: image_t = image_create_render_target(TabTextures.to_pow2(img.width), TabTextures.to_pow2(img.height)); g2_begin(target); - g2_set_pipeline(Base.pipe_copy); + g2_set_pipeline(base_pipe_copy); g2_draw_scaled_image(img, 0, 0, target.width, target.height); g2_set_pipeline(null); g2_end(); - Base.notify_on_next_frame(() => { + base_notify_on_next_frame(() => { let f: string = UIFiles.filename; if (f == "") f = tr("untitled"); if (!f.endsWith(".png")) f += ".png"; @@ -141,14 +141,14 @@ class TabTextures { ///if (is_paint || is_sculpt) if (UIMenu.menu_button(ui, tr("To Mask"))) { - Base.notify_on_next_frame(() => { - Base.create_image_mask(asset); + base_notify_on_next_frame(() => { + base_create_image_mask(asset); }); } ///end if (UIMenu.menu_button(ui, tr("Set as Envmap"))) { - Base.notify_on_next_frame(() => { + base_notify_on_next_frame(() => { ImportEnvmap.run(asset.file, img); }); } @@ -168,10 +168,10 @@ class TabTextures { if (UIMenu.menu_button(ui, tr("Delete"), "delete")) { TabTextures.delete_texture(asset); } - if (!isPacked && UIMenu.menu_button(ui, tr("Open Containing Directory..."))) { + if (!is_packed && UIMenu.menu_button(ui, tr("Open Containing Directory..."))) { File.start(asset.file.substr(0, asset.file.lastIndexOf(Path.sep))); } - if (!isPacked && UIMenu.menu_button(ui, tr("Open in Browser"))) { + if (!is_packed && UIMenu.menu_button(ui, tr("Open in Browser"))) { TabBrowser.show_directory(asset.file.substr(0, asset.file.lastIndexOf(Path.sep))); } }, count); @@ -197,9 +197,9 @@ class TabTextures { if (ui.is_hovered) zui_tooltip(tr("Drag and drop files here")); } - let inFocus: bool = ui.input_x > ui._window_x && ui.input_x < ui._window_x + ui._window_w && - ui.input_y > ui._window_y && ui.input_y < ui._window_y + ui._window_h; - if (inFocus && ui.is_delete_down && Project.assets.length > 0 && Project.assets.indexOf(Context.raw.texture) >= 0) { + let in_focus: bool = ui.input_x > ui._window_x && ui.input_x < ui._window_x + ui._window_w && + ui.input_y > ui._window_y && ui.input_y < ui._window_y + ui._window_h; + if (in_focus && ui.is_delete_down && Project.assets.length > 0 && Project.assets.indexOf(Context.raw.texture) >= 0) { ui.is_delete_down = false; TabTextures.delete_texture(Context.raw.texture); } @@ -258,7 +258,7 @@ class TabTextures { UIBase.hwnds[tab_area_t.SIDEBAR1].redraws = 2; ///end } - Base.notify_on_next_frame(_next); + base_notify_on_next_frame(_next); for (let m of Project.materials) TabTextures.update_texture_pointers(m.canvas.nodes, i); ///if (is_paint || is_sculpt) diff --git a/base/Sources/Translator.ts b/base/Sources/Translator.ts index f45ef2e9..2b76a8e7 100644 --- a/base/Sources/Translator.ts +++ b/base/Sources/Translator.ts @@ -40,8 +40,8 @@ class Translator { } // (Re)loads translations for the specified locale - static load_translations = (newLocale: string) => { - if (newLocale == "system") { + static load_translations = (new_locale: string) => { + if (new_locale == "system") { Config.raw.locale = krom_language(); } @@ -63,9 +63,9 @@ class Translator { if (Config.raw.locale != "en") { // Load the translation file - let translationJson: string = sys_buffer_to_string(krom_load_blob(`data/locale/${Config.raw.locale}.json`)); + let translation_json: string = sys_buffer_to_string(krom_load_blob(`data/locale/${Config.raw.locale}.json`)); - let data: any = json_parse(translationJson); + let data: any = json_parse(translation_json); for (let field in data) { let atranslations: any = Translator.translations as any; atranslations[field] = data[field]; @@ -91,21 +91,21 @@ class Translator { } if (cjk) { - let cjkFontPath: string = (Path.is_protected() ? krom_save_path() : "") + "font_cjk.ttc"; - let cjkFontDiskPath: string = (Path.is_protected() ? krom_save_path() : Path.data() + Path.sep) + "font_cjk.ttc"; - if (!File.exists(cjkFontDiskPath)) { - File.download("https://github.com/armory3d/armorbase/raw/main/Assets/common/extra/font_cjk.ttc", cjkFontDiskPath, () => { - if (!File.exists(cjkFontDiskPath)) { + let cjk_font_path: string = (Path.is_protected() ? krom_save_path() : "") + "font_cjk.ttc"; + let cjk_font_disk_path: string = (Path.is_protected() ? krom_save_path() : Path.data() + Path.sep) + "font_cjk.ttc"; + if (!File.exists(cjk_font_disk_path)) { + File.download("https://github.com/armory3d/armorbase/raw/main/Assets/common/extra/font_cjk.ttc", cjk_font_disk_path, () => { + if (!File.exists(cjk_font_disk_path)) { // Fall back to English Config.raw.locale = "en"; Translator.extended_glyphs(); Translator.translations.clear(); Translator.init_font(false, "font.ttf", 1.0); } - else Translator.init_font(true, cjkFontPath, 1.4); + else Translator.init_font(true, cjk_font_path, 1.4); }, 20332392); } - else Translator.init_font(true, cjkFontPath, 1.4); + else Translator.init_font(true, cjk_font_path, 1.4); } else Translator.init_font(false, "font.ttf", 1.0); } @@ -116,15 +116,15 @@ class Translator { app_notify_on_init(() => { let f: g2_font_t = data_get_font(fontPath); if (cjk) { - let acjkFontIndices: any = Translator.cjk_font_indices as any; - let fontIndex: i32 = Translator.cjk_font_indices.has(Config.raw.locale) ? acjkFontIndices[Config.raw.locale] : 0; - g2_font_set_font_index(f, fontIndex); + let acjk_font_indices: any = Translator.cjk_font_indices as any; + let font_index: i32 = Translator.cjk_font_indices.has(Config.raw.locale) ? acjk_font_indices[Config.raw.locale] : 0; + g2_font_set_font_index(f, font_index); } - Base.font = f; + base_font = f; // Scale up the font size and elements width a bit - Base.theme.FONT_SIZE = Math.floor(Base.default_font_size * fontScale); - Base.theme.ELEMENT_W = Math.floor(Base.default_element_w * (Config.raw.locale != "en" ? 1.4 : 1.0)); - let uis: zui_t[] = Base.get_uis(); + base_theme.FONT_SIZE = Math.floor(base_default_font_size * fontScale); + base_theme.ELEMENT_W = Math.floor(base_default_element_w * (Config.raw.locale != "en" ? 1.4 : 1.0)); + let uis: zui_t[] = base_get_uis(); for (let ui of uis) { zui_set_font(ui, f); zui_set_scale(ui, zui_SCALE(ui)); @@ -144,9 +144,9 @@ class Translator { // Returns a list of supported locales (plus English and the automatically detected system locale) static get_supported_locales = (): string[] => { let locales: string[] = ["system", "en"]; - for (let localeFilename of File.read_directory(Path.data() + Path.sep + "locale")) { + for (let locale_filename of File.read_directory(Path.data() + Path.sep + "locale")) { // Trim the `.json` file extension from file names - locales.push(localeFilename.substr(0, -5)); + locales.push(locale_filename.substr(0, -5)); } return locales; } diff --git a/base/Sources/UIBase.ts b/base/Sources/UIBase.ts index e1ba0628..3d83606e 100644 --- a/base/Sources/UIBase.ts +++ b/base/Sources/UIBase.ts @@ -135,7 +135,7 @@ class UIBase { if (Project.fonts == null) { Project.fonts = []; - Project.fonts.push(SlotFont.create("default.ttf", Base.font)); + Project.fonts.push(SlotFont.create("default.ttf", base_font)); Context.raw.font = Project.fonts[0]; } @@ -201,7 +201,7 @@ class UIBase { History.reset(); let scale: f32 = Config.raw.window_scale; - UIBase.ui = zui_create({ theme: Base.theme, font: Base.font, scale_factor: scale, color_wheel: Base.color_wheel, black_white_gradient: Base.color_wheel_gradient }); + UIBase.ui = zui_create({ theme: base_theme, font: base_font, scale_factor: scale, color_wheel: base_color_wheel, black_white_gradient: base_color_wheel_gradient }); zui_set_on_border_hover(UIBase.on_border_hover); zui_set_on_text_hover(UIBase.on_text_hover); zui_set_on_deselect_text(UIBase.on_deselect_text); @@ -235,7 +235,7 @@ class UIBase { Project.paint_objects = [Context.raw.paint_object]; if (Project.filepath == "") { - app_notify_on_init(Base.init_layers); + app_notify_on_init(base_init_layers); } Context.raw.project_objects = []; @@ -250,7 +250,7 @@ class UIBase { for (let p of Plugin.plugins.values()) if (p.update != null) p.update(); - if (!Base.ui_enabled) return; + if (!base_ui_enabled) return; if (!UINodes.ui.is_typing && !UIBase.ui.is_typing) { if (Operator.shortcut(Config.keymap.toggle_node_editor)) { @@ -313,19 +313,19 @@ class UIBase { ///if krom_linux if (Operator.shortcut("alt+enter", ShortcutType.ShortcutStarted)) { - Base.toggle_fullscreen(); + base_toggle_fullscreen(); } ///end ///if (is_paint || is_sculpt) let decal: bool = Context.raw.tool == workspace_tool_t.DECAL || Context.raw.tool == workspace_tool_t.TEXT; - let decalMask: bool = decal && Operator.shortcut(Config.keymap.decal_mask, ShortcutType.ShortcutDown); + let decal_mask: bool = decal && Operator.shortcut(Config.keymap.decal_mask, ShortcutType.ShortcutDown); if ((Context.raw.brush_can_lock || Context.raw.brush_locked) && mouse_moved) { if (Operator.shortcut(Config.keymap.brush_radius, ShortcutType.ShortcutDown) || Operator.shortcut(Config.keymap.brush_opacity, ShortcutType.ShortcutDown) || Operator.shortcut(Config.keymap.brush_angle, ShortcutType.ShortcutDown) || - (decalMask && Operator.shortcut(Config.keymap.decal_mask + "+" + Config.keymap.brush_radius, ShortcutType.ShortcutDown))) { + (decal_mask && Operator.shortcut(Config.keymap.decal_mask + "+" + Config.keymap.brush_radius, ShortcutType.ShortcutDown))) { if (Context.raw.brush_locked) { if (Operator.shortcut(Config.keymap.brush_opacity, ShortcutType.ShortcutDown)) { Context.raw.brush_opacity += mouse_movement_x / 500; @@ -340,7 +340,7 @@ class UIBase { Context.raw.brush_angle_handle.value = Context.raw.brush_angle; MakeMaterial.parse_paint_material(); } - else if (decalMask && Operator.shortcut(Config.keymap.decal_mask + "+" + Config.keymap.brush_radius, ShortcutType.ShortcutDown)) { + else if (decal_mask && Operator.shortcut(Config.keymap.decal_mask + "+" + Config.keymap.brush_radius, ShortcutType.ShortcutDown)) { Context.raw.brush_decal_mask_radius += mouse_movement_x / 150; Context.raw.brush_decal_mask_radius = Math.max(0.01, Math.min(4.0, Context.raw.brush_decal_mask_radius)); Context.raw.brush_decal_mask_radius = Math.round(Context.raw.brush_decal_mask_radius * 100) / 100; @@ -380,10 +380,10 @@ class UIBase { } ///end - let isTyping: bool = UIBase.ui.is_typing || UIView2D.ui.is_typing || UINodes.ui.is_typing; + let is_typing: bool = UIBase.ui.is_typing || UIView2D.ui.is_typing || UINodes.ui.is_typing; ///if (is_paint || is_sculpt) - if (!isTyping) { + if (!is_typing) { if (Operator.shortcut(Config.keymap.select_material, ShortcutType.ShortcutDown)) { UIBase.hwnds[tab_area_t.SIDEBAR1].redraws = 2; for (let i: i32 = 1; i < 10; ++i) if (keyboard_started(i + "")) Context.select_material(i - 1); @@ -396,7 +396,7 @@ class UIBase { ///end // Viewport shortcuts - if (Context.in_paint_area() && !isTyping) { + if (Context.in_paint_area() && !is_typing) { ///if is_paint if (!mouse_down("right")) { // Fly mode off @@ -429,7 +429,7 @@ class UIBase { if (Operator.shortcut(Config.keymap.brush_radius) || Operator.shortcut(Config.keymap.brush_opacity) || Operator.shortcut(Config.keymap.brush_angle) || - (decalMask && Operator.shortcut(Config.keymap.decal_mask + "+" + Config.keymap.brush_radius))) { + (decal_mask && Operator.shortcut(Config.keymap.decal_mask + "+" + Config.keymap.brush_radius))) { Context.raw.brush_can_lock = true; if (!pen_connected) mouse_lock(); Context.raw.lock_started_x = mouse_x; @@ -447,7 +447,7 @@ class UIBase { Context.raw.brush_radius_handle.value = Context.raw.brush_radius; UIHeader.header_handle.redraws = 2; } - else if (decalMask) { + else if (decal_mask) { if (Operator.shortcut(Config.keymap.decal_mask + "+" + Config.keymap.brush_radius_decrease, ShortcutType.ShortcutRepeat)) { Context.raw.brush_decal_mask_radius -= UIBase.get_radius_increment(); Context.raw.brush_decal_mask_radius = Math.max(Math.round(Context.raw.brush_decal_mask_radius * 100) / 100, 0.01); @@ -463,7 +463,7 @@ class UIBase { } } - if (decalMask && (Operator.shortcut(Config.keymap.decal_mask, ShortcutType.ShortcutStarted) || Operator.shortcut(Config.keymap.decal_mask, ShortcutType.ShortcutReleased))) { + if (decal_mask && (Operator.shortcut(Config.keymap.decal_mask, ShortcutType.ShortcutStarted) || Operator.shortcut(Config.keymap.decal_mask, ShortcutType.ShortcutReleased))) { UIHeader.header_handle.redraws = 2; } ///end @@ -539,8 +539,8 @@ class UIBase { ///end UIMenu.draw((ui: zui_t) => { - let modeHandle: zui_handle_t = zui_handle("uibase_0"); - modeHandle.position = Context.raw.viewport_mode; + let mode_handle: zui_handle_t = zui_handle("uibase_0"); + mode_handle.position = Context.raw.viewport_mode; zui_text(tr("Viewport Mode"), zui_align_t.RIGHT, ui.t.HIGHLIGHT_COL); let modes: string[] = [ tr("Lit"), @@ -572,17 +572,17 @@ class UIBase { ///end for (let i: i32 = 0; i < modes.length; ++i) { - zui_radio(modeHandle, i, modes[i], shortcuts[i]); + zui_radio(mode_handle, i, modes[i], shortcuts[i]); } let index: i32 = shortcuts.indexOf(keyboard_key_code(ui.key)); if (ui.is_key_pressed && index != -1) { - modeHandle.position = index; + mode_handle.position = index; ui.changed = true; - Context.set_viewport_mode(modeHandle.position); + Context.set_viewport_mode(mode_handle.position); } - else if (modeHandle.changed) { - Context.set_viewport_mode(modeHandle.position); + else if (mode_handle.changed) { + Context.set_viewport_mode(mode_handle.position); ui.changed = true; } }, count); @@ -603,7 +603,7 @@ class UIBase { !Operator.shortcut(Config.keymap.brush_radius, ShortcutType.ShortcutDown) && !Operator.shortcut(Config.keymap.brush_opacity, ShortcutType.ShortcutDown) && !Operator.shortcut(Config.keymap.brush_angle, ShortcutType.ShortcutDown) && - !(decalMask && Operator.shortcut(Config.keymap.decal_mask + "+" + Config.keymap.brush_radius, ShortcutType.ShortcutDown)); + !(decal_mask && Operator.shortcut(Config.keymap.decal_mask + "+" + Config.keymap.brush_radius, ShortcutType.ShortcutDown)); ///end ///if is_lab let b: bool = (Context.raw.brush_can_lock || Context.raw.brush_locked) && @@ -689,7 +689,7 @@ class UIBase { if (!mouse_down()) { UIBase.border_handle_ptr = 0; - Base.is_resizing = false; + base_is_resizing = false; } ///if arm_physics @@ -738,12 +738,12 @@ class UIBase { let pairs: pair_t[] = PhysicsWorld.get_contact_pairs(world, Context.raw.paint_body); if (pairs != null) { for (let p of pairs) { - Context.raw.last_particle_hit_x = Context.raw.particle_hit_x != 0 ? Context.raw.particle_hit_x : p.posA.x; - Context.raw.last_particle_hit_y = Context.raw.particle_hit_y != 0 ? Context.raw.particle_hit_y : p.posA.y; - Context.raw.last_particle_hit_z = Context.raw.particle_hit_z != 0 ? Context.raw.particle_hit_z : p.posA.z; - Context.raw.particle_hit_x = p.posA.x; - Context.raw.particle_hit_y = p.posA.y; - Context.raw.particle_hit_z = p.posA.z; + Context.raw.last_particle_hit_x = Context.raw.particle_hit_x != 0 ? Context.raw.particle_hit_x : p.pos_a.x; + Context.raw.last_particle_hit_y = Context.raw.particle_hit_y != 0 ? Context.raw.particle_hit_y : p.pos_a.y; + Context.raw.last_particle_hit_z = Context.raw.particle_hit_z != 0 ? Context.raw.particle_hit_z : p.pos_a.z; + Context.raw.particle_hit_x = p.pos_a.x; + Context.raw.particle_hit_y = p.pos_a.y; + Context.raw.particle_hit_z = p.pos_a.z; Context.raw.pdirty = 1; break; // 1 pair for now } @@ -753,9 +753,9 @@ class UIBase { } static view_top = () => { - let isTyping: bool = UIBase.ui.is_typing || UIView2D.ui.is_typing || UINodes.ui.is_typing; + let is_typing: bool = UIBase.ui.is_typing || UIView2D.ui.is_typing || UINodes.ui.is_typing; - if (Context.in_paint_area() && !isTyping) { + if (Context.in_paint_area() && !is_typing) { if (mouse_view_x() < app_w()) { Viewport.set_view(0, 0, 1, 0, 0, 0); } @@ -763,19 +763,19 @@ class UIBase { } static operator_search = () => { - let searchHandle: zui_handle_t = zui_handle("uibase_1"); + let search_handle: zui_handle_t = zui_handle("uibase_1"); let first: bool = true; UIMenu.draw((ui: zui_t) => { zui_fill(0, 0, ui._w / zui_SCALE(ui), ui.t.ELEMENT_H * 8, ui.t.SEPARATOR_COL); - let search: string = zui_text_input(searchHandle, "", zui_align_t.LEFT, true, true); + let search: string = zui_text_input(search_handle, "", zui_align_t.LEFT, true, true); ui.changed = false; if (first) { first = false; - searchHandle.text = ""; - zui_start_text_edit(searchHandle); // Focus search bar + search_handle.text = ""; + zui_start_text_edit(search_handle); // Focus search bar } - if (searchHandle.changed) UIBase.operator_search_offset = 0; + if (search_handle.changed) UIBase.operator_search_offset = 0; if (ui.is_key_pressed) { // Move selection if (ui.key == key_code_t.DOWN && UIBase.operator_search_offset < 6) UIBase.operator_search_offset++; @@ -801,7 +801,7 @@ class UIBase { if (enter && count == 0) { // Hide popup on enter when command is not found ui.changed = true; - searchHandle.text = ""; + search_handle.text = ""; } ui.t.BUTTON_COL = BUTTON_COL; }, 8, -1, -1); @@ -809,7 +809,7 @@ class UIBase { static toggle_distract_free = () => { UIBase.show = !UIBase.show; - Base.resize(); + base_resize(); } static get_radius_increment = (): f32 => { @@ -822,10 +822,10 @@ class UIBase { ///if (is_paint || is_sculpt) static get_brush_stencil_rect = (): rect_t => { - let w: i32 = Math.floor(Context.raw.brush_stencil_image.width * (Base.h() / Context.raw.brush_stencil_image.height) * Context.raw.brush_stencil_scale); - let h: i32 = Math.floor(Base.h() * Context.raw.brush_stencil_scale); - let x: i32 = Math.floor(Base.x() + Context.raw.brush_stencil_x * Base.w()); - let y: i32 = Math.floor(Base.y() + Context.raw.brush_stencil_y * Base.h()); + let w: i32 = Math.floor(Context.raw.brush_stencil_image.width * (base_h() / Context.raw.brush_stencil_image.height) * Context.raw.brush_stencil_scale); + let h: i32 = Math.floor(base_h() * Context.raw.brush_stencil_scale); + let x: i32 = Math.floor(base_x() + Context.raw.brush_stencil_x * base_w()); + let y: i32 = Math.floor(base_y() + Context.raw.brush_stencil_y * base_h()); return { w: w, h: h, x: x, y: y }; } ///end @@ -840,7 +840,7 @@ class UIBase { UIBase.sidebar_mini_w = Math.floor(UIBase.default_sidebar_mini_w * zui_SCALE(UIBase.ui)); ///end - if (!Base.ui_enabled) return; + if (!base_ui_enabled) return; ///if (is_paint || is_sculpt) // Same mapping for paint and rotate (predefined in touch keymap) @@ -848,17 +848,17 @@ class UIBase { if (mouse_started() && Config.keymap.action_paint == Config.keymap.action_rotate) { UIBase.action_paint_remap = Config.keymap.action_paint; UtilRender.pick_pos_nor_tex(); - let isMesh: bool = Math.abs(Context.raw.posx_picked) < 50 && Math.abs(Context.raw.posy_picked) < 50 && Math.abs(Context.raw.posz_picked) < 50; + let is_mesh: bool = Math.abs(Context.raw.posx_picked) < 50 && Math.abs(Context.raw.posy_picked) < 50 && Math.abs(Context.raw.posz_picked) < 50; ///if krom_android // Allow rotating with both pen and touch, because hovering a pen prevents touch input on android - let penOnly: bool = false; + let pen_only: bool = false; ///else - let penOnly: bool = Context.raw.pen_painting_only; + let pen_only: bool = Context.raw.pen_painting_only; ///end - let isPen: bool = penOnly && pen_down(); + let is_pen: bool = pen_only && pen_down(); // Mesh picked - disable rotate // Pen painting only - rotate with touch, paint with pen - if ((isMesh && !penOnly) || isPen) { + if ((is_mesh && !pen_only) || is_pen) { Config.keymap.action_rotate = ""; Config.keymap.action_paint = UIBase.action_paint_remap; } @@ -901,13 +901,13 @@ class UIBase { Context.raw.brush_stencil_scale += mouse_movement_x / 400 * mult; } else if (Context.raw.brush_stencil_rotating) { - let gizmoX: f32 = r.x + r.w / 2; - let gizmoY: f32 = r.y + r.h / 2; - Context.raw.brush_stencil_angle = -Math.atan2(mouse_y - gizmoY, mouse_x - gizmoX) - Math.PI / 2; + let gizmo_x: f32 = r.x + r.w / 2; + let gizmo_y: f32 = r.y + r.h / 2; + Context.raw.brush_stencil_angle = -Math.atan2(mouse_y - gizmo_y, mouse_x - gizmo_x) - Math.PI / 2; } else { - Context.raw.brush_stencil_x += mouse_movement_x / Base.w(); - Context.raw.brush_stencil_y += mouse_movement_y / Base.h(); + Context.raw.brush_stencil_x += mouse_movement_x / base_w(); + Context.raw.brush_stencil_y += mouse_movement_y / base_h(); } } else Context.raw.brush_stencil_scaling = false; @@ -915,30 +915,30 @@ class UIBase { Context.raw.brush_stencil_scale -= mouse_wheel_delta / 10; } // Center after scale - let ratio: f32 = Base.h() / Context.raw.brush_stencil_image.height; - let oldW: f32 = _scale * Context.raw.brush_stencil_image.width * ratio; - let newW: f32 = Context.raw.brush_stencil_scale * Context.raw.brush_stencil_image.width * ratio; - let oldH: f32 = _scale * Base.h(); - let newH: f32 = Context.raw.brush_stencil_scale * Base.h(); - Context.raw.brush_stencil_x += (oldW - newW) / Base.w() / 2; - Context.raw.brush_stencil_y += (oldH - newH) / Base.h() / 2; + let ratio: f32 = base_h() / Context.raw.brush_stencil_image.height; + let old_w: f32 = _scale * Context.raw.brush_stencil_image.width * ratio; + let new_w: f32 = Context.raw.brush_stencil_scale * Context.raw.brush_stencil_image.width * ratio; + let old_h: f32 = _scale * base_h(); + let new_h: f32 = Context.raw.brush_stencil_scale * base_h(); + Context.raw.brush_stencil_x += (old_w - new_w) / base_w() / 2; + Context.raw.brush_stencil_y += (old_h - new_h) / base_h() / 2; } ///end - let setCloneSource: bool = Context.raw.tool == workspace_tool_t.CLONE && Operator.shortcut(Config.keymap.set_clone_source + "+" + Config.keymap.action_paint, ShortcutType.ShortcutDown); + let set_clone_source: bool = Context.raw.tool == workspace_tool_t.CLONE && Operator.shortcut(Config.keymap.set_clone_source + "+" + Config.keymap.action_paint, ShortcutType.ShortcutDown); ///if (is_paint || is_sculpt) let decal: bool = Context.raw.tool == workspace_tool_t.DECAL || Context.raw.tool == workspace_tool_t.TEXT; - let decalMask: bool = decal && Operator.shortcut(Config.keymap.decal_mask + "+" + Config.keymap.action_paint, ShortcutType.ShortcutDown); + let decal_mask: bool = decal && Operator.shortcut(Config.keymap.decal_mask + "+" + Config.keymap.action_paint, ShortcutType.ShortcutDown); let down: bool = Operator.shortcut(Config.keymap.action_paint, ShortcutType.ShortcutDown) || - decalMask || - setCloneSource || + decal_mask || + set_clone_source || Operator.shortcut(Config.keymap.brush_ruler + "+" + Config.keymap.action_paint, ShortcutType.ShortcutDown) || (pen_down() && !keyboard_down("alt")); ///end ///if is_lab let down: bool = Operator.shortcut(Config.keymap.action_paint, ShortcutType.ShortcutDown) || - setCloneSource || + set_clone_source || Operator.shortcut(Config.keymap.brush_ruler + "+" + Config.keymap.action_paint, ShortcutType.ShortcutDown) || (pen_down() && !keyboard_down("alt")); ///end @@ -987,15 +987,15 @@ class UIBase { my < app_h() && my > app_y()) { - if (setCloneSource) { + if (set_clone_source) { Context.raw.clone_start_x = mx; Context.raw.clone_start_y = my; } else { if (Context.raw.brush_time == 0 && - !Base.is_dragging && - !Base.is_resizing && - !Base.is_combo_selected()) { // Paint started + !base_is_dragging && + !base_is_resizing && + !base_is_combo_selected()) { // Paint started // Draw line if (Operator.shortcut(Config.keymap.brush_ruler + "+" + Config.keymap.action_paint, ShortcutType.ShortcutDown)) { @@ -1058,8 +1058,8 @@ class UIBase { ///if is_paint // New color id picked, update fill layer if (Context.raw.tool == workspace_tool_t.COLORID && Context.raw.layer.fill_layer != null) { - Base.notify_on_next_frame(() => { - Base.update_fill_layer(); + base_notify_on_next_frame(() => { + base_update_fill_layer(); MakeMaterial.parse_paint_material(false); }); } @@ -1071,7 +1071,7 @@ class UIBase { Context.raw.layers_preview_dirty = false; Context.raw.layer_preview_dirty = false; Context.raw.mask_preview_last = null; - if (Base.pipe_merge == null) Base.make_pipe(); + if (base_pipe_merge == null) base_make_pipe(); // Update all layer previews for (let l of Project.layers) { if (SlotLayer.is_group(l)) continue; @@ -1079,8 +1079,8 @@ class UIBase { let source: image_t = l.texpaint; g2_begin(target); g2_clear(0x00000000); - // g2_set_pipeline(l.isMask() ? Base.pipeCopy8 : Base.pipeCopy); - g2_set_pipeline(Base.pipe_copy); // texpaint_preview is always RGBA32 for now + // g2_set_pipeline(l.isMask() ? base_pipe_copy8 : base_pipe_copy); + g2_set_pipeline(base_pipe_copy); // texpaint_preview is always RGBA32 for now g2_draw_scaled_image(source, 0, 0, target.width, target.height); g2_set_pipeline(null); g2_end(); @@ -1090,15 +1090,15 @@ class UIBase { if (Context.raw.layer_preview_dirty && !SlotLayer.is_group(Context.raw.layer)) { Context.raw.layer_preview_dirty = false; Context.raw.mask_preview_last = null; - if (Base.pipe_merge == null) Base.make_pipe(); + if (base_pipe_merge == null) base_make_pipe(); // Update layer preview let l: SlotLayerRaw = Context.raw.layer; let target: image_t = l.texpaint_preview; let source: image_t = l.texpaint; g2_begin(target); g2_clear(0x00000000); - // g2_set_pipeline(Context.raw.layer.isMask() ? Base.pipeCopy8 : Base.pipeCopy); - g2_set_pipeline(Base.pipe_copy); // texpaint_preview is always RGBA32 for now + // g2_set_pipeline(Context.raw.layer.isMask() ? base_pipe_copy8 : base_pipe_copy); + g2_set_pipeline(base_pipe_copy); // texpaint_preview is always RGBA32 for now g2_draw_scaled_image(source, 0, 0, target.width, target.height); g2_set_pipeline(null); g2_end(); @@ -1106,20 +1106,20 @@ class UIBase { } ///end - let undoPressed: bool = Operator.shortcut(Config.keymap.edit_undo); - let redoPressed: bool = Operator.shortcut(Config.keymap.edit_redo) || + let undo_pressed: bool = Operator.shortcut(Config.keymap.edit_undo); + let redo_pressed: bool = Operator.shortcut(Config.keymap.edit_redo) || (keyboard_down("control") && keyboard_started("y")); // Two-finger tap to undo, three-finger tap to redo if (Context.in_viewport() && Config.raw.touch_ui) { if (mouse_started("middle")) { UIBase.redo_tap_time = time_time(); } else if (mouse_started("right")) { UIBase.undo_tap_time = time_time(); } - else if (mouse_released("middle") && time_time() - UIBase.redo_tap_time < 0.1) { UIBase.redo_tap_time = UIBase.undo_tap_time = 0; redoPressed = true; } - else if (mouse_released("right") && time_time() - UIBase.undo_tap_time < 0.1) { UIBase.redo_tap_time = UIBase.undo_tap_time = 0; undoPressed = true; } + else if (mouse_released("middle") && time_time() - UIBase.redo_tap_time < 0.1) { UIBase.redo_tap_time = UIBase.undo_tap_time = 0; redo_pressed = true; } + else if (mouse_released("right") && time_time() - UIBase.undo_tap_time < 0.1) { UIBase.redo_tap_time = UIBase.undo_tap_time = 0; undo_pressed = true; } } - if (undoPressed) History.undo(); - else if (redoPressed) History.redo(); + if (undo_pressed) History.undo(); + else if (redo_pressed) History.redo(); ///if (is_paint || is_sculpt) Gizmo.update(); @@ -1142,7 +1142,7 @@ class UIBase { if (!UIBase.show || sys_width() == 0 || sys_height() == 0) return; - UIBase.ui.input_enabled = Base.ui_enabled; + UIBase.ui.input_enabled = base_ui_enabled; // Remember last tab positions for (let i: i32 = 0; i < UIBase.htabs.length; ++i) { @@ -1179,7 +1179,7 @@ class UIBase { static draw_sidebar = () => { // Tabs let mini: bool = Config.raw.layout[layout_size_t.SIDEBAR_W] <= UIBase.sidebar_mini_w; - let expandButtonOffset: i32 = Config.raw.touch_ui ? Math.floor(zui_ELEMENT_H(UIBase.ui) + zui_ELEMENT_OFFSET(UIBase.ui)) : 0; + let expand_button_offset: i32 = Config.raw.touch_ui ? Math.floor(zui_ELEMENT_H(UIBase.ui) + zui_ELEMENT_OFFSET(UIBase.ui)) : 0; UIBase.tabx = sys_width() - Config.raw.layout[layout_size_t.SIDEBAR_W]; let _SCROLL_W: i32 = UIBase.ui.t.SCROLL_W; @@ -1188,7 +1188,7 @@ class UIBase { if (zui_window(UIBase.hwnds[tab_area_t.SIDEBAR0], UIBase.tabx, 0, Config.raw.layout[layout_size_t.SIDEBAR_W], Config.raw.layout[layout_size_t.SIDEBAR_H0])) { for (let i: i32 = 0; i < (mini ? 1 : UIBase.hwnd_tabs[tab_area_t.SIDEBAR0].length); ++i) UIBase.hwnd_tabs[tab_area_t.SIDEBAR0][i](UIBase.htabs[tab_area_t.SIDEBAR0]); } - if (zui_window(UIBase.hwnds[tab_area_t.SIDEBAR1], UIBase.tabx, Config.raw.layout[layout_size_t.SIDEBAR_H0], Config.raw.layout[layout_size_t.SIDEBAR_W], Config.raw.layout[layout_size_t.SIDEBAR_H1] - expandButtonOffset)) { + if (zui_window(UIBase.hwnds[tab_area_t.SIDEBAR1], UIBase.tabx, Config.raw.layout[layout_size_t.SIDEBAR_H0], Config.raw.layout[layout_size_t.SIDEBAR_W], Config.raw.layout[layout_size_t.SIDEBAR_H1] - expand_button_offset)) { for (let i: i32 = 0; i < (mini ? 1 : UIBase.hwnd_tabs[tab_area_t.SIDEBAR1].length); ++i) UIBase.hwnd_tabs[tab_area_t.SIDEBAR1][i](UIBase.htabs[tab_area_t.SIDEBAR1]); } @@ -1242,7 +1242,7 @@ class UIBase { } static render_cursor = () => { - if (!Base.ui_enabled) return; + if (!base_ui_enabled) return; ///if is_paint if (Context.raw.tool == workspace_tool_t.MATERIAL || Context.raw.tool == workspace_tool_t.BAKE) return; @@ -1251,8 +1251,8 @@ class UIBase { g2_set_color(0xffffffff); Context.raw.view_index = Context.raw.view_index_last; - let mx: i32 = Base.x() + Context.raw.paint_vec.x * Base.w(); - let my: i32 = Base.y() + Context.raw.paint_vec.y * Base.h(); + let mx: i32 = base_x() + Context.raw.paint_vec.x * base_w(); + let my: i32 = base_y() + Context.raw.paint_vec.y * base_h(); Context.raw.view_index = -1; // Radius being scaled @@ -1315,31 +1315,31 @@ class UIBase { g2_draw_sub_image(img, mx + 10, my + 10, rect.x, rect.y, rect.w, rect.h); } - let cursorImg: image_t = Res.get("cursor.k"); - let psize: i32 = Math.floor(cursorImg.width * (Context.raw.brush_radius * Context.raw.brush_nodes_radius) * zui_SCALE(UIBase.ui)); + let cursor_img: image_t = Res.get("cursor.k"); + let psize: i32 = Math.floor(cursor_img.width * (Context.raw.brush_radius * Context.raw.brush_nodes_radius) * zui_SCALE(UIBase.ui)); // Clone source cursor if (Context.raw.tool == workspace_tool_t.CLONE && !keyboard_down("alt") && (mouse_down() || pen_down())) { g2_set_color(0x66ffffff); - g2_draw_scaled_image(cursorImg, mx + Context.raw.clone_delta_x * app_w() - psize / 2, my + Context.raw.clone_delta_y * app_h() - psize / 2, psize, psize); + g2_draw_scaled_image(cursor_img, mx + Context.raw.clone_delta_x * app_w() - psize / 2, my + Context.raw.clone_delta_y * app_h() - psize / 2, psize, psize); g2_set_color(0xffffffff); } let decal: bool = Context.raw.tool == workspace_tool_t.DECAL || Context.raw.tool == workspace_tool_t.TEXT; if (!Config.raw.brush_3d || Context.in_2d_view() || decal) { - let decalMask: bool = decal && Operator.shortcut(Config.keymap.decal_mask, ShortcutType.ShortcutDown); + let decal_mask: bool = decal && Operator.shortcut(Config.keymap.decal_mask, ShortcutType.ShortcutDown); if (decal && !Context.in_nodes()) { - let decalAlpha: f32 = 0.5; - if (!decalMask) { + let decal_alpha: f32 = 0.5; + if (!decal_mask) { Context.raw.decal_x = Context.raw.paint_vec.x; Context.raw.decal_y = Context.raw.paint_vec.y; - decalAlpha = Context.raw.brush_opacity; + decal_alpha = Context.raw.brush_opacity; // Radius being scaled if (Context.raw.brush_locked) { - Context.raw.decal_x += (Context.raw.lock_started_x - sys_width() / 2) / Base.w(); - Context.raw.decal_y += (Context.raw.lock_started_y - sys_height() / 2) / Base.h(); + Context.raw.decal_x += (Context.raw.lock_started_x - sys_width() / 2) / base_w(); + Context.raw.decal_y += (Context.raw.lock_started_y - sys_height() / 2) / base_h(); } } @@ -1348,19 +1348,19 @@ class UIBase { let psizey: i32 = Math.floor(256 * zui_SCALE(UIBase.ui) * (Context.raw.brush_radius * Context.raw.brush_nodes_radius)); Context.raw.view_index = Context.raw.view_index_last; - let decalX: f32 = Base.x() + Context.raw.decal_x * Base.w() - psizex / 2; - let decalY: f32 = Base.y() + Context.raw.decal_y * Base.h() - psizey / 2; + let decalx: f32 = base_x() + Context.raw.decal_x * base_w() - psizex / 2; + let decaly: f32 = base_y() + Context.raw.decal_y * base_h() - psizey / 2; Context.raw.view_index = -1; - g2_set_color(color_from_floats(1, 1, 1, decalAlpha)); + g2_set_color(color_from_floats(1, 1, 1, decal_alpha)); let angle: f32 = (Context.raw.brush_angle + Context.raw.brush_nodes_angle) * (Math.PI / 180); - let cx: f32 = decalX + psizex / 2; - let cy: f32 = decalY + psizey / 2; + let cx: f32 = decalx + psizex / 2; + let cy: f32 = decaly + psizey / 2; g2_set_transformation(mat3_multmat(mat3_multmat(mat3_translation(cx, cy), mat3_rotation(angle)), mat3_translation(-cx, -cy))); ///if (krom_direct3d11 || krom_direct3d12 || krom_metal || krom_vulkan) - g2_draw_scaled_image(Context.raw.decal_image, decalX, decalY, psizex, psizey); + g2_draw_scaled_image(Context.raw.decal_image, decalx, decaly, psizex, psizey); ///else - g2_draw_scaled_image(Context.raw.decal_image, decalX, decalY + psizey, psizex, -psizey); + g2_draw_scaled_image(Context.raw.decal_image, decalx, decaly + psizey, psizex, -psizey); ///end g2_set_transformation(null); g2_set_color(0xffffffff); @@ -1372,15 +1372,15 @@ class UIBase { Context.raw.tool == workspace_tool_t.BLUR || Context.raw.tool == workspace_tool_t.SMUDGE || Context.raw.tool == workspace_tool_t.PARTICLE || - (decalMask && !Config.raw.brush_3d) || - (decalMask && Context.in_2d_view())) { - if (decalMask) { - psize = Math.floor(cursorImg.width * (Context.raw.brush_decal_mask_radius * Context.raw.brush_nodes_radius) * zui_SCALE(UIBase.ui)); + (decal_mask && !Config.raw.brush_3d) || + (decal_mask && Context.in_2d_view())) { + if (decal_mask) { + psize = Math.floor(cursor_img.width * (Context.raw.brush_decal_mask_radius * Context.raw.brush_nodes_radius) * zui_SCALE(UIBase.ui)); } if (Config.raw.brush_3d && Context.in_2d_view()) { psize = Math.floor(psize * UIView2D.pan_scale); } - g2_draw_scaled_image(cursorImg, mx - psize / 2, my - psize / 2, psize, psize); + g2_draw_scaled_image(cursor_img, mx - psize / 2, my - psize / 2, psize, psize); } } @@ -1394,11 +1394,11 @@ class UIBase { Context.raw.tool == workspace_tool_t.SMUDGE || Context.raw.tool == workspace_tool_t.PARTICLE)) { g2_fill_rect(mx - 1, my - 1, 2, 2); - mx = Context.raw.brush_lazy_x * Base.w() + Base.x(); - my = Context.raw.brush_lazy_y * Base.h() + Base.y(); + mx = Context.raw.brush_lazy_x * base_w() + base_x(); + my = Context.raw.brush_lazy_y * base_h() + base_y(); let radius: f32 = Context.raw.brush_lazy_radius * 180; g2_set_color(0xff666666); - g2_draw_scaled_image(cursorImg, mx - radius / 2, my - radius / 2, radius, radius); + g2_draw_scaled_image(cursor_img, mx - radius / 2, my - radius / 2, radius, radius); g2_set_color(0xffffffff); } } @@ -1416,7 +1416,7 @@ class UIBase { UINodes.show = !UINodes.show; ///end - Base.resize(); + base_resize(); } ///if (is_paint || is_sculpt) @@ -1425,7 +1425,7 @@ class UIBase { zui_end_input(); UINodes.show = !UINodes.show || UINodes.canvas_type != canvas_type_t.BRUSH; UINodes.canvas_type = canvas_type_t.BRUSH; - Base.resize(); + base_resize(); } ///end @@ -1436,7 +1436,7 @@ class UIBase { else UIView2D.show = !UIView2D.show; UIView2D.type = type; UIView2D.hwnd.redraws = 2; - Base.resize(); + base_resize(); } static toggle_browser = () => { @@ -1457,7 +1457,7 @@ class UIBase { } static on_border_hover = (handle_ptr: i32, side: i32) => { - if (!Base.ui_enabled) return; + if (!base_ui_enabled) return; ///if (is_paint || is_sculpt) if (handle_ptr != UIBase.hwnds[tab_area_t.SIDEBAR0].ptr && @@ -1489,7 +1489,7 @@ class UIBase { if (zui_current.input_started) { UIBase.border_started = side; UIBase.border_handle_ptr = handle_ptr; - Base.is_resizing = true; + base_is_resizing = true; } } diff --git a/base/Sources/UIBox.ts b/base/Sources/UIBox.ts index 59fc35b0..48491ead 100644 --- a/base/Sources/UIBox.ts +++ b/base/Sources/UIBox.ts @@ -19,10 +19,10 @@ class UIBox { static render = () => { if (!UIMenu.show) { - let ui: zui_t = Base.ui_box; - let inUse: bool = ui.combo_selected_handle_ptr != 0; - let isEscape: bool = keyboard_started("escape"); - if (UIBox.draws > 2 && (ui.input_released || isEscape) && !inUse && !ui.is_typing) { + let ui: zui_t = base_ui_box; + let in_use: bool = ui.combo_selected_handle_ptr != 0; + let is_escape: bool = keyboard_started("escape"); + if (UIBox.draws > 2 && (ui.input_released || is_escape) && !in_use && !ui.is_typing) { let appw: i32 = sys_width(); let apph: i32 = sys_height(); let mw: i32 = Math.floor(UIBox.modalw * zui_SCALE(ui)); @@ -33,7 +33,7 @@ class UIBox { let bottom: f32 = (apph / 2 + mh / 2) + UIBox.hwnd.drag_y; let mx: i32 = mouse_x; let my: i32 = mouse_y; - if ((UIBox.click_to_hide && (mx < left || mx > right || my < top || my > bottom)) || isEscape) { + if ((UIBox.click_to_hide && (mx < left || mx > right || my < top || my > bottom)) || is_escape) { UIBox.hide(); } } @@ -50,7 +50,7 @@ class UIBox { g2_end(); - let ui: zui_t = Base.ui_box; + let ui: zui_t = base_ui_box; let appw: i32 = sys_width(); let apph: i32 = sys_height(); let mw: i32 = Math.floor(UIBox.modalw * zui_SCALE(ui)); @@ -64,8 +64,8 @@ class UIBox { zui_begin(ui); if (zui_window(UIBox.hwnd, left, top, mw, mh, UIBox.draggable)) { ui._y += 10; - let tabVertical: bool = Config.raw.touch_ui; - if (zui_tab(zui_handle("uibox_0"), UIBox.box_title, tabVertical)) { + let tab_vertical: bool = Config.raw.touch_ui; + if (zui_tab(zui_handle("uibox_0"), UIBox.box_title, tab_vertical)) { let htext: zui_handle_t = zui_handle("uibox_1"); htext.text = UIBox.box_text; UIBox.copyable ? @@ -147,7 +147,7 @@ class UIBox { static hide_internal = () => { if (UIBox.modal_on_hide != null) UIBox.modal_on_hide(); UIBox.show = false; - Base.redraw_ui(); + base_redraw_ui(); } ///if (krom_android || krom_ios) @@ -155,7 +155,7 @@ class UIBox { tween_reset(); tween_to({target: UIBox, props: { tweenAlpha: 0.5 }, duration: 0.2, ease: ease_t.EXPO_OUT}); UIBox.hwnd.drag_y = Math.floor(sys_height() / 2); - tween_to({target: UIBox.hwnd, props: { dragY: 0 }, duration: 0.2, ease: ease_t.EXPO_OUT, tick: () => { Base.redraw_ui(); }}); + tween_to({target: UIBox.hwnd, props: { dragY: 0 }, duration: 0.2, ease: ease_t.EXPO_OUT, tick: () => { base_redraw_ui(); }}); } static tween_out = () => { diff --git a/base/Sources/UIFiles.ts b/base/Sources/UIFiles.ts index bcf03642..6932dcec 100644 --- a/base/Sources/UIFiles.ts +++ b/base/Sources/UIFiles.ts @@ -53,19 +53,19 @@ class UIFiles { // let known: bool = false; // UIBox.show_custom((ui: ZuiRaw) => { // if (Zui.tab(Zui.handle(), tr("File Browser"))) { - // let pathHandle: zui_handle_t = Zui.handle(); - // let fileHandle: zui_handle_t = Zui.handle(); + // let path_handle: zui_handle_t = Zui.handle(); + // let file_handle: zui_handle_t = Zui.handle(); // Zui.row([6 / 10, 2 / 10, 2 / 10]); - // filename = Zui.textInput(fileHandle, tr("File")); + // filename = Zui.textInput(file_handle, tr("File")); // Zui.text("*." + filters, Center); // if (Zui.button(isSave ? tr("Save") : tr("Open")) || known || ui.isReturnDown) { // UIBox.hide(); // filesDone((known || isSave) ? path : path + Path.sep + filename); - // if (known) pathHandle.text = pathHandle.text.substr(0, pathHandle.text.lastIndexOf(Path.sep)); + // if (known) path_handle.text = path_handle.text.substr(0, path_handle.text.lastIndexOf(Path.sep)); // } // known = Path.isTexture(path) || Path.isMesh(path) || Path.isProject(path); - // path = fileBrowser(ui, pathHandle, false); - // if (pathHandle.changed) ui.currentWindow.redraws = 3; + // path = fileBrowser(ui, path_handle, false); + // if (path_handle.changed) ui.currentWindow.redraws = 3; // } // }, 600, 500); // } @@ -84,14 +84,14 @@ class UIFiles { let icons: image_t = Res.get("icons.k"); let folder: rect_t = Res.tile50(icons, 2, 1); let file: rect_t = Res.tile50(icons, 3, 1); - let isCloud: bool = handle.text.startsWith("cloud"); + let is_cloud: bool = handle.text.startsWith("cloud"); - if (isCloud && File.cloud == null) File.init_cloud(() => { UIBase.hwnds[tab_area_t.STATUS].redraws = 3; }); - if (isCloud && File.read_directory("cloud", false).length == 0) return handle.text; + if (is_cloud && File.cloud == null) File.init_cloud(() => { UIBase.hwnds[tab_area_t.STATUS].redraws = 3; }); + if (is_cloud && File.read_directory("cloud", false).length == 0) return handle.text; ///if krom_ios - let documentDirectory: string = krom_save_dialog("", ""); - documentDirectory = documentDirectory.substr(0, documentDirectory.length - 8); // Strip /'untitled' + let document_directory: string = krom_save_dialog("", ""); + document_directory = document_directory.substr(0, document_directory.length - 8); // Strip /'untitled' ///end if (handle.text == "") handle.text = UIFiles.default_path; @@ -107,16 +107,16 @@ class UIFiles { ///end if (nested) UIFiles.files.push(".."); - let dirPath: string = handle.text; + let dir_path: string = handle.text; ///if krom_ios - if (!isCloud) dirPath = documentDirectory + dirPath; + if (!is_cloud) dir_path = document_directory + dir_path; ///end - let filesAll: string[] = File.read_directory(dirPath, foldersOnly); + let files_all: string[] = File.read_directory(dir_path, foldersOnly); - for (let f of filesAll) { + for (let f of files_all) { if (f == "" || f.charAt(0) == ".") continue; // Skip hidden if (f.indexOf(".") > 0 && !Path.is_known(f)) continue; // Skip unknown extensions - if (isCloud && f.indexOf("_icon.") >= 0) continue; // Skip thumbnails + if (is_cloud && f.indexOf("_icon.") >= 0) continue; // Skip thumbnails if (f.toLowerCase().indexOf(search.toLowerCase()) < 0) continue; // Search filter UIFiles.files.push(f); } @@ -160,20 +160,20 @@ class UIFiles { let generic: bool = true; let icon: image_t = null; - if (isCloud && f != ".." && !UIFiles.offline) { + if (is_cloud && f != ".." && !UIFiles.offline) { if (UIFiles.icon_map == null) UIFiles.icon_map = new Map(); icon = UIFiles.icon_map.get(handle.text + Path.sep + f); if (icon == null) { - let filesAll: string[] = File.read_directory(handle.text); - let iconFile: string = f.substr(0, f.lastIndexOf(".")) + "_icon.jpg"; - if (filesAll.indexOf(iconFile) >= 0) { + let files_all: string[] = File.read_directory(handle.text); + let icon_file: string = f.substr(0, f.lastIndexOf(".")) + "_icon.jpg"; + if (files_all.indexOf(icon_file) >= 0) { let empty: image_t = render_path_render_targets.get("empty_black")._image; UIFiles.icon_map.set(handle.text + Path.sep + f, empty); - File.cache_cloud(handle.text + Path.sep + iconFile, (abs: string) => { + File.cache_cloud(handle.text + Path.sep + icon_file, (abs: string) => { if (abs != null) { let image: image_t = data_get_image(abs); app_notify_on_init(() => { - if (Base.pipe_copyRGB == null) Base.make_pipe_copy_rgb(); + if (base_pipe_copy_rgb == null) base_make_pipe_copy_rgb(); icon = image_create_render_target(image.width, image.height); if (f.endsWith(".arm")) { // Used for material sphere alpha cutout g2_begin(icon); @@ -186,7 +186,7 @@ class UIFiles { g2_begin(icon); g2_clear(0xffffffff); } - g2_set_pipeline(Base.pipe_copyRGB); + g2_set_pipeline(base_pipe_copy_rgb); g2_draw_image(image, 0, 0); g2_set_pipeline(null); g2_end(); @@ -214,40 +214,40 @@ class UIFiles { generic = false; } } - if (f.endsWith(".arm") && !isCloud) { + if (f.endsWith(".arm") && !is_cloud) { if (UIFiles.icon_map == null) UIFiles.icon_map = new Map(); let key: string = handle.text + Path.sep + f; icon = UIFiles.icon_map.get(key); if (!UIFiles.icon_map.has(key)) { - let blobPath: string = key; + let blob_path: string = key; ///if krom_ios - blobPath = documentDirectory + blobPath; + blob_path = document_directory + blob_path; // TODO: implement native .arm parsing first ///else - let buffer: buffer_t = krom_load_blob(blobPath); + let buffer: buffer_t = krom_load_blob(blob_path); let raw: any = armpack_decode(buffer); if (raw.material_icons != null) { - let bytesIcon: any = raw.material_icons[0]; - icon = image_from_bytes(lz4_decode(bytesIcon, 256 * 256 * 4), 256, 256); + let bytes_icon: any = raw.material_icons[0]; + icon = image_from_bytes(lz4_decode(bytes_icon, 256 * 256 * 4), 256, 256); } ///if (is_paint || is_sculpt) else if (raw.mesh_icons != null) { - let bytesIcon: any = raw.mesh_icons[0]; - icon = image_from_bytes(lz4_decode(bytesIcon, 256 * 256 * 4), 256, 256); + let bytes_icon: any = raw.mesh_icons[0]; + icon = image_from_bytes(lz4_decode(bytes_icon, 256 * 256 * 4), 256, 256); } else if (raw.brush_icons != null) { - let bytesIcon: any = raw.brush_icons[0]; - icon = image_from_bytes(lz4_decode(bytesIcon, 256 * 256 * 4), 256, 256); + let bytes_icon: any = raw.brush_icons[0]; + icon = image_from_bytes(lz4_decode(bytes_icon, 256 * 256 * 4), 256, 256); } ///end ///if is_lab if (raw.mesh_icon != null) { - let bytesIcon: any = raw.mesh_icon; - icon = image_from_bytes(lz4_decode(bytesIcon, 256 * 256 * 4), 256, 256); + let bytes_icon: any = raw.mesh_icon; + icon = image_from_bytes(lz4_decode(bytes_icon, 256 * 256 * 4), 256, 256); } ///end @@ -271,7 +271,7 @@ class UIFiles { } } - if (Path.is_texture(f) && !isCloud) { + if (Path.is_texture(f) && !is_cloud) { let w: i32 = 50; if (UIFiles.icon_map == null) UIFiles.icon_map = new Map(); let shandle: string = handle.text + Path.sep + f; @@ -281,13 +281,13 @@ class UIFiles { UIFiles.icon_map.set(shandle, empty); let image: image_t = data_get_image(shandle); app_notify_on_init(() => { - if (Base.pipe_copyRGB == null) Base.make_pipe_copy_rgb(); + if (base_pipe_copy_rgb == null) base_make_pipe_copy_rgb(); let sw: i32 = image.width > image.height ? w : Math.floor(1.0 * image.width / image.height * w); let sh: i32 = image.width > image.height ? Math.floor(1.0 * image.height / image.width * w) : w; icon = image_create_render_target(sw, sh); g2_begin(icon); g2_clear(0xffffffff); - g2_set_pipeline(Base.pipe_copyRGB); + g2_set_pipeline(base_pipe_copy_rgb); g2_draw_scaled_image(image, 0, 0, sw, sh); g2_set_pipeline(null); g2_end(); @@ -318,24 +318,24 @@ class UIFiles { if (state == zui_state_t.STARTED) { if (f != ".." && dragFiles) { - Base.drag_off_x = -(mouse_x - uix - ui._window_x - 3); - Base.drag_off_y = -(mouse_y - uiy - ui._window_y + 1); - Base.drag_file = handle.text; + base_drag_off_x = -(mouse_x - uix - ui._window_x - 3); + base_drag_off_y = -(mouse_y - uiy - ui._window_y + 1); + base_drag_file = handle.text; ///if krom_ios - if (!isCloud) Base.drag_file = documentDirectory + Base.drag_file; + if (!is_cloud) base_drag_file = document_directory + base_drag_file; ///end - if (Base.drag_file.charAt(Base.drag_file.length - 1) != Path.sep) { - Base.drag_file += Path.sep; + if (base_drag_file.charAt(base_drag_file.length - 1) != Path.sep) { + base_drag_file += Path.sep; } - Base.drag_file += f; - Base.drag_file_icon = icon; + base_drag_file += f; + base_drag_file_icon = icon; } UIFiles.selected = i; if (time_time() - Context.raw.select_time < 0.25) { - Base.drag_file = null; - Base.drag_file_icon = null; - Base.is_dragging = false; + base_drag_file = null; + base_drag_file_icon = null; + base_is_dragging = false; handle.changed = ui.changed = true; if (f == "..") { // Up handle.text = handle.text.substring(0, handle.text.lastIndexOf(Path.sep)); diff --git a/base/Sources/UIHeader.ts b/base/Sources/UIHeader.ts index 8c05f40b..f8bdb83c 100644 --- a/base/Sources/UIHeader.ts +++ b/base/Sources/UIHeader.ts @@ -50,7 +50,7 @@ class UIHeader { ui.enabled = true; zui_text(tr("Color ID Map")); if (Project.asset_names.length > 0) { - let cid: i32 = zui_combo(Context.raw.colorid_handle, Base.enum_texts("TEX_IMAGE"), tr("Color ID")); + let cid: i32 = zui_combo(Context.raw.colorid_handle, base_enum_texts("TEX_IMAGE"), tr("Color ID")); if (Context.raw.colorid_handle.changed) { Context.raw.ddirty = 2; Context.raw.colorid_picked = false; @@ -77,14 +77,14 @@ class UIHeader { ui.enabled = Context.raw.colorid_picked; if (zui_button(tr("To Mask"))) { if (SlotLayer.is_mask(Context.raw.layer)) Context.set_layer(Context.raw.layer.parent); - let m: SlotLayerRaw = Base.new_mask(false, Context.raw.layer); + let m: SlotLayerRaw = base_new_mask(false, Context.raw.layer); let _next = () => { - if (Base.pipe_merge == null) Base.make_pipe(); + if (base_pipe_merge == null) base_make_pipe(); if (const_data_screen_aligned_vb == null) const_data_create_screen_aligned_data(); g4_begin(m.texpaint); - g4_set_pipeline(Base.pipe_colorid_to_mask); - g4_set_tex(Base.texpaint_colorid,render_path_render_targets.get("texpaint_colorid")._image); - g4_set_tex(Base.tex_colorid, Project.get_image(Project.assets[Context.raw.colorid_handle.position])); + g4_set_pipeline(base_pipe_colorid_to_mask); + g4_set_tex(base_texpaint_colorid,render_path_render_targets.get("texpaint_colorid")._image); + g4_set_tex(base_tex_colorid, Project.get_image(Project.assets[Context.raw.colorid_handle.position])); g4_set_vertex_buffer(const_data_screen_aligned_vb); g4_set_index_buffer(const_data_screen_aligned_ib); g4_draw(); @@ -93,39 +93,39 @@ class UIHeader { UIToolbar.toolbar_handle.redraws = 1; UIHeader.header_handle.redraws = 1; Context.raw.layer_preview_dirty = true; - Base.update_fill_layers(); + base_update_fill_layers(); } - Base.notify_on_next_frame(_next); + base_notify_on_next_frame(_next); History.new_white_mask(); } ui.enabled = true; } else if (Context.raw.tool == workspace_tool_t.PICKER || Context.raw.tool == workspace_tool_t.MATERIAL) { - let baseRPicked: f32 = Math.round(color_get_rb(Context.raw.picked_color.base) / 255 * 10) / 10; - let baseGPicked: f32 = Math.round(color_get_gb(Context.raw.picked_color.base) / 255 * 10) / 10; - let baseBPicked: f32 = Math.round(color_get_bb(Context.raw.picked_color.base) / 255 * 10) / 10; - let normalRPicked: f32 = Math.round(color_get_rb(Context.raw.picked_color.normal) / 255 * 10) / 10; - let normalGPicked: f32 = Math.round(color_get_gb(Context.raw.picked_color.normal) / 255 * 10) / 10; - let normalBPicked: f32 = Math.round(color_get_bb(Context.raw.picked_color.normal) / 255 * 10) / 10; - let occlusionPicked: f32 = Math.round(Context.raw.picked_color.occlusion * 100) / 100; - let roughnessPicked: f32 = Math.round(Context.raw.picked_color.roughness * 100) / 100; - let metallicPicked: f32 = Math.round(Context.raw.picked_color.metallic * 100) / 100; - let heightPicked: f32 = Math.round(Context.raw.picked_color.height * 100) / 100; - let opacityPicked: f32 = Math.round(Context.raw.picked_color.opacity * 100) / 100; + let base_r_picked: f32 = Math.round(color_get_rb(Context.raw.picked_color.base) / 255 * 10) / 10; + let base_g_picked: f32 = Math.round(color_get_gb(Context.raw.picked_color.base) / 255 * 10) / 10; + let base_b_picked: f32 = Math.round(color_get_bb(Context.raw.picked_color.base) / 255 * 10) / 10; + let normal_r_picked: f32 = Math.round(color_get_rb(Context.raw.picked_color.normal) / 255 * 10) / 10; + let normal_g_picked: f32 = Math.round(color_get_gb(Context.raw.picked_color.normal) / 255 * 10) / 10; + let normal_b_picked: f32 = Math.round(color_get_bb(Context.raw.picked_color.normal) / 255 * 10) / 10; + let occlusion_picked: f32 = Math.round(Context.raw.picked_color.occlusion * 100) / 100; + let roughness_picked: f32 = Math.round(Context.raw.picked_color.roughness * 100) / 100; + let metallic_picked: f32 = Math.round(Context.raw.picked_color.metallic * 100) / 100; + let height_picked: f32 = Math.round(Context.raw.picked_color.height * 100) / 100; + let opacity_picked: f32 = Math.round(Context.raw.picked_color.opacity * 100) / 100; let h: zui_handle_t = zui_handle("uiheader_0"); let color: color_t = 0xffffffff; - color = color_set_rb(color, baseRPicked * 255); - color = color_set_gb(color, baseGPicked * 255); - color = color_set_bb(color, baseBPicked * 255); + color = color_set_rb(color, base_r_picked * 255); + color = color_set_gb(color, base_g_picked * 255); + color = color_set_bb(color, base_b_picked * 255); h.color = color; let state: zui_state_t = zui_text("", 0, h.color); if (state == zui_state_t.STARTED) { let uix: i32 = ui._x; let uiy: i32 = ui._y; - Base.drag_off_x = -(mouse_x - uix - ui._window_x - 3); - Base.drag_off_y = -(mouse_y - uiy - ui._window_y + 1); - Base.drag_swatch = Project.clone_swatch(Context.raw.picked_color); + base_drag_off_x = -(mouse_x - uix - ui._window_x - 3); + base_drag_off_y = -(mouse_y - uiy - ui._window_y + 1); + base_drag_swatch = Project.clone_swatch(Context.raw.picked_color); } if (ui.is_hovered) zui_tooltip(tr("Drag and drop picked color to swatches, materials, layers or to the node editor")); if (ui.is_hovered && ui.input_released) { @@ -137,20 +137,20 @@ class UIHeader { }, 10); } if (zui_button(tr("Add Swatch"))) { - let newSwatch: swatch_color_t = Project.clone_swatch(Context.raw.picked_color); - Context.set_swatch(newSwatch); - Project.raw.swatches.push(newSwatch); + let new_swatch: swatch_color_t = Project.clone_swatch(Context.raw.picked_color); + Context.set_swatch(new_swatch); + Project.raw.swatches.push(new_swatch); UIBase.hwnds[2].redraws = 1; } if (ui.is_hovered) zui_tooltip(tr("Add picked color to swatches")); - zui_text(tr("Base") + ` (${baseRPicked},${baseGPicked},${baseBPicked})`); - zui_text(tr("Normal") + ` (${normalRPicked},${normalGPicked},${normalBPicked})`); - zui_text(tr("Occlusion") + ` (${occlusionPicked})`); - zui_text(tr("Roughness") + ` (${roughnessPicked})`); - zui_text(tr("Metallic") + ` (${metallicPicked})`); - zui_text(tr("Height") + ` (${heightPicked})`); - zui_text(tr("Opacity") + ` (${opacityPicked})`); + zui_text(tr("Base") + ` (${base_r_picked},${base_g_picked},${base_b_picked})`); + zui_text(tr("Normal") + ` (${normal_r_picked},${normal_g_picked},${normal_b_picked})`); + zui_text(tr("Occlusion") + ` (${occlusion_picked})`); + zui_text(tr("Roughness") + ` (${roughness_picked})`); + zui_text(tr("Metallic") + ` (${metallic_picked})`); + zui_text(tr("Height") + ` (${height_picked})`); + zui_text(tr("Opacity") + ` (${opacity_picked})`); Context.raw.picker_select_material = zui_check(zui_handle("uiheader_1", { selected: Context.raw.picker_select_material }), tr("Select Material")); zui_combo(Context.raw.picker_mask_handle, [tr("None"), tr("Material")], tr("Mask"), true); if (Context.raw.picker_mask_handle.changed) { @@ -162,20 +162,20 @@ class UIHeader { ///if (krom_direct3d12 || krom_vulkan || krom_metal) let baking: bool = Context.raw.pdirty > 0; - let rtBake: bool = Context.raw.bake_type == bake_type_t.AO || Context.raw.bake_type == bake_type_t.LIGHTMAP || Context.raw.bake_type == bake_type_t.BENT_NORMAL || Context.raw.bake_type == bake_type_t.THICKNESS; + let rt_bake: bool = Context.raw.bake_type == bake_type_t.AO || Context.raw.bake_type == bake_type_t.LIGHTMAP || Context.raw.bake_type == bake_type_t.BENT_NORMAL || Context.raw.bake_type == bake_type_t.THICKNESS; if (baking && zui_button(tr("Stop"))) { Context.raw.pdirty = 0; Context.raw.rdirty = 2; } ///else let baking: bool = false; - let rtBake: bool = false; + let rt_bake: bool = false; ///end if (!baking && zui_button(tr("Bake"))) { - Context.raw.pdirty = rtBake ? Context.raw.bake_samples : 1; + Context.raw.pdirty = rt_bake ? Context.raw.bake_samples : 1; Context.raw.rdirty = 3; - Base.notify_on_next_frame(() => { + base_notify_on_next_frame(() => { Context.raw.layer_preview_dirty = true; }); UIBase.hwnds[0].redraws = 2; @@ -185,7 +185,7 @@ class UIHeader { ///end } - let bakeHandle: zui_handle_t = zui_handle("uiheader_2", { position: Context.raw.bake_type }); + let bake_handle: zui_handle_t = zui_handle("uiheader_2", { position: Context.raw.bake_type }); let bakes: string[] = [ tr("AO"), tr("Curvature"), @@ -210,7 +210,7 @@ class UIHeader { } ///end - Context.raw.bake_type = zui_combo(bakeHandle, bakes, tr("Bake")); + Context.raw.bake_type = zui_combo(bake_handle, bakes, tr("Bake")); ///if (krom_direct3d12 || krom_vulkan || krom_metal) if (!krom_raytrace_supported()) { @@ -219,30 +219,30 @@ class UIHeader { ///end ///if (krom_direct3d12 || krom_vulkan || krom_metal) - if (rtBake) { - let samplesHandle: zui_handle_t = zui_handle("uiheader_3", { value: Context.raw.bake_samples }); - Context.raw.bake_samples = Math.floor(zui_slider(samplesHandle, tr("Samples"), 1, 512, true, 1)); + if (rt_bake) { + let samples_handle: zui_handle_t = zui_handle("uiheader_3", { value: Context.raw.bake_samples }); + Context.raw.bake_samples = Math.floor(zui_slider(samples_handle, tr("Samples"), 1, 512, true, 1)); } ///end if (Context.raw.bake_type == bake_type_t.NORMAL_OBJECT || Context.raw.bake_type == bake_type_t.POSITION || Context.raw.bake_type == bake_type_t.BENT_NORMAL) { - let bakeUpAxisHandle: zui_handle_t = zui_handle("uiheader_4", { position: Context.raw.bake_up_axis }); - Context.raw.bake_up_axis = zui_combo(bakeUpAxisHandle, [tr("Z"), tr("Y")], tr("Up Axis"), true); + let bake_up_axis_handle: zui_handle_t = zui_handle("uiheader_4", { position: Context.raw.bake_up_axis }); + Context.raw.bake_up_axis = zui_combo(bake_up_axis_handle, [tr("Z"), tr("Y")], tr("Up Axis"), true); } if (Context.raw.bake_type == bake_type_t.AO || Context.raw.bake_type == bake_type_t.CURVATURE) { - let bakeAxisHandle: zui_handle_t = zui_handle("uiheader_5", { position: Context.raw.bake_axis }); - Context.raw.bake_axis = zui_combo(bakeAxisHandle, [tr("XYZ"), tr("X"), tr("Y"), tr("Z"), tr("-X"), tr("-Y"), tr("-Z")], tr("Axis"), true); + let bake_axis_handle: zui_handle_t = zui_handle("uiheader_5", { position: Context.raw.bake_axis }); + Context.raw.bake_axis = zui_combo(bake_axis_handle, [tr("XYZ"), tr("X"), tr("Y"), tr("Z"), tr("-X"), tr("-Y"), tr("-Z")], tr("Axis"), true); } if (Context.raw.bake_type == bake_type_t.AO) { - let strengthHandle: zui_handle_t = zui_handle("uiheader_6", { value: Context.raw.bake_ao_strength }); - Context.raw.bake_ao_strength = zui_slider(strengthHandle, tr("Strength"), 0.0, 2.0, true); - let radiusHandle: zui_handle_t = zui_handle("uiheader_7", { value: Context.raw.bake_ao_radius }); - Context.raw.bake_ao_radius = zui_slider(radiusHandle, tr("Radius"), 0.0, 2.0, true); - let offsetHandle: zui_handle_t = zui_handle("uiheader_8", { value: Context.raw.bake_ao_offset }); - Context.raw.bake_ao_offset = zui_slider(offsetHandle, tr("Offset"), 0.0, 2.0, true); + let strength_handle: zui_handle_t = zui_handle("uiheader_6", { value: Context.raw.bake_ao_strength }); + Context.raw.bake_ao_strength = zui_slider(strength_handle, tr("Strength"), 0.0, 2.0, true); + let radius_handle: zui_handle_t = zui_handle("uiheader_7", { value: Context.raw.bake_ao_radius }); + Context.raw.bake_ao_radius = zui_slider(radius_handle, tr("Radius"), 0.0, 2.0, true); + let offset_handle: zui_handle_t = zui_handle("uiheader_8", { value: Context.raw.bake_ao_offset }); + Context.raw.bake_ao_offset = zui_slider(offset_handle, tr("Offset"), 0.0, 2.0, true); } ///if (krom_direct3d12 || krom_vulkan || krom_metal) - if (rtBake) { + if (rt_bake) { let progress: f32 = RenderPathRaytraceBake.current_sample / Context.raw.bake_samples; if (progress > 1.0) progress = 1.0; // Progress bar @@ -257,20 +257,20 @@ class UIHeader { } ///end if (Context.raw.bake_type == bake_type_t.CURVATURE) { - let strengthHandle: zui_handle_t = zui_handle("uiheader_9", { value: Context.raw.bake_curv_strength }); - Context.raw.bake_curv_strength = zui_slider(strengthHandle, tr("Strength"), 0.0, 2.0, true); - let radiusHandle: zui_handle_t = zui_handle("uiheader_10", { value: Context.raw.bake_curv_radius }); - Context.raw.bake_curv_radius = zui_slider(radiusHandle, tr("Radius"), 0.0, 2.0, true); - let offsetHandle: zui_handle_t = zui_handle("uiheader_11", { value: Context.raw.bake_curv_offset }); - Context.raw.bake_curv_offset = zui_slider(offsetHandle, tr("Offset"), -2.0, 2.0, true); - let smoothHandle: zui_handle_t = zui_handle("uiheader_12", { value: Context.raw.bake_curv_smooth }); - Context.raw.bake_curv_smooth = Math.floor(zui_slider(smoothHandle, tr("Smooth"), 0, 5, false, 1)); + let strength_handle: zui_handle_t = zui_handle("uiheader_9", { value: Context.raw.bake_curv_strength }); + Context.raw.bake_curv_strength = zui_slider(strength_handle, tr("Strength"), 0.0, 2.0, true); + let radius_handle: zui_handle_t = zui_handle("uiheader_10", { value: Context.raw.bake_curv_radius }); + Context.raw.bake_curv_radius = zui_slider(radius_handle, tr("Radius"), 0.0, 2.0, true); + let offset_handle: zui_handle_t = zui_handle("uiheader_11", { value: Context.raw.bake_curv_offset }); + Context.raw.bake_curv_offset = zui_slider(offset_handle, tr("Offset"), -2.0, 2.0, true); + let smooth_handle: zui_handle_t = zui_handle("uiheader_12", { value: Context.raw.bake_curv_smooth }); + Context.raw.bake_curv_smooth = Math.floor(zui_slider(smooth_handle, tr("Smooth"), 0, 5, false, 1)); } if (Context.raw.bake_type == bake_type_t.NORMAL || Context.raw.bake_type == bake_type_t.HEIGHT || Context.raw.bake_type == bake_type_t.DERIVATIVE) { let ar: string[] = []; for (let p of Project.paint_objects) ar.push(p.base.name); - let polyHandle: zui_handle_t = zui_handle("uiheader_13", { position: Context.raw.bake_high_poly }); - Context.raw.bake_high_poly = zui_combo(polyHandle, ar, tr("High Poly")); + let poly_handle: zui_handle_t = zui_handle("uiheader_13", { position: Context.raw.bake_high_poly }); + Context.raw.bake_high_poly = zui_combo(poly_handle, ar, tr("High Poly")); } if (ui.changed) { MakeMaterial.parse_paint_material(); @@ -287,9 +287,9 @@ class UIHeader { Context.raw.tool == workspace_tool_t.PARTICLE) { let decal: bool = Context.raw.tool == workspace_tool_t.DECAL || Context.raw.tool == workspace_tool_t.TEXT; - let decalMask: bool = decal && Operator.shortcut(Config.keymap.decal_mask, ShortcutType.ShortcutDown); + let decal_mask: bool = decal && Operator.shortcut(Config.keymap.decal_mask, ShortcutType.ShortcutDown); if (Context.raw.tool != workspace_tool_t.FILL) { - if (decalMask) { + if (decal_mask) { Context.raw.brush_decal_mask_radius = zui_slider(Context.raw.brush_decal_mask_radius_handle, tr("Radius"), 0.01, 2.0, true); if (ui.is_hovered) zui_tooltip(tr("Hold {brush_radius} and move mouse to the left or press {brush_radius_decrease} to decrease the radius\nHold {brush_radius} and move mouse to the right or press {brush_radius_increase} to increase the radius", new Map([["brush_radius", Config.keymap.brush_radius], ["brush_radius_decrease", Config.keymap.brush_radius_decrease], ["brush_radius_increase", Config.keymap.brush_radius_increase]]))); } @@ -307,9 +307,9 @@ class UIHeader { Context.raw.tool == workspace_tool_t.FILL || Context.raw.tool == workspace_tool_t.DECAL || Context.raw.tool == workspace_tool_t.TEXT) { - let brushScaleHandle: zui_handle_t = zui_handle("uiheader_14", { value: Context.raw.brush_scale }); - Context.raw.brush_scale = zui_slider(brushScaleHandle, tr("UV Scale"), 0.01, 5.0, true); - if (brushScaleHandle.changed) { + let brush_scale_handle: zui_handle_t = zui_handle("uiheader_14", { value: Context.raw.brush_scale }); + Context.raw.brush_scale = zui_slider(brush_scale_handle, tr("UV Scale"), 0.01, 5.0, true); + if (brush_scale_handle.changed) { if (Context.raw.tool == workspace_tool_t.DECAL || Context.raw.tool == workspace_tool_t.TEXT) { let current: image_t = _g2_current; g2_end(); @@ -329,13 +329,13 @@ class UIHeader { Context.raw.brush_opacity = zui_slider(Context.raw.brush_opacity_handle, tr("Opacity"), 0.0, 1.0, true); if (ui.is_hovered) zui_tooltip(tr("Hold {brush_opacity} and move mouse to the left to decrease the opacity\nHold {brush_opacity} and move mouse to the right to increase the opacity", new Map([["brush_opacity", Config.keymap.brush_opacity]]))); - if (Context.raw.tool == workspace_tool_t.BRUSH || Context.raw.tool == workspace_tool_t.ERASER || Context.raw.tool == workspace_tool_t.CLONE || decalMask) { + if (Context.raw.tool == workspace_tool_t.BRUSH || Context.raw.tool == workspace_tool_t.ERASER || Context.raw.tool == workspace_tool_t.CLONE || decal_mask) { Context.raw.brush_hardness = zui_slider(zui_handle("uiheader_15", { value: Context.raw.brush_hardness }), tr("Hardness"), 0.0, 1.0, true); } if (Context.raw.tool != workspace_tool_t.ERASER) { - let brushBlendingHandle: zui_handle_t = zui_handle("uiheader_16", { value: Context.raw.brush_blending }); - Context.raw.brush_blending = zui_combo(brushBlendingHandle, [ + let brush_blending_handle: zui_handle_t = zui_handle("uiheader_16", { value: Context.raw.brush_blending }); + Context.raw.brush_blending = zui_combo(brush_blending_handle, [ tr("Mix"), tr("Darken"), tr("Multiply"), @@ -355,15 +355,15 @@ class UIHeader { tr("Color"), tr("Value"), ], tr("Blending")); - if (brushBlendingHandle.changed) { + if (brush_blending_handle.changed) { MakeMaterial.parse_paint_material(); } } if (Context.raw.tool == workspace_tool_t.BRUSH || Context.raw.tool == workspace_tool_t.FILL) { - let paintHandle: zui_handle_t = zui_handle("uiheader_17"); - Context.raw.brush_paint = zui_combo(paintHandle, [tr("UV Map"), tr("Triplanar"), tr("Project")], tr("TexCoord")); - if (paintHandle.changed) { + let paint_handle: zui_handle_t = zui_handle("uiheader_17"); + Context.raw.brush_paint = zui_combo(paint_handle, [tr("UV Map"), tr("Triplanar"), tr("Project")], tr("TexCoord")); + if (paint_handle.changed) { MakeMaterial.parse_paint_material(); } } @@ -405,28 +405,28 @@ class UIHeader { else { let _w: i32 = ui._w; let sc: f32 = zui_SCALE(ui); - let touchHeader: bool = (Config.raw.touch_ui && Config.raw.layout[layout_size_t.HEADER] == 1); - if (touchHeader) ui._x -= 4 * sc; - ui._w = Math.floor((touchHeader ? 54 : 60) * sc); + let touch_header: bool = (Config.raw.touch_ui && Config.raw.layout[layout_size_t.HEADER] == 1); + if (touch_header) ui._x -= 4 * sc; + ui._w = Math.floor((touch_header ? 54 : 60) * sc); - let xrayHandle: zui_handle_t = zui_handle("uiheader_19", { selected: Context.raw.xray }); - Context.raw.xray = zui_check(xrayHandle, tr("X-Ray")); - if (xrayHandle.changed) { + let xray_handle: zui_handle_t = zui_handle("uiheader_19", { selected: Context.raw.xray }); + Context.raw.xray = zui_check(xray_handle, tr("X-Ray")); + if (xray_handle.changed) { MakeMaterial.parse_paint_material(); } - let symXHandle: zui_handle_t = zui_handle("uiheader_20", { selected: false }); - let symYHandle: zui_handle_t = zui_handle("uiheader_21", { selected: false }); - let symZHandle: zui_handle_t = zui_handle("uiheader_22", { selected: false }); + let sym_x_handle: zui_handle_t = zui_handle("uiheader_20", { selected: false }); + let sym_y_handle: zui_handle_t = zui_handle("uiheader_21", { selected: false }); + let sym_z_handle: zui_handle_t = zui_handle("uiheader_22", { selected: false }); if (Config.raw.layout[layout_size_t.HEADER] == 1) { if (Config.raw.touch_ui) { ui._w = Math.floor(19 * sc); - Context.raw.sym_x = zui_check(symXHandle, ""); + Context.raw.sym_x = zui_check(sym_x_handle, ""); ui._x -= 4 * sc; - Context.raw.sym_y = zui_check(symYHandle, ""); + Context.raw.sym_y = zui_check(sym_y_handle, ""); ui._x -= 4 * sc; - Context.raw.sym_z = zui_check(symZHandle, ""); + Context.raw.sym_z = zui_check(sym_z_handle, ""); ui._x -= 4 * sc; ui._w = Math.floor(40 * sc); zui_text(tr("X") + tr("Y") + tr("Z")); @@ -435,21 +435,21 @@ class UIHeader { ui._w = Math.floor(56 * sc); zui_text(tr("Symmetry")); ui._w = Math.floor(25 * sc); - Context.raw.sym_x = zui_check(symXHandle, tr("X")); - Context.raw.sym_y = zui_check(symYHandle, tr("Y")); - Context.raw.sym_z = zui_check(symZHandle, tr("Z")); + Context.raw.sym_x = zui_check(sym_x_handle, tr("X")); + Context.raw.sym_y = zui_check(sym_y_handle, tr("Y")); + Context.raw.sym_z = zui_check(sym_z_handle, tr("Z")); } ui._w = _w; } else { // Popup ui._w = _w; - Context.raw.sym_x = zui_check(symXHandle, tr("Symmetry") + " " + tr("X")); - Context.raw.sym_y = zui_check(symYHandle, tr("Symmetry") + " " + tr("Y")); - Context.raw.sym_z = zui_check(symZHandle, tr("Symmetry") + " " + tr("Z")); + Context.raw.sym_x = zui_check(sym_x_handle, tr("Symmetry") + " " + tr("X")); + Context.raw.sym_y = zui_check(sym_y_handle, tr("Symmetry") + " " + tr("Y")); + Context.raw.sym_z = zui_check(sym_z_handle, tr("Symmetry") + " " + tr("Z")); } - if (symXHandle.changed || symYHandle.changed || symZHandle.changed) { + if (sym_x_handle.changed || sym_y_handle.changed || sym_z_handle.changed) { MakeMaterial.parse_paint_material(); } } @@ -457,9 +457,9 @@ class UIHeader { ///if arm_physics if (Context.raw.tool == workspace_tool_t.PARTICLE) { ui._x += 10 * zui_SCALE(ui); - let physHandle: zui_handle_t = zui_handle("uiheader_23", { selected: false }); - Context.raw.particle_physics = zui_check(physHandle, tr("Physics")); - if (physHandle.changed) { + let phys_handle: zui_handle_t = zui_handle("uiheader_23", { selected: false }); + Context.raw.particle_physics = zui_check(phys_handle, tr("Physics")); + if (phys_handle.changed) { UtilParticle.init_particle_physics(); MakeMaterial.parse_paint_material(); } @@ -491,7 +491,7 @@ class UIHeader { let nodes: zui_nodes_t = UINodes.get_nodes(); let canvas: zui_node_canvas_t = UINodes.get_canvas(true); - let inpaint: bool = nodes.nodesSelectedId.length > 0 && zui_get_node(canvas.nodes, nodes.nodesSelectedId[0]).type == "InpaintNode"; + let inpaint: bool = nodes.nodes_selected_id.length > 0 && zui_get_node(canvas.nodes, nodes.nodes_selected_id[0]).type == "InpaintNode"; if (inpaint) { Context.raw.brush_radius = zui_slider(Context.raw.brush_radius_handle, tr("Radius"), 0.01, 2.0, true); if (ui.is_hovered) zui_tooltip(tr("Hold {brush_radius} and move mouse to the left or press {brush_radius_decrease} to decrease the radius\nHold {brush_radius} and move mouse to the right or press {brush_radius_increase} to increase the radius", new Map([["brush_radius", Config.keymap.brush_radius], ["brush_radius_decrease", Config.keymap.brush_radius_decrease], ["brush_radius_increase", Config.keymap.brush_radius_increase]]))); diff --git a/base/Sources/UIMenu.ts b/base/Sources/UIMenu.ts index 2498a4d0..963bdd2a 100644 --- a/base/Sources/UIMenu.ts +++ b/base/Sources/UIMenu.ts @@ -14,8 +14,8 @@ class UIMenu { static hide_menu: bool = false; static render = () => { - let ui: zui_t = Base.ui_menu; - let menuW: i32 = UIMenu.menu_commands != null ? Math.floor(Base.default_element_w * zui_SCALE(Base.ui_menu) * 2.3) : Math.floor(zui_ELEMENT_W(ui) * 2.3); + let ui: zui_t = base_ui_menu; + let menu_w: i32 = UIMenu.menu_commands != null ? Math.floor(base_default_element_w * zui_SCALE(base_ui_menu) * 2.3) : Math.floor(zui_ELEMENT_W(ui) * 2.3); let _BUTTON_COL: i32 = ui.t.BUTTON_COL; ui.t.BUTTON_COL = ui.t.SEPARATOR_COL; let _ELEMENT_OFFSET: i32 = ui.t.ELEMENT_OFFSET; @@ -23,7 +23,7 @@ class UIMenu { let _ELEMENT_H: i32 = ui.t.ELEMENT_H; ui.t.ELEMENT_H = Config.raw.touch_ui ? (28 + 2) : 28; - zui_begin_region(ui, UIMenu.menu_x, UIMenu.menu_y, menuW); + zui_begin_region(ui, UIMenu.menu_x, UIMenu.menu_y, menu_w); if (UIMenu.menu_commands != null) { g2_set_color(ui.t.ACCENT_SELECT_COL); @@ -89,18 +89,18 @@ class UIMenu { if (UIMenu.menu_button(ui, tr("Exit"))) sys_stop(); } else if (UIMenu.menu_category == menu_category_t.EDIT) { - let stepUndo: string = ""; - let stepRedo: string = ""; + let step_undo: string = ""; + let step_redo: string = ""; if (History.undos > 0) { - stepUndo = History.steps[History.steps.length - 1 - History.redos].name; + step_undo = History.steps[History.steps.length - 1 - History.redos].name; } if (History.redos > 0) { - stepRedo = History.steps[History.steps.length - History.redos].name; + step_redo = History.steps[History.steps.length - History.redos].name; } ui.enabled = History.undos > 0; - if (UIMenu.menu_button(ui, tr("Undo {step}", new Map([["step", stepUndo]])), Config.keymap.edit_undo)) History.undo(); + if (UIMenu.menu_button(ui, tr("Undo {step}", new Map([["step", step_undo]])), Config.keymap.edit_undo)) History.undo(); ui.enabled = History.redos > 0; - if (UIMenu.menu_button(ui, tr("Redo {step}", new Map([["step", stepRedo]])), Config.keymap.edit_redo)) History.redo(); + if (UIMenu.menu_button(ui, tr("Redo {step}", new Map([["step", step_redo]])), Config.keymap.edit_redo)) History.redo(); ui.enabled = true; UIMenu.menu_separator(ui); if (UIMenu.menu_button(ui, tr("Preferences..."), Config.keymap.edit_prefs)) BoxPreferences.show(); @@ -113,7 +113,7 @@ class UIMenu { ///if !(krom_android || krom_ios) if (UIMenu.menu_button(ui, tr("Toggle Fullscreen"), "alt+enter")) { - Base.toggle_fullscreen(); + base_toggle_fullscreen(); } ///end @@ -121,25 +121,25 @@ class UIMenu { UIMenu.menu_fill(ui); let p: world_data_t = scene_world; - let envHandle: zui_handle_t = zui_handle("uimenu_0"); - envHandle.value = p.strength; + let env_handle: zui_handle_t = zui_handle("uimenu_0"); + env_handle.value = p.strength; UIMenu.menu_align(ui); - p.strength = zui_slider(envHandle, tr("Environment"), 0.0, 8.0, true); - if (envHandle.changed) Context.raw.ddirty = 2; + p.strength = zui_slider(env_handle, tr("Environment"), 0.0, 8.0, true); + if (env_handle.changed) Context.raw.ddirty = 2; UIMenu.menu_fill(ui); - let envaHandle: zui_handle_t = zui_handle("uimenu_1"); - envaHandle.value = Context.raw.envmap_angle / Math.PI * 180.0; - if (envaHandle.value < 0) { - envaHandle.value += (Math.floor(-envaHandle.value / 360) + 1) * 360; + let enva_handle: zui_handle_t = zui_handle("uimenu_1"); + enva_handle.value = Context.raw.envmap_angle / Math.PI * 180.0; + if (enva_handle.value < 0) { + enva_handle.value += (Math.floor(-enva_handle.value / 360) + 1) * 360; } - else if (envaHandle.value > 360) { - envaHandle.value -= Math.floor(envaHandle.value / 360) * 360; + else if (enva_handle.value > 360) { + enva_handle.value -= Math.floor(enva_handle.value / 360) * 360; } UIMenu.menu_align(ui); - Context.raw.envmap_angle = zui_slider(envaHandle, tr("Environment Angle"), 0.0, 360.0, true, 1) / 180.0 * Math.PI; + Context.raw.envmap_angle = zui_slider(enva_handle, tr("Environment Angle"), 0.0, 360.0, true, 1) / 180.0 * Math.PI; if (ui.is_hovered) zui_tooltip(tr("{shortcut} and move mouse", new Map([["shortcut", Config.keymap.rotate_envmap]]))); - if (envaHandle.changed) Context.raw.ddirty = 2; + if (enva_handle.changed) Context.raw.ddirty = 2; if (scene_lights.length > 0) { let light: light_object_t = scene_lights[0]; @@ -158,13 +158,13 @@ class UIMenu { let lahandle: zui_handle_t = zui_handle("uimenu_3"); lahandle.value = Context.raw.light_angle / Math.PI * 180; UIMenu.menu_align(ui); - let newAngle: f32 = zui_slider(lahandle, tr("Light Angle"), 0.0, 360.0, true, 1) / 180 * Math.PI; + let new_angle: f32 = zui_slider(lahandle, tr("Light Angle"), 0.0, 360.0, true, 1) / 180 * Math.PI; if (ui.is_hovered) zui_tooltip(tr("{shortcut} and move mouse", new Map([["shortcut", Config.keymap.rotate_light]]))); - let ldiff: f32 = newAngle - Context.raw.light_angle; + let ldiff: f32 = new_angle - Context.raw.light_angle; if (Math.abs(ldiff) > 0.005) { - if (newAngle < 0) newAngle += (Math.floor(-newAngle / (2 * Math.PI)) + 1) * 2 * Math.PI; - else if (newAngle > 2 * Math.PI) newAngle -= Math.floor(newAngle / (2 * Math.PI)) * 2 * Math.PI; - Context.raw.light_angle = newAngle; + if (new_angle < 0) new_angle += (Math.floor(-new_angle / (2 * Math.PI)) + 1) * 2 * Math.PI; + else if (new_angle > 2 * Math.PI) new_angle -= Math.floor(new_angle / (2 * Math.PI)) * 2 * Math.PI; + Context.raw.light_angle = new_angle; let m: mat4_t = mat4_rot_z(ldiff); mat4_mult_mat(light.base.transform.local, m); transform_decompose(light.base.transform); @@ -181,19 +181,19 @@ class UIMenu { ///if (is_paint || is_sculpt) UIMenu.menu_fill(ui); - let splitViewHandle: zui_handle_t = zui_handle("uimenu_5", { selected: Context.raw.split_view }); - Context.raw.split_view = zui_check(splitViewHandle, " " + tr("Split View")); - if (splitViewHandle.changed) { - Base.resize(); + let split_view_handle: zui_handle_t = zui_handle("uimenu_5", { selected: Context.raw.split_view }); + Context.raw.split_view = zui_check(split_view_handle, " " + tr("Split View")); + if (split_view_handle.changed) { + base_resize(); } ///end ///if is_lab UIMenu.menu_fill(ui); - let brushScaleHandle: zui_handle_t = zui_handle("uimenu_6", { value: Context.raw.brush_scale }); + let brush_scale_handle: zui_handle_t = zui_handle("uimenu_6", { value: Context.raw.brush_scale }); UIMenu.menu_align(ui); - Context.raw.brush_scale = zui_slider(brushScaleHandle, tr("UV Scale"), 0.01, 5.0, true); - if (brushScaleHandle.changed) { + Context.raw.brush_scale = zui_slider(brush_scale_handle, tr("UV Scale"), 0.01, 5.0, true); + if (brush_scale_handle.changed) { MakeMaterial.parse_mesh_material(); ///if (krom_direct3d12 || krom_vulkan || krom_metal) RenderPathRaytrace.uv_scale = Context.raw.brush_scale; @@ -203,16 +203,16 @@ class UIMenu { ///end UIMenu.menu_fill(ui); - let cullHandle: zui_handle_t = zui_handle("uimenu_7", { selected: Context.raw.cull_backfaces }); - Context.raw.cull_backfaces = zui_check(cullHandle, " " + tr("Cull Backfaces")); - if (cullHandle.changed) { + let cull_handle: zui_handle_t = zui_handle("uimenu_7", { selected: Context.raw.cull_backfaces }); + Context.raw.cull_backfaces = zui_check(cull_handle, " " + tr("Cull Backfaces")); + if (cull_handle.changed) { MakeMaterial.parse_mesh_material(); } UIMenu.menu_fill(ui); - let filterHandle: zui_handle_t = zui_handle("uimenu_8", { selected: Context.raw.texture_filter }); - Context.raw.texture_filter = zui_check(filterHandle, " " + tr("Filter Textures")); - if (filterHandle.changed) { + let filter_handle: zui_handle_t = zui_handle("uimenu_8", { selected: Context.raw.texture_filter }); + Context.raw.texture_filter = zui_check(filter_handle, " " + tr("Filter Textures")); + if (filter_handle.changed) { MakeMaterial.parse_paint_material(); MakeMaterial.parse_mesh_material(); } @@ -238,9 +238,9 @@ class UIMenu { ///end UIMenu.menu_fill(ui); - let compassHandle: zui_handle_t = zui_handle("uimenu_9", { selected: Context.raw.show_compass }); - Context.raw.show_compass = zui_check(compassHandle, " " + tr("Compass")); - if (compassHandle.changed) Context.raw.ddirty = 2; + let compass_handle: zui_handle_t = zui_handle("uimenu_9", { selected: Context.raw.show_compass }); + Context.raw.show_compass = zui_check(compass_handle, " " + tr("Compass")); + if (compass_handle.changed) Context.raw.ddirty = 2; UIMenu.menu_fill(ui); Context.raw.show_envmap = zui_check(Context.raw.show_envmap_handle, " " + tr("Envmap")); @@ -258,8 +258,8 @@ class UIMenu { if (ui.changed) UIMenu.keep_open = true; } else if (UIMenu.menu_category == menu_category_t.MODE) { - let modeHandle: zui_handle_t = zui_handle("uimenu_10"); - modeHandle.position = Context.raw.viewport_mode; + let mode_handle: zui_handle_t = zui_handle("uimenu_10"); + mode_handle.position = Context.raw.viewport_mode; let modes: string[] = [ tr("Lit"), tr("Base Color"), @@ -295,13 +295,13 @@ class UIMenu { for (let i: i32 = 0; i < modes.length; ++i) { UIMenu.menu_fill(ui); let shortcut: string = Config.raw.touch_ui ? "" : Config.keymap.viewport_mode + ", " + shortcuts[i]; - zui_radio(modeHandle, i, modes[i], shortcut); + zui_radio(mode_handle, i, modes[i], shortcut); } - if (modeHandle.changed) { - Context.set_viewport_mode(modeHandle.position); + if (mode_handle.changed) { + Context.set_viewport_mode(mode_handle.position); // TODO: rotate mode is not supported for path tracing yet - if (modeHandle.position == viewport_mode_t.PATH_TRACE && Context.raw.camera_controls == camera_controls_t.ROTATE) { + if (mode_handle.position == viewport_mode_t.PATH_TRACE && Context.raw.camera_controls == camera_controls_t.ROTATE) { Context.raw.camera_controls = camera_controls_t.ORBIT; Viewport.reset(); } @@ -369,19 +369,19 @@ class UIMenu { UIMenu.menu_fill(ui); UIMenu.menu_align(ui); - let cameraControlsHandle: zui_handle_t = zui_handle("uimenu_12"); - cameraControlsHandle.position = Context.raw.camera_controls; - Context.raw.camera_controls = zui_inline_radio(cameraControlsHandle, [tr("Orbit"), tr("Rotate"), tr("Fly")], zui_align_t.LEFT); + let camera_controls_handle: zui_handle_t = zui_handle("uimenu_12"); + camera_controls_handle.position = Context.raw.camera_controls; + Context.raw.camera_controls = zui_inline_radio(camera_controls_handle, [tr("Orbit"), tr("Rotate"), tr("Fly")], zui_align_t.LEFT); - let orbitAndRotateTooltip: string = tr("Orbit and Rotate mode:\n{rotate_shortcut} or move right mouse button to rotate.\n{zoom_shortcut} or scroll to zoom.\n{pan_shortcut} or move middle mouse to pan.", + let orbit_and_rotate_tooltip: string = tr("Orbit and Rotate mode:\n{rotate_shortcut} or move right mouse button to rotate.\n{zoom_shortcut} or scroll to zoom.\n{pan_shortcut} or move middle mouse to pan.", new Map([ ["rotate_shortcut", Config.keymap.action_rotate], ["zoom_shortcut", Config.keymap.action_zoom], ["pan_shortcut", Config.keymap.action_pan] ]) ); - let flyTooltip: string = tr("Fly mode:\nHold the right mouse button and one of the following commands:\nmove mouse to rotate.\nw, up or scroll up to move forward.\ns, down or scroll down to move backward.\na or left to move left.\nd or right to move right.\ne to move up.\nq to move down.\nHold shift to move faster or alt to move slower."); - if (ui.is_hovered) zui_tooltip(orbitAndRotateTooltip + "\n\n" + flyTooltip); + let fly_tooltip: string = tr("Fly mode:\nHold the right mouse button and one of the following commands:\nmove mouse to rotate.\nw, up or scroll up to move forward.\ns, down or scroll down to move backward.\na or left to move left.\nd or right to move right.\ne to move up.\nq to move down.\nHold shift to move faster or alt to move slower."); + if (ui.is_hovered) zui_tooltip(orbit_and_rotate_tooltip + "\n\n" + fly_tooltip); UIMenu.menu_fill(ui); UIMenu.menu_align(ui); @@ -433,11 +433,11 @@ class UIMenu { if (buffer != null) { // Compare versions let update: any = json_parse(sys_buffer_to_string(buffer)); - let updateVersion: i32 = Math.floor(update.version); - if (updateVersion > 0) { + let update_version: i32 = Math.floor(update.version); + if (update_version > 0) { let date: string = Config.get_date().substr(2); // 2019 -> 19 - let dateInt: i32 = parseInt(string_replace_all(date, "-", "")); - if (updateVersion > dateInt) { + let date_int: i32 = parseInt(string_replace_all(date, "-", "")); + if (update_version > date_int) { UIBox.show_message(tr("Update"), tr("Update is available!\nPlease visit {url}.", new Map([["url", manifest_url]]))); } else { @@ -462,13 +462,13 @@ class UIMenu { krom_sys_command('wmic path win32_VideoController get name > "' + save + '"'); let blob: buffer_t = krom_load_blob(save); let u8: Uint8Array = new Uint8Array(blob); - let gpuRaw: string = ""; + let gpu_raw: string = ""; for (let i: i32 = 0; i < Math.floor(u8.length / 2); ++i) { let c: string = String.fromCharCode(u8[i * 2]); - gpuRaw += c; + gpu_raw += c; } - let gpus: string[] = gpuRaw.split("\n"); + let gpus: string[] = gpu_raw.split("\n"); gpus = gpus.splice(1, gpus.length - 2); let gpu: string = ""; for (let g of gpus) { @@ -481,8 +481,8 @@ class UIMenu { ///end UIBox.show_custom((ui: zui_t) => { - let tabVertical: bool = Config.raw.touch_ui; - if (zui_tab(zui_handle("uimenu_13"), tr("About"), tabVertical)) { + let tab_vertical: bool = Config.raw.touch_ui; + if (zui_tab(zui_handle("uimenu_13"), tr("About"), tab_vertical)) { let img: image_t = data_get_image("badge.k"); zui_image(img); @@ -530,7 +530,7 @@ class UIMenu { static hide = () => { UIMenu.show = false; - Base.redraw_ui(); + base_redraw_ui(); } static draw = (commands: (ui: zui_t)=>void = null, elements: i32, x: i32 = -1, y: i32 = -1) => { @@ -545,22 +545,22 @@ class UIMenu { static fit_to_screen = () => { // Prevent the menu going out of screen - let menuW: f32 = Base.default_element_w * zui_SCALE(Base.ui_menu) * 2.3; - if (UIMenu.menu_x + menuW > sys_width()) { - if (UIMenu.menu_x - menuW > 0) { - UIMenu.menu_x = Math.floor(UIMenu.menu_x - menuW); + let menu_w: f32 = base_default_element_w * zui_SCALE(base_ui_menu) * 2.3; + if (UIMenu.menu_x + menu_w > sys_width()) { + if (UIMenu.menu_x - menu_w > 0) { + UIMenu.menu_x = Math.floor(UIMenu.menu_x - menu_w); } else { - UIMenu.menu_x = Math.floor(sys_width() - menuW); + UIMenu.menu_x = Math.floor(sys_width() - menu_w); } } - let menuH: f32 = Math.floor(UIMenu.menu_elements * 30 * zui_SCALE(Base.ui_menu)); // ui.t.ELEMENT_H - if (UIMenu.menu_y + menuH > sys_height()) { - if (UIMenu.menu_y - menuH > 0) { - UIMenu.menu_y = Math.floor(UIMenu.menu_y - menuH); + let menu_h: f32 = Math.floor(UIMenu.menu_elements * 30 * zui_SCALE(base_ui_menu)); // ui.t.ELEMENT_H + if (UIMenu.menu_y + menu_h > sys_height()) { + if (UIMenu.menu_y - menu_h > 0) { + UIMenu.menu_y = Math.floor(UIMenu.menu_y - menu_h); } else { - UIMenu.menu_y = sys_height() - menuH; + UIMenu.menu_y = sys_height() - menu_h; } UIMenu.menu_x += 1; // Move out of mouse focus } diff --git a/base/Sources/UIMenubar.ts b/base/Sources/UIMenubar.ts index 3d6c0dd2..24282897 100644 --- a/base/Sources/UIMenubar.ts +++ b/base/Sources/UIMenubar.ts @@ -44,7 +44,7 @@ class UIMenubar { Console.toast(tr("Saving project")); Project.project_save(); ///end - Base.notify_on_next_frame(() => { + base_notify_on_next_frame(() => { BoxProjects.show(); }); } @@ -137,8 +137,8 @@ class UIMenubar { scale_tex: mesh.scaleTex }; let md: mesh_data_t = mesh_data_create(raw); - let dotPlane: mesh_object_t = scene_get_child(".Plane").ext; - UIMenubar._plane = mesh_object_create(md, dotPlane.materials); + let dot_plane: mesh_object_t = scene_get_child(".Plane").ext; + UIMenubar._plane = mesh_object_create(md, dot_plane.materials); array_remove(scene_meshes, UIMenubar._plane); } @@ -167,10 +167,10 @@ class UIMenubar { UIMenu.menu_x = Math.floor(ui._x - ui._w); UIMenu.menu_y = Math.floor(zui_MENUBAR_H(ui)); if (Config.raw.touch_ui) { - let menuW: i32 = Math.floor(Base.default_element_w * zui_SCALE(Base.ui_menu) * 2.0); + let menuW: i32 = Math.floor(base_default_element_w * zui_SCALE(base_ui_menu) * 2.0); UIMenu.menu_x -= Math.floor((menuW - ui._w) / 2) + Math.floor(UIHeader.headerh / 2); - UIMenu.menu_x += Math.floor(2 * zui_SCALE(Base.ui_menu)); - UIMenu.menu_y -= Math.floor(2 * zui_SCALE(Base.ui_menu)); + UIMenu.menu_x += Math.floor(2 * zui_SCALE(base_ui_menu)); + UIMenu.menu_y -= Math.floor(2 * zui_SCALE(base_ui_menu)); UIMenu.keep_open = true; } } @@ -179,9 +179,9 @@ class UIMenubar { let col: i32 = ui.t.WINDOW_BG_COL; if (col < 0) col += 4294967296; let light: bool = col > (0xff666666 + 4294967296); - let iconAccent: i32 = light ? 0xff666666 : 0xffaaaaaa; + let icon_accent: i32 = light ? 0xff666666 : 0xffaaaaaa; let img: image_t = Res.get("icons.k"); let rect: rect_t = Res.tile50(img, i, j); - return zui_image(img, iconAccent, -1.0, rect.x, rect.y, rect.w, rect.h) == zui_state_t.RELEASED; + return zui_image(img, icon_accent, -1.0, rect.x, rect.y, rect.w, rect.h) == zui_state_t.RELEASED; } } diff --git a/base/Sources/UINodes.ts b/base/Sources/UINodes.ts index 5cddfe80..1be2a7d2 100644 --- a/base/Sources/UINodes.ts +++ b/base/Sources/UINodes.ts @@ -44,45 +44,45 @@ class UINodes { zui_set_on_canvas_control(UINodes.on_canvas_control); let scale: f32 = Config.raw.window_scale; - UINodes.ui = zui_create({ theme: Base.theme, font: Base.font, color_wheel: Base.color_wheel, black_white_gradient: Base.color_wheel_gradient, scale_factor: scale }); + UINodes.ui = zui_create({ theme: base_theme, font: base_font, color_wheel: base_color_wheel, black_white_gradient: base_color_wheel_gradient, scale_factor: scale }); UINodes.ui.scroll_enabled = false; } static on_link_drag = (linkDragId: i32, isNewLink: bool) => { if (isNewLink) { let nodes: zui_nodes_t = UINodes.get_nodes(); - let linkDrag: zui_node_link_t = zui_get_link(UINodes.get_canvas(true).links, linkDragId); - let node: zui_node_t = zui_get_node(UINodes.get_canvas(true).nodes, linkDrag.from_id > -1 ? linkDrag.from_id : linkDrag.to_id); - let linkX: i32 = UINodes.ui._window_x + zui_nodes_NODE_X(node); - let linkY: i32 = UINodes.ui._window_y + zui_nodes_NODE_Y(node); - if (linkDrag.from_id > -1) { - linkX += zui_nodes_NODE_W(node); - linkY += zui_nodes_OUTPUT_Y(node.outputs, linkDrag.from_socket); + let link_drag: zui_node_link_t = zui_get_link(UINodes.get_canvas(true).links, linkDragId); + let node: zui_node_t = zui_get_node(UINodes.get_canvas(true).nodes, link_drag.from_id > -1 ? link_drag.from_id : link_drag.to_id); + let link_x: i32 = UINodes.ui._window_x + zui_nodes_NODE_X(node); + let link_y: i32 = UINodes.ui._window_y + zui_nodes_NODE_Y(node); + if (link_drag.from_id > -1) { + link_x += zui_nodes_NODE_W(node); + link_y += zui_nodes_OUTPUT_Y(node.outputs, link_drag.from_socket); } else { - linkY += zui_nodes_INPUT_Y(UINodes.get_canvas(true), node.inputs, linkDrag.to_socket) + zui_nodes_OUTPUTS_H(node.outputs) + zui_nodes_BUTTONS_H(node); + link_y += zui_nodes_INPUT_Y(UINodes.get_canvas(true), node.inputs, link_drag.to_socket) + zui_nodes_OUTPUTS_H(node.outputs) + zui_nodes_BUTTONS_H(node); } - if (Math.abs(mouse_x - linkX) > 5 || Math.abs(mouse_y - linkY) > 5) { // Link length + if (Math.abs(mouse_x - link_x) > 5 || Math.abs(mouse_y - link_y) > 5) { // Link length UINodes.node_search(-1, -1, () => { - let n: zui_node_t = zui_get_node(UINodes.get_canvas(true).nodes, nodes.nodesSelectedId[0]); - if (linkDrag.to_id == -1 && n.inputs.length > 0) { - linkDrag.to_id = n.id; - let fromType: string = node.outputs[linkDrag.from_socket].type; + let n: zui_node_t = zui_get_node(UINodes.get_canvas(true).nodes, nodes.nodes_selected_id[0]); + if (link_drag.to_id == -1 && n.inputs.length > 0) { + link_drag.to_id = n.id; + let from_type: string = node.outputs[link_drag.from_socket].type; // Connect to the first socket - linkDrag.to_socket = 0; + link_drag.to_socket = 0; // Try to find the first type-matching socket and use it if present for (let socket of n.inputs) { - if (socket.type == fromType) { - linkDrag.to_socket = n.inputs.indexOf(socket); + if (socket.type == from_type) { + link_drag.to_socket = n.inputs.indexOf(socket); break; } } - UINodes.get_canvas(true).links.push(linkDrag); + UINodes.get_canvas(true).links.push(link_drag); } - else if (linkDrag.from_id == -1 && n.outputs.length > 0) { - linkDrag.from_id = n.id; - linkDrag.from_socket = 0; - UINodes.get_canvas(true).links.push(linkDrag); + else if (link_drag.from_id == -1 && n.outputs.length > 0) { + link_drag.from_id = n.id; + link_drag.from_socket = 0; + UINodes.get_canvas(true).links.push(link_drag); } ///if is_lab ParserLogic.parse(UINodes.get_canvas(true)); @@ -91,8 +91,8 @@ class UINodes { }); } // Selecting which node socket to preview - else if (node.id == nodes.nodesSelectedId[0]) { - Context.raw.node_preview_socket = linkDrag.from_id > -1 ? linkDrag.from_socket : 0; + else if (node.id == nodes.nodes_selected_id[0]) { + Context.raw.node_preview_socket = link_drag.from_id > -1 ? link_drag.from_socket : 0; ///if (is_paint || is_sculpt) Context.raw.node_preview_dirty = true; ///end @@ -107,7 +107,7 @@ class UINodes { let node: zui_node_t = zui_get_node(canvas.nodes, socket.node_id); if (UINodes.ui.input_released_r) { if (node.type == "GROUP_INPUT" || node.type == "GROUP_OUTPUT") { - Base.notify_on_next_frame(() => { + base_notify_on_next_frame(() => { UIMenu.draw((ui: zui_t) => { if (UIMenu.menu_button(ui, tr("Edit"))) { let htype: zui_handle_t = zui_handle("uinodes_0"); @@ -131,7 +131,7 @@ class UINodes { } } else hval0.value = socket.default_value; - Base.notify_on_next_frame(() => { + base_notify_on_next_frame(() => { zui_end_input(); UIBox.show_custom((ui: zui_t) => { if (zui_tab(zui_handle("uinodes_8"), tr("Socket"))) { @@ -196,7 +196,7 @@ class UINodes { else UINodes.on_canvas_released(); } // Selecting which node socket to preview - else if (node.id == nodes.nodesSelectedId[0]) { + else if (node.id == nodes.nodes_selected_id[0]) { let i: i32 = node.outputs.indexOf(socket); if (i > -1) { Context.raw.node_preview_socket = i; @@ -219,27 +219,27 @@ class UINodes { break; } } - if (selected == null) nodes.nodesSelectedId = []; - else if (nodes.nodesSelectedId.indexOf(selected.id) == -1) nodes.nodesSelectedId = [selected.id]; + if (selected == null) nodes.nodes_selected_id = []; + else if (nodes.nodes_selected_id.indexOf(selected.id) == -1) nodes.nodes_selected_id = [selected.id]; // Node context menu if (!zui_socket_released()) { - let numberOfEntries: i32 = 5; - if (UINodes.canvas_type == canvas_type_t.MATERIAL) ++numberOfEntries; - if (selected != null && selected.type == "RGB") ++numberOfEntries; + let number_of_entries: i32 = 5; + if (UINodes.canvas_type == canvas_type_t.MATERIAL) ++number_of_entries; + if (selected != null && selected.type == "RGB") ++number_of_entries; UIMenu.draw((uiMenu: zui_t) => { uiMenu._y += 1; - let isProtected: bool = selected == null || + let is_protected: bool = selected == null || ///if (is_paint || is_sculpt) selected.type == "OUTPUT_MATERIAL_PBR" || ///end selected.type == "GROUP_INPUT" || selected.type == "GROUP_OUTPUT" || selected.type == "BrushOutputNode"; - uiMenu.enabled = !isProtected; + uiMenu.enabled = !is_protected; if (UIMenu.menu_button(uiMenu, tr("Cut"), "ctrl+x")) { - Base.notify_on_next_frame(() => { + base_notify_on_next_frame(() => { UINodes.hwnd.redraws = 2; zui_set_is_copy(true); zui_set_is_cut(true); @@ -247,29 +247,29 @@ class UINodes { }); } if (UIMenu.menu_button(uiMenu, tr("Copy"), "ctrl+c")) { - Base.notify_on_next_frame(() => { + base_notify_on_next_frame(() => { zui_set_is_copy(true); UINodes.is_node_menu_op = true; }); } uiMenu.enabled = zui_clipboard != ""; if (UIMenu.menu_button(uiMenu, tr("Paste"), "ctrl+v")) { - Base.notify_on_next_frame(() => { + base_notify_on_next_frame(() => { UINodes.hwnd.redraws = 2; zui_set_is_paste(true); UINodes.is_node_menu_op = true; }); } - uiMenu.enabled = !isProtected; + uiMenu.enabled = !is_protected; if (UIMenu.menu_button(uiMenu, tr("Delete"), "delete")) { - Base.notify_on_next_frame(() => { + base_notify_on_next_frame(() => { UINodes.hwnd.redraws = 2; UINodes.ui.is_delete_down = true; UINodes.is_node_menu_op = true; }); } if (UIMenu.menu_button(uiMenu, tr("Duplicate"))) { - Base.notify_on_next_frame(() => { + base_notify_on_next_frame(() => { UINodes.hwnd.redraws = 2; zui_set_is_copy(true); zui_set_is_paste(true); @@ -279,9 +279,9 @@ class UINodes { if (selected != null && selected.type == "RGB") { if (UIMenu.menu_button(uiMenu, tr("Add Swatch"))) { let color: any = selected.outputs[0].default_value; - let newSwatch: swatch_color_t = Project.make_swatch(color_from_floats(color[0], color[1], color[2], color[3])); - Context.set_swatch(newSwatch); - Project.raw.swatches.push(newSwatch); + let new_swatch: swatch_color_t = Project.make_swatch(color_from_floats(color[0], color[1], color[2], color[3])); + Context.set_swatch(new_swatch); + Project.raw.swatches.push(new_swatch); UIBase.hwnds[tab_area_t.STATUS].redraws = 1; } } @@ -294,7 +294,7 @@ class UINodes { } uiMenu.enabled = true; - }, numberOfEntries); + }, number_of_entries); } } @@ -303,7 +303,7 @@ class UINodes { let canvas: zui_node_canvas_t = UINodes.get_canvas(true); for (let node of canvas.nodes) { if (zui_get_input_in_rect(UINodes.ui._window_x + zui_nodes_NODE_X(node), UINodes.ui._window_y + zui_nodes_NODE_Y(node), zui_nodes_NODE_W(node), zui_nodes_NODE_H(canvas, node))) { - if (node.id == nodes.nodesSelectedId[0]) { + if (node.id == nodes.nodes_selected_id[0]) { UIView2D.hwnd.redraws = 2; if (time_time() - Context.raw.select_time < 0.25) UIBase.show_2d_view(view_2d_type_t.NODE); Context.raw.select_time = time_time(); @@ -359,13 +359,13 @@ class UINodes { } let pan: bool = ui.input_down_r || Operator.shortcut(Config.keymap.action_pan, ShortcutType.ShortcutDown); - let zoomDelta: f32 = Operator.shortcut(Config.keymap.action_zoom, ShortcutType.ShortcutDown) ? UINodes.get_zoom_delta(ui) / 100.0 : 0.0; + let zoom_delta: f32 = Operator.shortcut(Config.keymap.action_zoom, ShortcutType.ShortcutDown) ? UINodes.get_zoom_delta(ui) / 100.0 : 0.0; let control: any = { pan_x: pan ? ui.input_dx : 0.0, pan_y: pan ? ui.input_dy : 0.0, - zoom: ui.input_wheel_delta != 0.0 ? -ui.input_wheel_delta / 10 : zoomDelta + zoom: ui.input_wheel_delta != 0.0 ? -ui.input_wheel_delta / 10 : zoom_delta }; - if (Base.is_combo_selected()) control.zoom = 0.0; + if (base_is_combo_selected()) control.zoom = 0.0; return control; } @@ -413,7 +413,7 @@ class UINodes { } static update = () => { - if (!UINodes.show || !Base.ui_enabled) return; + if (!UINodes.show || !base_ui_enabled) return; ///if (is_paint || is_sculpt) UINodes.wx = Math.floor(app_w()) + UIToolbar.toolbar_w; @@ -442,11 +442,11 @@ class UINodes { if (UINodes.ui.is_typing || !UINodes.ui.input_enabled) return; let nodes: zui_nodes_t = UINodes.get_nodes(); - if (nodes.nodesSelectedId.length > 0 && UINodes.ui.is_key_pressed) { - if (UINodes.ui.key == key_code_t.LEFT) for (let n of nodes.nodesSelectedId) zui_get_node(UINodes.get_canvas(true).nodes, n).x -= 1; - else if (UINodes.ui.key == key_code_t.RIGHT) for (let n of nodes.nodesSelectedId) zui_get_node(UINodes.get_canvas(true).nodes, n).x += 1; - if (UINodes.ui.key == key_code_t.UP) for (let n of nodes.nodesSelectedId) zui_get_node(UINodes.get_canvas(true).nodes, n).y -= 1; - else if (UINodes.ui.key == key_code_t.DOWN) for (let n of nodes.nodesSelectedId) zui_get_node(UINodes.get_canvas(true).nodes, n).y += 1; + if (nodes.nodes_selected_id.length > 0 && UINodes.ui.is_key_pressed) { + if (UINodes.ui.key == key_code_t.LEFT) for (let n of nodes.nodes_selected_id) zui_get_node(UINodes.get_canvas(true).nodes, n).x -= 1; + else if (UINodes.ui.key == key_code_t.RIGHT) for (let n of nodes.nodes_selected_id) zui_get_node(UINodes.get_canvas(true).nodes, n).x += 1; + if (UINodes.ui.key == key_code_t.UP) for (let n of nodes.nodes_selected_id) zui_get_node(UINodes.get_canvas(true).nodes, n).y -= 1; + else if (UINodes.ui.key == key_code_t.DOWN) for (let n of nodes.nodes_selected_id) zui_get_node(UINodes.get_canvas(true).nodes, n).y += 1; } // Node search popup @@ -470,22 +470,22 @@ class UINodes { } static node_search = (x: i32 = -1, y: i32 = -1, done: ()=>void = null) => { - let searchHandle: zui_handle_t = zui_handle("uinodes_9"); + let search_handle: zui_handle_t = zui_handle("uinodes_9"); let first: bool = true; UIMenu.draw((ui: zui_t) => { g2_set_color(ui.t.SEPARATOR_COL); zui_draw_rect(true, ui._x, ui._y, ui._w, zui_ELEMENT_H(ui) * 8); g2_set_color(0xffffffff); - let search: string = zui_text_input(searchHandle, "", zui_align_t.LEFT, true, true).toLowerCase(); + let search: string = zui_text_input(search_handle, "", zui_align_t.LEFT, true, true).toLowerCase(); ui.changed = false; if (first) { first = false; - searchHandle.text = ""; - zui_start_text_edit(searchHandle); // Focus search bar + search_handle.text = ""; + zui_start_text_edit(search_handle); // Focus search bar } - if (searchHandle.changed) UINodes.node_search_offset = 0; + if (search_handle.changed) UINodes.node_search_offset = 0; if (ui.is_key_pressed) { // Move selection if (ui.key == key_code_t.DOWN && UINodes.node_search_offset < 6) UINodes.node_search_offset++; @@ -496,13 +496,13 @@ class UINodes { let BUTTON_COL: i32 = ui.t.BUTTON_COL; ///if (is_paint || is_sculpt) - let nodeList: zui_node_t[][] = UINodes.canvas_type == canvas_type_t.MATERIAL ? NodesMaterial.list : NodesBrush.list; + let node_list: zui_node_t[][] = UINodes.canvas_type == canvas_type_t.MATERIAL ? NodesMaterial.list : NodesBrush.list; ///end ///if is_lab - let nodeList: zui_node_t[][] = NodesBrush.list; + let node_list: zui_node_t[][] = NodesBrush.list; ///end - for (let list of nodeList) { + for (let list of node_list) { for (let n of list) { if (tr(n.name).toLowerCase().indexOf(search) >= 0) { ui.t.BUTTON_COL = count == UINodes.node_search_offset ? ui.t.HIGHLIGHT_COL : ui.t.SEPARATOR_COL; @@ -512,7 +512,7 @@ class UINodes { let canvas: zui_node_canvas_t = UINodes.get_canvas(true); UINodes.node_search_spawn = UINodes.make_node(n, nodes, canvas); // Spawn selected node canvas.nodes.push(UINodes.node_search_spawn); - nodes.nodesSelectedId = [UINodes.node_search_spawn.id]; + nodes.nodes_selected_id = [UINodes.node_search_spawn.id]; nodes.nodesDrag = true; ///if is_lab @@ -533,7 +533,7 @@ class UINodes { } if (enter && count == 0) { // Hide popup on enter when node is not found ui.changed = true; - searchHandle.text = ""; + search_handle.text = ""; } ui.t.BUTTON_COL = BUTTON_COL; }, 8, x, y); @@ -596,7 +596,7 @@ class UINodes { UIBase.hwnds[tab_area_t.SIDEBAR1].redraws = 2; } else { - Base.is_fill_material() ? Base.update_fill_layers() : UtilRender.make_material_preview(); + base_is_fill_material() ? base_update_fill_layers() : UtilRender.make_material_preview(); if (UIView2D.show && UIView2D.type == view_2d_type_t.NODE) { UIView2D.hwnd.redraws = 2; } @@ -616,8 +616,8 @@ class UINodes { ///if (is_paint || is_sculpt) MakeMaterial.parse_paint_material(); - if (UINodes.canvas_type == canvas_type_t.MATERIAL && Base.is_fill_material()) { - Base.update_fill_layers(); + if (UINodes.canvas_type == canvas_type_t.MATERIAL && base_is_fill_material()) { + base_update_fill_layers(); UtilRender.make_material_preview(); } @@ -632,8 +632,8 @@ class UINodes { } let nodes: zui_nodes_t = UINodes.get_nodes(); - if (nodes.nodesSelectedId.length > 0 && nodes.nodesSelectedId[0] != UINodes.last_node_selected_id) { - UINodes.last_node_selected_id = nodes.nodesSelectedId[0]; + if (nodes.nodes_selected_id.length > 0 && nodes.nodes_selected_id[0] != UINodes.last_node_selected_id) { + UINodes.last_node_selected_id = nodes.nodes_selected_id[0]; ///if (is_paint || is_sculpt) Context.raw.node_preview_dirty = true; ///end @@ -656,7 +656,7 @@ class UINodes { if (!UINodes.show || sys_width() == 0 || sys_height() == 0) return; - UINodes.ui.input_enabled = Base.ui_enabled; + UINodes.ui.input_enabled = base_ui_enabled; g2_end(); @@ -718,15 +718,15 @@ class UINodes { } // Nodes - let _inputEnabled: bool = UINodes.ui.input_enabled; - UINodes.ui.input_enabled = _inputEnabled && !UINodes.show_menu; + let _input_enabled: bool = UINodes.ui.input_enabled; + UINodes.ui.input_enabled = _input_enabled && !UINodes.show_menu; ///if (is_paint || is_sculpt) UINodes.ui.window_border_right = Config.raw.layout[layout_size_t.SIDEBAR_W]; ///end UINodes.ui.window_border_top = UIHeader.headerh * 2; UINodes.ui.window_border_bottom = Config.raw.layout[layout_size_t.STATUS_H]; zui_node_canvas(nodes, UINodes.ui, c); - UINodes.ui.input_enabled = _inputEnabled; + UINodes.ui.input_enabled = _input_enabled; if (nodes.colorPickerCallback != null) { Context.raw.color_picker_previous_tool = Context.raw.tool; @@ -753,34 +753,34 @@ class UINodes { // Remove nodes with unknown id for this canvas type if (zui_is_paste) { ///if (is_paint || is_sculpt) - let nodeList: zui_node_t[][] = UINodes.canvas_type == canvas_type_t.MATERIAL ? NodesMaterial.list : NodesBrush.list; + let node_list: zui_node_t[][] = UINodes.canvas_type == canvas_type_t.MATERIAL ? NodesMaterial.list : NodesBrush.list; ///end ///if is_lab - let nodeList: zui_node_t[][] = NodesBrush.list; + let node_list: zui_node_t[][] = NodesBrush.list; ///end let i: i32 = 0; while (i++ < c.nodes.length) { - let canvasNode: zui_node_t = c.nodes[i - 1]; - if (zui_exclude_remove.indexOf(canvasNode.type) >= 0) { + let canvas_node: zui_node_t = c.nodes[i - 1]; + if (zui_exclude_remove.indexOf(canvas_node.type) >= 0) { continue; } let found: bool = false; - for (let list of nodeList) { - for (let listNode of list) { - if (canvasNode.type == listNode.type) { + for (let list of node_list) { + for (let list_node of list) { + if (canvas_node.type == list_node.type) { found = true; break; } } if (found) break; } - if (canvasNode.type == "GROUP" && !UINodes.can_place_group(canvasNode.name)) { + if (canvas_node.type == "GROUP" && !UINodes.can_place_group(canvas_node.name)) { found = false; } if (!found) { - zui_remove_node(canvasNode, c); - array_remove(nodes.nodesSelectedId, canvasNode.id); + zui_remove_node(canvas_node, c); + array_remove(nodes.nodes_selected_id, canvas_node.id); i--; } } @@ -809,13 +809,13 @@ class UINodes { UINodes.uichanged_last = UINodes.ui.changed; // Node previews - if (Config.raw.node_preview && nodes.nodesSelectedId.length > 0) { + if (Config.raw.node_preview && nodes.nodes_selected_id.length > 0) { let img: image_t = null; - let sel: zui_node_t = zui_get_node(c.nodes, nodes.nodesSelectedId[0]); + let sel: zui_node_t = zui_get_node(c.nodes, nodes.nodes_selected_id[0]); ///if (is_paint || is_sculpt) - let singleChannel: bool = sel.type == "LAYER_MASK"; + let single_channel: bool = sel.type == "LAYER_MASK"; if (sel.type == "LAYER" || sel.type == "LAYER_MASK") { let id: any = sel.buttons[0].default_value; if (id < Project.layers.length) { @@ -842,9 +842,9 @@ class UINodes { ///else - let brushNode: LogicNode = ParserLogic.get_logic_node(sel); - if (brushNode != null) { - img = brushNode.get_cached_image(); + let brush_node: LogicNode = ParserLogic.get_logic_node(sel); + if (brush_node != null) { + img = brush_node.get_cached_image(); } ///end @@ -856,13 +856,13 @@ class UINodes { let ty: f32 = UINodes.wh - th - 8 * zui_SCALE(UINodes.ui); ///if krom_opengl - let invertY: bool = sel.type == "MATERIAL"; + let invert_y: bool = sel.type == "MATERIAL"; ///else - let invertY: bool = false; + let invert_y: bool = false; ///end ///if (is_paint || is_sculpt) - if (singleChannel) { + if (single_channel) { g2_set_pipeline(UIView2D.pipe); ///if krom_opengl krom_g4_set_pipeline(UIView2D.pipe.pipeline_); @@ -872,12 +872,12 @@ class UINodes { ///end g2_set_color(0xffffffff); - invertY ? + invert_y ? g2_draw_scaled_image(img, tx, ty + th, tw, -th) : g2_draw_scaled_image(img, tx, ty, tw, th); ///if (is_paint || is_sculpt) - if (singleChannel) { + if (single_channel) { g2_set_pipeline(null); } ///end @@ -889,9 +889,9 @@ class UINodes { g2_fill_rect(0, zui_ELEMENT_H(UINodes.ui), UINodes.ww, zui_ELEMENT_H(UINodes.ui) + zui_ELEMENT_OFFSET(UINodes.ui) * 2); g2_set_color(0xffffffff); - let startY: i32 = zui_ELEMENT_H(UINodes.ui) + zui_ELEMENT_OFFSET(UINodes.ui); + let start_y: i32 = zui_ELEMENT_H(UINodes.ui) + zui_ELEMENT_OFFSET(UINodes.ui); UINodes.ui._x = 0; - UINodes.ui._y = 2 + startY; + UINodes.ui._y = 2 + start_y; UINodes.ui._w = ew; ///if (is_paint || is_sculpt) @@ -899,27 +899,27 @@ class UINodes { let h: zui_handle_t = zui_handle("uinodes_11"); h.text = c.name; UINodes.ui._w = Math.floor(Math.min(g2_font_width(UINodes.ui.font, UINodes.ui.font_size, h.text) + 15 * zui_SCALE(UINodes.ui), 100 * zui_SCALE(UINodes.ui))); - let newName: string = zui_text_input(h, ""); + let new_name: string = zui_text_input(h, ""); UINodes.ui._x += UINodes.ui._w + 3; - UINodes.ui._y = 2 + startY; + UINodes.ui._y = 2 + start_y; UINodes.ui._w = ew; if (h.changed) { // Check whether renaming is possible and update group links if (UINodes.group_stack.length > 0) { - let canRename: bool = true; + let can_rename: bool = true; for (let m of Project.material_groups) { - if (m.canvas.name == newName) canRename = false; // Name already used + if (m.canvas.name == new_name) can_rename = false; // Name already used } - if (canRename) { - let oldName: string = c.name; - c.name = newName; + if (can_rename) { + let old_name: string = c.name; + c.name = new_name; let canvases: zui_node_canvas_t[] = []; for (let m of Project.materials) canvases.push(m.canvas); for (let m of Project.material_groups) canvases.push(m.canvas); for (let canvas of canvases) { for (let n of canvas.nodes) { - if (n.type == "GROUP" && n.name == oldName) { + if (n.type == "GROUP" && n.name == old_name) { n.name = c.name; } } @@ -927,14 +927,14 @@ class UINodes { } } else { - c.name = newName; + c.name = new_name; } } ///end ///if is_lab UINodes.ui.window_border_top = 0; - UINodesExt.drawButtons(ew, startY); + UINodesExt.drawButtons(ew, start_y); ///end let _BUTTON_COL: i32 = UINodes.ui.t.BUTTON_COL; @@ -963,13 +963,13 @@ class UINodes { UIMenu.menu_category_h = Math.floor(zui_MENUBAR_H(UINodes.ui)); } UINodes.ui._x += UINodes.ui._w + 3; - UINodes.ui._y = 2 + startY; + UINodes.ui._y = 2 + start_y; } if (Config.raw.touch_ui) { let _w: i32 = UINodes.ui._w; UINodes.ui._w = Math.floor(36 * zui_SCALE(UINodes.ui)); - UINodes.ui._y = 4 * zui_SCALE(UINodes.ui) + startY; + UINodes.ui._y = 4 * zui_SCALE(UINodes.ui) + start_y; if (UIMenubar.icon_button(UINodes.ui, 2, 3)) { UINodes.node_search(Math.floor(UINodes.ui._window_x + UINodes.ui._x), Math.floor(UINodes.ui._window_y + UINodes.ui._y)); } @@ -984,7 +984,7 @@ class UINodes { zui_tooltip(tr("Search for nodes") + ` (${Config.keymap.node_search})`); } UINodes.ui._x += UINodes.ui._w + 3; - UINodes.ui._y = 2 + startY; + UINodes.ui._y = 2 + start_y; UINodes.ui.t.BUTTON_COL = _BUTTON_COL; @@ -1006,16 +1006,16 @@ class UINodes { let list:zui_node_t[][] = NodesBrush.list; ///end - let numNodes: i32 = list[UINodes.menu_category].length; + let num_nodes: i32 = list[UINodes.menu_category].length; ///if (is_paint || is_sculpt) - let isGroupCategory: bool = UINodes.canvas_type == canvas_type_t.MATERIAL && NodesMaterial.categories[UINodes.menu_category] == "Group"; + let is_group_category: bool = UINodes.canvas_type == canvas_type_t.MATERIAL && NodesMaterial.categories[UINodes.menu_category] == "Group"; ///end ///if is_lab - let isGroupCategory: bool = NodesMaterial.categories[UINodes.menu_category] == "Group"; + let is_group_category: bool = NodesMaterial.categories[UINodes.menu_category] == "Group"; ///end - if (isGroupCategory) numNodes += Project.material_groups.length; + if (is_group_category) num_nodes += Project.material_groups.length; let py: i32 = UINodes.popup_y; let menuw: i32 = Math.floor(ew * 2.3); @@ -1036,7 +1036,7 @@ class UINodes { let nodes: zui_nodes_t = UINodes.get_nodes(); let node: zui_node_t = UINodes.make_node(n, nodes, canvas); canvas.nodes.push(node); - nodes.nodesSelectedId = [node.id]; + nodes.nodes_selected_id = [node.id]; nodes.nodesDrag = true; ///if is_lab ParserLogic.parse(canvas); @@ -1048,7 +1048,7 @@ class UINodes { UINodes.ui._y = py; } } - if (isGroupCategory) { + if (is_group_category) { for (let g of Project.material_groups) { zui_fill(0, 1, UINodes.ui._w / zui_SCALE(UINodes.ui), UINodes.ui.t.BUTTON_H + 2, UINodes.ui.t.ACCENT_SELECT_COL); zui_fill(1, 1, UINodes.ui._w / zui_SCALE(UINodes.ui) - 2, UINodes.ui.t.BUTTON_H + 1, UINodes.ui.t.SEPARATOR_COL); @@ -1061,7 +1061,7 @@ class UINodes { let nodes: zui_nodes_t = UINodes.get_nodes(); let node: zui_node_t = UINodes.make_group_node(g.canvas, nodes, canvas); canvas.nodes.push(node); - nodes.nodesSelectedId = [node.id]; + nodes.nodes_selected_id = [node.id]; nodes.nodesDrag = true; } @@ -1116,26 +1116,26 @@ class UINodes { } } // Group was deleted / renamed - let groupExists: bool = false; + let group_exists: bool = false; for (let group of Project.material_groups) { if (groupName == group.canvas.name) { - groupExists = true; + group_exists = true; } } - if (!groupExists) return false; + if (!group_exists) return false; return true; } - static push_undo = (lastCanvas: zui_node_canvas_t = null) => { - if (lastCanvas == null) lastCanvas = UINodes.get_canvas(true); - let canvasGroup: i32 = UINodes.group_stack.length > 0 ? Project.material_groups.indexOf(UINodes.group_stack[UINodes.group_stack.length - 1]) : null; + static push_undo = (last_canvas: zui_node_canvas_t = null) => { + if (last_canvas == null) last_canvas = UINodes.get_canvas(true); + let canvas_group: i32 = UINodes.group_stack.length > 0 ? Project.material_groups.indexOf(UINodes.group_stack[UINodes.group_stack.length - 1]) : null; ///if (is_paint || is_sculpt) UIBase.hwnds[tab_area_t.SIDEBAR0].redraws = 2; - History.edit_nodes(lastCanvas, UINodes.canvas_type, canvasGroup); + History.edit_nodes(last_canvas, UINodes.canvas_type, canvas_group); ///end ///if is_lab - History.edit_nodes(lastCanvas, canvasGroup); + History.edit_nodes(last_canvas, canvas_group); ///end } @@ -1150,7 +1150,7 @@ class UINodes { ///end n.buttons[0].default_value = index; - UINodes.get_nodes().nodesSelectedId = [n.id]; + UINodes.get_nodes().nodes_selected_id = [n.id]; ///if is_lab ParserLogic.parse(Project.canvas); @@ -1164,7 +1164,7 @@ class UINodes { let g: node_group_t = UINodes.group_stack.length > 0 ? UINodes.group_stack[UINodes.group_stack.length - 1] : null; let n: zui_node_t = NodesMaterial.create_node(SlotLayer.is_mask(Context.raw.layer) ? "LAYER_MASK" : "LAYER", g); n.buttons[0].default_value = index; - UINodes.get_nodes().nodesSelectedId = [n.id]; + UINodes.get_nodes().nodes_selected_id = [n.id]; } static accept_material_drag = (index: i32) => { @@ -1172,7 +1172,7 @@ class UINodes { let g: node_group_t = UINodes.group_stack.length > 0 ? UINodes.group_stack[UINodes.group_stack.length - 1] : null; let n: zui_node_t = NodesMaterial.create_node("MATERIAL", g); n.buttons[0].default_value = index; - UINodes.get_nodes().nodesSelectedId = [n.id]; + UINodes.get_nodes().nodes_selected_id = [n.id]; } ///end @@ -1187,7 +1187,7 @@ class UINodes { color_get_bb(swatch.base) / 255, color_get_ab(swatch.base) / 255 ]; - UINodes.get_nodes().nodesSelectedId = [n.id]; + UINodes.get_nodes().nodes_selected_id = [n.id]; ///end } @@ -1217,22 +1217,22 @@ class UINodes { node.id = zui_get_node_id(canvas.nodes); node.x = UINodes.get_node_x(); node.y = UINodes.get_node_y(); - let groupInput: zui_node_t = null; - let groupOutput: zui_node_t = null; + let group_input: zui_node_t = null; + let group_output: zui_node_t = null; for (let g of Project.material_groups) { if (g.canvas.name == node.name) { for (let n of g.canvas.nodes) { - if (n.type == "GROUP_INPUT") groupInput = n; - else if (n.type == "GROUP_OUTPUT") groupOutput = n; + if (n.type == "GROUP_INPUT") group_input = n; + else if (n.type == "GROUP_OUTPUT") group_output = n; } break; } } - if (groupInput != null && groupOutput != null) { - for (let soc of groupInput.outputs) { + if (group_input != null && group_output != null) { + for (let soc of group_input.outputs) { node.inputs.push(NodesMaterial.create_socket(nodes, node, soc.name, soc.type, canvas, soc.min, soc.max, soc.default_value)); } - for (let soc of groupOutput.inputs) { + for (let soc of group_output.inputs) { node.outputs.push(NodesMaterial.create_socket(nodes, node, soc.name, soc.type, canvas, soc.min, soc.max, soc.default_value)); } } @@ -1242,9 +1242,9 @@ class UINodes { ///if (is_paint || is_sculpt) static make_node_preview = () => { let nodes: zui_nodes_t = Context.raw.material.nodes; - if (nodes.nodesSelectedId.length == 0) return; + if (nodes.nodes_selected_id.length == 0) return; - let node: zui_node_t = zui_get_node(Context.raw.material.canvas.nodes, nodes.nodesSelectedId[0]); + let node: zui_node_t = zui_get_node(Context.raw.material.canvas.nodes, nodes.nodes_selected_id[0]); // if (node == null) return; Context.raw.node_preview_name = node.name; diff --git a/base/Sources/UIToolbar.ts b/base/Sources/UIToolbar.ts index 71f10c3b..29957790 100644 --- a/base/Sources/UIToolbar.ts +++ b/base/Sources/UIToolbar.ts @@ -49,7 +49,7 @@ class UIToolbar { let col: i32 = ui.t.WINDOW_BG_COL; if (col < 0) col += 4294967296; let light: bool = col > (0xff666666 + 4294967296); - let iconAccent: i32 = light ? 0xff666666 : -1; + let icon_accent: i32 = light ? 0xff666666 : -1; // Properties icon if (Config.raw.layout[layout_size_t.HEADER] == 1) { @@ -67,8 +67,8 @@ class UIToolbar { ui.t.ELEMENT_H = Math.floor(ui.t.ELEMENT_H * 1.5); ui.t.BUTTON_H = ui.t.ELEMENT_H; ui.t.BUTTON_COL = ui.t.WINDOW_BG_COL; - let fontHeight: i32 = g2_font_height(ui.font, ui.font_size); - ui.font_offset_y = (zui_ELEMENT_H(ui) - fontHeight) / 2; + let font_height: i32 = g2_font_height(ui.font, ui.font_size); + ui.font_offset_y = (zui_ELEMENT_H(ui) - font_height) / 2; let _w: i32 = ui._w; ui._w = UIToolbar.toolbar_w; @@ -102,19 +102,19 @@ class UIToolbar { "(" + Config.keymap.tool_material + ")", ]; - let drawTool = (i: i32) => { + let draw_tool = (i: i32) => { ui._x += 2; if (Context.raw.tool == i) UIToolbar.draw_highlight(); - let tileY: i32 = Math.floor(i / 12); - let tileX: i32 = tileY % 2 == 0 ? i % 12 : (11 - (i % 12)); - let rect: rect_t = Res.tile50(img, tileX, tileY); + let tile_y: i32 = Math.floor(i / 12); + let tile_x: i32 = tile_y % 2 == 0 ? i % 12 : (11 - (i % 12)); + let rect: rect_t = Res.tile50(img, tile_x, tile_y); let _y: i32 = ui._y; - let imageState: zui_state_t = zui_image(img, iconAccent, -1.0, rect.x, rect.y, rect.w, rect.h); - if (imageState == zui_state_t.STARTED) { + let image_state: zui_state_t = zui_image(img, icon_accent, -1.0, rect.x, rect.y, rect.w, rect.h); + if (image_state == zui_state_t.STARTED) { Context.select_tool(i); } - else if (imageState == zui_state_t.RELEASED && Config.raw.layout[layout_size_t.HEADER] == 0) { + else if (image_state == zui_state_t.RELEASED && Config.raw.layout[layout_size_t.HEADER] == 0) { if (UIToolbar.last_tool == i) { UIToolbar.tool_properties_menu(); } @@ -132,24 +132,24 @@ class UIToolbar { ui._y += 2; } - drawTool(workspace_tool_t.BRUSH); + draw_tool(workspace_tool_t.BRUSH); ///if is_paint - drawTool(workspace_tool_t.ERASER); - drawTool(workspace_tool_t.FILL); - drawTool(workspace_tool_t.DECAL); - drawTool(workspace_tool_t.TEXT); - drawTool(workspace_tool_t.CLONE); - drawTool(workspace_tool_t.BLUR); - drawTool(workspace_tool_t.SMUDGE); - drawTool(workspace_tool_t.PARTICLE); - drawTool(workspace_tool_t.COLORID); - drawTool(workspace_tool_t.PICKER); - drawTool(workspace_tool_t.BAKE); - drawTool(workspace_tool_t.MATERIAL); + draw_tool(workspace_tool_t.ERASER); + draw_tool(workspace_tool_t.FILL); + draw_tool(workspace_tool_t.DECAL); + draw_tool(workspace_tool_t.TEXT); + draw_tool(workspace_tool_t.CLONE); + draw_tool(workspace_tool_t.BLUR); + draw_tool(workspace_tool_t.SMUDGE); + draw_tool(workspace_tool_t.PARTICLE); + draw_tool(workspace_tool_t.COLORID); + draw_tool(workspace_tool_t.PICKER); + draw_tool(workspace_tool_t.BAKE); + draw_tool(workspace_tool_t.MATERIAL); ///end ///if is_forge - drawTool(workspace_tool_t.GIZMO); + draw_tool(workspace_tool_t.GIZMO); ///end ui.image_scroll_align = true; @@ -170,7 +170,7 @@ class UIToolbar { let _y: i32 = ui._y; let _w: i32 = ui._w; UIMenu.draw((ui: zui_t) => { - let startY: i32 = ui._y; + let start_y: i32 = ui._y; ui.changed = false; UIHeader.draw_tool_properties(ui); @@ -183,7 +183,7 @@ class UIToolbar { Config.raw.layout[layout_size_t.HEADER] = 1; } - let h: i32 = ui._y - startY; + let h: i32 = ui._y - start_y; UIMenu.menu_elements = Math.floor(h / zui_ELEMENT_H(ui)); UIMenu.menu_x = Math.floor(_x + _w + 2); UIMenu.menu_y = Math.floor(_y - 6 * zui_SCALE(ui)); diff --git a/base/Sources/UIView2D.ts b/base/Sources/UIView2D.ts index d7109645..1fae4c14 100644 --- a/base/Sources/UIView2D.ts +++ b/base/Sources/UIView2D.ts @@ -47,7 +47,7 @@ class UIView2D { ///end let scale: f32 = Config.raw.window_scale; - UIView2D.ui = zui_create({ theme: Base.theme, font: Base.font, color_wheel: Base.color_wheel, black_white_gradient: Base.color_wheel_gradient, scale_factor: scale }); + UIView2D.ui = zui_create({ theme: base_theme, font: base_font, color_wheel: base_color_wheel, black_white_gradient: base_color_wheel_gradient, scale_factor: scale }); UIView2D.ui.scroll_enabled = false; } @@ -132,11 +132,11 @@ class UIView2D { ///else let nodes: zui_nodes_t = UINodes.get_nodes(); - if (nodes.nodesSelectedId.length > 0) { - let sel: zui_node_t = zui_get_node(UINodes.get_canvas(true).nodes, nodes.nodesSelectedId[0]); - let brushNode: LogicNode = ParserLogic.get_logic_node(sel); - if (brushNode != null) { - tex = brushNode.get_cached_image(); + if (nodes.nodes_selected_id.length > 0) { + let sel: zui_node_t = zui_get_node(UINodes.get_canvas(true).nodes, nodes.nodes_selected_id[0]); + let brush_node: LogicNode = ParserLogic.get_logic_node(sel); + if (brush_node != null) { + tex = brush_node.get_cached_image(); } } @@ -146,20 +146,20 @@ class UIView2D { else if (UIView2D.type == view_2d_type_t.LAYER) { let layer: SlotLayerRaw = l; - if (Config.raw.brush_live && RenderPathPaint.liveLayerDrawn > 0) { - layer = RenderPathPaint.liveLayer; + if (Config.raw.brush_live && RenderPathPaint.live_layer_drawn > 0) { + layer = RenderPathPaint.live_layer; } if (UIView2D.layer_mode == view_2d_layer_mode_t.VISIBLE) { let current: image_t = _g2_current; if (current != null) g2_end(); - layer = Base.flatten(); + layer = base_flatten(); if (current != null) g2_begin(current); } else if (SlotLayer.is_group(layer)) { let current: image_t = _g2_current; if (current != null) g2_end(); - layer = Base.flatten(false, SlotLayer.get_children(layer)); + layer = base_flatten(false, SlotLayer.get_children(layer)); if (current != null) g2_begin(current); } @@ -230,7 +230,7 @@ class UIView2D { if ((Context.in_2d_view(view_2d_type_t.ASSET) || Context.in_2d_view(view_2d_type_t.NODE)) && Context.raw.tool == workspace_tool_t.PICKER && UIView2D.ui.input_down) { let x: f32 = UIView2D.ui.input_x - tx - UIView2D.wx; let y: f32 = UIView2D.ui.input_y - ty - UIView2D.wy; - Base.notify_on_next_frame(() => { + base_notify_on_next_frame(() => { let texpaint_picker: image_t = render_path_render_targets.get("texpaint_picker")._image; g2_begin(texpaint_picker); g2_draw_scaled_image(tex, -x, -y, tw, th); @@ -268,9 +268,9 @@ class UIView2D { g2_fill_rect(0, zui_ELEMENT_H(UIView2D.ui), UIView2D.ww, zui_ELEMENT_H(UIView2D.ui) + zui_ELEMENT_OFFSET(UIView2D.ui) * 2); g2_set_color(0xffffffff); - let startY: f32 = zui_ELEMENT_H(UIView2D.ui) + zui_ELEMENT_OFFSET(UIView2D.ui); + let start_y: f32 = zui_ELEMENT_H(UIView2D.ui) + zui_ELEMENT_OFFSET(UIView2D.ui); UIView2D.ui._x = 2; - UIView2D.ui._y = 2 + startY; + UIView2D.ui._y = 2 + start_y; UIView2D.ui._w = ew; // Editable layer name @@ -302,8 +302,8 @@ class UIView2D { ///else let nodes: zui_nodes_t = UINodes.get_nodes(); - if (nodes.nodesSelectedId.length > 0) { - zui_text(zui_get_node(UINodes.get_canvas(true).nodes, nodes.nodesSelectedId[0]).name); + if (nodes.nodes_selected_id.length > 0) { + zui_text(zui_get_node(UINodes.get_canvas(true).nodes, nodes.nodes_selected_id[0]).name); } ///end @@ -322,7 +322,7 @@ class UIView2D { if (h.changed) UIBase.hwnds[0].redraws = 2; UIView2D.ui._x += UIView2D.ui._w + 3; - UIView2D.ui._y = 2 + startY; + UIView2D.ui._y = 2 + start_y; UIView2D.ui._w = ew; ///if (is_paint || is_sculpt) @@ -332,7 +332,7 @@ class UIView2D { tr("Selected"), ], tr("Layers")); UIView2D.ui._x += ew + 3; - UIView2D.ui._y = 2 + startY; + UIView2D.ui._y = 2 + start_y; if (!SlotLayer.is_mask(Context.raw.layer)) { UIView2D.tex_type = zui_combo(zui_handle("uiview2d_3", { position: UIView2D.tex_type }), [ @@ -345,19 +345,19 @@ class UIView2D { tr("Height"), ], tr("Texture")); UIView2D.ui._x += ew + 3; - UIView2D.ui._y = 2 + startY; + UIView2D.ui._y = 2 + start_y; } UIView2D.ui._w = Math.floor(ew * 0.7 + 3); UIView2D.uvmap_show = zui_check(zui_handle("uiview2d_4", { selected: UIView2D.uvmap_show }), tr("UV Map")); UIView2D.ui._x += ew * 0.7 + 3; - UIView2D.ui._y = 2 + startY; + UIView2D.ui._y = 2 + start_y; } ///end UIView2D.tiled_show = zui_check(zui_handle("uiview2d_5", { selected: UIView2D.tiled_show }), tr("Tiled")); UIView2D.ui._x += ew * 0.7 + 3; - UIView2D.ui._y = 2 + startY; + UIView2D.ui._y = 2 + start_y; if (UIView2D.type == view_2d_type_t.ASSET && tex != null) { // Texture resolution zui_text(tex.width + "x" + tex.height); @@ -366,10 +366,10 @@ class UIView2D { // Picked position ///if (is_paint || is_sculpt) if (Context.raw.tool == workspace_tool_t.PICKER && (UIView2D.type == view_2d_type_t.LAYER || UIView2D.type == view_2d_type_t.ASSET)) { - let cursorImg: image_t = Res.get("cursor.k"); + let cursor_img: image_t = Res.get("cursor.k"); let hsize: f32 = 16 * zui_SCALE(UIView2D.ui); let size: f32 = hsize * 2; - g2_draw_scaled_image(cursorImg, tx + tw * Context.raw.uvx_picked - hsize, ty + th * Context.raw.uvy_picked - hsize, size, size); + g2_draw_scaled_image(cursor_img, tx + tw * Context.raw.uvx_picked - hsize, ty + th * Context.raw.uvy_picked - hsize, size, size); } ///end } @@ -384,7 +384,7 @@ class UIView2D { Context.raw.paint2d = false; ///end - if (!Base.ui_enabled || + if (!base_ui_enabled || !UIView2D.show || mouse_x < UIView2D.wx || mouse_x > UIView2D.wx + UIView2D.ww || @@ -400,13 +400,13 @@ class UIView2D { UIView2D.pan_x += control.pan_x; UIView2D.pan_y += control.pan_y; if (control.zoom != 0) { - let _panX: f32 = UIView2D.pan_x / UIView2D.pan_scale; - let _panY: f32 = UIView2D.pan_y / UIView2D.pan_scale; + let _pan_x: f32 = UIView2D.pan_x / UIView2D.pan_scale; + let _pan_y: f32 = UIView2D.pan_y / UIView2D.pan_scale; UIView2D.pan_scale += control.zoom; if (UIView2D.pan_scale < 0.1) UIView2D.pan_scale = 0.1; if (UIView2D.pan_scale > 6.0) UIView2D.pan_scale = 6.0; - UIView2D.pan_x = _panX * UIView2D.pan_scale; - UIView2D.pan_y = _panY * UIView2D.pan_scale; + UIView2D.pan_x = _pan_x * UIView2D.pan_scale; + UIView2D.pan_y = _pan_y * UIView2D.pan_scale; if (zui_touch_scroll()) { // Zoom to finger location @@ -417,15 +417,15 @@ class UIView2D { ///if (is_paint || is_sculpt) let decal: bool = Context.raw.tool == workspace_tool_t.DECAL || Context.raw.tool == workspace_tool_t.TEXT; - let decalMask: bool = decal && Operator.shortcut(Config.keymap.decal_mask + "+" + Config.keymap.action_paint, ShortcutType.ShortcutDown); - let setCloneSource: bool = Context.raw.tool == workspace_tool_t.CLONE && Operator.shortcut(Config.keymap.set_clone_source + "+" + Config.keymap.action_paint, ShortcutType.ShortcutDown); + let decal_mask: bool = decal && Operator.shortcut(Config.keymap.decal_mask + "+" + Config.keymap.action_paint, ShortcutType.ShortcutDown); + let set_clone_source: bool = Context.raw.tool == workspace_tool_t.CLONE && Operator.shortcut(Config.keymap.set_clone_source + "+" + Config.keymap.action_paint, ShortcutType.ShortcutDown); if (UIView2D.type == view_2d_type_t.LAYER && !UIView2D.text_input_hover && (Operator.shortcut(Config.keymap.action_paint, ShortcutType.ShortcutDown) || Operator.shortcut(Config.keymap.brush_ruler + "+" + Config.keymap.action_paint, ShortcutType.ShortcutDown) || - decalMask || - setCloneSource || + decal_mask || + set_clone_source || Config.raw.brush_live)) { Context.raw.paint2d = true; } diff --git a/base/Sources/UniformsExt.ts b/base/Sources/UniformsExt.ts index d5042dda..4ff475c9 100644 --- a/base/Sources/UniformsExt.ts +++ b/base/Sources/UniformsExt.ts @@ -24,17 +24,17 @@ class UniformsExt { case "_brushRadius": { ///if (is_paint || is_sculpt) let decal: bool = Context.raw.tool == workspace_tool_t.DECAL || Context.raw.tool == workspace_tool_t.TEXT; - let decalMask: bool = decal && Operator.shortcut(Config.keymap.decal_mask + "+" + Config.keymap.action_paint, ShortcutType.ShortcutDown); - let brushDecalMaskRadius: f32 = Context.raw.brush_decal_mask_radius; + let decal_mask: bool = decal && Operator.shortcut(Config.keymap.decal_mask + "+" + Config.keymap.action_paint, ShortcutType.ShortcutDown); + let brush_decal_mask_radius: f32 = Context.raw.brush_decal_mask_radius; if (Config.raw.brush_3d) { - brushDecalMaskRadius *= Context.raw.paint2d ? 0.55 * UIView2D.pan_scale : 2.0; + brush_decal_mask_radius *= Context.raw.paint2d ? 0.55 * UIView2D.pan_scale : 2.0; } - let radius: f32 = decalMask ? brushDecalMaskRadius : Context.raw.brush_radius; + let radius: f32 = decal_mask ? brush_decal_mask_radius : Context.raw.brush_radius; let val: f32 = (radius * Context.raw.brush_nodes_radius) / 15.0; if (Config.raw.pressure_radius && pen_down()) { val *= pen_pressure * Config.raw.pressure_sensitivity; } - let scale2d: f32 = (900 / Base.h()) * Config.raw.window_scale; + let scale2d: f32 = (900 / base_h()) * Config.raw.window_scale; if (Config.raw.brush_3d && !decal) { val *= Context.raw.paint2d ? 0.55 * scale2d * UIView2D.pan_scale : 2; @@ -83,8 +83,8 @@ class UniformsExt { return val; } case "_brushHardness": { - let decalMask: bool = Operator.shortcut(Config.keymap.decal_mask + "+" + Config.keymap.action_paint, ShortcutType.ShortcutDown); - if (Context.raw.tool != workspace_tool_t.BRUSH && Context.raw.tool != workspace_tool_t.ERASER && Context.raw.tool != workspace_tool_t.CLONE && !decalMask) return 1.0; + let decal_mask: bool = Operator.shortcut(Config.keymap.decal_mask + "+" + Config.keymap.action_paint, ShortcutType.ShortcutDown); + if (Context.raw.tool != workspace_tool_t.BRUSH && Context.raw.tool != workspace_tool_t.ERASER && Context.raw.tool != workspace_tool_t.CLONE && !decal_mask) return 1.0; let val: f32 = Context.raw.brush_hardness * Context.raw.brush_nodes_hardness; if (Config.raw.pressure_hardness && pen_down()) { val *= pen_pressure * Config.raw.pressure_sensitivity; @@ -113,7 +113,7 @@ class UniformsExt { } ///end case "_decalLayerDim": { - return mat4_get_scale(Context.raw.layer.decalMat).z * 0.5; + return mat4_get_scale(Context.raw.layer.decal_mat).z * 0.5; } case "_pickerOpacity": { return Context.raw.picked_color.opacity; @@ -169,8 +169,8 @@ class UniformsExt { } ///if (is_paint || is_sculpt) case "_brushAngle": { - let brushAngle: f32 = Context.raw.brush_angle + Context.raw.brush_nodes_angle; - let angle: f32 = Context.raw.layer.fill_layer != null ? Context.raw.layer.angle : brushAngle; + let brush_angle: f32 = Context.raw.brush_angle + Context.raw.brush_nodes_angle; + let angle: f32 = Context.raw.layer.fill_layer != null ? Context.raw.layer.angle : brush_angle; angle *= (Math.PI / 180); if (Config.raw.pressure_angle && pen_down()) { angle *= pen_pressure * Config.raw.pressure_sensitivity; @@ -190,7 +190,7 @@ class UniformsExt { case "_brushDirection": { v = _uniforms_vec; // Discard first paint for directional brush - let allowPaint: bool = Context.raw.prev_paint_vec_x != Context.raw.last_paint_vec_x && + let allow_paint: bool = Context.raw.prev_paint_vec_x != Context.raw.last_paint_vec_x && Context.raw.prev_paint_vec_y != Context.raw.last_paint_vec_y && Context.raw.prev_paint_vec_x > 0 && Context.raw.prev_paint_vec_y > 0; @@ -203,19 +203,19 @@ class UniformsExt { lastx = UniformsExt.vec2d(lastx); } let angle: f32 = Math.atan2(-y + lasty, x - lastx) - Math.PI / 2; - vec4_set(v, Math.cos(angle), Math.sin(angle), allowPaint ? 1 : 0); + vec4_set(v, Math.cos(angle), Math.sin(angle), allow_paint ? 1 : 0); Context.raw.prev_paint_vec_x = Context.raw.last_paint_vec_x; Context.raw.prev_paint_vec_y = Context.raw.last_paint_vec_y; return v; } case "_decalLayerLoc": { v = _uniforms_vec; - vec4_set(v, Context.raw.layer.decalMat.m[12], Context.raw.layer.decalMat.m[13], Context.raw.layer.decalMat.m[14]); + vec4_set(v, Context.raw.layer.decal_mat.m[12], Context.raw.layer.decal_mat.m[13], Context.raw.layer.decal_mat.m[14]); return v; } case "_decalLayerNor": { v = _uniforms_vec; - vec4_normalize(vec4_set(v, Context.raw.layer.decalMat.m[8], Context.raw.layer.decalMat.m[9], Context.raw.layer.decalMat.m[10])); + vec4_normalize(vec4_set(v, Context.raw.layer.decal_mat.m[8], Context.raw.layer.decal_mat.m[9], Context.raw.layer.decal_mat.m[10])); return v; } case "_pickerBase": { @@ -258,7 +258,7 @@ class UniformsExt { static vec2d = (x: f32) => { // Transform from 3d viewport coord to 2d view coord Context.raw.paint2d_view = false; - let res: f32 = (x * Base.w() - Base.w()) / UIView2D.ww; + let res: f32 = (x * base_w() - base_w()) / UIView2D.ww; Context.raw.paint2d_view = true; return res; } @@ -305,11 +305,11 @@ class UniformsExt { return UniformsExt.vec; } case "_decalMask": { - let decalMask: bool = Operator.shortcut(Config.keymap.decal_mask + "+" + Config.keymap.action_paint, ShortcutType.ShortcutDown); + let decal_mask: bool = Operator.shortcut(Config.keymap.decal_mask + "+" + Config.keymap.action_paint, ShortcutType.ShortcutDown); let val: f32 = (Context.raw.brush_radius * Context.raw.brush_nodes_radius) / 15.0; - let scale2d: f32 = (900 / Base.h()) * Config.raw.window_scale; + let scale2d: f32 = (900 / base_h()) * Config.raw.window_scale; val *= scale2d; // Projection ratio - vec4_set(UniformsExt.vec, Context.raw.decal_x, Context.raw.decal_y, decalMask ? 1 : 0, val); + vec4_set(UniformsExt.vec, Context.raw.decal_x, Context.raw.decal_y, decal_mask ? 1 : 0, val); if (Context.raw.paint2d) UniformsExt.vec.x = UniformsExt.vec2d(UniformsExt.vec.x); return UniformsExt.vec; } @@ -323,7 +323,7 @@ class UniformsExt { ///if (is_paint || is_sculpt) case "_decalLayerMatrix": { // Decal layer let m: mat4_t = _uniforms_mat; - mat4_set_from(m, Context.raw.layer.decalMat); + mat4_set_from(m, Context.raw.layer.decal_mat); mat4_get_inv(m, m); mat4_mult_mat(m, UniformsExt.ortho_p); return m; diff --git a/base/Sources/UtilMesh.ts b/base/Sources/UtilMesh.ts index dbbefd23..b63eddd5 100644 --- a/base/Sources/UtilMesh.ts +++ b/base/Sources/UtilMesh.ts @@ -3,31 +3,31 @@ class UtilMesh { static unwrappers: Mapvoid)> = new Map(); - static merge_mesh = (paintObjects: mesh_object_t[] = null) => { - if (paintObjects == null) paintObjects = Project.paint_objects; - if (paintObjects.length == 0) return; - Context.raw.merged_object_is_atlas = paintObjects.length < Project.paint_objects.length; + static merge_mesh = (paint_objects: mesh_object_t[] = null) => { + if (paint_objects == null) paint_objects = Project.paint_objects; + if (paint_objects.length == 0) return; + Context.raw.merged_object_is_atlas = paint_objects.length < Project.paint_objects.length; let vlen: i32 = 0; let ilen: i32 = 0; - let maxScale: f32 = 0.0; - for (let i: i32 = 0; i < paintObjects.length; ++i) { - vlen += paintObjects[i].data.vertex_arrays[0].values.length; - ilen += paintObjects[i].data.index_arrays[0].values.length; - if (paintObjects[i].data.scale_pos > maxScale) maxScale = paintObjects[i].data.scale_pos; + let max_scale: f32 = 0.0; + for (let i: i32 = 0; i < paint_objects.length; ++i) { + vlen += paint_objects[i].data.vertex_arrays[0].values.length; + ilen += paint_objects[i].data.index_arrays[0].values.length; + if (paint_objects[i].data.scale_pos > max_scale) max_scale = paint_objects[i].data.scale_pos; } vlen = Math.floor(vlen / 4); let va0: Int16Array = new Int16Array(vlen * 4); let va1: Int16Array = new Int16Array(vlen * 2); let va2: Int16Array = new Int16Array(vlen * 2); - let va3: Int16Array = paintObjects[0].data.vertex_arrays.length > 3 ? new Int16Array(vlen * 4) : null; + let va3: Int16Array = paint_objects[0].data.vertex_arrays.length > 3 ? new Int16Array(vlen * 4) : null; let ia: Uint32Array = new Uint32Array(ilen); let voff: i32 = 0; let ioff: i32 = 0; - for (let i: i32 = 0; i < paintObjects.length; ++i) { - let vas: vertex_array_t[] = paintObjects[i].data.vertex_arrays; - let ias: index_array_t[] = paintObjects[i].data.index_arrays; - let scale: f32 = paintObjects[i].data.scale_pos; + for (let i: i32 = 0; i < paint_objects.length; ++i) { + let vas: vertex_array_t[] = paint_objects[i].data.vertex_arrays; + let ias: index_array_t[] = paint_objects[i].data.index_arrays; + let scale: f32 = paint_objects[i].data.scale_pos; // Pos for (let j: i32 = 0; j < vas[0].values.length; ++j) va0[j + voff * 4] = vas[0].values[j]; @@ -35,17 +35,17 @@ class UtilMesh { // Translate ///if is_forge for (let j: i32 = 0; j < Math.floor(va0.length / 4); ++j) { - va0[j * 4 + voff * 4] += Math.floor(transform_world_x(paintObjects[i].base.transform) * 32767); - va0[j * 4 + 1 + voff * 4] += Math.floor(transform_world_y(paintObjects[i].base.transform) * 32767); - va0[j * 4 + 2 + voff * 4] += Math.floor(transform_world_z(paintObjects[i].base.transform) * 32767); + va0[j * 4 + voff * 4] += Math.floor(transform_world_x(paint_objects[i].base.transform) * 32767); + va0[j * 4 + 1 + voff * 4] += Math.floor(transform_world_y(paint_objects[i].base.transform) * 32767); + va0[j * 4 + 2 + voff * 4] += Math.floor(transform_world_z(paint_objects[i].base.transform) * 32767); } ///end // Re-scale for (let j: i32 = 0; j < Math.floor(va0.length / 4); ++j) { - va0[j * 4 + voff * 4] = Math.floor((va0[j * 4 + voff * 4] * scale) / maxScale); - va0[j * 4 + 1 + voff * 4] = Math.floor((va0[j * 4 + 1 + voff * 4] * scale) / maxScale); - va0[j * 4 + 2 + voff * 4] = Math.floor((va0[j * 4 + 2 + voff * 4] * scale) / maxScale); + va0[j * 4 + voff * 4] = Math.floor((va0[j * 4 + voff * 4] * scale) / max_scale); + va0[j * 4 + 1 + voff * 4] = Math.floor((va0[j * 4 + 1 + voff * 4] * scale) / max_scale); + va0[j * 4 + 2 + voff * 4] = Math.floor((va0[j * 4 + 2 + voff * 4] * scale) / max_scale); } // Nor for (let j: i32 = 0; j < vas[1].values.length; ++j) va1[j + voff * 2] = vas[1].values[j]; @@ -70,7 +70,7 @@ class UtilMesh { index_arrays: [ { values: ia, material: 0 } ], - scale_pos: maxScale, + scale_pos: max_scale, scale_tex: 1.0 }; if (va3 != null) raw.vertex_arrays.push({ values: va3, attrib: "col", data: "short4norm" }); @@ -290,19 +290,19 @@ class UtilMesh { let g: mesh_data_t = o.data; let sc: f32 = o.data.scale_pos / 32767; let va: i16_array_t = o.data.vertex_arrays[0].values; - let maxScale: f32 = 0.0; + let max_scale: f32 = 0.0; for (let i: i32 = 0; i < Math.floor(va.length / 4); ++i) { - if (Math.abs(va[i * 4 ] * sc - dx) > maxScale) maxScale = Math.abs(va[i * 4 ] * sc - dx); - if (Math.abs(va[i * 4 + 1] * sc - dy) > maxScale) maxScale = Math.abs(va[i * 4 + 1] * sc - dy); - if (Math.abs(va[i * 4 + 2] * sc - dz) > maxScale) maxScale = Math.abs(va[i * 4 + 2] * sc - dz); + if (Math.abs(va[i * 4 ] * sc - dx) > max_scale) max_scale = Math.abs(va[i * 4 ] * sc - dx); + if (Math.abs(va[i * 4 + 1] * sc - dy) > max_scale) max_scale = Math.abs(va[i * 4 + 1] * sc - dy); + if (Math.abs(va[i * 4 + 2] * sc - dz) > max_scale) max_scale = Math.abs(va[i * 4 + 2] * sc - dz); } - o.base.transform.scale_world = o.data.scale_pos = o.data.scale_pos = maxScale; + o.base.transform.scale_world = o.data.scale_pos = o.data.scale_pos = max_scale; transform_build_matrix(o.base.transform); for (let i: i32 = 0; i < Math.floor(va.length / 4); ++i) { - va[i * 4 ] = Math.floor((va[i * 4 ] * sc - dx) / maxScale * 32767); - va[i * 4 + 1] = Math.floor((va[i * 4 + 1] * sc - dy) / maxScale * 32767); - va[i * 4 + 2] = Math.floor((va[i * 4 + 2] * sc - dz) / maxScale * 32767); + va[i * 4 ] = Math.floor((va[i * 4 ] * sc - dx) / max_scale * 32767); + va[i * 4 + 1] = Math.floor((va[i * 4 + 1] * sc - dy) / max_scale * 32767); + va[i * 4 + 2] = Math.floor((va[i * 4 + 2] * sc - dz) / max_scale * 32767); } let l: i32 = g4_vertex_struct_byte_size(g._.structure) / 2; @@ -320,7 +320,7 @@ class UtilMesh { static apply_displacement = (texpaint_pack: image_t, strength: f32 = 0.1, uvScale: f32 = 1.0) => { let height: buffer_t = image_get_pixels(texpaint_pack); - let heightView: buffer_view_t = new DataView(height); + let height_view: buffer_view_t = new DataView(height); let res: i32 = texpaint_pack.width; let o: mesh_object_t = Project.paint_objects[0]; let g: mesh_data_t = o.data; @@ -331,7 +331,7 @@ class UtilMesh { let y: i32 = Math.floor(vertices.getInt16((i * l + 7) * 2, true) / 32767 * res); let xx: i32 = Math.floor(x * uvScale) % res; let yy: i32 = Math.floor(y * uvScale) % res; - let h: f32 = (1.0 - heightView.getUint8((yy * res + xx) * 4 + 3) / 255) * strength; + let h: f32 = (1.0 - height_view.getUint8((yy * res + xx) * 4 + 3) / 255) * strength; vertices.setInt16((i * l ) * 2, vertices.getInt16((i * l ) * 2, true) - Math.floor(vertices.getInt16((i * l + 4) * 2, true) * h), true); vertices.setInt16((i * l + 1) * 2, vertices.getInt16((i * l + 1) * 2, true) - Math.floor(vertices.getInt16((i * l + 5) * 2, true) * h), true); vertices.setInt16((i * l + 2) * 2, vertices.getInt16((i * l + 2) * 2, true) - Math.floor(vertices.getInt16((i * l + 3) * 2, true) * h), true); diff --git a/base/Sources/UtilRender.ts b/base/Sources/UtilRender.ts index ffea707c..7074f7ff 100644 --- a/base/Sources/UtilRender.ts +++ b/base/Sources/UtilRender.ts @@ -25,20 +25,20 @@ class UtilRender { mat4_set_from(Context.raw.saved_camera, scene_camera.base.transform.local); let m: mat4_t = mat4_create(0.9146286343879498, -0.0032648027153306235, 0.404281837254303, 0.4659988049397712, 0.404295023959927, 0.007367569133732468, -0.9145989516155143, -1.0687517188018691, 0.000007410128652369705, 0.9999675337275382, 0.008058532943908717, 0.015935682577325486, 0, 0, 0, 1); transform_set_matrix(scene_camera.base.transform, m); - let savedFov: f32 = scene_camera.data.fov; + let saved_fov: f32 = scene_camera.data.fov; scene_camera.data.fov = 0.92; Viewport.update_camera_type(camera_type_t.PERSPECTIVE); let light: light_object_t = scene_lights[0]; - let _lightStrength: f32 = light.data.strength; + let _light_strength: f32 = light.data.strength; let probe: world_data_t = scene_world; - let _probeStrength: f32 = probe.strength; + let _probe_strength: f32 = probe.strength; light.data.strength = 0; probe.strength = 7; - let _envmapAngle: f32 = Context.raw.envmap_angle; + let _envmap_angle: f32 = Context.raw.envmap_angle; Context.raw.envmap_angle = 6.0; - let _brushScale: f32 = Context.raw.brush_scale; + let _brush_scale: f32 = Context.raw.brush_scale; Context.raw.brush_scale = 1.5; - let _brushNodesScale: f32 = Context.raw.brush_nodes_scale; + let _brush_nodes_scale: f32 = Context.raw.brush_nodes_scale; Context.raw.brush_nodes_scale = 1.0; scene_world._.envmap = Context.raw.preview_envmap; @@ -65,14 +65,14 @@ class UtilRender { transform_set_matrix(scene_camera.base.transform, Context.raw.saved_camera); Viewport.update_camera_type(Context.raw.camera_type); - scene_camera.data.fov = savedFov; + scene_camera.data.fov = saved_fov; camera_object_build_proj(scene_camera); camera_object_build_mat(scene_camera); - light.data.strength = _lightStrength; - probe.strength = _probeStrength; - Context.raw.envmap_angle = _envmapAngle; - Context.raw.brush_scale = _brushScale; - Context.raw.brush_nodes_scale = _brushNodesScale; + light.data.strength = _light_strength; + probe.strength = _probe_strength; + Context.raw.envmap_angle = _envmap_angle; + Context.raw.brush_scale = _brush_scale; + Context.raw.brush_nodes_scale = _brush_nodes_scale; scene_world._.envmap = Context.raw.show_envmap ? Context.raw.saved_envmap : Context.raw.empty_envmap; MakeMaterial.parse_mesh_material(); Context.raw.ddirty = 0; @@ -102,7 +102,7 @@ class UtilRender { let m: mat4_t = mat4_identity(); mat4_translate(m, 0, 0, 1); transform_set_matrix(scene_camera.base.transform, m); - let savedFov: f32 = scene_camera.data.fov; + let saved_fov: f32 = scene_camera.data.fov; scene_camera.data.fov = 0.92; Viewport.update_camera_type(camera_type_t.PERSPECTIVE); let light: light_object_t = scene_lights[0]; @@ -131,7 +131,7 @@ class UtilRender { Context.raw.paint_object = painto; transform_set_matrix(scene_camera.base.transform, Context.raw.saved_camera); - scene_camera.data.fov = savedFov; + scene_camera.data.fov = saved_fov; Viewport.update_camera_type(Context.raw.camera_type); camera_object_build_proj(scene_camera); camera_object_build_mat(scene_camera); @@ -151,10 +151,10 @@ class UtilRender { let text: string = Context.raw.text_tool_text; let font: g2_font_t = Context.raw.font.font; - let fontSize: i32 = 200; - let textW: i32 = Math.floor(g2_font_width(font, fontSize, text)); - let textH: i32 = Math.floor(g2_font_height(font, fontSize)); - let texW: i32 = textW + 32; + let font_size: i32 = 200; + let text_w: i32 = Math.floor(g2_font_width(font, font_size, text)); + let text_h: i32 = Math.floor(g2_font_height(font, font_size)); + let texW: i32 = text_w + 32; if (texW < 512) texW = 512; if (Context.raw.text_tool_image != null && Context.raw.text_tool_image.width < texW) { image_unload(Context.raw.text_tool_image); @@ -170,9 +170,9 @@ class UtilRender { g2_begin(Context.raw.text_tool_image); g2_clear(0xff000000); g2_set_font(font); - g2_set_font_size(fontSize); + g2_set_font_size(font_size); g2_set_color(0xffffffff); - g2_draw_string(text, texW / 2 - textW / 2, texW / 2 - textH / 2); + g2_draw_string(text, texW / 2 - text_w / 2, texW / 2 - text_h / 2); g2_end(); if (current != null) g2_begin(current); @@ -184,18 +184,18 @@ class UtilRender { let text: string = "Abg"; let font: g2_font_t = Context.raw.font.font; - let fontSize: i32 = 318; - let textW: i32 = Math.floor(g2_font_width(font, fontSize, text)) + 8; - let textH: i32 = Math.floor(g2_font_height(font, fontSize)) + 8; + let font_size: i32 = 318; + let text_w: i32 = Math.floor(g2_font_width(font, font_size, text)) + 8; + let text_h: i32 = Math.floor(g2_font_height(font, font_size)) + 8; if (Context.raw.font.image == null) { Context.raw.font.image = image_create_render_target(512, 512, tex_format_t.RGBA32); } g2_begin(Context.raw.font.image); g2_clear(0x00000000); g2_set_font(font); - g2_set_font_size(fontSize); + g2_set_font_size(font_size); g2_set_color(0xffffffff); - g2_draw_string(text, 512 / 2 - textW / 2, 512 / 2 - textH / 2); + g2_draw_string(text, 512 / 2 - text_w / 2, 512 / 2 - text_h / 2); g2_end(); Context.raw.font.preview_ready = true; @@ -203,18 +203,18 @@ class UtilRender { } static make_brush_preview = () => { - if (RenderPathPaint.liveLayerLocked) return; + if (RenderPathPaint.live_layer_locked) return; Context.raw.material_preview = true; let current: image_t = _g2_current; if (current != null) g2_end(); // Prepare layers - if (RenderPathPaint.liveLayer == null) { - RenderPathPaint.liveLayer = SlotLayer.create("_live"); + if (RenderPathPaint.live_layer == null) { + RenderPathPaint.live_layer = SlotLayer.create("_live"); } - let l: SlotLayerRaw = RenderPathPaint.liveLayer; + let l: SlotLayerRaw = RenderPathPaint.live_layer; SlotLayer.clear(l); if (Context.raw.brush.image == null) { @@ -248,15 +248,15 @@ class UtilRender { visibles.push(p.base.visible); p.base.visible = false; } - let mergedObjectVisible: bool = false; + let merged_object_visible: bool = false; if (Context.raw.merged_object != null) { - mergedObjectVisible = Context.raw.merged_object.base.visible; + merged_object_visible = Context.raw.merged_object.base.visible; Context.raw.merged_object.base.visible = false; } let cam: camera_object_t = scene_camera; mat4_set_from(Context.raw.saved_camera, cam.base.transform.local); - let savedFov: f32 = cam.data.fov; + let saved_fov: f32 = cam.data.fov; Viewport.update_camera_type(camera_type_t.PERSPECTIVE); let m: mat4_t = mat4_identity(); mat4_translate(m, 0, 0, 0.5); @@ -277,40 +277,40 @@ class UtilRender { vec4_set(planeo.base.transform.loc, m.m[12], -m.m[13], 0.0); transform_build_matrix(planeo.base.transform); - RenderPathPaint.liveLayerDrawn = 0; + RenderPathPaint.live_layer_drawn = 0; RenderPathBase.draw_gbuffer(); // Paint brush preview - let _brushRadius: f32 = Context.raw.brush_radius; - let _brushOpacity: f32 = Context.raw.brush_opacity; - let _brushHardness: f32 = Context.raw.brush_hardness; + let _brush_radius: f32 = Context.raw.brush_radius; + let _brush_opacity: f32 = Context.raw.brush_opacity; + let _brush_hardness: f32 = Context.raw.brush_hardness; Context.raw.brush_radius = 0.33; Context.raw.brush_opacity = 1.0; Context.raw.brush_hardness = 0.8; let _x: f32 = Context.raw.paint_vec.x; let _y: f32 = Context.raw.paint_vec.y; - let _lastX: f32 = Context.raw.last_paint_vec_x; - let _lastY: f32 = Context.raw.last_paint_vec_y; + let _last_x: f32 = Context.raw.last_paint_vec_x; + let _last_y: f32 = Context.raw.last_paint_vec_y; let _pdirty: i32 = Context.raw.pdirty; Context.raw.pdirty = 2; - let pointsX: f32[] = [0.2, 0.2, 0.35, 0.5, 0.5, 0.5, 0.65, 0.8, 0.8, 0.8]; - let pointsY: f32[] = [0.5, 0.5, 0.35 - 0.04, 0.2 - 0.08, 0.4 + 0.015, 0.6 + 0.03, 0.45 - 0.025, 0.3 - 0.05, 0.5 + 0.025, 0.7 + 0.05]; - for (let i: i32 = 1; i < pointsX.length; ++i) { - Context.raw.last_paint_vec_x = pointsX[i - 1]; - Context.raw.last_paint_vec_y = pointsY[i - 1]; - Context.raw.paint_vec.x = pointsX[i]; - Context.raw.paint_vec.y = pointsY[i]; + let points_x: f32[] = [0.2, 0.2, 0.35, 0.5, 0.5, 0.5, 0.65, 0.8, 0.8, 0.8]; + let points_y: f32[] = [0.5, 0.5, 0.35 - 0.04, 0.2 - 0.08, 0.4 + 0.015, 0.6 + 0.03, 0.45 - 0.025, 0.3 - 0.05, 0.5 + 0.025, 0.7 + 0.05]; + for (let i: i32 = 1; i < points_x.length; ++i) { + Context.raw.last_paint_vec_x = points_x[i - 1]; + Context.raw.last_paint_vec_y = points_y[i - 1]; + Context.raw.paint_vec.x = points_x[i]; + Context.raw.paint_vec.y = points_y[i]; RenderPathPaint.commands_paint(false); } - Context.raw.brush_radius = _brushRadius; - Context.raw.brush_opacity = _brushOpacity; - Context.raw.brush_hardness = _brushHardness; + Context.raw.brush_radius = _brush_radius; + Context.raw.brush_opacity = _brush_opacity; + Context.raw.brush_hardness = _brush_hardness; Context.raw.paint_vec.x = _x; Context.raw.paint_vec.y = _y; - Context.raw.last_paint_vec_x = _lastX; - Context.raw.last_paint_vec_y = _lastY; + Context.raw.last_paint_vec_x = _last_x; + Context.raw.last_paint_vec_y = _last_y; Context.raw.prev_paint_vec_x = -1; Context.raw.prev_paint_vec_y = -1; Context.raw.pdirty = _pdirty; @@ -331,22 +331,22 @@ class UtilRender { Project.paint_objects[i].base.visible = visibles[i]; } if (Context.raw.merged_object != null) { - Context.raw.merged_object.base.visible = mergedObjectVisible; + Context.raw.merged_object.base.visible = merged_object_visible; } Context.raw.paint_object = painto; transform_set_matrix(scene_camera.base.transform, Context.raw.saved_camera); - scene_camera.data.fov = savedFov; + scene_camera.data.fov = saved_fov; Viewport.update_camera_type(Context.raw.camera_type); camera_object_build_proj(scene_camera); camera_object_build_mat(scene_camera); // Scale layer down to to image preview - if (Base.pipe_merge == null) Base.make_pipe(); - l = RenderPathPaint.liveLayer; + if (base_pipe_merge == null) base_make_pipe(); + l = RenderPathPaint.live_layer; let target: image_t = Context.raw.brush.image; g2_begin(target); g2_clear(0x00000000); - g2_set_pipeline(Base.pipe_copy); + g2_set_pipeline(base_pipe_copy); g2_draw_scaled_image(l.texpaint, 0, 0, target.width, target.height); g2_set_pipeline(null); g2_end(); @@ -372,7 +372,7 @@ class UtilRender { UtilRender.create_screen_aligned_full_data(); } - let _scaleWorld: f32 = Context.raw.paint_object.base.transform.scale_world; + let _scale_world: f32 = Context.raw.paint_object.base.transform.scale_world; Context.raw.paint_object.base.transform.scale_world = 3.0; transform_build_matrix(Context.raw.paint_object.base.transform); @@ -386,7 +386,7 @@ class UtilRender { g4_draw(); g4_end(); - Context.raw.paint_object.base.transform.scale_world = _scaleWorld; + Context.raw.paint_object.base.transform.scale_world = _scale_world; transform_build_matrix(Context.raw.paint_object.base.transform); } @@ -415,12 +415,12 @@ class UtilRender { static get_decal_mat = (): mat4_t => { UtilRender.pick_pos_nor_tex(); - let decalMat: mat4_t = mat4_identity(); + let decal_mat: mat4_t = mat4_identity(); let loc: vec4_t = vec4_create(Context.raw.posx_picked, Context.raw.posy_picked, Context.raw.posz_picked); let rot: quat_t = quat_from_to(quat_create(), vec4_create(0.0, 0.0, -1.0), vec4_create(Context.raw.norx_picked, Context.raw.nory_picked, Context.raw.norz_picked)); let scale: vec4_t = vec4_create(Context.raw.brush_radius * 0.5, Context.raw.brush_radius * 0.5, Context.raw.brush_radius * 0.5); - mat4_compose(decalMat, loc, rot, scale); - return decalMat; + mat4_compose(decal_mat, loc, rot, scale); + return decal_mat; } static create_screen_aligned_full_data = () => { diff --git a/base/Sources/UtilUV.ts b/base/Sources/UtilUV.ts index 0fe7fce1..3bc14803 100644 --- a/base/Sources/UtilUV.ts +++ b/base/Sources/UtilUV.ts @@ -23,10 +23,10 @@ class UtilUV { if (UtilUV.uvmap_cached) return; - let resX: i32 = Config.get_texture_res_x(); - let resY: i32 = Config.get_texture_res_y(); + let res_x: i32 = Config.get_texture_res_x(); + let res_y: i32 = Config.get_texture_res_y(); if (UtilUV.uvmap == null) { - UtilUV.uvmap = image_create_render_target(resX, resY); + UtilUV.uvmap = image_create_render_target(res_x, res_y); } UtilUV.uvmap_cached = true; @@ -39,7 +39,7 @@ class UtilUV { g2_begin(UtilUV.uvmap); g2_clear(0x00000000); g2_set_color(0xffcccccc); - let strength: f32 = resX > 2048 ? 2.0 : 1.0; + let strength: f32 = res_x > 2048 ? 2.0 : 1.0; let f: f32 = (1 / 32767) * UtilUV.uvmap.width; for (let i: i32 = 0; i < Math.floor(inda.length / 3); ++i) { let x1: f32 = (texa[inda[i * 3 ] * 2 ]) * f; @@ -161,8 +161,8 @@ class UtilUV { let check = (c: coord_t) => { if (c.x < 0 || c.x >= w || c.y < 0 || c.y >= h) return; if (view.getUint8(c.y * w + c.x) == 255) return; - let dilateView: DataView = new DataView(UtilUV.dilate_bytes); - if (dilateView.getUint8(c.y * r * UtilUV.dilatemap.width + c.x * r) == 0) return; + let dilate_view: DataView = new DataView(UtilUV.dilate_bytes); + if (dilate_view.getUint8(c.y * r * UtilUV.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 }); diff --git a/base/Sources/Viewport.ts b/base/Sources/Viewport.ts index 77395a42..d8bbc374 100644 --- a/base/Sources/Viewport.ts +++ b/base/Sources/Viewport.ts @@ -25,7 +25,7 @@ class Viewport { if (o.type == "camera_object") { mat4_set_from_f32_array(cam.base.transform.local, o.transform); transform_decompose(cam.base.transform); - if (Context.raw.fov_handle != null) Context.raw.fov_handle.value = cam.data.fov = Base.default_fov; + if (Context.raw.fov_handle != null) Context.raw.fov_handle.value = cam.data.fov = base_default_fov; Context.raw.cam_handle.position = 0; cam.data.ortho = null; camera_object_build_proj(cam); diff --git a/base/Sources/args.ts b/base/Sources/args.ts new file mode 100644 index 00000000..1fcf03fb --- /dev/null +++ b/base/Sources/args.ts @@ -0,0 +1,187 @@ + +let args_use: bool = false; +let args_asset_path: string = ""; +let args_background: bool = false; +///if (is_paint || is_lab) +let args_export_textures: bool = false; +let args_export_textures_type: string = ""; +let args_export_textures_preset: string = ""; +let args_export_textures_path: string = ""; +///end +///if (is_paint || is_sculpt) +let args_reimport_mesh: bool = false; +let args_export_mesh: bool = false; +let args_export_mesh_path: string = ""; +///end +///if is_paint +let args_export_material: bool = false; +let args_export_material_path: string = ""; +///end + +function args_parse() { + if (krom_get_arg_count() > 1) { + args_use = true; + + let i: i32 = 0; + while (i < krom_get_arg_count()) { + // Process each arg + let current_arg: string = krom_get_arg(i); + + if (Path.is_project(current_arg)) { + Project.filepath = current_arg; + } + else if (current_arg == "--b" || current_arg == "--background") { + args_background = true; + } + + ///if (is_paint || is_lab) + else if (Path.is_texture(current_arg)) { + args_asset_path = current_arg; + } + else if (current_arg == "--export-textures" && (i + 3) <= krom_get_arg_count()) { + args_export_textures = true; + ++i; + args_export_textures_type = krom_get_arg(i); + ++i; + args_export_textures_preset = krom_get_arg(i); + ++i; + args_export_textures_path = krom_get_arg(i); + } + ///end + + ///if (is_paint || is_sculpt) + else if (current_arg == "--reload-mesh") { + args_reimport_mesh = true; + } + else if (current_arg == "--export-mesh" && (i + 1) <= krom_get_arg_count()) { + args_export_mesh = true; + ++i; + args_export_mesh_path = krom_get_arg(i); + } + else if (Path.is_mesh(current_arg) || (i > 1 && !current_arg.startsWith("-") && Path.is_folder(current_arg))) { + args_asset_path = current_arg; + } + ///end + + ///if is_paint + else if (current_arg == "--export-material" && (i + 1) <= krom_get_arg_count()) { + args_export_material = true; + ++i; + args_export_material_path = krom_get_arg(i); + } + ///end + + ++i; + } + } +} + +function args_run() { + if (args_use) { + app_notify_on_init(() => { + if (Project.filepath != "") { + ImportArm.run_project(Project.filepath); + } + else if (args_asset_path != "") { + ImportAsset.run(args_asset_path, -1, -1, false); + ///if is_paint + if (Path.is_texture(args_asset_path)) { + UIBase.show_2d_view(view_2d_type_t.ASSET); + } + ///end + } + ///if (is_paint || is_sculpt) + else if (args_reimport_mesh) { + Project.reimport_mesh(); + } + ///end + + ///if (is_paint || is_lab) + if (args_export_textures) { + if (args_export_textures_type == "png" || + args_export_textures_type == "jpg" || + args_export_textures_type == "exr16" || + args_export_textures_type == "exr32") { + if (Path.is_folder(args_export_textures_path)) { + // Applying the correct format type from args + if (args_export_textures_type == "png") { + ///if is_paint + base_bits_handle.position = texture_bits_t.BITS8; + ///end + Context.raw.format_type = texture_ldr_format_t.PNG; + } + else if (args_export_textures_type == "jpg") { + ///if is_paint + base_bits_handle.position = texture_bits_t.BITS8; + ///end + Context.raw.format_type = texture_ldr_format_t.JPG; + } + else if (args_export_textures_type == "exr16") { + ///if is_paint + base_bits_handle.position = texture_bits_t.BITS16; + ///end + } + else if (args_export_textures_type == "exr32") { + ///if is_paint + base_bits_handle.position = texture_bits_t.BITS32; + ///end + } + + ///if is_paint + Context.raw.layers_export = export_mode_t.VISIBLE; + ///end + + // Get export preset and apply the correct one from args + BoxExport.files = File.read_directory(Path.data() + Path.sep + "export_presets"); + for (let i: i32 = 0; i < BoxExport.files.length; ++i) { + BoxExport.files[i] = BoxExport.files[i].substr(0, BoxExport.files[i].length - 5); // Strip .json + } + + let file: string = "export_presets/" + BoxExport.files[0] + ".json"; + for (let f of BoxExport.files) if (f == args_export_textures_preset) { + file = "export_presets/" + BoxExport.files[BoxExport.files.indexOf(f)] + ".json"; + } + + let blob: ArrayBuffer = data_get_blob(file); + BoxExport.preset = JSON.parse(sys_buffer_to_string(blob)); + data_delete_blob("export_presets/" + file); + + // Export queue + app_notify_on_init(() => { + ExportTexture.run(args_export_textures_path); + }); + } + else { + krom_log(tr("Invalid export directory")); + } + } + else { + krom_log(tr("Invalid texture type")); + } + } + ///end + + ///if (is_paint || is_sculpt) + else if (args_export_mesh) { + if (Path.is_folder(args_export_mesh_path)) { + let f: string = UIFiles.filename; + if (f == "") f = tr("untitled"); + ExportMesh.run(args_export_mesh_path + Path.sep + f, null, false); + } + else { + krom_log(tr("Invalid export directory")); + } + } + ///end + + ///if is_paint + else if (args_export_material) { + Context.raw.write_icon_on_export = true; + ExportArm.run_material(args_export_material_path); + } + ///end + + if (args_background) sys_stop(); + }); + } +} diff --git a/base/Sources/base.ts b/base/Sources/base.ts new file mode 100644 index 00000000..f05d538b --- /dev/null +++ b/base/Sources/base.ts @@ -0,0 +1,2273 @@ + +let base_ui_enabled: bool = true; +let base_is_dragging: bool = false; +let base_is_resizing: bool = false; +let base_drag_asset: asset_t = null; +let base_drag_swatch: swatch_color_t = null; +let base_drag_file: string = null; +let base_drag_file_icon: image_t = null; +let base_drag_tint = 0xffffffff; +let base_drag_size: i32 = -1; +let base_drag_rect: rect_t = null; +let base_drag_off_x: f32 = 0.0; +let base_drag_off_y: f32 = 0.0; +let base_drag_start: f32 = 0.0; +let base_drop_x: f32 = 0.0; +let base_drop_y: f32 = 0.0; +let base_font: g2_font_t = null; +let base_theme: theme_t; +let base_color_wheel: image_t; +let base_color_wheel_gradient: image_t; +let base_ui_box: zui_t; +let base_ui_menu: zui_t; +let base_default_element_w: i32 = 100; +let base_default_element_h: i32 = 28; +let base_default_font_size: i32 = 13; +let base_res_handle: zui_handle_t = zui_handle_create(); +let base_bits_handle: zui_handle_t = zui_handle_create(); +let base_drop_paths: string[] = []; +let base_appx: i32 = 0; +let base_appy: i32 = 0; +let base_last_window_width: i32 = 0; +let base_last_window_height: i32 = 0; +///if (is_paint || is_sculpt) +let base_drag_material: SlotMaterialRaw = null; +let base_drag_layer: SlotLayerRaw = null; +///end + +let base_pipe_copy: pipeline_t; +let base_pipe_copy8: pipeline_t; +let base_pipe_copy128: pipeline_t; +let base_pipe_copy_bgra: pipeline_t; +let base_pipe_copy_rgb: pipeline_t = null; +///if (is_paint || is_sculpt) +let base_pipe_merge: pipeline_t = null; +let base_pipe_merge_r: pipeline_t = null; +let base_pipe_merge_g: pipeline_t = null; +let base_pipe_merge_b: pipeline_t = null; +let base_pipe_merge_a: pipeline_t = null; +let base_pipe_invert8: pipeline_t; +let base_pipe_apply_mask: pipeline_t; +let base_pipe_merge_mask: pipeline_t; +let base_pipe_colorid_to_mask: pipeline_t; +let base_tex0: kinc_tex_unit_t; +let base_tex1: kinc_tex_unit_t; +let base_texmask: kinc_tex_unit_t; +let base_texa: kinc_tex_unit_t; +let base_opac: kinc_const_loc_t; +let base_blending: kinc_const_loc_t; +let base_tex0_mask: kinc_tex_unit_t; +let base_texa_mask: kinc_tex_unit_t; +let base_tex0_merge_mask: kinc_tex_unit_t; +let base_texa_merge_mask: kinc_tex_unit_t; +let base_tex_colorid: kinc_tex_unit_t; +let base_texpaint_colorid: kinc_tex_unit_t; +let base_opac_merge_mask: kinc_const_loc_t; +let base_blending_merge_mask: kinc_const_loc_t; +let base_temp_mask_image: image_t = null; +///end +///if is_lab +let base_pipe_copy_r: pipeline_t; +let base_pipe_copy_g: pipeline_t; +let base_pipe_copy_b: pipeline_t; +let base_pipe_copy_a: pipeline_t; +let base_pipe_copy_a_tex: kinc_tex_unit_t; +let base_pipe_inpaint_preview: pipeline_t; +let base_tex0_inpaint_preview: kinc_tex_unit_t; +let base_texa_inpaint_preview: kinc_tex_unit_t; +///end +let base_temp_image: image_t = null; +let base_expa: image_t = null; +let base_expb: image_t = null; +let base_expc: image_t = null; +let base_pipe_cursor: pipeline_t; +let base_cursor_vp: kinc_const_loc_t; +let base_cursor_inv_vp: kinc_const_loc_t; +let base_cursor_mouse: kinc_const_loc_t; +let base_cursor_tex_step: kinc_const_loc_t; +let base_cursor_radius: kinc_const_loc_t; +let base_cursor_camera_right: kinc_const_loc_t; +let base_cursor_tint: kinc_const_loc_t; +let base_cursor_tex: kinc_tex_unit_t; +let base_cursor_gbufferd: kinc_tex_unit_t; + +///if (is_paint || is_sculpt) +let base_default_base: f32 = 0.5; +let base_default_rough: f32 = 0.4; +///if (krom_android || krom_ios) +let base_max_layers: i32 = 18; +///else +let base_max_layers: i32 = 255; +///end +///end +let base_default_fov: f32 = 0.69; + +let base_default_keymap: any = { + action_paint: "left", + action_rotate: "alt+left", + action_pan: "alt+middle", + action_zoom: "alt+right", + rotate_light: "shift+middle", + rotate_envmap: "ctrl+middle", + set_clone_source: "alt", + stencil_transform: "ctrl", + stencil_hide: "z", + brush_radius: "f", + brush_radius_decrease: "[", + brush_radius_increase: "]", + brush_ruler: "shift", + file_new: "ctrl+n", + file_open: "ctrl+o", + file_open_recent: "ctrl+shift+o", + file_save: "ctrl+s", + file_save_as: "ctrl+shift+s", + file_reimport_mesh: "ctrl+r", + file_reimport_textures: "ctrl+shift+r", + file_import_assets: "ctrl+i", + file_export_textures: "ctrl+e", + file_export_textures_as: "ctrl+shift+e", + edit_undo: "ctrl+z", + edit_redo: "ctrl+shift+z", + edit_prefs: "ctrl+k", + view_reset: "0", + view_front: "1", + view_back: "ctrl+1", + view_right: "3", + view_left: "ctrl+3", + view_top: "7", + view_bottom: "ctrl+7", + view_camera_type: "5", + view_orbit_left: "4", + view_orbit_right: "6", + view_orbit_up: "8", + view_orbit_down: "2", + view_orbit_opposite: "9", + view_zoom_in: "", + view_zoom_out: "", + view_distract_free: "f11", + viewport_mode: "ctrl+m", + toggle_node_editor: "tab", + toggle_2d_view: "shift+tab", + toggle_browser: "`", + node_search: "space", + operator_search: "space", + ///if (is_paint || is_sculpt) + decal_mask: "ctrl", + select_material: "shift+number", + select_layer: "alt+number", + brush_opacity: "shift+f", + brush_angle: "alt+f", + tool_brush: "b", + tool_eraser: "e", + tool_fill: "g", + tool_decal: "d", + tool_text: "t", + tool_clone: "l", + tool_blur: "u", + tool_smudge: "m", + tool_particle: "p", + tool_colorid: "c", + tool_picker: "v", + tool_bake: "k", + tool_gizmo: "", + tool_material: "", + swap_brush_eraser: "", + ///end +}; + +function base_init() { + base_last_window_width = sys_width(); + base_last_window_height = sys_height(); + + sys_notify_on_drop_files(function(drop_path: string) { + ///if krom_linux + drop_path = decodeURIComponent(drop_path); + ///end + drop_path = trim_end(drop_path); + base_drop_paths.push(drop_path); + }); + + sys_notify_on_app_state( + function() { // Foreground + Context.raw.foreground_event = true; + Context.raw.last_paint_x = -1; + Context.raw.last_paint_y = -1; + }, + function() {}, // Resume + function() {}, // Pause + function() { // Background + // Release keys after alt-tab / win-tab + keyboard_up_listener(key_code_t.ALT); + keyboard_up_listener(key_code_t.WIN); + }, + function() { // Shutdown + ///if (krom_android || krom_ios) + Project.project_save(); + ///end + } + ); + + krom_set_save_and_quit_callback(base_save_and_quit_callback); + + let f: g2_font_t = data_get_font("font.ttf"); + let image_color_wheel: image_t = data_get_image("color_wheel.k"); + let image_color_wheel_gradient: image_t = data_get_image("color_wheel_gradient.k"); + + base_font = f; + Config.load_theme(Config.raw.theme, false); + base_default_element_w = base_theme.ELEMENT_W; + base_default_font_size = base_theme.FONT_SIZE; + Translator.load_translations(Config.raw.locale); + UIFiles.filename = tr("untitled"); + ///if (krom_android || krom_ios) + sys_title_set(tr("untitled")); + ///end + + // Baked font for fast startup + if (Config.raw.locale == "en") { + base_font.font_ = krom_g2_font_13(base_font.blob); + base_font.glyphs = _g2_font_glyphs; + } + else g2_font_init(base_font); + + base_color_wheel = image_color_wheel; + base_color_wheel_gradient = image_color_wheel_gradient; + zui_set_enum_texts(base_enum_texts); + zui_tr = tr; + base_ui_box = zui_create({ theme: base_theme, font: f, scale_factor: Config.raw.window_scale, color_wheel: base_color_wheel, black_white_gradient: base_color_wheel_gradient }); + base_ui_menu = zui_create({ theme: base_theme, font: f, scale_factor: Config.raw.window_scale, color_wheel: base_color_wheel, black_white_gradient: base_color_wheel_gradient }); + base_default_element_h = base_ui_menu.t.ELEMENT_H; + + // Init plugins + if (Config.raw.plugins != null) { + for (let plugin of Config.raw.plugins) { + Plugin.start(plugin); + } + } + + args_parse(); + + new Camera(); + new UIBase(); + new UINodes(); + new UIView2D(); + + ///if is_lab + RandomNode.setSeed(Math.floor(time_time() * 4294967295)); + ///end + + app_notify_on_update(base_update); + app_notify_on_render_2d(UIView2D.render); + app_notify_on_update(UIView2D.update); + ///if (is_paint || is_sculpt) + app_notify_on_render_2d(UIBase.render_cursor); + ///end + app_notify_on_update(UINodes.update); + app_notify_on_render_2d(UINodes.render); + app_notify_on_update(UIBase.update); + app_notify_on_render_2d(UIBase.render); + app_notify_on_update(Camera.update); + app_notify_on_render_2d(base_render); + + ///if (is_paint || is_sculpt) + base_appx = UIToolbar.toolbar_w; + ///end + ///if is_lab + base_appx = 0; + ///end + + base_appy = UIHeader.headerh; + if (Config.raw.layout[layout_size_t.HEADER] == 1) base_appy += UIHeader.headerh; + let cam: camera_object_t = scene_camera; + cam.data.fov = Math.floor(cam.data.fov * 100) / 100; + camera_object_build_proj(cam); + + args_run(); + + ///if (krom_android || krom_ios) + let has_projects: bool = Config.raw.recent_projects.length > 0; + ///else + let has_projects: bool = true; + ///end + + if (Config.raw.splash_screen && has_projects) { + BoxProjects.show(); + } +} + +function base_save_and_quit_callback(save: bool) { + base_save_window_rect(); + if (save) Project.project_save(true); + else sys_stop(); +} + +///if (is_paint || is_sculpt) +function base_w(): i32 { + // Drawing material preview + if (Context.raw.material_preview) { + return UtilRender.material_preview_size; + } + + // Drawing decal preview + if (Context.raw.decal_preview) { + return UtilRender.decal_preview_size; + } + + let res: i32 = 0; + if (Config.raw.layout == null) { + let sidebarw: i32 = UIBase.default_sidebar_w; + res = sys_width() - sidebarw - UIToolbar.default_toolbar_w; + } + else if (UINodes.show || UIView2D.show) { + res = sys_width() - Config.raw.layout[layout_size_t.SIDEBAR_W] - Config.raw.layout[layout_size_t.NODES_W] - UIToolbar.toolbar_w; + } + else if (UIBase.show) { + res = sys_width() - Config.raw.layout[layout_size_t.SIDEBAR_W] - UIToolbar.toolbar_w; + } + else { // Distract free + res = sys_width(); + } + if (Context.raw.view_index > -1) { + res = Math.floor(res / 2); + } + if (Context.raw.paint2d_view) { + res = UIView2D.ww; + } + + return res > 0 ? res : 1; // App was minimized, force render path resize +} + +function base_h(): i32 { + // Drawing material preview + if (Context.raw.material_preview) { + return UtilRender.material_preview_size; + } + + // Drawing decal preview + if (Context.raw.decal_preview) { + return UtilRender.decal_preview_size; + } + + let res: i32 = sys_height(); + + if (Config.raw.layout == null) { + res -= UIHeader.default_header_h * 2 + UIStatus.default_status_h; + + ///if (krom_android || krom_ios) + let layout_header: i32 = 0; + ///else + let layout_header: i32 = 1; + ///end + if (layout_header == 0) { + res += UIHeader.headerh; + } + } + else if (UIBase.show && res > 0) { + let statush: i32 = Config.raw.layout[layout_size_t.STATUS_H]; + res -= Math.floor(UIHeader.default_header_h * 2 * Config.raw.window_scale) + statush; + + if (Config.raw.layout[layout_size_t.HEADER] == 0) { + res += UIHeader.headerh; + } + } + + return res > 0 ? res : 1; // App was minimized, force render path resize +} +///end + +///if is_lab +function base_w(): i32 { + let res: i32 = 0; + if (UINodes == null) { + res = sys_width(); + } + else if (UINodes.show || UIView2D.show) { + res = sys_width() - Config.raw.layout[layout_size_t.NODES_W]; + } + else { // Distract free + res = sys_width(); + } + + return res > 0 ? res : 1; // App was minimized, force render path resize +} + +function base_h(): i32 { + let res: i32 = sys_height(); + if (UIBase == null) { + res -= UIHeader.default_header_h * 2 + UIStatus.default_status_h; + } + else if (res > 0) { + let statush: i32 = Config.raw.layout[layout_size_t.STATUS_H]; + res -= Math.floor(UIHeader.default_header_h * 2 * Config.raw.window_scale) + statush; + } + + return res > 0 ? res : 1; // App was minimized, force render path resize +} +///end + +function base_x(): i32 { + ///if (is_paint || is_sculpt) + return Context.raw.view_index == 1 ? base_appx + base_w() : base_appx; + ///end + ///if is_lab + return base_appx; + ///end +} + +function base_y(): i32 { + return base_appy; +} + +function base_on_resize() { + if (sys_width() == 0 || sys_height() == 0) return; + + let ratio_w: f32 = sys_width() / base_last_window_width; + base_last_window_width = sys_width(); + let ratio_h: f32 = sys_height() / base_last_window_height; + base_last_window_height = sys_height(); + + Config.raw.layout[layout_size_t.NODES_W] = Math.floor(Config.raw.layout[layout_size_t.NODES_W] * ratio_w); + ///if (is_paint || is_sculpt) + Config.raw.layout[layout_size_t.SIDEBAR_H0] = Math.floor(Config.raw.layout[layout_size_t.SIDEBAR_H0] * ratio_h); + Config.raw.layout[layout_size_t.SIDEBAR_H1] = sys_height() - Config.raw.layout[layout_size_t.SIDEBAR_H0]; + ///end + + base_resize(); + + ///if (krom_linux || krom_darwin) + base_save_window_rect(); + ///end +} + +function base_save_window_rect() { + ///if (krom_windows || krom_linux || krom_darwin) + Config.raw.window_w = sys_width(); + Config.raw.window_h = sys_height(); + Config.raw.window_x = sys_x(); + Config.raw.window_y = sys_y(); + Config.save(); + ///end +} + +function base_resize() { + if (sys_width() == 0 || sys_height() == 0) return; + + let cam: camera_object_t = scene_camera; + if (cam.data.ortho != null) { + cam.data.ortho[2] = -2 * (app_h() / app_w()); + cam.data.ortho[3] = 2 * (app_h() / app_w()); + } + camera_object_build_proj(cam); + + if (Context.raw.camera_type == camera_type_t.ORTHOGRAPHIC) { + Viewport.update_camera_type(Context.raw.camera_type); + } + + Context.raw.ddirty = 2; + + if (UIBase.show) { + ///if (is_paint || is_sculpt) + base_appx = UIToolbar.toolbar_w; + ///end + ///if is_lab + base_appx = 0; + ///end + base_appy = UIHeader.headerh * 2; + if (Config.raw.layout[layout_size_t.HEADER] == 0) { + base_appy -= UIHeader.headerh; + } + } + else { + base_appx = 0; + base_appy = 0; + } + + if (UINodes.grid != null) { + let _grid: image_t = UINodes.grid; + let _next = function() { + image_unload(_grid); + } + base_notify_on_next_frame(_next); + UINodes.grid = null; + } + + base_redraw_ui(); +} + +function base_redraw_ui() { + UIHeader.header_handle.redraws = 2; + UIBase.hwnds[tab_area_t.STATUS].redraws = 2; + UIMenubar.menu_handle.redraws = 2; + UIMenubar.workspace_handle.redraws = 2; + UINodes.hwnd.redraws = 2; + UIBox.hwnd.redraws = 2; + UIView2D.hwnd.redraws = 2; + if (Context.raw.ddirty < 0) Context.raw.ddirty = 0; // Redraw viewport + ///if (is_paint || is_sculpt) + UIBase.hwnds[tab_area_t.SIDEBAR0].redraws = 2; + UIBase.hwnds[tab_area_t.SIDEBAR1].redraws = 2; + UIToolbar.toolbar_handle.redraws = 2; + if (Context.raw.split_view) Context.raw.ddirty = 1; + ///end +} + +function base_update() { + if (mouse_movement_x != 0 || mouse_movement_y != 0) { + krom_set_mouse_cursor(0); // Arrow + } + + ///if (is_paint || is_sculpt) + let has_drag: bool = base_drag_asset != null || base_drag_material != null || base_drag_layer != null || base_drag_file != null || base_drag_swatch != null; + ///end + ///if is_lab + let has_drag: bool = base_drag_asset != null || base_drag_file != null || base_drag_swatch != null; + ///end + + if (Config.raw.touch_ui) { + // Touch and hold to activate dragging + if (base_drag_start < 0.2) { + if (has_drag && mouse_down()) base_drag_start += time_real_delta(); + else base_drag_start = 0; + has_drag = false; + } + if (mouse_released()) { + base_drag_start = 0; + } + let moved: bool = Math.abs(mouse_movement_x) > 1 && Math.abs(mouse_movement_y) > 1; + if ((mouse_released() || moved) && !has_drag) { + base_drag_asset = null; + base_drag_swatch = null; + base_drag_file = null; + base_drag_file_icon = null; + base_is_dragging = false; + ///if (is_paint || is_sculpt) + base_drag_material = null; + base_drag_layer = null; + ///end + } + // Disable touch scrolling while dragging is active + zui_set_touch_scroll(!base_is_dragging); + } + + if (has_drag && (mouse_movement_x != 0 || mouse_movement_y != 0)) { + base_is_dragging = true; + } + if (mouse_released() && has_drag) { + if (base_drag_asset != null) { + if (Context.in_nodes()) { // Create image texture + UINodes.accept_asset_drag(Project.assets.indexOf(base_drag_asset)); + } + else if (Context.in_viewport()) { + if (base_drag_asset.file.toLowerCase().endsWith(".hdr")) { + let image: image_t = Project.get_image(base_drag_asset); + ImportEnvmap.run(base_drag_asset.file, image); + } + } + ///if (is_paint || is_sculpt) + else if (Context.in_layers() || Context.in_2d_view()) { // Create mask + base_create_image_mask(base_drag_asset); + } + ///end + base_drag_asset = null; + } + else if (base_drag_swatch != null) { + if (Context.in_nodes()) { // Create RGB node + UINodes.accept_swatch_drag(base_drag_swatch); + } + else if (Context.in_swatches()) { + TabSwatches.accept_swatch_drag(base_drag_swatch); + } + ///if (is_paint || is_sculpt) + else if (Context.in_materials()) { + TabMaterials.accept_swatch_drag(base_drag_swatch); + } + else if (Context.in_viewport()) { + let color: i32 = base_drag_swatch.base; + color = color_set_ab(color, base_drag_swatch.opacity * 255); + base_create_color_layer(color, base_drag_swatch.occlusion, base_drag_swatch.roughness, base_drag_swatch.metallic); + } + else if (Context.in_layers() && TabLayers.can_drop_new_layer(Context.raw.drag_dest)) { + let color: i32 = base_drag_swatch.base; + color = color_set_ab(color, base_drag_swatch.opacity * 255); + base_create_color_layer(color, base_drag_swatch.occlusion, base_drag_swatch.roughness, base_drag_swatch.metallic, Context.raw.drag_dest); + } + ///end + + base_drag_swatch = null; + } + else if (base_drag_file != null) { + if (!Context.in_browser()) { + base_drop_x = mouse_x; + base_drop_y = mouse_y; + + ///if (is_paint || is_sculpt) + let material_count: i32 = Project.materials.length; + ImportAsset.run(base_drag_file, base_drop_x, base_drop_y, true, true, function() { + // Asset was material + if (Project.materials.length > material_count) { + base_drag_material = Context.raw.material; + base_material_dropped(); + } + }); + ///end + + ///if is_lab + ImportAsset.run(base_drag_file, base_drop_x, base_drop_y); + ///end + } + base_drag_file = null; + base_drag_file_icon = null; + } + ///if (is_paint || is_sculpt) + else if (base_drag_material != null) { + base_material_dropped(); + } + else if (base_drag_layer != null) { + if (Context.in_nodes()) { + UINodes.accept_layer_drag(Project.layers.indexOf(base_drag_layer)); + } + else if (Context.in_layers() && base_is_dragging) { + SlotLayer.move(base_drag_layer, Context.raw.drag_dest); + MakeMaterial.parse_mesh_material(); + } + base_drag_layer = null; + } + ///end + + krom_set_mouse_cursor(0); // Arrow + base_is_dragging = false; + } + if (Context.raw.color_picker_callback != null && (mouse_released() || mouse_released("right"))) { + Context.raw.color_picker_callback = null; + Context.select_tool(Context.raw.color_picker_previous_tool); + } + + base_handle_drop_paths(); + + ///if (is_paint || is_sculpt) + ///if krom_windows + let is_picker: bool = Context.raw.tool == workspace_tool_t.PICKER || Context.raw.tool == workspace_tool_t.MATERIAL; + let decal: bool = Context.raw.tool == workspace_tool_t.DECAL || Context.raw.tool == workspace_tool_t.TEXT; + zui_set_always_redraw_window(!Context.raw.cache_draws || + UIMenu.show || + UIBox.show || + base_is_dragging || + is_picker || + decal || + UIView2D.show || + !Config.raw.brush_3d || + Context.raw.frame < 3); + ///end + ///end + + if (zui_always_redraw_window() && Context.raw.ddirty < 0) Context.raw.ddirty = 0; +} + +///if (is_paint || is_sculpt) +function base_material_dropped() { + // Material drag and dropped onto viewport or layers tab + if (Context.in_viewport()) { + let uv_type: uv_type_t = keyboard_down("control") ? uv_type_t.PROJECT : uv_type_t.UVMAP; + let decal_mat: mat4_t = uv_type == uv_type_t.PROJECT ? UtilRender.get_decal_mat() : null; + base_create_fill_layer(uv_type, decal_mat); + } + if (Context.in_layers() && TabLayers.can_drop_new_layer(Context.raw.drag_dest)) { + let uv_type: uv_type_t = keyboard_down("control") ? uv_type_t.PROJECT : uv_type_t.UVMAP; + let decal_mat: mat4_t = uv_type == uv_type_t.PROJECT ? UtilRender.get_decal_mat() : null; + base_create_fill_layer(uv_type, decal_mat, Context.raw.drag_dest); + } + else if (Context.in_nodes()) { + UINodes.accept_material_drag(Project.materials.indexOf(base_drag_material)); + } + base_drag_material = null; +} +///end + +function base_handle_drop_paths() { + if (base_drop_paths.length > 0) { + ///if (krom_linux || krom_darwin) + let wait: bool = !mouse_moved; // Mouse coords not updated during drag + ///else + let wait: bool = false; + ///end + if (!wait) { + base_drop_x = mouse_x; + base_drop_y = mouse_y; + let drop_path: string = base_drop_paths.shift(); + ImportAsset.run(drop_path, base_drop_x, base_drop_y); + } + } +} + +///if (is_paint || is_sculpt) +function base_get_drag_background(): rect_t { + let icons: image_t = Res.get("icons.k"); + if (base_drag_layer != null && !SlotLayer.is_group(base_drag_layer) && base_drag_layer.fill_layer == null) { + return Res.tile50(icons, 4, 1); + } + return null; +} +///end + +function base_get_drag_image(): image_t { + base_drag_tint = 0xffffffff; + base_drag_size = -1; + base_drag_rect = null; + if (base_drag_asset != null) { + return Project.get_image(base_drag_asset); + } + if (base_drag_swatch != null) { + base_drag_tint = base_drag_swatch.base; + base_drag_size = 26; + return TabSwatches.empty; + } + if (base_drag_file != null) { + if (base_drag_file_icon != null) return base_drag_file_icon; + let icons: image_t = Res.get("icons.k"); + base_drag_rect = base_drag_file.indexOf(".") > 0 ? Res.tile50(icons, 3, 1) : Res.tile50(icons, 2, 1); + base_drag_tint = UIBase.ui.t.HIGHLIGHT_COL; + return icons; + } + + ///if is_paint + if (base_drag_material != null) { + return base_drag_material.image_icon; + } + if (base_drag_layer != null && SlotLayer.is_group(base_drag_layer)) { + let icons: image_t = Res.get("icons.k"); + let folder_closed: rect_t = Res.tile50(icons, 2, 1); + let folder_open: rect_t = Res.tile50(icons, 8, 1); + base_drag_rect = base_drag_layer.show_panel ? folder_open : folder_closed; + base_drag_tint = UIBase.ui.t.LABEL_COL - 0x00202020; + return icons; + } + if (base_drag_layer != null && SlotLayer.is_mask(base_drag_layer) && base_drag_layer.fill_layer == null) { + TabLayers.make_mask_preview_rgba32(base_drag_layer); + return Context.raw.mask_preview_rgba32; + } + if (base_drag_layer != null) { + return base_drag_layer.fill_layer != null ? base_drag_layer.fill_layer.image_icon : base_drag_layer.texpaint_preview; + } + ///end + + return null; +} + +function base_render() { + if (sys_width() == 0 || sys_height() == 0) return; + + if (Context.raw.frame == 2) { + ///if (is_paint || is_sculpt) + UtilRender.make_material_preview(); + UIBase.hwnds[tab_area_t.SIDEBAR1].redraws = 2; + ///end + + MakeMaterial.parse_mesh_material(); + MakeMaterial.parse_paint_material(); + Context.raw.ddirty = 0; + + ///if (is_paint || is_sculpt) + if (History.undo_layers == null) { + History.undo_layers = []; + for (let i: i32 = 0; i < Config.raw.undo_steps; ++i) { + let l: SlotLayerRaw = SlotLayer.create("_undo" + History.undo_layers.length); + History.undo_layers.push(l); + } + } + ///end + + // Default workspace + if (Config.raw.workspace != 0) { + UIHeader.worktab.position = Config.raw.workspace; + UIMenubar.workspace_handle.redraws = 2; + UIHeader.worktab.changed = true; + } + + // Default camera controls + Context.raw.camera_controls = Config.raw.camera_controls; + + ///if is_lab + base_notify_on_next_frame(function() { + base_notify_on_next_frame(function() { + TabMeshes.set_default_mesh(".Sphere"); + }); + }); + ///end + + ///if is_sculpt + base_notify_on_next_frame(function() { + base_notify_on_next_frame(function() { + Context.raw.project_type = project_model_t.SPHERE; + Project.project_new(); + }); + }); + ///end + } + else if (Context.raw.frame == 3) { + Context.raw.ddirty = 3; + } + Context.raw.frame++; + + if (base_is_dragging) { + krom_set_mouse_cursor(1); // Hand + let img: image_t = base_get_drag_image(); + + ///if (is_paint || is_sculpt) + let scale_factor: f32 = zui_SCALE(UIBase.ui); + ///end + ///if is_lab + let scale_factor: f32 = zui_SCALE(base_ui_box); + ///end + + let size: f32 = (base_drag_size == -1 ? 50 : base_drag_size) * scale_factor; + let ratio: f32 = size / img.width; + let h: f32 = img.height * ratio; + + ///if (is_lab || krom_direct3d11 || krom_direct3d12 || krom_metal || krom_vulkan) + let inv: i32 = 0; + ///else + let inv: i32 = (base_drag_material != null || (base_drag_layer != null && base_drag_layer.fill_layer != null)) ? h : 0; + ///end + + g2_set_color(base_drag_tint); + + ///if (is_paint || is_sculpt) + let bg_rect: rect_t = base_get_drag_background(); + if (bg_rect != null) { + g2_draw_scaled_sub_image(Res.get("icons.k"), bg_rect.x, bg_rect.y, bg_rect.w, bg_rect.h, mouse_x + base_drag_off_x, mouse_y + base_drag_off_y + inv, size, h - inv * 2); + } + ///end + + base_drag_rect == null ? + g2_draw_scaled_image(img, mouse_x + base_drag_off_x, mouse_y + base_drag_off_y + inv, size, h - inv * 2) : + g2_draw_scaled_sub_image(img, base_drag_rect.x, base_drag_rect.y, base_drag_rect.w, base_drag_rect.h, mouse_x + base_drag_off_x, mouse_y + base_drag_off_y + inv, size, h - inv * 2); + g2_set_color(0xffffffff); + } + + let using_menu: bool = UIMenu.show && mouse_y > UIHeader.headerh; + base_ui_enabled = !UIBox.show && !using_menu && !base_is_combo_selected(); + if (UIBox.show) UIBox.render(); + if (UIMenu.show) UIMenu.render(); + + // Save last pos for continuos paint + Context.raw.last_paint_vec_x = Context.raw.paint_vec.x; + Context.raw.last_paint_vec_y = Context.raw.paint_vec.y; + + ///if (krom_android || krom_ios) + // No mouse move events for touch, re-init last paint position on touch start + if (!mouse_down()) { + Context.raw.last_paint_x = -1; + Context.raw.last_paint_y = -1; + } + ///end +} + +function base_enum_texts(node_type: string): string[] { + ///if (is_paint || is_sculpt) + if (node_type == "TEX_IMAGE") { + return Project.asset_names.length > 0 ? Project.asset_names : [""]; + } + if (node_type == "LAYER" || node_type == "LAYER_MASK") { + let layer_names: string[] = []; + for (let l of Project.layers) layer_names.push(l.name); + return layer_names; + } + if (node_type == "MATERIAL") { + let material_names: string[] = []; + for (let m of Project.materials) material_names.push(m.canvas.name); + return material_names; + } + ///end + + ///if is_lab + if (node_type == "ImageTextureNode") { + return Project.asset_names.length > 0 ? Project.asset_names : [""]; + } + ///end + + return null; +} + +function base_get_asset_index(fileName: string): i32 { + let i: i32 = Project.asset_names.indexOf(fileName); + return i >= 0 ? i : 0; +} + +function base_notify_on_next_frame(f: ()=>void) { + let _render = function() { + app_notify_on_init(function() { + let _update = function() { + app_notify_on_init(f); + app_remove_update(_update); + } + app_notify_on_update(_update); + }); + app_remove_render(_render); + } + app_notify_on_render(_render); +} + +function base_toggle_fullscreen() { + if (sys_mode() == window_mode_t.WINDOWED) { + ///if (krom_windows || krom_linux || krom_darwin) + Config.raw.window_w = sys_width(); + Config.raw.window_h = sys_height(); + Config.raw.window_x = sys_x(); + Config.raw.window_y = sys_y(); + ///end + sys_mode_set(window_mode_t.FULLSCREEN); + } + else { + sys_mode_set(window_mode_t.WINDOWED); + sys_resize(Config.raw.window_w, Config.raw.window_h); + sys_move(Config.raw.window_x, Config.raw.window_y); + } +} + +function base_is_scrolling(): bool { + for (let ui of base_get_uis()) if (ui.is_scrolling) return true; + return false; +} + +function base_is_combo_selected(): bool { + for (let ui of base_get_uis()) if (ui.combo_selected_handle_ptr != 0) return true; + return false; +} + +function base_get_uis(): zui_t[] { + return [base_ui_box, base_ui_menu, UIBase.ui, UINodes.ui, UIView2D.ui]; +} + +function base_is_decal_layer(): bool { + ///if is_paint + let is_paint: bool = Context.raw.tool != workspace_tool_t.MATERIAL && Context.raw.tool != workspace_tool_t.BAKE; + return is_paint && Context.raw.layer.fill_layer != null && Context.raw.layer.uv_type == uv_type_t.PROJECT; + ///end + + ///if (is_sculpt || is_lab) + return false; + ///end +} + +function base_redraw_status() { + UIBase.hwnds[tab_area_t.STATUS].redraws = 2; +} + +function base_redraw_console() { + let statush: i32 = Config.raw.layout[layout_size_t.STATUS_H]; + if (UIBase.ui != null && statush > UIStatus.default_status_h * zui_SCALE(UIBase.ui)) { + UIBase.hwnds[tab_area_t.STATUS].redraws = 2; + } +} + +function base_init_layout() { + let show2d: bool = (UINodes != null && UINodes.show) || (UIView2D != null && UIView2D.show); + + let raw: config_t = Config.raw; + raw.layout = [ + ///if (is_paint || is_sculpt) + Math.floor(UIBase.default_sidebar_w * raw.window_scale), // LayoutSidebarW + Math.floor(sys_height() / 2), // LayoutSidebarH0 + Math.floor(sys_height() / 2), // LayoutSidebarH1 + ///end + + ///if krom_ios + show2d ? Math.floor((app_w() + raw.layout[layout_size_t.NODES_W]) * 0.473) : Math.floor(app_w() * 0.473), // LayoutNodesW + ///elseif krom_android + show2d ? Math.floor((app_w() + raw.layout[layout_size_t.NODES_W]) * 0.473) : Math.floor(app_w() * 0.473), + ///else + show2d ? Math.floor((app_w() + raw.layout[layout_size_t.NODES_W]) * 0.515) : Math.floor(app_w() * 0.515), // Align with ui header controls + ///end + + Math.floor(app_h() / 2), // LayoutNodesH + Math.floor(UIStatus.default_status_h * raw.window_scale), // LayoutStatusH + + ///if (krom_android || krom_ios) + 0, // LayoutHeader + ///else + 1, + ///end + ]; + + raw.layout_tabs = [ + ///if (is_paint || is_sculpt) + 0, + 0, + ///end + 0 + ]; +} + +function base_init_config() { + let raw: config_t = Config.raw; + raw.recent_projects = []; + raw.bookmarks = []; + raw.plugins = []; + ///if (krom_android || krom_ios) + raw.keymap = "touch.json"; + ///else + raw.keymap = "default.json"; + ///end + raw.theme = "default.json"; + raw.server = "https://armorpaint.fra1.digitaloceanspaces.com"; + raw.undo_steps = 4; + raw.pressure_radius = true; + raw.pressure_sensitivity = 1.0; + raw.camera_zoom_speed = 1.0; + raw.camera_pan_speed = 1.0; + raw.camera_rotation_speed = 1.0; + raw.zoom_direction = zoom_direction_t.VERTICAL; + ///if (is_paint || is_sculpt) + raw.displace_strength = 0.0; + ///else + raw.displace_strength = 1.0; + ///end + raw.wrap_mouse = false; + ///if is_paint + raw.workspace = space_type_t.SPACE3D; + ///end + ///if is_sculpt + raw.workspace = space_type_t.SPACE3D; + ///end + ///if is_lab + raw.workspace = space_type_t.SPACE2D; + ///end + ///if (krom_android || krom_ios) + raw.camera_controls = camera_controls_t.ROTATE; + ///else + raw.camera_controls = camera_controls_t.ORBIT; + ///end + raw.layer_res = texture_res_t.RES2048; + ///if (krom_android || krom_ios) + raw.touch_ui = true; + raw.splash_screen = true; + ///else + raw.touch_ui = false; + raw.splash_screen = false; + ///end + ///if (is_paint || is_sculpt) + raw.node_preview = true; + ///else + raw.node_preview = false; + ///end + + ///if (is_paint || is_sculpt) + raw.pressure_hardness = true; + raw.pressure_angle = false; + raw.pressure_opacity = false; + ///if (krom_vulkan || krom_ios) + raw.material_live = false; + ///else + raw.material_live = true; + ///end + raw.brush_3d = true; + raw.brush_depth_reject = true; + raw.brush_angle_reject = true; + raw.brush_live = false; + raw.show_asset_names = false; + ///end + + ///if is_paint + raw.dilate = dilate_type_t.INSTANT; + raw.dilate_radius = 2; + ///end + + ///if is_lab + raw.gpu_inference = true; + ///end +} + +function base_init_layers() { + ///if (is_paint || is_sculpt) + SlotLayer.clear(Project.layers[0], color_from_floats(base_default_base, base_default_base, base_default_base, 1.0)); + ///end + + ///if is_lab + let texpaint: image_t = render_path_render_targets.get("texpaint")._image; + let texpaint_nor: image_t = render_path_render_targets.get("texpaint_nor")._image; + let texpaint_pack: image_t = render_path_render_targets.get("texpaint_pack")._image; + g2_begin(texpaint); + g2_draw_scaled_image(Res.get("placeholder.k"), 0, 0, Config.get_texture_res_x(), Config.get_texture_res_y()); // Base + g2_end(); + g4_begin(texpaint_nor); + g4_clear(color_from_floats(0.5, 0.5, 1.0, 0.0)); // Nor + g4_end(); + g4_begin(texpaint_pack); + g4_clear(color_from_floats(1.0, 0.4, 0.0, 0.0)); // Occ, rough, met + g4_end(); + let texpaint_nor_empty: image_t = render_path_render_targets.get("texpaint_nor_empty")._image; + let texpaint_pack_empty: image_t = render_path_render_targets.get("texpaint_pack_empty")._image; + g4_begin(texpaint_nor_empty); + g4_clear(color_from_floats(0.5, 0.5, 1.0, 0.0)); // Nor + g4_end(); + g4_begin(texpaint_pack_empty); + g4_clear(color_from_floats(1.0, 0.4, 0.0, 0.0)); // Occ, rough, met + g4_end(); + ///end +} + +///if (is_paint || is_sculpt) +function base_resize_layers() { + let conf: config_t = Config.raw; + if (base_res_handle.position >= Math.floor(texture_res_t.RES16384)) { // Save memory for >=16k + conf.undo_steps = 1; + if (Context.raw.undo_handle != null) { + Context.raw.undo_handle.value = conf.undo_steps; + } + while (History.undo_layers.length > conf.undo_steps) { + let l: SlotLayerRaw = History.undo_layers.pop(); + base_notify_on_next_frame(function() { + SlotLayer.unload(l); + }); + } + } + for (let l of Project.layers) SlotLayer.resize_and_set_bits(l); + for (let l of History.undo_layers) SlotLayer.resize_and_set_bits(l); + let rts: map_t = render_path_render_targets; + let _texpaint_blend0: image_t = rts.get("texpaint_blend0")._image; + base_notify_on_next_frame(function() { + image_unload(_texpaint_blend0); + }); + rts.get("texpaint_blend0").width = Config.get_texture_res_x(); + rts.get("texpaint_blend0").height = Config.get_texture_res_y(); + rts.get("texpaint_blend0")._image = image_create_render_target(Config.get_texture_res_x(), Config.get_texture_res_y(), tex_format_t.R8); + let _texpaint_blend1: image_t = rts.get("texpaint_blend1")._image; + base_notify_on_next_frame(function() { + image_unload(_texpaint_blend1); + }); + rts.get("texpaint_blend1").width = Config.get_texture_res_x(); + rts.get("texpaint_blend1").height = Config.get_texture_res_y(); + rts.get("texpaint_blend1")._image = image_create_render_target(Config.get_texture_res_x(), Config.get_texture_res_y(), tex_format_t.R8); + Context.raw.brush_blend_dirty = true; + if (rts.get("texpaint_blur") != null) { + let _texpaint_blur: image_t = rts.get("texpaint_blur")._image; + base_notify_on_next_frame(function() { + image_unload(_texpaint_blur); + }); + let size_x: f32 = Math.floor(Config.get_texture_res_x() * 0.95); + let size_y: f32 = Math.floor(Config.get_texture_res_y() * 0.95); + rts.get("texpaint_blur").width = size_x; + rts.get("texpaint_blur").height = size_y; + rts.get("texpaint_blur")._image = image_create_render_target(size_x, size_y); + } + if (RenderPathPaint.live_layer != null) SlotLayer.resize_and_set_bits(RenderPathPaint.live_layer); + ///if (krom_direct3d12 || krom_vulkan || krom_metal) + RenderPathRaytrace.ready = false; // Rebuild baketex + ///end + Context.raw.ddirty = 2; +} + +function base_set_layer_bits() { + for (let l of Project.layers) SlotLayer.resize_and_set_bits(l); + for (let l of History.undo_layers) SlotLayer.resize_and_set_bits(l); +} + +function base_make_merge_pipe(red: bool, green: bool, blue: bool, alpha: bool): pipeline_t { + let pipe: pipeline_t = g4_pipeline_create(); + pipe.vertex_shader = sys_get_shader("pass.vert"); + pipe.fragment_shader = sys_get_shader("layer_merge.frag"); + let vs: vertex_struct_t = g4_vertex_struct_create(); + g4_vertex_struct_add(vs, "pos", vertex_data_t.F32_2X); + pipe.input_layout = [vs]; + pipe.color_write_masks_red = [red]; + pipe.color_write_masks_green = [green]; + pipe.color_write_masks_blue = [blue]; + pipe.color_write_masks_alpha = [alpha]; + g4_pipeline_compile(pipe); + return pipe; +} +///end + +function base_make_pipe() { + ///if (is_paint || is_sculpt) + base_pipe_merge = base_make_merge_pipe(true, true, true, true); + base_pipe_merge_r = base_make_merge_pipe(true, false, false, false); + base_pipe_merge_g = base_make_merge_pipe(false, true, false, false); + base_pipe_merge_b = base_make_merge_pipe(false, false, true, false); + base_pipe_merge_a = base_make_merge_pipe(false, false, false, true); + base_tex0 =g4_pipeline_get_tex_unit(base_pipe_merge, "tex0"); // Always binding texpaint.a for blending + base_tex1 =g4_pipeline_get_tex_unit(base_pipe_merge, "tex1"); + base_texmask =g4_pipeline_get_tex_unit(base_pipe_merge, "texmask"); + base_texa =g4_pipeline_get_tex_unit(base_pipe_merge, "texa"); + base_opac =g4_pipeline_get_const_loc(base_pipe_merge, "opac"); + base_blending =g4_pipeline_get_const_loc(base_pipe_merge, "blending"); + ///end + + { + base_pipe_copy = g4_pipeline_create(); + base_pipe_copy.vertex_shader = sys_get_shader("layer_view.vert"); + base_pipe_copy.fragment_shader = sys_get_shader("layer_copy.frag"); + let vs: vertex_struct_t = g4_vertex_struct_create(); + g4_vertex_struct_add(vs, "pos", vertex_data_t.F32_3X); + g4_vertex_struct_add(vs, "tex", vertex_data_t.F32_2X); + g4_vertex_struct_add(vs, "col", vertex_data_t.U8_4X_NORM); + base_pipe_copy.input_layout = [vs]; + g4_pipeline_compile(base_pipe_copy); + } + + { + base_pipe_copy_bgra = g4_pipeline_create(); + base_pipe_copy_bgra.vertex_shader = sys_get_shader("layer_view.vert"); + base_pipe_copy_bgra.fragment_shader = sys_get_shader("layer_copy_bgra.frag"); + let vs: vertex_struct_t = g4_vertex_struct_create(); + g4_vertex_struct_add(vs, "pos", vertex_data_t.F32_3X); + g4_vertex_struct_add(vs, "tex", vertex_data_t.F32_2X); + g4_vertex_struct_add(vs, "col", vertex_data_t.U8_4X_NORM); + base_pipe_copy_bgra.input_layout = [vs]; + g4_pipeline_compile(base_pipe_copy_bgra); + } + + ///if (krom_metal || krom_vulkan || krom_direct3d12) + { + base_pipe_copy8 = g4_pipeline_create(); + base_pipe_copy8.vertex_shader = sys_get_shader("layer_view.vert"); + base_pipe_copy8.fragment_shader = sys_get_shader("layer_copy.frag"); + let vs: vertex_struct_t = g4_vertex_struct_create(); + g4_vertex_struct_add(vs, "pos", vertex_data_t.F32_3X); + g4_vertex_struct_add(vs, "tex", vertex_data_t.F32_2X); + g4_vertex_struct_add(vs, "col", vertex_data_t.U8_4X_NORM); + base_pipe_copy8.input_layout = [vs]; + base_pipe_copy8.color_attachment_count = 1; + base_pipe_copy8.color_attachments[0] = tex_format_t.R8; + g4_pipeline_compile(base_pipe_copy8); + } + + { + base_pipe_copy128 = g4_pipeline_create(); + base_pipe_copy128.vertex_shader = sys_get_shader("layer_view.vert"); + base_pipe_copy128.fragment_shader = sys_get_shader("layer_copy.frag"); + let vs: vertex_struct_t = g4_vertex_struct_create(); + g4_vertex_struct_add(vs, "pos", vertex_data_t.F32_3X); + g4_vertex_struct_add(vs, "tex", vertex_data_t.F32_2X); + g4_vertex_struct_add(vs, "col", vertex_data_t.U8_4X_NORM); + base_pipe_copy128.input_layout = [vs]; + base_pipe_copy128.color_attachment_count = 1; + base_pipe_copy128.color_attachments[0] = tex_format_t.RGBA128; + g4_pipeline_compile(base_pipe_copy128); + } + ///else + base_pipe_copy8 = base_pipe_copy; + base_pipe_copy128 = base_pipe_copy; + ///end + + ///if (is_paint || is_sculpt) + { + base_pipe_invert8 = g4_pipeline_create(); + base_pipe_invert8.vertex_shader = sys_get_shader("layer_view.vert"); + base_pipe_invert8.fragment_shader = sys_get_shader("layer_invert.frag"); + let vs: vertex_struct_t = g4_vertex_struct_create(); + g4_vertex_struct_add(vs, "pos", vertex_data_t.F32_3X); + g4_vertex_struct_add(vs, "tex", vertex_data_t.F32_2X); + g4_vertex_struct_add(vs, "col", vertex_data_t.U8_4X_NORM); + base_pipe_invert8.input_layout = [vs]; + base_pipe_invert8.color_attachment_count = 1; + base_pipe_invert8.color_attachments[0] = tex_format_t.R8; + g4_pipeline_compile(base_pipe_invert8); + } + + { + base_pipe_apply_mask = g4_pipeline_create(); + base_pipe_apply_mask.vertex_shader = sys_get_shader("pass.vert"); + base_pipe_apply_mask.fragment_shader = sys_get_shader("mask_apply.frag"); + let vs: vertex_struct_t = g4_vertex_struct_create(); + g4_vertex_struct_add(vs, "pos", vertex_data_t.F32_2X); + base_pipe_apply_mask.input_layout = [vs]; + g4_pipeline_compile(base_pipe_apply_mask); + base_tex0_mask = g4_pipeline_get_tex_unit(base_pipe_apply_mask, "tex0"); + base_texa_mask = g4_pipeline_get_tex_unit(base_pipe_apply_mask, "texa"); + } + + { + base_pipe_merge_mask = g4_pipeline_create(); + base_pipe_merge_mask.vertex_shader = sys_get_shader("pass.vert"); + base_pipe_merge_mask.fragment_shader = sys_get_shader("mask_merge.frag"); + let vs: vertex_struct_t = g4_vertex_struct_create(); + g4_vertex_struct_add(vs, "pos", vertex_data_t.F32_2X); + base_pipe_merge_mask.input_layout = [vs]; + g4_pipeline_compile(base_pipe_merge_mask); + base_tex0_merge_mask = g4_pipeline_get_tex_unit(base_pipe_merge_mask, "tex0"); + base_texa_merge_mask = g4_pipeline_get_tex_unit(base_pipe_merge_mask, "texa"); + base_opac_merge_mask = g4_pipeline_get_const_loc(base_pipe_merge_mask, "opac"); + base_blending_merge_mask = g4_pipeline_get_const_loc(base_pipe_merge_mask, "blending"); + } + + { + base_pipe_colorid_to_mask = g4_pipeline_create(); + base_pipe_colorid_to_mask.vertex_shader = sys_get_shader("pass.vert"); + base_pipe_colorid_to_mask.fragment_shader = sys_get_shader("mask_colorid.frag"); + let vs: vertex_struct_t = g4_vertex_struct_create(); + g4_vertex_struct_add(vs, "pos", vertex_data_t.F32_2X); + base_pipe_colorid_to_mask.input_layout = [vs]; + g4_pipeline_compile(base_pipe_colorid_to_mask); + base_texpaint_colorid = g4_pipeline_get_tex_unit(base_pipe_colorid_to_mask, "texpaint_colorid"); + base_tex_colorid = g4_pipeline_get_tex_unit(base_pipe_colorid_to_mask, "texcolorid"); + } + ///end + + ///if is_lab + { + base_pipe_copy_r = g4_pipeline_create(); + base_pipe_copy_r.vertex_shader = sys_get_shader("layer_view.vert"); + base_pipe_copy_r.fragment_shader = sys_get_shader("layer_copy.frag"); + let vs: vertex_struct_t = g4_vertex_struct_create(); + g4_vertex_struct_add(vs, "pos", vertex_data_t.F32_3X); + g4_vertex_struct_add(vs, "tex", vertex_data_t.F32_2X); + g4_vertex_struct_add(vs, "col", vertex_data_t.U8_4X_NORM); + base_pipe_copy_r.input_layout = [vs]; + base_pipe_copy_r.color_write_masks_green = [false]; + base_pipe_copy_r.color_write_masks_blue = [false]; + base_pipe_copy_r.color_write_masks_alpha = [false]; + g4_pipeline_compile(base_pipe_copy_r); + } + + { + base_pipe_copy_g = g4_pipeline_create(); + base_pipe_copy_g.vertex_shader = sys_get_shader("layer_view.vert"); + base_pipe_copy_g.fragment_shader = sys_get_shader("layer_copy.frag"); + let vs: vertex_struct_t = g4_vertex_struct_create(); + g4_vertex_struct_add(vs, "pos", vertex_data_t.F32_3X); + g4_vertex_struct_add(vs, "tex", vertex_data_t.F32_2X); + g4_vertex_struct_add(vs, "col", vertex_data_t.U8_4X_NORM); + base_pipe_copy_g.input_layout = [vs]; + base_pipe_copy_g.color_write_masks_red = [false]; + base_pipe_copy_g.color_write_masks_blue = [false]; + base_pipe_copy_g.color_write_masks_alpha = [false]; + g4_pipeline_compile(base_pipe_copy_g); + } + + { + base_pipe_copy_b = g4_pipeline_create(); + base_pipe_copy_b.vertex_shader = sys_get_shader("layer_view.vert"); + base_pipe_copy_b.fragment_shader = sys_get_shader("layer_copy.frag"); + let vs: vertex_struct_t = g4_vertex_struct_create(); + g4_vertex_struct_add(vs, "pos", vertex_data_t.F32_3X); + g4_vertex_struct_add(vs, "tex", vertex_data_t.F32_2X); + g4_vertex_struct_add(vs, "col", vertex_data_t.U8_4X_NORM); + base_pipe_copy_b.input_layout = [vs]; + base_pipe_copy_b.color_write_masks_red = [false]; + base_pipe_copy_b.color_write_masks_green = [false]; + base_pipe_copy_b.color_write_masks_alpha = [false]; + g4_pipeline_compile(base_pipe_copy_b); + } + + { + base_pipe_inpaint_preview = g4_pipeline_create(); + base_pipe_inpaint_preview.vertex_shader = sys_get_shader("pass.vert"); + base_pipe_inpaint_preview.fragment_shader = sys_get_shader("inpaint_preview.frag"); + let vs: vertex_struct_t = g4_vertex_struct_create(); + g4_vertex_struct_add(vs, "pos", vertex_data_t.F32_2X); + base_pipe_inpaint_preview.input_layout = [vs]; + g4_pipeline_compile(base_pipe_inpaint_preview); + base_tex0_inpaint_preview = g4_pipeline_get_tex_unit(base_pipe_inpaint_preview, "tex0"); + base_texa_inpaint_preview = g4_pipeline_get_tex_unit(base_pipe_inpaint_preview, "texa"); + } + ///end +} + +function base_make_pipe_copy_rgb() { + base_pipe_copy_rgb = g4_pipeline_create(); + base_pipe_copy_rgb.vertex_shader = sys_get_shader("layer_view.vert"); + base_pipe_copy_rgb.fragment_shader = sys_get_shader("layer_copy.frag"); + let vs: vertex_struct_t = g4_vertex_struct_create(); + g4_vertex_struct_add(vs, "pos", vertex_data_t.F32_3X); + g4_vertex_struct_add(vs, "tex", vertex_data_t.F32_2X); + g4_vertex_struct_add(vs, "col", vertex_data_t.U8_4X_NORM); + base_pipe_copy_rgb.input_layout = [vs]; + base_pipe_copy_rgb.color_write_masks_alpha = [false]; + g4_pipeline_compile(base_pipe_copy_rgb); +} + +///if is_lab +function base_make_pipe_copy_a() { + base_pipe_copy_a = g4_pipeline_create(); + base_pipe_copy_a.vertex_shader = sys_get_shader("pass.vert"); + base_pipe_copy_a.fragment_shader = sys_get_shader("layer_copy_rrrr.frag"); + let vs: vertex_struct_t = g4_vertex_struct_create(); + g4_vertex_struct_add(vs, "pos", vertex_data_t.F32_2X); + base_pipe_copy_a.input_layout = [vs]; + base_pipe_copy_a.color_write_masks_red = [false]; + base_pipe_copy_a.color_write_masks_green = [false]; + base_pipe_copy_a.color_write_masks_blue = [false]; + g4_pipeline_compile(base_pipe_copy_a); + base_pipe_copy_a_tex = g4_pipeline_get_tex_unit(base_pipe_copy_a, "tex"); +} +///end + +function base_make_cursor_pipe() { + base_pipe_cursor = g4_pipeline_create(); + base_pipe_cursor.vertex_shader = sys_get_shader("cursor.vert"); + base_pipe_cursor.fragment_shader = sys_get_shader("cursor.frag"); + let vs: vertex_struct_t = g4_vertex_struct_create(); + ///if (krom_metal || krom_vulkan) + g4_vertex_struct_add(vs, "tex", vertex_data_t.I16_2X_NORM); + ///else + g4_vertex_struct_add(vs, "pos", vertex_data_t.I16_4X_NORM); + g4_vertex_struct_add(vs, "nor", vertex_data_t.I16_2X_NORM); + g4_vertex_struct_add(vs, "tex", vertex_data_t.I16_2X_NORM); + ///end + base_pipe_cursor.input_layout = [vs]; + base_pipe_cursor.blend_source = blend_factor_t.SOURCE_ALPHA; + base_pipe_cursor.blend_dest = blend_factor_t.INV_SOURCE_ALPHA; + base_pipe_cursor.depth_write = false; + base_pipe_cursor.depth_mode = compare_mode_t.ALWAYS; + g4_pipeline_compile(base_pipe_cursor); + base_cursor_vp = g4_pipeline_get_const_loc(base_pipe_cursor, "VP"); + base_cursor_inv_vp = g4_pipeline_get_const_loc(base_pipe_cursor, "invVP"); + base_cursor_mouse = g4_pipeline_get_const_loc(base_pipe_cursor, "mouse"); + base_cursor_tex_step = g4_pipeline_get_const_loc(base_pipe_cursor, "texStep"); + base_cursor_radius = g4_pipeline_get_const_loc(base_pipe_cursor, "radius"); + base_cursor_camera_right = g4_pipeline_get_const_loc(base_pipe_cursor, "cameraRight"); + base_cursor_tint = g4_pipeline_get_const_loc(base_pipe_cursor, "tint"); + base_cursor_gbufferd = g4_pipeline_get_tex_unit(base_pipe_cursor, "gbufferD"); + base_cursor_tex = g4_pipeline_get_tex_unit(base_pipe_cursor, "tex"); +} + +function base_make_temp_img() { + ///if (is_paint || is_sculpt) + let l: SlotLayerRaw = Project.layers[0]; + ///end + ///if is_lab + let l: any = BrushOutputNode.inst; + ///end + + if (base_temp_image != null && (base_temp_image.width != l.texpaint.width || base_temp_image.height != l.texpaint.height || base_temp_image.format != l.texpaint.format)) { + let _temptex0: render_target_t = render_path_render_targets.get("temptex0"); + base_notify_on_next_frame(function() { + render_target_unload(_temptex0); + }); + render_path_render_targets.delete("temptex0"); + base_temp_image = null; + } + if (base_temp_image == null) { + ///if (is_paint || is_sculpt) + let format: string = base_bits_handle.position == texture_bits_t.BITS8 ? "RGBA32" : + base_bits_handle.position == texture_bits_t.BITS16 ? "RGBA64" : + "RGBA128"; + ///end + ///if is_lab + let format: string = "RGBA32"; + ///end + + let t: render_target_t = render_target_create(); + t.name = "temptex0"; + t.width = l.texpaint.width; + t.height = l.texpaint.height; + t.format = format; + let rt: render_target_t = render_path_create_render_target(t); + base_temp_image = rt._image; + } +} + +///if (is_paint || is_sculpt) +function base_make_temp_mask_img() { + if (base_temp_mask_image != null && (base_temp_mask_image.width != Config.get_texture_res_x() || base_temp_mask_image.height != Config.get_texture_res_y())) { + let _temp_mask_image: image_t = base_temp_mask_image; + base_notify_on_next_frame(function() { + image_unload(_temp_mask_image); + }); + base_temp_mask_image = null; + } + if (base_temp_mask_image == null) { + base_temp_mask_image = image_create_render_target(Config.get_texture_res_x(), Config.get_texture_res_y(), tex_format_t.R8); + } +} +///end + +function base_make_export_img() { + ///if (is_paint || is_sculpt) + let l: SlotLayerRaw = Project.layers[0]; + ///end + ///if is_lab + let l: any = BrushOutputNode.inst; + ///end + + if (base_expa != null && (base_expa.width != l.texpaint.width || base_expa.height != l.texpaint.height || base_expa.format != l.texpaint.format)) { + let _expa: image_t = base_expa; + let _expb: image_t = base_expb; + let _expc: image_t = base_expc; + base_notify_on_next_frame(function() { + image_unload(_expa); + image_unload(_expb); + image_unload(_expc); + }); + base_expa = null; + base_expb = null; + base_expc = null; + render_path_render_targets.delete("expa"); + render_path_render_targets.delete("expb"); + render_path_render_targets.delete("expc"); + } + if (base_expa == null) { + ///if (is_paint || is_sculpt) + let format: string = base_bits_handle.position == texture_bits_t.BITS8 ? "RGBA32" : + base_bits_handle.position == texture_bits_t.BITS16 ? "RGBA64" : + "RGBA128"; + ///end + ///if is_lab + let format: string = "RGBA32"; + ///end + + { + let t: render_target_t = render_target_create(); + t.name = "expa"; + t.width = l.texpaint.width; + t.height = l.texpaint.height; + t.format = format; + let rt: render_target_t = render_path_create_render_target(t); + base_expa = rt._image; + } + + { + let t: render_target_t = render_target_create(); + t.name = "expb"; + t.width = l.texpaint.width; + t.height = l.texpaint.height; + t.format = format; + let rt: render_target_t = render_path_create_render_target(t); + base_expb = rt._image; + } + + { + let t: render_target_t = render_target_create(); + t.name = "expc"; + t.width = l.texpaint.width; + t.height = l.texpaint.height; + t.format = format; + let rt: render_target_t = render_path_create_render_target(t); + base_expc = rt._image; + } + } +} + +///if (is_paint || is_sculpt) +function base_duplicate_layer(l: SlotLayerRaw) { + if (!SlotLayer.is_group(l)) { + let new_layer: SlotLayerRaw = SlotLayer.duplicate(l); + Context.set_layer(new_layer); + let masks: SlotLayerRaw[] = SlotLayer.get_masks(l, false); + if (masks != null) { + for (let m of masks) { + m = SlotLayer.duplicate(m); + m.parent = new_layer; + array_remove(Project.layers, m); + Project.layers.splice(Project.layers.indexOf(new_layer), 0, m); + } + } + Context.set_layer(new_layer); + } + else { + let new_group: SlotLayerRaw = base_new_group(); + array_remove(Project.layers, new_group); + Project.layers.splice(Project.layers.indexOf(l) + 1, 0, new_group); + // group.show_panel = true; + for (let c of SlotLayer.get_children(l)) { + let masks: SlotLayerRaw[] = SlotLayer.get_masks(c, false); + let new_layer: SlotLayerRaw = SlotLayer.duplicate(c); + new_layer.parent = new_group; + array_remove(Project.layers, new_layer); + Project.layers.splice(Project.layers.indexOf(new_group), 0, new_layer); + if (masks != null) { + for (let m of masks) { + let new_mask: SlotLayerRaw = SlotLayer.duplicate(m); + new_mask.parent = new_layer; + array_remove(Project.layers, new_mask); + Project.layers.splice(Project.layers.indexOf(new_layer), 0, new_mask); + } + } + } + let group_masks: SlotLayerRaw[] = SlotLayer.get_masks(l); + if (group_masks != null) { + for (let m of group_masks) { + let new_mask: SlotLayerRaw = SlotLayer.duplicate(m); + new_mask.parent = new_group; + array_remove(Project.layers, new_mask); + Project.layers.splice(Project.layers.indexOf(new_group), 0, new_mask); + } + } + Context.set_layer(new_group); + } +} + +function base_apply_masks(l: SlotLayerRaw) { + let masks: SlotLayerRaw[] = SlotLayer.get_masks(l); + + if (masks != null) { + for (let i: i32 = 0; i < masks.length - 1; ++i) { + base_merge_layer(masks[i + 1], masks[i]); + SlotLayer.delete(masks[i]); + } + SlotLayer.apply_mask(masks[masks.length - 1]); + Context.raw.layer_preview_dirty = true; + } +} + +function base_merge_down() { + let l1: SlotLayerRaw = Context.raw.layer; + + if (SlotLayer.is_group(l1)) { + l1 = base_merge_group(l1); + } + else if (SlotLayer.has_masks(l1)) { // It is a layer + base_apply_masks(l1); + Context.set_layer(l1); + } + + let l0: SlotLayerRaw = Project.layers[Project.layers.indexOf(l1) - 1]; + + if (SlotLayer.is_group(l0)) { + l0 = base_merge_group(l0); + } + else if (SlotLayer.has_masks(l0)) { // It is a layer + base_apply_masks(l0); + Context.set_layer(l0); + } + + base_merge_layer(l0, l1); + SlotLayer.delete(l1); + Context.set_layer(l0); + Context.raw.layer_preview_dirty = true; +} + +function base_merge_group(l: SlotLayerRaw) { + if (!SlotLayer.is_group(l)) return null; + + let children: SlotLayerRaw[] = SlotLayer.get_children(l); + + if (children.length == 1 && SlotLayer.has_masks(children[0], false)) { + base_apply_masks(children[0]); + } + + for (let i: i32 = 0; i < children.length - 1; ++i) { + Context.set_layer(children[children.length - 1 - i]); + History.merge_layers(); + base_merge_down(); + } + + // Now apply the group masks + let masks: SlotLayerRaw[] = SlotLayer.get_masks(l); + if (masks != null) { + for (let i: i32 = 0; i < masks.length - 1; ++i) { + base_merge_layer(masks[i + 1], masks[i]); + SlotLayer.delete(masks[i]); + } + base_apply_mask(children[0], masks[masks.length - 1]); + } + + children[0].parent = null; + children[0].name = l.name; + if (children[0].fill_layer != null) SlotLayer.to_paint_layer(children[0]); + SlotLayer.delete(l); + return children[0]; +} + +function base_merge_layer(l0 : SlotLayerRaw, l1: SlotLayerRaw, use_mask: bool = false) { + if (!l1.visible || SlotLayer.is_group(l1)) return; + + if (base_pipe_merge == null) base_make_pipe(); + base_make_temp_img(); + if (const_data_screen_aligned_vb == null) const_data_create_screen_aligned_data(); + + g2_begin(base_temp_image); // Copy to temp + g2_set_pipeline(base_pipe_copy); + g2_draw_image(l0.texpaint, 0, 0); + g2_set_pipeline(null); + g2_end(); + + let empty: image_t = render_path_render_targets.get("empty_white")._image; + let mask: image_t = empty; + let l1masks: SlotLayerRaw[] = use_mask ? SlotLayer.get_masks(l1) : null; + if (l1masks != null) { + // for (let i: i32 = 1; i < l1masks.length - 1; ++i) { + // mergeLayer(l1masks[i + 1], l1masks[i]); + // } + mask = l1masks[0].texpaint; + } + + if (SlotLayer.is_mask(l1)) { + g4_begin(l0.texpaint); + g4_set_pipeline(base_pipe_merge_mask); + g4_set_tex(base_tex0_merge_mask, l1.texpaint); + g4_set_tex(base_texa_merge_mask, base_temp_image); + g4_set_float(base_opac_merge_mask, SlotLayer.get_opacity(l1)); + g4_set_int(base_blending_merge_mask, l1.blending); + g4_set_vertex_buffer(const_data_screen_aligned_vb); + g4_set_index_buffer(const_data_screen_aligned_ib); + g4_draw(); + g4_end(); + } + + if (SlotLayer.is_layer(l1)) { + if (l1.paint_base) { + g4_begin(l0.texpaint); + g4_set_pipeline(base_pipe_merge); + g4_set_tex(base_tex0, l1.texpaint); + g4_set_tex(base_tex1, empty); + g4_set_tex(base_texmask, mask); + g4_set_tex(base_texa, base_temp_image); + g4_set_float(base_opac, SlotLayer.get_opacity(l1)); + g4_set_int(base_blending, l1.blending); + g4_set_vertex_buffer(const_data_screen_aligned_vb); + g4_set_index_buffer(const_data_screen_aligned_ib); + g4_draw(); + g4_end(); + } + + ///if is_paint + g2_begin(base_temp_image); + g2_set_pipeline(base_pipe_copy); + g2_draw_image(l0.texpaint_nor, 0, 0); + g2_set_pipeline(null); + g2_end(); + + if (l1.paint_nor) { + g4_begin(l0.texpaint_nor); + g4_set_pipeline(base_pipe_merge); + g4_set_tex(base_tex0, l1.texpaint); + g4_set_tex(base_tex1, l1.texpaint_nor); + g4_set_tex(base_texmask, mask); + g4_set_tex(base_texa, base_temp_image); + g4_set_float(base_opac, SlotLayer.get_opacity(l1)); + g4_set_int(base_blending, l1.paint_nor_blend ? -2 : -1); + g4_set_vertex_buffer(const_data_screen_aligned_vb); + g4_set_index_buffer(const_data_screen_aligned_ib); + g4_draw(); + g4_end(); + } + + g2_begin(base_temp_image); + g2_set_pipeline(base_pipe_copy); + g2_draw_image(l0.texpaint_pack, 0, 0); + g2_set_pipeline(null); + g2_end(); + + if (l1.paint_occ || l1.paint_rough || l1.paint_met || l1.paint_height) { + if (l1.paint_occ && l1.paint_rough && l1.paint_met && l1.paint_height) { + base_commands_merge_pack(base_pipe_merge, l0.texpaint_pack, l1.texpaint, l1.texpaint_pack, SlotLayer.get_opacity(l1), mask, l1.paint_height_blend ? -3 : -1); + } + else { + if (l1.paint_occ) base_commands_merge_pack(base_pipe_merge_r, l0.texpaint_pack, l1.texpaint, l1.texpaint_pack, SlotLayer.get_opacity(l1), mask); + if (l1.paint_rough) base_commands_merge_pack(base_pipe_merge_g, l0.texpaint_pack, l1.texpaint, l1.texpaint_pack, SlotLayer.get_opacity(l1), mask); + if (l1.paint_met) base_commands_merge_pack(base_pipe_merge_b, l0.texpaint_pack, l1.texpaint, l1.texpaint_pack, SlotLayer.get_opacity(l1), mask); + } + } + ///end + } +} + +function base_flatten(height_to_normal: bool = false, layers: SlotLayerRaw[] = null): any { + if (layers == null) layers = Project.layers; + base_make_temp_img(); + base_make_export_img(); + if (base_pipe_merge == null) base_make_pipe(); + if (const_data_screen_aligned_vb == null) const_data_create_screen_aligned_data(); + let empty: image_t = render_path_render_targets.get("empty_white")._image; + + // Clear export layer + g4_begin(base_expa); + g4_clear(color_from_floats(0.0, 0.0, 0.0, 0.0)); + g4_end(); + g4_begin(base_expb); + g4_clear(color_from_floats(0.5, 0.5, 1.0, 0.0)); + g4_end(); + g4_begin(base_expc); + g4_clear(color_from_floats(1.0, 0.0, 0.0, 0.0)); + g4_end(); + + // Flatten layers + for (let l1 of layers) { + if (!SlotLayer.is_visible(l1)) continue; + if (!SlotLayer.is_layer(l1)) continue; + + let mask: image_t = empty; + let l1masks: SlotLayerRaw[] = SlotLayer.get_masks(l1); + if (l1masks != null) { + if (l1masks.length > 1) { + base_make_temp_mask_img(); + g2_begin(base_temp_mask_image); + g2_clear(0x00000000); + g2_end(); + let l1: any = { texpaint: base_temp_mask_image }; + for (let i: i32 = 0; i < l1masks.length; ++i) { + base_merge_layer(l1, l1masks[i]); + } + mask = base_temp_mask_image; + } + else mask = l1masks[0].texpaint; + } + + if (l1.paint_base) { + g2_begin(base_temp_image); // Copy to temp + g2_set_pipeline(base_pipe_copy); + g2_draw_image(base_expa, 0, 0); + g2_set_pipeline(null); + g2_end(); + + g4_begin(base_expa); + g4_set_pipeline(base_pipe_merge); + g4_set_tex(base_tex0, l1.texpaint); + g4_set_tex(base_tex1, empty); + g4_set_tex(base_texmask, mask); + g4_set_tex(base_texa, base_temp_image); + g4_set_float(base_opac, SlotLayer.get_opacity(l1)); + g4_set_int(base_blending, layers.length > 1 ? l1.blending : 0); + g4_set_vertex_buffer(const_data_screen_aligned_vb); + g4_set_index_buffer(const_data_screen_aligned_ib); + g4_draw(); + g4_end(); + } + + ///if is_paint + if (l1.paint_nor) { + g2_begin(base_temp_image); + g2_set_pipeline(base_pipe_copy); + g2_draw_image(base_expb, 0, 0); + g2_set_pipeline(null); + g2_end(); + + g4_begin(base_expb); + g4_set_pipeline(base_pipe_merge); + g4_set_tex(base_tex0, l1.texpaint); + g4_set_tex(base_tex1, l1.texpaint_nor); + g4_set_tex(base_texmask, mask); + g4_set_tex(base_texa, base_temp_image); + g4_set_float(base_opac, SlotLayer.get_opacity(l1)); + g4_set_int(base_blending, l1.paint_nor_blend ? -2 : -1); + g4_set_vertex_buffer(const_data_screen_aligned_vb); + g4_set_index_buffer(const_data_screen_aligned_ib); + g4_draw(); + g4_end(); + } + + if (l1.paint_occ || l1.paint_rough || l1.paint_met || l1.paint_height) { + g2_begin(base_temp_image); + g2_set_pipeline(base_pipe_copy); + g2_draw_image(base_expc, 0, 0); + g2_set_pipeline(null); + g2_end(); + + if (l1.paint_occ && l1.paint_rough && l1.paint_met && l1.paint_height) { + base_commands_merge_pack(base_pipe_merge, base_expc, l1.texpaint, l1.texpaint_pack, SlotLayer.get_opacity(l1), mask, l1.paint_height_blend ? -3 : -1); + } + else { + if (l1.paint_occ) base_commands_merge_pack(base_pipe_merge_r, base_expc, l1.texpaint, l1.texpaint_pack, SlotLayer.get_opacity(l1), mask); + if (l1.paint_rough) base_commands_merge_pack(base_pipe_merge_g, base_expc, l1.texpaint, l1.texpaint_pack, SlotLayer.get_opacity(l1), mask); + if (l1.paint_met) base_commands_merge_pack(base_pipe_merge_b, base_expc, l1.texpaint, l1.texpaint_pack, SlotLayer.get_opacity(l1), mask); + } + } + ///end + } + + ///if krom_metal + // Flush command list + g2_begin(base_expa); + g2_end(); + g2_begin(base_expb); + g2_end(); + g2_begin(base_expc); + g2_end(); + ///end + + let l0: any = { texpaint: base_expa, texpaint_nor: base_expb, texpaint_pack: base_expc }; + + // Merge height map into normal map + if (height_to_normal && MakeMaterial.height_used) { + + g2_begin(base_temp_image); + g2_set_pipeline(base_pipe_copy); + g2_draw_image(l0.texpaint_nor, 0, 0); + g2_set_pipeline(null); + g2_end(); + + g4_begin(l0.texpaint_nor); + g4_set_pipeline(base_pipe_merge); + g4_set_tex(base_tex0, base_temp_image); + g4_set_tex(base_tex1, l0.texpaint_pack); + g4_set_tex(base_texmask, empty); + g4_set_tex(base_texa, empty); + g4_set_float(base_opac, 1.0); + g4_set_int(base_blending, -4); + g4_set_vertex_buffer(const_data_screen_aligned_vb); + g4_set_index_buffer(const_data_screen_aligned_ib); + g4_draw(); + g4_end(); + } + + return l0; +} + +function base_apply_mask(l: SlotLayerRaw, m: SlotLayerRaw) { + if (!SlotLayer.is_layer(l) || !SlotLayer.is_mask(m)) return; + + if (base_pipe_merge == null) base_make_pipe(); + base_make_temp_img(); + + // Copy layer to temp + g2_begin(base_temp_image); + g2_set_pipeline(base_pipe_copy); + g2_draw_image(l.texpaint, 0, 0); + g2_set_pipeline(null); + g2_end(); + + // Apply mask + if (const_data_screen_aligned_vb == null) const_data_create_screen_aligned_data(); + g4_begin(l.texpaint); + g4_set_pipeline(base_pipe_apply_mask); + g4_set_tex(base_tex0_mask, base_temp_image); + g4_set_tex(base_texa_mask, m.texpaint); + g4_set_vertex_buffer(const_data_screen_aligned_vb); + g4_set_index_buffer(const_data_screen_aligned_ib); + g4_draw(); + g4_end(); +} + +function base_commands_merge_pack(pipe: pipeline_t, i0: image_t, i1: image_t, i1pack: image_t, i1mask_opacity: f32, i1texmask: image_t, i1blending: i32 = -1) { + g4_begin(i0); + g4_set_pipeline(pipe); + g4_set_tex(base_tex0, i1); + g4_set_tex(base_tex1, i1pack); + g4_set_tex(base_texmask, i1texmask); + g4_set_tex(base_texa, base_temp_image); + g4_set_float(base_opac, i1mask_opacity); + g4_set_int(base_blending, i1blending); + g4_set_vertex_buffer(const_data_screen_aligned_vb); + g4_set_index_buffer(const_data_screen_aligned_ib); + g4_draw(); + g4_end(); +} + +function base_is_fill_material(): bool { + ///if is_paint + if (Context.raw.tool == workspace_tool_t.MATERIAL) return true; + ///end + + let m: SlotMaterialRaw = Context.raw.material; + for (let l of Project.layers) if (l.fill_layer == m) return true; + return false; +} + +function base_update_fill_layers() { + let _layer: SlotLayerRaw = Context.raw.layer; + let _tool: workspace_tool_t = Context.raw.tool; + let _fill_type: i32 = Context.raw.fill_type_handle.position; + let current: image_t = null; + + ///if is_paint + if (Context.raw.tool == workspace_tool_t.MATERIAL) { + if (RenderPathPaint.live_layer == null) { + RenderPathPaint.live_layer = SlotLayer.create("_live"); + } + + current = _g2_current; + if (current != null) g2_end(); + + Context.raw.tool = workspace_tool_t.FILL; + Context.raw.fill_type_handle.position = fill_type_t.OBJECT; + MakeMaterial.parse_paint_material(false); + Context.raw.pdirty = 1; + RenderPathPaint.use_live_layer(true); + RenderPathPaint.commands_paint(false); + RenderPathPaint.dilate(true, true); + RenderPathPaint.use_live_layer(false); + Context.raw.tool = _tool; + Context.raw.fill_type_handle.position = _fill_type; + Context.raw.pdirty = 0; + Context.raw.rdirty = 2; + + if (current != null) g2_begin(current); + return; + } + ///end + + let has_fill_layer: bool = false; + let has_fill_mask: bool = false; + for (let l of Project.layers) if (SlotLayer.is_layer(l) && l.fill_layer == Context.raw.material) has_fill_layer = true; + for (let l of Project.layers) if (SlotLayer.is_mask(l) && l.fill_layer == Context.raw.material) has_fill_mask = true; + + if (has_fill_layer || has_fill_mask) { + current = _g2_current; + if (current != null) g2_end(); + Context.raw.pdirty = 1; + Context.raw.tool = workspace_tool_t.FILL; + Context.raw.fill_type_handle.position = fill_type_t.OBJECT; + + if (has_fill_layer) { + let first: bool = true; + for (let l of Project.layers) { + if (SlotLayer.is_layer(l) && l.fill_layer == Context.raw.material) { + Context.raw.layer = l; + if (first) { + first = false; + MakeMaterial.parse_paint_material(false); + } + base_set_object_mask(); + SlotLayer.clear(l); + RenderPathPaint.commands_paint(false); + RenderPathPaint.dilate(true, true); + } + } + } + if (has_fill_mask) { + let first: bool = true; + for (let l of Project.layers) { + if (SlotLayer.is_mask(l) && l.fill_layer == Context.raw.material) { + Context.raw.layer = l; + if (first) { + first = false; + MakeMaterial.parse_paint_material(false); + } + base_set_object_mask(); + SlotLayer.clear(l); + RenderPathPaint.commands_paint(false); + RenderPathPaint.dilate(true, true); + } + } + } + + Context.raw.pdirty = 0; + Context.raw.ddirty = 2; + Context.raw.rdirty = 2; + Context.raw.layers_preview_dirty = true; // Repaint all layer previews as multiple layers might have changed. + if (current != null) g2_begin(current); + Context.raw.layer = _layer; + base_set_object_mask(); + Context.raw.tool = _tool; + Context.raw.fill_type_handle.position = _fill_type; + MakeMaterial.parse_paint_material(false); + } +} + +function base_update_fill_layer(parse_paint: bool = true) { + let current: image_t = _g2_current; + if (current != null) g2_end(); + + let _tool: workspace_tool_t = Context.raw.tool; + let _fill_type: i32 = Context.raw.fill_type_handle.position; + Context.raw.tool = workspace_tool_t.FILL; + Context.raw.fill_type_handle.position = fill_type_t.OBJECT; + Context.raw.pdirty = 1; + + SlotLayer.clear(Context.raw.layer); + + if (parse_paint) MakeMaterial.parse_paint_material(false); + RenderPathPaint.commands_paint(false); + RenderPathPaint.dilate(true, true); + + Context.raw.rdirty = 2; + Context.raw.tool = _tool; + Context.raw.fill_type_handle.position = _fill_type; + if (current != null) g2_begin(current); +} + +function base_set_object_mask() { + ///if is_sculpt + return; + ///end + + let ar: string[] = [tr("None")]; + for (let p of Project.paint_objects) ar.push(p.base.name); + + let mask: i32 = Context.object_mask_used() ? SlotLayer.get_object_mask(Context.raw.layer) : 0; + if (Context.layer_filter_used()) mask = Context.raw.layer_filter; + if (mask > 0) { + if (Context.raw.merged_object != null) { + Context.raw.merged_object.base.visible = false; + } + let o: mesh_object_t = Project.paint_objects[0]; + for (let p of Project.paint_objects) { + if (p.base.name == ar[mask]) { + o = p; + break; + } + } + Context.select_paint_object(o); + } + else { + let is_atlas: bool = SlotLayer.get_object_mask(Context.raw.layer) > 0 && SlotLayer.get_object_mask(Context.raw.layer) <= Project.paint_objects.length; + if (Context.raw.merged_object == null || is_atlas || Context.raw.merged_object_is_atlas) { + let visibles: mesh_object_t[] = is_atlas ? Project.get_atlas_objects(SlotLayer.get_object_mask(Context.raw.layer)) : null; + UtilMesh.merge_mesh(visibles); + } + Context.select_paint_object(Context.main_object()); + Context.raw.paint_object.skip_context = "paint"; + Context.raw.merged_object.base.visible = true; + } + UtilUV.dilatemap_cached = false; +} + +function base_new_layer(clear: bool = true, position: i32 = -1): SlotLayerRaw { + if (Project.layers.length > base_max_layers) return null; + let l: SlotLayerRaw = SlotLayer.create(); + l.object_mask = Context.raw.layer_filter; + if (position == -1) { + if (SlotLayer.is_mask(Context.raw.layer)) Context.set_layer(Context.raw.layer.parent); + Project.layers.splice(Project.layers.indexOf(Context.raw.layer) + 1, 0, l); + } + else { + Project.layers.splice(position, 0, l); + } + + Context.set_layer(l); + let li: i32 = Project.layers.indexOf(Context.raw.layer); + if (li > 0) { + let below: SlotLayerRaw = Project.layers[li - 1]; + if (SlotLayer.is_layer(below)) { + Context.raw.layer.parent = below.parent; + } + } + if (clear) app_notify_on_init(function() { SlotLayer.clear(l); }); + Context.raw.layer_preview_dirty = true; + return l; +} + +function base_new_mask(clear: bool = true, parent: SlotLayerRaw, position: i32 = -1): SlotLayerRaw { + if (Project.layers.length > base_max_layers) return null; + let l: SlotLayerRaw = SlotLayer.create("", layer_slot_type_t.MASK, parent); + if (position == -1) position = Project.layers.indexOf(parent); + Project.layers.splice(position, 0, l); + Context.set_layer(l); + if (clear) app_notify_on_init(function() { SlotLayer.clear(l); }); + Context.raw.layer_preview_dirty = true; + return l; +} + +function base_new_group(): SlotLayerRaw { + if (Project.layers.length > base_max_layers) return null; + let l: SlotLayerRaw = SlotLayer.create("", layer_slot_type_t.GROUP); + Project.layers.push(l); + Context.set_layer(l); + return l; +} + +function base_create_fill_layer(uv_type: uv_type_t = uv_type_t.UVMAP, decal_mat: mat4_t = null, position: i32 = -1) { + let _init = function() { + let l: SlotLayerRaw = base_new_layer(false, position); + History.new_layer(); + l.uv_type = uv_type; + if (decal_mat != null) l.decal_mat = decal_mat; + l.object_mask = Context.raw.layer_filter; + History.to_fill_layer(); + SlotLayer.to_fill_layer(l); + } + app_notify_on_init(_init); +} + +function base_create_image_mask(asset: asset_t) { + let l: SlotLayerRaw = Context.raw.layer; + if (SlotLayer.is_mask(l) || SlotLayer.is_group(l)) { + return; + } + + History.new_layer(); + let m: SlotLayerRaw = base_new_mask(false, l); + SlotLayer.clear(m, 0x00000000, Project.get_image(asset)); + Context.raw.layer_preview_dirty = true; +} + +function base_create_color_layer(baseColor: i32, occlusion: f32 = 1.0, roughness: f32 = base_default_rough, metallic: f32 = 0.0, position: i32 = -1) { + let _init = function() { + let l: SlotLayerRaw = base_new_layer(false, position); + History.new_layer(); + l.uv_type = uv_type_t.UVMAP; + l.object_mask = Context.raw.layer_filter; + SlotLayer.clear(l, baseColor, null, occlusion, roughness, metallic); + } + app_notify_on_init(_init); +} + +function base_on_layers_resized() { + app_notify_on_init(function() { + base_resize_layers(); + let _layer: SlotLayerRaw = Context.raw.layer; + let _material: SlotMaterialRaw = Context.raw.material; + for (let l of Project.layers) { + if (l.fill_layer != null) { + Context.raw.layer = l; + Context.raw.material = l.fill_layer; + base_update_fill_layer(); + } + } + Context.raw.layer = _layer; + Context.raw.material = _material; + MakeMaterial.parse_paint_material(); + }); + UtilUV.uvmap = null; + UtilUV.uvmap_cached = false; + UtilUV.trianglemap = null; + UtilUV.trianglemap_cached = false; + UtilUV.dilatemap_cached = false; + ///if (krom_direct3d12 || krom_vulkan || krom_metal) + RenderPathRaytrace.ready = false; + ///end +} +///end + +///if is_lab +function base_flatten(heightToNormal: bool = false): any { + let texpaint: image_t = BrushOutputNode.inst.texpaint; + let texpaint_nor: image_t = BrushOutputNode.inst.texpaint_nor; + let texpaint_pack: image_t = BrushOutputNode.inst.texpaint_pack; + + let nodes: zui_nodes_t = UINodes.get_nodes(); + let canvas: zui_node_canvas_t = UINodes.get_canvas(true); + if (nodes.nodes_selected_id.length > 0) { + let node: zui_node_t = zui_get_node(canvas.nodes, nodes.nodes_selected_id[0]); + let brush_node: LogicNode = ParserLogic.get_logic_node(node); + if (brush_node != null && brush_node.get_cached_image() != null) { + texpaint = brush_node.get_cached_image(); + texpaint_nor = render_path_render_targets.get("texpaint_nor_empty")._image; + texpaint_pack = render_path_render_targets.get("texpaint_pack_empty")._image; + } + } + + return { texpaint: texpaint, texpaint_nor: texpaint_nor, texpaint_pack: texpaint_pack }; +} + +function base_on_layers_resized() { + image_unload(BrushOutputNode.inst.texpaint); + BrushOutputNode.inst.texpaint = render_path_render_targets.get("texpaint")._image = image_create_render_target(Config.get_texture_res_x(), Config.get_texture_res_y()); + image_unload(BrushOutputNode.inst.texpaint_nor); + BrushOutputNode.inst.texpaint_nor = render_path_render_targets.get("texpaint_nor")._image = image_create_render_target(Config.get_texture_res_x(), Config.get_texture_res_y()); + image_unload(BrushOutputNode.inst.texpaint_pack); + BrushOutputNode.inst.texpaint_pack = render_path_render_targets.get("texpaint_pack")._image = image_create_render_target(Config.get_texture_res_x(), Config.get_texture_res_y()); + + if (InpaintNode.image != null) { + image_unload(InpaintNode.image); + InpaintNode.image = null; + image_unload(InpaintNode.mask); + InpaintNode.mask = null; + InpaintNode.init(); + } + + if (PhotoToPBRNode.images != null) { + for (let image of PhotoToPBRNode.images) image_unload(image); + PhotoToPBRNode.images = null; + PhotoToPBRNode.init(); + } + + if (TilingNode.image != null) { + image_unload(TilingNode.image); + TilingNode.image = null; + TilingNode.init(); + } + + image_unload(render_path_render_targets.get("texpaint_blend0")._image); + render_path_render_targets.get("texpaint_blend0")._image = image_create_render_target(Config.get_texture_res_x(), Config.get_texture_res_y(), tex_format_t.R8); + image_unload(render_path_render_targets.get("texpaint_blend1")._image); + render_path_render_targets.get("texpaint_blend1")._image = image_create_render_target(Config.get_texture_res_x(), Config.get_texture_res_y(), tex_format_t.R8); + + if (render_path_render_targets.get("texpaint_node") != null) { + render_path_render_targets.delete("texpaint_node"); + } + if (render_path_render_targets.get("texpaint_node_target") != null) { + render_path_render_targets.delete("texpaint_node_target"); + } + + base_notify_on_next_frame(function() { + base_init_layers(); + }); + + ///if (krom_direct3d12 || krom_vulkan || krom_metal) + RenderPathRaytrace.ready = false; + ///end +} +///end diff --git a/base/Sources/main.ts b/base/Sources/main.ts index 381fb12e..a07d9e79 100644 --- a/base/Sources/main.ts +++ b/base/Sources/main.ts @@ -30,15 +30,15 @@ function kickstart() { } function main_start() { - app_on_resize = Base.on_resize; - app_on_w = Base.w; - app_on_h = Base.h; - app_on_x = Base.x; - app_on_y = Base.y; + app_on_resize = base_on_resize; + app_on_w = base_w; + app_on_h = base_h; + app_on_x = base_x; + app_on_y = base_y; Config.init(); sys_start(Config.get_options()); - if (Config.raw.layout == null) Base.init_layout(); + if (Config.raw.layout == null) base_init_layout(); krom_set_app_name(manifest_title); app_init(function() { let o: object_t = scene_set_active("Scene"); @@ -55,7 +55,7 @@ function main_start() { render_path_commands = RenderPathDeferred.commands; } - new Base(); + base_init(); }); }