Skip to content

Commit

Permalink
Brush node fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
luboslenco committed Sep 24, 2024
1 parent 20ac542 commit c790f88
Show file tree
Hide file tree
Showing 18 changed files with 43 additions and 54 deletions.
7 changes: 4 additions & 3 deletions armorpaint/sources/nodes/brush_output_node.ts
Original file line number Diff line number Diff line change
@@ -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;
}

Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion armorpaint/sources/nodes/input_node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 5 additions & 4 deletions armorpaint/sources/nodes/tex_image_node.ts
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
7 changes: 1 addition & 6 deletions base/sources/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
4 changes: 2 additions & 2 deletions base/sources/nodes/boolean_node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion base/sources/nodes/color_node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
4 changes: 2 additions & 2 deletions base/sources/nodes/float_node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions base/sources/nodes/integer_node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion base/sources/nodes/math_node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion base/sources/nodes/null_node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion base/sources/nodes/random_node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion base/sources/nodes/separate_vector_node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions base/sources/nodes/string_node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion base/sources/nodes/time_node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion base/sources/nodes/vector_math_node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions base/sources/nodes/vector_node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
33 changes: 12 additions & 21 deletions base/sources/parser_logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string> = null;
let parser_logic_node_map: map_t<string, logic_node_ext_t>;
let parser_logic_raw_map: map_t<logic_node_ext_t, ui_node_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];
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}
1 change: 1 addition & 0 deletions base/sources/ui_nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c790f88

Please sign in to comment.