From f28adda69ca59acccbc9e11cdb59325daaa3f788 Mon Sep 17 00:00:00 2001 From: luboslenco Date: Fri, 27 Mar 2026 11:52:34 +0100 Subject: [PATCH] paint: live node preview with script node --- base/sources/engine.c | 11 +++++++++++ paint/sources/ui_nodes.c | 16 ++++++++++++++++ paint/sources/uniforms_ext.c | 3 +++ 3 files changed, 30 insertions(+) diff --git a/base/sources/engine.c b/base/sources/engine.c index bd9e2473..634bffa6 100644 --- a/base/sources/engine.c +++ b/base/sources/engine.c @@ -1625,6 +1625,13 @@ bool uniforms_set_context_const(i32 location, shader_const_t *c) { return false; } +vec4_t uniforms_vec4_zero_to_one(vec4_t v) { + v.x = v.x == 0.0 ? 1.0 : v.x; + v.y = v.y == 0.0 ? 1.0 : v.y; + v.z = v.z == 0.0 ? 1.0 : v.z; + return v; +} + void uniforms_set_obj_const(object_t *obj, i32 loc, shader_const_t *c) { if (c->link == NULL) { return; @@ -1691,11 +1698,15 @@ void uniforms_set_obj_const(object_t *obj, i32 loc, shader_const_t *c) { if (string_equals(c->link, "_dim")) { // Model space vec4_t d = obj->transform->dim; vec4_t s = obj->transform->scale; + d = uniforms_vec4_zero_to_one(d); + s = uniforms_vec4_zero_to_one(s); v = vec4_create((d.x / s.x), (d.y / s.y), (d.z / s.z), 0.0); } else if (string_equals(c->link, "_half_dim")) { // Model space vec4_t d = obj->transform->dim; vec4_t s = obj->transform->scale; + d = uniforms_vec4_zero_to_one(d); + s = uniforms_vec4_zero_to_one(s); v = vec4_create((d.x / s.x) / 2, (d.y / s.y) / 2, (d.z / s.z) / 2, 0.0); } else if (uniforms_vec3_links != NULL) { diff --git a/paint/sources/ui_nodes.c b/paint/sources/ui_nodes.c index 6eb74b99..3416755c 100644 --- a/paint/sources/ui_nodes.c +++ b/paint/sources/ui_nodes.c @@ -828,6 +828,22 @@ void ui_nodes_render(void *_) { ui_nodes_last_node_selected_id = ui_nodes->nodes_selected_id->buffer[0]; ui_node_t *sel = ui_get_node(c->nodes, ui_nodes->nodes_selected_id->buffer[0]); ui_nodes_make_node_preview(sel); + + // If script node is present, update selected node preview on every frame + bool has_script_node = false; + ui_node_canvas_t *canvas = context_raw->material->canvas; + for (i32 i = 0; i < canvas->nodes->length; ++i) { + ui_node_t *n = canvas->nodes->buffer[i]; + if (string_equals(n->type, "SCRIPT_CPU")) { + has_script_node = true; + break; + } + } + if (has_script_node) { + ui_nodes_last_node_selected_id = -1; + ui_view2d_hwnd->redraws = 2; + iron_delay_idle_sleep(); + } } else if (ui_nodes->nodes_selected_id->length == 0) { ui_nodes_last_node_selected_id = -1; diff --git a/paint/sources/uniforms_ext.c b/paint/sources/uniforms_ext.c index 0dc9b189..71cbb6d7 100644 --- a/paint/sources/uniforms_ext.c +++ b/paint/sources/uniforms_ext.c @@ -149,6 +149,9 @@ f32 uniforms_ext_f32_link(object_t *object, material_data_t *mat, char *link) { char *key = keys->buffer[i]; char *script = any_map_get(parser_material_script_links, key); f32 result = NAN; + if (script != NULL) { + result = 0.0; + } if (!string_equals(script, "")) { minic_ctx_t *_ctx = minic_eval(string("float main() { return %s; }", script)); result = minic_ctx_result(_ctx);