paint: live node preview with script node

This commit is contained in:
luboslenco
2026-03-27 11:52:34 +01:00
parent 89a0f29258
commit f28adda69c
3 changed files with 30 additions and 0 deletions
+11
View File
@@ -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) {
+16
View File
@@ -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;
+3
View File
@@ -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);