Files
armorpaint/paint/sources/neural_nodes/image_to_depth_node.ts
T

97 lines
2.3 KiB
TypeScript
Raw Normal View History

2025-11-06 19:16:12 +01:00
function image_to_depth_node_init() {
array_push(nodes_material_neural, image_to_depth_node_def);
2025-11-13 14:04:57 +01:00
map_set(parser_material_node_values, "NEURAL_IMAGE_TO_DEPTH", neural_node_value);
2025-11-06 19:16:12 +01:00
map_set(ui_nodes_custom_buttons, "image_to_depth_node_button", image_to_depth_node_button);
}
function image_to_depth_node_button(node_id: i32) {
let canvas: ui_node_canvas_t = ui_nodes_get_canvas(true);
let node: ui_node_t = ui_get_node(canvas.nodes, node_id);
2025-11-18 18:46:15 +01:00
let node_name: string = parser_material_node_name(node);
let h: ui_handle_t = ui_handle(node_name);
2025-11-06 19:16:12 +01:00
let models: string[] = [ "Marigold" ];
2025-11-18 18:46:15 +01:00
let model: i32 = ui_combo(ui_nest(h, 0), models, tr("Model"));
2025-11-06 19:16:12 +01:00
2025-11-19 22:50:04 +01:00
if (neural_node_button(node, models[model])) {
2025-11-18 18:46:15 +01:00
let from_node: ui_node_t = neural_from_node(node.inputs[0], 0);
2025-11-06 19:16:12 +01:00
let input: gpu_texture_t = ui_nodes_get_node_preview_image(from_node);
if (input != null) {
2025-11-13 14:04:57 +01:00
let dir: string = neural_node_dir();
2025-11-06 19:16:12 +01:00
iron_write_png(dir + path_sep + "input.png", gpu_get_texture_pixels(input), input.width, input.height, 0);
2025-11-13 14:04:57 +01:00
let argv: string[] = [
2025-11-14 16:04:36 +01:00
dir + "/sd_vulkan",
2025-11-13 14:04:57 +01:00
"-m",
dir + "/marigold-depth-v1-1.q8_0.gguf",
"--sampling-method",
"ddim_trailing",
"--steps",
"10",
"-s",
"-1",
"-W",
"768",
"-H",
"768",
"-p",
2025-11-18 18:46:15 +01:00
"_height",
2025-11-13 14:04:57 +01:00
"-i",
dir + "/input.png",
"-o",
dir + "/output.png",
null
];
iron_exec_async(argv[0], argv.buffer);
sys_notify_on_update(neural_node_check_result, node);
2025-11-06 19:16:12 +01:00
}
}
}
let image_to_depth_node_def: ui_node_t = {
id : 0,
name : _tr("Image to Depth"),
type : "NEURAL_IMAGE_TO_DEPTH",
x : 0,
y : 0,
color : 0xff4982a0,
inputs : [ {
id : 0,
node_id : 0,
name : _tr("Color"),
type : "RGBA",
color : 0xffc7c729,
default_value : f32_array_create_xyzw(0.0, 0.0, 0.0, 1.0),
min : 0.0,
max : 1.0,
precision : 100,
display : 0
} ],
2025-11-06 19:18:48 +01:00
outputs : [ {
id : 0,
node_id : 0,
name : _tr("Depth"),
type : "VALUE",
color : 0xffa1a1a1,
default_value : f32_array_create_x(1.0),
min : 0.0,
max : 1.0,
precision : 100,
display : 0
} ],
2025-11-06 19:16:12 +01:00
buttons : [ {
name : "image_to_depth_node_button",
type : "CUSTOM",
output : -1,
default_value : f32_array_create_x(0),
data : null,
min : 0.0,
max : 1.0,
precision : 100,
height : 2
} ],
width : 0,
flags : 0
};