diff --git a/armorlab/Sources/make_material.ts b/armorlab/Sources/make_material.ts index cc6f4237..f2f699f9 100644 --- a/armorlab/Sources/make_material.ts +++ b/armorlab/Sources/make_material.ts @@ -1,7 +1,7 @@ let make_material_default_scon: shader_context_t = null; let make_material_default_mcon: material_context_t = null; -let make_material_height_used = false; +let make_material_height_used: bool = false; function make_material_parse_mesh_material() { let m = project_material_data; diff --git a/armorpaint/Sources/import_folder.ts b/armorpaint/Sources/import_folder.ts index 73ce5020..d31e29bd 100644 --- a/armorpaint/Sources/import_folder.ts +++ b/armorpaint/Sources/import_folder.ts @@ -128,6 +128,12 @@ function import_folder_place_image_node(nodes: zui_nodes_t, canvas: zui_node_can n.buttons[0].default_value = f32_array_create_x(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 }; + let l: zui_node_link_t = { + id: zui_next_link_id(canvas.links.buffer, canvas.links.length), + from_id: n.id, + from_socket: 0, + to_id: to_id, + to_socket: to_socket + }; array_push(canvas.links, l); } diff --git a/armorpaint/Sources/make_material.ts b/armorpaint/Sources/make_material.ts index 4c2994b7..9e1c22db 100644 --- a/armorpaint/Sources/make_material.ts +++ b/armorpaint/Sources/make_material.ts @@ -2,9 +2,9 @@ let make_material_default_scon: shader_context_t = null; let make_material_default_mcon: material_context_t = null; -let make_material_height_used = false; -let make_material_emis_used = false; -let make_material_subs_used = false; +let make_material_height_used: bool = false; +let make_material_emis_used: bool = false; +let make_material_subs_used: bool = false; function make_material_get_mout(): bool { for (let i: i32 = 0; i < ui_nodes_get_canvas_material().nodes.length; ++i) { @@ -271,7 +271,8 @@ function make_material_bake_node_previews() { if (context_raw.node_previews == null) { context_raw.node_previews = map_create(); } - make_material_traverse_nodes(ui_nodes_get_canvas_material().nodes, null, []); + let empty: zui_node_t[] = []; + make_material_traverse_nodes(ui_nodes_get_canvas_material().nodes, null, empty); let keys: string[] = map_keys(context_raw.node_previews); for (let i: i32 = 0; i < keys.length; ++i) { @@ -296,7 +297,7 @@ function make_material_traverse_nodes(nodes: zui_node_t[], group: zui_node_canva if (g.canvas.name == node.name) { array_push(parents, node); make_material_traverse_nodes(g.canvas.nodes, g.canvas, parents); - parents.pop(); + array_pop(parents); break; } } @@ -392,7 +393,12 @@ function make_material_bake_node_preview(node: zui_node_t, group: zui_node_canva } } -function make_material_parse_node_preview_material(node: zui_node_t, group: zui_node_canvas_t = null, parents: zui_node_t[] = null): { scon: shader_context_t, mcon: material_context_t } { +type parse_node_preview_result_t = { + scon: shader_context_t; + mcon: material_context_t; +}; + +function make_material_parse_node_preview_material(node: zui_node_t, group: zui_node_canvas_t = null, parents: zui_node_t[] = null): parse_node_preview_result_t { if (node.outputs.length == 0) { return null; } @@ -410,7 +416,11 @@ function make_material_parse_node_preview_material(node: zui_node_t, group: zui_ return null; } let mcon: material_context_t = material_context_create(mcon_raw); - return { scon: scon, mcon: mcon }; + let result: parse_node_preview_result_t = { + scon: scon, + mcon: mcon + }; + return result; } function make_material_parse_brush() { diff --git a/armorpaint/Sources/make_mesh.ts b/armorpaint/Sources/make_mesh.ts index e8e52d66..90add853 100644 --- a/armorpaint/Sources/make_mesh.ts +++ b/armorpaint/Sources/make_mesh.ts @@ -150,7 +150,8 @@ function make_mesh_run(data: material_t, layer_pass: i32 = 0): node_shader_conte continue; } texture_count++; - node_shader_add_uniform(frag, "sampler2D texpaint_view_mask" + m.id, "_texpaint" + array_index_of(project_layers, m)); + let index: i32 = array_index_of(project_layers, m); + node_shader_add_uniform(frag, "sampler2D texpaint_view_mask" + m.id, "_texpaint" + index); } } @@ -204,7 +205,8 @@ function make_mesh_run(data: material_t, layer_pass: i32 = 0): node_shader_conte if (i > 0) { node_shader_write(frag, " || "); } - node_shader_write(frag, visibles[i].base.uid + " == uid"); + let uid: i32 = visibles[i].base.uid; + node_shader_write(frag, uid + " == uid"); } node_shader_write(frag, ") {"); } @@ -244,7 +246,9 @@ function make_mesh_run(data: material_t, layer_pass: i32 = 0): node_shader_conte node_shader_add_shared_sampler(frag, "sampler2D texpaint" + m.id); node_shader_write(frag, "{"); // Group mask is sampled across multiple layers node_shader_write(frag, "float texpaint_mask_sample" + m.id + " = textureLodShared(texpaint" + m.id + ", texCoord, 0.0).r;"); - node_shader_write(frag, texpaint_mask + " = " + make_material_blend_mode_mask(frag, m.blending, texpaint_mask, "texpaint_mask_sample" + m.id, "float(" + slot_layer_get_opacity(m) + ")") + ";"); + let opac: f32 = slot_layer_get_opacity(m); + let mask: string = make_material_blend_mode_mask(frag, m.blending, texpaint_mask, "texpaint_mask_sample" + m.id, "float(" + opac + ")"); + node_shader_write(frag, texpaint_mask + " = " + mask + ";"); node_shader_write(frag, "}"); } node_shader_write(frag, "texpaint_opac *= clamp(" + texpaint_mask + ", 0.0, 1.0);"); @@ -252,7 +256,8 @@ function make_mesh_run(data: material_t, layer_pass: i32 = 0): node_shader_conte } if (slot_layer_get_opacity(l) < 1) { - node_shader_write(frag, "texpaint_opac *= " + slot_layer_get_opacity(l) + ";"); + let opac: f32 = slot_layer_get_opacity(l); + node_shader_write(frag, "texpaint_opac *= " + opac + ";"); } if (l.paint_base) { @@ -463,9 +468,10 @@ function make_mesh_run(data: material_t, layer_pass: i32 = 0): node_shader_conte node_shader_write(frag, "fragColor[1] = vec4(nAttr, 1.0);"); } else if (context_raw.viewport_mode == viewport_mode_t.MATERIAL_ID) { - node_shader_add_shared_sampler(frag, "sampler2D texpaint_nor" + context_raw.layer.id); + let id: i32 = context_raw.layer.id; + node_shader_add_shared_sampler(frag, "sampler2D texpaint_nor" + id); node_shader_add_uniform(frag, "vec2 texpaintSize", "_texpaintSize"); - node_shader_write(frag, "float sample_matid = texelFetch(texpaint_nor" + context_raw.layer.id + ", ivec2(texCoord * texpaintSize), 0).a + 1.0 / 255.0;"); + node_shader_write(frag, "float sample_matid = texelFetch(texpaint_nor" + id + ", ivec2(texCoord * texpaintSize), 0).a + 1.0 / 255.0;"); node_shader_write(frag, "float matid_r = fract(sin(dot(vec2(sample_matid, sample_matid * 20.0), vec2(12.9898, 78.233))) * 43758.5453);"); node_shader_write(frag, "float matid_g = fract(sin(dot(vec2(sample_matid * 20.0, sample_matid), vec2(12.9898, 78.233))) * 43758.5453);"); node_shader_write(frag, "float matid_b = fract(sin(dot(vec2(sample_matid, sample_matid * 40.0), vec2(12.9898, 78.233))) * 43758.5453);"); @@ -481,15 +487,20 @@ function make_mesh_run(data: material_t, layer_pass: i32 = 0): node_shader_conte } else if (context_raw.viewport_mode == viewport_mode_t.MASK && (slot_layer_get_masks(context_raw.layer) != null || slot_layer_is_mask(context_raw.layer))) { if (slot_layer_is_mask(context_raw.layer)) { - node_shader_write(frag, "float mask_view = textureLodShared(texpaint" + context_raw.layer.id + ", texCoord, 0.0).r;"); + let id: i32 = context_raw.layer.id; + node_shader_write(frag, "float mask_view = textureLodShared(texpaint" + id + ", texCoord, 0.0).r;"); } else { node_shader_write(frag, "float mask_view = 0.0;"); for (let i: i32 = 0; i < slot_layer_get_masks(context_raw.layer).length; ++i) { let m: slot_layer_t = slot_layer_get_masks(context_raw.layer)[i]; - if (!slot_layer_is_visible(m)) continue; + if (!slot_layer_is_visible(m)) { + continue; + } node_shader_write(frag, "float mask_sample" + m.id + " = textureLodShared(texpaint_view_mask" + m.id + ", texCoord, 0.0).r;"); - node_shader_write(frag, "mask_view = " + make_material_blend_mode_mask(frag, m.blending, "mask_view", "mask_sample" + m.id, "float(" + slot_layer_get_opacity(m) + ")") + ";"); + let opac: f32 = slot_layer_get_opacity(m); + let mask: string = make_material_blend_mode_mask(frag, m.blending, "mask_view", "mask_sample" + m.id, "float(" + opac + ")"); + node_shader_write(frag, "mask_view = " + mask + ";"); } } node_shader_write(frag, "fragColor[1] = vec4(mask_view, mask_view, mask_view, 1.0);"); diff --git a/armorpaint/Sources/make_mesh_preview.ts b/armorpaint/Sources/make_mesh_preview.ts index c76bc7a7..21c2cbd4 100644 --- a/armorpaint/Sources/make_mesh_preview.ts +++ b/armorpaint/Sources/make_mesh_preview.ts @@ -55,7 +55,8 @@ function make_mesh_preview_run(data: material_t, matcon: material_context_t): no node_shader_add_uniform(vert, "mat4 WVP", "_world_view_proj_matrix"); node_shader_write_attrib(vert, "gl_Position = mul(vec4(" + pos + ".xyz, 1.0), WVP);"); - let brush_scale: string = (context_raw.brush_scale * context_raw.brush_nodes_scale) + ""; + let sc: f32 = context_raw.brush_scale * context_raw.brush_nodes_scale; + let brush_scale: string = sc + ""; node_shader_add_out(vert, "vec2 texCoord"); node_shader_write_attrib(vert, "texCoord = tex * float(" + brush_scale + ");"); diff --git a/armorpaint/Sources/make_node_preview.ts b/armorpaint/Sources/make_node_preview.ts index e356c641..53757da5 100644 --- a/armorpaint/Sources/make_node_preview.ts +++ b/armorpaint/Sources/make_node_preview.ts @@ -50,7 +50,13 @@ function make_node_preview_run(data: material_t, matcon: material_context_t, nod parser_material_parents = parents; } let links: zui_node_link_t[] = parser_material_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 }; + let link: zui_node_link_t = { + id: zui_next_link_id(links.buffer, links.length), + from_id: node.id, + from_socket: context_raw.node_preview_socket, + to_id: -1, + to_socket: -1 + }; array_push(links, link); parser_material_con = con_mesh; diff --git a/armorpaint/Sources/make_paint.ts b/armorpaint/Sources/make_paint.ts index 47d1eba6..d4921e0c 100644 --- a/armorpaint/Sources/make_paint.ts +++ b/armorpaint/Sources/make_paint.ts @@ -11,18 +11,23 @@ function make_paint_is_raytraced_bake(): bool { function make_paint_color_attachments(): string[] { if (context_raw.tool == workspace_tool_t.COLORID) { - return ["RGBA32"]; + let res: string[] = ["RGBA32"]; + return res; } if (context_raw.tool == workspace_tool_t.PICKER && context_raw.pick_pos_nor_tex) { - return ["RGBA128", "RGBA128"]; + let res: string[] = ["RGBA128", "RGBA128"]; + return res; } if (context_raw.tool == workspace_tool_t.PICKER || context_raw.tool == workspace_tool_t.MATERIAL) { - return ["RGBA32", "RGBA32", "RGBA32", "RGBA32"]; + let res: string[] = ["RGBA32", "RGBA32", "RGBA32", "RGBA32"]; + return res; } if (context_raw.tool == workspace_tool_t.BAKE && make_paint_is_raytraced_bake()) { - return ["RGBA64", "RGBA64"]; + let res: string[] = ["RGBA64", "RGBA64"]; + return res; } - return ["RGBA32", "RGBA32", "RGBA32", "R8"]; + let res: string[] = ["RGBA32", "RGBA32", "RGBA32", "R8"]; + return res; } function make_paint_run(data: material_t, matcon: material_context_t): node_shader_context_t { diff --git a/armorpaint/Sources/nodes/input_node.ts b/armorpaint/Sources/nodes/input_node.ts index 5c1c7e11..eaf2dc99 100644 --- a/armorpaint/Sources/nodes/input_node.ts +++ b/armorpaint/Sources/nodes/input_node.ts @@ -83,7 +83,12 @@ function input_node_update(self: float_node_t) { let dy: f32 = math_abs(input_node_lock_start_y - mouse_view_y()); if (dx > 1 || dy > 1) { input_node_lock_begin = false; - dx > dy ? input_node_lock_y = true : input_node_lock_x = true; + if (dx > dy) { + input_node_lock_y = true; + } + else { + input_node_lock_x = true; + } } } diff --git a/armorpaint/Sources/nodes_brush.ts b/armorpaint/Sources/nodes_brush.ts index fab798a4..639e397c 100644 --- a/armorpaint/Sources/nodes_brush.ts +++ b/armorpaint/Sources/nodes_brush.ts @@ -20,7 +20,7 @@ let nodes_brush_list: node_list_t[] = [ nodes_brush_category0 ]; -let nodes_brush_creates: map_t; +let nodes_brush_creates: map_tlogic_node_ext_t>; function nodes_brush_init() { nodes_brush_creates = map_create(); diff --git a/armorpaint/Sources/render_path_paint.ts b/armorpaint/Sources/render_path_paint.ts index 4fb4d11b..1dae6a34 100644 --- a/armorpaint/Sources/render_path_paint.ts +++ b/armorpaint/Sources/render_path_paint.ts @@ -102,7 +102,7 @@ function render_path_paint_init() { ///end } -function render_path_paint_commands_paint(dilation = true) { +function render_path_paint_commands_paint(dilation: bool = true) { let tid: i32 = context_raw.layer.id; if (context_raw.pdirty > 0) { @@ -142,15 +142,19 @@ function render_path_paint_commands_paint(dilation = true) { else if (context_raw.tool == workspace_tool_t.PICKER || context_raw.tool == workspace_tool_t.MATERIAL) { if (context_raw.pick_pos_nor_tex) { if (context_raw.paint2d) { - render_path_set_target("gbuffer0", ["gbuffer1", "gbuffer2"]); + let additional: string[] = ["gbuffer1", "gbuffer2"]; + render_path_set_target("gbuffer0", additional); render_path_draw_meshes("mesh"); } - render_path_set_target("texpaint_posnortex_picker0", ["texpaint_posnortex_picker1"]); + let additional: string[] = ["texpaint_posnortex_picker1"]; + render_path_set_target("texpaint_posnortex_picker0", additional); render_path_bind_target("gbuffer2", "gbuffer2"); render_path_bind_target("_main", "gbufferD"); render_path_draw_meshes("paint"); - let texpaint_posnortex_picker0: image_t = map_get(render_path_render_targets, "texpaint_posnortex_picker0")._image; - let texpaint_posnortex_picker1: image_t = map_get(render_path_render_targets, "texpaint_posnortex_picker1")._image; + let picker0: render_target_t = map_get(render_path_render_targets, "texpaint_posnortex_picker0"); + let picker1: render_target_t = map_get(render_path_render_targets, "texpaint_posnortex_picker1"); + let texpaint_posnortex_picker0: image_t = picker0._image; + let texpaint_posnortex_picker1: image_t = picker1._image; let a: buffer_view_t = buffer_view_create(image_get_pixels(texpaint_posnortex_picker0)); let b: buffer_view_t = buffer_view_create(image_get_pixels(texpaint_posnortex_picker1)); context_raw.posx_picked = buffer_view_get_f32(a, 0); @@ -163,7 +167,8 @@ function render_path_paint_commands_paint(dilation = true) { context_raw.uvy_picked = buffer_view_get_f32(b, 12); } else { - render_path_set_target("texpaint_picker", ["texpaint_nor_picker", "texpaint_pack_picker", "texpaint_uv_picker"]); + let additional: string[] = ["texpaint_nor_picker", "texpaint_pack_picker", "texpaint_uv_picker"]; + render_path_set_target("texpaint_picker", additional); render_path_bind_target("gbuffer2", "gbuffer2"); tid = context_raw.layer.id; let use_live_layer: bool = context_raw.tool == workspace_tool_t.MATERIAL; @@ -180,14 +185,14 @@ function render_path_paint_commands_paint(dilation = true) { ui_header_handle.redraws = 2; ui_base_hwnds[2].redraws = 2; - let texpaint_picker: image_t = map_get(render_path_render_targets, "texpaint_picker")._image; - let texpaint_nor_picker: image_t = map_get(render_path_render_targets, "texpaint_nor_picker")._image; - let texpaint_pack_picker: image_t = map_get(render_path_render_targets, "texpaint_pack_picker")._image; - let texpaint_uv_picker: image_t = map_get(render_path_render_targets, "texpaint_uv_picker")._image; - let a: buffer_view_t = buffer_view_create(image_get_pixels(texpaint_picker)); - let b: buffer_view_t = buffer_view_create(image_get_pixels(texpaint_nor_picker)); - let c: buffer_view_t = buffer_view_create(image_get_pixels(texpaint_pack_picker)); - let d: buffer_view_t = buffer_view_create(image_get_pixels(texpaint_uv_picker)); + let texpaint_picker: render_target_t = map_get(render_path_render_targets, "texpaint_picker"); + let texpaint_nor_picker: render_target_t = map_get(render_path_render_targets, "texpaint_nor_picker"); + let texpaint_pack_picker: render_target_t = map_get(render_path_render_targets, "texpaint_pack_picker"); + let texpaint_uv_picker: render_target_t = map_get(render_path_render_targets, "texpaint_uv_picker"); + let a: buffer_view_t = buffer_view_create(image_get_pixels(texpaint_picker._image)); + let b: buffer_view_t = buffer_view_create(image_get_pixels(texpaint_nor_picker._image)); + let c: buffer_view_t = buffer_view_create(image_get_pixels(texpaint_pack_picker._image)); + let d: buffer_view_t = buffer_view_create(image_get_pixels(texpaint_uv_picker._image)); if (context_raw.color_picker_callback != null) { context_raw.color_picker_callback(context_raw.picked_color); @@ -271,10 +276,12 @@ function render_path_paint_commands_paint(dilation = true) { break; } } - render_path_set_target(texpaint, ["texpaint_nor" + ptid, "texpaint_pack" + ptid, "texpaint_blend0"]); + let additional: string[] = ["texpaint_nor" + ptid, "texpaint_pack" + ptid, "texpaint_blend0"]; + render_path_set_target(texpaint, additional); } else { - render_path_set_target(texpaint, ["texpaint_nor" + tid, "texpaint_pack" + tid, "texpaint_blend0"]); + let additional: string[] = ["texpaint_nor" + tid, "texpaint_pack" + tid, "texpaint_blend0"]; + render_path_set_target(texpaint, additional); } render_path_bind_target("_main", "gbufferD"); if ((context_raw.xray || config_raw.brush_angle_reject) && config_raw.brush_3d) { @@ -303,7 +310,7 @@ function render_path_paint_commands_paint(dilation = true) { if (context_raw.tool == workspace_tool_t.BAKE && context_raw.bake_type == bake_type_t.CURVATURE && context_raw.bake_curv_smooth > 0) { if (map_get(render_path_render_targets, "texpaint_blur") == null) { - let t = render_target_create(); + let t: render_target_t = render_target_create(); t.name = "texpaint_blur"; t.width = math_floor(config_get_texture_res_x() * 0.95); t.height = math_floor(config_get_texture_res_y() * 0.95); @@ -332,7 +339,8 @@ function render_path_paint_commands_paint(dilation = true) { render_path_set_target("texpaint_blend1"); render_path_bind_target("texpaint_blend0", "tex"); render_path_draw_shader("shader_datas/copy_pass/copyR8_pass"); - render_path_set_target(texpaint, ["texpaint_blend0"]); + let additional: string[] = ["texpaint_blend0"]; + render_path_set_target(texpaint, additional); render_path_bind_target("gbufferD_undo", "gbufferD"); if ((context_raw.xray || config_raw.brush_angle_reject) && config_raw.brush_3d) { render_path_bind_target("gbuffer0", "gbuffer0"); @@ -380,13 +388,13 @@ function render_path_paint_use_live_layer(use: bool) { _render_path_paint_texpaint_pack_undo = map_get(render_path_render_targets, "texpaint_pack_undo" + hid); _render_path_paint_texpaint_nor = map_get(render_path_render_targets, "texpaint_nor" + tid); _render_path_paint_texpaint_pack = map_get(render_path_render_targets, "texpaint_pack" + tid); - map_set(render_path_render_targets, "texpaint_undo" + hid,map_get(render_path_render_targets, "texpaint" + tid)); - map_set(render_path_render_targets, "texpaint" + tid,map_get(render_path_render_targets, "texpaint_live")); + map_set(render_path_render_targets, "texpaint_undo" + hid, map_get(render_path_render_targets, "texpaint" + tid)); + map_set(render_path_render_targets, "texpaint" + tid, map_get(render_path_render_targets, "texpaint_live")); if (slot_layer_is_layer(context_raw.layer)) { - map_set(render_path_render_targets, "texpaint_nor_undo" + hid,map_get(render_path_render_targets, "texpaint_nor" + tid)); - map_set(render_path_render_targets, "texpaint_pack_undo" + hid,map_get(render_path_render_targets, "texpaint_pack" + tid)); - map_set(render_path_render_targets, "texpaint_nor" + tid,map_get(render_path_render_targets, "texpaint_nor_live")); - map_set(render_path_render_targets, "texpaint_pack" + tid,map_get(render_path_render_targets, "texpaint_pack_live")); + map_set(render_path_render_targets, "texpaint_nor_undo" + hid, map_get(render_path_render_targets, "texpaint_nor" + tid)); + map_set(render_path_render_targets, "texpaint_pack_undo" + hid, map_get(render_path_render_targets, "texpaint_pack" + tid)); + map_set(render_path_render_targets, "texpaint_nor" + tid, map_get(render_path_render_targets, "texpaint_nor_live")); + map_set(render_path_render_targets, "texpaint_pack" + tid, map_get(render_path_render_targets, "texpaint_pack_live")); } } else { @@ -429,7 +437,8 @@ function render_path_paint_commands_live_brush() { render_path_draw_shader("shader_datas/copy_pass/copy_pass"); } else { - render_path_set_target("texpaint_live", ["texpaint_nor_live", "texpaint_pack_live"]); + let additional: string[] = ["texpaint_nor_live", "texpaint_pack_live"]; + render_path_set_target("texpaint_live", additional); render_path_bind_target("texpaint" + tid, "tex0"); render_path_bind_target("texpaint_nor" + tid, "tex1"); render_path_bind_target("texpaint_pack" + tid, "tex2"); @@ -516,7 +525,8 @@ function render_path_paint_draw_cursor(mx: f32, my: f32, radius: f32, tint_r: f3 let decal_mask: bool = decal && operator_shortcut(map_get(config_keymap, "decal_mask"), shortcut_type_t.DOWN); let img: image_t = (decal && !decal_mask) ? context_raw.decal_image : resource_get("cursor.k"); g4_set_tex(base_cursor_tex, img); - let gbuffer0: image_t = map_get(render_path_render_targets, "gbuffer0")._image; + let rt: render_target_t = map_get(render_path_render_targets, "gbuffer0"); + let gbuffer0: image_t = rt._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); @@ -529,7 +539,13 @@ function render_path_paint_draw_cursor(mx: f32, my: f32, radius: f32, tint_r: f3 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"}])); + let vs: vertex_element_t = [ + { + name: "tex", + data: "short2norm" + } + ]; + g4_set_vertex_buffer(mesh_data_get(geom, vs)); ///else g4_set_vertex_buffer(geom._.vertex_buffer); ///end @@ -720,27 +736,29 @@ function render_path_paint_draw() { } context_select_paint_object(_paint_object); - let _render_final = function () { - context_raw.bake_type = _bake_type; - make_material_parse_paint_material(); - context_raw.pdirty = 1; - render_path_paint_commands_paint(); - context_raw.pdirty = 0; - render_path_paint_baking = false; - } - let _render_deriv = function () { - context_raw.bake_type = bake_type_t.HEIGHT; - make_material_parse_paint_material(); - context_raw.pdirty = 1; - render_path_paint_commands_paint(); - context_raw.pdirty = 0; - if (render_path_paint_push_undo_last) { - history_paint(); - } - app_notify_on_init(_render_final); - } - // @ts-ignore - app_notify_on_init(context_raw.bake_type == bake_type_t.DERIVATIVE ? _render_deriv : _render_final); + //// + // let _render_final: ()=>void = function () { + // context_raw.bake_type = _bake_type; + // make_material_parse_paint_material(); + // context_raw.pdirty = 1; + // render_path_paint_commands_paint(); + // context_raw.pdirty = 0; + // render_path_paint_baking = false; + // } + // let _render_deriv: ()=>void = function () { + // context_raw.bake_type = bake_type_t.HEIGHT; + // make_material_parse_paint_material(); + // context_raw.pdirty = 1; + // render_path_paint_commands_paint(); + // context_raw.pdirty = 0; + // if (render_path_paint_push_undo_last) { + // history_paint(); + // } + // app_notify_on_init(_render_final); + // } + // // @ts-ignore + // app_notify_on_init(context_raw.bake_type == bake_type_t.DERIVATIVE ? _render_deriv : _render_final); + //// } } else if (context_raw.bake_type == bake_type_t.OBJECTID) { @@ -794,7 +812,8 @@ function render_path_paint_draw() { render_path_set_target("texpaint_blend1"); render_path_clear_target(0x00000000); ///else - render_path_set_target("texpaint_blend0", ["texpaint_blend1"]); + let additional: string[] = ["texpaint_blend1"]; + render_path_set_target("texpaint_blend0", additional); render_path_clear_target(0x00000000); ///end } @@ -863,7 +882,8 @@ function render_path_paint_set_plane_mesh() { scale_tex: 1.0 }; let md: mesh_data_t = mesh_data_create(raw); - let materials: material_data_t[] = scene_get_child(".Plane").ext.materials; + let mo: mesh_object_t = scene_get_child(".Plane").ext; + let materials: material_data_t[] = mo.materials; let o: mesh_object_t = scene_add_mesh_object(md, materials); o.base.name = ".PlaneTiled"; } diff --git a/armorpaint/Sources/render_path_preview.ts b/armorpaint/Sources/render_path_preview.ts index 74fc810d..b947f90f 100644 --- a/armorpaint/Sources/render_path_preview.ts +++ b/armorpaint/Sources/render_path_preview.ts @@ -71,7 +71,8 @@ function render_path_preview_commands_preview() { render_path_set_target("mgbuffer0"); render_path_clear_target(0xffffffff, 1.0, clear_flag_t.COLOR | clear_flag_t.DEPTH); - render_path_set_target("mgbuffer0", ["mgbuffer1", "mgbuffer2"]); + let additional: string[] = ["mgbuffer1", "mgbuffer2"]; + render_path_set_target("mgbuffer0", additional); render_path_draw_meshes("mesh"); // Deferred light @@ -97,8 +98,10 @@ function render_path_preview_commands_preview() { let framebuffer: string = "texpreview"; let selected_mat: slot_material_t = context_raw.material; - map_get(render_path_render_targets, "texpreview")._image = selected_mat.image; - map_get(render_path_render_targets, "texpreview_icon")._image = selected_mat.image_icon; + let texpreview: render_target_t = map_get(render_path_render_targets, "texpreview"); + let texpreview_icon: render_target_t = map_get(render_path_render_targets, "texpreview_icon"); + texpreview._image = selected_mat.image; + texpreview_icon._image = selected_mat.image_icon; render_path_set_target(framebuffer); render_path_bind_target("mtex", "tex"); @@ -115,7 +118,8 @@ function render_path_preview_commands_decal() { render_path_set_target("gbuffer0"); render_path_clear_target(0xffffffff, 1.0, clear_flag_t.COLOR | clear_flag_t.DEPTH); - render_path_set_target("gbuffer0", ["gbuffer1", "gbuffer2"]); + let additional: string[] = ["gbuffer1", "gbuffer2"]; + render_path_set_target("gbuffer0", additional); render_path_draw_meshes("mesh"); // Deferred light @@ -140,7 +144,8 @@ function render_path_preview_commands_decal() { ///end let framebuffer: string = "texpreview"; - map_get(render_path_render_targets, "texpreview")._image = context_raw.decal_image; + let texpreview: render_target_t = map_get(render_path_render_targets, "texpreview"); + texpreview._image = context_raw.decal_image; render_path_set_target(framebuffer); diff --git a/armorpaint/Sources/slot_brush.ts b/armorpaint/Sources/slot_brush.ts index bebf9716..95ab5564 100644 --- a/armorpaint/Sources/slot_brush.ts +++ b/armorpaint/Sources/slot_brush.ts @@ -25,11 +25,12 @@ function slot_brush_create(c: zui_node_canvas_t = null): slot_brush_t { if (c == null) { if (slot_brush_default_canvas == null) { // Synchronous - let b: buffer_t = data_get_blob("default_brush.arm") + let b: buffer_t = data_get_blob("default_brush.arm"); slot_brush_default_canvas = b; } raw.canvas = armpack_decode(slot_brush_default_canvas); - raw.canvas.name = "Brush " + (raw.id + 1); + let id: i32 = (raw.id + 1); + raw.canvas.name = "Brush " + id; } else { raw.canvas = c; diff --git a/armorpaint/Sources/slot_layer.ts b/armorpaint/Sources/slot_layer.ts index b80f1c5d..5fe5e94f 100644 --- a/armorpaint/Sources/slot_layer.ts +++ b/armorpaint/Sources/slot_layer.ts @@ -72,10 +72,12 @@ function slot_layer_create(ext: string = "", type: layer_slot_type_t = layer_slo raw.parent = parent; if (type == layer_slot_type_t.GROUP) { - raw.name = "Group " + (raw.id + 1); + let id: i32 = (raw.id + 1); + raw.name = "Group " + id; } else if (type == layer_slot_type_t.LAYER) { - raw.name = "Layer " + (raw.id + 1); + let id: i32 = (raw.id + 1); + raw.name = "Layer " + id; ///if is_paint let format: string = base_bits_handle.position == texture_bits_t.BITS8 ? "RGBA32" : base_bits_handle.position == texture_bits_t.BITS16 ? "RGBA64" : @@ -119,7 +121,8 @@ function slot_layer_create(ext: string = "", type: layer_slot_type_t = layer_slo ///if is_paint else { // Mask - raw.name = "Mask " + (raw.id + 1); + let id: i32 = (raw.id + 1); + raw.name = "Mask " + id; let format: string = "RGBA32"; // Full bits for undo support, R8 is used raw.blending = blend_type_t.ADD; @@ -219,8 +222,10 @@ function slot_layer_unload(raw: slot_layer_t) { function slot_layer_swap(raw: slot_layer_t, other: slot_layer_t) { if ((slot_layer_is_layer(raw) || slot_layer_is_mask(raw)) && (slot_layer_is_layer(other) || slot_layer_is_mask(other))) { - map_get(render_path_render_targets, "texpaint" + raw.ext)._image = other.texpaint; - map_get(render_path_render_targets, "texpaint" + other.ext)._image = raw.texpaint; + let rt0: render_target_t = map_get(render_path_render_targets, "texpaint" + raw.ext); + let rt1: render_target_t = map_get(render_path_render_targets, "texpaint" + other.ext); + rt0._image = other.texpaint; + rt1._image = raw.texpaint; let _texpaint: image_t = raw.texpaint; raw.texpaint = other.texpaint; other.texpaint = _texpaint; @@ -234,10 +239,14 @@ function slot_layer_swap(raw: slot_layer_t, other: slot_layer_t) { ///if is_paint if (slot_layer_is_layer(raw) && slot_layer_is_layer(other)) { - map_get(render_path_render_targets, "texpaint_nor" + raw.ext)._image = other.texpaint_nor; - map_get(render_path_render_targets, "texpaint_pack" + raw.ext)._image = other.texpaint_pack; - map_get(render_path_render_targets, "texpaint_nor" + other.ext)._image = raw.texpaint_nor; - map_get(render_path_render_targets, "texpaint_pack" + other.ext)._image = raw.texpaint_pack; + let nor0: render_target_t = map_get(render_path_render_targets, "texpaint_nor" + raw.ext); + nor0._image = other.texpaint_nor; + let pack0: render_target_t = map_get(render_path_render_targets, "texpaint_pack" + raw.ext); + pack0._image = other.texpaint_pack; + let nor1: render_target_t = map_get(render_path_render_targets, "texpaint_nor" + other.ext); + nor1._image = raw.texpaint_nor; + let pack1: render_target_t = map_get(render_path_render_targets, "texpaint_pack" + other.ext); + pack1._image = 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; @@ -287,7 +296,8 @@ function slot_layer_invert_mask(raw: slot_layer_t) { app_notify_on_next_frame(function (_texpaint: image_t) { image_unload(_texpaint); }, _texpaint); - raw.texpaint = map_get(render_path_render_targets, "texpaint" + raw.id)._image = inverted; + let rt: render_target_t = map_get(render_path_render_targets, "texpaint" + raw.id); + raw.texpaint = rt._image = inverted; context_raw.layer_preview_dirty = true; context_raw.ddirty = 3; } @@ -436,10 +446,13 @@ function slot_layer_resize_and_set_bits(raw: slot_layer_t) { }, _texpaint_pack); ///end - map_get(rts, "texpaint" + raw.ext)._image = raw.texpaint; + let rt: render_target_t = map_get(rts, "texpaint" + raw.ext); + rt._image = raw.texpaint; ///if is_paint - map_get(rts, "texpaint_nor" + raw.ext)._image = raw.texpaint_nor; - map_get(rts, "texpaint_pack" + raw.ext)._image = raw.texpaint_pack; + let rt_nor: render_target_t = map_get(rts, "texpaint_nor" + raw.ext); + rt_nor._image = raw.texpaint_nor; + let rt_pack: render_target_t = map_get(rts, "texpaint_pack" + raw.ext); + rt_pack._image = raw.texpaint_pack; ///end } else if (slot_layer_is_mask(raw)) { @@ -456,7 +469,8 @@ function slot_layer_resize_and_set_bits(raw: slot_layer_t) { image_unload(_texpaint); }, _texpaint); - map_get(rts, "texpaint" + raw.ext)._image = raw.texpaint; + let rt: render_target_t = map_get(rts, "texpaint" + raw.ext); + rt._image = raw.texpaint; } } @@ -517,7 +531,7 @@ function slot_layer_get_recursive_children(raw: slot_layer_t): slot_layer_t[] { return children; } -function slot_layer_get_masks(raw: slot_layer_t, includeGroupMasks = true): slot_layer_t[] { +function slot_layer_get_masks(raw: slot_layer_t, include_group_masks: bool = true): slot_layer_t[] { if (slot_layer_is_mask(raw)) { return null; } @@ -534,7 +548,7 @@ function slot_layer_get_masks(raw: slot_layer_t, includeGroupMasks = true): slot } } // Child masks of a parent group - if (includeGroupMasks) { + if (include_group_masks) { if (raw.parent != null && slot_layer_is_group(raw.parent)) { for (let i: i32 = 0; i < project_layers.length; ++i) { let l: slot_layer_t = project_layers[i]; @@ -550,7 +564,7 @@ function slot_layer_get_masks(raw: slot_layer_t, includeGroupMasks = true): slot return children; } -function slot_layer_has_masks(raw: slot_layer_t, includeGroupMasks = true): bool { +function slot_layer_has_masks(raw: slot_layer_t, include_group_masks: bool = true): bool { // Layer mask for (let i: i32 = 0; i < project_layers.length; ++i) { let l: slot_layer_t = project_layers[i]; @@ -559,7 +573,7 @@ function slot_layer_has_masks(raw: slot_layer_t, includeGroupMasks = true): bool } } // Group mask - if (includeGroupMasks && raw.parent != null && slot_layer_is_group(raw.parent)) { + if (include_group_masks && raw.parent != null && slot_layer_is_group(raw.parent)) { for (let i: i32 = 0; i < project_layers.length; ++i) { let l: slot_layer_t = project_layers[i]; if (l.parent == raw.parent && slot_layer_is_mask(l)) { diff --git a/armorpaint/Sources/slot_material.ts b/armorpaint/Sources/slot_material.ts index d9812294..d4bb817a 100644 --- a/armorpaint/Sources/slot_material.ts +++ b/armorpaint/Sources/slot_material.ts @@ -54,7 +54,8 @@ function slot_material_create(m: material_data_t = null, c: zui_node_canvas_t = slot_material_default_canvas = b; } raw.canvas = armpack_decode(slot_material_default_canvas); - raw.canvas.name = "Material " + (raw.id + 1); + let id: i32 = (raw.id + 1); + raw.canvas.name = "Material " + id; } else { raw.canvas = c; diff --git a/armorpaint/Sources/tab_layers.ts b/armorpaint/Sources/tab_layers.ts index acbc5f2b..287c8160 100644 --- a/armorpaint/Sources/tab_layers.ts +++ b/armorpaint/Sources/tab_layers.ts @@ -149,7 +149,7 @@ function tab_layers_button_new(text: string) { } let pointers: map_t = tab_layers_init_layer_map(); - let group = base_new_group(); + let group: slot_layer_t = base_new_group(); context_set_layer(l); array_remove(project_layers, group); array_insert(project_layers, array_index_of(project_layers, l) + 1, group); @@ -213,9 +213,9 @@ function tab_layers_remap_layer_pointers(nodes: zui_node_t[], pointer_map: map_t for (let i: i32 = 0; i < nodes.length; ++i) { let n: zui_node_t = nodes[i]; if (n.type == "LAYER" || n.type == "LAYER_MASK") { - let i: any = n.buttons[0].default_value; + let i: i32 = n.buttons[0].default_value[0]; if (map_get(pointer_map, i) != null) { - n.buttons[0].default_value = map_get(pointer_map, i); + n.buttons[0].default_value[0] = map_get(pointer_map, i); } } } @@ -314,7 +314,7 @@ function tab_layers_draw_layer_slot(l: slot_layer_t, i: i32, mini: bool) { } function tab_layers_draw_layer_slot_mini(l: slot_layer_t, i: i32) { - let ui = ui_base_ui; + let ui: zui_t = ui_base_ui; let row: f32[] = [1, 1]; zui_row(row); @@ -356,7 +356,7 @@ function tab_layers_draw_layer_slot_full(l: slot_layer_t, i: i32) { col -= 0x99000000; } - if (zui_image(icons, col, -1.0, r.x, r.y, r.w, r.h) == zui_state_t.RELEASED) { + if (_zui_image(icons, col, -1.0, r.x, r.y, r.w, r.h) == zui_state_t.RELEASED) { tab_layers_layer_toggle_visible(l); } ui._x -= 2; @@ -396,10 +396,10 @@ function tab_layers_draw_layer_slot_full(l: slot_layer_t, i: i32) { if (tab_layers_layer_name_edit == l.id) { tab_layers_layer_name_handle.text = l.name; l.name = zui_text_input(tab_layers_layer_name_handle); - if (ui.text_selected_handle_ptr != tab_layers_layer_name_handle.ptr) tab_layers_layer_name_edit = -1; + if (ui.text_selected_handle != tab_layers_layer_name_handle) tab_layers_layer_name_edit = -1; } else { - if (ui.enabled && ui.input_enabled && ui.combo_selected_handle_ptr == 0 && + if (ui.enabled && ui.input_enabled && ui.combo_selected_handle == 0 && ui.input_x > ui._window_x + ui._x && ui.input_x < ui._window_x + ui._window_w && ui.input_y > ui._window_y + ui._y - center && ui.input_y < ui._window_y + ui._y - center + (step * zui_SCALE(ui)) * 2) { if (ui.input_started) { @@ -597,7 +597,8 @@ function tab_layers_handle_layer_icon_state(l: slot_layer_t, i: i32, state: zui_ zui_tooltip_image(texpaint_preview); } if (i < 9) { - zui_tooltip(l.name + " - (" + map_get(config_keymap, "select_layer") + " " + (i + 1) + ")"); + let i1: i32 = (i + 1); + zui_tooltip(l.name + " - (" + map_get(config_keymap, "select_layer") + " " + i1 + ")"); } else { zui_tooltip(l.name); @@ -627,7 +628,7 @@ function tab_layers_handle_layer_icon_state(l: slot_layer_t, i: i32, state: zui_ } } -function tab_layers_draw_layer_icon(l: slot_layer_t, i: i32, uix: f32, uiy: f32, mini: bool) { +function tab_layers_draw_layer_icon(l: slot_layer_t, i: i32, uix: f32, uiy: f32, mini: bool): zui_state_t { let ui: zui_t = ui_base_ui; let icons: image_t = resource_get("icons.k"); let icon_h: i32 = (zui_ELEMENT_H(ui) - (mini ? 2 : 3)) * 2; @@ -660,8 +661,8 @@ function tab_layers_draw_layer_icon(l: slot_layer_t, i: i32, uix: f32, uiy: f32, 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--; + _zui_image(icons, 0xffffffff, icon_h, r.x, r.y, r.w, r.h); + ui.current_ratio--; ui._x = _x; ui._y = _y; ui._w = _w; @@ -674,7 +675,7 @@ function tab_layers_draw_layer_icon(l: slot_layer_t, i: i32, uix: f32, uiy: f32, krom_g4_set_int(ui_view2d_channel_loc, 1); } - let state: zui_state_t = zui_image(icon, 0xffffffff, icon_h); + let state: zui_state_t = _zui_image(icon, 0xffffffff, icon_h); if (l.fill_layer == null && slot_layer_is_mask(l)) { g2_set_pipeline(null); @@ -684,7 +685,7 @@ function tab_layers_draw_layer_icon(l: slot_layer_t, i: i32, uix: f32, uiy: f32, let is_typing: bool = ui.is_typing || ui_view2d_ui.is_typing || ui_nodes_ui.is_typing; if (!is_typing) { if (i < 9 && operator_shortcut(map_get(config_keymap, "select_layer"), shortcut_type_t.DOWN)) { - let number: string = any_to_string(i + 1) ; + let number: string = i32_to_string(i + 1) ; let width: i32 = g2_font_width(ui.ops.font, ui.font_size, number) + 10; let height: i32 = g2_font_height(ui.ops.font, ui.font_size); g2_set_color(ui.ops.theme.TEXT_COL); @@ -700,11 +701,11 @@ function tab_layers_draw_layer_icon(l: slot_layer_t, i: i32, uix: f32, uiy: f32, let folder_closed: rect_t = resource_tile50(icons, 2, 1); let folder_open: rect_t = resource_tile50(icons, 8, 1); let folder: rect_t = l.show_panel ? folder_open : folder_closed; - return zui_image(icons, ui.ops.theme.LABEL_COL - 0x00202020, icon_h, folder.x, folder.y, folder.w, folder.h); + return _zui_image(icons, ui.ops.theme.LABEL_COL - 0x00202020, icon_h, folder.x, folder.y, folder.w, folder.h); } } -function tab_layers_can_merge_down(l: slot_layer_t) : bool { +function tab_layers_can_merge_down(l: slot_layer_t): bool { let index: i32 = array_index_of(project_layers, l); // Lowest layer if (index == 0) { @@ -934,15 +935,17 @@ function tab_layers_draw_layer_context_menu(l: slot_layer_t, mini: bool) { base_on_layers_resized(); } ui._y = _y; - zui_draw_string(tr("Res"), null, 0, zui_align_t.RIGHT); + zui_draw_string(tr("Res"), -1, 0, zui_align_t.RIGHT, true); zui_end_element(); ui_menu_fill(ui); ui_menu_align(ui); ///if (krom_android || krom_ios) - zui_inline_radio(base_bits_handle, ["8bit"]); + let bits_items: string[] = ["8bit"]; + zui_inline_radio(base_bits_handle, bits_items, zui_align_t.LEFT); ///else - zui_inline_radio(base_bits_handle, ["8bit", "16bit", "32bit"]); + let bits_items: string[] = ["8bit", "16bit", "32bit"]; + zui_inline_radio(base_bits_handle, bits_items, zui_align_t.LEFT); ///end if (base_bits_handle.changed) { app_notify_on_init(base_set_layer_bits); @@ -984,7 +987,8 @@ function tab_layers_draw_layer_context_menu(l: slot_layer_t, mini: bool) { ui_menu_align(ui); let uv_type_handle: zui_handle_t = zui_nest(zui_handle(__ID__), 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); + let uv_type_items: string[] = [tr("UV Map"), tr("Triplanar"), tr("Project")]; + l.uv_type = zui_inline_radio(uv_type_handle, uv_type_items, zui_align_t.LEFT); if (uv_type_handle.changed) { context_set_material(l.fill_layer); context_set_layer(l); @@ -1149,7 +1153,7 @@ function tab_layers_delete_layer(l: slot_layer_t) { } } -function tab_layers_can_delete(l: slot_layer_t) { +function tab_layers_can_delete(l: slot_layer_t): bool { let num_layers: i32 = 0; if (slot_layer_is_mask(l)) { @@ -1172,7 +1176,7 @@ function tab_layers_can_delete(l: slot_layer_t) { return num_layers > 1; } -function tab_layers_can_drop_new_layer(position: i32) { +function tab_layers_can_drop_new_layer(position: i32): bool { if (position > 0 && position < project_layers.length && slot_layer_is_mask(project_layers[position - 1])) { // 1. The layer to insert is inserted in the middle // 2. The layer below is a mask, i.e. the layer would have to be a (group) mask, too. diff --git a/armorsculpt/Sources/export_obj.ts b/armorsculpt/Sources/export_obj.ts index 1bafc8a1..4e61c1eb 100644 --- a/armorsculpt/Sources/export_obj.ts +++ b/armorsculpt/Sources/export_obj.ts @@ -35,7 +35,7 @@ function export_obj_run(path: string, paint_objects: mesh_object_t[], apply_disp // Merge shared vertices and remap indices let posa2: i16_array_t = i16_array_create(len * 3); - let posmap: map_t = map_create(); + let posmap: i32_array_t = i32_array_create(len); let pi = 0; for (let i: i32 = 0; i < len; ++i) { @@ -44,13 +44,13 @@ function export_obj_run(path: string, paint_objects: mesh_object_t[], apply_disp if (posa2[j * 3 ] == posa[i * 4 ] && posa2[j * 3 + 1] == posa[i * 4 + 1] && posa2[j * 3 + 2] == posa[i * 4 + 2]) { - map_set(posmap, i, j); + posmap[i] = j; found = true; break; } } if (!found) { - map_set(posmap, i, pi); + posmap[i] = pi; posa2[pi * 3 ] = posa[i * 4 ]; posa2[pi * 3 + 1] = posa[i * 4 + 1]; posa2[pi * 3 + 2] = posa[i * 4 + 2]; @@ -74,9 +74,9 @@ function export_obj_run(path: string, paint_objects: mesh_object_t[], apply_disp // let inda = mesh.index_arrays[0].values; for (let i: i32 = 0; i < math_floor(inda.length / 3); ++i) { - let pi1 = map_get(posmap, inda[i * 3 ]) + 1 + poff; - let pi2 = map_get(posmap, inda[i * 3 + 1]) + 1 + poff; - let pi3 = map_get(posmap, inda[i * 3 + 2]) + 1 + poff; + let pi1 = posmap[inda[i * 3 ]] + 1 + poff; + let pi2 = posmap[inda[i * 3 + 1]] + 1 + poff; + let pi3 = posmap[inda[i * 3 + 2]] + 1 + poff; export_obj_write_string(o, "f "); export_obj_write_string(o, pi1 + ""); export_obj_write_string(o, " "); diff --git a/armorsculpt/Sources/tab_layers.ts b/armorsculpt/Sources/tab_layers.ts index 345f79f2..ffd827ab 100644 --- a/armorsculpt/Sources/tab_layers.ts +++ b/armorsculpt/Sources/tab_layers.ts @@ -237,7 +237,7 @@ function tab_layers_draw_layer_slot_full(l: slot_layer_t, i: i32) { col -= 0x99000000; } - if (zui_image(icons, col, -1.0, r.x, r.y, r.w, r.h) == zui_state_t.RELEASED) { + if (_zui_image(icons, col, -1.0, r.x, r.y, r.w, r.h) == zui_state_t.RELEASED) { tab_layers_layer_toggle_visible(l); } ui._x -= 2; @@ -252,12 +252,12 @@ function tab_layers_draw_layer_slot_full(l: slot_layer_t, i: i32) { if (tab_layers_layer_name_edit == l.id) { tab_layers_layer_name_handle.text = l.name; l.name = zui_text_input(tab_layers_layer_name_handle); - if (ui.text_selected_handle_ptr != tab_layers_layer_name_handle.ptr) { + if (ui.text_selected_handle != tab_layers_layer_name_handle) { tab_layers_layer_name_edit = -1; } } else { - if (ui.enabled && ui.input_enabled && ui.combo_selected_handle_ptr == 0 && + if (ui.enabled && ui.input_enabled && ui.combo_selected_handle == 0 && ui.input_x > ui._window_x + ui._x && ui.input_x < ui._window_x + ui._window_w && ui.input_y > ui._window_y + ui._y - center && ui.input_y < ui._window_y + ui._y - center + (step * zui_SCALE(ui)) * 2) { if (ui.input_started) { @@ -412,7 +412,7 @@ function tab_layers_draw_layer_context_menu(l: slot_layer_t, mini: bool) { } -function tab_layers_can_drop_new_layer(position: i32) { +function tab_layers_can_drop_new_layer(position: i32): bool { if (position > 0 && position < project_layers.length && slot_layer_is_mask(project_layers[position - 1])) { // 1. The layer to insert is inserted in the middle // 2. The layer below is a mask, i.e. the layer would have to be a (group) mask, too. diff --git a/base/Sources/args.ts b/base/Sources/args.ts index e58947a9..f7fcd2be 100644 --- a/base/Sources/args.ts +++ b/base/Sources/args.ts @@ -134,7 +134,8 @@ function args_run() { // Get export preset and apply the correct one from args box_export_files = file_read_directory(path_data() + path_sep + "export_presets"); for (let i: i32 = 0; i < box_export_files.length; ++i) { - box_export_files[i] = substring(box_export_files[i], 0, box_export_files[i].length - 5); // Strip .json + let s: string = box_export_files[i]; + box_export_files[i] = substring(s, 0, s.length - 5); // Strip .json } let file: string = "export_presets/" + box_export_files[0] + ".json"; diff --git a/base/Sources/base.ts b/base/Sources/base.ts index a385f536..76e83015 100644 --- a/base/Sources/base.ts +++ b/base/Sources/base.ts @@ -15,7 +15,7 @@ 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_theme: zui_theme_t; let base_color_wheel: image_t; let base_color_wheel_gradient: image_t; let base_ui_box: zui_t; @@ -101,6 +101,7 @@ let base_max_layers: i32 = 255; ///end ///end let base_default_fov: f32 = 0.69; +let _base_material_count: i32; function base_get_default_keymap(): map_t { let keymap: map_t = map_create(); @@ -236,15 +237,16 @@ function base_init() { base_color_wheel = image_color_wheel; base_color_wheel_gradient = image_color_wheel_gradient; - zui_set_enum_texts(base_enum_texts); + // zui_set_enum_texts(base_enum_texts); + zui_nodes_enum_texts = base_enum_texts; zui_tr = tr; let ops: zui_options_t = { theme: base_theme, - font: f, + font: f.font_, scale_factor: config_raw.window_scale, - color_wheel: base_color_wheel, - black_white_gradient: base_color_wheel_gradient - } + color_wheel: base_color_wheel.texture_, + black_white_gradient: base_color_wheel_gradient.texture_ + }; base_ui_box = zui_create(ops); base_ui_menu = zui_create(ops); base_default_element_h = base_ui_menu.ops.theme.ELEMENT_H; @@ -566,7 +568,7 @@ function base_update() { ///end } // Disable touch scrolling while dragging is active - zui_set_touch_scroll(!base_is_dragging); + zui_touch_scroll = !base_is_dragging; } if (has_drag && (mouse_movement_x != 0 || mouse_movement_y != 0)) { @@ -621,10 +623,10 @@ function base_update() { base_drop_y = mouse_y; ///if (is_paint || is_sculpt) - let material_count: i32 = project_materials.length; + _base_material_count = project_materials.length; import_asset_run(base_drag_file, base_drop_x, base_drop_y, true, true, function () { // Asset was material - if (project_materials.length > material_count) { + if (project_materials.length > _base_material_count) { base_drag_material = context_raw.material; base_material_dropped(); } @@ -668,7 +670,7 @@ function base_update() { ///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 || + zui_always_redraw_window = !context_raw.cache_draws || ui_menu_show || ui_box_show || base_is_dragging || @@ -676,11 +678,11 @@ function base_update() { decal || ui_view2d_show || !config_raw.brush_3d || - context_raw.frame < 3); + context_raw.frame < 3; ///end ///end - if (zui_always_redraw_window() && context_raw.ddirty < 0) context_raw.ddirty = 0; + if (zui_always_redraw_window && context_raw.ddirty < 0) context_raw.ddirty = 0; } ///if (is_paint || is_sculpt) @@ -713,7 +715,7 @@ function base_handle_drop_paths() { if (!wait) { base_drop_x = mouse_x; base_drop_y = mouse_y; - let drop_path: string = base_drop_paths.shift(); + let drop_path: string = array_shift(base_drop_paths); import_asset_run(drop_path, base_drop_x, base_drop_y); } } @@ -792,7 +794,9 @@ function base_render() { if (history_undo_layers == null) { history_undo_layers = []; for (let i: i32 = 0; i < config_raw.undo_steps; ++i) { - let l: slot_layer_t = slot_layer_create("_undo" + history_undo_layers.length); + let len: i32 = history_undo_layers.length; + let ext: string = "_undo" + len; + let l: slot_layer_t = slot_layer_create(ext); array_push(history_undo_layers, l); } } @@ -891,7 +895,13 @@ function base_render() { 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 (project_asset_names.length > 0) { + project_asset_names; + } + else { + let empty: string[] = [""]; + return empty; + } } if (node_type == "LAYER" || node_type == "LAYER_MASK") { let layer_names: string[] = []; @@ -913,7 +923,13 @@ function base_enum_texts(node_type: string): string[] { ///if is_lab if (node_type == "ImageTextureNode") { - return project_asset_names.length > 0 ? project_asset_names : [""]; + if (project_asset_names.length > 0) { + project_asset_names; + } + else { + let empty: string[] = [""]; + return empty; + } } ///end @@ -955,7 +971,7 @@ function base_is_scrolling(): bool { function base_is_combo_selected(): bool { for (let i: i32 = 0; i < base_get_uis().length; ++i) { let ui: zui_t = base_get_uis()[i]; - if (ui.combo_selected_handle_ptr != 0) { + if (ui.combo_selected_handle != null) { return true; } } @@ -963,7 +979,8 @@ function base_is_combo_selected(): bool { } function base_get_uis(): zui_t[] { - return [base_ui_box, base_ui_menu, ui_base_ui, ui_nodes_ui, ui_view2d_ui]; + let uis: zui_t[] = [base_ui_box, base_ui_menu, ui_base_ui, ui_nodes_ui, ui_view2d_ui]; + return uis; } function base_is_decal_layer(): bool { @@ -1143,7 +1160,7 @@ function base_resize_layers() { context_raw.undo_handle.value = conf.undo_steps; } while (history_undo_layers.length > conf.undo_steps) { - let l: slot_layer_t = history_undo_layers.pop(); + let l: slot_layer_t = array_pop(history_undo_layers); app_notify_on_next_frame(function (l: slot_layer_t) { slot_layer_unload(l); }, l); @@ -1157,32 +1174,40 @@ function base_resize_layers() { let l: slot_layer_t = history_undo_layers[i]; slot_layer_resize_and_set_bits(l); } + let rts: map_t = render_path_render_targets; - let _texpaint_blend0: image_t = map_get(rts, "texpaint_blend0")._image; + + let blend0: render_target_t = map_get(rts, "texpaint_blend0"); + let _texpaint_blend0: image_t = blend0._image; app_notify_on_next_frame(function (_texpaint_blend0: image_t) { image_unload(_texpaint_blend0); }, _texpaint_blend0); - map_get(rts, "texpaint_blend0").width = config_get_texture_res_x(); - map_get(rts, "texpaint_blend0").height = config_get_texture_res_y(); - map_get(rts, "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 = map_get(rts, "texpaint_blend1")._image; + blend0.width = config_get_texture_res_x(); + blend0.height = config_get_texture_res_y(); + blend0._image = image_create_render_target(config_get_texture_res_x(), config_get_texture_res_y(), tex_format_t.R8); + + let blend1: render_target_t = map_get(rts, "texpaint_blend1"); + let _texpaint_blend1: image_t = blend1._image; app_notify_on_next_frame(function (_texpaint_blend1: image_t) { image_unload(_texpaint_blend1); }, _texpaint_blend1); - map_get(rts, "texpaint_blend1").width = config_get_texture_res_x(); - map_get(rts, "texpaint_blend1").height = config_get_texture_res_y(); - map_get(rts, "texpaint_blend1")._image = image_create_render_target(config_get_texture_res_x(), config_get_texture_res_y(), tex_format_t.R8); + blend1.width = config_get_texture_res_x(); + blend1.height = config_get_texture_res_y(); + 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 (map_get(rts, "texpaint_blur") != null) { - let _texpaint_blur: image_t = map_get(rts, "texpaint_blur")._image; + + let blur: render_target_t = map_get(rts, "texpaint_blur"); + if (blur != null) { + let _texpaint_blur: image_t = blur._image; app_notify_on_next_frame(function (_texpaint_blur: image_t) { image_unload(_texpaint_blur); }, _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); - map_get(rts, "texpaint_blur").width = size_x; - map_get(rts, "texpaint_blur").height = size_y; - map_get(rts, "texpaint_blur")._image = image_create_render_target(size_x, size_y); + blur.width = size_x; + blur.height = size_y; + blur._image = image_create_render_target(size_x, size_y); } if (render_path_paint_live_layer != null) { slot_layer_resize_and_set_bits(render_path_paint_live_layer); @@ -1483,8 +1508,8 @@ function base_make_temp_img() { 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"; + base_bits_handle.position == texture_bits_t.BITS16 ? "RGBA64" : + "RGBA128"; ///end ///if is_lab let format: string = "RGBA32"; @@ -1678,7 +1703,7 @@ function base_merge_down() { context_raw.layer_preview_dirty = true; } -function base_merge_group(l: slot_layer_t) { +function base_merge_group(l: slot_layer_t): slot_layer_t { if (!slot_layer_is_group(l)) { return null; } @@ -1733,7 +1758,8 @@ function base_merge_layer(l0 : slot_layer_t, l1: slot_layer_t, use_mask: bool = g2_set_pipeline(null); g2_end(); - let empty: image_t = map_get(render_path_render_targets, "empty_white")._image; + let empty_rt: render_target_t = map_get(render_path_render_targets, "empty_white"); + let empty: image_t = empty_rt._image; let mask: image_t = empty; let l1masks: slot_layer_t[] = use_mask ? slot_layer_get_masks(l1) : null; if (l1masks != null) { @@ -1820,7 +1846,7 @@ function base_merge_layer(l0 : slot_layer_t, l1: slot_layer_t, use_mask: bool = } } -function base_flatten(height_to_normal: bool = false, layers: slot_layer_t[] = null): any { +function base_flatten(height_to_normal: bool = false, layers: slot_layer_t[] = null): slot_layer_t { if (layers == null) { layers = project_layers; } @@ -1832,7 +1858,8 @@ function base_flatten(height_to_normal: bool = false, layers: slot_layer_t[] = n if (const_data_screen_aligned_vb == null) { const_data_create_screen_aligned_data(); } - let empty: image_t = map_get(render_path_render_targets, "empty_white")._image; + let empty_rt: render_target_t = map_get(render_path_render_targets, "empty_white"); + let empty: image_t = empty_rt._image; // Clear export layer g4_begin(base_expa); @@ -1863,7 +1890,7 @@ function base_flatten(height_to_normal: bool = false, layers: slot_layer_t[] = n g2_begin(base_temp_mask_image); g2_clear(0x00000000); g2_end(); - let l1: any = { texpaint: base_temp_mask_image }; + let l1: slot_layer_t = { texpaint: base_temp_mask_image }; for (let i: i32 = 0; i < l1masks.length; ++i) { base_merge_layer(l1, l1masks[i]); } @@ -1952,7 +1979,11 @@ function base_flatten(height_to_normal: bool = false, layers: slot_layer_t[] = n g2_end(); ///end - let l0: any = { texpaint: base_expa, texpaint_nor: base_expb, texpaint_pack: base_expc }; + let l0: slot_layer_t = { + texpaint: base_expa, + texpaint_nor: base_expb, + texpaint_pack: base_expc + }; // Merge height map into normal map if (height_to_normal && make_material_height_used) { diff --git a/base/Sources/box_export.ts b/base/Sources/box_export.ts index 0cbe105b..a109caff 100644 --- a/base/Sources/box_export.ts +++ b/base/Sources/box_export.ts @@ -170,14 +170,14 @@ function box_export_tab_export_textures(ui: zui_t, title: string, bake_material: }); } 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: string = base_bits_handle.position != texture_bits_t.BITS8 ? "exr" : context_raw.format_type == texture_ldr_format_t.PNG ? "png" : "jpg"; + _box_export_bake_material = bake_material; ui_files_show(filters, true, false, function (path: string) { context_raw.texture_export_path = path; ///if (krom_android || krom_ios) console_toast(tr("Exporting textures")); krom_g4_swap_buffers(); ///end - _box_export_bake_material = bake_material; app_notify_on_init(function () { ///if is_paint export_texture_run(context_raw.texture_export_path, _box_export_bake_material); @@ -190,7 +190,9 @@ function box_export_tab_export_textures(ui: zui_t, title: string, bake_material: } } if (ui.is_hovered) { - zui_tooltip(tr("Export texture files") + " (" + map_get(config_keymap, "file_export_textures") + ")"); + let key: string = map_get(config_keymap, "file_export_textures"); + let tip: string = tr("Export texture files") + " (" + key + ")"; + zui_tooltip(tip); } } } @@ -325,7 +327,12 @@ function box_export_tab_presets(ui: zui_t) { row = [1 / 8]; zui_row(row); if (zui_button(tr("Add"))) { - array_push(box_export_preset.textures, { name: "base", channels: ["base_r", "base_g", "base_b", "1.0"], color_space: "linear" }); + let tex: export_preset_texture_t = { + name: "base", + channels: ["base_r", "base_g", "base_b", "1.0"], + color_space: "linear" + }; + array_push(box_export_preset.textures, tex); box_export_hpreset.children = null; box_export_save_preset(); } @@ -342,7 +349,8 @@ function box_export_tab_atlases(ui: zui_t) { project_atlas_names = []; for (let i: i32 = 0; i < project_paint_objects.length; ++i) { array_push(project_atlas_objects, 0); - array_push(project_atlas_names, tr("Atlas") + " " + (i + 1)); + let i1: i32 = i + 1; + array_push(project_atlas_names, tr("Atlas") + " " + i1); } } for (let i: i32 = 0; i < project_paint_objects.length; ++i) { @@ -365,6 +373,8 @@ function box_export_show_mesh() { }); } +let _box_export_apply_displacement: bool; + function box_export_tab_export_mesh(ui: zui_t, htab: zui_handle_t) { let tab_vertical: bool = config_raw.touch_ui; if (zui_tab(htab, tr("Export Mesh"), tab_vertical)) { @@ -390,7 +400,14 @@ function box_export_tab_export_mesh(ui: zui_t, htab: zui_handle_t) { let tris: i32 = 0; let pos: i32 = box_export_mesh_handle.position; - let paint_objects: mesh_object_t[] = pos == 0 ? project_paint_objects : [project_paint_objects[pos - 1]]; + let paint_objects: mesh_object_t[]; + if (pos == 0) { + paint_objects = project_paint_objects; + } + else { + let po: mesh_object_t = project_paint_objects[pos - 1]; + paint_objects = [po]; + } for (let i: i32 = 0; i < paint_objects.length; ++i) { let po: mesh_object_t = paint_objects[i]; for (let i: i32 = 0; i < po.data.index_arrays.length; ++i) { @@ -406,6 +423,7 @@ function box_export_tab_export_mesh(ui: zui_t, htab: zui_handle_t) { } if (zui_button(tr("Export"))) { ui_box_hide(); + _box_export_apply_displacement = apply_displacement; ui_files_show(context_raw.export_mesh_format == mesh_format_t.OBJ ? "obj" : "arm", true, false, function (path: string) { ///if (krom_android || krom_ios) let f: string = sys_title(); @@ -419,7 +437,17 @@ function box_export_tab_export_mesh(ui: zui_t, htab: zui_handle_t) { console_toast(tr("Exporting mesh")); krom_g4_swap_buffers(); ///end - export_mesh_run(path + path_sep + f, box_export_mesh_handle.position == 0 ? null : [project_paint_objects[box_export_mesh_handle.position - 1]], apply_displacement); + + let paint_objects: mesh_object_t[]; + if (box_export_mesh_handle.position == 0) { + paint_objects = null; + } + else { + let po: mesh_object_t = project_paint_objects[box_export_mesh_handle.position - 1]; + paint_objects = [po]; + } + + export_mesh_run(path + path_sep + f, paint_objects, _box_export_apply_displacement); }); } } @@ -493,7 +521,8 @@ function box_export_show_brush() { function box_export_fetch_presets() { box_export_files = file_read_directory(path_data() + path_sep + "export_presets"); for (let i: i32 = 0; i < box_export_files.length; ++i) { - box_export_files[i] = substring(box_export_files[i], 0, box_export_files[i].length - 5); // Strip .json + let s: string = box_export_files[i]; + box_export_files[i] = substring(s, 0, s.length - 5); // Strip .json } } @@ -516,7 +545,7 @@ function box_export_new_preset(name: string) { name += ".json"; } let path: string = path_data() + path_sep + "export_presets" + path_sep + name; - krom_file_save_bytes(path, sys_string_to_buffer(template)); + krom_file_save_bytes(path, sys_string_to_buffer(template), 0); } function box_export_save_preset() { @@ -525,6 +554,6 @@ function box_export_save_preset() { return; // generic is const } let path: string = path_data() + path_sep + "export_presets" + path_sep + name + ".json"; - krom_file_save_bytes(path, sys_string_to_buffer(json_stringify(box_export_preset))); + krom_file_save_bytes(path, sys_string_to_buffer(json_stringify(box_export_preset)), 0); } ///end diff --git a/base/Sources/box_preferences.ts b/base/Sources/box_preferences.ts index f5f2710f..a32912a0 100644 --- a/base/Sources/box_preferences.ts +++ b/base/Sources/box_preferences.ts @@ -7,6 +7,9 @@ let box_preferences_preset_handle: zui_handle_t; let box_preferences_locales: string[] = null; let box_preferences_themes: string[] = null; let box_preferences_world_color: i32 = 0xff080808; +let _box_preferences_f: string; +let _box_preferences_h: zui_handle_t; +let _box_preferences_ui: zui_t; function box_preferences_show() { ui_box_show_custom(function (ui: zui_t) { @@ -35,7 +38,7 @@ function box_preferences_show() { zui_slider(hscale, tr("UI Scale"), 1.0, 4.0, true, 10); if (context_raw.hscale_was_changed && !ui.input_down) { context_raw.hscale_was_changed = false; - if (hscale.value == null) { + if (hscale.value == 0.0) { hscale.value = 1.0; } config_raw.window_scale = hscale.value; @@ -106,9 +109,9 @@ function box_preferences_show() { } config_raw.touch_ui = zui_check(h_touch_ui, tr("Touch UI")); if (ui.changed) { - zui_set_touch_scroll(config_raw.touch_ui); - zui_set_touch_hold(config_raw.touch_ui); - zui_set_touch_tooltip(config_raw.touch_ui); + zui_touch_scroll = config_raw.touch_ui; + zui_touch_hold = config_raw.touch_ui; + zui_touch_tooltip = config_raw.touch_ui; config_load_theme(config_raw.theme); box_preferences_set_scale(); ui_base_tag_ui_redraw(); @@ -130,7 +133,7 @@ function box_preferences_show() { if (zui_button(tr("Restore")) && !ui_menu_show) { ui_menu_draw(function (ui: zui_t) { if (ui_menu_button(ui, tr("Confirm"))) { - app_notify_on_init(function () { + app_notify_on_init(function (ui: zui_t) { ui.ops.theme.ELEMENT_H = base_default_element_h; config_restore(); box_preferences_set_scale(); @@ -144,14 +147,15 @@ function box_preferences_show() { box_preferences_files_keymap = null; make_material_parse_mesh_material(); make_material_parse_paint_material(); - }); + }, ui); } if (ui_menu_button(ui, tr("Import..."))) { + _box_preferences_ui = ui; ui_files_show("json", false, false, function (path: string) { let b: buffer_t = data_get_blob(path); let raw: config_t = json_parse(sys_buffer_to_string(b)); app_notify_on_init(function (raw: config_t) { - ui.ops.theme.ELEMENT_H = base_default_element_h; + _box_preferences_ui.ops.theme.ELEMENT_H = base_default_element_h; config_import_from(raw); box_preferences_set_scale(); make_material_parse_mesh_material(); @@ -207,7 +211,7 @@ function box_preferences_show() { 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)); + krom_file_save_bytes(path, sys_string_to_buffer(template), 0); box_preferences_fetch_themes(); // Refresh file list config_raw.theme = theme_name; box_preferences_theme_handle.position = box_preferences_get_theme_index(); @@ -227,11 +231,12 @@ function box_preferences_show() { if (zui_button(tr("Export"))) { ui_files_show("json", true, false, function (path: string) { - path += path_sep + ui_files_filename; + path += path_sep; + path += ui_files_filename; if (!ends_with(path, ".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)), 0); }); } @@ -250,9 +255,10 @@ function box_preferences_show() { zui_row(row); zui_text("", 0, h.color); if (ui.is_hovered && ui.input_released) { + _box_preferences_h = h; ui_menu_draw(function (ui: zui_t) { ui.changed = false; - zui_color_wheel(h, false, null, 11 * ui.ops.theme.ELEMENT_H * zui_SCALE(ui), true); + zui_color_wheel(_box_preferences_h, false, -1, 11 * ui.ops.theme.ELEMENT_H * zui_SCALE(ui), true); if (ui.changed) { ui_menu_keep_open = true; } @@ -285,7 +291,7 @@ function box_preferences_show() { let key: string = zui_theme_keys[i]; let h: zui_handle_t = zui_nest(hlist, i); - let val: any = theme[key]; + let val: i32 = 0; //// theme[key]; let is_hex: bool = ends_with(key, "_COL"); if (is_hex && val < 0) { @@ -297,16 +303,17 @@ function box_preferences_show() { zui_row(row); zui_text("", 0, val); if (ui.is_hovered && ui.input_released) { - h.color = theme[key]; - ui_menu_draw(function (ui: zui_t) { - ui.changed = false; - let color: i32 = zui_color_wheel(h, false, null, 11 * ui.ops.theme.ELEMENT_H * zui_SCALE(ui), true); - let theme: any = base_theme; - theme[key] = color; - if (ui.changed) { - ui_menu_keep_open = true; - } - }, 11); + // h.color = theme[key]; + // _box_preferences_h = h; + // ui_menu_draw(function (ui: zui_t) { + // ui.changed = false; + // let color: i32 = zui_color_wheel(_box_preferences_h, false, -1, 11 * ui.ops.theme.ELEMENT_H * zui_SCALE(ui), true); + // // let theme: any = base_theme; + // // theme[key] = color; //// + // if (ui.changed) { + // ui_menu_keep_open = true; + // } + // }, 11); } } @@ -319,22 +326,22 @@ function box_preferences_show() { key == "ROUND_CORNERS") { h.selected = val; let b: bool = zui_check(h, key); - theme[key] = b; + // theme[key] = b; //// } else if (key == "LINK_STYLE") { let styles: string[] = [tr("Straight"), tr("Curved")]; h.position = val; let i: i32 = zui_combo(h, styles, key, true); - theme[key] = i; + // theme[key] = i; //// } else { h.text = is_hex ? i32_to_string_hex(val) : i32_to_string(val); zui_text_input(h, key); if (is_hex) { - theme[key] = parse_int_hex(h.text); + // theme[key] = parse_int_hex(h.text); //// } else { - theme[key] = parse_int(h.text); + // theme[key] = parse_int(h.text); //// } } @@ -362,11 +369,12 @@ function box_preferences_show() { ///if (is_paint || is_sculpt) while (history_undo_layers.length < config_raw.undo_steps) { - let l: slot_layer_t = slot_layer_create("_undo" + history_undo_layers.length); + let len: i32 = history_undo_layers.length; + let l: slot_layer_t = slot_layer_create("_undo" + len); array_push(history_undo_layers, l); } while (history_undo_layers.length > config_raw.undo_steps) { - let l: slot_layer_t = history_undo_layers.pop(); + let l: slot_layer_t = array_pop(history_undo_layers); slot_layer_unload(l); } ///end @@ -765,7 +773,7 @@ function box_preferences_show() { 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)); + krom_file_save_bytes(path, sys_string_to_buffer(template), 0); box_preferences_fetch_keymaps(); // Refresh file list config_raw.keymap = keymap_name; box_preferences_preset_handle.position = box_preferences_get_preset_index(); @@ -841,7 +849,7 @@ plugin.draw_ui = function (ui) {\ 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)); + krom_file_save_bytes(path, sys_string_to_buffer(template), 0); box_preferences_files_plugin = null; // Refresh file list ui_box_hide(); box_preferences_htab.position = 6; // Plugins @@ -883,15 +891,16 @@ plugin.draw_ui = function (ui) {\ base_redraw_ui(); } if (ui.is_hovered && ui.input_released_r) { + _box_preferences_f = f; ui_menu_draw(function (ui: zui_t) { - let path: string = path_data() + path_sep + "plugins" + path_sep + f; + let path: string = path_data() + path_sep + "plugins" + path_sep + _box_preferences_f; if (ui_menu_button(ui, tr("Edit in Text Editor"))) { file_start(path); } if (ui_menu_button(ui, tr("Edit in Script Tab"))) { - let blob: buffer_t = data_get_blob("plugins/" + f); + let blob: buffer_t = data_get_blob("plugins/" + _box_preferences_f); tab_script_hscript.text = sys_buffer_to_string(blob); - data_delete_blob("plugins/" + f); + data_delete_blob("plugins/" + _box_preferences_f); console_info(tr("Script opened")); } if (ui_menu_button(ui, tr("Export"))) { @@ -899,16 +908,16 @@ plugin.draw_ui = function (ui) {\ if (!ends_with(ui_files_filename, ".js")) { ui_files_filename += ".js"; } - let path: string = path_data() + path_sep + "plugins" + path_sep + f; + let path: string = path_data() + path_sep + "plugins" + path_sep + _box_preferences_f; file_copy(path, dest + path_sep + ui_files_filename); }); } if (ui_menu_button(ui, tr("Delete"))) { - if (array_index_of(config_raw.plugins, f) >= 0) { - array_remove(config_raw.plugins, f); - plugin_stop(f); + if (array_index_of(config_raw.plugins, _box_preferences_f) >= 0) { + array_remove(config_raw.plugins, _box_preferences_f); + plugin_stop(_box_preferences_f); } - array_remove(box_preferences_files_plugin, f); + array_remove(box_preferences_files_plugin, _box_preferences_f); file_delete(path); } }, 4); @@ -924,17 +933,19 @@ plugin.draw_ui = function (ui) {\ function box_preferences_fetch_themes() { box_preferences_themes = file_read_directory(path_data() + path_sep + "themes"); for (let i: i32 = 0; i < box_preferences_themes.length; ++i) { - box_preferences_themes[i] = substring(box_preferences_themes[i], 0, box_preferences_themes[i].length - 5); // Strip .json + let s: string = box_preferences_themes[i]; + box_preferences_themes[i] = substring(box_preferences_themes[i], 0, s.length - 5); // Strip .json } - box_preferences_themes.unshift("default"); + array_insert(box_preferences_themes, 0, "default"); } function box_preferences_fetch_keymaps() { box_preferences_files_keymap = file_read_directory(path_data() + path_sep + "keymap_presets"); for (let i: i32 = 0; i < box_preferences_files_keymap.length; ++i) { - box_preferences_files_keymap[i] = substring(box_preferences_files_keymap[i], 0, box_preferences_files_keymap[i].length - 5); // Strip .json + let s: string = box_preferences_files_keymap[i]; + box_preferences_files_keymap[i] = substring(box_preferences_files_keymap[i], 0, s.length - 5); // Strip .json } - box_preferences_files_keymap.unshift("default"); + array_insert(box_preferences_files_keymap, 0, "default"); } function box_preferences_fetch_plugins() { @@ -951,15 +962,15 @@ function box_preferences_get_preset_index(): i32 { function box_preferences_set_scale() { let scale: f32 = config_raw.window_scale; - zui_set_scale(ui_base_ui, scale); + _zui_set_scale(ui_base_ui, scale); ui_header_h = math_floor(ui_header_default_h * scale); config_raw.layout[layout_size_t.STATUS_H] = math_floor(ui_status_default_status_h * scale); ui_menubar_w = math_floor(ui_menubar_default_w * scale); ui_base_set_icon_scale(); - zui_set_scale(ui_nodes_ui, scale); - zui_set_scale(ui_view2d_ui, scale); - zui_set_scale(base_ui_box, scale); - zui_set_scale(base_ui_menu, scale); + _zui_set_scale(ui_nodes_ui, scale); + _zui_set_scale(ui_view2d_ui, scale); + _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(ui_base_default_sidebar_w * scale); diff --git a/base/Sources/box_projects.ts b/base/Sources/box_projects.ts index 14893a55..d1f818eb 100644 --- a/base/Sources/box_projects.ts +++ b/base/Sources/box_projects.ts @@ -37,6 +37,7 @@ function box_projects_show() { let _box_projects_path: string; let _box_projects_icon_path: string; +let _box_projects_i: i32; function box_projects_tab(ui: zui_t) { if (zui_tab(box_projects_htab, tr("Projects"), true)) { @@ -73,7 +74,7 @@ function box_projects_tab(ui: zui_t) { let show_asset_names: bool = true; for (let row: i32 = 0; row < math_ceil(recent_projects.length / num); ++row) { - let mult = show_asset_names ? 2 : 1; + let mult: i32 = show_asset_names ? 2 : 1; let ar: f32[] = []; for (let i: i32 = 0; i < num * mult; ++i) { array_push(ar, 1 / num); @@ -120,7 +121,7 @@ function box_projects_tab(ui: zui_t) { if (icon != null) { zui_fill(0, 0, 128, 128, ui.ops.theme.SEPARATOR_COL); - let state: i32 = zui_image(icon, 0xffffffff, 128 * zui_SCALE(ui)); + let state: i32 = _zui_image(icon, 0xffffffff, 128 * zui_SCALE(ui)); if (state == zui_state_t.RELEASED) { let _uix: i32 = ui._x; ui._x = uix; @@ -140,16 +141,17 @@ function box_projects_tab(ui: zui_t) { if (ui.is_hovered && ui.input_released_r) { _box_projects_path = path; _box_projects_icon_path = icon_path; + _box_projects_i = i; ui_menu_draw(function (ui: zui_t) { // if (menuButton(ui, tr("Duplicate"))) {} if (ui_menu_button(ui, tr("Delete"))) { app_notify_on_init(function () { file_delete(_box_projects_path); file_delete(_box_projects_icon_path); - let data_path: string = substring(path, 0, path.length - 4); + let data_path: string = substring(_box_projects_path, 0, _box_projects_path.length - 4); file_delete(data_path); let recent_projects: string[] = config_raw.recent_projects; - array_splice(recent_projects, i, 1); + array_splice(recent_projects, _box_projects_i, 1); }); } }, 1); @@ -239,7 +241,7 @@ function box_projects_recent_tab(ui: zui_t) { function box_projects_draw_badge(ui: zui_t) { let img: image_t = data_get_image("badge.k"); - zui_image(img); + _zui_image(img); zui_end_element(); } diff --git a/base/Sources/camera.ts b/base/Sources/camera.ts index 1a665a8b..a0c10526 100644 --- a/base/Sources/camera.ts +++ b/base/Sources/camera.ts @@ -173,8 +173,10 @@ function camera_update() { if (operator_shortcut(map_get(config_keymap, "rotate_light"), shortcut_type_t.DOWN)) { camera_redraws = 2; let light: light_object_t = scene_lights[0]; - context_raw.light_angle = (context_raw.light_angle + ((mouse_movement_x / 100) % (2 * math_pi()) + 2 * math_pi())) % (2 * math_pi()); - let m: mat4_t = mat4_rot_z(mouse_movement_x / 100); + let pi2: f32 = math_pi() * 2.0; + let mx: f32 = mouse_movement_x / 100; + context_raw.light_angle = math_fmod(context_raw.light_angle + math_fmod(mx, pi2) + pi2, pi2); + let m: mat4_t = mat4_rot_z(mx); mat4_mult_mat(light.base.transform.local, m); transform_decompose(light.base.transform); } diff --git a/base/Sources/config.ts b/base/Sources/config.ts index 6e576538..30233e9f 100644 --- a/base/Sources/config.ts +++ b/base/Sources/config.ts @@ -7,7 +7,12 @@ let config_default_button_spacing: string = " "; let config_button_spacing: string = config_default_button_spacing; function config_load(done: ()=>void) { - let blob: buffer_t = data_get_blob((path_is_protected() ? krom_save_path() : "") + "config.json"); + let path: string = ""; + if (path_is_protected()) { + path += krom_save_path(); + } + path += "config.json"; + let blob: buffer_t = data_get_blob(path); ///if krom_linux if (blob == null) { // Protected directory @@ -26,13 +31,22 @@ function config_load(done: ()=>void) { function config_save() { // Use system application data folder // when running from protected path like "Program Files" - let path: string = (path_is_protected() ? krom_save_path() : path_data() + path_sep) + "config.json"; + let path: string = ""; + if (path_is_protected()) { + path += krom_save_path(); + } + else { + path += path_data(); + path += path_sep; + } + path += "config.json"; + let buffer: buffer_t = sys_string_to_buffer(json_stringify(config_raw)); - krom_file_save_bytes(path, buffer); + krom_file_save_bytes(path, buffer, 0); ///if krom_linux // Protected directory if (!file_exists(path)) { - krom_file_save_bytes(krom_save_path() + "config.json", buffer); + krom_file_save_bytes(krom_save_path() + "config.json", buffer, 0); } ///end } @@ -91,25 +105,30 @@ function config_init() { } } - zui_set_touch_scroll(config_raw.touch_ui); - zui_set_touch_hold(config_raw.touch_ui); - zui_set_touch_tooltip(config_raw.touch_ui); + zui_touch_scroll = config_raw.touch_ui; + zui_touch_hold = config_raw.touch_ui; + zui_touch_tooltip = config_raw.touch_ui; base_res_handle.position = config_raw.layer_res; config_load_keymap(); } +type version_t = { + sha: string; + date: string; +}; + function config_get_sha(): string { let sha: string = ""; let blob: buffer_t = data_get_blob("version.json"); - sha = json_parse(sys_buffer_to_string(blob)).sha; - return sha; + let v: version_t = json_parse(sys_buffer_to_string(blob)); + return v.sha; } function config_get_date(): string { let date: string = ""; let blob: buffer_t = data_get_blob("version.json"); - date = json_parse(sys_buffer_to_string(blob)).date; - return date; + let v: version_t = json_parse(sys_buffer_to_string(blob)); + return v.date; } function config_get_options(): kinc_sys_ops_t { @@ -125,7 +144,7 @@ function config_get_options(): kinc_sys_ops_t { window_features |= window_features_t.MINIMIZABLE; } let title: string = "untitled - " + manifest_title; - return { + let ops: kinc_sys_ops_t = { title: title, width: config_raw.window_w, height: config_raw.window_h, @@ -136,6 +155,7 @@ function config_get_options(): kinc_sys_ops_t { vsync: config_raw.window_vsync, frequency: config_raw.window_frequency }; + return ops; } function config_restore() { @@ -199,7 +219,7 @@ function config_save_keymap() { } let path: string = data_path() + "keymap_presets/" + config_raw.keymap; let buffer: buffer_t = sys_string_to_buffer(json_stringify(config_keymap)); - krom_file_save_bytes(path, buffer); + krom_file_save_bytes(path, buffer, 0); } function config_get_super_sample_quality(f: f32): i32 { @@ -258,7 +278,7 @@ function config_load_theme(theme: string, tag_redraw: bool = true) { for (let i: i32 = 0; i < zui_theme_keys.length; ++i) { let key: string = zui_theme_keys[i]; // @ts-ignore - base_theme[key] = parsed[key]; + // base_theme[key] = parsed[key]; //// } } @@ -273,7 +293,7 @@ function config_load_theme(theme: string, tag_redraw: bool = true) { for (let i: i32 = 0; i < zui_theme_keys.length; ++i) { let key: string = zui_theme_keys[i]; // @ts-ignore - ui.ops.theme[key] = base_theme[key]; + // ui.ops.theme[key] = base_theme[key]; //// } base_theme = ui.ops.theme; diff --git a/base/Sources/console.ts b/base/Sources/console.ts index fd305321..5a687731 100644 --- a/base/Sources/console.ts +++ b/base/Sources/console.ts @@ -18,7 +18,7 @@ function console_draw_toast(s: string) { 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); } -function _console_toast_render(s: any) { +function _console_toast_render(s: string) { console_draw_toast(s); krom_g4_swap_buffers(); app_remove_render_2d(_console_toast_render); @@ -68,10 +68,10 @@ function console_log(s: string) { console_trace(s); } -function console_trace(v: any) { +function console_trace(s: string) { base_redraw_console(); - console_last_traces.unshift(any_to_string(v)); + array_insert(console_last_traces, 0, s); if (console_last_traces.length > 100) { - console_last_traces.pop(); + array_pop(console_last_traces); } } diff --git a/base/Sources/context.ts b/base/Sources/context.ts index f7ca06b2..7cc8fc96 100644 --- a/base/Sources/context.ts +++ b/base/Sources/context.ts @@ -769,11 +769,11 @@ function context_in_paint_area(): bool { } function context_in_layers(): bool { - return zui_get_hovered_tab_name() == tr("Layers"); + return zui_hovered_tab_name() == tr("Layers"); } function context_in_materials(): bool { - return zui_get_hovered_tab_name() == tr("Materials"); + return zui_hovered_tab_name() == tr("Materials"); } ///if (is_paint || is_sculpt) @@ -791,11 +791,11 @@ function context_in_nodes(): bool { } function context_in_swatches(): bool { - return zui_get_hovered_tab_name() == tr("Swatches"); + return zui_hovered_tab_name() == tr("Swatches"); } function context_in_browser(): bool { - return zui_get_hovered_tab_name() == tr("Browser"); + return zui_hovered_tab_name() == tr("Browser"); } function context_get_area_type(): area_type_t { diff --git a/base/Sources/export_arm.ts b/base/Sources/export_arm.ts index 192fb258..718e5942 100644 --- a/base/Sources/export_arm.ts +++ b/base/Sources/export_arm.ts @@ -1,12 +1,42 @@ +function encode_scene(raw: scene_t): buffer_t { + return null; + + // armpack_encode_start(encoded); + // armpack_encode_map(3); + // armpack_encode_string("name"); + // armpack_encode_string(canvas->name); +} + +function encode_scene_size(raw: scene_t): i32 { + return 0; + + // uint32_t size = 0; + // size += armpack_size_map(); + // size += armpack_size_string("name"); + // size += armpack_size_string(canvas->name); +} + +function encode_project(raw: project_format_t): buffer_t { + return null; +} + +function encode_project_size(raw: project_format_t): i32 { + return 0; +} + function export_arm_run_mesh(path: string, paint_objects: mesh_object_t[]) { let mesh_datas: mesh_data_t[] = []; for (let i: i32 = 0; i < paint_objects.length; ++i) { let p: mesh_object_t = paint_objects[i]; array_push(mesh_datas, p.data); } - let raw: scene_t = { mesh_datas: mesh_datas }; - let b: buffer_t = armpack_encode(raw); + + let raw: scene_t = { + mesh_datas: mesh_datas + }; + let b: buffer_t = encode_scene(raw); + if (!ends_with(path, ".arm")) { path += ".arm"; } @@ -79,7 +109,7 @@ function export_arm_run_project() { let ld: layer_data_t[] = []; for (let i: i32 = 0; i < project_layers.length; ++i) { let l: slot_layer_t = project_layers[i]; - array_push(ld, { + let d: layer_data_t = { name: l.name, res: l.texpaint != null ? l.texpaint.width : project_layers[0].texpaint.width, bpp: bpp, @@ -109,7 +139,8 @@ function export_arm_run_project() { paint_emis: l.paint_emis, paint_subs: l.paint_subs ///end - }); + }; + array_push(ld, d); } ///end @@ -201,7 +232,7 @@ function export_arm_run_project() { } ///end - let buffer: buffer_t = armpack_encode(project_raw); + let buffer: buffer_t = encode_project(project_raw); krom_file_save_bytes(project_filepath, buffer, buffer_size(buffer) + 1); // Save to recent @@ -212,7 +243,7 @@ function export_arm_run_project() { ///end let recent: string[] = config_raw.recent_projects; array_remove(recent, recent_path); - recent.unshift(recent_path); + array_insert(recent, 0, recent_path); config_save(); console_info(tr("Project saved")); @@ -320,7 +351,7 @@ function export_arm_run_material(path: string) { export_arm_pack_assets(raw, assets); } - let buffer: buffer_t = armpack_encode(raw); + let buffer: buffer_t = encode_project(raw); krom_file_save_bytes(path, buffer, buffer_size(buffer) + 1); } ///end @@ -387,7 +418,7 @@ function export_arm_run_brush(path: string) { export_arm_pack_assets(raw, assets); } - let buffer: buffer_t = armpack_encode(raw); + let buffer: buffer_t = encode_project(raw); krom_file_save_bytes(path, buffer, buffer_size(buffer) + 1); } ///end @@ -435,7 +466,7 @@ function export_arm_meshes_to_files(project_path: string): string[] { function export_arm_fonts_to_files(project_path: string, fonts: slot_font_t[]): string[] { let font_files: string[] = []; - for (let i = 1; i = map_create(); - let normap: map_t = map_create(); - let texmap: map_t = map_create(); + let posmap: i32_array_t = i32_array_create(len); + let normap: i32_array_t = i32_array_create(len); + let texmap: i32_array_t = i32_array_create(len); let pi: i32 = 0; let ni: i32 = 0; @@ -39,13 +39,13 @@ function export_obj_run(path: string, paint_objects: mesh_object_t[], apply_disp if (posa2[j * 3 ] == posa[i * 4 ] && posa2[j * 3 + 1] == posa[i * 4 + 1] && posa2[j * 3 + 2] == posa[i * 4 + 2]) { - map_set(posmap, i, j); + posmap[i] = j; found = true; break; } } if (!found) { - map_set(posmap, i, pi); + posmap[i] = pi; posa2[pi * 3 ] = posa[i * 4 ]; posa2[pi * 3 + 1] = posa[i * 4 + 1]; posa2[pi * 3 + 2] = posa[i * 4 + 2]; @@ -57,13 +57,13 @@ function export_obj_run(path: string, paint_objects: mesh_object_t[], apply_disp if (nora2[j * 3 ] == nora[i * 2 ] && nora2[j * 3 + 1] == nora[i * 2 + 1] && nora2[j * 3 + 2] == posa[i * 4 + 3]) { - map_set(normap, i, j); + normap[i] = j; found = true; break; } } if (!found) { - map_set(normap, i, ni); + normap[i] = ni; nora2[ni * 3 ] = nora[i * 2 ]; nora2[ni * 3 + 1] = nora[i * 2 + 1]; nora2[ni * 3 + 2] = posa[i * 4 + 3]; @@ -74,13 +74,13 @@ function export_obj_run(path: string, paint_objects: mesh_object_t[], apply_disp for (let j: i32 = 0; j < ti; ++j) { if (texa2[j * 2 ] == texa[i * 2 ] && texa2[j * 2 + 1] == texa[i * 2 + 1]) { - map_set(texmap, i, j); + texmap[i] = j; found = true; break; } } if (!found) { - map_set(texmap, i, ti); + texmap[i] = ti; texa2[ti * 2 ] = texa[i * 2 ]; texa2[ti * 2 + 1] = texa[i * 2 + 1]; ti++; @@ -104,41 +104,49 @@ function export_obj_run(path: string, paint_objects: mesh_object_t[], apply_disp export_obj_write_string(o, "o " + p.base.name + "\n"); for (let i: i32 = 0; i < pi; ++i) { export_obj_write_string(o, "v "); - export_obj_write_string(o, posa2[i * 3] * sc + ""); + let f: f32 = posa2[i * 3] * sc; + export_obj_write_string(o, f + ""); export_obj_write_string(o, " "); - export_obj_write_string(o, posa2[i * 3 + 2] * sc + ""); + f = posa2[i * 3 + 2] * sc; + export_obj_write_string(o, f + ""); export_obj_write_string(o, " "); - export_obj_write_string(o, -posa2[i * 3 + 1] * sc + ""); + f = -posa2[i * 3 + 1] * sc; + export_obj_write_string(o, f + ""); export_obj_write_string(o, "\n"); } for (let i: i32 = 0; i < ni; ++i) { export_obj_write_string(o, "vn "); - export_obj_write_string(o, nora2[i * 3] * inv + ""); + let f: f32 = nora2[i * 3] * inv; + export_obj_write_string(o, f + ""); export_obj_write_string(o, " "); - export_obj_write_string(o, nora2[i * 3 + 2] * inv + ""); + f = nora2[i * 3 + 2] * inv; + export_obj_write_string(o, f + ""); export_obj_write_string(o, " "); - export_obj_write_string(o, -nora2[i * 3 + 1] * inv + ""); + f = -nora2[i * 3 + 1] * inv; + export_obj_write_string(o, f + ""); export_obj_write_string(o, "\n"); } for (let i: i32 = 0; i < ti; ++i) { export_obj_write_string(o, "vt "); - export_obj_write_string(o, texa2[i * 2] * inv + ""); + let f: f32 = texa2[i * 2] * inv; + export_obj_write_string(o, f + ""); export_obj_write_string(o, " "); - export_obj_write_string(o, 1.0 - texa2[i * 2 + 1] * inv + ""); + f = 1.0 - texa2[i * 2 + 1] * inv; + export_obj_write_string(o, f + ""); export_obj_write_string(o, "\n"); } let inda: u32_array_t = mesh.index_arrays[0].values; for (let i: i32 = 0; i < math_floor(inda.length / 3); ++i) { - let pi1: i32 = map_get(posmap, inda[i * 3 ]) + 1 + poff; - let pi2: i32 = map_get(posmap, inda[i * 3 + 1]) + 1 + poff; - let pi3: i32 = map_get(posmap, inda[i * 3 + 2]) + 1 + poff; - let ni1: i32 = map_get(normap, inda[i * 3 ]) + 1 + noff; - let ni2: i32 = map_get(normap, inda[i * 3 + 1]) + 1 + noff; - let ni3: i32 = map_get(normap, inda[i * 3 + 2]) + 1 + noff; - let ti1: i32 = map_get(texmap, inda[i * 3 ]) + 1 + toff; - let ti2: i32 = map_get(texmap, inda[i * 3 + 1]) + 1 + toff; - let ti3: i32 = map_get(texmap, inda[i * 3 + 2]) + 1 + toff; + let pi1: i32 = posmap[inda[i * 3 ]] + 1 + poff; + let pi2: i32 = posmap[inda[i * 3 + 1]] + 1 + poff; + let pi3: i32 = posmap[inda[i * 3 + 2]] + 1 + poff; + let ni1: i32 = normap[inda[i * 3 ]] + 1 + noff; + let ni2: i32 = normap[inda[i * 3 + 1]] + 1 + noff; + let ni3: i32 = normap[inda[i * 3 + 2]] + 1 + noff; + let ti1: i32 = texmap[inda[i * 3 ]] + 1 + toff; + let ti2: i32 = texmap[inda[i * 3 + 1]] + 1 + toff; + let ti3: i32 = texmap[inda[i * 3 + 2]] + 1 + toff; export_obj_write_string(o, "f "); export_obj_write_string(o, pi1 + ""); export_obj_write_string(o, "/"); @@ -168,6 +176,9 @@ function export_obj_run(path: string, paint_objects: mesh_object_t[], apply_disp path += ".obj"; } - let b: buffer_t = u8_array_t.from(o).buffer; + let b: buffer_t = { + data: o.buffer, + length: o.length + }; krom_file_save_bytes(path, b, buffer_size(b)); } diff --git a/base/Sources/export_texture.ts b/base/Sources/export_texture.ts index 9e6bcb47..3d25253c 100644 --- a/base/Sources/export_texture.ts +++ b/base/Sources/export_texture.ts @@ -81,13 +81,26 @@ function export_texture_run(path: string, bake_material: bool = false) { } } else { - export_texture_run_layers(path, context_raw.layers_export == export_mode_t.SELECTED ? (slot_layer_is_group(context_raw.layer) ? slot_layer_get_children(context_raw.layer) : [context_raw.layer]) : project_layers); + let layers: slot_layer_t[]; + if (context_raw.layers_export == export_mode_t.SELECTED) { + if (slot_layer_is_group(context_raw.layer)) { + layers = slot_layer_get_children(context_raw.layer); + } + else { + layers = [context_raw.layer]; + } + } + else { + layers = project_layers; + } + export_texture_run_layers(path, layers); } } ///end ///if is_lab - export_texture_run_layers(path, [brush_output_node_inst]); + let layers: slot_layer_t[] = [brush_output_node_inst]; + export_texture_run_layers(path, layers); ///end ///if krom_ios @@ -123,7 +136,8 @@ function export_texture_run_bake_material(path: string) { planeo.base.visible = false; context_raw.paint_object = _paint_object; - export_texture_run_layers(path, [render_path_paint_live_layer], "", true); + let layers: slot_layer_t[] = [render_path_paint_live_layer]; + export_texture_run_layers(path, layers, "", true); } ///end @@ -166,7 +180,8 @@ function export_texture_run_layers(path: string, layers: any[], object_name: str if (const_data_screen_aligned_vb == null) { const_data_create_screen_aligned_data(); } - let empty: image_t = map_get(render_path_render_targets, "empty_white")._image; + let rt: render_target_t = map_get(render_path_render_targets, "empty_white"); + let empty: image_t = rt._image; // Append object mask name let export_selected: bool = context_raw.layers_export == export_mode_t.SELECTED; @@ -216,7 +231,9 @@ function export_texture_run_layers(path: string, layers: any[], object_name: str g2_begin(base_temp_mask_image); g2_clear(0x00000000); g2_end(); - let l1: any = { texpaint: base_temp_mask_image }; + let l1: slot_layer_t = { + texpaint: base_temp_mask_image + }; for (let i: i32 = 0; i < l1masks.length; ++i) { base_merge_layer(l1, l1masks[i]); } @@ -335,7 +352,7 @@ function export_texture_run_layers(path: string, layers: any[], object_name: str for (let i: i32 = 0; i < preset.textures.length; ++i) { let t: export_preset_texture_t = preset.textures[i]; let c: string[] = t.channels; - let tex_name = t.name != "" ? "_" + t.name : ""; + let tex_name: string = t.name != "" ? "_" + t.name : ""; 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") { export_texture_write_texture(path + path_sep + f + tex_name + ext, pixpaint, 1); @@ -456,7 +473,11 @@ function export_texture_write_texture(file: string, pixels: buffer_t, type: i32 map_set(data_cached_images, file, image); let ar: string[] = string_split(file, path_sep); let name: string = ar[ar.length - 1]; - let asset: asset_t = {name: name, file: file, id: project_asset_id++}; + let asset: asset_t = { + name: name, + file: file, + id: project_asset_id++ + }; array_push(project_assets, asset); if (project_raw.assets == null) { project_raw.assets = []; @@ -464,7 +485,8 @@ function export_texture_write_texture(file: string, pixels: buffer_t, type: i32 array_push(project_raw.assets, asset.file); array_push(project_asset_names, asset.name); map_set(project_asset_map, asset.id, image); - export_arm_pack_assets(project_raw, [asset]); + let assets: asset_t[] = [asset]; + export_arm_pack_assets(project_raw, assets); return; } diff --git a/base/Sources/file.ts b/base/Sources/file.ts index 4c1ec249..1c9597c7 100644 --- a/base/Sources/file.ts +++ b/base/Sources/file.ts @@ -17,7 +17,13 @@ let file_cloud_sizes: map_t = null; function file_read_directory(path: string, folders_only: bool = false): string[] { if (starts_with(path, "cloud")) { let files: string[] = file_cloud != null ? map_get(file_cloud, string_replace_all(path, "\\", "/")) : null; - return files != null ? files : []; + if (files != null) { + return files; + } + else { + let empty: string[] = []; + return empty; + } } // ///if krom_android // path = string_replace_all(path, "//", "/"); @@ -79,7 +85,7 @@ function file_download(url: string, dst_path: string, done: (url: string)=>void, krom_http_request(url, size, function (url: string, ab: buffer_t) { let fdd: file_download_data_t = map_get(_file_download_map, url); if (ab != null) { - krom_file_save_bytes(fdd.dst_path, ab); + krom_file_save_bytes(fdd.dst_path, ab, 0); } fdd.done(url); }); @@ -101,7 +107,15 @@ type file_download_bytes_data_t = { let _file_download_bytes_map: map_t = map_create(); function file_download_bytes(url: string, done: (url: string, ab: buffer_t)=>void) { - let save: string = (path_is_protected() ? krom_save_path() : path_data() + path_sep) + "download.bin"; + let save: string; + if (path_is_protected()) { + save = krom_save_path(); + } + else { + save = path_data() + path_sep; + } + save += "download.bin"; + let fdbd: file_download_bytes_data_t = { url: url, save: save, done: done }; map_set(_file_download_bytes_map, url, fdbd); file_download(url, save, function (url: string) { @@ -125,12 +139,28 @@ function file_cache_cloud(path: string, done: (s: string)=>void) { ///else let path2: string = path; ///end - let dest: string = (path_is_protected() ? krom_save_path() : krom_get_files_location() + path_sep) + path2; + let dest: string; + if (path_is_protected()) { + dest = krom_save_path(); + } + else { + dest = krom_get_files_location() + path_sep; + } + dest += path2; + if (file_exists(dest)) { ///if (krom_darwin || krom_ios) done(dest); ///else - done((path_is_protected() ? krom_save_path() : path_working_dir() + path_sep) + path); + let p: string; + if (path_is_protected()) { + p = krom_save_path(); + } + else { + p = path_working_dir() + path_sep; + } + p += path; + done(p); ///end return; } @@ -149,7 +179,7 @@ function file_cache_cloud(path: string, done: (s: string)=>void) { file_download(url, dest, function (url: string) { let fccd: file_cache_cloud_data_t = map_get(_file_cache_cloud_map, url); - if (!file_exists(dest)) { + if (!file_exists(fccd.dest)) { console_error(strings_error5()); fccd.done(null); return; @@ -157,7 +187,15 @@ function file_cache_cloud(path: string, done: (s: string)=>void) { ///if (krom_darwin || krom_ios) fccd.done(fccd.dest); ///else - fccd.done((path_is_protected() ? krom_save_path() : path_working_dir() + path_sep) + fccd.path); + let p: string; + if (path_is_protected()) { + p = krom_save_path(); + } + else { + p = path_working_dir() + path_sep; + } + p += fccd.path; + fccd.done(p); ///end }, map_get(file_cloud_sizes, path)); } @@ -168,7 +206,8 @@ function file_init_cloud_bytes(done: ()=>void, append: string = "") { _file_init_cloud_bytes_done = done; file_download_bytes(config_raw.server + "/?list-type=2" + append, function (url: string, buffer: buffer_t) { if (buffer == null) { - map_set(file_cloud, "cloud", []); + let empty: string[] = []; + map_set(file_cloud, "cloud", empty); console_error(strings_error5()); return; } @@ -193,13 +232,14 @@ function file_init_cloud_bytes(done: ()=>void, append: string = "") { pos_start += 6; // pos_end = string_index_of_pos(str, "", pos_start); - array_push(sizes, Number(substring(str, pos_start, pos_end))); + array_push(sizes, parse_int(substring(str, pos_start, pos_end))); } for (let i: i32 = 0; i < files.length; ++i) { let file: string = files[i]; if (path_is_folder(file)) { - map_set(file_cloud, substring(file, 0, file.length - 1), []); + let empty: string[] = []; + map_set(file_cloud, substring(file, 0, file.length - 1), empty); } } for (let i: i32 = 0; i < files.length; ++i) { diff --git a/base/Sources/geom.ts b/base/Sources/geom.ts index 340a396a..39d861d7 100644 --- a/base/Sources/geom.ts +++ b/base/Sources/geom.ts @@ -30,8 +30,10 @@ function geom_make_plane(size_x: f32 = 1.0, size_y: f32 = 1.0, verts_x: i32 = 2, mesh.posa[i * 4 + 3] = 32767; x = (i % verts_x) / (verts_x - 1); y = 1.0 - math_floor(i / verts_x) / (verts_y - 1); - mesh.texa[i * 2 ] = (math_floor(x * 32767 * uv_scale) - 1) % 32767; - mesh.texa[i * 2 + 1] = (math_floor(y * 32767 * uv_scale) - 1) % 32767; + let tx: i32 = (math_floor(x * 32767 * uv_scale) - 1); + let ty: i32 = (math_floor(y * 32767 * uv_scale) - 1); + mesh.texa[i * 2 ] = tx % 32767; + mesh.texa[i * 2 + 1] = ty % 32767; } for (let i: i32 = 0; i < (verts_x - 1) * (verts_y - 1); ++i) { let x: f32 = i % (verts_x - 1); @@ -47,7 +49,7 @@ function geom_make_plane(size_x: f32 = 1.0, size_y: f32 = 1.0, verts_x: i32 = 2, return mesh; } -function geom_make_uv_sphere(radius: f32 = 1.0, widthSegments: i32 = 32, heightSegments: i32 = 16, stretch_uv: bool = true, uvScale: f32 = 1.0): raw_mesh_t { +function geom_make_uv_sphere(radius: f32 = 1.0, width_segments: i32 = 32, height_segments: i32 = 16, stretch_uv: bool = true, uvScale: f32 = 1.0): raw_mesh_t { let mesh: raw_mesh_t = {}; mesh.scale_pos = 1.0; @@ -61,24 +63,24 @@ function geom_make_uv_sphere(radius: f32 = 1.0, widthSegments: i32 = 32, heightS let inv: f32 = (1 / mesh.scale_pos) * 32767; let pi2: f32 = math_pi() * 2; - let width_verts: i32 = widthSegments + 1; - let height_verts: i32 = heightSegments + 1; + let width_verts: i32 = width_segments + 1; + let height_verts: i32 = height_segments + 1; mesh.posa = i16_array_create(width_verts * height_verts * 4); mesh.nora = i16_array_create(width_verts * height_verts * 2); mesh.texa = i16_array_create(width_verts * height_verts * 2); - mesh.inda = u32_array_create(widthSegments * heightSegments * 6 - widthSegments * 6); + mesh.inda = u32_array_create(width_segments * height_segments * 6 - width_segments * 6); let nor: vec4_t = vec4_create(); let pos: i32 = 0; for (let y: i32 = 0; y < height_verts; ++y) { - let v: f32 = y / heightSegments; + let v: f32 = y / height_segments; 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; + let u_off: f32 = y == 0 ? 0.5 / width_segments : y == height_segments ? -0.5 / width_segments : 0.0; for (let x: i32 = 0; x < width_verts; ++x) { - let u: f32 = x / widthSegments; + let u: f32 = x / width_segments; let u_pi2: f32 = u * pi2; let v_pi: f32 = v * math_pi(); let v_pi_sin: f32 = math_sin(v_pi); @@ -94,16 +96,18 @@ function geom_make_uv_sphere(radius: f32 = 1.0, widthSegments: i32 = 32, heightS 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 + u_off) * 32767) - 1) % 32767; - mesh.texa[i2 + 1] = (math_floor(v_flip * 32767) - 1) % 32767; + let tx: i32 = (math_floor((u + u_off) * 32767) - 1); + let ty: i32 = (math_floor(v_flip * 32767) - 1); + mesh.texa[i2 ] = tx % 32767; + mesh.texa[i2 + 1] = ty % 32767; pos++; } } pos = 0; - let height_segments1: i32 = heightSegments - 1; - for (let y: i32 = 0; y < heightSegments; ++y) { - for (let x: i32 = 0; x < widthSegments; ++x) { + let height_segments1: i32 = height_segments - 1; + for (let y: i32 = 0; y < height_segments; ++y) { + for (let x: i32 = 0; x < width_segments; ++x) { let x1: i32 = x + 1; let y1: i32 = y + 1; let a: f32 = y * width_verts + x1; @@ -130,9 +134,12 @@ type raw_mesh_t = { posa?: i16_array_t; nora?: i16_array_t; texa?: i16_array_t; + cola?: i16_array_t; inda?: u32_array_t; scale_pos?: f32; scale_tex?: f32; name?: string; has_next?: bool; + vertex_arrays?: vertex_array_t[]; + index_arrays?: index_array_t[]; }; diff --git a/base/Sources/history.ts b/base/Sources/history.ts index 84bccf24..b240cfa3 100644 --- a/base/Sources/history.ts +++ b/base/Sources/history.ts @@ -121,8 +121,14 @@ function history_undo() { current_layer = project_layers[mask_pos]; } - let layers_to_restore: slot_layer_t[] = slot_layer_is_group(current_layer) ? slot_layer_get_children(current_layer) : [current_layer]; - layers_to_restore.reverse(); + let layers_to_restore: slot_layer_t[]; + if (slot_layer_is_group(current_layer)) { + layers_to_restore = slot_layer_get_children(current_layer); + } + else { + layers_to_restore = [current_layer]; + } + array_reverse(layers_to_restore); for (let i: i32 = 0; i < layers_to_restore.length; ++i) { let layer: slot_layer_t = layers_to_restore[i]; @@ -183,7 +189,11 @@ function history_undo() { make_material_parse_mesh_material(); } else if (step.name == tr("Delete Node Group")) { - array_insert(project_material_groups, step.canvas_group, { canvas: null, nodes: zui_nodes_create() }); + let ng: node_group_t = { + canvas: null, + nodes: zui_nodes_create() + }; + array_insert(project_material_groups, step.canvas_group, ng); history_swap_canvas(step); } else if (step.name == tr("New Material")) { @@ -325,7 +335,8 @@ function history_redo() { history_copy_merging_layers2(layers); } else { - history_copy_merging_layers2([context_raw.layer, context_raw.layer.parent]); + let layers: slot_layer_t[] = [context_raw.layer, context_raw.layer.parent]; + history_copy_merging_layers2(layers); } app_notify_on_next_frame(function () { @@ -429,10 +440,24 @@ function history_redo() { function history_reset() { ///if (is_paint || is_sculpt) - history_steps = [{name: tr("New"), layer: 0, layer_type: layer_slot_type_t.LAYER, layer_parent: -1, object: 0, material: 0, brush: 0}]; + history_steps = [ + { + name: tr("New", null), + layer: 0, + layer_type: layer_slot_type_t.LAYER, + layer_parent: -1, + object: 0, + material: 0, + brush: 0 + } + ]; ///end ///if is_lab - history_steps = [{name: tr("New")}]; + history_steps = [ + { + name: tr("New", null) + } + ]; ///end history_undos = 0; @@ -510,7 +535,7 @@ function history_merge_layers() { if (slot_layer_has_masks(context_raw.layer)) { step.layer -= slot_layer_get_masks(context_raw.layer).length; } - history_steps.shift(); // Merge consumes 2 steps + array_shift(history_steps); // Merge consumes 2 steps history_undos--; // TODO: use undo layer in app_merge_down to save memory } @@ -523,7 +548,8 @@ function history_apply_mask() { history_copy_merging_layers2(layers); } else { - history_copy_merging_layers2([context_raw.layer, context_raw.layer.parent]); + let layers: slot_layer_t[] = [context_raw.layer, context_raw.layer.parent]; + history_copy_merging_layers2(layers); } history_push(tr("Apply Mask")); } @@ -612,7 +638,7 @@ function history_push(name: string): step_t { } if (history_redos > 0) { for (let i: i32 = 0; i < history_redos; ++i) { - history_steps.pop(); + array_pop(history_steps); } history_redos = 0; } @@ -623,7 +649,7 @@ function history_push(name: string): step_t { let mpos: i32 = array_index_of(project_materials, context_raw.material); let bpos: i32 = array_index_of(project_brushes, context_raw.brush); - array_push(history_steps, { + let step: step_t = { name: name, layer: lpos, layer_type: slot_layer_is_mask(context_raw.layer) ? layer_slot_type_t.MASK : slot_layer_is_group(context_raw.layer) ? layer_slot_type_t.GROUP : layer_slot_type_t.LAYER, @@ -634,17 +660,20 @@ function history_push(name: string): step_t { layer_opacity: context_raw.layer.mask_opacity, layer_object: context_raw.layer.object_mask, layer_blending: context_raw.layer.blending - }); + }; + + array_push(history_steps, step); ///end ///if is_lab - array_push(history_steps, { + let step: step_t = { name: name - }); + }; + array_push(history_steps, step); ///end while (history_steps.length > config_raw.undo_steps + 1) { - history_steps.shift(); + array_shift(history_steps); } return history_steps[history_steps.length - 1]; } @@ -689,7 +718,8 @@ function history_copy_to_undo(from_id: i32, to_id: i32, is_mask: bool) { render_path_draw_shader("shader_datas/copy_pass/copy_pass"); } else { - render_path_set_target("texpaint_undo" + to_id, ["texpaint_nor_undo" + to_id, "texpaint_pack_undo" + to_id]); + let additional: string[] = ["texpaint_nor_undo" + to_id, "texpaint_pack_undo" + to_id]; + render_path_set_target("texpaint_undo" + to_id, additional); render_path_bind_target("texpaint" + from_id, "tex0"); render_path_bind_target("texpaint_nor" + from_id, "tex1"); render_path_bind_target("texpaint_pack" + from_id, "tex2"); @@ -699,11 +729,14 @@ function history_copy_to_undo(from_id: i32, to_id: i32, is_mask: bool) { } ///end -function history_get_canvas_owner(step: step_t): any { +function history_get_canvas(step: step_t): zui_node_canvas_t { ///if (is_paint || is_sculpt) - return step.canvas_group == -1 ? - project_materials[step.material] : - project_material_groups[step.canvas_group]; + if (step.canvas_group == -1) { + return project_materials[step.material].canvas; + } + else { + return project_material_groups[step.canvas_group].canvas; + } ///end ///if is_lab @@ -711,11 +744,22 @@ function history_get_canvas_owner(step: step_t): any { ///end } +function history_set_canvas(step: step_t, canvas: zui_node_canvas_t) { + ///if (is_paint || is_sculpt) + if (step.canvas_group == -1) { + project_materials[step.material].canvas = canvas; + } + else { + project_material_groups[step.canvas_group].canvas = canvas; + } + ///end +} + function history_swap_canvas(step: step_t) { ///if (is_paint || is_sculpt) if (step.canvas_type == 0) { - let _canvas: zui_node_canvas_t = history_get_canvas_owner(step).canvas; - history_get_canvas_owner(step).canvas = step.canvas; + let _canvas: zui_node_canvas_t = history_get_canvas(step); + history_set_canvas(step, step.canvas); step.canvas = _canvas; context_raw.material = project_materials[step.material]; } @@ -728,8 +772,8 @@ function history_swap_canvas(step: step_t) { ///end ///if is_lab - let _canvas: zui_node_canvas_t = history_get_canvas_owner(step).canvas; - history_get_canvas_owner(step).canvas = step.canvas; + let _canvas: zui_node_canvas_t = history_get_canvas(step); + history_set_canvas(step, step.canvas); step.canvas = _canvas; ///end diff --git a/base/Sources/import_arm.ts b/base/Sources/import_arm.ts index ca69a251..dbc2b588 100644 --- a/base/Sources/import_arm.ts +++ b/base/Sources/import_arm.ts @@ -54,7 +54,7 @@ function import_arm_run_project(path: string) { ///end let recent: string[] = config_raw.recent_projects; array_remove(recent, recent_path); - recent.unshift(recent_path); + array_insert(recent, 0, recent_path); config_save(); project_raw = project; @@ -72,9 +72,8 @@ function import_arm_run_project(path: string) { if (project_raw.envmap != null) { project_raw.envmap = data_is_abs(project_raw.envmap) ? project_raw.envmap : base + project_raw.envmap; } - if (project_raw.envmap_strength != null) { - scene_world.strength = project_raw.envmap_strength; - } + scene_world.strength = project_raw.envmap_strength; + if (project_raw.camera_world != null) { scene_camera.base.transform.local = mat4_from_f32_array(project_raw.camera_world); transform_decompose(scene_camera.base.transform); @@ -184,20 +183,22 @@ function import_arm_run_project(path: string) { } } let rts: map_t = render_path_render_targets; - let _texpaint_blend0: image_t = map_get(rts, "texpaint_blend0")._image; + let blend0: render_target_t = map_get(rts, "texpaint_blend0"); + let _texpaint_blend0: image_t = blend0._image; app_notify_on_next_frame(function (_texpaint_blend0: image_t) { image_unload(_texpaint_blend0); }, _texpaint_blend0); - map_get(rts, "texpaint_blend0").width = config_get_texture_res_x(); - map_get(rts, "texpaint_blend0").height = config_get_texture_res_y(); - map_get(rts, "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 = map_get(rts, "texpaint_blend1")._image; + blend0.width = config_get_texture_res_x(); + blend0.height = config_get_texture_res_y(); + 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 blend1: render_target_t = map_get(rts, "texpaint_blend1"); + let _texpaint_blend1: image_t = blend1._image; app_notify_on_next_frame(function (_texpaint_blend1: image_t) { image_unload(_texpaint_blend1); }, _texpaint_blend1); - map_get(rts, "texpaint_blend1").width = config_get_texture_res_x(); - map_get(rts, "texpaint_blend1").height = config_get_texture_res_y(); - map_get(rts, "texpaint_blend1")._image = image_create_render_target(config_get_texture_res_x(), config_get_texture_res_y(), tex_format_t.R8, depth_format_t.NO_DEPTH); + blend1.width = config_get_texture_res_x(); + blend1.height = config_get_texture_res_y(); + blend1._image = image_create_render_target(config_get_texture_res_x(), config_get_texture_res_y(), tex_format_t.R8, depth_format_t.NO_DEPTH); context_raw.brush_blend_dirty = true; } @@ -342,7 +343,11 @@ function import_arm_run_project(path: string) { if (project.material_groups != null) { for (let i: i32 = 0; i < project.material_groups.length; ++i) { let g: zui_node_canvas_t = project.material_groups[i]; - array_push(project_material_groups, { canvas: g, nodes: zui_nodes_create() }); + let ng: node_group_t = { + canvas: g, + nodes: zui_nodes_create() + }; + array_push(project_material_groups, ng); } } @@ -467,7 +472,11 @@ function import_arm_run_material_from_project(project: project_format_t, path: s import_arm_rename_group(c.name, imported, project.material_groups); // Ensure unique group name } import_arm_init_nodes(c.nodes); - array_push(project_material_groups, { canvas: c, nodes: zui_nodes_create() }); + let ng: node_group_t = { + canvas: c, + nodes: zui_nodes_create() + }; + array_push(project_material_groups, ng); } } diff --git a/base/Sources/import_blend_material.ts b/base/Sources/import_blend_material.ts index e862c9df..8cb82a55 100644 --- a/base/Sources/import_blend_material.ts +++ b/base/Sources/import_blend_material.ts @@ -2,340 +2,343 @@ ///if (is_paint || is_sculpt) function import_blend_material_run(path: string) { - let b: buffer_t = data_get_blob(path); - let bl: blend_t = parser_blend_init(b); - if (bl.dna == null) { - console_error(strings_error3()); - return; - } + // let b: buffer_t = data_get_blob(path); + // let bl: blend_t = parser_blend_init(b); + // if (bl.dna == null) { + // console_error(strings_error3()); + // return; + // } - let mats: bl_handle_t[] = parser_blend_get(bl, "Material"); - if (mats.length == 0) { - console_error("Error: No materials found"); - return; - } + // let mats: bl_handle_t[] = parser_blend_get(bl, "Material"); + // if (mats.length == 0) { + // console_error("Error: No materials found"); + // return; + // } - let imported: slot_material_t[] = []; + // let imported: slot_material_t[] = []; - for (let i: i32 = 0; i < mats.length; ++i) { - let mat: bl_handle_t = mats[i]; - // Material slot - context_raw.material = slot_material_create(project_materials[0].data); - array_push(project_materials, context_raw.material); - array_push(imported, context_raw.material); - let nodes: zui_nodes_t = context_raw.material.nodes; - let canvas: zui_node_canvas_t = context_raw.material.canvas; - canvas.name = bl_handle_get(bl_handle_get(mat, "id"), "name"); // MAWood - canvas.name = substring(canvas.name, 2, canvas.name.length); - let nout: zui_node_t = null; - for (let i: i32 = 0; i < canvas.nodes.length; ++i) { - let n: zui_node_t = canvas.nodes[i]; - if (n.type == "OUTPUT_MATERIAL_PBR") { - nout = n; - break; - } - } - for (let i: i32 = 0; i < canvas.nodes.length; ++i) { - let n: zui_node_t = canvas.nodes[i]; - if (n.name == "RGB") { - zui_remove_node(n, canvas); - break; - } - } + // for (let i: i32 = 0; i < mats.length; ++i) { + // let mat: bl_handle_t = mats[i]; + // // Material slot + // context_raw.material = slot_material_create(project_materials[0].data); + // array_push(project_materials, context_raw.material); + // array_push(imported, context_raw.material); + // let nodes: zui_nodes_t = context_raw.material.nodes; + // let canvas: zui_node_canvas_t = context_raw.material.canvas; + // let id: bl_handle_t = bl_handle_get(mat, "id"); + // canvas.name = bl_handle_get(id, "name"); // MAWood + // canvas.name = substring(canvas.name, 2, canvas.name.length); + // let nout: zui_node_t = null; + // for (let i: i32 = 0; i < canvas.nodes.length; ++i) { + // let n: zui_node_t = canvas.nodes[i]; + // if (n.type == "OUTPUT_MATERIAL_PBR") { + // nout = n; + // break; + // } + // } + // for (let i: i32 = 0; i < canvas.nodes.length; ++i) { + // let n: zui_node_t = canvas.nodes[i]; + // if (n.name == "RGB") { + // zui_remove_node(n, canvas); + // break; + // } + // } - // Parse nodetree - let nodetree: any = bl_handle_get(mat, "nodetree"); // bNodeTree - let blnodes: any = bl_handle_get(nodetree, "nodes"); // ListBase - let bllinks: any = bl_handle_get(nodetree, "links"); // bNodeLink + // // Parse nodetree + // let nodetree: any = bl_handle_get(mat, "nodetree"); // bNodeTree + // let blnodes: any = bl_handle_get(nodetree, "nodes"); // ListBase + // let bllinks: any = bl_handle_get(nodetree, "links"); // bNodeLink - // Look for Principled BSDF node - let node: any = bl_handle_get(blnodes, "first", 0, "bNode"); - let last: any = bl_handle_get(blnodes, "last", 0, "bNode"); - while (true) { - if (bl_handle_get(node, "idname") == "ShaderNodeBsdfPrincipled") { - break; - } - if (bl_handle_get(node, "name") == bl_handle_get(last, "name")) { - break; - } - node = bl_handle_get(node, "next"); - } - if (bl_handle_get(node, "idname") != "ShaderNodeBsdfPrincipled") { - console_error("Error: No Principled BSDF node found"); - continue; - } + // // Look for Principled BSDF node + // let node: any = bl_handle_get(blnodes, "first", 0, "bNode"); + // let last: any = bl_handle_get(blnodes, "last", 0, "bNode"); + // while (true) { + // if (bl_handle_get(node, "idname") == "ShaderNodeBsdfPrincipled") { + // break; + // } + // if (bl_handle_get(node, "name") == bl_handle_get(last, "name")) { + // break; + // } + // node = bl_handle_get(node, "next"); + // } + // if (bl_handle_get(node, "idname") != "ShaderNodeBsdfPrincipled") { + // console_error("Error: No Principled BSDF node found"); + // continue; + // } - // Use Principled BSDF as material output - nout.name = bl_handle_get(node, "name"); - nout.x = bl_handle_get(node, "locx") + 400; - nout.y = -bl_handle_get(node, "locy") + 400; + // // Use Principled BSDF as material output + // nout.name = bl_handle_get(node, "name"); + // let nx: i32 = bl_handle_get(node, "locx"); + // let ny: i32 = bl_handle_get(node, "locy"); + // nout.x = nx + 400; + // nout.y = -ny + 400; - // Place nodes - node = bl_handle_get(blnodes, "first", 0, "bNode"); - while (true) { - // Search for node in list - let search: string = bl_handle_get(node, "idname"); - search = to_lower_case(substring(search, 10, search.length)); - let base: zui_node_t = null; - for (let i: i32 = 0; i < nodes_material_list.length; ++i) { - let list: zui_node_t[] = nodes_material_list[i]; - let found: bool = false; - for (let i: i32 = 0; i < list.length; ++i) { - let n: zui_node_t = list[i]; - let s: string = to_lower_case(string_replace_all(n.type, "_", "")); - if (search == s) { - base = n; - found = true; - break; - } - } - if (found) { - break; - } - } + // // Place nodes + // node = bl_handle_get(blnodes, "first", 0, "bNode"); + // while (true) { + // // Search for node in list + // let search: string = bl_handle_get(node, "idname"); + // search = to_lower_case(substring(search, 10, search.length)); + // let base: zui_node_t = null; + // for (let i: i32 = 0; i < nodes_material_list.length; ++i) { + // let list: zui_node_t[] = nodes_material_list[i]; + // let found: bool = false; + // for (let i: i32 = 0; i < list.length; ++i) { + // let n: zui_node_t = list[i]; + // let s: string = to_lower_case(string_replace_all(n.type, "_", "")); + // if (search == s) { + // base = n; + // found = true; + // break; + // } + // } + // if (found) { + // break; + // } + // } - if (base != null) { - let n: zui_node_t = ui_nodes_make_node(base, nodes, canvas); - n.x = bl_handle_get(node, "locx") + 400; - n.y = -bl_handle_get(node, "locy") + 400; - n.name = bl_handle_get(node, "name"); + // if (base != null) { + // let n: zui_node_t = ui_nodes_make_node(base, nodes, canvas); + // n.x = bl_handle_get(node, "locx") + 400; + // n.y = -bl_handle_get(node, "locy") + 400; + // n.name = bl_handle_get(node, "name"); - // Fill input socket values - let inputs: any = bl_handle_get(node, "inputs"); - let sock: any = bl_handle_get(inputs, "first", 0, "bNodeSocket"); - let pos: i32 = 0; - while (true) { - if (pos >= n.inputs.length) { - break; - } - n.inputs[pos].default_value = import_blend_material_read_blend_socket(sock); + // // Fill input socket values + // let inputs: any = bl_handle_get(node, "inputs"); + // let sock: any = bl_handle_get(inputs, "first", 0, "bNodeSocket"); + // let pos: i32 = 0; + // while (true) { + // if (pos >= n.inputs.length) { + // break; + // } + // n.inputs[pos].default_value = import_blend_material_read_blend_socket(sock); - let last: any = sock; - sock = bl_handle_get(sock, "next"); - if (last.block == sock.block) { - break; - } - pos++; - } + // let last: any = sock; + // sock = bl_handle_get(sock, "next"); + // if (last.block == sock.block) { + // break; + // } + // pos++; + // } - // Fill button values - if (search == "teximage") { - let img: any = bl_handle_get(node, "id", 0, "Image"); - let file: string = bl_handle_get(img, "name"); // "//desktop\logo.png" - file = substring(file, 2, file.length); - file = path_base_dir(path) + file; - import_texture_run(file); - let ar: string[] = string_split(file, path_sep); - let filename: string = ar[ar.length - 1]; - n.buttons[0].default_value = f32_array_create_x(base_get_asset_index(filename)); - } - else if (search == "valtorgb") { - // let ramp: any = bl_handle_get(node, "storage", 0, "ColorBand"); - // n.buttons[0].data = bl_handle_get(ramp, "ipotype") == 0 ? 0 : 1; // Linear / Constant - // let elems: f32[][] = n.buttons[0].default_value; - // for (let i: i32 = 0; i < bl_handle_get(ramp, "tot"); ++i) { - // if (i >= elems.length) { - // array_push(elems, [1.0, 1.0, 1.0, 1.0, 0.0]); - // } - // let cbdata: any = bl_handle_get(ramp, "data", i, "CBData"); - // elems[i][0] = math_floor(bl_handle_get(cbdata, "r") * 100) / 100; - // elems[i][1] = math_floor(bl_handle_get(cbdata, "g") * 100) / 100; - // elems[i][2] = math_floor(bl_handle_get(cbdata, "b") * 100) / 100; - // elems[i][3] = math_floor(bl_handle_get(cbdata, "a") * 100) / 100; - // elems[i][4] = math_floor(bl_handle_get(cbdata, "pos") * 100) / 100; - // } - } - else if (search == "mixrgb" || search == "math") { - n.buttons[0].default_value = f32_array_create_x(bl_handle_get(node, "custom1")); - n.buttons[1].default_value = f32_array_create_x(bl_handle_get(node, "custom2") & 2); - } - else if (search == "mapping") { - let storage: any = bl_handle_get(node, "storage", 0, "TexMapping"); - n.buttons[0].default_value = bl_handle_get(storage, "loc"); - n.buttons[1].default_value = bl_handle_get(storage, "rot"); - n.buttons[2].default_value = bl_handle_get(storage, "size"); - // let mat: any = get(storage, "mat"); float[4][4] - // storage.flag & 1 // use_min - // storage.flag & 2 // use_max - // storage.min[0] - // storage.min[1] - // storage.min[2] - // storage.max[0] - // storage.max[1] - // storage.max[2] - } + // // Fill button values + // if (search == "teximage") { + // let img: any = bl_handle_get(node, "id", 0, "Image"); + // let file: string = bl_handle_get(img, "name"); // "//desktop\logo.png" + // file = substring(file, 2, file.length); + // file = path_base_dir(path) + file; + // import_texture_run(file); + // let ar: string[] = string_split(file, path_sep); + // let filename: string = ar[ar.length - 1]; + // n.buttons[0].default_value = f32_array_create_x(base_get_asset_index(filename)); + // } + // else if (search == "valtorgb") { + // // let ramp: any = bl_handle_get(node, "storage", 0, "ColorBand"); + // // n.buttons[0].data = bl_handle_get(ramp, "ipotype") == 0 ? 0 : 1; // Linear / Constant + // // let elems: f32[][] = n.buttons[0].default_value; + // // for (let i: i32 = 0; i < bl_handle_get(ramp, "tot"); ++i) { + // // if (i >= elems.length) { + // // array_push(elems, [1.0, 1.0, 1.0, 1.0, 0.0]); + // // } + // // let cbdata: any = bl_handle_get(ramp, "data", i, "CBData"); + // // elems[i][0] = math_floor(bl_handle_get(cbdata, "r") * 100) / 100; + // // elems[i][1] = math_floor(bl_handle_get(cbdata, "g") * 100) / 100; + // // elems[i][2] = math_floor(bl_handle_get(cbdata, "b") * 100) / 100; + // // elems[i][3] = math_floor(bl_handle_get(cbdata, "a") * 100) / 100; + // // elems[i][4] = math_floor(bl_handle_get(cbdata, "pos") * 100) / 100; + // // } + // } + // else if (search == "mixrgb" || search == "math") { + // n.buttons[0].default_value = f32_array_create_x(bl_handle_get(node, "custom1")); + // n.buttons[1].default_value = f32_array_create_x(bl_handle_get(node, "custom2") & 2); + // } + // else if (search == "mapping") { + // let storage: any = bl_handle_get(node, "storage", 0, "TexMapping"); + // n.buttons[0].default_value = bl_handle_get(storage, "loc"); + // n.buttons[1].default_value = bl_handle_get(storage, "rot"); + // n.buttons[2].default_value = bl_handle_get(storage, "size"); + // // let mat: any = get(storage, "mat"); float[4][4] + // // storage.flag & 1 // use_min + // // storage.flag & 2 // use_max + // // storage.min[0] + // // storage.min[1] + // // storage.min[2] + // // storage.max[0] + // // storage.max[1] + // // storage.max[2] + // } - // Fill output socket values - let outputs: any = bl_handle_get(node, "outputs"); - sock = bl_handle_get(outputs, "first", 0, "bNodeSocket"); - pos = 0; - while (true) { - if (pos >= n.outputs.length) { - break; - } - n.outputs[pos].default_value = import_blend_material_read_blend_socket(sock); + // // Fill output socket values + // let outputs: any = bl_handle_get(node, "outputs"); + // sock = bl_handle_get(outputs, "first", 0, "bNodeSocket"); + // pos = 0; + // while (true) { + // if (pos >= n.outputs.length) { + // break; + // } + // n.outputs[pos].default_value = import_blend_material_read_blend_socket(sock); - let last: any = sock; - sock = bl_handle_get(sock, "next"); - if (last.block == sock.block) { - break; - } - pos++; - } + // let last: any = sock; + // sock = bl_handle_get(sock, "next"); + // if (last.block == sock.block) { + // break; + // } + // pos++; + // } - array_push(canvas.nodes, n); - } + // array_push(canvas.nodes, n); + // } - if (bl_handle_get(node, "name") == bl_handle_get(last, "name")) { - break; - } - node = bl_handle_get(node, "next"); - } + // if (bl_handle_get(node, "name") == bl_handle_get(last, "name")) { + // break; + // } + // node = bl_handle_get(node, "next"); + // } - // Place links - let link: any = bl_handle_get(bllinks, "first", 0, "bNodeLink"); - while (true) { - let fromnode: any = bl_handle_get(bl_handle_get(link, "fromnode"), "name"); - let tonode: any = bl_handle_get(bl_handle_get(link, "tonode"), "name"); - let fromsock: any = bl_handle_get(link, "fromsock"); - let tosock: any = bl_handle_get(link, "tosock"); + // // Place links + // let link: any = bl_handle_get(bllinks, "first", 0, "bNodeLink"); + // while (true) { + // let fromnode: any = bl_handle_get(bl_handle_get(link, "fromnode"), "name"); + // let tonode: any = bl_handle_get(bl_handle_get(link, "tonode"), "name"); + // let fromsock: any = bl_handle_get(link, "fromsock"); + // let tosock: any = bl_handle_get(link, "tosock"); - let from_id: i32 = -1; - let to_id: i32 = -1; - for (let i: i32 = 0; i < canvas.nodes.length; ++i) { - let n: zui_node_t = canvas.nodes[i]; - if (n.name == fromnode) { - from_id = n.id; - break; - } - } - for (let i: i32 = 0; i < canvas.nodes.length; ++i) { - let n: zui_node_t = canvas.nodes[i]; - if (n.name == tonode) { - to_id = n.id; - break; - } - } + // let from_id: i32 = -1; + // let to_id: i32 = -1; + // for (let i: i32 = 0; i < canvas.nodes.length; ++i) { + // let n: zui_node_t = canvas.nodes[i]; + // if (n.name == fromnode) { + // from_id = n.id; + // break; + // } + // } + // for (let i: i32 = 0; i < canvas.nodes.length; ++i) { + // let n: zui_node_t = canvas.nodes[i]; + // if (n.name == tonode) { + // to_id = n.id; + // break; + // } + // } - if (from_id >= 0 && to_id >= 0) { - let from_socket: i32 = 0; - let sock: any = fromsock; - while (true) { - let last: any = sock; - sock = bl_handle_get(sock, "prev"); - if (last.block == sock.block) { - break; - } - from_socket++; - } + // if (from_id >= 0 && to_id >= 0) { + // let from_socket: i32 = 0; + // let sock: any = fromsock; + // while (true) { + // let last: any = sock; + // sock = bl_handle_get(sock, "prev"); + // if (last.block == sock.block) { + // break; + // } + // from_socket++; + // } - let to_socket: i32 = 0; - sock = tosock; - while (true) { - let last: any = sock; - sock = bl_handle_get(sock, "prev"); - if (last.block == sock.block) { - break; - } - to_socket++; - } + // let to_socket: i32 = 0; + // sock = tosock; + // while (true) { + // let last: any = sock; + // sock = bl_handle_get(sock, "prev"); + // if (last.block == sock.block) { + // break; + // } + // to_socket++; + // } - let valid: bool = true; + // let valid: bool = true; - // Remap principled - if (tonode == nout.name) { - if (to_socket == 0) { - to_socket = 0; // Base - } - else if (to_socket == 18) { - to_socket = 1; // Opac - } - else if (to_socket == 7) { - to_socket = 3; // Rough - } - else if (to_socket == 4) { - to_socket = 4; // Met - } - else if (to_socket == 19) { - to_socket = 5; // TODO: auto-remove normal_map node - } - else if (to_socket == 17) { - to_socket = 6; // Emis - } - else if (to_socket == 1) { - to_socket = 8; // Subs - } - else { - valid = false; - } - } + // // Remap principled + // if (tonode == nout.name) { + // if (to_socket == 0) { + // to_socket = 0; // Base + // } + // else if (to_socket == 18) { + // to_socket = 1; // Opac + // } + // else if (to_socket == 7) { + // to_socket = 3; // Rough + // } + // else if (to_socket == 4) { + // to_socket = 4; // Met + // } + // else if (to_socket == 19) { + // to_socket = 5; // TODO: auto-remove normal_map node + // } + // else if (to_socket == 17) { + // to_socket = 6; // Emis + // } + // else if (to_socket == 1) { + // to_socket = 8; // Subs + // } + // else { + // valid = false; + // } + // } - if (valid) { - let raw: zui_node_link_t = { - id: zui_get_link_id(canvas.links), - from_id: from_id, - from_socket: from_socket, - to_id: to_id, - to_socket: to_socket - }; - array_push(canvas.links, raw); - } - } + // if (valid) { + // let raw: zui_node_link_t = { + // id: zui_next_link_id(canvas.links.buffer, canvas.links.length), + // from_id: from_id, + // from_socket: from_socket, + // to_id: to_id, + // to_socket: to_socket + // }; + // array_push(canvas.links, raw); + // } + // } - let last: any = link; - link = bl_handle_get(link, "next"); - if (last.block == link.block) { - break; - } - } - history_new_material(); - } + // let last: any = link; + // link = bl_handle_get(link, "next"); + // if (last.block == link.block) { + // break; + // } + // } + // history_new_material(); + // } - app_notify_on_init(function (imported: slot_material_t[]) { - for (let i: i32 = 0; i < imported.length; ++i) { - let m: slot_material_t = imported[i]; - context_set_material(m); - make_material_parse_paint_material(); - util_render_make_material_preview(); - } - }, imported); + // app_notify_on_init(function (imported: slot_material_t[]) { + // for (let i: i32 = 0; i < imported.length; ++i) { + // let m: slot_material_t = imported[i]; + // context_set_material(m); + // make_material_parse_paint_material(); + // util_render_make_material_preview(); + // } + // }, imported); - ui_base_hwnds[tab_area_t.SIDEBAR1].redraws = 2; - data_delete_blob(path); + // ui_base_hwnds[tab_area_t.SIDEBAR1].redraws = 2; + // data_delete_blob(path); } -function import_blend_material_read_blend_socket(sock: any): any { - let idname: any = bl_handle_get(sock, "idname"); - if (starts_with(idname, "NodeSocketVector")) { - let v: any = bl_handle_get(bl_handle_get(sock, "default_value", 0, "bNodeSocketValueVector"), "value"); - v[0] = math_floor(v[0] * 100) / 100; - v[1] = math_floor(v[1] * 100) / 100; - v[2] = math_floor(v[2] * 100) / 100; - return v; - } - else if (starts_with(idname, "NodeSocketColor")) { - let v: any = bl_handle_get(bl_handle_get(sock, "default_value", 0, "bNodeSocketValueRGBA"), "value"); - v[0] = math_floor(v[0] * 100) / 100; - v[1] = math_floor(v[1] * 100) / 100; - v[2] = math_floor(v[2] * 100) / 100; - v[3] = math_floor(v[3] * 100) / 100; - return v; - } - else if (starts_with(idname, "NodeSocketFloat")) { - let v: any = bl_handle_get(bl_handle_get(sock, "default_value", 0, "bNodeSocketValueFloat"), "value"); - v = math_floor(v * 100) / 100; - return v; - } - else if (starts_with(idname, "NodeSocketInt")) { - return bl_handle_get(bl_handle_get(sock, "default_value", 0, "bNodeSocketValueInt"), "value"); - } - else if (starts_with(idname, "NodeSocketBoolean")) { - return bl_handle_get(bl_handle_get(sock, "default_value", 0, "bNodeSocketValueBoolean"), "value"); - } - else if (starts_with(idname, "NodeSocketString")) { - return bl_handle_get(bl_handle_get(sock, "default_value", 0, "bNodeSocketValueString"), "value"); - } - return null; -} +// function import_blend_material_read_blend_socket(sock: any): any { +// let idname: any = bl_handle_get(sock, "idname"); +// if (starts_with(idname, "NodeSocketVector")) { +// let v: any = bl_handle_get(bl_handle_get(sock, "default_value", 0, "bNodeSocketValueVector"), "value"); +// v[0] = math_floor(v[0] * 100) / 100; +// v[1] = math_floor(v[1] * 100) / 100; +// v[2] = math_floor(v[2] * 100) / 100; +// return v; +// } +// else if (starts_with(idname, "NodeSocketColor")) { +// let v: any = bl_handle_get(bl_handle_get(sock, "default_value", 0, "bNodeSocketValueRGBA"), "value"); +// v[0] = math_floor(v[0] * 100) / 100; +// v[1] = math_floor(v[1] * 100) / 100; +// v[2] = math_floor(v[2] * 100) / 100; +// v[3] = math_floor(v[3] * 100) / 100; +// return v; +// } +// else if (starts_with(idname, "NodeSocketFloat")) { +// let v: any = bl_handle_get(bl_handle_get(sock, "default_value", 0, "bNodeSocketValueFloat"), "value"); +// v = math_floor(v * 100) / 100; +// return v; +// } +// else if (starts_with(idname, "NodeSocketInt")) { +// return bl_handle_get(bl_handle_get(sock, "default_value", 0, "bNodeSocketValueInt"), "value"); +// } +// else if (starts_with(idname, "NodeSocketBoolean")) { +// return bl_handle_get(bl_handle_get(sock, "default_value", 0, "bNodeSocketValueBoolean"), "value"); +// } +// else if (starts_with(idname, "NodeSocketString")) { +// return bl_handle_get(bl_handle_get(sock, "default_value", 0, "bNodeSocketValueString"), "value"); +// } +// return null; +// } ///end diff --git a/base/Sources/import_blend_mesh.ts b/base/Sources/import_blend_mesh.ts index 757ed9c3..e6f353ef 100644 --- a/base/Sources/import_blend_mesh.ts +++ b/base/Sources/import_blend_mesh.ts @@ -2,499 +2,499 @@ let import_blend_mesh_eps: f32 = 1.0 / 32767; function import_blend_mesh_run(path: string, replace_existing: bool = true) { - let b: buffer_t = data_get_blob(path); - let bl: blend_t = parser_blend_init(b); - if (bl.dna == null) { - console_error(strings_error3()); - return; - } + // let b: buffer_t = data_get_blob(path); + // let bl: blend_t = parser_blend_init(b); + // if (bl.dna == null) { + // console_error(strings_error3()); + // return; + // } - let obs: bl_handle_t[] = parser_blend_get(bl, "Object"); - if (obs == null || obs.length == 0) { - import_mesh_make_mesh(null, path); - return; - } + // let obs: bl_handle_t[] = parser_blend_get(bl, "Object"); + // if (obs == null || obs.length == 0) { + // import_mesh_make_mesh(null, path); + // return; + // } - let first: bool = true; - for (let i: i32 = 0; i < obs.length; ++i) { - let ob: bl_handle_t = obs[i]; - if (bl_handle_get(ob, "type") != 1) { - continue; - } + // let first: bool = true; + // for (let i: i32 = 0; i < obs.length; ++i) { + // let ob: bl_handle_t = obs[i]; + // if (bl_handle_get(ob, "type") != 1) { + // continue; + // } - let name: string = bl_handle_get(bl_handle_get(ob, "id"), "name"); - name = substring(name, 2, name.length); + // let name: string = bl_handle_get(bl_handle_get(ob, "id"), "name"); + // name = substring(name, 2, name.length); - let m: any = bl_handle_get(ob, "data", 0, "Mesh"); - if (m == null) { - continue; - } + // let m: any = bl_handle_get(ob, "data", 0, "Mesh"); + // if (m == null) { + // continue; + // } - let totpoly: i32 = bl_handle_get(m, "totpoly"); - if (totpoly == 0) { - continue; - } + // let totpoly: i32 = bl_handle_get(m, "totpoly"); + // if (totpoly == 0) { + // continue; + // } - let numtri: i32 = 0; - for (let i: i32 = 0; i < totpoly; ++i) { - let poly: any = bl_handle_get(m, "mpoly", i); - let totloop: i32 = bl_handle_get(poly, "totloop"); - numtri += totloop - 2; - } - let inda: u32_array_t = u32_array_create(numtri * 3); - for (let i: i32 = 0; i < inda.length; ++i) { - inda[i] = i; - } + // let numtri: i32 = 0; + // for (let i: i32 = 0; i < totpoly; ++i) { + // let poly: any = bl_handle_get(m, "mpoly", i); + // let totloop: i32 = bl_handle_get(poly, "totloop"); + // numtri += totloop - 2; + // } + // let inda: u32_array_t = u32_array_create(numtri * 3); + // for (let i: i32 = 0; i < inda.length; ++i) { + // inda[i] = i; + // } - let posa32: f32_array_t = f32_array_create(numtri * 3 * 4); - let posa: i16_array_t = i16_array_create(numtri * 3 * 4); - let nora: i16_array_t = i16_array_create(numtri * 3 * 2); + // let posa32: f32_array_t = f32_array_create(numtri * 3 * 4); + // let posa: i16_array_t = i16_array_create(numtri * 3 * 4); + // let nora: i16_array_t = i16_array_create(numtri * 3 * 2); - // pdata, 25 == CD_MPOLY - // let vdata: any = get(m, "vdata"); - // let codata: any = null; - // let codata_pos: i32 = 0; - // for (let i: i32 = 0; i < get(vdata, "totlayer"); ++i) { - // let l: any = get(vdata, "layers", i); - // if (get(l, "type") == 0) { // CD_MVERT - // let ptr: any = get(l, "data"); - // codata_pos = bl.get(map, ptr).pos; - // codata = l; - // } - // } + // // pdata, 25 == CD_MPOLY + // // let vdata: any = get(m, "vdata"); + // // let codata: any = null; + // // let codata_pos: i32 = 0; + // // for (let i: i32 = 0; i < get(vdata, "totlayer"); ++i) { + // // let l: any = get(vdata, "layers", i); + // // if (get(l, "type") == 0) { // CD_MVERT + // // let ptr: any = get(l, "data"); + // // codata_pos = bl.get(map, ptr).pos; + // // codata = l; + // // } + // // } - let ldata: any = bl_handle_get(m, "ldata"); - let uvdata: any = null; - let uvdata_pos: i32 = 0; - let coldata: any = null; - let coldata_pos: i32 = 0; + // let ldata: any = bl_handle_get(m, "ldata"); + // let uvdata: any = null; + // let uvdata_pos: i32 = 0; + // let coldata: any = null; + // let coldata_pos: i32 = 0; - for (let i: i32 = 0; i < bl_handle_get(ldata, "totlayer"); ++i) { - let l: any = bl_handle_get(ldata, "layers", i); - if (bl_handle_get(l, "type") == 16) { // CD_MLOOPUV - let ptr: any = bl_handle_get(l, "data"); - uvdata_pos = map_get(bl.map, ptr).pos; - uvdata = l; - } - else if (bl_handle_get(l, "type") == 17) { // CD_PROP_BYTE_COLOR - let ptr: any = bl_handle_get(l, "data"); - coldata_pos = map_get(bl.map, ptr).pos; - coldata = l; - } - // CD_MLOOP == 26 - } + // for (let i: i32 = 0; i < bl_handle_get(ldata, "totlayer"); ++i) { + // let l: any = bl_handle_get(ldata, "layers", i); + // if (bl_handle_get(l, "type") == 16) { // CD_MLOOPUV + // let ptr: any = bl_handle_get(l, "data"); + // uvdata_pos = map_get(bl.map, ptr).pos; + // uvdata = l; + // } + // else if (bl_handle_get(l, "type") == 17) { // CD_PROP_BYTE_COLOR + // let ptr: any = bl_handle_get(l, "data"); + // coldata_pos = map_get(bl.map, ptr).pos; + // coldata = l; + // } + // // CD_MLOOP == 26 + // } - let hasuv: bool = uvdata != null; - let texa: i16_array_t = hasuv ? i16_array_create(numtri * 3 * 2) : null; - let hascol: bool = context_raw.parse_vcols && coldata != null; - let cola: i16_array_t = hascol ? i16_array_create(numtri * 3 * 4) : null; + // let hasuv: bool = uvdata != null; + // let texa: i16_array_t = hasuv ? i16_array_create(numtri * 3 * 2) : null; + // let hascol: bool = context_raw.parse_vcols && coldata != null; + // let cola: i16_array_t = hascol ? i16_array_create(numtri * 3 * 4) : null; - let tri: i32 = 0; - let vec0: vec4_t = vec4_create(); - let vec1: vec4_t = vec4_create(); - let vec2: vec4_t = vec4_create(); - for (let i: i32 = 0; i < totpoly; ++i) { - let poly: any = bl_handle_get(m, "mpoly", i); - // let smooth: bool = get(poly, "flag") & 1 == 1; // ME_SMOOTH - let smooth: bool = false; // TODO: fetch smooth normals - let loopstart: i32 = bl_handle_get(poly, "loopstart"); - let totloop: i32 = bl_handle_get(poly, "totloop"); - if (totloop <= 4) { // Convex, fan triangulation - let v0: bl_handle_t = import_blend_mesh_get_mvert_v(m, loopstart + totloop - 1); - let v1: bl_handle_t = import_blend_mesh_get_mvert_v(m, loopstart); - let co0: any = bl_handle_get(v0, "co"); - let co1: any = bl_handle_get(v1, "co"); - let no0: any = bl_handle_get(v0, "no"); - let no1: any = bl_handle_get(v1, "no"); - if (smooth) { - vec4_normalize(vec4_set(vec0, no0[0] / 32767, no0[1] / 32767, no0[2] / 32767)); // shortmax - vec4_normalize(vec4_set(vec1, no1[0] / 32767, no1[1] / 32767, no1[2] / 32767)); - } - let uv0: f32_array_t = null; - let uv1: f32_array_t = null; - let uv2: f32_array_t = null; - if (hasuv) { - bl.pos = uvdata_pos + (loopstart + totloop - 1) * 4 * 3; // * 3 = x, y, flag - uv0 = parser_blend_read_f32array(bl, 2); - if (uv0[0] > 1.0 + import_blend_mesh_eps) { - uv0[0] = uv0[0] - math_floor(uv0[0]); - } - if (uv0[1] > 1.0 + import_blend_mesh_eps) { - uv0[1] = uv0[1] - math_floor(uv0[1]); - } - bl.pos = uvdata_pos + (loopstart) * 4 * 3; - uv1 = parser_blend_read_f32array(bl, 2); - if (uv1[0] > 1.0 + import_blend_mesh_eps) { - uv1[0] = uv1[0] - math_floor(uv1[0]); - } - if (uv1[1] > 1.0 + import_blend_mesh_eps) { - uv1[1] = uv1[1] - math_floor(uv1[1]); - } - } - let col0r: i32 = 0; - let col0g: i32 = 0; - let col0b: i32 = 0; - let col1r: i32 = 0; - let col1g: i32 = 0; - let col1b: i32 = 0; - let col2r: i32 = 0; - let col2g: i32 = 0; - let col2b: i32 = 0; - if (hascol) { - bl.pos = coldata_pos + (loopstart + totloop - 1) * 1 * 4; // * 4 = r, g, b, a - col0r = parser_blend_read_i8(bl); - col0g = parser_blend_read_i8(bl); - col0b = parser_blend_read_i8(bl); - bl.pos = coldata_pos + (loopstart) * 1 * 4; - col1r = parser_blend_read_i8(bl); - col1g = parser_blend_read_i8(bl); - col1b = parser_blend_read_i8(bl); - } - for (let j: i32 = 0; j < totloop - 2; ++j) { - let v2: bl_handle_t = import_blend_mesh_get_mvert_v(m, loopstart + j + 1); - let co2: any = bl_handle_get(v2, "co"); - let no2: any = bl_handle_get(v2, "no"); - if (smooth) { - vec4_normalize(vec4_set(vec2, no2[0] / 32767, no2[1] / 32767, no2[2] / 32767)); - } - else { - vec4_set(vec2, co2[0], co2[1], co2[2]); - vec4_set(vec1, co1[0], co1[1], co1[2]); - vec4_sub_vecs(vec0, vec2, vec1); - vec4_set(vec2, co0[0], co0[1], co0[2]); - vec4_sub_vecs(vec1, vec2, vec1); - vec4_cross(vec0, vec1); - vec4_normalize(vec0); - } - posa32[tri * 9 ] = co0[0]; - posa32[tri * 9 + 1] = co0[1]; - posa32[tri * 9 + 2] = co0[2]; - posa32[tri * 9 + 3] = co1[0]; - posa32[tri * 9 + 4] = co1[1]; - posa32[tri * 9 + 5] = co1[2]; - posa32[tri * 9 + 6] = co2[0]; - posa32[tri * 9 + 7] = co2[1]; - posa32[tri * 9 + 8] = co2[2]; - posa[tri * 12 + 3] = math_floor(vec0.z * 32767); - posa[tri * 12 + 7] = math_floor((smooth ? vec1.z : vec0.z) * 32767); - posa[tri * 12 + 11] = math_floor((smooth ? vec2.z : vec0.z) * 32767); - nora[tri * 6 ] = math_floor(vec0.x * 32767); - nora[tri * 6 + 1] = math_floor(vec0.y * 32767); - nora[tri * 6 + 2] = math_floor((smooth ? vec1.x : vec0.x) * 32767); - nora[tri * 6 + 3] = math_floor((smooth ? vec1.y : vec0.y) * 32767); - nora[tri * 6 + 4] = math_floor((smooth ? vec2.x : vec0.x) * 32767); - nora[tri * 6 + 5] = math_floor((smooth ? vec2.y : vec0.y) * 32767); - co1 = co2; - no1 = no2; - vec4_set_from(vec1, vec2); - if (hasuv) { - bl.pos = uvdata_pos + (loopstart + j + 1) * 4 * 3; - uv2 = parser_blend_read_f32array(bl, 2); - if (uv2[0] > 1.0 + import_blend_mesh_eps) { - uv2[0] = uv2[0] - math_floor(uv2[0]); - } - if (uv2[1] > 1.0 + import_blend_mesh_eps) { - uv2[1] = uv2[1] - math_floor(uv2[1]); - } - texa[tri * 6 ] = math_floor(uv0[0] * 32767); - texa[tri * 6 + 1] = math_floor((1.0 - uv0[1]) * 32767); - texa[tri * 6 + 2] = math_floor(uv1[0] * 32767); - texa[tri * 6 + 3] = math_floor((1.0 - uv1[1]) * 32767); - texa[tri * 6 + 4] = math_floor(uv2[0] * 32767); - texa[tri * 6 + 5] = math_floor((1.0 - uv2[1]) * 32767); - uv1 = uv2; - } - if (hascol) { - bl.pos = coldata_pos + (loopstart + j + 1) * 1 * 4; - col2r = parser_blend_read_i8(bl); - col2g = parser_blend_read_i8(bl); - col2b = parser_blend_read_i8(bl); - cola[tri * 12 ] = col0r * 128; - cola[tri * 12 + 1] = col0g * 128; - cola[tri * 12 + 2] = col0b * 128; - cola[tri * 12 + 3] = col1r * 128; - cola[tri * 12 + 4] = col1g * 128; - cola[tri * 12 + 5] = col1b * 128; - cola[tri * 12 + 6] = col2r * 128; - cola[tri * 12 + 7] = col2g * 128; - cola[tri * 12 + 8] = col2b * 128; - col1r = col2r; - col1g = col2g; - col1b = col2b; - } - tri++; - } - } - else { // Convex or concave, ear clipping - let va: i32[] = []; - for (let i: i32 = 0; i < totloop; ++i) { - array_push(va, loopstart + i); - } - let v0: bl_handle_t = import_blend_mesh_get_mvert_v(m, loopstart); - let v1: bl_handle_t = import_blend_mesh_get_mvert_v(m, loopstart + 1); - let v2: bl_handle_t = import_blend_mesh_get_mvert_v(m, loopstart + 2); - let co0: any = bl_handle_get(v0, "co"); - let co1: any = bl_handle_get(v1, "co"); - let co2: any = bl_handle_get(v2, "co"); - vec4_set(vec2, co2[0], co2[1], co2[2]); - vec4_set(vec1, co1[0], co1[1], co1[2]); - vec4_sub_vecs(vec0, vec2, vec1); - vec4_set(vec2, co0[0], co0[1], co0[2]); - vec4_sub_vecs(vec1, vec2, vec1); - vec4_cross(vec0, vec1); - vec4_normalize(vec0, ); + // let tri: i32 = 0; + // let vec0: vec4_t = vec4_create(); + // let vec1: vec4_t = vec4_create(); + // let vec2: vec4_t = vec4_create(); + // for (let i: i32 = 0; i < totpoly; ++i) { + // let poly: any = bl_handle_get(m, "mpoly", i); + // // let smooth: bool = get(poly, "flag") & 1 == 1; // ME_SMOOTH + // let smooth: bool = false; // TODO: fetch smooth normals + // let loopstart: i32 = bl_handle_get(poly, "loopstart"); + // let totloop: i32 = bl_handle_get(poly, "totloop"); + // if (totloop <= 4) { // Convex, fan triangulation + // let v0: bl_handle_t = import_blend_mesh_get_mvert_v(m, loopstart + totloop - 1); + // let v1: bl_handle_t = import_blend_mesh_get_mvert_v(m, loopstart); + // let co0: any = bl_handle_get(v0, "co"); + // let co1: any = bl_handle_get(v1, "co"); + // let no0: any = bl_handle_get(v0, "no"); + // let no1: any = bl_handle_get(v1, "no"); + // if (smooth) { + // vec4_normalize(vec4_set(vec0, no0[0] / 32767, no0[1] / 32767, no0[2] / 32767)); // shortmax + // vec4_normalize(vec4_set(vec1, no1[0] / 32767, no1[1] / 32767, no1[2] / 32767)); + // } + // let uv0: f32_array_t = null; + // let uv1: f32_array_t = null; + // let uv2: f32_array_t = null; + // if (hasuv) { + // bl.pos = uvdata_pos + (loopstart + totloop - 1) * 4 * 3; // * 3 = x, y, flag + // uv0 = parser_blend_read_f32array(bl, 2); + // if (uv0[0] > 1.0 + import_blend_mesh_eps) { + // uv0[0] = uv0[0] - math_floor(uv0[0]); + // } + // if (uv0[1] > 1.0 + import_blend_mesh_eps) { + // uv0[1] = uv0[1] - math_floor(uv0[1]); + // } + // bl.pos = uvdata_pos + (loopstart) * 4 * 3; + // uv1 = parser_blend_read_f32array(bl, 2); + // if (uv1[0] > 1.0 + import_blend_mesh_eps) { + // uv1[0] = uv1[0] - math_floor(uv1[0]); + // } + // if (uv1[1] > 1.0 + import_blend_mesh_eps) { + // uv1[1] = uv1[1] - math_floor(uv1[1]); + // } + // } + // let col0r: i32 = 0; + // let col0g: i32 = 0; + // let col0b: i32 = 0; + // let col1r: i32 = 0; + // let col1g: i32 = 0; + // let col1b: i32 = 0; + // let col2r: i32 = 0; + // let col2g: i32 = 0; + // let col2b: i32 = 0; + // if (hascol) { + // bl.pos = coldata_pos + (loopstart + totloop - 1) * 1 * 4; // * 4 = r, g, b, a + // col0r = parser_blend_read_i8(bl); + // col0g = parser_blend_read_i8(bl); + // col0b = parser_blend_read_i8(bl); + // bl.pos = coldata_pos + (loopstart) * 1 * 4; + // col1r = parser_blend_read_i8(bl); + // col1g = parser_blend_read_i8(bl); + // col1b = parser_blend_read_i8(bl); + // } + // for (let j: i32 = 0; j < totloop - 2; ++j) { + // let v2: bl_handle_t = import_blend_mesh_get_mvert_v(m, loopstart + j + 1); + // let co2: any = bl_handle_get(v2, "co"); + // let no2: any = bl_handle_get(v2, "no"); + // if (smooth) { + // vec4_normalize(vec4_set(vec2, no2[0] / 32767, no2[1] / 32767, no2[2] / 32767)); + // } + // else { + // vec4_set(vec2, co2[0], co2[1], co2[2]); + // vec4_set(vec1, co1[0], co1[1], co1[2]); + // vec4_sub_vecs(vec0, vec2, vec1); + // vec4_set(vec2, co0[0], co0[1], co0[2]); + // vec4_sub_vecs(vec1, vec2, vec1); + // vec4_cross(vec0, vec1); + // vec4_normalize(vec0); + // } + // posa32[tri * 9 ] = co0[0]; + // posa32[tri * 9 + 1] = co0[1]; + // posa32[tri * 9 + 2] = co0[2]; + // posa32[tri * 9 + 3] = co1[0]; + // posa32[tri * 9 + 4] = co1[1]; + // posa32[tri * 9 + 5] = co1[2]; + // posa32[tri * 9 + 6] = co2[0]; + // posa32[tri * 9 + 7] = co2[1]; + // posa32[tri * 9 + 8] = co2[2]; + // posa[tri * 12 + 3] = math_floor(vec0.z * 32767); + // posa[tri * 12 + 7] = math_floor((smooth ? vec1.z : vec0.z) * 32767); + // posa[tri * 12 + 11] = math_floor((smooth ? vec2.z : vec0.z) * 32767); + // nora[tri * 6 ] = math_floor(vec0.x * 32767); + // nora[tri * 6 + 1] = math_floor(vec0.y * 32767); + // nora[tri * 6 + 2] = math_floor((smooth ? vec1.x : vec0.x) * 32767); + // nora[tri * 6 + 3] = math_floor((smooth ? vec1.y : vec0.y) * 32767); + // nora[tri * 6 + 4] = math_floor((smooth ? vec2.x : vec0.x) * 32767); + // nora[tri * 6 + 5] = math_floor((smooth ? vec2.y : vec0.y) * 32767); + // co1 = co2; + // no1 = no2; + // vec4_set_from(vec1, vec2); + // if (hasuv) { + // bl.pos = uvdata_pos + (loopstart + j + 1) * 4 * 3; + // uv2 = parser_blend_read_f32array(bl, 2); + // if (uv2[0] > 1.0 + import_blend_mesh_eps) { + // uv2[0] = uv2[0] - math_floor(uv2[0]); + // } + // if (uv2[1] > 1.0 + import_blend_mesh_eps) { + // uv2[1] = uv2[1] - math_floor(uv2[1]); + // } + // texa[tri * 6 ] = math_floor(uv0[0] * 32767); + // texa[tri * 6 + 1] = math_floor((1.0 - uv0[1]) * 32767); + // texa[tri * 6 + 2] = math_floor(uv1[0] * 32767); + // texa[tri * 6 + 3] = math_floor((1.0 - uv1[1]) * 32767); + // texa[tri * 6 + 4] = math_floor(uv2[0] * 32767); + // texa[tri * 6 + 5] = math_floor((1.0 - uv2[1]) * 32767); + // uv1 = uv2; + // } + // if (hascol) { + // bl.pos = coldata_pos + (loopstart + j + 1) * 1 * 4; + // col2r = parser_blend_read_i8(bl); + // col2g = parser_blend_read_i8(bl); + // col2b = parser_blend_read_i8(bl); + // cola[tri * 12 ] = col0r * 128; + // cola[tri * 12 + 1] = col0g * 128; + // cola[tri * 12 + 2] = col0b * 128; + // cola[tri * 12 + 3] = col1r * 128; + // cola[tri * 12 + 4] = col1g * 128; + // cola[tri * 12 + 5] = col1b * 128; + // cola[tri * 12 + 6] = col2r * 128; + // cola[tri * 12 + 7] = col2g * 128; + // cola[tri * 12 + 8] = col2b * 128; + // col1r = col2r; + // col1g = col2g; + // col1b = col2b; + // } + // tri++; + // } + // } + // else { // Convex or concave, ear clipping + // let va: i32[] = []; + // for (let i: i32 = 0; i < totloop; ++i) { + // array_push(va, loopstart + i); + // } + // let v0: bl_handle_t = import_blend_mesh_get_mvert_v(m, loopstart); + // let v1: bl_handle_t = import_blend_mesh_get_mvert_v(m, loopstart + 1); + // let v2: bl_handle_t = import_blend_mesh_get_mvert_v(m, loopstart + 2); + // let co0: any = bl_handle_get(v0, "co"); + // let co1: any = bl_handle_get(v1, "co"); + // let co2: any = bl_handle_get(v2, "co"); + // vec4_set(vec2, co2[0], co2[1], co2[2]); + // vec4_set(vec1, co1[0], co1[1], co1[2]); + // vec4_sub_vecs(vec0, vec2, vec1); + // vec4_set(vec2, co0[0], co0[1], co0[2]); + // vec4_sub_vecs(vec1, vec2, vec1); + // vec4_cross(vec0, vec1); + // vec4_normalize(vec0, ); - let nx: f32 = vec0.x; - let ny: f32 = vec0.y; - let nz: f32 = vec0.z; - let nxabs: f32 = math_abs(nx); - let nyabs: f32 = math_abs(ny); - let nzabs: f32 = math_abs(nz); - let flip: bool = nx + ny + nz > 0; - let axis: i32 = nxabs > nyabs && nxabs > nzabs ? 0 : nyabs > nxabs && nyabs > nzabs ? 1 : 2; - let axis0: i32 = axis == 0 ? (flip ? 2 : 1) : axis == 1 ? (flip ? 0 : 2) : (flip ? 1 : 0); - let axis1: i32 = axis == 0 ? (flip ? 1 : 2) : axis == 1 ? (flip ? 2 : 0) : (flip ? 0 : 1); + // let nx: f32 = vec0.x; + // let ny: f32 = vec0.y; + // let nz: f32 = vec0.z; + // let nxabs: f32 = math_abs(nx); + // let nyabs: f32 = math_abs(ny); + // let nzabs: f32 = math_abs(nz); + // let flip: bool = nx + ny + nz > 0; + // let axis: i32 = nxabs > nyabs && nxabs > nzabs ? 0 : nyabs > nxabs && nyabs > nzabs ? 1 : 2; + // let axis0: i32 = axis == 0 ? (flip ? 2 : 1) : axis == 1 ? (flip ? 0 : 2) : (flip ? 1 : 0); + // let axis1: i32 = axis == 0 ? (flip ? 1 : 2) : axis == 1 ? (flip ? 2 : 0) : (flip ? 0 : 1); - let winding: f32 = 0.0; - for (let i: i32 = 0; i < totloop; ++i) { - let v0: bl_handle_t = import_blend_mesh_get_mvert_v(m, loopstart + i); - let v1: bl_handle_t = import_blend_mesh_get_mvert_v(m, loopstart + ((i + 1) % totloop)); - let co0: any = bl_handle_get(v0, "co"); - let co1: any = bl_handle_get(v1, "co"); - winding += (co1[axis0] - co0[axis0]) * (co1[axis1] + co0[axis1]); - } - flip = winding > 0 ? nx + ny + nz > 0 : nx + ny + nz < 0; - axis0 = axis == 0 ? (flip ? 2 : 1) : axis == 1 ? (flip ? 0 : 2) : (flip ? 1 : 0); - axis1 = axis == 0 ? (flip ? 1 : 2) : axis == 1 ? (flip ? 2 : 0) : (flip ? 0 : 1); + // let winding: f32 = 0.0; + // for (let i: i32 = 0; i < totloop; ++i) { + // let v0: bl_handle_t = import_blend_mesh_get_mvert_v(m, loopstart + i); + // let v1: bl_handle_t = import_blend_mesh_get_mvert_v(m, loopstart + ((i + 1) % totloop)); + // let co0: any = bl_handle_get(v0, "co"); + // let co1: any = bl_handle_get(v1, "co"); + // winding += (co1[axis0] - co0[axis0]) * (co1[axis1] + co0[axis1]); + // } + // flip = winding > 0 ? nx + ny + nz > 0 : nx + ny + nz < 0; + // axis0 = axis == 0 ? (flip ? 2 : 1) : axis == 1 ? (flip ? 0 : 2) : (flip ? 1 : 0); + // axis1 = axis == 0 ? (flip ? 1 : 2) : axis == 1 ? (flip ? 2 : 0) : (flip ? 0 : 1); - let vi: i32 = totloop; - let loops: i32 = 0; - let i: i32 = -1; - while (vi > 2 && loops++ < vi) { - i = (i + 1) % vi; - let i1: i32 = (i + 1) % vi; - let i2: i32 = (i + 2) % vi; - let v0: bl_handle_t = import_blend_mesh_get_mvert_v(m, va[i ]); - let v1: bl_handle_t = import_blend_mesh_get_mvert_v(m, va[i1]); - let v2: bl_handle_t = import_blend_mesh_get_mvert_v(m, va[i2]); - let co0: any = bl_handle_get(v0, "co"); - let co1: any = bl_handle_get(v1, "co"); - let co2: any = bl_handle_get(v2, "co"); - let v0x: f32 = co0[axis0]; - let v0y: f32 = co0[axis1]; - let v1x: f32 = co1[axis0]; - let v1y: f32 = co1[axis1]; - let v2x: f32 = co2[axis0]; - let v2y: f32 = co2[axis1]; + // let vi: i32 = totloop; + // let loops: i32 = 0; + // let i: i32 = -1; + // while (vi > 2 && loops++ < vi) { + // i = (i + 1) % vi; + // let i1: i32 = (i + 1) % vi; + // let i2: i32 = (i + 2) % vi; + // let v0: bl_handle_t = import_blend_mesh_get_mvert_v(m, va[i ]); + // let v1: bl_handle_t = import_blend_mesh_get_mvert_v(m, va[i1]); + // let v2: bl_handle_t = import_blend_mesh_get_mvert_v(m, va[i2]); + // let co0: any = bl_handle_get(v0, "co"); + // let co1: any = bl_handle_get(v1, "co"); + // let co2: any = bl_handle_get(v2, "co"); + // let v0x: f32 = co0[axis0]; + // let v0y: f32 = co0[axis1]; + // let v1x: f32 = co1[axis0]; + // let v1y: f32 = co1[axis1]; + // let v2x: f32 = co2[axis0]; + // let v2y: f32 = co2[axis1]; - let e0x: f32 = v0x - v1x; // Not an interior vertex - let e0y: f32 = v0y - v1y; - let e1x: f32 = v2x - v1x; - let e1y: f32 = v2y - v1y; - let cross: f32 = e0x * e1y - e0y * e1x; - if (cross <= 0) { - continue; - } + // let e0x: f32 = v0x - v1x; // Not an interior vertex + // let e0y: f32 = v0y - v1y; + // let e1x: f32 = v2x - v1x; + // let e1y: f32 = v2y - v1y; + // let cross: f32 = e0x * e1y - e0y * e1x; + // if (cross <= 0) { + // continue; + // } - let overlap: bool = false; // Other vertex found inside this triangle - for (let j: i32 = 0; j < vi - 3; ++j) { - let j0: i32 = (i + 3 + j) % vi; - let v: bl_handle_t = import_blend_mesh_get_mvert_v(m, va[j0]); - let co: any = bl_handle_get(v, "co"); - let px: f32 = co[axis0]; - let py: f32 = co[axis1]; + // let overlap: bool = false; // Other vertex found inside this triangle + // for (let j: i32 = 0; j < vi - 3; ++j) { + // let j0: i32 = (i + 3 + j) % vi; + // let v: bl_handle_t = import_blend_mesh_get_mvert_v(m, va[j0]); + // let co: any = bl_handle_get(v, "co"); + // let px: f32 = co[axis0]; + // let py: f32 = co[axis1]; - if (util_mesh_pnpoly(v0x, v0y, v1x, v1y, v2x, v2y, px, py)) { - overlap = true; - break; - } - } - if (overlap) { - continue; - } + // if (util_mesh_pnpoly(v0x, v0y, v1x, v1y, v2x, v2y, px, py)) { + // overlap = true; + // break; + // } + // } + // if (overlap) { + // continue; + // } - // Found ear - { - let no0: any = bl_handle_get(v0, "no"); - let no1: any = bl_handle_get(v1, "no"); - let no2: any = bl_handle_get(v2, "no"); - if (smooth) { - vec4_normalize(vec4_set(vec0, no0[0] / 32767, no0[1] / 32767, no0[2] / 32767)); // shortmax - vec4_normalize(vec4_set(vec1, no1[0] / 32767, no1[1] / 32767, no1[2] / 32767)); - vec4_normalize(vec4_set(vec2, no2[0] / 32767, no2[1] / 32767, no2[2] / 32767)); - } - else { - vec4_set(vec2, co2[0], co2[1], co2[2]); - vec4_set(vec1, co1[0], co1[1], co1[2]); - vec4_sub_vecs(vec0, vec2, vec1); - vec4_set(vec2, co0[0], co0[1], co0[2]); - vec4_sub_vecs(vec1, vec2, vec1); - vec4_cross(vec0, vec1); - vec4_normalize(vec0, ); - } - let uv0: f32_array_t = null; - let uv1: f32_array_t = null; - let uv2: f32_array_t = null; - if (hasuv) { - bl.pos = uvdata_pos + (va[i ]) * 4 * 3; - uv0 = parser_blend_read_f32array(bl, 2); - if (uv0[0] > 1.0 + import_blend_mesh_eps) { - uv0[0] = uv0[0] - math_floor(uv0[0]); - } - if (uv0[1] > 1.0 + import_blend_mesh_eps) { - uv0[1] = uv0[1] - math_floor(uv0[1]); - } - bl.pos = uvdata_pos + (va[i1]) * 4 * 3; - uv1 = parser_blend_read_f32array(bl, 2); - if (uv1[0] > 1.0 + import_blend_mesh_eps) { - uv1[0] = uv1[0] - math_floor(uv1[0]); - } - if (uv1[1] > 1.0 + import_blend_mesh_eps) { - uv1[1] = uv1[1] - math_floor(uv1[1]); - } - bl.pos = uvdata_pos + (va[i2]) * 4 * 3; - uv2 = parser_blend_read_f32array(bl, 2); - if (uv2[0] > 1.0 + import_blend_mesh_eps) { - uv2[0] = uv2[0] - math_floor(uv2[0]); - } - if (uv2[1] > 1.0 + import_blend_mesh_eps) { - uv2[1] = uv2[1] - math_floor(uv2[1]); - } - } - let col0r: i32 = 0; - let col0g: i32 = 0; - let col0b: i32 = 0; - let col1r: i32 = 0; - let col1g: i32 = 0; - let col1b: i32 = 0; - let col2r: i32 = 0; - let col2g: i32 = 0; - let col2b: i32 = 0; - if (hascol) { - bl.pos = coldata_pos + (va[i ]) * 1 * 4; - col0r = parser_blend_read_i8(bl); - col0g = parser_blend_read_i8(bl); - col0b = parser_blend_read_i8(bl); - bl.pos = coldata_pos + (va[i1]) * 1 * 4; - col1r = parser_blend_read_i8(bl); - col1g = parser_blend_read_i8(bl); - col1b = parser_blend_read_i8(bl); - bl.pos = coldata_pos + (va[i2]) * 1 * 4; - col2r = parser_blend_read_i8(bl); - col2g = parser_blend_read_i8(bl); - col2b = parser_blend_read_i8(bl); - } - posa32[tri * 9 ] = co0[0]; - posa32[tri * 9 + 1] = co0[1]; - posa32[tri * 9 + 2] = co0[2]; - posa32[tri * 9 + 3] = co1[0]; - posa32[tri * 9 + 4] = co1[1]; - posa32[tri * 9 + 5] = co1[2]; - posa32[tri * 9 + 6] = co2[0]; - posa32[tri * 9 + 7] = co2[1]; - posa32[tri * 9 + 8] = co2[2]; - posa[tri * 12 + 3] = math_floor(vec0.z * 32767); - posa[tri * 12 + 7] = math_floor((smooth ? vec1.z : vec0.z) * 32767); - posa[tri * 12 + 11] = math_floor((smooth ? vec2.z : vec0.z) * 32767); - nora[tri * 6 ] = math_floor(vec0.x * 32767); - nora[tri * 6 + 1] = math_floor(vec0.y * 32767); - nora[tri * 6 + 2] = math_floor((smooth ? vec1.x : vec0.x) * 32767); - nora[tri * 6 + 3] = math_floor((smooth ? vec1.y : vec0.y) * 32767); - nora[tri * 6 + 4] = math_floor((smooth ? vec2.x : vec0.x) * 32767); - nora[tri * 6 + 5] = math_floor((smooth ? vec2.y : vec0.y) * 32767); - if (hasuv) { - texa[tri * 6 ] = math_floor(uv0[0] * 32767); - texa[tri * 6 + 1] = math_floor((1.0 - uv0[1]) * 32767); - texa[tri * 6 + 2] = math_floor(uv1[0] * 32767); - texa[tri * 6 + 3] = math_floor((1.0 - uv1[1]) * 32767); - texa[tri * 6 + 4] = math_floor(uv2[0] * 32767); - texa[tri * 6 + 5] = math_floor((1.0 - uv2[1]) * 32767); - } - if (hascol) { - cola[tri * 12 ] = col0r * 128; - cola[tri * 12 + 1] = col0g * 128; - cola[tri * 12 + 2] = col0b * 128; - cola[tri * 12 + 3] = col1r * 128; - cola[tri * 12 + 4] = col1g * 128; - cola[tri * 12 + 5] = col1b * 128; - cola[tri * 12 + 6] = col2r * 128; - cola[tri * 12 + 7] = col2g * 128; - cola[tri * 12 + 8] = col2b * 128; - } - tri++; - } + // // Found ear + // { + // let no0: any = bl_handle_get(v0, "no"); + // let no1: any = bl_handle_get(v1, "no"); + // let no2: any = bl_handle_get(v2, "no"); + // if (smooth) { + // vec4_normalize(vec4_set(vec0, no0[0] / 32767, no0[1] / 32767, no0[2] / 32767)); // shortmax + // vec4_normalize(vec4_set(vec1, no1[0] / 32767, no1[1] / 32767, no1[2] / 32767)); + // vec4_normalize(vec4_set(vec2, no2[0] / 32767, no2[1] / 32767, no2[2] / 32767)); + // } + // else { + // vec4_set(vec2, co2[0], co2[1], co2[2]); + // vec4_set(vec1, co1[0], co1[1], co1[2]); + // vec4_sub_vecs(vec0, vec2, vec1); + // vec4_set(vec2, co0[0], co0[1], co0[2]); + // vec4_sub_vecs(vec1, vec2, vec1); + // vec4_cross(vec0, vec1); + // vec4_normalize(vec0, ); + // } + // let uv0: f32_array_t = null; + // let uv1: f32_array_t = null; + // let uv2: f32_array_t = null; + // if (hasuv) { + // bl.pos = uvdata_pos + (va[i ]) * 4 * 3; + // uv0 = parser_blend_read_f32array(bl, 2); + // if (uv0[0] > 1.0 + import_blend_mesh_eps) { + // uv0[0] = uv0[0] - math_floor(uv0[0]); + // } + // if (uv0[1] > 1.0 + import_blend_mesh_eps) { + // uv0[1] = uv0[1] - math_floor(uv0[1]); + // } + // bl.pos = uvdata_pos + (va[i1]) * 4 * 3; + // uv1 = parser_blend_read_f32array(bl, 2); + // if (uv1[0] > 1.0 + import_blend_mesh_eps) { + // uv1[0] = uv1[0] - math_floor(uv1[0]); + // } + // if (uv1[1] > 1.0 + import_blend_mesh_eps) { + // uv1[1] = uv1[1] - math_floor(uv1[1]); + // } + // bl.pos = uvdata_pos + (va[i2]) * 4 * 3; + // uv2 = parser_blend_read_f32array(bl, 2); + // if (uv2[0] > 1.0 + import_blend_mesh_eps) { + // uv2[0] = uv2[0] - math_floor(uv2[0]); + // } + // if (uv2[1] > 1.0 + import_blend_mesh_eps) { + // uv2[1] = uv2[1] - math_floor(uv2[1]); + // } + // } + // let col0r: i32 = 0; + // let col0g: i32 = 0; + // let col0b: i32 = 0; + // let col1r: i32 = 0; + // let col1g: i32 = 0; + // let col1b: i32 = 0; + // let col2r: i32 = 0; + // let col2g: i32 = 0; + // let col2b: i32 = 0; + // if (hascol) { + // bl.pos = coldata_pos + (va[i ]) * 1 * 4; + // col0r = parser_blend_read_i8(bl); + // col0g = parser_blend_read_i8(bl); + // col0b = parser_blend_read_i8(bl); + // bl.pos = coldata_pos + (va[i1]) * 1 * 4; + // col1r = parser_blend_read_i8(bl); + // col1g = parser_blend_read_i8(bl); + // col1b = parser_blend_read_i8(bl); + // bl.pos = coldata_pos + (va[i2]) * 1 * 4; + // col2r = parser_blend_read_i8(bl); + // col2g = parser_blend_read_i8(bl); + // col2b = parser_blend_read_i8(bl); + // } + // posa32[tri * 9 ] = co0[0]; + // posa32[tri * 9 + 1] = co0[1]; + // posa32[tri * 9 + 2] = co0[2]; + // posa32[tri * 9 + 3] = co1[0]; + // posa32[tri * 9 + 4] = co1[1]; + // posa32[tri * 9 + 5] = co1[2]; + // posa32[tri * 9 + 6] = co2[0]; + // posa32[tri * 9 + 7] = co2[1]; + // posa32[tri * 9 + 8] = co2[2]; + // posa[tri * 12 + 3] = math_floor(vec0.z * 32767); + // posa[tri * 12 + 7] = math_floor((smooth ? vec1.z : vec0.z) * 32767); + // posa[tri * 12 + 11] = math_floor((smooth ? vec2.z : vec0.z) * 32767); + // nora[tri * 6 ] = math_floor(vec0.x * 32767); + // nora[tri * 6 + 1] = math_floor(vec0.y * 32767); + // nora[tri * 6 + 2] = math_floor((smooth ? vec1.x : vec0.x) * 32767); + // nora[tri * 6 + 3] = math_floor((smooth ? vec1.y : vec0.y) * 32767); + // nora[tri * 6 + 4] = math_floor((smooth ? vec2.x : vec0.x) * 32767); + // nora[tri * 6 + 5] = math_floor((smooth ? vec2.y : vec0.y) * 32767); + // if (hasuv) { + // texa[tri * 6 ] = math_floor(uv0[0] * 32767); + // texa[tri * 6 + 1] = math_floor((1.0 - uv0[1]) * 32767); + // texa[tri * 6 + 2] = math_floor(uv1[0] * 32767); + // texa[tri * 6 + 3] = math_floor((1.0 - uv1[1]) * 32767); + // texa[tri * 6 + 4] = math_floor(uv2[0] * 32767); + // texa[tri * 6 + 5] = math_floor((1.0 - uv2[1]) * 32767); + // } + // if (hascol) { + // cola[tri * 12 ] = col0r * 128; + // cola[tri * 12 + 1] = col0g * 128; + // cola[tri * 12 + 2] = col0b * 128; + // cola[tri * 12 + 3] = col1r * 128; + // cola[tri * 12 + 4] = col1g * 128; + // cola[tri * 12 + 5] = col1b * 128; + // cola[tri * 12 + 6] = col2r * 128; + // cola[tri * 12 + 7] = col2g * 128; + // cola[tri * 12 + 8] = col2b * 128; + // } + // tri++; + // } - for (let j: i32 = ((i + 1) % vi); j < vi - 1; ++j) { // Consume vertex - va[j] = va[j + 1]; - } - vi--; - i--; - loops = 0; - } - } - } + // for (let j: i32 = ((i + 1) % vi); j < vi - 1; ++j) { // Consume vertex + // va[j] = va[j + 1]; + // } + // vi--; + // i--; + // loops = 0; + // } + // } + // } - // Apply world matrix - let obmat: any = bl_handle_get(ob, "obmat", 0, "float", 16); - let mat: mat4_t = mat4_transpose(mat4_from_f32_array(obmat)); - let v: vec4_t = vec4_create(); - for (let i: i32 = 0; i < math_floor(posa32.length / 3); ++i) { - vec4_set(v, posa32[i * 3], posa32[i * 3 + 1], posa32[i * 3 + 2]); - vec4_apply_mat4(v, mat); - posa32[i * 3 ] = v.x; - posa32[i * 3 + 1] = v.y; - posa32[i * 3 + 2] = v.z; - } - mat4_get_inv(mat, mat); - mat4_transpose3x3(mat); - mat.m[12] = mat.m[13] = mat.m[14] = mat.m[15] = 0; - for (let i: i32 = 0; i < math_floor(nora.length / 2); ++i) { - vec4_set(v, nora[i * 2] / 32767, nora[i * 2 + 1] / 32767, posa[i * 4 + 3] / 32767); - vec4_apply_mat(v, mat); - vec4_normalize(v); - nora[i * 2 ] = math_floor(v.x * 32767); - nora[i * 2 + 1] = math_floor(v.y * 32767); - posa[i * 4 + 3] = math_floor(v.z * 32767); - } + // // Apply world matrix + // let obmat: any = bl_handle_get(ob, "obmat", 0, "float", 16); + // let mat: mat4_t = mat4_transpose(mat4_from_f32_array(obmat)); + // let v: vec4_t = vec4_create(); + // for (let i: i32 = 0; i < math_floor(posa32.length / 3); ++i) { + // vec4_set(v, posa32[i * 3], posa32[i * 3 + 1], posa32[i * 3 + 2]); + // vec4_apply_mat4(v, mat); + // posa32[i * 3 ] = v.x; + // posa32[i * 3 + 1] = v.y; + // posa32[i * 3 + 2] = v.z; + // } + // mat4_get_inv(mat, mat); + // mat4_transpose3x3(mat); + // mat.m[12] = mat.m[13] = mat.m[14] = mat.m[15] = 0; + // for (let i: i32 = 0; i < math_floor(nora.length / 2); ++i) { + // vec4_set(v, nora[i * 2] / 32767, nora[i * 2 + 1] / 32767, posa[i * 4 + 3] / 32767); + // vec4_apply_mat(v, mat); + // vec4_normalize(v); + // nora[i * 2 ] = math_floor(v.x * 32767); + // nora[i * 2 + 1] = math_floor(v.y * 32767); + // posa[i * 4 + 3] = math_floor(v.z * 32767); + // } - // Pack positions to (-1, 1) range - let scale_pos: f32 = 0.0; - for (let i: i32 = 0; i < posa32.length; ++i) { - let f: f32 = math_abs(posa32[i]); - if (scale_pos < f) { - scale_pos = f; - } - } - 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); - posa[i * 4 + 2] = math_floor(posa32[i * 3 + 2] * 32767 * inv); - } + // // Pack positions to (-1, 1) range + // let scale_pos: f32 = 0.0; + // for (let i: i32 = 0; i < posa32.length; ++i) { + // let f: f32 = math_abs(posa32[i]); + // if (scale_pos < f) { + // scale_pos = f; + // } + // } + // 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); + // posa[i * 4 + 2] = math_floor(posa32[i * 3 + 2] * 32767 * inv); + // } - let obj: any = { - posa: posa, - nora: nora, - texa: texa, - cola: cola, - inda: inda, - name: name, - scale_pos: scale_pos, - scale_tex: 1.0 - }; + // let obj: any = { + // posa: posa, + // nora: nora, + // texa: texa, + // cola: cola, + // inda: inda, + // name: name, + // scale_pos: scale_pos, + // scale_tex: 1.0 + // }; - if (first && replace_existing) { - import_mesh_make_mesh(obj, path); - } - else { - import_mesh_add_mesh(obj); - } - first = false; - } + // if (first && replace_existing) { + // import_mesh_make_mesh(obj, path); + // } + // else { + // import_mesh_add_mesh(obj); + // } + // first = false; + // } - data_delete_blob(path); + // data_delete_blob(path); } -function import_blend_mesh_get_mvert_v(m: bl_handle_t, loopstart: i32) { - return bl_handle_get(m, "mvert", bl_handle_get(bl_handle_get(m, "mloop", loopstart), "v")); -} +// function import_blend_mesh_get_mvert_v(m: bl_handle_t, loopstart: i32) { +// return bl_handle_get(m, "mvert", bl_handle_get(bl_handle_get(m, "mloop", loopstart), "v")); +// } diff --git a/base/Sources/import_gpl.ts b/base/Sources/import_gpl.ts index b8c39db0..97910316 100644 --- a/base/Sources/import_gpl.ts +++ b/base/Sources/import_gpl.ts @@ -21,7 +21,7 @@ function import_gpl_run(path: string, replace_existing: bool) { // else { // let tokens: string[] = string_split(delimiter, line); // if (tokens.length < 3) continue; - // let swatch: TSwatchColor = makeSwatch(Color.fromBytes(any_to_string(tokens[0]), any_to_string(tokens[1]), any_to_string(tokens[2]))); + // let swatch: TSwatchColor = makeSwatch(Color.fromBytes(tokens[0], tokens[1], tokens[2])); // array_push(swatches, swatch); // } // } diff --git a/base/Sources/import_mesh.ts b/base/Sources/import_mesh.ts index 343b1658..7df1412c 100644 --- a/base/Sources/import_mesh.ts +++ b/base/Sources/import_mesh.ts @@ -36,13 +36,13 @@ function import_mesh_run(path: string, replace_existing: bool = true) { } else { let ext: string = substring(path, string_last_index_of(path, ".") + 1, path.length); - let importer: (s: string)=>any = map_get(path_mesh_importers, ext); - let mesh: any = importer(path); + let importer: (s: string)=>raw_mesh_t = map_get(path_mesh_importers, ext); + let mesh: raw_mesh_t = importer(path); replace_existing ? import_mesh_make_mesh(mesh, path) : import_mesh_add_mesh(mesh); let has_next: bool = mesh.has_next; while (has_next) { - let mesh: any = importer(path); + let mesh: raw_mesh_t = importer(path); has_next = mesh.has_next; import_mesh_add_mesh(mesh); @@ -113,10 +113,15 @@ function import_mesh_finish_import() { ///end } -function _import_mesh_make_mesh(mesh: any) { +function _import_mesh_make_mesh(mesh: raw_mesh_t) { let raw: mesh_data_t = import_mesh_raw_mesh(mesh); if (mesh.cola != null) { - array_push(raw.vertex_arrays, { values: mesh.cola, attrib: "col", data: "short4norm" }); + let va: vertex_array_t = { + values: mesh.cola, + attrib: "col", + data: "short4norm" + }; + array_push(raw.vertex_arrays, va); } let md: mesh_data_t = mesh_data_create(raw); @@ -156,7 +161,7 @@ function _import_mesh_make_mesh(mesh: any) { ///if (is_paint || is_sculpt) if (import_mesh_clear_layers) { while (project_layers.length > 0) { - let l: slot_layer_t = project_layers.pop(); + let l: slot_layer_t = array_pop(project_layers); slot_layer_unload(l); } base_new_layer(false); @@ -174,7 +179,15 @@ function _import_mesh_make_mesh(mesh: any) { } } -function import_mesh_make_mesh(mesh: any, path: string) { +function import_mesh_first_unwrap_done(mesh: raw_mesh_t) { + _import_mesh_make_mesh(mesh); + for (let i: i32 = 0; i < import_mesh_meshes_to_unwrap.length; ++i) { + let mesh: raw_mesh_t = import_mesh_meshes_to_unwrap[i]; + project_unwrap_mesh_box(mesh, _import_mesh_add_mesh, true); + } +} + +function import_mesh_make_mesh(mesh: raw_mesh_t, path: string) { if (mesh == null || mesh.posa == null || mesh.nora == null || mesh.inda == null || mesh.posa.length == 0) { console_error(strings_error3()); return; @@ -184,24 +197,22 @@ function import_mesh_make_mesh(mesh: any, path: string) { if (import_mesh_meshes_to_unwrap == null) { import_mesh_meshes_to_unwrap = []; } - let first_unwrap_done = function (mesh: any) { - _import_mesh_make_mesh(mesh); - for (let i: i32 = 0; i < import_mesh_meshes_to_unwrap.length; ++i) { - let mesh: any = import_mesh_meshes_to_unwrap[i]; - project_unwrap_mesh_box(mesh, _import_mesh_add_mesh, true); - } - } - project_unwrap_mesh_box(mesh, first_unwrap_done); + project_unwrap_mesh_box(mesh, import_mesh_first_unwrap_done); } else { _import_mesh_make_mesh(mesh); } } -function _import_mesh_add_mesh(mesh: any) { +function _import_mesh_add_mesh(mesh: raw_mesh_t) { let raw: mesh_data_t = import_mesh_raw_mesh(mesh); if (mesh.cola != null) { - array_push(raw.vertex_arrays, { values: mesh.cola, attrib: "col", data: "short4norm" }); + let va: vertex_array_t = { + values: mesh.cola, + attrib: "col", + data: "short4norm" + }; + array_push(raw.vertex_arrays, va); } let md: mesh_data_t = mesh_data_create(raw); @@ -235,7 +246,7 @@ function _import_mesh_add_mesh(mesh: any) { ///end } -function import_mesh_add_mesh(mesh: any) { +function import_mesh_add_mesh(mesh: raw_mesh_t) { if (mesh.texa == null) { if (import_mesh_meshes_to_unwrap != null) { array_push(import_mesh_meshes_to_unwrap, mesh); @@ -249,18 +260,34 @@ function import_mesh_add_mesh(mesh: any) { } } -function import_mesh_raw_mesh(mesh: any): mesh_data_t { - return { +function import_mesh_raw_mesh(mesh: raw_mesh_t): mesh_data_t { + let raw: raw_mesh_t = { name: mesh.name, vertex_arrays: [ - { values: mesh.posa, attrib: "pos", data: "short4norm" }, - { values: mesh.nora, attrib: "nor", data: "short2norm" }, - { values: mesh.texa, attrib: "tex", data: "short2norm" } + { + values: mesh.posa, + attrib: "pos", + data: "short4norm" + }, + { + values: mesh.nora, + attrib: "nor", + data: "short2norm" + }, + { + values: mesh.texa, + attrib: "tex", + data: "short2norm" + } ], index_arrays: [ - { values: mesh.inda, material: 0 } + { + values: mesh.inda, + material: 0 + } ], scale_pos: mesh.scale_pos, scale_tex: mesh.scale_tex }; + return raw; } diff --git a/base/Sources/import_obj.ts b/base/Sources/import_obj.ts index 8bb609a0..49eab005 100644 --- a/base/Sources/import_obj.ts +++ b/base/Sources/import_obj.ts @@ -1,4 +1,22 @@ +declare type obj_part_t = { + posa: i16_array_t; + nora: i16_array_t; + texa: i16_array_t; + inda: u32_array_t; + vertex_count: i32; + index_count: i32; + scale_pos: f32; + scale_tex: f32; + name: string; + has_next: bool; + pos: i32; + udims: u32_array_t[]; + udims_count: u32_array_t; + udims_u: i32; + udims_v: i32; +}; + function import_obj_run(path: string, replace_existing: bool = true) { let i: split_type_t = context_raw.split_by; let is_udim: bool = i == split_type_t.UDIM; @@ -10,22 +28,22 @@ function import_obj_run(path: string, replace_existing: bool = true) { let b: buffer_t = data_get_blob(path); if (is_udim) { - let part: any = krom_io_obj_parse(b, split_code, 0, is_udim); - let name: string = part.name; - for (let i: i32 = 0; i < part.udims.length; ++i) { - if (part.udims[i].length == 0) { - continue; - } - let u: i32 = i % part.udims_u; - let v: i32 = math_floor(i / part.udims_u); - part.name = name + "." + (1000 + v * 10 + u + 1); - part.inda = part.udims[i]; - i == 0 ? (replace_existing ? import_mesh_make_mesh(part, path) : import_mesh_add_mesh(part)) : import_mesh_add_mesh(part); - } + // let part: obj_part_t = krom_io_obj_parse(b, split_code, 0, is_udim); + // let name: string = part.name; + // for (let i: i32 = 0; i < part.udims.length; ++i) { + // if (part.udims[i].length == 0) { + // continue; + // } + // let u: i32 = i % part.udims_u; + // let v: i32 = math_floor(i / part.udims_u); + // part.name = name + "." + (1000 + v * 10 + u + 1); + // part.inda = part.udims[i]; + // i == 0 ? (replace_existing ? import_mesh_make_mesh(part, path) : import_mesh_add_mesh(part)) : import_mesh_add_mesh(part); + // } } else { - let parts: any[] = []; - let part: any = krom_io_obj_parse(b, split_code, 0, false); + let parts: obj_part_t[] = []; + let part: obj_part_t = krom_io_obj_parse(b, split_code, 0, false); array_push(parts, part); while (part.has_next) { part = krom_io_obj_parse(b, split_code, part.pos, false); @@ -94,16 +112,30 @@ function import_obj_run(path: string, replace_existing: bool = true) { let nora: i16_array_t = i16_array_create(nora0.length + nora1.length); let texa: i16_array_t = (texa0 != null && texa1 != null) ? i16_array_create(texa0.length + texa1.length) : null; let inda: u32_array_t = u32_array_create(inda0.length + inda1.length); - nora.set(nora0); - nora.set(nora1, nora0.length); - if (texa != null) { - texa.set(texa0); - texa.set(texa1, texa0.length); + + for (let k: i32 = 0; k < nora0.length; ++k) { + nora[k] = nora0[k]; + } + for (let k: i32 = 0; k < nora1.length; ++k) { + nora[k + nora0.length] = nora1[k]; + } + + if (texa != null) { + for (let k: i32 = 0; k < texa0.length; ++k) { + texa[k] = texa0[k]; + } + for (let k: i32 = 0; k < texa1.length; ++k) { + texa[k + texa0.length] = texa1[k]; + } + } + + for (let k: i32 = 0; k < inda0.length; ++k) { + inda[k] = inda0[k]; } - inda.set(inda0); for (let k: i32 = 0; k < inda1.length; ++k) { inda[k + inda0.length] = inda1[k] + voff; } + parts[i].posa = posa; parts[i].nora = nora; parts[i].texa = texa; diff --git a/base/Sources/line_draw.ts b/base/Sources/line_draw.ts index 705b0d5c..197a79cb 100644 --- a/base/Sources/line_draw.ts +++ b/base/Sources/line_draw.ts @@ -144,13 +144,20 @@ function line_draw_line(x1: f32, y1: f32, z1: f32, x2: f32, y2: f32, z2: f32) { vec4_add(vec4_set(line_draw_corner4, x2, y2, z2), line_width); let i: i32 = line_draw_lines * 24; // 4 * 6 (structure len) - line_draw_add_vb_data(i, [line_draw_corner1.x, line_draw_corner1.y, line_draw_corner1.z, color_get_rb(line_draw_color) / 255, color_get_gb(line_draw_color) / 255, color_get_ab(line_draw_color) / 255]); + let data: f32[] = [line_draw_corner1.x, line_draw_corner1.y, line_draw_corner1.z, color_get_rb(line_draw_color) / 255, color_get_gb(line_draw_color) / 255, color_get_ab(line_draw_color) / 255]; + line_draw_add_vb_data(i, data); + i += 6; - line_draw_add_vb_data(i, [line_draw_corner2.x, line_draw_corner2.y, line_draw_corner2.z, color_get_rb(line_draw_color) / 255, color_get_gb(line_draw_color) / 255, color_get_ab(line_draw_color) / 255]); + data = [line_draw_corner2.x, line_draw_corner2.y, line_draw_corner2.z, color_get_rb(line_draw_color) / 255, color_get_gb(line_draw_color) / 255, color_get_ab(line_draw_color) / 255]; + line_draw_add_vb_data(i, data); + i += 6; - line_draw_add_vb_data(i, [line_draw_corner3.x, line_draw_corner3.y, line_draw_corner3.z, color_get_rb(line_draw_color) / 255, color_get_gb(line_draw_color) / 255, color_get_ab(line_draw_color) / 255]); + data = [line_draw_corner3.x, line_draw_corner3.y, line_draw_corner3.z, color_get_rb(line_draw_color) / 255, color_get_gb(line_draw_color) / 255, color_get_ab(line_draw_color) / 255]; + line_draw_add_vb_data(i, data); + i += 6; - line_draw_add_vb_data(i, [line_draw_corner4.x, line_draw_corner4.y, line_draw_corner4.z, color_get_rb(line_draw_color) / 255, color_get_gb(line_draw_color) / 255, color_get_ab(line_draw_color) / 255]); + data = [line_draw_corner4.x, line_draw_corner4.y, line_draw_corner4.z, color_get_rb(line_draw_color) / 255, color_get_gb(line_draw_color) / 255, color_get_ab(line_draw_color) / 255]; + line_draw_add_vb_data(i, data); i = line_draw_lines * 6; line_draw_ib_data[i ] = line_draw_lines * 4; diff --git a/base/Sources/logic_node.ts b/base/Sources/logic_node.ts index e68bb0e0..bbbfb21a 100644 --- a/base/Sources/logic_node.ts +++ b/base/Sources/logic_node.ts @@ -5,16 +5,20 @@ type logic_node_t = { get?: (self: any, from: i32)=>logic_node_value_t; get_as_image?: (self: any, from: i32)=>image_t; get_cached_image?: (self: any)=>image_t; - set?: (self: any, value: any)=>void; + set?: (self: any, value: f32_array_t)=>void; }; +type logic_node_ext_t = { + base?: logic_node_t; +} + type logic_node_value_t = { _f32?: f32; _any?: any; }; type logic_node_input_t = { - node?: any; // logic_node_t + node?: logic_node_ext_t; from?: i32; // Socket index }; @@ -66,6 +70,6 @@ function logic_node_input_get_as_image(self: logic_node_input_t): image_t { return self.node.base.get_as_image(self.node, self.from); } -function logic_node_input_set(self: logic_node_input_t, value: any) { +function logic_node_input_set(self: logic_node_input_t, value: f32_array_t) { self.node.base.set(self.node, value); } diff --git a/base/Sources/main.ts b/base/Sources/main.ts index b9c9ac17..fdd3b9e3 100644 --- a/base/Sources/main.ts +++ b/base/Sources/main.ts @@ -18,16 +18,18 @@ function main() { ///else - kickstart(); + // kickstart(); + krom_set_app_name(manifest_title); + config_load(main_start); ///end } -function kickstart() { - // Used to locate external application data folder - krom_set_app_name(manifest_title); - config_load(main_start); -} +// function kickstart() { +// // Used to locate external application data folder +// krom_set_app_name(manifest_title); +// config_load(main_start); +// } function main_start() { app_on_resize = base_on_resize; diff --git a/base/Sources/make_voxel.ts b/base/Sources/make_voxel.ts index 41c6fabf..370861c9 100644 --- a/base/Sources/make_voxel.ts +++ b/base/Sources/make_voxel.ts @@ -8,10 +8,20 @@ function make_voxel_run(data: shader_context_t) { let pipe_state: pipeline_t = data._.pipe_state; pipe_state.input_layout = [structure]; + data.vertex_elements = [ - {name: "pos", data: "short4norm"}, - {name: "nor", data: "short2norm"}, - {name: "tex", data: "short2norm"} + { + name: "pos", + data: "short4norm" + }, + { + name: "nor", + data: "short2norm" + }, + { + name: "tex", + data: "short2norm" + } ]; // ///if arm_skin @@ -30,16 +40,29 @@ function make_voxel_run(data: shader_context_t) { g4_pipeline_compile(pipe_state); data.constants = [ - { name: "W", type: "mat4", link: "_world_matrix" }, - { name: "N", type: "mat3", link: "_normal_matrix" } + { + name: "W", + type: "mat4", + link: "_world_matrix" + }, + { + name: "N", + type: "mat3", + link: "_normal_matrix" + } ]; 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 } + { + name: "texpaint_pack" + }, + { + name: "voxels", + image_uniform: true + } ]; data._.tex_units = [ g4_pipeline_get_tex_unit(pipe_state, "texpaint_pack"), diff --git a/base/Sources/nodes/boolean_node.ts b/base/Sources/nodes/boolean_node.ts index e8d14816..371fbfff 100644 --- a/base/Sources/nodes/boolean_node.ts +++ b/base/Sources/nodes/boolean_node.ts @@ -4,12 +4,12 @@ type boolean_node_t = { value?: bool; }; -function boolean_node_create(arg: bool): boolean_node_t { +function boolean_node_create(args: f32_array_t): boolean_node_t { let n: boolean_node_t = {}; n.base = logic_node_create(); n.base.get = boolean_node_get; n.base.set = boolean_node_set; - n.value = arg; + n.value = args[0] > 0.0; return n; } @@ -18,16 +18,18 @@ function boolean_node_get(self: boolean_node_t, from: i32): logic_node_value_t { return logic_node_input_get(self.base.inputs[0]); } else { - let v: logic_node_value_t = { _f32: self.value ? 1.0 : 0.0 }; + let v: logic_node_value_t = { + _f32: self.value ? 1.0 : 0.0 + }; return v; } } -function boolean_node_set(self: boolean_node_t, value: any) { +function boolean_node_set(self: boolean_node_t, value: f32_array_t) { if (self.base.inputs.length > 0) { logic_node_input_set(self.base.inputs[0], value); } else { - self.value = value; + self.value = value[0] > 0.0; } } diff --git a/base/Sources/nodes/color_node.ts b/base/Sources/nodes/color_node.ts index bef77f0b..6b0536bb 100644 --- a/base/Sources/nodes/color_node.ts +++ b/base/Sources/nodes/color_node.ts @@ -5,7 +5,7 @@ type color_node_t = { image?: image_t; }; -function color_node_create(args: any): color_node_t { +function color_node_create(args: f32_array_t): color_node_t { let r: f32 = args == null ? 0.8 : args[0]; let g: f32 = args == null ? 0.8 : args[1]; let b: f32 = args == null ? 0.8 : args[2]; @@ -46,11 +46,14 @@ function color_node_get_as_image(self: color_node_t, from: i32): image_t { return self.image; } -function color_node_set(self: color_node_t, value: any) { +function color_node_set(self: color_node_t, value: f32_array_t) { if (self.base.inputs.length > 0) { logic_node_input_set(self.base.inputs[0], value); } else { - self.value = value; + self.value.x = value[0]; + self.value.y = value[1]; + self.value.z = value[2]; + self.value.w = value[3]; } } diff --git a/base/Sources/nodes/float_node.ts b/base/Sources/nodes/float_node.ts index 2b64a273..2d27bc67 100644 --- a/base/Sources/nodes/float_node.ts +++ b/base/Sources/nodes/float_node.ts @@ -5,13 +5,13 @@ type float_node_t = { image?: image_t; }; -function float_node_create(arg: f32): float_node_t { +function float_node_create(args: f32): float_node_t { let n: float_node_t = {}; n.base = logic_node_create(); n.base.get = float_node_get; n.base.get_as_image = float_node_get_as_image; n.base.set = float_node_set; - n.value = arg; + n.value = args; return n; } @@ -42,12 +42,12 @@ function float_node_get_as_image(self: float_node_t, from: i32): image_t { return self.image; } -function float_node_set(self: float_node_t, value: any) { +function float_node_set(self: float_node_t, value: f32_array_t) { if (self.base.inputs.length > 0) { logic_node_input_set(self.base.inputs[0], value); } else { - self.value = value; + self.value = value[0]; } } diff --git a/base/Sources/nodes/integer_node.ts b/base/Sources/nodes/integer_node.ts index 09bba121..bec2fe77 100644 --- a/base/Sources/nodes/integer_node.ts +++ b/base/Sources/nodes/integer_node.ts @@ -4,12 +4,12 @@ type integer_node_t = { value?: i32; }; -function integer_node_create(arg: i32): integer_node_t { +function integer_node_create(args: f32_array_t): integer_node_t { let n: float_node_t = {}; n.base = logic_node_create(); n.base.get = integer_node_get; n.base.set = integer_node_set; - n.value = arg; + n.value = args[0]; return n; } @@ -23,11 +23,11 @@ function integer_node_get(self: integer_node_t, from: i32): logic_node_value_t { } } -function integer_node_set(self: integer_node_t, value: any) { +function integer_node_set(self: integer_node_t, value: f32_array_t) { if (self.base.inputs.length > 0) { logic_node_input_set(self.base.inputs[0], value); } else { - self.value = value; + self.value = value[0]; } } diff --git a/base/Sources/nodes/math_node.ts b/base/Sources/nodes/math_node.ts index e174736b..f4c67fbb 100644 --- a/base/Sources/nodes/math_node.ts +++ b/base/Sources/nodes/math_node.ts @@ -5,7 +5,7 @@ type math_node_t = { use_clamp?: bool; }; -function math_node_create(arg: any): math_node_t { +function math_node_create(args: f32_array_t): math_node_t { let n: math_node_t = {}; n.base = logic_node_create(); n.base.get = math_node_get; @@ -87,7 +87,7 @@ function math_node_get(self: math_node_t, from: i32): logic_node_value_t { f = v1 > v2 ? 1.0 : 0.0; } else if (op == "Modulo") { - f = v1 % v2; + f = math_fmod(v1, v2); } else if (op == "Snap") { f = math_floor(v1 / v2) * v2; @@ -105,7 +105,7 @@ function math_node_get(self: math_node_t, from: i32): logic_node_value_t { f = v1 > 0 ? 1.0 : (v1 < 0 ? -1.0 : 0); } else if (op == "Ping-Pong") { - f = (v2 != 0.0) ? v2 - math_abs((math_abs(v1) % (2 * v2)) - v2) : 0.0; + f = (v2 != 0.0) ? v2 - math_abs(math_fmod(math_abs(v1), (2 * v2)) - v2) : 0.0; } else if (op == "Hyperbolic Sine") { f = (math_exp(v1) - math_exp(-v1)) / 2.0; @@ -127,7 +127,9 @@ function math_node_get(self: math_node_t, from: i32): logic_node_value_t { f = f < 0.0 ? 0.0 : (f > 1.0 ? 1.0 : f); } - let v: logic_node_value_t = { _f32: f }; + let v: logic_node_value_t = { + _f32: f + }; return v; } diff --git a/base/Sources/nodes/null_node.ts b/base/Sources/nodes/null_node.ts index 1f6efdce..741d2dd8 100644 --- a/base/Sources/nodes/null_node.ts +++ b/base/Sources/nodes/null_node.ts @@ -3,7 +3,7 @@ type null_node_t = { base?: logic_node_t; }; -function null_node_create(arg: any): null_node_t { +function null_node_create(args: f32_array_t): null_node_t { let n: null_node_t = {}; n.base = logic_node_create(); n.base.get = float_node_get; diff --git a/base/Sources/nodes/random_node.ts b/base/Sources/nodes/random_node.ts index ac09630a..51ac85fc 100644 --- a/base/Sources/nodes/random_node.ts +++ b/base/Sources/nodes/random_node.ts @@ -8,7 +8,7 @@ let random_node_b: i32; let random_node_c: i32; let random_node_d: i32 = -1; -function random_node_create(arg: any): random_node_t { +function random_node_create(args: f32_array_t): random_node_t { let n: random_node_t = {}; n.base = logic_node_create(); n.base.get = random_node_get; @@ -30,9 +30,9 @@ function random_node_get_int(): i32 { // Courtesy of https://github.com/Kode/Kha/blob/main/Sources/kha/math/Random.hx let t: i32 = (random_node_a + random_node_b | 0) + random_node_d | 0; random_node_d = random_node_d + 1 | 0; - random_node_a = random_node_b ^ random_node_b >>> 9; + random_node_a = random_node_b ^ (u32)random_node_b >> 9; random_node_b = random_node_c + (random_node_c << 3) | 0; - random_node_c = random_node_c << 21 | random_node_c >>> 11; + random_node_c = random_node_c << 21 | (u32)random_node_c >> 11; random_node_c = random_node_c + t | 0; return t & 0x7fffffff; } diff --git a/base/Sources/nodes/separate_vector_node.ts b/base/Sources/nodes/separate_vector_node.ts index 7c878d5c..6676b788 100644 --- a/base/Sources/nodes/separate_vector_node.ts +++ b/base/Sources/nodes/separate_vector_node.ts @@ -3,7 +3,7 @@ type separate_vector_node_t = { base?: logic_node_t; }; -function separate_vector_node_create(arg: any): separate_vector_node_t { +function separate_vector_node_create(args: f32_array_t): separate_vector_node_t { let n: separate_vector_node_t = {}; n.base = logic_node_create(); n.base.get = separate_vector_node_get; diff --git a/base/Sources/nodes/time_node.ts b/base/Sources/nodes/time_node.ts index 3b38c41f..31195e17 100644 --- a/base/Sources/nodes/time_node.ts +++ b/base/Sources/nodes/time_node.ts @@ -3,7 +3,7 @@ type time_node_t = { base?: logic_node_t; }; -function time_node_create(arg: any): time_node_t { +function time_node_create(args: f32_array_t): time_node_t { let n: time_node_t = {}; n.base = logic_node_create(); n.base.get = time_node_get; diff --git a/base/Sources/nodes/vector_math_node.ts b/base/Sources/nodes/vector_math_node.ts index b9c0ff0f..3be975d7 100644 --- a/base/Sources/nodes/vector_math_node.ts +++ b/base/Sources/nodes/vector_math_node.ts @@ -5,7 +5,7 @@ type vector_math_node_t = { v?: vec4_t; }; -function vector_math_node_create(arg: any): vector_math_node_t { +function vector_math_node_create(args: f32_array_t): vector_math_node_t { let n: vector_math_node_t = {}; n.base = logic_node_create(); n.base.get = vector_math_node_get; @@ -39,7 +39,7 @@ function vector_math_node_get(self: vector_math_node_t, from: i32): logic_node_v vec4_cross(self.v, v2); } else if (op == "Normalize") { - vec4_normalize(self.v, ); + vec4_normalize(self.v); } else if (op == "Multiply") { self.v.x *= v2.x; @@ -105,9 +105,9 @@ function vector_math_node_get(self: vector_math_node_t, from: i32): logic_node_v self.v.z = v1.z - math_floor(v1.z); } else if (op == "Modulo") { - self.v.x = v1.x % v2.x; - self.v.y = v1.y % v2.y; - self.v.z = v1.z % v2.z; + self.v.x = math_fmod(v1.x, v2.x); + self.v.y = math_fmod(v1.y, v2.y); + self.v.z = math_fmod(v1.z, v2.z); } else if (op == "Snap") { self.v.x = math_floor(v1.x / v2.x) * v2.x; diff --git a/base/Sources/nodes/vector_node.ts b/base/Sources/nodes/vector_node.ts index 183d90fe..0452ba56 100644 --- a/base/Sources/nodes/vector_node.ts +++ b/base/Sources/nodes/vector_node.ts @@ -5,7 +5,7 @@ type vector_node_t = { image?: image_t; }; -function vector_node_create(args: any): vector_node_t { +function vector_node_create(args: f32_array_t): vector_node_t { let n: vector_node_t = {}; n.base = logic_node_create(); n.base.get = vector_node_get; @@ -42,18 +42,21 @@ function vector_node_get_as_image(self: vector_node_t, from: i32): image_t { } let b: buffer_t = buffer_create(16); let v: buffer_view_t = buffer_view_create(b); - buffer_view_set_f32(v, 0, self.base.inputs[0].node.value); - buffer_view_set_f32(v, 4, self.base.inputs[1].node.value); - buffer_view_set_f32(v, 8, self.base.inputs[2].node.value); + let n0: float_node_t = self.base.inputs[0].node; + let n1: float_node_t = self.base.inputs[1].node; + let n2: float_node_t = self.base.inputs[2].node; + buffer_view_set_f32(v, 0, n0.value); + buffer_view_set_f32(v, 4, n1.value); + buffer_view_set_f32(v, 8, n2.value); buffer_view_set_f32(v, 12, 1.0); self.image = image_from_bytes(b, 1, 1, tex_format_t.RGBA128); return self.image; } -function vector_node_set(self: vector_node_t, value: any) { - logic_node_input_set(self.base.inputs[0], value.x); - logic_node_input_set(self.base.inputs[1], value.y); - logic_node_input_set(self.base.inputs[2], value.z); +function vector_node_set(self: vector_node_t, value: f32_array_t) { + logic_node_input_set(self.base.inputs[0], f32_array_create_x(value[0])); + logic_node_input_set(self.base.inputs[1], f32_array_create_x(value[1])); + logic_node_input_set(self.base.inputs[2], f32_array_create_x(value[2])); } let vector_node_def: zui_node_t = { diff --git a/base/Sources/nodes_material.ts b/base/Sources/nodes_material.ts index 546a6adf..d72d6322 100644 --- a/base/Sources/nodes_material.ts +++ b/base/Sources/nodes_material.ts @@ -3867,7 +3867,7 @@ function nodes_material_vector_curves_button(ui: zui_t, nodes: zui_nodes_t, node } if (zui_button("-")) { if (val.length > 2) { - val.pop(); + array_pop(val); } } let ihandle: zui_handle_t = zui_nest(zui_nest(zui_nest(nhandle, 0), 2), axis); @@ -3926,7 +3926,7 @@ function nodes_material_color_ramp_button(ui: zui_t, nodes: zui_nodes_t, node: z ihandle.value += 1; } if (zui_button("-") && vals.length > 1) { - vals.pop(); + array_pop(vals); ihandle.value -= 1; } @@ -3955,7 +3955,7 @@ function nodes_material_color_ramp_button(ui: zui_t, nodes: zui_nodes_t, node: z let rx: f32 = nx + ui._w - zui_nodes_p(37); let ry: f32 = ny - zui_nodes_p(5); nodes._input_started = ui.input_started = false; - zui_nodes_rgba_popup(ui, chandle, val, math_floor(rx), math_floor(ry + zui_ELEMENT_H(ui))); + zui_nodes_rgba_popup(chandle, val, math_floor(rx), math_floor(ry + zui_ELEMENT_H(ui))); } val[0] = color_get_rb(chandle.color) / 255; val[1] = color_get_gb(chandle.color) / 255; @@ -3980,8 +3980,6 @@ function nodes_material_new_group_button(ui: zui_t, nodes: zui_nodes_t, node: zu } } - array_push(zui_node_replace, node); - let canvas: zui_node_canvas_t = { name: node.name, nodes: [ @@ -4022,7 +4020,11 @@ function nodes_material_new_group_button(ui: zui_t, nodes: zui_nodes_t, node: zu ], links: [] }; - array_push(project_material_groups, { canvas: canvas, nodes: zui_nodes_create() }); + let ng: node_group_t = { + canvas: canvas, + nodes: zui_nodes_create() + }; + array_push(project_material_groups, ng); } let group: node_group_t = null; @@ -4090,7 +4092,6 @@ function nodes_material_sync_sockets(node: zui_node_t) { let g: node_group_t = project_material_groups[i]; nodes_material_sync_group_sockets(g.canvas, c.name, node); } - array_push(zui_node_replace, node); } function nodes_material_sync_group_sockets(canvas: zui_node_canvas_t, group_name: string, node: zui_node_t) { @@ -4100,7 +4101,12 @@ function nodes_material_sync_group_sockets(canvas: zui_node_canvas_t, group_name let is_inputs: bool = node.name == "Group Input"; let old_sockets: zui_node_socket_t[] = is_inputs ? n.inputs : n.outputs; let sockets: zui_node_socket_t[] = json_parse(json_stringify(is_inputs ? node.outputs : node.inputs)); - is_inputs ? n.inputs = sockets : n.outputs = sockets; + if (is_inputs) { + n.inputs = sockets; + } + else { + n.outputs = sockets; + } for (let i: i32 = 0; i < sockets.length; ++i) { let s: zui_node_socket_t = sockets[i]; s.node_id = n.id; @@ -4119,17 +4125,17 @@ function nodes_material_get_socket_color(type: string): i32 { return type == "RGBA" ? 0xffc7c729 : type == "VECTOR" ? 0xff6363c7 : 0xffa1a1a1; } -function nodes_material_get_socket_default_value(type: string): any { - return type == "RGBA" ? f32_array_create_xyzw(0.8, 0.8, 0.8, 1.0) : type == "VECTOR" ? f32_array_create_xyz(0.0, 0.0, 0.0) : 0.0; +function nodes_material_get_socket_default_value(type: string): f32_array_t { + return type == "RGBA" ? f32_array_create_xyzw(0.8, 0.8, 0.8, 1.0) : type == "VECTOR" ? f32_array_create_xyz(0.0, 0.0, 0.0) : f32_array_create_x(0.0); } function nodes_material_get_socket_name(type: string): string { return type == "RGBA" ? _tr("Color") : type == "VECTOR" ? _tr("Vector") : _tr("Value"); } -function nodes_material_create_socket(nodes: zui_nodes_t, node: zui_node_t, name: string, type: string, canvas: zui_node_canvas_t, min = 0.0, max = 1.0, default_value: any = null): zui_node_socket_t { - return { - id: zui_get_socket_id(canvas.nodes), +function nodes_material_create_socket(nodes: zui_nodes_t, node: zui_node_t, name: string, type: string, canvas: zui_node_canvas_t, min: f32 = 0.0, max: f32 = 1.0, default_value: any = null): zui_node_socket_t { + let soc: zui_node_socket_t = { + id: zui_get_socket_id(canvas.nodes.buffer, canvas.nodes.length), node_id: node.id, name: name == null ? nodes_material_get_socket_name(type) : name, type: type, @@ -4137,7 +4143,8 @@ function nodes_material_create_socket(nodes: zui_nodes_t, node: zui_node_t, name default_value: default_value == null ? nodes_material_get_socket_default_value(type) : default_value, min: min, max: max - } + }; + return soc; } function nodes_material_get_node_t(node_type: string): zui_node_t { diff --git a/base/Sources/operator.ts b/base/Sources/operator.ts index 33924837..3e48a321 100644 --- a/base/Sources/operator.ts +++ b/base/Sources/operator.ts @@ -1,13 +1,15 @@ -let operator_ops: map_t = map_create(); -function operator_register(name: string, call: any) { +let operator_ops: map_tvoid> = map_create(); + +function operator_register(name: string, call: ()=>void) { map_set(operator_ops, name, call); } function operator_run(name: string) { if (map_get(operator_ops, name) != null) { - map_get(operator_ops, name)(); + let cb: ()=>void = map_get(operator_ops, name); + cb(); } } diff --git a/base/Sources/parser_blend.ts b/base/Sources/parser_blend.ts index 5bea8a95..46509c6d 100644 --- a/base/Sources/parser_blend.ts +++ b/base/Sources/parser_blend.ts @@ -18,7 +18,7 @@ type blend_t = { // Data blocks?: block_t[]; dna?: dna_t; - map?: map_t; // Map blocks by memory address + map?: map_t; // Map blocks by memory address }; function parser_blend_init(buffer: buffer_t): blend_t { @@ -67,7 +67,8 @@ function parser_blend_get(raw: blend_t, type: string): bl_handle_t[] { let handles: bl_handle_t[] = []; for (let i: i32 = 0; i < raw.blocks.length; ++i) { let b: block_t = raw.blocks[i]; - if (raw.dna.structs[b.sdna_index].type == type_index) { + let stype: i32 = raw.dna.structs[b.sdna_index].type; + if (stype == type_index) { let h: bl_handle_t = {}; h.offset = 0; array_push(handles, h); @@ -125,10 +126,10 @@ function parser_blend_parse(raw: blend_t) { b.size = parser_blend_read_i32(raw); // Memory address - let addr: any = parser_blend_read_pointer(raw); - if (map_get(raw.map, addr) == null) { - map_set(raw.map, addr, b); - } + let addr: i64 = parser_blend_read_pointer(raw); + // if (map_get(raw.map, addr) == null) { //// + // map_set(raw.map, addr, b); //// + // } //// // Index of dna struct contained in this block b.sdna_index = parser_blend_read_i32(raw); @@ -217,9 +218,8 @@ function parser_blend_read_i32(raw: blend_t): i32 { return i; } -function parser_blend_read_i64(raw: blend_t): any { - let aview: any = raw.view; - let i: i32 = aview.getBigInt64(raw.pos, raw.little_endian); +function parser_blend_read_i64(raw: blend_t): i64 { + let i: i32 = buffer_view_get_i64(raw.view, raw.pos); //, raw.little_endian raw.pos += 8; return i; } @@ -286,7 +286,7 @@ function parser_blend_read_char(raw: blend_t): string { return string_from_char_code(parser_blend_read_i8(raw)); } -function parser_blend_read_pointer(raw: blend_t): any { +function parser_blend_read_pointer(raw: blend_t): i64 { return raw.pointer_size == 4 ? parser_blend_read_i32(raw) : parser_blend_read_i64(raw); } @@ -379,44 +379,46 @@ function bl_handle_get(raw: bl_handle_t, name: string, index: i32 = 0, as_type: blend.pos = raw.block.pos + new_offset; let is_array: bool = char_at(dna_name, dna_name.length - 1) == "]"; let len: i32 = is_array ? (array_len > 0 ? array_len : bl_handle_get_array_len(dna_name)) : 1; - if (type == "int") { - return is_array ? parser_blend_read_i32array(blend, len) : parser_blend_read_i32(blend); - } - else if (type == "char") { - return is_array ? parser_blend_read_string(blend) : parser_blend_read_i8(blend); - } - else if (type == "uchar") { - return is_array ? parser_blend_read_i8array(blend, len) : parser_blend_read_i8(blend); - } - else if (type == "short") { - return is_array ? parser_blend_read_i16array(blend, len) : parser_blend_read_i16(blend); - } - else if (type == "ushort") { - return is_array ? parser_blend_read_i16array(blend, len) : parser_blend_read_i16(blend); - } - else if (type == "float") { - return is_array ? parser_blend_read_f32array(blend, len) : parser_blend_read_f32(blend); - } - else if (type == "double") { - return 0; //readf64(blend); - } - else if (type == "long") { - return is_array ? parser_blend_read_i32array(blend, len) : parser_blend_read_i32(blend); - } - else if (type == "ulong") { - return is_array ? parser_blend_read_i32array(blend, len) : parser_blend_read_i32(blend); - } - else if (type == "int64_t") { - return parser_blend_read_i64(blend); - } - else if (type == "uint64_t") { - return parser_blend_read_i64(blend); - } - else if (type == "void") { - if (char_at(dna_name, 0) == "*") { - return parser_blend_read_i64(blend); - } - } + //// + // if (type == "int") { + // return is_array ? parser_blend_read_i32array(blend, len) : parser_blend_read_i32(blend); + // } + // else if (type == "char") { + // return is_array ? parser_blend_read_string(blend) : parser_blend_read_i8(blend); + // } + // else if (type == "uchar") { + // return is_array ? parser_blend_read_i8array(blend, len) : parser_blend_read_i8(blend); + // } + // else if (type == "short") { + // return is_array ? parser_blend_read_i16array(blend, len) : parser_blend_read_i16(blend); + // } + // else if (type == "ushort") { + // return is_array ? parser_blend_read_i16array(blend, len) : parser_blend_read_i16(blend); + // } + // else if (type == "float") { + // return is_array ? parser_blend_read_f32array(blend, len) : parser_blend_read_f32(blend); + // } + // else if (type == "double") { + // return 0; //readf64(blend); + // } + // else if (type == "long") { + // return is_array ? parser_blend_read_i32array(blend, len) : parser_blend_read_i32(blend); + // } + // else if (type == "ulong") { + // return is_array ? parser_blend_read_i32array(blend, len) : parser_blend_read_i32(blend); + // } + // else if (type == "int64_t") { + // return parser_blend_read_i64(blend); + // } + // else if (type == "uint64_t") { + // return parser_blend_read_i64(blend); + // } + // else if (type == "void") { + // if (char_at(dna_name, 0) == "*") { + // return parser_blend_read_i64(blend); + // } + // } + //// } // Structure let h: bl_handle_t = {}; @@ -425,11 +427,15 @@ function bl_handle_get(raw: bl_handle_t, name: string, index: i32 = 0, as_type: let is_pointer: bool = char_at(dna_name, 0) == "*"; if (is_pointer) { raw.block.blend.pos = raw.block.pos + new_offset; - let addr: any = parser_blend_read_pointer(raw.block.blend); - if (map_get(raw.block.blend.map, addr) != null) { - h.block = map_get(raw.block.blend.map, addr); - } - else h.block = raw.block; + let addr: i64 = parser_blend_read_pointer(raw.block.blend); + //// + // if (map_get(raw.block.blend.map, addr) != null) { + // h.block = map_get(raw.block.blend.map, addr); + // } + // else { + // h.block = raw.block; + // } + //// h.offset = 0; } else { diff --git a/base/Sources/parser_logic.ts b/base/Sources/parser_logic.ts index 8f391f9b..f91d1e09 100644 --- a/base/Sources/parser_logic.ts +++ b/base/Sources/parser_logic.ts @@ -106,7 +106,7 @@ function parser_logic_build_node(node: zui_node_t): string { array_push(parser_logic_parsed_nodes, name); // Create node - let v: any = parser_logic_create_node_instance(node.type, null); + let v: logic_node_ext_t = parser_logic_create_node_instance(node.type, null); map_set(parser_logic_node_map, name, v); map_set(parser_logic_raw_map, v, node); @@ -226,17 +226,20 @@ function parser_logic_build_default_node(inp: zui_node_socket_t): logic_node_t { return v; } -function parser_logic_create_node_instance(node_type: string, args: any): any { +function parser_logic_create_node_instance(node_type: string, args: f32_array_t): logic_node_ext_t { if (map_get(parser_logic_custom_nodes, node_type) != null) { let node: logic_node_t = logic_node_create(); node.get = map_get(parser_logic_custom_nodes, node_type); - return node; + let ext: logic_node_ext_t = { + base: node + }; + return ext; } if (nodes_brush_creates == null) { nodes_brush_init(); } - let create: any = map_get(nodes_brush_creates, node_type); + let create: (args: f32_array_t)=>logic_node_ext_t = map_get(nodes_brush_creates, node_type); return create(args); } diff --git a/base/Sources/parser_material.ts b/base/Sources/parser_material.ts index 6ec95aba..ca73d4d2 100644 --- a/base/Sources/parser_material.ts +++ b/base/Sources/parser_material.ts @@ -31,7 +31,7 @@ let parser_material_cotangent_frame_written: bool; let parser_material_tex_coord: string = "texCoord"; let parser_material_eps: f32 = 0.000001; -let parser_material_custom_nodes: map_t = map_create(); +let parser_material_custom_nodes: map_tstring> = map_create(); let parser_material_parse_surface: bool = true; let parser_material_parse_opacity: bool = true; let parser_material_parse_height: bool = false; @@ -144,9 +144,15 @@ function parser_material_parse(canvas: zui_node_canvas_t, _con: node_shader_cont } if (parser_material_start_node != null) { - let link: zui_node_link_t = { id: 99999, from_id: parser_material_start_node.id, from_socket: 0, to_id: -1, to_socket: -1 }; + let link: zui_node_link_t = { + id: 99999, + from_id: parser_material_start_node.id, + from_socket: 0, + to_id: -1, + to_socket: -1 + }; parser_material_write_result(link); - return { + let sout: shader_out_t = { out_basecol: "vec3(0.0, 0.0, 0.0)", out_roughness: "0.0", out_metallic: "0.0", @@ -155,7 +161,8 @@ function parser_material_parse(canvas: zui_node_canvas_t, _con: node_shader_cont out_height: "0.0", out_emission: "0.0", out_subsurface: "0.0" - } + }; + return sout; } let output_node: zui_node_t = parser_material_node_by_type(parser_material_nodes, "OUTPUT_MATERIAL"); @@ -301,7 +308,7 @@ function parser_material_push_group(g: zui_node_canvas_t) { } function parser_material_pop_group() { - parser_material_canvases.pop(); + array_pop(parser_material_canvases); let g: zui_node_canvas_t = parser_material_canvases[parser_material_canvases.length - 1]; parser_material_nodes = g.nodes; parser_material_links = g.links; @@ -317,13 +324,13 @@ function parser_material_parse_group(node: zui_node_t, socket: zui_node_socket_t let index: i32 = parser_material_socket_index(node, socket); let inp: zui_node_socket_t = output_node.inputs[index]; let out_group: string = parser_material_parse_input(inp); - parser_material_parents.pop(); + array_pop(parser_material_parents); parser_material_pop_group(); return out_group; } function parser_material_parse_group_input(node: zui_node_t, socket: zui_node_socket_t): string { - let parent: zui_node_t = parser_material_parents.pop(); // Leaving group + let parent: zui_node_t = array_pop(parser_material_parents); // Leaving group parser_material_pop_group(); let index: i32 = parser_material_socket_index(node, socket); let inp: zui_node_socket_t = parent.inputs[index]; @@ -359,7 +366,7 @@ function parser_material_parse_shader_input(inp: zui_node_socket_t): shader_out_ return parser_material_parse_shader(from_node, from_node.outputs[l.from_socket]); } else { - return { + let sout: shader_out_t = { out_basecol: "vec3(0.8, 0.8, 0.8)", out_roughness: "0.0", out_metallic: "0.0", @@ -369,6 +376,7 @@ function parser_material_parse_shader_input(inp: zui_node_socket_t): shader_out_ out_emission: "0.0", out_subsurface: "0.0" }; + return sout; } } @@ -382,7 +390,7 @@ function parser_material_parse_shader(node: zui_node_t, socket: zui_node_socket_ out_height: "0.0", out_emission: "0.0", out_subsurface: "0.0" - } + }; if (node.type == "OUTPUT_MATERIAL_PBR") { if (parser_material_parse_surface) { @@ -560,7 +568,8 @@ function parser_material_parse_vector(node: zui_node_t, socket: zui_node_socket_ coloring = string_replace_all(coloring, " ", "_"); let res: string = ""; if (coloring == "INTENSITY") { - res = parser_material_to_vec3("tex_voronoi(" + co + " * " + scale + ", texturePass(snoise256)).a"); + let voronoi: string = "tex_voronoi(" + co + " * " + scale + ", texturePass(snoise256)).a"; + res = parser_material_to_vec3(voronoi); } else { // Cells res = "tex_voronoi(" + co + " * " + scale + ", texturePass(snoise256)).rgb"; @@ -595,7 +604,8 @@ function parser_material_parse_vector(node: zui_node_t, socket: zui_node_socket_ let tex_name: string = "texwarp_" + parser_material_node_name(node); node_shader_add_uniform(parser_material_curshader, "sampler2D " + tex_name, "_" + tex_name); let store: string = parser_material_store_var_name(node); - node_shader_write(parser_material_curshader, "float " + store + "_rad = " + angle + " * (" + math_pi() + " / 180);"); + let pi: f32 = math_pi(); + node_shader_write(parser_material_curshader, "float " + store + "_rad = " + angle + " * (" + pi + " / 180);"); node_shader_write(parser_material_curshader, "float " + store + "_x = cos(" + store + "_rad);"); node_shader_write(parser_material_curshader, "float " + store + "_y = sin(" + store + "_rad);"); return "texture(" + tex_name + ", texCoord + vec2(" + store + "_x, " + store + "_y) * " + mask + ").rgb;"; @@ -662,7 +672,8 @@ function parser_material_parse_vector(node: zui_node_t, socket: zui_node_socket_ out_col = "max(" + col1 + ", " + col2 + " * " + fac_var + ")"; } else if (blend == "SCREEN") { - out_col = "(vec3(1.0, 1.0, 1.0) - (" + parser_material_to_vec3("1.0 - " + fac_var + "") + " + " + fac_var + " * (vec3(1.0, 1.0, 1.0) - " + col2 + ")) * (vec3(1.0, 1.0, 1.0) - " + col1 + "))"; + let v3: string = parser_material_to_vec3("1.0 - " + fac_var + ""); + out_col = "(vec3(1.0, 1.0, 1.0) - (" + v3 + " + " + fac_var + " * (vec3(1.0, 1.0, 1.0) - " + col2 + ")) * (vec3(1.0, 1.0, 1.0) - " + col1 + "))"; } else if (blend == "DODGE") { out_col = "mix(" + col1 + ", " + col1 + " / (vec3(1.0, 1.0, 1.0) - " + col2 + "), " + fac_var + ")"; @@ -692,7 +703,8 @@ function parser_material_parse_vector(node: zui_node_t, socket: zui_node_socket_ else if (blend == "DIVIDE") { let eps: f32 = 0.000001; col2 = "max(" + col2 + ", vec3(" + eps + ", " + eps + ", " + eps + "))"; - out_col = "(" + parser_material_to_vec3("(1.0 - " + fac_var + ") * " + col1 + " + " + fac_var + " * " + col1 + " / " + col2) + ")"; + let v3: string = parser_material_to_vec3("(1.0 - " + fac_var + ") * " + col1 + " + " + fac_var + " * " + col1 + " / " + col2); + out_col = "(" + v3 + ")"; } else if (blend == "HUE") { node_shader_add_function(parser_material_curshader, str_hue_sat); @@ -723,67 +735,70 @@ function parser_material_parse_vector(node: zui_node_t, socket: zui_node_socket_ return "(floor(100.0 * " + strength + " * " + col + ") / (100.0 * " + strength + "))"; } else if (node.type == "VALTORGB") { // ColorRamp - let fac: string = parser_material_parse_value_input(node.inputs[0]); - let interp: string = node.buttons[0].data[0] == 0 ? "LINEAR" : "CONSTANT"; - let elems: f32[][] = null; //node.buttons[0].default_value; - if (elems.length == 1) { - // return parser_material_vec3(elems[0]); - } - // Write cols array - let cols_var: string = parser_material_node_name(node) + "_cols"; - node_shader_write(parser_material_curshader, "vec3 " + cols_var + "[" + elems.length + "];"); // TODO: Make const - for (let i: i32 = 0; i < elems.length; ++i) { - // node_shader_write(parser_material_curshader, cols_var + "[" + i + "] = " + parser_material_vec3(elems[i]) + ";"); - } - // Get index - let fac_var: string = parser_material_node_name(node) + "_fac"; - node_shader_write(parser_material_curshader, "float " + fac_var + " = " + fac + ";"); - let index: string = "0"; - for (let i: i32 = 1; i < elems.length; ++i) { - index += " + (" + fac_var + " > " + elems[i][4] + " ? 1 : 0)"; - } - // Write index - let index_var: string = parser_material_node_name(node) + "_i"; - node_shader_write(parser_material_curshader, "int " + index_var + " = " + index + ";"); - if (interp == "CONSTANT") { - return "" + cols_var + "[" + index_var + "]"; - } - else { // Linear - // Write facs array - let facs_var: string = parser_material_node_name(node) + "_facs"; - node_shader_write(parser_material_curshader, "float " + facs_var + "[" + elems + "length}];"); // TODO: Make const - for (let i: i32 = 0; i < elems.length; ++i) { - node_shader_write(parser_material_curshader, facs_var + "[" + i + "] = " + elems[i][4] + ";"); - } - // Mix color - // float f = (pos - start) * (1.0 / (finish - start)) - return "mix(" + cols_var + "[" + index_var + "], " + cols_var + "[" + index_var + " + 1], (" + fac_var + " - " + facs_var + "[" + index_var + "]) * (1.0 / (" + facs_var + "[" + index_var + " + 1] - " + facs_var + "[" + index_var + "]) ))"; - } + // let fac: string = parser_material_parse_value_input(node.inputs[0]); + // let data0: i32 = node.buttons[0].data[0]; + // let interp: string = data0 == 0 ? "LINEAR" : "CONSTANT"; + // // let elems: f32[][] = null; //node.buttons[0].default_value; + // let elems: f32[] = null; //node.buttons[0].default_value; + // if (elems.length == 1) { + // // return parser_material_vec3(elems[0]); + // } + // // Write cols array + // let cols_var: string = parser_material_node_name(node) + "_cols"; + // let len: i32 = elems.length; + // node_shader_write(parser_material_curshader, "vec3 " + cols_var + "[" + len + "];"); // TODO: Make const + // for (let i: i32 = 0; i < elems.length; ++i) { + // // node_shader_write(parser_material_curshader, cols_var + "[" + i + "] = " + parser_material_vec3(elems[i]) + ";"); + // } + // // Get index + // let fac_var: string = parser_material_node_name(node) + "_fac"; + // node_shader_write(parser_material_curshader, "float " + fac_var + " = " + fac + ";"); + // let index: string = "0"; + // for (let i: i32 = 1; i < elems.length; ++i) { + // index += " + (" + fac_var + " > " + elems[i][4] + " ? 1 : 0)"; + // } + // // Write index + // let index_var: string = parser_material_node_name(node) + "_i"; + // node_shader_write(parser_material_curshader, "int " + index_var + " = " + index + ";"); + // if (interp == "CONSTANT") { + // return "" + cols_var + "[" + index_var + "]"; + // } + // else { // Linear + // // Write facs array + // let facs_var: string = parser_material_node_name(node) + "_facs"; + // node_shader_write(parser_material_curshader, "float " + facs_var + "[" + elems + "length}];"); // TODO: Make const + // for (let i: i32 = 0; i < elems.length; ++i) { + // node_shader_write(parser_material_curshader, facs_var + "[" + i + "] = " + elems[i][4] + ";"); + // } + // // Mix color + // // float f = (pos - start) * (1.0 / (finish - start)) + // return "mix(" + cols_var + "[" + index_var + "], " + cols_var + "[" + index_var + " + 1], (" + fac_var + " - " + facs_var + "[" + index_var + "]) * (1.0 / (" + facs_var + "[" + index_var + " + 1] - " + facs_var + "[" + index_var + "]) ))"; + // } } else if (node.type == "CURVE_VEC") { - let fac: string = parser_material_parse_value_input(node.inputs[0]); - let vec: string = parser_material_parse_vector_input(node.inputs[1]); - let curves: any = node.buttons[0].default_value; - let name: string = parser_material_node_name(node); - let vc0: string = parser_material_vector_curve(name + "0", vec + ".x", curves[0]); - let vc1: string = parser_material_vector_curve(name + "1", vec + ".y", curves[1]); - let vc2: string = parser_material_vector_curve(name + "2", vec + ".z", curves[2]); - // mapping.curves[0].points[0].handle_type // bezier curve - return "(vec3(" + vc0 + ", " + vc1 + ", " + vc2 + ") * " + fac + ")"; + // let fac: string = parser_material_parse_value_input(node.inputs[0]); + // let vec: string = parser_material_parse_vector_input(node.inputs[1]); + // let curves: f32_array_t = node.buttons[0].default_value; + // let name: string = parser_material_node_name(node); + // let vc0: string = parser_material_vector_curve(name + "0", vec + ".x", curves[0]); + // let vc1: string = parser_material_vector_curve(name + "1", vec + ".y", curves[1]); + // let vc2: string = parser_material_vector_curve(name + "2", vec + ".z", curves[2]); + // // mapping.curves[0].points[0].handle_type // bezier curve + // return "(vec3(" + vc0 + ", " + vc1 + ", " + vc2 + ") * " + fac + ")"; } else if (node.type == "CURVE_RGB") { // RGB Curves - let fac: string = parser_material_parse_value_input(node.inputs[0]); - let vec: string = parser_material_parse_vector_input(node.inputs[1]); - let curves: any = node.buttons[0].default_value; - let name: string = parser_material_node_name(node); - // mapping.curves[0].points[0].handle_type - let vc0: string = parser_material_vector_curve(name + "0", vec + ".x", curves[0]); - let vc1: string = parser_material_vector_curve(name + "1", vec + ".y", curves[1]); - let vc2: string = parser_material_vector_curve(name + "2", vec + ".z", curves[2]); - let vc3a: string = parser_material_vector_curve(name + "3a", vec + ".x", curves[3]); - let vc3b: string = parser_material_vector_curve(name + "3b", vec + ".y", curves[3]); - let vc3c: string = parser_material_vector_curve(name + "3c", vec + ".z", curves[3]); - return "(sqrt(vec3(" + vc0 + ", " + vc1 + ", " + vc2 + ") * vec3(" + vc3a + ", " + vc3b + ", " + vc3c + ")) * " + fac + ")"; + // let fac: string = parser_material_parse_value_input(node.inputs[0]); + // let vec: string = parser_material_parse_vector_input(node.inputs[1]); + // let curves: any = node.buttons[0].default_value; + // let name: string = parser_material_node_name(node); + // // mapping.curves[0].points[0].handle_type + // let vc0: string = parser_material_vector_curve(name + "0", vec + ".x", curves[0]); + // let vc1: string = parser_material_vector_curve(name + "1", vec + ".y", curves[1]); + // let vc2: string = parser_material_vector_curve(name + "2", vec + ".z", curves[2]); + // let vc3a: string = parser_material_vector_curve(name + "3a", vec + ".x", curves[3]); + // let vc3b: string = parser_material_vector_curve(name + "3b", vec + ".y", curves[3]); + // let vc3c: string = parser_material_vector_curve(name + "3c", vec + ".z", curves[3]); + // return "(sqrt(vec3(" + vc0 + ", " + vc1 + ", " + vc2 + ") * vec3(" + vc3a + ", " + vc3b + ", " + vc3c + ")) * " + fac + ")"; } else if (node.type == "COMBHSV") { node_shader_add_function(parser_material_curshader, str_hue_sat); @@ -821,7 +836,7 @@ function parser_material_parse_vector(node: zui_node_t, socket: zui_node_socket_ } else if (node.type == "MATERIAL") { let result: string = "vec3(0.0, 0.0, 0.0)"; - let mi: any = node.buttons[0].default_value; + let mi: i32 = node.buttons[0].default_value[0]; if (mi >= project_materials.length) { return result; } @@ -840,7 +855,7 @@ function parser_material_parse_vector(node: zui_node_t, socket: zui_node_socket_ } parser_material_nodes = _nodes; parser_material_links = _links; - parser_material_parents.pop(); + array_pop(parser_material_parents); return result; } else if (node.type == "PICKER") { @@ -1120,7 +1135,8 @@ function parser_material_parse_vector(node: zui_node_t, socket: zui_node_socket_ return parser_material_to_vec3(height); } else if (map_get(parser_material_custom_nodes, node.type) != null) { - return map_get(parser_material_custom_nodes, node.type)(node, socket); + let cb: (n: zui_node_t, s: zui_node_socket_t)=>string = map_get(parser_material_custom_nodes, node.type); + return cb(node, socket); } return "vec3(0.0, 0.0, 0.0)"; } @@ -1242,7 +1258,7 @@ function parser_material_parse_value(node: zui_node_t, socket: zui_node_socket_t } else if (node.type == "MATERIAL") { let result: string = "0.0"; - let mi: any = node.buttons[0].default_value; + let mi: i32 = node.buttons[0].default_value[0]; if (mi >= project_materials.length) return result; let m: slot_material_t = project_materials[mi]; let _nodes: zui_node_t[] = parser_material_nodes; @@ -1268,7 +1284,7 @@ function parser_material_parse_value(node: zui_node_t, socket: zui_node_socket_t } parser_material_nodes = _nodes; parser_material_links = _links; - parser_material_parents.pop(); + array_pop(parser_material_parents); return result; } else if (node.type == "PICKER") { @@ -1689,7 +1705,8 @@ function parser_material_parse_value(node: zui_node_t, socket: zui_node_socket_t } } else if (map_get(parser_material_custom_nodes, node.type) != null) { - return map_get(parser_material_custom_nodes, node.type)(node, socket); + let cb: (n: zui_node_t, s: zui_node_socket_t)=>string = map_get(parser_material_custom_nodes, node.type); + return cb(node, socket); } return "0.0"; } @@ -1730,31 +1747,34 @@ function parser_material_get_gradient(grad: string, co: string): string { function parser_material_vector_curve(name: string, fac: string, points: f32_array_t[]): string { // Write Ys array - let ys_var: string = name + "_ys"; - let num: i32 = points.length; - node_shader_write(parser_material_curshader, "float " + ys_var + "[" + num + "];"); // TODO: Make const - for (let i: i32 = 0; i < num; ++i) { - node_shader_write(parser_material_curshader, ys_var + "[" + i + "] = " + points[i][1] + ";"); - } - // Get index - let fac_var: string = name + "_fac"; - node_shader_write(parser_material_curshader, "float " + fac_var + " = " + fac + ";"); - let index: string = "0"; - for (let i: i32 = 1; i < num; ++i) { - index += " + (" + fac_var + " > " + points[i][0] + " ? 1 : 0)"; - } - // Write index - let index_var: string = name + "_i"; - node_shader_write(parser_material_curshader, "int " + index_var + " = " + index + ";"); - // Linear - // Write Xs array - let facs_var: string = name + "_xs"; - node_shader_write(parser_material_curshader, "float " + facs_var + "[" + num + "];"); // TODO: Make const - for (let i: i32 = 0; i < num; ++i) { - node_shader_write(parser_material_curshader, "" + facs_var + "[" + i + "] = " + points[i][0] + ";"); - } - // Map vector - return "mix(" + ys_var + "[" + index_var + "], " + ys_var + "[" + index_var + " + 1], (" + fac_var + " - " + facs_var + "[" + index_var + "]) * (1.0 / (" + facs_var + "[" + index_var + " + 1] - " + facs_var + "[" + index_var + "])))"; + // let ys_var: string = name + "_ys"; + // let num: i32 = points.length; + // node_shader_write(parser_material_curshader, "float " + ys_var + "[" + num + "];"); // TODO: Make const + // for (let i: i32 = 0; i < num; ++i) { + // node_shader_write(parser_material_curshader, ys_var + "[" + i + "] = " + points[i][1] + ";"); + // } + // // Get index + // let fac_var: string = name + "_fac"; + // node_shader_write(parser_material_curshader, "float " + fac_var + " = " + fac + ";"); + // let index: string = "0"; + // for (let i: i32 = 1; i < num; ++i) { + // index += " + (" + fac_var + " > " + points[i][0] + " ? 1 : 0)"; + // } + // // Write index + // let index_var: string = name + "_i"; + // node_shader_write(parser_material_curshader, "int " + index_var + " = " + index + ";"); + // // Linear + // // Write Xs array + // let facs_var: string = name + "_xs"; + // node_shader_write(parser_material_curshader, "float " + facs_var + "[" + num + "];"); // TODO: Make const + // for (let i: i32 = 0; i < num; ++i) { + // node_shader_write(parser_material_curshader, "" + facs_var + "[" + i + "] = " + points[i][0] + ";"); + // } + // // Map vector + // return "mix(" + ys_var + "[" + index_var + "], " + ys_var + "[" + index_var + " + 1], (" + fac_var + " - " + facs_var + "[" + index_var + "]) * (1.0 / (" + facs_var + "[" + index_var + " + 1] - " + facs_var + "[" + index_var + "])))"; + + //// + return ""; } function parser_material_res_var_name(node: zui_node_t, socket: zui_node_socket_t): string { @@ -1859,10 +1879,13 @@ function parser_material_vec1(v: f32): string { } function parser_material_vec3(v: f32_array_t): string { + let v0: f32 = v[0]; + let v1: f32 = v[1]; + let v2: f32 = v[2]; ///if krom_android - return "vec3(float(" + v[0] + "), float(" + v[1] + "), float(" + v[2] + "))"; + return "vec3(float(" + v0 + "), float(" + v1 + "), float(" + v2 + "))"; ///else - return "vec3(" + v[0] + ", " + v[1] + ", " + v[2] + ")"; + return "vec3(" + v0 + ", " + v1 + ", " + v2 + ")"; ///end } @@ -1937,7 +1960,8 @@ function parser_material_enum_data(s: string): string { } function parser_material_make_texture(image_node: zui_node_t, tex_name: string, matname: string = null): bind_tex_t { - let filepath: string = parser_material_enum_data(base_enum_texts(image_node.type)[image_node.buttons[0].default_value[0]]); + let i: i32 = image_node.buttons[0].default_value[0]; + let filepath: string = parser_material_enum_data(base_enum_texts(image_node.type)[i]); if (filepath == "" || string_index_of(filepath, ".") == -1) { return null; } diff --git a/base/Sources/path.ts b/base/Sources/path.ts index 32815bbf..9d5960a3 100644 --- a/base/Sources/path.ts +++ b/base/Sources/path.ts @@ -35,8 +35,8 @@ function path_to_relative(from: string, to: string): string { let a: string[] = string_split(from, path_sep); let b: string[] = string_split(to, path_sep); while (a[0] == b[0]) { - a.shift(); - b.shift(); + array_shift(a); + array_shift(b); if (a.length == 0 || b.length == 0) { break; } @@ -45,7 +45,7 @@ function path_to_relative(from: string, to: string): string { for (let i: i32 = 0; i < a.length - 1; ++i) { base += ".." + path_sep; } - base += b.join(path_sep); + base += string_array_join(b, path_sep); return base; } @@ -61,7 +61,7 @@ function path_normalize(path: string): string { i++; } } - return ar.join(path_sep); + return string_array_join(ar, path_sep); } function path_base_dir(path: string): string { @@ -71,7 +71,14 @@ function path_base_dir(path: string): string { function path_working_dir(): string { if (path_working_dir_cache == null) { let cmd: string = path_pwd; - let save: string = (path_is_protected() ? krom_save_path() : path_data() + path_sep) + "working_dir.txt"; + let save: string; + if (path_is_protected()) { + save = krom_save_path(); + } + else { + save = path_data() + path_sep; + } + save += "working_dir.txt"; krom_sys_command(cmd + " > \"" + save + "\""); path_working_dir_cache = trim_end(sys_buffer_to_string(krom_load_blob(save))); } @@ -171,7 +178,8 @@ function path_is_displacement_tex(p: string): bool { } function path_is_folder(p: string): bool { - return string_index_of(string_split(string_replace_all(p, "\\", "/"), "/").pop(), ".") == -1; + let last: string = array_pop(string_split(string_replace_all(p, "\\", "/"), "/")); + return string_index_of(last, ".") == -1; } function path_is_protected(): bool { diff --git a/base/Sources/project.ts b/base/Sources/project.ts index e0dd2865..4125c916 100644 --- a/base/Sources/project.ts +++ b/base/Sources/project.ts @@ -95,11 +95,12 @@ function project_new_box() { if (project_mesh_list == null) { project_mesh_list = file_read_directory(path_data() + path_sep + "meshes"); for (let i: i32 = 0; i < project_mesh_list.length; ++i) { - project_mesh_list[i] = substring(project_mesh_list[i], 0, project_mesh_list[i].length - 4); // Trim .arm + let s: string = project_mesh_list[i]; + project_mesh_list[i] = substring(project_mesh_list[i], 0, s.length - 4); // Trim .arm } - project_mesh_list.unshift("plane"); - project_mesh_list.unshift("sphere"); - project_mesh_list.unshift("rounded_cube"); + array_insert(project_mesh_list, 0, "plane"); + array_insert(project_mesh_list, 0, "sphere"); + array_insert(project_mesh_list, 0, "rounded_cube"); } let row: f32[] = [0.5, 0.5]; @@ -185,14 +186,14 @@ function project_new(reset_layers: bool = true) { if (context_raw.project_type != project_model_t.ROUNDED_CUBE) { let raw: mesh_data_t = null; if (context_raw.project_type == project_model_t.SPHERE || context_raw.project_type == project_model_t.TESSELLATED_PLANE) { - let mesh: any = context_raw.project_type == project_model_t.SPHERE ? + let mesh: raw_mesh_t = context_raw.project_type == project_model_t.SPHERE ? geom_make_uv_sphere(1, 512, 256) : geom_make_plane(1, 1, 512, 512); mesh.name = "Tessellated"; raw = import_mesh_raw_mesh(mesh); ///if is_sculpt - app_notify_on_next_frame(function (mesh: any) { + app_notify_on_next_frame(function (mesh: raw_mesh_t) { let f32a: f32_array_t = f32_array_create(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]; @@ -214,7 +215,8 @@ function project_new(reset_layers: bool = true) { } else { let b: buffer_t = data_get_blob("meshes/" + project_mesh_list[context_raw.project_type] + ".arm"); - raw = armpack_decode(b).mesh_datas[0]; + let scene: scene_t = armpack_decode(b); + raw = scene.mesh_datas[0]; } let md: mesh_data_t = mesh_data_create(raw); @@ -243,7 +245,7 @@ function project_new(reset_layers: bool = true) { project_paint_objects = [context_raw.paint_object]; ///if (is_paint || is_sculpt) while (project_materials.length > 0) { - slot_material_unload(project_materials.pop()); + slot_material_unload(array_pop(project_materials)); } ///end let m: material_data_t = data_get_material("Scene", "Material"); @@ -304,7 +306,7 @@ function project_new(reset_layers: bool = true) { ///if (is_paint || is_sculpt) 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) { - slot_layer_unload(project_layers.pop()); + slot_layer_unload(array_pop(project_layers)); } let layer: slot_layer_t = slot_layer_create(); array_push(project_layers, layer); @@ -348,7 +350,8 @@ function project_import_material() { } function project_import_brush() { - ui_files_show("arm," + path_texture_formats.join(","), false, true, function (path: string) { + let formats: string = string_array_join(path_texture_formats, ","); + ui_files_show("arm," + formats, false, true, function (path: string) { // Create brush from texture if (path_is_texture(path)) { // Import texture @@ -371,13 +374,14 @@ function project_import_brush() { n.y = 340; n.buttons[0].default_value = f32_array_create_x(asset_index); let links: zui_node_link_t[] = context_raw.brush.canvas.links; - array_push(links, { - id: zui_get_link_id(links), + let link: zui_node_link_t = { + id: zui_next_link_id(links.buffer, links.length), from_id: n.id, from_socket: 0, to_id: 0, to_socket: 4 - }); + }; + array_push(links, link); // Parse brush make_material_parse_brush(); @@ -398,7 +402,7 @@ let _project_import_mesh_done: ()=>void; function project_import_mesh(replace_existing: bool = true, done: ()=>void = null) { _project_import_mesh_replace_existing = replace_existing; _project_import_mesh_done = done; - ui_files_show(path_mesh_formats.join(","), false, false, function (path: string) { + ui_files_show(string_array_join(path_mesh_formats, ","), false, false, function (path: string) { project_import_mesh_box(path, _project_import_mesh_replace_existing, true, _project_import_mesh_done); }); } @@ -498,11 +502,11 @@ function project_reimport_mesh() { } } -let _project_unwrap_mesh_box_mesh: any; -let _project_unwrap_mesh_box_done: (a: any)=>void; +let _project_unwrap_mesh_box_mesh: raw_mesh_t; +let _project_unwrap_mesh_box_done: (a: raw_mesh_t)=>void; let _project_unwrap_mesh_box_skip_ui: bool; -function project_unwrap_mesh_box(mesh: any, done: (a: any)=>void, skip_ui: bool = false) { +function project_unwrap_mesh_box(mesh: raw_mesh_t, done: (a: raw_mesh_t)=>void, skip_ui: bool = false) { _project_unwrap_mesh_box_mesh = mesh; _project_unwrap_mesh_box_done = done; @@ -510,8 +514,8 @@ function project_unwrap_mesh_box(mesh: any, done: (a: any)=>void, skip_ui: bool ui_box_show_custom(function (ui: zui_t) { - let mesh: any = _project_unwrap_mesh_box_mesh; - let done: (a: any)=>void = _project_unwrap_mesh_box_done; + let mesh: raw_mesh_t = _project_unwrap_mesh_box_mesh; + let done: (a: raw_mesh_t)=>void = _project_unwrap_mesh_box_done; let skip_ui: bool = _project_unwrap_mesh_box_skip_ui; let tab_vertical: bool = config_raw.touch_ui; @@ -553,7 +557,8 @@ function project_unwrap_mesh_box(mesh: any, done: (a: any)=>void, skip_ui: bool config_enable_plugin(f); console_info(f + " " + tr("plugin enabled")); } - map_get(util_mesh_unwrappers, f)(mesh); + let cb: (a: any)=>void = map_get(util_mesh_unwrappers, f); + cb(mesh); } done(mesh); } @@ -565,7 +570,7 @@ let _project_import_asset_hdr_as_envmap: bool; function project_import_asset(filters: string = null, hdr_as_envmap: bool = true) { if (filters == null) { - filters = path_texture_formats.join(",") + "," + path_mesh_formats.join(","); + filters = string_array_join(path_texture_formats, ",") + "," + string_array_join(path_mesh_formats, ","); } _project_import_asset_hdr_as_envmap = hdr_as_envmap; @@ -605,8 +610,8 @@ function project_reimport_texture_load(path: string, asset: asset_t) { array_splice(project_assets, i, 1); array_splice(project_asset_names, i, 1); import_texture_run(asset.file); - array_insert(project_assets, i, project_assets.pop()); - array_insert(project_asset_names, i, project_asset_names.pop()); + array_insert(project_assets, i, array_pop(project_assets)); + array_insert(project_asset_names, i, array_pop(project_asset_names)); ///if (is_paint || is_sculpt) if (context_raw.texture == old_asset) { @@ -628,7 +633,7 @@ let _project_reimport_texture_asset: asset_t; function project_reimport_texture(asset: asset_t) { if (!file_exists(asset.file)) { - let filters: string = path_texture_formats.join(","); + let filters: string = string_array_join(path_texture_formats, ","); _project_reimport_texture_asset = asset; ui_files_show(filters, false, false, function (path: string) { project_reimport_texture_load(path, _project_reimport_texture_asset); @@ -645,7 +650,9 @@ function project_get_image(asset: asset_t): image_t { ///if (is_paint || is_sculpt) function project_get_used_atlases(): string[] { - if (project_atlas_objects == null) return null; + if (project_atlas_objects == null) { + return null; + } let used: i32[] = []; for (let i: i32 = 0; i < project_atlas_objects.length; ++i) { let ao: i32 = project_atlas_objects[i]; @@ -712,11 +719,13 @@ function project_export_swatches() { } function make_swatch(base: i32 = 0xffffffff): swatch_color_t { - return { base: base, opacity: 1.0, occlusion: 1.0, roughness: 0.0, metallic: 0.0, normal: 0xff8080ff, emission: 0.0, height: 0.0, subsurface: 0.0 }; + let s: swatch_color_t = { base: base, opacity: 1.0, occlusion: 1.0, roughness: 0.0, metallic: 0.0, normal: 0xff8080ff, emission: 0.0, height: 0.0, subsurface: 0.0 }; + return s; } function project_clone_swatch(swatch: swatch_color_t): swatch_color_t { - return { base: swatch.base, opacity: swatch.opacity, occlusion: swatch.occlusion, roughness: swatch.roughness, metallic: swatch.metallic, normal: swatch.normal, emission: swatch.emission, height: swatch.height, subsurface: swatch.subsurface }; + let s: swatch_color_t = { base: swatch.base, opacity: swatch.opacity, occlusion: swatch.occlusion, roughness: swatch.roughness, metallic: swatch.metallic, normal: swatch.normal, emission: swatch.emission, height: swatch.height, subsurface: swatch.subsurface }; + return s; } function project_set_default_swatches() { diff --git a/base/Sources/render_path_base.ts b/base/Sources/render_path_base.ts index f422eacf..317ed024 100644 --- a/base/Sources/render_path_base.ts +++ b/base/Sources/render_path_base.ts @@ -43,7 +43,7 @@ function render_path_base_apply_config() { let keys: string[] = map_keys(render_path_render_targets); for (let i: i32 = 0; i < keys.length; ++i) { let rt: render_target_t = map_get(render_path_render_targets, keys[i]); - if (rt.width == 0 && rt.scale != null) { + if (rt.width == 0 && rt.scale != 1.0) { rt.scale = render_path_base_super_sample; } } @@ -66,7 +66,7 @@ function render_path_base_draw_compass() { let compass: mesh_object_t = scene_get_child(".Compass").ext; let _visible: bool = compass.base.visible; - let _parent: object = compass.base.parent; + let _parent: object_t = compass.base.parent; let _loc: vec4_t = compass.base.transform.loc; let _rot: quat_t = compass.base.transform.rot; let crot: quat_t = cam.base.transform.rot; @@ -80,7 +80,8 @@ function render_path_base_draw_compass() { vec4_set(compass.base.transform.scale, 0.4, 0.4, 0.4); transform_build_matrix(compass.base.transform); compass.frustum_culling = false; - mesh_object_render(compass, "overlay", []); + let empty: string[] = []; + mesh_object_render(compass, "overlay", empty); cam.p = _P; compass.base.visible = _visible; @@ -513,13 +514,14 @@ function render_path_base_draw_gbuffer() { ///if krom_metal render_path_clear_target(0x00000000, 1.0, clear_flag_t.COLOR | clear_flag_t.DEPTH); ///else - render_path_clear_target(null, 1.0, clear_flag_t.DEPTH); + render_path_clear_target(0, 1.0, clear_flag_t.DEPTH); ///end if (make_mesh_layer_pass_count == 1) { render_path_set_target("gbuffer2"); render_path_clear_target(0xff000000); } - render_path_set_target("gbuffer0", ["gbuffer1", "gbuffer2"]); + let additional: string[] = ["gbuffer1", "gbuffer2"]; + render_path_set_target("gbuffer0", additional); render_path_paint_bind_layers(); render_path_draw_meshes("mesh"); render_path_paint_unbind_layers(); @@ -532,7 +534,10 @@ function render_path_base_draw_gbuffer() { render_path_set_target("gbuffer2" + ping); render_path_clear_target(0xff000000); } - render_path_set_target("gbuffer0" + ping, ["gbuffer1" + ping, "gbuffer2" + ping]); + let g1ping: string = "gbuffer1" + ping; + let g2ping: string = "gbuffer2" + ping; + let additional: string[] = [g1ping, g2ping]; + render_path_set_target("gbuffer0" + ping, additional); render_path_bind_target("gbuffer0" + pong, "gbuffer0"); render_path_bind_target("gbuffer1" + pong, "gbuffer1"); render_path_bind_target("gbuffer2" + pong, "gbuffer2"); @@ -554,7 +559,8 @@ function render_path_base_draw_gbuffer() { function render_path_base_make_gbuffer_copy_textures() { let copy: render_target_t = map_get(render_path_render_targets, "gbuffer0_copy"); - if (copy == null || copy._image.width != map_get(render_path_render_targets, "gbuffer0")._image.width || copy._image.height != map_get(render_path_render_targets, "gbuffer0")._image.height) { + let g0: render_target_t = map_get(render_path_render_targets, "gbuffer0"); + if (copy == null || copy._image.width != g0._image.width || copy._image.height != g0._image.height) { { let t: render_target_t = render_target_create(); t.name = "gbuffer0_copy"; @@ -593,7 +599,8 @@ function render_path_base_make_gbuffer_copy_textures() { } function render_path_base_copy_to_gbuffer() { - render_path_set_target("gbuffer0", ["gbuffer1", "gbuffer2"]); + let additional: string[] = ["gbuffer1", "gbuffer2"]; + render_path_set_target("gbuffer0", additional); render_path_bind_target("gbuffer0_copy", "tex0"); render_path_bind_target("gbuffer1_copy", "tex1"); render_path_bind_target("gbuffer2_copy", "tex2"); diff --git a/base/Sources/resource.ts b/base/Sources/resource.ts index a46be922..86e6e55b 100644 --- a/base/Sources/resource.ts +++ b/base/Sources/resource.ts @@ -15,17 +15,20 @@ function resource_get(name: string): image_t { function resource_tile50(img: image_t, x: i32, y: i32): rect_t { let size: i32 = config_raw.window_scale > 1 ? 100 : 50; - return { x: x * size, y: y * size, w: size, h: size }; + let r: rect_t = { x: x * size, y: y * size, w: size, h: size }; + return r; } function resource_tile25(img: image_t, x: i32, y: i32): rect_t { let size: i32 = config_raw.window_scale > 1 ? 50 : 25; - return { x: x * size, y: y * size, w: size, h: size }; + let r: rect_t = { x: x * size, y: y * size, w: size, h: size }; + return r; } function resource_tile18(img: image_t, x: i32, y: i32): rect_t { let size: i32 = config_raw.window_scale > 1 ? 36 : 18; - return { x: x * size, y: img.height - (y + 1) * size, w: size, h: size }; + let r: rect_t = { x: x * size, y: img.height - (y + 1) * size, w: size, h: size }; + return r; } ///if arm_snapshot diff --git a/base/Sources/tab_browser.ts b/base/Sources/tab_browser.ts index 7e76d7b7..802d4e21 100644 --- a/base/Sources/tab_browser.ts +++ b/base/Sources/tab_browser.ts @@ -67,14 +67,14 @@ function tab_browser_draw(htab: zui_handle_t) { let refresh: bool = false; 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")) || (in_focus && ui.is_key_pressed && ui.key == key_code_t.F5)) { + if (zui_button(tr("Refresh")) || (in_focus && ui.is_key_pressed && ui.key_code == key_code_t.F5)) { refresh = true; } tab_browser_hsearch.text = zui_text_input(tab_browser_hsearch, tr("Search"), zui_align_t.LEFT, true, true); if (ui.is_hovered) { zui_tooltip(tr("ctrl+f to search") + "\n" + tr("esc to cancel")); } - if (ui.is_ctrl_down && ui.is_key_pressed && ui.key == key_code_t.F) { // Start searching via ctrl+f + if (ui.is_ctrl_down && ui.is_key_pressed && ui.key_code == key_code_t.F) { // Start searching via ctrl+f zui_start_text_edit(tab_browser_hsearch); } if (tab_browser_hsearch.text != "" && (zui_button(tr("X")) || ui.is_escape_down)) { @@ -189,7 +189,8 @@ function tab_browser_draw(htab: zui_handle_t) { }, path); tab_browser_hpath.text = substring(tab_browser_hpath.text, 0, string_last_index_of(tab_browser_hpath.text, path_sep)); } - tab_browser_known = string_index_of(substring(tab_browser_hpath.text, string_last_index_of(tab_browser_hpath.text, path_sep), tab_browser_hpath.text.length), ".") > 0; + let hpath_text: string = tab_browser_hpath.text; + tab_browser_known = string_index_of(substring(tab_browser_hpath.text, string_last_index_of(tab_browser_hpath.text, path_sep), hpath_text.length), ".") > 0; ///if krom_android if (ends_with(tab_browser_hpath.text, "." + to_lower_case(manifest_title))) { tab_browser_known = false; diff --git a/base/Sources/tab_brushes.ts b/base/Sources/tab_brushes.ts index ea65f8a9..afb307a9 100644 --- a/base/Sources/tab_brushes.ts +++ b/base/Sources/tab_brushes.ts @@ -68,7 +68,7 @@ function tab_brushes_draw(htab: zui_handle_t) { let uix: f32 = ui._x; //let uiy: f32 = ui._y; let tile: i32 = zui_SCALE(ui) > 1 ? 100 : 50; - let state: zui_state_t = project_brushes[i].preview_ready ? zui_image(img) : zui_image(resource_get("icons.k"), -1, -1.0, tile * 5, tile, tile, tile); + let state: zui_state_t = project_brushes[i].preview_ready ? _zui_image(img) : _zui_image(resource_get("icons.k"), -1, -1.0, tile * 5, tile, tile, tile); if (state == zui_state_t.STARTED) { if (context_raw.brush != project_brushes[i]) { context_select_brush(i); diff --git a/base/Sources/tab_console.ts b/base/Sources/tab_console.ts index 51374a14..55f3a913 100644 --- a/base/Sources/tab_console.ts +++ b/base/Sources/tab_console.ts @@ -34,7 +34,7 @@ function tab_console_draw(htab: zui_handle_t) { } if (zui_button(tr("Export"))) { ui_files_show("txt", true, false, function (path: string) { - let str: string = console_last_traces.join("\n"); + let str: string = string_array_join(console_last_traces, "\n"); let f: string = ui_files_filename; if (f == "") { f = tr("untitled"); @@ -43,12 +43,12 @@ function tab_console_draw(htab: zui_handle_t) { if (!ends_with(path, ".txt")) { path += ".txt"; } - krom_file_save_bytes(path, sys_string_to_buffer(str)); + krom_file_save_bytes(path, sys_string_to_buffer(str), 0); }); } ///if (krom_windows || krom_linux || krom_darwin) if (zui_button(tr("Copy"))) { - let str: string = console_last_traces.join("\n"); + let str: string = string_array_join(console_last_traces, "\n"); krom_copy_to_clipboard(str); } ///end diff --git a/base/Sources/tab_fonts.ts b/base/Sources/tab_fonts.ts index 06d9df67..ed0ab988 100644 --- a/base/Sources/tab_fonts.ts +++ b/base/Sources/tab_fonts.ts @@ -83,11 +83,11 @@ function tab_fonts_draw(htab: zui_handle_t) { // g4_set_pipeline(pipe); // ///end // g4_set_int(channelLocation, 1); - state = zui_image(img); + state = _zui_image(img); // g2_set_pipeline(null); } else { - state = zui_image(resource_get("icons.k"), -1, -1.0, tile * 6, tile, tile, tile); + state = _zui_image(resource_get("icons.k"), -1, -1.0, tile * 6, tile, tile, tile); } if (state == zui_state_t.STARTED) { diff --git a/base/Sources/tab_materials.ts b/base/Sources/tab_materials.ts index f90275ce..a3856a27 100644 --- a/base/Sources/tab_materials.ts +++ b/base/Sources/tab_materials.ts @@ -58,7 +58,7 @@ function tab_materials_draw_slots(mini: bool) { for (let row: i32 = 0; row < math_floor(math_ceil(project_materials.length / num)); ++row) { let mult: i32 = config_raw.show_asset_names ? 2 : 1; let ar: f32[] = []; - for (let i = 0; i < num * mult; ++i) { + for (let i: i32 = 0; i < num * mult; ++i) { array_push(ar, 1 / num); } zui_row(ar); @@ -110,15 +110,15 @@ function tab_materials_draw_slots(mini: bool) { let uiy: f32 = ui._y; let tile: i32 = zui_SCALE(ui) > 1 ? 100 : 50; let imgh: f32 = mini ? ui_base_default_sidebar_mini_w * 0.85 * zui_SCALE(ui) : -1.0; - let state = project_materials[i].preview_ready ? - zui_image(img, 0xffffffff, imgh) : - zui_image(resource_get("icons.k"), 0xffffffff, -1.0, tile, tile, tile, tile); + let state: zui_state_t = project_materials[i].preview_ready ? + _zui_image(img, 0xffffffff, imgh) : + _zui_image(resource_get("icons.k"), 0xffffffff, -1.0, tile, tile, tile, tile); // Draw material numbers when selecting a material via keyboard shortcut let is_typing: bool = ui.is_typing || ui_view2d_ui.is_typing || ui_nodes_ui.is_typing; if (!is_typing) { if (i < 9 && operator_shortcut(map_get(config_keymap, "select_material"), shortcut_type_t.DOWN)) { - let number: string = any_to_string(i + 1); + let number: string = i32_to_string(i + 1); let width: i32 = g2_font_width(ui.ops.font, ui.font_size, number) + 10; let height: i32 = g2_font_height(ui.ops.font, ui.font_size); g2_set_color(ui.ops.theme.TEXT_COL); @@ -274,7 +274,8 @@ function tab_materials_draw_slots(mini: bool) { if (ui.is_hovered) { zui_tooltip_image(imgFull); if (i < 9) { - zui_tooltip(project_materials[i].canvas.name + " - (" + map_get(config_keymap, "select_material") + " " + (i + 1) + ")"); + let i1: i32 = i + 1; + zui_tooltip(project_materials[i].canvas.name + " - (" + map_get(config_keymap, "select_material") + " " + i1 + ")"); } else { zui_tooltip(project_materials[i].canvas.name); @@ -287,7 +288,8 @@ function tab_materials_draw_slots(mini: bool) { zui_text(project_materials[i].canvas.name, zui_align_t.CENTER); if (ui.is_hovered) { if (i < 9) { - zui_tooltip(project_materials[i].canvas.name + " - (" + map_get(config_keymap, "select_material") + " " + (i + 1) + ")"); + let i1: i32 = i + 1; + zui_tooltip(project_materials[i].canvas.name + " - (" + map_get(config_keymap, "select_material") + " " + i1 + ")"); } else { zui_tooltip(project_materials[i].canvas.name); diff --git a/base/Sources/tab_script.ts b/base/Sources/tab_script.ts index 6b78549a..60722612 100644 --- a/base/Sources/tab_script.ts +++ b/base/Sources/tab_script.ts @@ -17,7 +17,7 @@ function tab_script_draw(htab: zui_handle_t) { zui_row(row); } if (zui_button(tr("Run"))) { - js_eval(tab_script_hscript.text); + js_eval(tab_script_hscript.text, ""); } if (zui_button(tr("Clear"))) { tab_script_hscript.text = ""; @@ -40,7 +40,7 @@ function tab_script_draw(htab: zui_handle_t) { if (!ends_with(path, ".js")) { path += ".js"; } - krom_file_save_bytes(path, sys_string_to_buffer(str)); + krom_file_save_bytes(path, sys_string_to_buffer(str), 0); }); } zui_end_sticky(); @@ -50,13 +50,13 @@ function tab_script_draw(htab: zui_handle_t) { 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)); - zui_set_text_area_line_numbers(true); - zui_set_text_area_scroll_past_end(true); - zui_set_text_area_coloring(tab_script_get_text_coloring()); + zui_text_area_line_numbers = true; + zui_text_area_scroll_past_end = true; + zui_text_area_coloring = tab_script_get_text_coloring(); zui_text_area(tab_script_hscript); - zui_set_text_area_line_numbers(false); - zui_set_text_area_scroll_past_end(false); - zui_set_text_area_coloring(null); + zui_text_area_line_numbers = false; + zui_text_area_scroll_past_end = false; + zui_text_area_coloring = null; zui_set_font(ui, _font); ui.font_size = _font_size; } diff --git a/base/Sources/tab_swatches.ts b/base/Sources/tab_swatches.ts index 2c6f7567..a5248259 100644 --- a/base/Sources/tab_swatches.ts +++ b/base/Sources/tab_swatches.ts @@ -119,7 +119,7 @@ function tab_swatches_draw(htab: zui_handle_t) { zui_fill(-1, -2 , 2, 32, ui.ops.theme.HIGHLIGHT_COL); } - let state: zui_state_t = zui_image(tab_swatches_empty_get(), project_raw.swatches[i].base, slotw); + let state: zui_state_t = _zui_image(tab_swatches_empty_get(), project_raw.swatches[i].base, slotw); if (state == zui_state_t.STARTED) { context_set_swatch(project_raw.swatches[i]); @@ -142,7 +142,7 @@ function tab_swatches_draw(htab: zui_handle_t) { let h: zui_handle_t = zui_handle(__ID__); h.color = context_raw.swatch.base; - context_raw.swatch.base = zui_color_wheel(h, false, null, 11 * ui.ops.theme.ELEMENT_H * zui_SCALE(ui), true, function () { + context_raw.swatch.base = zui_color_wheel(h, false, -1, 11 * ui.ops.theme.ELEMENT_H * zui_SCALE(ui), true, function () { context_raw.color_picker_previous_tool = context_raw.tool; context_select_tool(workspace_tool_t.PICKER); diff --git a/base/Sources/tab_textures.ts b/base/Sources/tab_textures.ts index 651faafa..ba6a8d7e 100644 --- a/base/Sources/tab_textures.ts +++ b/base/Sources/tab_textures.ts @@ -2,6 +2,8 @@ let _tab_textures_draw_img: image_t; let _tab_textures_draw_path: string; let _tab_textures_draw_asset: asset_t; +let _tab_textures_draw_i: i32; +let _tab_textures_draw_is_packed: bool; function tab_textures_draw(htab: zui_handle_t) { let ui: zui_t = ui_base_ui; @@ -20,7 +22,7 @@ function tab_textures_draw(htab: zui_handle_t) { } if (zui_button(tr("Import"))) { - ui_files_show(path_texture_formats.join(","), false, true, function (path: string) { + ui_files_show(string_array_join(path_texture_formats, ","), false, true, function (path: string) { import_asset_run(path, -1.0, -1.0, true, false); ui_base_hwnds[tab_area_t.STATUS].redraws = 2; }); @@ -77,7 +79,7 @@ function tab_textures_draw(htab: zui_handle_t) { let uix: f32 = ui._x; 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) { + 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; @@ -109,7 +111,12 @@ function tab_textures_draw(htab: zui_handle_t) { if (ui.is_hovered) { zui_tooltip_image(img, 256); - zui_tooltip(asset.name + (is_packed ? " " + tr("(packed)") : "")); + if (is_packed) { + zui_tooltip(asset.name + " " + tr("(packed)")); + } + else { + zui_tooltip(asset.name); + } } if (ui.is_hovered && ui.input_released_r) { @@ -125,6 +132,9 @@ function tab_textures_draw(htab: zui_handle_t) { ///end _tab_textures_draw_img = img; + _tab_textures_draw_asset = asset; + _tab_textures_draw_i = i; + _tab_textures_draw_is_packed = is_packed; ui_menu_draw(function (ui: zui_t) { if (ui_menu_button(ui, tr("Export"))) { @@ -147,7 +157,7 @@ function tab_textures_draw(htab: zui_handle_t) { g2_draw_scaled_image(img, 0, 0, target.width, target.height); g2_set_pipeline(null); g2_end(); - app_notify_on_next_frame(function () { + app_notify_on_next_frame(function (target: image_t) { let path: string = _tab_textures_draw_path; let f: string = ui_files_filename; if (f == "") { @@ -158,17 +168,16 @@ function tab_textures_draw(htab: zui_handle_t) { } krom_write_png(path + path_sep + f, image_get_pixels(target), target.width, target.height, 0); image_unload(target); - }); + }, target); }); }); } if (ui_menu_button(ui, tr("Reimport"))) { - project_reimport_texture(asset); + project_reimport_texture(_tab_textures_draw_asset); } ///if (is_paint || is_sculpt) if (ui_menu_button(ui, tr("To Mask"))) { - _tab_textures_draw_asset = asset; app_notify_on_next_frame(function () { base_create_image_mask(_tab_textures_draw_asset); }); @@ -176,8 +185,6 @@ function tab_textures_draw(htab: zui_handle_t) { ///end if (ui_menu_button(ui, tr("Set as Envmap"))) { - _tab_textures_draw_asset = asset; - _tab_textures_draw_img = img; app_notify_on_next_frame(function () { import_envmap_run(_tab_textures_draw_asset.file, _tab_textures_draw_img); }); @@ -185,7 +192,7 @@ function tab_textures_draw(htab: zui_handle_t) { ///if is_paint if (ui_menu_button(ui, tr("Set as Color ID Map"))) { - context_raw.colorid_handle.position = i; + context_raw.colorid_handle.position = _tab_textures_draw_i; context_raw.colorid_picked = false; ui_toolbar_handle.redraws = 1; if (context_raw.tool == workspace_tool_t.COLORID) { @@ -196,13 +203,13 @@ function tab_textures_draw(htab: zui_handle_t) { ///end if (ui_menu_button(ui, tr("Delete"), "delete")) { - tab_textures_delete_texture(asset); + tab_textures_delete_texture(_tab_textures_draw_asset); } - if (!is_packed && ui_menu_button(ui, tr("Open Containing Directory..."))) { - file_start(substring(asset.file, 0, string_last_index_of(asset.file, path_sep))); + if (!_tab_textures_draw_is_packed && ui_menu_button(ui, tr("Open Containing Directory..."))) { + file_start(substring(_tab_textures_draw_asset.file, 0, string_last_index_of(_tab_textures_draw_asset.file, path_sep))); } - if (!is_packed && ui_menu_button(ui, tr("Open in Browser"))) { - tab_browser_show_directory(substring(asset.file, 0, string_last_index_of(asset.file, path_sep))); + if (!_tab_textures_draw_is_packed && ui_menu_button(ui, tr("Open in Browser"))) { + tab_browser_show_directory(substring(_tab_textures_draw_asset.file, 0, string_last_index_of(_tab_textures_draw_asset.file, path_sep))); } }, count); } @@ -225,7 +232,7 @@ function tab_textures_draw(htab: zui_handle_t) { else { let img: image_t = resource_get("icons.k"); let r: rect_t = resource_tile50(img, 0, 1); - zui_image(img, ui.ops.theme.BUTTON_COL, r.h, r.x, r.y, r.w, r.h); + _zui_image(img, ui.ops.theme.BUTTON_COL, r.h, r.x, r.y, r.w, r.h); if (ui.is_hovered) { zui_tooltip(tr("Drag and drop files here")); } diff --git a/base/Sources/translator.ts b/base/Sources/translator.ts index e9ea28ac..341fd4d4 100644 --- a/base/Sources/translator.ts +++ b/base/Sources/translator.ts @@ -7,7 +7,7 @@ let translator_last_locale: string = "en"; // Mark strings as localizable in order to be parsed by the extract_locale script // The string will not be translated to the currently selected locale though -function _tr(s: string) { +function _tr(s: string): string { return s; } @@ -24,13 +24,17 @@ function tr(id: string, vars: map_t = null): string { if (vars != null) { let keys: string[] = map_keys(vars); for (let i: i32 = 0; i < keys.length; ++i) { - translation = string_replace_all(translation, "{" + keys[i] + "}", any_to_string(map_get(vars, keys[i]))); + let search: string = "{" + keys[i] + "}"; + translation = string_replace_all(translation, search, map_get(vars, keys[i])); } } return translation; } +let _translator_load_translations_cjk_font_path: string; +let _translator_load_translations_cjk_font_disk_path: string; + // (Re)loads translations for the specified locale function translator_load_translations(new_locale: string) { @@ -55,7 +59,7 @@ function translator_load_translations(new_locale: string) { // No translations to load, as source strings are in English // Clear existing translations if switching languages at runtime - translator_translations.clear(); + translator_translations = map_create(); if (config_raw.locale == "en" && translator_last_locale == "en") { // No need to generate extended font atlas for English locale @@ -96,28 +100,34 @@ function translator_load_translations(new_locale: string) { } if (cjk) { - 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, function () { + if (path_is_protected()) { + _translator_load_translations_cjk_font_path = krom_save_path(); + _translator_load_translations_cjk_font_disk_path = krom_save_path(); + } + else { + _translator_load_translations_cjk_font_path = ""; + _translator_load_translations_cjk_font_disk_path = path_data() + path_sep; + } + _translator_load_translations_cjk_font_path += "font_cjk.ttc"; + _translator_load_translations_cjk_font_disk_path += "font_cjk.ttc"; - 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(_translator_load_translations_cjk_font_disk_path)) { + file_download("https://github.com/armory3d/armorbase/raw/main/Assets/common/extra/font_cjk.ttc", _translator_load_translations_cjk_font_disk_path, function () { - if (!file_exists(cjk_font_disk_path)) { + if (!file_exists(_translator_load_translations_cjk_font_disk_path)) { // Fall back to English config_raw.locale = "en"; translator_extended_glyphs(); - translator_translations.clear(); + translator_translations = map_create(); translator_init_font(false, "font.ttf", 1.0); } else { - translator_init_font(true, cjk_font_path, 1.4); + translator_init_font(true, _translator_load_translations_cjk_font_path, 1.4); } }, 20332392); } else { - translator_init_font(true, cjk_font_path, 1.4); + translator_init_font(true, _translator_load_translations_cjk_font_path, 1.4); } } else { @@ -130,7 +140,7 @@ let _translator_init_font_font_path: string; let _translator_init_font_font_scale: f32; function translator_init_font(cjk: bool, font_path: string, font_scale: f32) { - array_sort(_g2_font_glyphs, function (a: i32, b: i32) { + array_sort(_g2_font_glyphs, function (a: i32, b: i32): i32 { return a - b; }); @@ -158,7 +168,7 @@ function translator_init_font(cjk: bool, font_path: string, font_scale: f32) { for (let i: i32 = 0; i < uis.length; ++i) { let ui: zui_t = uis[i]; zui_set_font(ui, f); - zui_set_scale(ui, zui_SCALE(ui)); + _zui_set_scale(ui, zui_SCALE(ui)); } }); } @@ -179,7 +189,9 @@ function translator_extended_glyphs() { // Returns a list of supported locales (plus English and the automatically detected system locale) function translator_get_supported_locales(): string[] { let locales: string[] = ["system", "en"]; - for (let locale_filename of file_read_directory(path_data() + path_sep + "locale")) { + let files: string[] = file_read_directory(path_data() + path_sep + "locale"); + for (let i: i32 = 0; i < files.length; ++i) { + let locale_filename: string = files[i]; // Trim the ".json" file extension from file names array_push(locales, substring(locale_filename, 0, locale_filename.length - 5)); } diff --git a/base/Sources/ui_base.ts b/base/Sources/ui_base.ts index c2a97c4b..56fb1a00 100644 --- a/base/Sources/ui_base.ts +++ b/base/Sources/ui_base.ts @@ -2,7 +2,7 @@ let ui_base_show: bool = true; let ui_base_ui: zui_t; let ui_base_border_started: i32 = 0; -let ui_base_border_handle_ptr: i32 = 0; +let ui_base_border_handle: zui_handle_t = null; let ui_base_action_paint_remap: string = ""; let ui_base_operator_search_offset: i32 = 0; let ui_base_undo_tap_time: f32 = 0.0; @@ -10,7 +10,12 @@ let ui_base_redo_tap_time: f32 = 0.0; let ui_base_hwnds: zui_handle_t[] = ui_base_init_hwnds(); let ui_base_htabs: zui_handle_t[] = ui_base_init_htabs(); -let ui_base_hwnd_tabs: any[] = ui_base_init_hwnd_tabs(); + +type tab_draw_t = { + f: (h: zui_handle_t)=>void; +}; +type tab_draw_array_t = tab_draw_t[]; +let ui_base_hwnd_tabs: tab_draw_array_t[] = ui_base_init_hwnd_tabs(); ///if (is_paint || is_sculpt) let ui_base_default_sidebar_mini_w: i32 = 56; @@ -27,40 +32,69 @@ let ui_base_sidebar_mini_w: i32 = ui_base_default_sidebar_mini_w; function ui_base_init_hwnds(): zui_handle_t[] { ///if is_paint - return [zui_handle_create(), zui_handle_create(), zui_handle_create()]; + let hwnds: zui_handle_t[] = [zui_handle_create(), zui_handle_create(), zui_handle_create()]; ///end ///if is_sculpt - return [zui_handle_create(), zui_handle_create(), zui_handle_create()]; + let hwnds: zui_handle_t[] = [zui_handle_create(), zui_handle_create(), zui_handle_create()]; ///end ///if is_lab - return [zui_handle_create()]; + let hwnds: zui_handle_t[] = [zui_handle_create()]; ///end + return hwnds; } function ui_base_init_htabs(): zui_handle_t[] { ///if is_paint - return [zui_handle_create(), zui_handle_create(), zui_handle_create()]; + let htabs: zui_handle_t[] = [zui_handle_create(), zui_handle_create(), zui_handle_create()]; ///end ///if is_sculpt - return [zui_handle_create(), zui_handle_create(), zui_handle_create()]; + let htabs: zui_handle_t[] = [zui_handle_create(), zui_handle_create(), zui_handle_create()]; ///end ///if is_lab - return [zui_handle_create()]; + let htabs: zui_handle_t[] = [zui_handle_create()]; ///end + return htabs; } -function ui_base_init_hwnd_tabs(): any[] { +function _draw_callback_create(f: (h: zui_handle_t)=>void): tab_draw_t { + let cb: tab_draw_t = { f: f }; + return cb; +} + +function ui_base_init_hwnd_tabs(): tab_draw_array_t[] { + + let r: tab_draw_array_t[] = []; + ///if is_paint - return [ - [tab_layers_draw, tab_history_draw, tab_plugins_draw - ///if is_forge - , tab_objects_draw - ///end - ], - [tab_materials_draw, tab_brushes_draw, tab_particles_draw], - [tab_browser_draw, tab_textures_draw, tab_meshes_draw, tab_fonts_draw, tab_swatches_draw, tab_script_draw, tab_console_draw, ui_status_draw_version_tab] + let a0: tab_draw_array_t = [ + _draw_callback_create(tab_layers_draw), + _draw_callback_create(tab_history_draw), + _draw_callback_create(tab_plugins_draw) + ///if is_forge + , _draw_callback_create(tab_objects_draw) + ///end ]; + let a1: tab_draw_array_t = [ + _draw_callback_create(tab_materials_draw), + _draw_callback_create(tab_brushes_draw), + _draw_callback_create(tab_particles_draw) + ]; + let a2: tab_draw_array_t = [ + _draw_callback_create(tab_browser_draw), + _draw_callback_create(tab_textures_draw), + _draw_callback_create(tab_meshes_draw), + _draw_callback_create(tab_fonts_draw), + _draw_callback_create(tab_swatches_draw), + _draw_callback_create(tab_script_draw), + _draw_callback_create(tab_console_draw), + _draw_callback_create(ui_status_draw_version_tab) + ]; + + array_push(r, a0); + array_push(r, a1); + array_push(r, a2); ///end + ///if is_sculpt return [ [tab_layers_draw, tab_history_draw, tab_plugins_draw @@ -72,11 +106,14 @@ function ui_base_init_hwnd_tabs(): any[] { [tab_browser_draw, tab_textures_draw, tab_meshes_draw, tab_fonts_draw, tab_script_draw, tab_console_draw, ui_status_draw_version_tab] ]; ///end + ///if is_lab return [ [tab_browser_draw, tab_textures_draw, tab_meshes_draw, tab_swatches_draw, tab_plugins_draw, tab_script_draw, tab_console_draw, ui_status_draw_version_tab] ]; ///end + + return r; } function ui_base_init() { @@ -178,16 +215,16 @@ function ui_base_init() { let scale: f32 = config_raw.window_scale; let ops: zui_options_t = { theme: base_theme, - font: base_font, + font: base_font.font_, scale_factor: scale, - color_wheel: base_color_wheel, - black_white_gradient: base_color_wheel_gradient + color_wheel: base_color_wheel.texture_, + black_white_gradient: base_color_wheel_gradient.texture_ }; ui_base_ui = zui_create(ops); - zui_set_on_border_hover(ui_base_on_border_hover); - zui_set_on_text_hover(ui_base_on_text_hover); - zui_set_on_deselect_text(ui_base_on_deselect_text); - zui_set_on_tab_drop(ui_base_on_tab_drop); + zui_on_border_hover = ui_base_on_border_hover; + zui_on_text_hover = ui_base_on_text_hover; + zui_on_deselect_text = ui_base_on_deselect_text; + zui_on_tab_drop = ui_base_on_tab_drop; ///if (is_paint || is_sculpt) let resources: string[] = ["cursor.k", "icons.k"]; @@ -346,7 +383,8 @@ function ui_base_update() { } else if (operator_shortcut(map_get(config_keymap, "brush_angle"), shortcut_type_t.DOWN)) { context_raw.brush_angle += mouse_movement_x / 5; - context_raw.brush_angle = math_floor(context_raw.brush_angle) % 360; + let i: i32 = math_floor(context_raw.brush_angle); + context_raw.brush_angle = i % 360; if (context_raw.brush_angle < 0) context_raw.brush_angle += 360; context_raw.brush_angle_handle.value = context_raw.brush_angle; make_material_parse_paint_material(); @@ -652,7 +690,7 @@ function ui_base_update() { zui_radio(mode_handle, i, modes[i], shortcuts[i]); } - let index: i32 = array_index_of(shortcuts, keyboard_key_code(ui.key)); + let index: i32 = array_index_of(shortcuts, keyboard_key_code(ui.key_code)); if (ui.is_key_pressed && index != -1) { mode_handle.position = index; ui.changed = true; @@ -703,8 +741,8 @@ function ui_base_update() { } ///if (is_paint || is_sculpt) - if (ui_base_border_handle_ptr != 0) { - if (ui_base_border_handle_ptr == ui_nodes_hwnd.ptr || ui_base_border_handle_ptr == ui_view2d_hwnd.ptr) { + if (ui_base_border_handle != 0) { + if (ui_base_border_handle == ui_nodes_hwnd || ui_base_border_handle == ui_view2d_hwnd) { if (ui_base_border_started == border_side_t.LEFT) { config_raw.layout[layout_size_t.NODES_W] -= math_floor(mouse_movement_x); if (config_raw.layout[layout_size_t.NODES_W] < 32) { @@ -724,7 +762,7 @@ function ui_base_update() { } } } - else if (ui_base_border_handle_ptr == ui_base_hwnds[tab_area_t.STATUS].ptr) { + else if (ui_base_border_handle == ui_base_hwnds[tab_area_t.STATUS]) { let my: i32 = math_floor(mouse_movement_y); if (config_raw.layout[layout_size_t.STATUS_H] - my >= ui_status_default_status_h * config_raw.window_scale && config_raw.layout[layout_size_t.STATUS_H] - my < sys_height() * 0.7) { config_raw.layout[layout_size_t.STATUS_H] -= my; @@ -742,7 +780,7 @@ function ui_base_update() { } else { let my: i32 = math_floor(mouse_movement_y); - if (ui_base_border_handle_ptr == ui_base_hwnds[tab_area_t.SIDEBAR1].ptr && ui_base_border_started == border_side_t.TOP) { + if (ui_base_border_handle == ui_base_hwnds[tab_area_t.SIDEBAR1] && ui_base_border_started == border_side_t.TOP) { if (config_raw.layout[layout_size_t.SIDEBAR_H0] + my > 32 && config_raw.layout[layout_size_t.SIDEBAR_H1] - my > 32) { config_raw.layout[layout_size_t.SIDEBAR_H0] += my; config_raw.layout[layout_size_t.SIDEBAR_H1] -= my; @@ -754,8 +792,8 @@ function ui_base_update() { ///end ///if is_lab - if (ui_base_border_handle_ptr != 0) { - if (ui_base_border_handle_ptr == ui_nodes_hwnd.ptr || ui_base_border_handle_ptr == ui_view2d_hwnd.ptr) { + if (ui_base_border_handle != null) { + if (ui_base_border_handle == ui_nodes_hwnd || ui_base_border_handle == ui_view2d_hwnd) { if (ui_base_border_started == border_side_t.LEFT) { config_raw.layout[layout_size_t.NODES_W] -= math_floor(mouse_movement_x); if (config_raw.layout[layout_size_t.NODES_W] < 32) { @@ -775,7 +813,7 @@ function ui_base_update() { } } } - else if (ui_base_border_handle_ptr == ui_base_hwnds[tab_area_t.STATUS].ptr) { + else if (ui_base_border_handle == ui_base_hwnds[tab_area_t.STATUS]) { let my: i32 = math_floor(mouse_movement_y); if (config_raw.layout[layout_size_t.STATUS_H] - my >= ui_status_default_status_h * config_raw.window_scale && config_raw.layout[layout_size_t.STATUS_H] - my < sys_height() * 0.7) { config_raw.layout[layout_size_t.STATUS_H] -= my; @@ -785,7 +823,7 @@ function ui_base_update() { ///end if (!mouse_down()) { - ui_base_border_handle_ptr = 0; + ui_base_border_handle = null; base_is_resizing = false; } @@ -884,10 +922,10 @@ function ui_base_operator_search() { } if (ui.is_key_pressed) { // Move selection - if (ui.key == key_code_t.DOWN && ui_base_operator_search_offset < 6) { + if (ui.key_code == key_code_t.DOWN && ui_base_operator_search_offset < 6) { ui_base_operator_search_offset++; } - if (ui.key == key_code_t.UP && ui_base_operator_search_offset > 0) { + if (ui.key_code == key_code_t.UP && ui_base_operator_search_offset > 0) { ui_base_operator_search_offset--; } } @@ -930,7 +968,7 @@ function ui_base_get_radius_increment(): f32 { return 0.1; } -function ui_base_hit_rect(mx: f32, my: f32, x: i32, y: i32, w: i32, h: i32) { +function ui_base_hit_rect(mx: f32, my: f32, x: i32, y: i32, w: i32, h: i32): bool { return mx > x && mx < x + w && my > y && my < y + h; } @@ -940,7 +978,13 @@ function ui_base_get_brush_stencil_rect(): rect_t { 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 }; + let r: rect_t = { + w: w, + h: h, + x: x, + y: y + }; + return r; } ///end @@ -1332,13 +1376,15 @@ function ui_base_draw_sidebar() { } if (zui_window(ui_base_hwnds[tab_area_t.SIDEBAR0], ui_base_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 : ui_base_hwnd_tabs[tab_area_t.SIDEBAR0].length); ++i) { - ui_base_hwnd_tabs[tab_area_t.SIDEBAR0][i](ui_base_htabs[tab_area_t.SIDEBAR0]); + let tabs: tab_draw_t[] = ui_base_hwnd_tabs[tab_area_t.SIDEBAR0]; + for (let i: i32 = 0; i < (mini ? 1 : tabs.length); ++i) { + tabs[i].f(ui_base_htabs[tab_area_t.SIDEBAR0]); } } if (zui_window(ui_base_hwnds[tab_area_t.SIDEBAR1], ui_base_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 : ui_base_hwnd_tabs[tab_area_t.SIDEBAR1].length); ++i) { - ui_base_hwnd_tabs[tab_area_t.SIDEBAR1][i](ui_base_htabs[tab_area_t.SIDEBAR1]); + let tabs: tab_draw_t[] = ui_base_hwnd_tabs[tab_area_t.SIDEBAR1]; + for (let i: i32 = 0; i < (mini ? 1 : tabs.length); ++i) { + tabs[i].f(ui_base_htabs[tab_area_t.SIDEBAR1]); } } @@ -1605,52 +1651,54 @@ function ui_base_toggle_browser() { function ui_base_set_icon_scale() { if (zui_SCALE(ui_base_ui) > 1) { - resource_load(["icons2x.k"]); + let res: string[] = ["icons2x.k"]; + resource_load(res); map_set(resource_bundled, "icons.k", resource_get("icons2x.k")); } else { - resource_load(["icons.k"]); + let res: string[] = ["icons.k"]; + resource_load(res); } } -function ui_base_on_border_hover(handle_ptr: i32, side: i32) { +function ui_base_on_border_hover(handle: zui_handle_t, side: i32) { if (!base_ui_enabled) return; ///if (is_paint || is_sculpt) - if (handle_ptr != ui_base_hwnds[tab_area_t.SIDEBAR0].ptr && - handle_ptr != ui_base_hwnds[tab_area_t.SIDEBAR1].ptr && - handle_ptr != ui_base_hwnds[tab_area_t.STATUS].ptr && - handle_ptr != ui_nodes_hwnd.ptr && - handle_ptr != ui_view2d_hwnd.ptr) { + if (handle != ui_base_hwnds[tab_area_t.SIDEBAR0] && + handle != ui_base_hwnds[tab_area_t.SIDEBAR1] && + handle != ui_base_hwnds[tab_area_t.STATUS] && + handle != ui_nodes_hwnd && + handle != ui_view2d_hwnd) { return; // Scalable handles } - if (handle_ptr == ui_view2d_hwnd.ptr && side != border_side_t.LEFT) { + if (handle == ui_view2d_hwnd && side != border_side_t.LEFT) { return; } - if (handle_ptr == ui_nodes_hwnd.ptr && side == border_side_t.TOP && !ui_view2d_show) { + if (handle == ui_nodes_hwnd && side == border_side_t.TOP && !ui_view2d_show) { return; } - if (handle_ptr == ui_base_hwnds[tab_area_t.SIDEBAR0].ptr && side == border_side_t.TOP) { + if (handle == ui_base_hwnds[tab_area_t.SIDEBAR0] && side == border_side_t.TOP) { return; } ///end ///if is_lab - if (handle_ptr != ui_base_hwnds[tab_area_t.STATUS].ptr && - handle_ptr != ui_nodes_hwnd.ptr && - handle_ptr != ui_view2d_hwnd.ptr) return; // Scalable handles - if (handle_ptr == ui_view2d_hwnd.ptr && side != border_side_t.LEFT) { + if (handle != ui_base_hwnds[tab_area_t.STATUS] && + handle != ui_nodes_hwnd && + handle != ui_view2d_hwnd) return; // Scalable handles + if (handle == ui_view2d_hwnd && side != border_side_t.LEFT) { return; } - if (handle_ptr == ui_nodes_hwnd.ptr && side == border_side_t.TOP && !ui_view2d_show) { + if (handle == ui_nodes_hwnd && side == border_side_t.TOP && !ui_view2d_show) { return; } ///end - if (handle_ptr == ui_nodes_hwnd.ptr && side != border_side_t.LEFT && side != border_side_t.TOP) { + if (handle == ui_nodes_hwnd && side != border_side_t.LEFT && side != border_side_t.TOP) { return; } - if (handle_ptr == ui_base_hwnds[tab_area_t.STATUS].ptr && side != border_side_t.TOP) { + if (handle == ui_base_hwnds[tab_area_t.STATUS] && side != border_side_t.TOP) { return; } if (side == border_side_t.RIGHT) { @@ -1663,7 +1711,7 @@ function ui_base_on_border_hover(handle_ptr: i32, side: i32) { if (zui_current.input_started) { ui_base_border_started = side; - ui_base_border_handle_ptr = handle_ptr; + ui_base_border_handle = handle; base_is_resizing = true; } } @@ -1678,21 +1726,23 @@ function ui_base_on_deselect_text() { ///end } -function ui_base_on_tab_drop(to_ptr: i32, to_position: i32, from_ptr: i32, from_position: i32) { +function ui_base_on_tab_drop(to: zui_handle_t, to_position: i32, from: zui_handle_t, from_position: i32) { let i: i32 = -1; let j: i32 = -1; for (let k: i32 = 0; k < ui_base_htabs.length; ++k) { - if (ui_base_htabs[k].ptr == to_ptr) { + if (ui_base_htabs[k] == to) { i = k; } - if (ui_base_htabs[k].ptr == from_ptr) { + if (ui_base_htabs[k] == from) { j = k; } } if (i > -1 && j > -1) { - let element: any = ui_base_hwnd_tabs[j][from_position]; - array_splice(ui_base_hwnd_tabs[j], from_position, 1); - array_insert(ui_base_hwnd_tabs[i], to_position, element); + let tabsi: tab_draw_t[] = ui_base_hwnd_tabs[i]; + let tabsj: tab_draw_t[] = ui_base_hwnd_tabs[j]; + let element: tab_draw_t = tabsj[from_position]; + array_splice(tabsj, from_position, 1); + array_insert(tabsi, to_position, element); ui_base_hwnds[i].redraws = 2; ui_base_hwnds[j].redraws = 2; } diff --git a/base/Sources/ui_box.ts b/base/Sources/ui_box.ts index 36ae3fff..021d0188 100644 --- a/base/Sources/ui_box.ts +++ b/base/Sources/ui_box.ts @@ -27,7 +27,7 @@ function ui_box_init() { function ui_box_render() { if (!ui_menu_show) { let ui: zui_t = base_ui_box; - let in_use: bool = ui.combo_selected_handle_ptr != 0; + let in_use: bool = ui.combo_selected_handle != null; let is_escape: bool = keyboard_started("escape"); if (ui_box_draws > 2 && (ui.input_released || is_escape) && !in_use && !ui.is_typing) { let appw: i32 = sys_width(); diff --git a/base/Sources/ui_files.ts b/base/Sources/ui_files.ts index eb6ed813..d3e4bd47 100644 --- a/base/Sources/ui_files.ts +++ b/base/Sources/ui_files.ts @@ -25,8 +25,9 @@ function ui_files_show(filters: string, is_save: bool, open_multiple: bool, file if (is_save) { ui_files_path = krom_save_dialog(filters, ""); if (ui_files_path != null) { - while (string_index_of(ui_files_path, path_sep + path_sep) >= 0) { - ui_files_path = string_replace_all(ui_files_path, path_sep + path_sep, path_sep); + let sep2: string = path_sep + path_sep; + while (string_index_of(ui_files_path, sep2) >= 0) { + ui_files_path = string_replace_all(ui_files_path, sep2, path_sep); } ui_files_path = string_replace_all(ui_files_path, "\r", ""); ui_files_filename = substring(ui_files_path, string_last_index_of(ui_files_path, path_sep) + 1, ui_files_path.length); @@ -39,8 +40,9 @@ function ui_files_show(filters: string, is_save: bool, open_multiple: bool, file if (paths != null) { for (let i: i32 = 0; i < paths.length; ++i) { let path: string = paths[i]; - while (string_index_of(path, path_sep + path_sep) >= 0) { - path = string_replace_all(path, path_sep + path_sep, path_sep); + let sep2: string = path_sep + path_sep; + while (string_index_of(path, sep2) >= 0) { + path = string_replace_all(path, sep2, path_sep); } path = string_replace_all(path, "\r", ""); ui_files_filename = substring(path, string_last_index_of(path, path_sep) + 1, path.length); @@ -64,6 +66,7 @@ function ui_files_release_keys() { let _ui_files_file_browser_handle: zui_handle_t; let _ui_files_file_browser_f: string; let _ui_files_file_browser_shandle: string; +let _ui_files_file_browser_w: i32; function ui_files_file_browser(ui: zui_t, handle: zui_handle_t, folders_only: bool = false, drag_files: bool = false, search: string = "", refresh: bool = false, context_menu: (s: string)=>void = null): string { @@ -91,17 +94,18 @@ function ui_files_file_browser(ui: zui_t, handle: zui_handle_t, folders_only: bo ui_files_files = []; // Up directory - let i1: i32 = string_index_of(handle.text, path_sep); - let nested: bool = i1 > -1 && handle.text.length - 1 > i1; + let text: string = handle.text; + let i1: i32 = string_index_of(text, path_sep); + let nested: bool = i1 > -1 && text.length - 1 > i1; ///if krom_windows // Server addresses like \\server are not nested - nested = nested && !(handle.text.length >= 2 && char_at(handle.text, 0) == path_sep && char_at(handle.text, 1) == path_sep && string_last_index_of(handle.text, path_sep) == 1); + nested = nested && !(text.length >= 2 && char_at(text, 0) == path_sep && char_at(text, 1) == path_sep && string_last_index_of(text, path_sep) == 1); ///end if (nested) { array_push(ui_files_files, ".."); } - let dir_path: string = handle.text; + let dir_path: string = text; ///if krom_ios if (!is_cloud) { dir_path = document_directory + dir_path; @@ -178,7 +182,8 @@ function ui_files_file_browser(ui: zui_t, handle: zui_handle_t, folders_only: bo let files_all: string[] = file_read_directory(handle.text); let icon_file: string = substring(f, 0, string_last_index_of(f, ".")) + "_icon.jpg"; if (array_index_of(files_all, icon_file) >= 0) { - let empty: image_t = map_get(render_path_render_targets, "empty_black")._image; + let rt: render_target_t = map_get(render_path_render_targets, "empty_black"); + let empty: image_t = rt._image; map_set(ui_files_icon_map, handle.text + path_sep + f, empty); _ui_files_file_browser_handle = handle; @@ -193,7 +198,7 @@ function ui_files_file_browser(ui: zui_t, handle: zui_handle_t, folders_only: bo base_make_pipe_copy_rgb(); } let icon: image_t = image_create_render_target(image.width, image.height); - if (ends_with(f, ".arm")) { // Used for material sphere alpha cutout + if (ends_with(_ui_files_file_browser_f, ".arm")) { // Used for material sphere alpha cutout g2_begin(icon); ///if (is_paint || is_sculpt) @@ -226,7 +231,7 @@ function ui_files_file_browser(ui: zui_t, handle: zui_handle_t, folders_only: bo zui_fill(-2, 0, 2, w + 4, ui.ops.theme.HIGHLIGHT_COL); zui_fill(w + 2 , -2, 2, w + 6, ui.ops.theme.HIGHLIGHT_COL); } - state = zui_image(icon, 0xffffffff, w * zui_SCALE(ui)); + state = _zui_image(icon, 0xffffffff, w * zui_SCALE(ui)); if (ui.is_hovered) { zui_tooltip_image(icon); zui_tooltip(f); @@ -249,7 +254,7 @@ function ui_files_file_browser(ui: zui_t, handle: zui_handle_t, folders_only: bo ///else let buffer: buffer_t = krom_load_blob(blob_path); - let raw: any = armpack_decode(buffer); + let raw: project_format_t = armpack_decode(buffer); if (raw.material_icons != null) { let bytes_icon: any = raw.material_icons[0]; icon = image_from_bytes(lz4_decode(bytes_icon, 256 * 256 * 4), 256, 256); @@ -284,7 +289,7 @@ function ui_files_file_browser(ui: zui_t, handle: zui_handle_t, folders_only: bo zui_fill(-2, 0, 2, w + 4, ui.ops.theme.HIGHLIGHT_COL); zui_fill(w + 2 , -2, 2, w + 6, ui.ops.theme.HIGHLIGHT_COL); } - state = zui_image(icon, 0xffffffff, w * zui_SCALE(ui)); + state = _zui_image(icon, 0xffffffff, w * zui_SCALE(ui)); if (ui.is_hovered) { zui_tooltip_image(icon); zui_tooltip(f); @@ -301,16 +306,19 @@ function ui_files_file_browser(ui: zui_t, handle: zui_handle_t, folders_only: bo let shandle: string = handle.text + path_sep + f; icon = map_get(ui_files_icon_map, shandle); if (icon == null) { - let empty: image_t = map_get(render_path_render_targets, "empty_black")._image; + let rt: render_target_t = map_get(render_path_render_targets, "empty_black"); + let empty: image_t = rt._image; map_set(ui_files_icon_map, shandle, empty); let image: image_t = data_get_image(shandle); _ui_files_file_browser_shandle = shandle; + _ui_files_file_browser_w = w; app_notify_on_init(function (image: image_t) { if (base_pipe_copy_rgb == null) { base_make_pipe_copy_rgb(); } + let w: i32 = _ui_files_file_browser_w; 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; let icon: image_t = image_create_render_target(sw, sh); @@ -332,13 +340,13 @@ function ui_files_file_browser(ui: zui_t, handle: zui_handle_t, folders_only: bo zui_fill(-2, 0, 2, w + 4, ui.ops.theme.HIGHLIGHT_COL); zui_fill(w + 2 , -2, 2, w + 6, ui.ops.theme.HIGHLIGHT_COL); } - state = zui_image(icon, 0xffffffff, icon.height * zui_SCALE(ui)); + state = _zui_image(icon, 0xffffffff, icon.height * zui_SCALE(ui)); generic = false; } } if (generic) { - state = zui_image(icons, col, 50 * zui_SCALE(ui), rect.x, rect.y, rect.w, rect.h); + state = _zui_image(icons, col, 50 * zui_SCALE(ui), rect.x, rect.y, rect.w, rect.h); } if (ui.is_hovered && ui.input_released_r && context_menu != null) { @@ -371,15 +379,17 @@ function ui_files_file_browser(ui: zui_t, handle: zui_handle_t, folders_only: bo if (f == "..") { // Up handle.text = substring(handle.text, 0, string_last_index_of(handle.text, path_sep)); // Drive root - if (handle.text.length == 2 && char_at(handle.text, 1) == ":") { - handle.text += path_sep; + let text: string = handle.text; + if (text.length == 2 && char_at(text, 1) == ":") { + text += path_sep; } } else { - if (char_at(handle.text, handle.text.length - 1) != path_sep) { - handle.text += path_sep; + let text: string = handle.text; + if (char_at(text, text.length - 1) != path_sep) { + text += path_sep; } - handle.text += f; + text += f; } ui_files_selected = -1; } @@ -396,7 +406,7 @@ function ui_files_file_browser(ui: zui_t, handle: zui_handle_t, folders_only: bo label0 = substring(label0, 0, label0.length - 1); } if (label1 != "") { - ui.cur_ratio--; + ui.current_ratio--; } zui_text(label0, zui_align_t.CENTER); if (ui.is_hovered) { diff --git a/base/Sources/ui_header.ts b/base/Sources/ui_header.ts index c5b3884f..ef472db1 100644 --- a/base/Sources/ui_header.ts +++ b/base/Sources/ui_header.ts @@ -43,7 +43,8 @@ function ui_header_draw_tool_properties(ui: zui_t) { if (context_raw.tool == workspace_tool_t.COLORID) { zui_text(tr("Picked Color")); if (context_raw.colorid_picked) { - zui_image(map_get(render_path_render_targets, "texpaint_colorid")._image, 0xffffffff, 64); + let rt: render_target_t = map_get(render_path_render_targets, "texpaint_colorid"); + _zui_image(rt._image, 0xffffffff, 64); } ui.enabled = context_raw.colorid_picked; if (zui_button(tr("Clear"))) { @@ -59,13 +60,13 @@ function ui_header_draw_tool_properties(ui: zui_t) { context_raw.colorid_picked = false; ui_toolbar_handle.redraws = 1; } - zui_image(project_get_image(project_assets[cid])); + _zui_image(project_get_image(project_assets[cid])); if (ui.is_hovered) { zui_tooltip_image(project_get_image(project_assets[cid]), 256); } } if (zui_button(tr("Import"))) { - ui_files_show(path_texture_formats.join(","), false, true, function (path: string) { + ui_files_show(string_array_join(path_texture_formats, ","), false, true, function (path: string) { import_asset_run(path, -1.0, -1.0, true, false); context_raw.colorid_handle.position = project_asset_names.length - 1; @@ -97,7 +98,8 @@ function ui_header_draw_tool_properties(ui: zui_t) { } g4_begin(m.texpaint); g4_set_pipeline(base_pipe_colorid_to_mask); - g4_set_tex(base_texpaint_colorid,map_get(render_path_render_targets, "texpaint_colorid")._image); + let rt: render_target_t = map_get(render_path_render_targets, "texpaint_colorid"); + g4_set_tex(base_texpaint_colorid, rt._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); @@ -148,7 +150,7 @@ function ui_header_draw_tool_properties(ui: zui_t) { ui_menu_draw(function (ui: zui_t) { zui_fill(0, 0, ui._w / zui_SCALE(ui), ui.ops.theme.ELEMENT_H * 9, ui.ops.theme.SEPARATOR_COL); ui.changed = false; - zui_color_wheel(_ui_header_draw_tool_properties_h, false, null, 10 * ui.ops.theme.ELEMENT_H * zui_SCALE(ui), false); + zui_color_wheel(_ui_header_draw_tool_properties_h, false, -1, 10 * ui.ops.theme.ELEMENT_H * zui_SCALE(ui), false); if (ui.changed) { ui_menu_keep_open = true; } @@ -234,7 +236,7 @@ function ui_header_draw_tool_properties(ui: zui_t) { array_push(bakes, tr("Thickness")); } else { - bakes.shift(); // Remove AO + array_shift(bakes); // Remove AO } ///end @@ -469,7 +471,7 @@ function ui_header_draw_tool_properties(ui: zui_t) { let h: zui_handle_t = zui_handle(__ID__); h.text = context_raw.text_tool_text; let w: i32 = ui._w; - if (ui.text_selected_handle_ptr == h.ptr || ui.submit_text_handle_ptr == h.ptr) { + if (ui.text_selected_handle == h || ui.submit_text_handle == h) { ui._w *= 3; } @@ -542,7 +544,10 @@ function ui_header_draw_tool_properties(ui: zui_t) { 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")); + let x: string = tr("X"); + let y: string = tr("Y"); + let z: string = tr("Z"); + zui_text(x + y + z); } else { ui._w = math_floor(56 * sc); diff --git a/base/Sources/ui_menu.ts b/base/Sources/ui_menu.ts index ffcefb57..5b2d1084 100644 --- a/base/Sources/ui_menu.ts +++ b/base/Sources/ui_menu.ts @@ -13,6 +13,11 @@ let ui_menu_hide_flag: bool = false; let _ui_menu_render_msg: string; +type update_info_t = { + version: i32; + version_name: string; +}; + function ui_menu_render() { let ui: zui_t = base_ui_menu; let menu_w: i32 = ui_menu_commands != null ? math_floor(base_default_element_w * zui_SCALE(base_ui_menu) * 2.3) : math_floor(zui_ELEMENT_W(ui) * 2.3); @@ -54,7 +59,7 @@ function ui_menu_render() { } ui_menu_separator(ui); if (ui_menu_button(ui, tr("Import Texture..."), map_get(config_keymap, "file_import_assets"))) { - project_import_asset(path_texture_formats.join(","), false); + project_import_asset(string_array_join(path_texture_formats, ","), false); } if (ui_menu_button(ui, tr("Import Envmap..."))) { ui_files_show("hdr", false, false, function (path: string) { @@ -245,7 +250,7 @@ function ui_menu_render() { ///if (is_paint || is_sculpt) ui_menu_fill(ui); - let split_view_handle = zui_handle(__ID__); + let split_view_handle: zui_handle_t = zui_handle(__ID__); if (split_view_handle.init) { split_view_handle.selected = context_raw.split_view; } @@ -459,7 +464,8 @@ function ui_menu_render() { ui_menu_align(ui); let camera_controls_handle: zui_handle_t = zui_handle(__ID__); 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 camera_controls_items: string[] = [tr("Orbit"), tr("Rotate"), tr("Fly")]; + context_raw.camera_controls = zui_inline_radio(camera_controls_handle, camera_controls_items, zui_align_t.LEFT); let vars: map_t = map_create(); map_set(vars, "rotate_shortcut", map_get(config_keymap, "action_rotate")); @@ -473,7 +479,8 @@ function ui_menu_render() { ui_menu_fill(ui); ui_menu_align(ui); - context_raw.camera_type = zui_inline_radio(context_raw.cam_handle, [tr("Perspective"), tr("Orthographic")], zui_align_t.LEFT); + let camera_type_items: string[] = [tr("Perspective"), tr("Orthographic")]; + context_raw.camera_type = zui_inline_radio(context_raw.cam_handle, camera_type_items, zui_align_t.LEFT); if (ui.is_hovered) { zui_tooltip(tr("Camera Type") + " (" + map_get(config_keymap, "view_camera_type") + ")"); } @@ -524,7 +531,7 @@ function ui_menu_render() { file_download_bytes("https://server.armorpaint.org/" + to_lower_case(manifest_title) + ".html", function (url: string, buffer: buffer_t) { if (buffer != null) { // Compare versions - let update: any = json_parse(sys_buffer_to_string(buffer)); + let update: update_info_t = json_parse(sys_buffer_to_string(buffer)); let update_version: i32 = math_floor(update.version); if (update_version > 0) { let date: string = config_get_date(); // 2019 -> 19 @@ -585,7 +592,7 @@ function ui_menu_render() { if (zui_tab(zui_handle(__ID__), tr("About"), tab_vertical)) { let img: image_t = data_get_image("badge.k"); - zui_image(img); + _zui_image(img); zui_end_element(); let h: zui_handle_t = zui_handle(__ID__); @@ -617,7 +624,7 @@ function ui_menu_render() { } } - ui_menu_hide_flag = ui.combo_selected_handle_ptr == 0 && !ui_menu_keep_open && !ui_menu_show_first && (ui.changed || ui.input_released || ui.input_released_r || ui.is_escape_down); + ui_menu_hide_flag = ui.combo_selected_handle == null && !ui_menu_keep_open && !ui_menu_show_first && (ui.changed || ui.input_released || ui.input_released_r || ui.is_escape_down); ui_menu_show_first = false; ui_menu_keep_open = false; diff --git a/base/Sources/ui_menubar.ts b/base/Sources/ui_menubar.ts index ebc8575f..f59d3367 100644 --- a/base/Sources/ui_menubar.ts +++ b/base/Sources/ui_menubar.ts @@ -208,5 +208,5 @@ function ui_menubar_icon_button(ui: zui_t, i: i32, j: i32): bool { let icon_accent: i32 = light ? 0xff666666 : 0xffaaaaaa; let img: image_t = resource_get("icons.k"); let rect: rect_t = resource_tile50(img, i, j); - return zui_image(img, icon_accent, -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/ui_nodes.ts b/base/Sources/ui_nodes.ts index 23a45efb..b910a77c 100644 --- a/base/Sources/ui_nodes.ts +++ b/base/Sources/ui_nodes.ts @@ -12,7 +12,7 @@ let ui_nodes_ww: i32; let ui_nodes_wh: i32; let ui_nodes_ui: zui_t; -let ui_nodes_canvas_type = canvas_type_t.MATERIAL; +let ui_nodes_canvas_type: canvas_type_t = canvas_type_t.MATERIAL; let ui_nodes_show_menu: bool = false; let ui_nodes_show_menu_first: bool = true; let ui_nodes_hide_menu: bool = false; @@ -36,17 +36,17 @@ let ui_nodes_group_stack: node_group_t[] = []; let ui_nodes_controls_down: bool = false; function ui_nodes_init() { - zui_set_on_link_drag(ui_nodes_on_link_drag); - zui_set_on_socket_released(ui_nodes_on_socket_released); - zui_set_on_canvas_released(ui_nodes_on_canvas_released); - zui_set_on_canvas_control(ui_nodes_on_canvas_control); + zui_nodes_on_link_drag = ui_nodes_on_link_drag; + zui_nodes_on_socket_released = ui_nodes_on_socket_released; + zui_nodes_on_canvas_released = ui_nodes_on_canvas_released; + zui_nodes_on_canvas_control = ui_nodes_on_canvas_control; let scale: f32 = config_raw.window_scale; let ops: zui_options_t = { theme: base_theme, - font: base_font, - color_wheel: base_color_wheel, - black_white_gradient: base_color_wheel_gradient, + font: base_font.font_, + color_wheel: base_color_wheel.texture_, + black_white_gradient: base_color_wheel_gradient.texture_, scale_factor: scale }; ui_nodes_ui = zui_create(ops); @@ -54,32 +54,37 @@ function ui_nodes_init() { } let _ui_nodes_on_link_drag_link_drag: zui_node_link_t; +let _ui_nodes_on_link_drag_node: zui_node_t; function ui_nodes_on_link_drag(link_drag_id: i32, is_new_link: bool) { if (is_new_link) { - let nodes: zui_nodes_t = ui_nodes_get_nodes(); - let link_drag: zui_node_link_t = zui_get_link(ui_nodes_get_canvas(true).links, link_drag_id); - let node: zui_node_t = zui_get_node(ui_nodes_get_canvas(true).nodes, link_drag.from_id > -1 ? link_drag.from_id : link_drag.to_id); + let ui_nodes: zui_nodes_t = ui_nodes_get_nodes(); + let links: zui_node_link_t[] = ui_nodes_get_canvas(true).links; + let link_drag: zui_node_link_t = zui_get_link(links.buffer, links.length, link_drag_id); + let nodes: zui_node_t[] = ui_nodes_get_canvas(true).nodes; + let node: zui_node_t = zui_get_node(nodes.buffer, nodes.length, link_drag.from_id > -1 ? link_drag.from_id : link_drag.to_id); let link_x: i32 = ui_nodes_ui._window_x + zui_nodes_NODE_X(node); let link_y: i32 = ui_nodes_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); + link_y += zui_nodes_OUTPUT_Y(node.outputs.length, link_drag.from_socket); } else { - link_y += zui_nodes_INPUT_Y(ui_nodes_get_canvas(true), node.inputs, link_drag.to_socket) + zui_nodes_OUTPUTS_H(node.outputs) + zui_nodes_BUTTONS_H(node); + link_y += zui_nodes_INPUT_Y(ui_nodes_get_canvas(true), node.inputs, link_drag.to_socket) + zui_nodes_OUTPUTS_H(node.outputs.length) + zui_nodes_BUTTONS_H(node); } if (math_abs(mouse_x - link_x) > 5 || math_abs(mouse_y - link_y) > 5) { // Link length _ui_nodes_on_link_drag_link_drag = link_drag; + _ui_nodes_on_link_drag_node = node; ui_nodes_node_search(-1, -1, function () { + let ui_nodes: zui_nodes_t = ui_nodes_get_nodes(); let link_drag: zui_node_link_t = _ui_nodes_on_link_drag_link_drag; - - let n: zui_node_t = zui_get_node(ui_nodes_get_canvas(true).nodes, nodes.nodes_selected_id[0]); + let nodes: zui_node_t[] = ui_nodes_get_canvas(true).nodes; + let n: zui_node_t = zui_get_node(nodes.buffer, nodes.length, ui_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; + let from_type: string = _ui_nodes_on_link_drag_node.outputs[link_drag.from_socket].type; // Connect to the first socket link_drag.to_socket = 0; // Try to find the first type-matching socket and use it if present @@ -104,7 +109,7 @@ function ui_nodes_on_link_drag(link_drag_id: i32, is_new_link: bool) { }); } // Selecting which node socket to preview - else if (node.id == nodes.nodes_selected_id[0]) { + else if (node.id == ui_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; @@ -129,7 +134,7 @@ function ui_nodes_on_socket_released(socket_id: i32) { let nodes: zui_nodes_t = ui_nodes_get_nodes(); let canvas: zui_node_canvas_t = ui_nodes_get_canvas(true); let socket: zui_node_socket_t = zui_get_socket(canvas.nodes, socket_id); - let node: zui_node_t = zui_get_node(canvas.nodes, socket.node_id); + let node: zui_node_t = zui_get_node(canvas.nodes.buffer, canvas.nodes.length, socket.node_id); if (ui_nodes_ui.input_released_r) { if (node.type == "GROUP_INPUT" || node.type == "GROUP_OUTPUT") { @@ -176,7 +181,7 @@ function ui_nodes_on_socket_released(socket_id: i32) { let name: string = zui_text_input(_ui_nodes_hname, tr("Name")); let min: f32 = zui_float_input(_ui_nodes_hmin, tr("Min")); let max: f32 = zui_float_input(_ui_nodes_hmax, tr("Max")); - let default_value: any = null; + let default_value: f32_array_t = null; if (type == 0) { let row: f32[] = [1 / 4, 1 / 4, 1 / 4, 1 / 4]; zui_row(row); @@ -195,7 +200,8 @@ function ui_nodes_on_socket_released(socket_id: i32) { default_value = f32_array_create_xyz(_ui_nodes_hval0.value, _ui_nodes_hval1.value, _ui_nodes_hval2.value); } else { - default_value = zui_float_input(_ui_nodes_hval0, tr("default_value")); + let f: f32 = zui_float_input(_ui_nodes_hval0, tr("default_value")); + default_value = f32_array_create_x(f); } if (zui_button(tr("OK"))) { // || ui.isReturnDown socket.name = name; @@ -214,6 +220,7 @@ function ui_nodes_on_socket_released(socket_id: i32) { } if (ui_menu_button(ui, tr("Delete"))) { let i: i32 = 0; + let canvas: zui_node_canvas_t = ui_nodes_get_canvas(true); // Remove links connected to the socket while (i < canvas.links.length) { let l: zui_node_link_t = canvas.links[i]; @@ -257,7 +264,7 @@ function ui_nodes_on_canvas_released() { let selected: zui_node_t = null; for (let i: i32 = 0; i < canvas.nodes.length; ++i) { let node: zui_node_t = canvas.nodes[i]; - if (zui_get_input_in_rect(ui_nodes_ui._window_x + zui_nodes_NODE_X(node), ui_nodes_ui._window_y + zui_nodes_NODE_Y(node), zui_nodes_NODE_W(node), zui_nodes_NODE_H(canvas, node))) { + if (zui_input_in_rect(ui_nodes_ui._window_x + zui_nodes_NODE_X(node), ui_nodes_ui._window_y + zui_nodes_NODE_Y(node), zui_nodes_NODE_W(node), zui_nodes_NODE_H(canvas, node))) { selected = node; break; } @@ -270,7 +277,7 @@ function ui_nodes_on_canvas_released() { } // Node context menu - if (!zui_socket_released()) { + if (!zui_nodes_socket_released) { let number_of_entries: i32 = 5; if (ui_nodes_canvas_type == canvas_type_t.MATERIAL) { ++number_of_entries; @@ -297,14 +304,14 @@ function ui_nodes_on_canvas_released() { if (ui_menu_button(ui_menu, tr("Cut"), "ctrl+x")) { app_notify_on_next_frame(function () { ui_nodes_hwnd.redraws = 2; - zui_set_is_copy(true); - zui_set_is_cut(true); + zui_is_copy = true; + zui_is_cut = true; ui_nodes_is_node_menu_op = true; }); } if (ui_menu_button(ui_menu, tr("Copy"), "ctrl+c")) { app_notify_on_next_frame(function () { - zui_set_is_copy(true); + zui_is_copy = true; ui_nodes_is_node_menu_op = true; }); } @@ -312,7 +319,7 @@ function ui_nodes_on_canvas_released() { if (ui_menu_button(ui_menu, tr("Paste"), "ctrl+v")) { app_notify_on_next_frame(function () { ui_nodes_hwnd.redraws = 2; - zui_set_is_paste(true); + zui_is_paste = true; ui_nodes_is_node_menu_op = true; }); } @@ -327,14 +334,14 @@ function ui_nodes_on_canvas_released() { if (ui_menu_button(ui_menu, tr("Duplicate"))) { app_notify_on_next_frame(function () { ui_nodes_hwnd.redraws = 2; - zui_set_is_copy(true); - zui_set_is_paste(true); + zui_is_copy = true; + zui_is_paste = true; ui_nodes_is_node_menu_op = true; }); } if (selected != null && selected.type == "RGB") { if (ui_menu_button(ui_menu, tr("Add Swatch"))) { - let color: any = selected.outputs[0].default_value; + let color: f32_array_t = selected.outputs[0].default_value; let new_swatch: swatch_color_t = make_swatch(color_from_floats(color[0], color[1], color[2], color[3])); context_set_swatch(new_swatch); array_push(project_raw.swatches, new_swatch); @@ -359,7 +366,7 @@ function ui_nodes_on_canvas_released() { let canvas: zui_node_canvas_t = ui_nodes_get_canvas(true); for (let i: i32 = 0; i < canvas.nodes.length; ++i) { let node: zui_node_t = canvas.nodes[i]; - if (zui_get_input_in_rect(ui_nodes_ui._window_x + zui_nodes_NODE_X(node), ui_nodes_ui._window_y + zui_nodes_NODE_Y(node), zui_nodes_NODE_W(node), zui_nodes_NODE_H(canvas, node))) { + if (zui_input_in_rect(ui_nodes_ui._window_x + zui_nodes_NODE_X(node), ui_nodes_ui._window_y + zui_nodes_NODE_Y(node), zui_nodes_NODE_W(node), zui_nodes_NODE_H(canvas, node))) { if (node.id == nodes.nodes_selected_id[0]) { ui_view2d_hwnd.redraws = 2; if (time_time() - context_raw.select_time < 0.25) ui_base_show_2d_view(view_2d_type_t.NODE); @@ -410,12 +417,13 @@ function ui_nodes_get_canvas_control(ui: zui_t, controls_down: bool): zui_canvas controls_down = false; } if (!controls_down) { - return { + let cc: zui_canvas_control_t = { pan_x: 0, pan_y: 0, zoom: 0, controls_down: controls_down - } + }; + return cc; } let pan: bool = ui.input_down_r || operator_shortcut(map_get(config_keymap, "action_pan"), shortcut_type_t.DOWN); @@ -528,28 +536,32 @@ function ui_nodes_update() { let nodes: zui_nodes_t = ui_nodes_get_nodes(); if (nodes.nodes_selected_id.length > 0 && ui_nodes_ui.is_key_pressed) { - if (ui_nodes_ui.key == key_code_t.LEFT) { + if (ui_nodes_ui.key_code == key_code_t.LEFT) { for (let i: i32 = 0; i < nodes.nodes_selected_id.length; ++i) { let n: i32 = nodes.nodes_selected_id[i]; - zui_get_node(ui_nodes_get_canvas(true).nodes, n).x -= 1; + let nodes: zui_node_t[] = ui_nodes_get_canvas(true).nodes; + zui_get_node(nodes.buffer, nodes.length, n).x -= 1; } } - else if (ui_nodes_ui.key == key_code_t.RIGHT) { + else if (ui_nodes_ui.key_code == key_code_t.RIGHT) { for (let i: i32 = 0; i < nodes.nodes_selected_id.length; ++i) { let n: i32 = nodes.nodes_selected_id[i]; - zui_get_node(ui_nodes_get_canvas(true).nodes, n).x += 1; + let nodes: zui_node_t[] = ui_nodes_get_canvas(true).nodes; + zui_get_node(nodes.buffer, nodes.length, n).x += 1; } } - if (ui_nodes_ui.key == key_code_t.UP) { + if (ui_nodes_ui.key_code == key_code_t.UP) { for (let i: i32 = 0; i < nodes.nodes_selected_id.length; ++i) { let n: i32 = nodes.nodes_selected_id[i]; - zui_get_node(ui_nodes_get_canvas(true).nodes, n).y -= 1; + let nodes: zui_node_t[] = ui_nodes_get_canvas(true).nodes; + zui_get_node(nodes.buffer, nodes.length, n).y -= 1; } } - else if (ui_nodes_ui.key == key_code_t.DOWN) { + else if (ui_nodes_ui.key_code == key_code_t.DOWN) { for (let i: i32 = 0; i < nodes.nodes_selected_id.length; ++i) { let n: i32 = nodes.nodes_selected_id[i]; - zui_get_node(ui_nodes_get_canvas(true).nodes, n).y += 1; + let nodes: zui_node_t[] = ui_nodes_get_canvas(true).nodes; + zui_get_node(nodes.buffer, nodes.length, n).y += 1; } } } @@ -601,10 +613,10 @@ function ui_nodes_node_search(x: i32 = -1, y: i32 = -1, done: ()=>void = null) { } if (ui.is_key_pressed) { // Move selection - if (ui.key == key_code_t.DOWN && ui_nodes_node_search_offset < 6) { + if (ui.key_code == key_code_t.DOWN && ui_nodes_node_search_offset < 6) { ui_nodes_node_search_offset++; } - if (ui.key == key_code_t.UP && ui_nodes_node_search_offset > 0) { + if (ui.key_code == key_code_t.UP && ui_nodes_node_search_offset > 0) { ui_nodes_node_search_offset--; } } @@ -613,10 +625,10 @@ function ui_nodes_node_search(x: i32 = -1, y: i32 = -1, done: ()=>void = null) { let BUTTON_COL: i32 = ui.ops.theme.BUTTON_COL; ///if (is_paint || is_sculpt) - let node_list: zui_node_t[][] = ui_nodes_canvas_type == canvas_type_t.MATERIAL ? nodes_material_list : nodes_brush_list; + let node_list: node_list_t[] = ui_nodes_canvas_type == canvas_type_t.MATERIAL ? nodes_material_list : nodes_brush_list; ///end ///if is_lab - let node_list: zui_node_t[][] = nodes_brush_list; + let node_list: node_list_t[] = nodes_brush_list; ///end for (let i: i32 = 0; i < node_list.length; ++i) { @@ -784,7 +796,7 @@ function ui_nodes_render() { // Remove dragged link when mouse is released out of the node viewport let c: zui_node_canvas_t = ui_nodes_get_canvas(true); if (ui_nodes_release_link && nodes.link_drag_id != -1) { - array_remove(c.links, zui_get_link(c.links, nodes.link_drag_id)); + array_remove(c.links, zui_get_link(c.links.buffer, c.links.length, nodes.link_drag_id)); nodes.link_drag_id = -1; } ui_nodes_release_link = ui_nodes_ui.input_released; @@ -853,7 +865,9 @@ function ui_nodes_render() { // Grid g2_set_color(0xffffffff); let step: f32 = 100 * zui_SCALE(ui_nodes_ui); - g2_draw_image(ui_nodes_grid, (nodes.pan_x * zui_nodes_SCALE()) % step - step, (nodes.pan_y * zui_nodes_SCALE()) % step - step); + let x: f32 = math_fmod(nodes.pan_x * zui_nodes_SCALE(), step) - step; + let y: f32 = math_fmod(nodes.pan_y * zui_nodes_SCALE(), step) - step; + g2_draw_image(ui_nodes_grid, x, y); // Undo if (ui_nodes_ui.input_started || ui_nodes_ui.is_key_pressed) { @@ -869,7 +883,7 @@ function ui_nodes_render() { ui_nodes_ui.window_border_top = ui_header_h * 2; ui_nodes_ui.window_border_bottom = config_raw.layout[layout_size_t.STATUS_H]; - zui_node_canvas(nodes, ui_nodes_ui, c); + zui_node_canvas(nodes, c); ui_nodes_ui.input_enabled = _input_enabled; if (nodes.color_picker_callback != null) { @@ -896,18 +910,18 @@ function ui_nodes_render() { } // Remove nodes with unknown id for this canvas type - if (zui_is_paste()) { + if (zui_is_paste) { ///if (is_paint || is_sculpt) - let node_list: zui_node_t[][] = ui_nodes_canvas_type == canvas_type_t.MATERIAL ? nodes_material_list : nodes_brush_list; + let node_list: node_list_t[] = ui_nodes_canvas_type == canvas_type_t.MATERIAL ? nodes_material_list : nodes_brush_list; ///end ///if is_lab - let node_list: zui_node_t[][] = nodes_brush_list; + let node_list: node_list_t[] = nodes_brush_list; ///end let i: i32 = 0; while (i++ < c.nodes.length) { let canvas_node: zui_node_t = c.nodes[i - 1]; - if (array_index_of(zui_exclude_remove, canvas_node.type) >= 0) { + if (array_index_of(zui_nodes_exclude_remove, canvas_node.type) >= 0) { continue; } let found: bool = false; @@ -936,9 +950,9 @@ function ui_nodes_render() { } if (ui_nodes_is_node_menu_op) { - zui_set_is_copy(false); - zui_set_is_cut(false); - zui_set_is_paste(false); + zui_is_copy = false; + zui_is_cut = false; + zui_is_paste = false; ui_nodes_ui.is_delete_down = false; } @@ -960,13 +974,13 @@ function ui_nodes_render() { // Node previews 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.nodes_selected_id[0]); + let sel: zui_node_t = zui_get_node(c.nodes.buffer, c.nodes.length, nodes.nodes_selected_id[0]); ///if (is_paint || is_sculpt) let single_channel: bool = sel.type == "LAYER_MASK"; if (sel.type == "LAYER" || sel.type == "LAYER_MASK") { - let id: any = sel.buttons[0].default_value; + let id: i32 = sel.buttons[0].default_value[0]; if (id < project_layers.length) { ///if is_paint img = project_layers[id].texpaint_preview; @@ -974,7 +988,7 @@ function ui_nodes_render() { } } else if (sel.type == "MATERIAL") { - let id: any = sel.buttons[0].default_value; + let id: i32 = sel.buttons[0].default_value[0]; if (id < project_materials.length) { img = project_materials[id].image; } @@ -1150,7 +1164,7 @@ function ui_nodes_render() { // Close node group if (ui_nodes_group_stack.length > 0 && zui_menu_button(tr("Close"))) { - ui_nodes_group_stack.pop(); + array_pop(ui_nodes_group_stack); } } @@ -1160,13 +1174,14 @@ function ui_nodes_render() { if (ui_nodes_show_menu) { ///if (is_paint || is_sculpt) - let list:zui_node_t[][] = ui_nodes_canvas_type == canvas_type_t.MATERIAL ? nodes_material_list : nodes_brush_list; + let list: node_list_t[] = ui_nodes_canvas_type == canvas_type_t.MATERIAL ? nodes_material_list : nodes_brush_list; ///end ///if is_lab - let list:zui_node_t[][] = nodes_brush_list; + let list: node_list_t[] = nodes_brush_list; ///end - let num_nodes: i32 = list[ui_nodes_menu_category].length; + let category: zui_node_t[] = list[ui_nodes_menu_category]; + let num_nodes: i32 = category.length; ///if (is_paint || is_sculpt) let is_group_category: bool = ui_nodes_canvas_type == canvas_type_t.MATERIAL && nodes_material_categories[ui_nodes_menu_category] == "Group"; @@ -1175,7 +1190,9 @@ function ui_nodes_render() { let is_group_category: bool = nodes_material_categories[ui_nodes_menu_category] == "Group"; ///end - if (is_group_category) num_nodes += project_material_groups.length; + if (is_group_category) { + num_nodes += project_material_groups.length; + } let py: i32 = ui_nodes_popup_y; let menuw: i32 = math_floor(ew * 2.3); @@ -1189,8 +1206,8 @@ function ui_nodes_render() { ui_menu_start(ui_nodes_ui); - for (let i: i32 = 0; i < list[ui_nodes_menu_category].length; ++i) { - let n: zui_node_t = list[ui_nodes_menu_category][i]; + for (let i: i32 = 0; i < category.length; ++i) { + let n: zui_node_t = category[i]; if (ui_menu_button(ui_nodes_ui, tr(n.name))) { ui_nodes_push_undo(); let canvas: zui_node_canvas_t = ui_nodes_get_canvas(true); @@ -1240,7 +1257,7 @@ function ui_nodes_render() { } } - ui_nodes_hide_menu = ui_nodes_ui.combo_selected_handle_ptr == 0 && !ui_nodes_show_menu_first && (ui_nodes_ui.changed || ui_nodes_ui.input_released || ui_nodes_ui.input_released_r || ui_nodes_ui.is_escape_down); + ui_nodes_hide_menu = ui_nodes_ui.combo_selected_handle == null && !ui_nodes_show_menu_first && (ui_nodes_ui.changed || ui_nodes_ui.input_released || ui_nodes_ui.input_released_r || ui_nodes_ui.is_escape_down); ui_nodes_show_menu_first = false; ui_nodes_ui.ops.theme.BUTTON_COL = _BUTTON_COL; @@ -1298,7 +1315,10 @@ function ui_nodes_push_undo(last_canvas: zui_node_canvas_t = null) { if (last_canvas == null) { last_canvas = ui_nodes_get_canvas(true); } - let canvas_group: i32 = ui_nodes_group_stack.length > 0 ? array_index_of(project_material_groups, ui_nodes_group_stack[ui_nodes_group_stack.length - 1]) : null; + let canvas_group: i32 = -1; + if (ui_nodes_group_stack.length > 0) { + canvas_group = array_index_of(project_material_groups, ui_nodes_group_stack[ui_nodes_group_stack.length - 1]); + } ///if (is_paint || is_sculpt) ui_base_hwnds[tab_area_t.SIDEBAR0].redraws = 2; @@ -1365,7 +1385,7 @@ function ui_nodes_accept_swatch_drag(swatch: swatch_color_t) { function ui_nodes_make_node(n: zui_node_t, nodes: zui_nodes_t, canvas: zui_node_canvas_t): zui_node_t { let node: zui_node_t = {}; - node.id = zui_get_node_id(canvas.nodes); + node.id = zui_next_node_id(canvas.nodes.buffer, canvas.nodes.length); node.name = n.name; node.type = n.type; node.x = ui_nodes_get_node_x(); @@ -1378,8 +1398,8 @@ function ui_nodes_make_node(n: zui_node_t, nodes: zui_nodes_t, canvas: zui_node_ let count: i32 = 0; for (let i: i32 = 0; i < n.inputs.length; ++i) { - let soc: zui_node_socket_t = {} - soc.id = zui_get_socket_id(canvas.nodes) + count; + let soc: zui_node_socket_t = {}; + soc.id = zui_get_socket_id(canvas.nodes.buffer, canvas.nodes.length) + count; count++; soc.node_id = node.id; soc.name = n.inputs[i].name; @@ -1395,7 +1415,7 @@ function ui_nodes_make_node(n: zui_node_t, nodes: zui_nodes_t, canvas: zui_node_ for (let i: i32 = 0; i < n.outputs.length; ++i) { let soc: zui_node_socket_t = {}; - soc.id = zui_get_socket_id(canvas.nodes) + count; + soc.id = zui_get_socket_id(canvas.nodes.buffer, canvas.nodes.length) + count; count++; soc.node_id = node.id; soc.name = n.outputs[i].name; @@ -1427,10 +1447,11 @@ function ui_nodes_make_node(n: zui_node_t, nodes: zui_nodes_t, canvas: zui_node_ } function ui_nodes_make_group_node(group_canvas: zui_node_canvas_t, nodes: zui_nodes_t, canvas: zui_node_canvas_t): zui_node_t { - let n: zui_node_t = nodes_material_list[5][0]; + let category: zui_node_t[] = nodes_material_list[5]; + let n: zui_node_t = category[0]; let node: zui_node_t = json_parse(json_stringify(n)); node.name = group_canvas.name; - node.id = zui_get_node_id(canvas.nodes); + node.id = zui_next_node_id(canvas.nodes.buffer, canvas.nodes.length); node.x = ui_nodes_get_node_x(); node.y = ui_nodes_get_node_y(); let group_input: zui_node_t = null; @@ -1465,12 +1486,13 @@ function ui_nodes_make_group_node(group_canvas: zui_node_canvas_t, nodes: zui_no ///if (is_paint || is_sculpt) function ui_nodes_make_node_preview() { - let nodes: zui_nodes_t = context_raw.material.nodes; - if (nodes.nodes_selected_id.length == 0) { + let ui_nodes: zui_nodes_t = context_raw.material.nodes; + if (ui_nodes.nodes_selected_id.length == 0) { return; } - let node: zui_node_t = zui_get_node(context_raw.material.canvas.nodes, nodes.nodes_selected_id[0]); + let nodes: zui_node_t[] = context_raw.material.canvas.nodes; + let node: zui_node_t = zui_get_node(nodes.buffer, nodes.length, ui_nodes.nodes_selected_id[0]); // if (node == null) return; context_raw.node_preview_name = node.name; @@ -1481,7 +1503,7 @@ function ui_nodes_make_node_preview() { return; } - if (array_index_of(context_raw.material.canvas.nodes, node) == -1) { + if (array_index_of(nodes, node) == -1) { return; } diff --git a/base/Sources/ui_status.ts b/base/Sources/ui_status.ts index 27bd13b5..598b34c8 100644 --- a/base/Sources/ui_status.ts +++ b/base/Sources/ui_status.ts @@ -27,16 +27,18 @@ function ui_status_render_ui() { g2_fill_rect(ui._window_w - 1, 0, 1, ui._window_h); // Draw tabs - for (let i: i32 = 0; i < ui_base_hwnd_tabs[tab_area_t.STATUS].length; ++i) { - let draw: any = ui_base_hwnd_tabs[tab_area_t.STATUS][i]; - draw(ui_base_htabs[tab_area_t.STATUS]); + let hwnd_draws: tab_draw_t[] = ui_base_hwnd_tabs[tab_area_t.STATUS]; + let htab: zui_handle_t = ui_base_htabs[tab_area_t.STATUS]; + for (let i: i32 = 0; i < hwnd_draws.length; ++i) { + let draw: tab_draw_t = hwnd_draws[i]; + draw.f(htab); } let minimized: bool = statush <= ui_status_default_status_h * config_raw.window_scale; - if (ui_base_htabs[tab_area_t.STATUS].changed && (ui_base_htabs[tab_area_t.STATUS].position == context_raw.last_status_position || minimized)) { + if (htab.changed && (htab.position == context_raw.last_status_position || minimized)) { ui_base_toggle_browser(); } - context_raw.last_status_position = ui_base_htabs[tab_area_t.STATUS].position; + context_raw.last_status_position = htab.position; } } diff --git a/base/Sources/ui_toolbar.ts b/base/Sources/ui_toolbar.ts index ceedb7c4..57729c85 100644 --- a/base/Sources/ui_toolbar.ts +++ b/base/Sources/ui_toolbar.ts @@ -39,7 +39,7 @@ function ui_toolbar_draw_tool(i: i32, ui: zui_t, img: image_t, icon_accent: i32, let rect: rect_t = resource_tile50(img, tile_x, tile_y); let _y: i32 = ui._y; - let image_state: zui_state_t = zui_image(img, icon_accent, -1.0, rect.x, rect.y, rect.w, rect.h); + 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) { _ui_toolbar_i = i; app_notify_on_next_frame(function() { @@ -55,7 +55,8 @@ function ui_toolbar_draw_tool(i: i32, ui: zui_t, img: image_t, icon_accent: i32, ///if is_paint if (i == workspace_tool_t.COLORID && context_raw.colorid_picked) { - g2_draw_scaled_sub_image(map_get(render_path_render_targets, "texpaint_colorid")._image, 0, 0, 1, 1, 0, _y + 1.5 * zui_SCALE(ui), 5 * zui_SCALE(ui), 34 * zui_SCALE(ui)); + let rt: render_target_t = map_get(render_path_render_targets, "texpaint_colorid"); + g2_draw_scaled_sub_image(rt._image, 0, 0, 1, 1, 0, _y + 1.5 * zui_SCALE(ui), 5 * zui_SCALE(ui), 34 * zui_SCALE(ui)); } ///end @@ -93,7 +94,7 @@ function ui_toolbar_render_ui() { // Properties icon if (config_raw.layout[layout_size_t.HEADER] == 1) { let rect: rect_t = resource_tile50(img, 7, 1); - if (zui_image(img, light ? 0xff666666 : ui.ops.theme.BUTTON_COL, -1.0, rect.x, rect.y, rect.w, rect.h) == zui_state_t.RELEASED) { + if (_zui_image(img, light ? 0xff666666 : ui.ops.theme.BUTTON_COL, -1.0, rect.x, rect.y, rect.w, rect.h) == zui_state_t.RELEASED) { config_raw.layout[layout_size_t.HEADER] = 0; } } @@ -136,21 +137,51 @@ function ui_toolbar_render_ui() { let vars_clone: map_t = map_create(); map_set(vars_clone, "key", map_get(config_keymap, "set_clone_source")); + let key_tool_brush: string = map_get(config_keymap, "tool_brush"); + let key_tool_eraser: string = map_get(config_keymap, "tool_eraser"); + let key_tool_fill: string = map_get(config_keymap, "tool_fill"); + let key_tool_decal: string = map_get(config_keymap, "tool_decal"); + let key_tool_text: string = map_get(config_keymap, "tool_text"); + let key_tool_clone: string = map_get(config_keymap, "tool_clone"); + let key_tool_blur: string = map_get(config_keymap, "tool_blur"); + let key_tool_smudge: string = map_get(config_keymap, "tool_smudge"); + let key_tool_particle: string = map_get(config_keymap, "tool_particle"); + let key_tool_colorid: string = map_get(config_keymap, "tool_colorid"); + let key_tool_picker: string = map_get(config_keymap, "tool_picker"); + let key_tool_bake: string = map_get(config_keymap, "tool_bake"); + let key_tool_gizmo: string = map_get(config_keymap, "tool_gizmo"); + let key_tool_material: string = map_get(config_keymap, "tool_material"); + + key_tool_brush = "(" + key_tool_brush + ") - " + tr("Hold {action_paint} to paint\nHold {key} and press {action_paint} to paint a straight line (ruler mode)", vars_brush); + key_tool_eraser = "(" + key_tool_eraser + ") - " + tr("Hold {action_paint} to erase\nHold {key} and press {action_paint} to erase a straight line (ruler mode)", vars_brush); + key_tool_fill = "(" + key_tool_fill + ")"; + key_tool_decal = "(" + key_tool_decal + ") - " + tr("Hold {key} to paint on a decal mask", vars_decal); + key_tool_text = "(" + key_tool_text + ") - " + tr("Hold {key} to use the text as a mask", vars_decal); + key_tool_clone = "(" + key_tool_clone + ") - " + tr("Hold {key} to set source", vars_clone); + key_tool_blur = "(" + key_tool_blur + ")"; + key_tool_smudge = "(" + key_tool_smudge + ")"; + key_tool_particle = "(" + key_tool_particle + ")"; + key_tool_colorid = "(" + key_tool_colorid + ")"; + key_tool_picker = "(" + key_tool_picker + ")"; + key_tool_bake = "(" + key_tool_bake + ")"; + key_tool_gizmo = "(" + key_tool_gizmo + ")"; + key_tool_material = "(" + key_tool_material + ")"; + let keys: string[] = [ - "(" + map_get(config_keymap, "tool_brush") + ") - " + tr("Hold {action_paint} to paint\nHold {key} and press {action_paint} to paint a straight line (ruler mode)", vars_brush), - "(" + map_get(config_keymap, "tool_eraser") + ") - " + tr("Hold {action_paint} to erase\nHold {key} and press {action_paint} to erase a straight line (ruler mode)", vars_brush), - "(" + map_get(config_keymap, "tool_fill") + ")", - "(" + map_get(config_keymap, "tool_decal") + ") - " + tr("Hold {key} to paint on a decal mask", vars_decal), - "(" + map_get(config_keymap, "tool_text") + ") - " + tr("Hold {key} to use the text as a mask", vars_decal), - "(" + map_get(config_keymap, "tool_clone") + ") - " + tr("Hold {key} to set source", vars_clone), - "(" + map_get(config_keymap, "tool_blur") + ")", - "(" + map_get(config_keymap, "tool_smudge") + ")", - "(" + map_get(config_keymap, "tool_particle") + ")", - "(" + map_get(config_keymap, "tool_colorid") + ")", - "(" + map_get(config_keymap, "tool_picker") + ")", - "(" + map_get(config_keymap, "tool_bake") + ")", - "(" + map_get(config_keymap, "tool_gizmo") + ")", - "(" + map_get(config_keymap, "tool_material") + ")", + key_tool_brush, + key_tool_eraser, + key_tool_fill, + key_tool_decal, + key_tool_text, + key_tool_clone, + key_tool_blur, + key_tool_smudge, + key_tool_particle, + key_tool_colorid, + key_tool_picker, + key_tool_bake, + key_tool_gizmo, + key_tool_material ]; ui_toolbar_draw_tool(workspace_tool_t.BRUSH, ui, img, icon_accent, keys); diff --git a/base/Sources/ui_view2d.ts b/base/Sources/ui_view2d.ts index 55178038..f35e86e0 100644 --- a/base/Sources/ui_view2d.ts +++ b/base/Sources/ui_view2d.ts @@ -47,9 +47,9 @@ function ui_view2d_init() { let scale: f32 = config_raw.window_scale; let ops: zui_options_t = { theme: base_theme, - font: base_font, - color_wheel: base_color_wheel, - black_white_gradient: base_color_wheel_gradient, + font: base_font.font_, + color_wheel: base_color_wheel.texture_, + black_white_gradient: base_color_wheel_gradient.texture_, scale_factor: scale }; ui_view2d_ui = zui_create(ops); @@ -130,7 +130,9 @@ function ui_view2d_render() { // Grid g2_set_color(0xffffffff); - g2_draw_image(ui_nodes_grid, (ui_view2d_pan_x * ui_view2d_pan_scale) % 100 - 100, (ui_view2d_pan_y * ui_view2d_pan_scale) % 100 - 100); + let gx: i32 = (i32)(ui_view2d_pan_x * ui_view2d_pan_scale) % 100 - 100; + let gy: i32 = (i32)(ui_view2d_pan_y * ui_view2d_pan_scale) % 100 - 100; + g2_draw_image(ui_nodes_grid, gx, gy); // Texture let tex: image_t = null; @@ -260,7 +262,8 @@ function ui_view2d_render() { _ui_view2d_render_th = th; app_notify_on_next_frame(function () { - let texpaint_picker: image_t = map_get(render_path_render_targets, "texpaint_picker")._image; + let rt: render_target_t = map_get(render_path_render_targets, "texpaint_picker"); + let texpaint_picker: image_t = rt._image; g2_begin(texpaint_picker); g2_draw_scaled_image(_ui_view2d_render_tex, -_ui_view2d_render_x, -_ui_view2d_render_y, _ui_view2d_render_tw, _ui_view2d_render_th); g2_end(); @@ -460,7 +463,7 @@ function ui_view2d_update() { ui_view2d_pan_x = _pan_x * ui_view2d_pan_scale; ui_view2d_pan_y = _pan_y * ui_view2d_pan_scale; - if (zui_touch_scroll()) { + if (zui_touch_scroll) { // Zoom to finger location ui_view2d_pan_x -= (ui_view2d_ui.input_x - ui_view2d_ui._window_x - ui_view2d_ui._window_w / 2) * control.zoom; ui_view2d_pan_y -= (ui_view2d_ui.input_y - ui_view2d_ui._window_y - ui_view2d_ui._window_h / 2) * control.zoom; diff --git a/base/Sources/uniforms_ext.ts b/base/Sources/uniforms_ext.ts index 55b6ebe7..a7aad87d 100644 --- a/base/Sources/uniforms_ext.ts +++ b/base/Sources/uniforms_ext.ts @@ -137,12 +137,11 @@ function uniforms_ext_f32_link(object: object_t, mat: material_data_t, link: str let keys: string[] = map_keys(parser_material_script_links); for (let i: i32 = 0; i < keys.length; ++i) { let key: string = keys[i]; - let asciprt_links: any = parser_material_script_links; - let script: string = asciprt_links[key]; + // let script: string = parser_material_script_links[key]; //// let result: f32 = 0.0; - if (script != "") { - result = js_eval(script); - } + // if (script != "") { + // result = js_eval(script); + // } return result; } } @@ -251,7 +250,7 @@ function uniforms_ext_vec3_link(object: object_t, mat: material_data_t, link: st } ///if (is_paint || is_sculpt) -function vec2d(x: f32) { +function vec2d(x: f32): f32 { // Transform from 3d viewport coord to 2d view coord context_raw.paint2d_view = false; let res: f32 = (x * base_w() - base_w()) / ui_view2d_ww; @@ -333,7 +332,8 @@ function uniforms_ext_tex_link(object: object_t, mat: material_data_t, link: str if (link == "_texpaint_undo") { ///if (is_paint || is_sculpt) let i: i32 = history_undo_i - 1 < 0 ? config_raw.undo_steps - 1 : history_undo_i - 1; - return map_get(render_path_render_targets, "texpaint_undo" + i)._image; + let rt: render_target_t = map_get(render_path_render_targets, "texpaint_undo" + i); + return rt._image; ///end ///if is_lab @@ -343,7 +343,8 @@ function uniforms_ext_tex_link(object: object_t, mat: material_data_t, link: str else if (link == "_texpaint_nor_undo") { ///if (is_paint || is_sculpt) let i: i32 = history_undo_i - 1 < 0 ? config_raw.undo_steps - 1 : history_undo_i - 1; - return map_get(render_path_render_targets, "texpaint_nor_undo" + i)._image; + let rt: render_target_t = map_get(render_path_render_targets, "texpaint_nor_undo" + i); + return rt._image; ///end ///if is_lab @@ -353,7 +354,8 @@ function uniforms_ext_tex_link(object: object_t, mat: material_data_t, link: str else if (link == "_texpaint_pack_undo") { ///if (is_paint || is_sculpt) let i: i32 = history_undo_i - 1 < 0 ? config_raw.undo_steps - 1 : history_undo_i - 1; - return map_get(render_path_render_targets, "texpaint_pack_undo" + i)._image; + let rt: render_target_t = map_get(render_path_render_targets, "texpaint_pack_undo" + i); + return rt._image; ///end ///if is_lab @@ -375,7 +377,8 @@ function uniforms_ext_tex_link(object: object_t, mat: material_data_t, link: str ///if (is_paint || is_sculpt) else if (link == "_texcolorid") { if (project_assets.length == 0) { - return map_get(render_path_render_targets, "empty_white")._image; + let rt: render_target_t = map_get(render_path_render_targets, "empty_white"); + return rt._image; } else { return project_get_image(project_assets[context_raw.colorid_handle.position]); @@ -391,7 +394,8 @@ function uniforms_ext_tex_link(object: object_t, mat: material_data_t, link: str return context_raw.brush_stencil_image; } else if (link == "_texparticle") { - return map_get(render_path_render_targets, "texparticle")._image; + let rt: render_target_t = map_get(render_path_render_targets, "texparticle"); + return rt._image; } ///end @@ -410,7 +414,13 @@ function uniforms_ext_tex_link(object: object_t, mat: material_data_t, link: str } else if (link == "_texuvislandmap") { app_notify_on_init(util_uv_cache_uv_island_map); - return util_uv_uvislandmap_cached ? util_uv_uvislandmap :map_get(render_path_render_targets, "empty_black")._image; + if (util_uv_uvislandmap_cached) { + return util_uv_uvislandmap; + } + else { + let rt: render_target_t = map_get(render_path_render_targets, "empty_black"); + return rt._image; + } } else if (link == "_texdilatemap") { return util_uv_dilatemap; @@ -419,12 +429,13 @@ function uniforms_ext_tex_link(object: object_t, mat: material_data_t, link: str if (starts_with(link, "_texpaint_pack_vert")) { let tid: string = substring(link, link.length - 1, link.length); - return map_get(render_path_render_targets, "texpaint_pack" + tid)._image; + let rt: render_target_t = map_get(render_path_render_targets, "texpaint_pack" + tid); + return rt._image; } if (starts_with(link, "_texpaint_vert")) { ///if (is_paint || is_sculpt) - let tid: i32 = Number(substring(link, link.length - 1, link.length)); + let tid: i32 = parse_int(substring(link, link.length - 1, link.length)); return tid < project_layers.length ? project_layers[tid].texpaint : null; ///end @@ -434,7 +445,7 @@ function uniforms_ext_tex_link(object: object_t, mat: material_data_t, link: str } if (starts_with(link, "_texpaint_nor")) { ///if is_paint - let tid: i32 = Number(substring(link, link.length - 1, link.length)); + let tid: i32 = parse_int(substring(link, link.length - 1, link.length)); return tid < project_layers.length ? project_layers[tid].texpaint_nor : null; ///end @@ -444,7 +455,7 @@ function uniforms_ext_tex_link(object: object_t, mat: material_data_t, link: str } if (starts_with(link, "_texpaint_pack")) { ///if is_paint - let tid: i32 = Number(substring(link, link.length - 1, link.length)); + let tid: i32 = parse_int(substring(link, link.length - 1, link.length)); return tid < project_layers.length ? project_layers[tid].texpaint_pack : null; ///end @@ -454,7 +465,7 @@ function uniforms_ext_tex_link(object: object_t, mat: material_data_t, link: str } if (starts_with(link, "_texpaint")) { ///if (is_paint || is_sculpt) - let tid: i32 = Number(substring(link, link.length - 1, link.length)); + let tid: i32 = parse_int(substring(link, link.length - 1, link.length)); return tid < project_layers.length ? project_layers[tid].texpaint : null; ///end @@ -466,15 +477,33 @@ function uniforms_ext_tex_link(object: object_t, mat: material_data_t, link: str ///if (is_paint || is_sculpt) if (starts_with(link, "_texblur_")) { let id: string = substring(link, 9, link.length); - return context_raw.node_previews != null ? map_get(context_raw.node_previews, id) :map_get(render_path_render_targets, "empty_black")._image; + if (context_raw.node_previews != null) { + return map_get(context_raw.node_previews, id); + } + else { + let rt: render_target_t = map_get(render_path_render_targets, "empty_black"); + return rt._image; + } } if (starts_with(link, "_texwarp_")) { let id: string = substring(link, 9, link.length); - return context_raw.node_previews != null ? map_get(context_raw.node_previews, id) :map_get(render_path_render_targets, "empty_black")._image; + if (context_raw.node_previews != null) { + return map_get(context_raw.node_previews, id); + } + else { + let rt: render_target_t = map_get(render_path_render_targets, "empty_black"); + return rt._image; + } } if (starts_with(link, "_texbake_")) { let id: string = substring(link, 9, link.length); - return context_raw.node_previews != null ? map_get(context_raw.node_previews, id) :map_get(render_path_render_targets, "empty_black")._image; + if (context_raw.node_previews != null) { + return map_get(context_raw.node_previews, id); + } + else { + let rt: render_target_t = map_get(render_path_render_targets, "empty_black"); + return rt._image; + } } ///end diff --git a/base/Sources/util_mesh.ts b/base/Sources/util_mesh.ts index e9f761db..537bd475 100644 --- a/base/Sources/util_mesh.ts +++ b/base/Sources/util_mesh.ts @@ -77,18 +77,38 @@ function util_mesh_merge(paint_objects: mesh_object_t[] = null) { let raw: mesh_data_t = { name: context_raw.paint_object.base.name, vertex_arrays: [ - { values: va0, attrib: "pos", data: "short4norm" }, - { values: va1, attrib: "nor", data: "short2norm" }, - { values: va2, attrib: "tex", data: "short2norm" } + { + values: va0, + attrib: "pos", + data: "short4norm" + }, + { + values: va1, + attrib: "nor", + data: "short2norm" + }, + { + values: va2, + attrib: "tex", + data: "short2norm" + } ], index_arrays: [ - { values: ia, material: 0 } + { + values: ia, + material: 0 + } ], scale_pos: max_scale, scale_tex: 1.0 }; if (va3 != null) { - array_push(raw.vertex_arrays, { values: va3, attrib: "col", data: "short4norm" }); + let col: vertex_array_t = { + values: va3, + attrib: "col", + data: "short4norm" + }; + array_push(raw.vertex_arrays, col); } util_mesh_remove_merged(); @@ -202,7 +222,7 @@ function util_mesh_calc_normals(smooth: bool = false) { vec4_sub_vecs(cb, vc, vb); vec4_sub_vecs(ab, va, vb); vec4_cross(cb, ab); - vec4_normalize(cb, ); + vec4_normalize(cb); buffer_view_set_i16(vertices, (i1 * l + 4) * 2, math_floor(cb.x * 32767)); buffer_view_set_i16(vertices, (i1 * l + 5) * 2, math_floor(cb.y * 32767)); buffer_view_set_i16(vertices, (i1 * l + 3) * 2, math_floor(cb.z * 32767)); @@ -248,7 +268,7 @@ function util_mesh_calc_normals(smooth: bool = false) { vec4_add_f(va, buffer_view_get_i16(vertices, (i1l + 4) * 2), buffer_view_get_i16(vertices, (i1l + 5) * 2), buffer_view_get_i16(vertices, (i1l + 3) * 2)); } vec4_mult(va, 1 / shared_len); - vec4_normalize(va, ); + vec4_normalize(va); let vax: i32 = math_floor(va.x * 32767); let vay: i32 = math_floor(va.y * 32767); let vaz: i32 = math_floor(va.z * 32767); @@ -361,7 +381,7 @@ function util_mesh_to_origin() { util_mesh_merge(); } -function util_mesh_apply_displacement(texpaint_pack: image_t, strength: f32 = 0.1, uvScale: f32 = 1.0) { +function util_mesh_apply_displacement(texpaint_pack: image_t, strength: f32 = 0.1, uv_scale: f32 = 1.0) { let height: buffer_t = image_get_pixels(texpaint_pack); let height_view: buffer_view_t = buffer_view_create(height); let res: i32 = texpaint_pack.width; @@ -372,8 +392,8 @@ function util_mesh_apply_displacement(texpaint_pack: image_t, strength: f32 = 0. for (let i: i32 = 0; i < math_floor(buffer_view_size(vertices) / 2 / l); ++i) { let x: i32 = math_floor(buffer_view_get_i16(vertices, (i * l + 6) * 2) / 32767 * res); let y: i32 = math_floor(buffer_view_get_i16(vertices, (i * l + 7) * 2) / 32767 * res); - let xx: i32 = math_floor(x * uvScale) % res; - let yy: i32 = math_floor(y * uvScale) % res; + let xx: i32 = (i32)math_floor(x * uv_scale) % res; + let yy: i32 = (i32)math_floor(y * uv_scale) % res; let h: f32 = (1.0 - buffer_view_get_u8(height_view, (yy * res + xx) * 4 + 3) / 255) * strength; buffer_view_set_i16(vertices, (i * l ) * 2, buffer_view_get_i16(vertices, (i * l ) * 2) - math_floor(buffer_view_get_i16(vertices, (i * l + 4) * 2) * h)); buffer_view_set_i16(vertices, (i * l + 1) * 2, buffer_view_get_i16(vertices, (i * l + 1) * 2) - math_floor(buffer_view_get_i16(vertices, (i * l + 5) * 2) * h)); @@ -389,7 +409,7 @@ function util_mesh_apply_displacement(texpaint_pack: image_t, strength: f32 = 0. } } -function util_mesh_equirect_unwrap(mesh: any) { +function util_mesh_equirect_unwrap(mesh: raw_mesh_t) { let verts: i32 = math_floor(mesh.posa.length / 4); mesh.texa = i16_array_create(verts * 2); let n: vec4_t = vec4_create(); diff --git a/base/Sources/util_render.ts b/base/Sources/util_render.ts index cef03708..03aed13f 100644 --- a/base/Sources/util_render.ts +++ b/base/Sources/util_render.ts @@ -359,8 +359,10 @@ function util_render_make_brush_preview() { g2_end(); // Scale image preview down to to icon - map_get(render_path_render_targets, "texpreview")._image = context_raw.brush.image; - map_get(render_path_render_targets, "texpreview_icon")._image = context_raw.brush.image_icon; + let texpreview: render_target_t = map_get(render_path_render_targets, "texpreview"); + texpreview._image = context_raw.brush.image; + let texpreview_icon: render_target_t = map_get(render_path_render_targets, "texpreview_icon"); + texpreview_icon._image = context_raw.brush.image_icon; render_path_set_target("texpreview_icon"); render_path_bind_target("texpreview", "tex"); render_path_draw_shader("shader_datas/supersample_resolve/supersample_resolve"); @@ -372,7 +374,7 @@ function util_render_make_brush_preview() { } function util_render_make_node_preview(canvas: zui_node_canvas_t, node: zui_node_t, image: image_t, group: zui_node_canvas_t = null, parents: zui_node_t[] = null) { - let res: any = make_material_parse_node_preview_material(node, group, parents); + let res: parse_node_preview_result_t = make_material_parse_node_preview_material(node, group, parents); if (res == null || res.scon == null) { return; } @@ -387,7 +389,8 @@ function util_render_make_node_preview(canvas: zui_node_canvas_t, node: zui_node g4_begin(image); g4_set_pipeline(res.scon._.pipe_state); - uniforms_set_context_consts(res.scon, [""]); + let empty: string[] = [""]; + uniforms_set_context_consts(res.scon, empty); uniforms_set_obj_consts(res.scon, context_raw.paint_object.base); uniforms_set_material_consts(res.scon, res.mcon); g4_set_vertex_buffer(util_render_screen_aligned_full_vb); @@ -436,7 +439,7 @@ function util_render_create_screen_aligned_full_data() { // Over-sized triangle let data: f32[] = [-math_floor(32767 / 3), -math_floor(32767 / 3), 0, 32767, 0, 0, 0, 0, 0, 0, 0, 0, 32767, -math_floor(32767 / 3), 0, 32767, 0, 0, 0, 0, 0, 0, 0, 0, - -math_floor(32767 / 3), 32767, 0, 32767, 0, 0, 0, 0, 0, 0, 0, 0]; + -math_floor(32767 / 3), 32767, 0, 32767, 0, 0, 0, 0, 0, 0, 0, 0]; let indices: i32[] = [0, 1, 2]; // Mandatory vertex data names and sizes diff --git a/base/Sources/util_uv.ts b/base/Sources/util_uv.ts index 75e5fd7a..761a3290 100644 --- a/base/Sources/util_uv.ts +++ b/base/Sources/util_uv.ts @@ -159,10 +159,14 @@ function _util_uv_check(c: coord_t, w: i32, h: i32, r: i32, view: buffer_view_t, return; } buffer_view_set_u8(view, c.y * w + c.x, 255); - array_push(coords, { x: c.x + 1, y: c.y }); - array_push(coords, { x: c.x - 1, y: c.y }); - array_push(coords, { x: c.x, y: c.y + 1 }); - array_push(coords, { x: c.x, y: c.y - 1 }); + let co: coord_t = { x: c.x + 1, y: c.y }; + array_push(coords, co); + co = { x: c.x - 1, y: c.y }; + array_push(coords, co); + co = { x: c.x, y: c.y + 1 }; + array_push(coords, co); + co = { x: c.x, y: c.y - 1 }; + array_push(coords, co); } function util_uv_cache_uv_island_map() { @@ -181,7 +185,7 @@ function util_uv_cache_uv_island_map() { let r: i32 = math_floor(util_uv_dilatemap.width / w); while (coords.length > 0) { - _util_uv_check(coords.pop(), w, h, r, view, coords); + _util_uv_check(array_pop(coords), w, h, r, view, coords); } if (util_uv_uvislandmap != null) { diff --git a/base/project.js b/base/project.js index 852e530d..fc823c5b 100644 --- a/base/project.js +++ b/base/project.js @@ -19,8 +19,8 @@ flags.with_g2 = true; flags.with_iron = true; flags.with_zui = true; -// flags.with_minits = true; //// -// flags.physics = false; //// +flags.with_minits = true; //// +flags.physics = false; //// flags.on_c_project_created = async function(c_project, platform, graphics) { c_project.addDefine("IDLE_SLEEP");