From c790f88e3a8c272e3d8387425ebc7a7ab4539758 Mon Sep 17 00:00:00 2001 From: luboslenco Date: Tue, 24 Sep 2024 16:50:54 +0200 Subject: [PATCH] Brush node fixes --- armorpaint/sources/nodes/brush_output_node.ts | 7 ++-- armorpaint/sources/nodes/input_node.ts | 2 +- armorpaint/sources/nodes/tex_image_node.ts | 9 ++--- base/sources/base.ts | 7 +--- base/sources/nodes/boolean_node.ts | 4 +-- base/sources/nodes/color_node.ts | 2 +- base/sources/nodes/float_node.ts | 4 +-- base/sources/nodes/integer_node.ts | 4 +-- base/sources/nodes/math_node.ts | 2 +- base/sources/nodes/null_node.ts | 2 +- base/sources/nodes/random_node.ts | 2 +- base/sources/nodes/separate_vector_node.ts | 2 +- base/sources/nodes/string_node.ts | 4 +-- base/sources/nodes/time_node.ts | 2 +- base/sources/nodes/vector_math_node.ts | 2 +- base/sources/nodes/vector_node.ts | 8 ++--- base/sources/parser_logic.ts | 33 +++++++------------ base/sources/ui_nodes.ts | 1 + 18 files changed, 43 insertions(+), 54 deletions(-) diff --git a/armorpaint/sources/nodes/brush_output_node.ts b/armorpaint/sources/nodes/brush_output_node.ts index 56918ce3f..722bf10d4 100644 --- a/armorpaint/sources/nodes/brush_output_node.ts +++ b/armorpaint/sources/nodes/brush_output_node.ts @@ -1,14 +1,16 @@ type brush_output_node_t = { base?: logic_node_t; + raw?: ui_node_t; }; -function brush_output_node_create(arg: any): brush_output_node_t { +function brush_output_node_create(raw: ui_node_t, args: f32_array_t): brush_output_node_t { let n: brush_output_node_t = {}; n.base = logic_node_create(); context_raw.run_brush = brush_output_node_run; context_raw.parse_brush_inputs = brush_output_node_parse_inputs; context_raw.brush_output_node_inst = n; + n.raw = raw; return n; } @@ -69,8 +71,7 @@ function brush_output_node_parse_inputs(self: brush_output_node_t) { make_material_parse_paint_material(); } - let n: ui_node_t = map_get(parser_logic_raw_map, self); - context_raw.brush_directional = n.buttons[0].default_value[0] > 0.0; + context_raw.brush_directional = self.raw.buttons[0].default_value[0] > 0.0; } function brush_output_node_run(self: brush_output_node_t, from: i32) { diff --git a/armorpaint/sources/nodes/input_node.ts b/armorpaint/sources/nodes/input_node.ts index 98629ea2e..9d4403826 100644 --- a/armorpaint/sources/nodes/input_node.ts +++ b/armorpaint/sources/nodes/input_node.ts @@ -14,7 +14,7 @@ let input_node_lock_start_x: f32 = 0.0; let input_node_lock_start_y: f32 = 0.0; let input_node_registered: bool = false; -function input_node_create(arg: any): input_node_t { +function input_node_create(raw: ui_node_t, args: f32_array_t): input_node_t { let n: float_node_t = {}; n.base = logic_node_create(); n.base.get = input_node_get; diff --git a/armorpaint/sources/nodes/tex_image_node.ts b/armorpaint/sources/nodes/tex_image_node.ts index 28473668d..af742b902 100644 --- a/armorpaint/sources/nodes/tex_image_node.ts +++ b/armorpaint/sources/nodes/tex_image_node.ts @@ -1,19 +1,20 @@ type tex_image_node_t = { base?: logic_node_t; + raw?: ui_node_t; }; -function tex_image_node_create(arg: any): tex_image_node_t { +function tex_image_node_create(raw: ui_node_t, args: f32_array_t): tex_image_node_t { let n: tex_image_node_t = {}; n.base = logic_node_create(); n.base.get = tex_image_node_get; + n.raw = raw; return n; } function tex_image_node_get(self: tex_image_node_t, from: i32): logic_node_value_t { - let n: ui_node_t = map_get(parser_logic_raw_map, self); - let ar: string[] = ui_nodes_enum_texts(n.type); - let i: i32 = n.buttons[0].default_value[0]; + let ar: string[] = ui_nodes_enum_texts(self.raw.type); + let i: i32 = self.raw.buttons[0].default_value[0]; let file: string = ar[i]; if (from == 0) { diff --git a/base/sources/base.ts b/base/sources/base.ts index d4d5ae7e3..045ce1378 100644 --- a/base/sources/base.ts +++ b/base/sources/base.ts @@ -494,12 +494,7 @@ function base_resize() { base_appy = 0; } - if (ui_nodes_grid != null) { - app_notify_on_next_frame(function (grid: image_t) { - image_unload(grid); - }, ui_nodes_grid); - ui_nodes_grid = null; - } + ui_nodes_grid_redraw = true; base_redraw_ui(); } diff --git a/base/sources/nodes/boolean_node.ts b/base/sources/nodes/boolean_node.ts index 371fbffff..57c537fb3 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(args: f32_array_t): boolean_node_t { +function boolean_node_create(raw: ui_node_t, 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 = args[0] > 0.0; + n.value = args == null ? false : args[0] > 0.0; return n; } diff --git a/base/sources/nodes/color_node.ts b/base/sources/nodes/color_node.ts index 4eeb7c13a..2aabe7fea 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: f32_array_t): color_node_t { +function color_node_create(raw: ui_node_t, 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]; diff --git a/base/sources/nodes/float_node.ts b/base/sources/nodes/float_node.ts index 346bd6062..401360d88 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(args: f32_array_t): float_node_t { +function float_node_create(raw: ui_node_t, args: f32_array_t): 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 = args[0]; + n.value = args == null ? 0.5 : args[0]; return n; } diff --git a/base/sources/nodes/integer_node.ts b/base/sources/nodes/integer_node.ts index bec2fe779..c05f03d2d 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(args: f32_array_t): integer_node_t { +function integer_node_create(raw: ui_node_t, 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 = args[0]; + n.value = args == null ? 0 : args[0]; return n; } diff --git a/base/sources/nodes/math_node.ts b/base/sources/nodes/math_node.ts index e71d26c36..3cbe7a7b4 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(args: f32_array_t): math_node_t { +function math_node_create(raw: ui_node_t, args: f32_array_t): math_node_t { let n: math_node_t = {}; n.base = logic_node_create(); n.base.get = math_node_get; diff --git a/base/sources/nodes/null_node.ts b/base/sources/nodes/null_node.ts index 741d2dd8f..9da0f54bf 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(args: f32_array_t): null_node_t { +function null_node_create(raw: ui_node_t, 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 03f3dd320..34a5c6215 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(args: f32_array_t): random_node_t { +function random_node_create(raw: ui_node_t, args: f32_array_t): random_node_t { let n: random_node_t = {}; n.base = logic_node_create(); n.base.get = random_node_get; diff --git a/base/sources/nodes/separate_vector_node.ts b/base/sources/nodes/separate_vector_node.ts index 2d45fa087..ab5626f96 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(args: f32_array_t): separate_vector_node_t { +function separate_vector_node_create(raw: ui_node_t, 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/string_node.ts b/base/sources/nodes/string_node.ts index 510bccf9d..877ede7f9 100644 --- a/base/sources/nodes/string_node.ts +++ b/base/sources/nodes/string_node.ts @@ -4,12 +4,12 @@ type string_node_t = { value?: string; }; -function string_node_create(arg: string): string_node_t { +function string_node_create(raw: ui_node_t, args: f32_array_t): string_node_t { let n: string_node_t = {}; n.base = logic_node_create(); n.base.get = string_node_get; n.base.set = string_node_set; - n.value = arg; + n.value = args == null ? "" : sys_buffer_to_string(args.buffer); return n; } diff --git a/base/sources/nodes/time_node.ts b/base/sources/nodes/time_node.ts index 6b55fc818..33862721b 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(args: f32_array_t): time_node_t { +function time_node_create(raw: ui_node_t, 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 70b763b9e..34841893c 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(args: f32_array_t): vector_math_node_t { +function vector_math_node_create(raw: ui_node_t, 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; diff --git a/base/sources/nodes/vector_node.ts b/base/sources/nodes/vector_node.ts index dcbedc30c..48692359c 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: f32_array_t): vector_node_t { +function vector_node_create(raw: ui_node_t, args: f32_array_t): vector_node_t { let n: vector_node_t = {}; n.base = logic_node_create(); n.base.get = vector_node_get; @@ -14,9 +14,9 @@ function vector_node_create(args: f32_array_t): vector_node_t { n.value = vec4_create(); if (args != null) { - logic_node_add_input(n.base, float_node_create(f32_array_create_x(args[0])), 0); - logic_node_add_input(n.base, float_node_create(f32_array_create_x(args[1])), 0); - logic_node_add_input(n.base, float_node_create(f32_array_create_x(args[2])), 0); + logic_node_add_input(n.base, float_node_create(null, f32_array_create_x(args[0])), 0); + logic_node_add_input(n.base, float_node_create(null, f32_array_create_x(args[1])), 0); + logic_node_add_input(n.base, float_node_create(null, f32_array_create_x(args[2])), 0); } return n; diff --git a/base/sources/parser_logic.ts b/base/sources/parser_logic.ts index a2ee08f3b..91e683da2 100644 --- a/base/sources/parser_logic.ts +++ b/base/sources/parser_logic.ts @@ -4,18 +4,12 @@ let parser_logic_nodes: ui_node_t[]; let parser_logic_links: ui_node_link_t[]; let parser_logic_parsed_nodes: string[] = null; -let parser_logic_parsed_labels: map_t = null; let parser_logic_node_map: map_t; -let parser_logic_raw_map: map_t; function parser_logic_get_logic_node(node: ui_node_t): logic_node_ext_t { return map_get(parser_logic_node_map, parser_logic_node_name(node)); } -function parser_logic_get_raw_node(node: logic_node_ext_t): ui_node_t { - return map_get(parser_logic_raw_map, node); -} - function parser_logic_get_node(id: i32): ui_node_t { for (let i: i32 = 0; i < parser_logic_nodes.length; ++i) { let n: ui_node_t = parser_logic_nodes[i]; @@ -85,9 +79,7 @@ function parser_logic_parse(canvas: ui_node_canvas_t) { parser_logic_links = canvas.links; parser_logic_parsed_nodes = []; - parser_logic_parsed_labels = map_create(); parser_logic_node_map = map_create(); - parser_logic_raw_map = map_create(); let root_nodes: ui_node_t[] = parser_logic_get_root_nodes(canvas); for (let i: i32 = 0; i < root_nodes.length; ++i) { @@ -108,9 +100,8 @@ function parser_logic_build_node(node: ui_node_t): string { array_push(parser_logic_parsed_nodes, name); // Create node - let v: logic_node_ext_t = parser_logic_create_node_instance(node.type, null); + let v: logic_node_ext_t = parser_logic_create_node_instance(node.type, node, null); map_set(parser_logic_node_map, name, v); - map_set(parser_logic_raw_map, v, node); // Create inputs let inp_node: logic_node_ext_t = null; @@ -185,39 +176,39 @@ function parser_logic_build_default_node(inp: ui_node_socket_t): logic_node_ext_ if (inp.default_value == null) { inp.default_value = f32_array_create_xyz(0, 0, 0); } - v = parser_logic_create_node_instance("vector_node", inp.default_value); + v = parser_logic_create_node_instance("vector_node", null, inp.default_value); } else if (inp.type == "RGBA") { if (inp.default_value == null) { inp.default_value = f32_array_create_xyzw(0, 0, 0, 0); } - v = parser_logic_create_node_instance("color_node", inp.default_value); + v = parser_logic_create_node_instance("color_node", null, inp.default_value); } else if (inp.type == "RGB") { if (inp.default_value == null) { inp.default_value = f32_array_create_xyzw(0, 0, 0, 0); } - v = parser_logic_create_node_instance("color_node", inp.default_value); + v = parser_logic_create_node_instance("color_node", null, inp.default_value); } else if (inp.type == "VALUE") { - v = parser_logic_create_node_instance("float_node", inp.default_value); + v = parser_logic_create_node_instance("float_node", null, inp.default_value); } else if (inp.type == "INT") { - v = parser_logic_create_node_instance("integer_node", inp.default_value); + v = parser_logic_create_node_instance("integer_node", null, inp.default_value); } else if (inp.type == "BOOLEAN") { - v = parser_logic_create_node_instance("boolean_node", inp.default_value); + v = parser_logic_create_node_instance("boolean_node", null, inp.default_value); } else if (inp.type == "STRING") { - v = parser_logic_create_node_instance("string_node", inp.default_value); + v = parser_logic_create_node_instance("string_node", null, inp.default_value); } else { - v = parser_logic_create_node_instance("null_node", null); + v = parser_logic_create_node_instance("null_node", null, null); } return v; } -function parser_logic_create_node_instance(node_type: string, args: f32_array_t): logic_node_ext_t { +function parser_logic_create_node_instance(node_type: string, raw: ui_node_t, 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); @@ -231,6 +222,6 @@ function parser_logic_create_node_instance(node_type: string, args: f32_array_t) nodes_brush_init(); } - let create: (args: f32_array_t)=>logic_node_ext_t = map_get(nodes_brush_creates, node_type); - return create(args); + let create: (raw: ui_node_t, args: f32_array_t)=>logic_node_ext_t = map_get(nodes_brush_creates, node_type); + return create(raw, args); } diff --git a/base/sources/ui_nodes.ts b/base/sources/ui_nodes.ts index b72ef0fec..6894b0c21 100644 --- a/base/sources/ui_nodes.ts +++ b/base/sources/ui_nodes.ts @@ -836,6 +836,7 @@ function ui_nodes_render() { image_unload(ui_nodes_grid); } ui_nodes_draw_grid(); + ui_nodes_grid_redraw = false; } ///if (is_paint || is_sculpt)