This commit is contained in:
luboslenco
2024-11-10 16:53:36 +01:00
parent fea777aed2
commit fcb5c90356
36 changed files with 1377 additions and 1413 deletions
-85
View File
@@ -4,9 +4,7 @@ function base_ext_init() {
}
function base_ext_render() {
if (context_raw.frame == 2) {
app_notify_on_next_frame(function () {
app_notify_on_next_frame(function () {
tab_meshes_set_default_mesh(".Sphere");
@@ -14,86 +12,3 @@ function base_ext_render() {
});
}
}
function base_ext_flatten(height_to_normal: bool = false, layers: slot_layer_t[] = null): slot_layer_t {
let texpaint: image_t = brush_output_node_inst.texpaint;
let texpaint_nor: image_t = brush_output_node_inst.texpaint_nor;
let texpaint_pack: image_t = brush_output_node_inst.texpaint_pack;
let nodes: ui_nodes_t = ui_nodes_get_nodes();
let canvas: ui_node_canvas_t = ui_nodes_get_canvas(true);
if (nodes.nodes_selected_id.length > 0) {
let node: ui_node_t = ui_get_node(canvas.nodes, nodes.nodes_selected_id[0]);
let brush_node: logic_node_ext_t = parser_logic_get_logic_node(node);
if (brush_node != null && logic_node_get_cached_image(brush_node.base) != null) {
texpaint = logic_node_get_cached_image(brush_node.base);
let texpaint_nor_rt: render_target_t = map_get(render_path_render_targets, "texpaint_nor_empty");
let texpaint_pack_rt: render_target_t = map_get(render_path_render_targets, "texpaint_pack_empty");
texpaint_nor = texpaint_nor_rt._image;
texpaint_pack = texpaint_pack_rt._image;
}
}
let l: slot_layer_t = { texpaint: texpaint, texpaint_nor: texpaint_nor, texpaint_pack: texpaint_pack };
return l;
}
function base_ext_on_layers_resized() {
image_unload(brush_output_node_inst.texpaint);
let texpaint_rt: render_target_t = map_get(render_path_render_targets, "texpaint");
brush_output_node_inst.texpaint = texpaint_rt._image = image_create_render_target(config_get_texture_res_x(), config_get_texture_res_y());
image_unload(brush_output_node_inst.texpaint_nor);
let texpaint_nor_rt: render_target_t = map_get(render_path_render_targets, "texpaint_nor");
brush_output_node_inst.texpaint_nor = texpaint_nor_rt._image = image_create_render_target(config_get_texture_res_x(), config_get_texture_res_y());
image_unload(brush_output_node_inst.texpaint_pack);
let texpaint_pack_rt: render_target_t = map_get(render_path_render_targets, "texpaint_pack");
brush_output_node_inst.texpaint_pack = texpaint_pack_rt._image = image_create_render_target(config_get_texture_res_x(), config_get_texture_res_y());
if (inpaint_node_image != null) {
image_unload(inpaint_node_image);
inpaint_node_image = null;
image_unload(inpaint_node_mask);
inpaint_node_mask = null;
inpaint_node_init();
}
if (photo_to_pbr_node_images != null) {
for (let i: i32 = 0; i < photo_to_pbr_node_images.length; ++i) {
let image: image_t = photo_to_pbr_node_images[i];
image_unload(image);
}
photo_to_pbr_node_images = null;
photo_to_pbr_node_init();
}
if (tiling_node_image != null) {
image_unload(tiling_node_image);
tiling_node_image = null;
tiling_node_init();
}
let texpaint_blend0_rt: render_target_t = map_get(render_path_render_targets, "texpaint_blend0");
image_unload(texpaint_blend0_rt._image);
texpaint_blend0_rt._image = image_create_render_target(config_get_texture_res_x(), config_get_texture_res_y(), tex_format_t.R8);
let texpaint_blend1_rt: render_target_t = map_get(render_path_render_targets, "texpaint_blend1");
image_unload(texpaint_blend1_rt._image);
texpaint_blend1_rt._image = image_create_render_target(config_get_texture_res_x(), config_get_texture_res_y(), tex_format_t.R8);
if (map_get(render_path_render_targets, "texpaint_node") != null) {
map_delete(render_path_render_targets, "texpaint_node");
}
if (map_get(render_path_render_targets, "texpaint_node_target") != null) {
map_delete(render_path_render_targets, "texpaint_node_target");
}
app_notify_on_next_frame(function () {
base_init_layers();
});
///if (arm_direct3d12 || arm_vulkan || arm_metal)
render_path_raytrace_ready = false;
///end
}
+23
View File
@@ -0,0 +1,23 @@
function context_ext_init(c: context_t) {
c.tool = workspace_tool_t.ERASER;
c.color_picker_previous_tool = workspace_tool_t.ERASER;
c.brush_radius = 0.25;
c.brush_radius_handle.value = 0.25;
c.brush_hardness = 0.8;
c.coords = vec4_create();
c.start_x = 0.0;
c.start_y = 0.0;
c.lock_begin = false;
c.lock_x = false;
c.lock_y = false;
c.lock_start_x = 0.0;
c.lock_start_y = 0.0;
c.registered = false;
}
function context_ext_select_paint_object(o: mesh_object_t) {
context_raw.paint_object = o;
}
+83
View File
@@ -0,0 +1,83 @@
function layers_ext_flatten(height_to_normal: bool = false, layers: slot_layer_t[] = null): slot_layer_t {
let texpaint: image_t = brush_output_node_inst.texpaint;
let texpaint_nor: image_t = brush_output_node_inst.texpaint_nor;
let texpaint_pack: image_t = brush_output_node_inst.texpaint_pack;
let nodes: ui_nodes_t = ui_nodes_get_nodes();
let canvas: ui_node_canvas_t = ui_nodes_get_canvas(true);
if (nodes.nodes_selected_id.length > 0) {
let node: ui_node_t = ui_get_node(canvas.nodes, nodes.nodes_selected_id[0]);
let brush_node: logic_node_ext_t = parser_logic_get_logic_node(node);
if (brush_node != null && logic_node_get_cached_image(brush_node.base) != null) {
texpaint = logic_node_get_cached_image(brush_node.base);
let texpaint_nor_rt: render_target_t = map_get(render_path_render_targets, "texpaint_nor_empty");
let texpaint_pack_rt: render_target_t = map_get(render_path_render_targets, "texpaint_pack_empty");
texpaint_nor = texpaint_nor_rt._image;
texpaint_pack = texpaint_pack_rt._image;
}
}
let l: slot_layer_t = { texpaint: texpaint, texpaint_nor: texpaint_nor, texpaint_pack: texpaint_pack };
return l;
}
function layers_ext_on_resized() {
image_unload(brush_output_node_inst.texpaint);
let texpaint_rt: render_target_t = map_get(render_path_render_targets, "texpaint");
brush_output_node_inst.texpaint = texpaint_rt._image = image_create_render_target(config_get_texture_res_x(), config_get_texture_res_y());
image_unload(brush_output_node_inst.texpaint_nor);
let texpaint_nor_rt: render_target_t = map_get(render_path_render_targets, "texpaint_nor");
brush_output_node_inst.texpaint_nor = texpaint_nor_rt._image = image_create_render_target(config_get_texture_res_x(), config_get_texture_res_y());
image_unload(brush_output_node_inst.texpaint_pack);
let texpaint_pack_rt: render_target_t = map_get(render_path_render_targets, "texpaint_pack");
brush_output_node_inst.texpaint_pack = texpaint_pack_rt._image = image_create_render_target(config_get_texture_res_x(), config_get_texture_res_y());
if (inpaint_node_image != null) {
image_unload(inpaint_node_image);
inpaint_node_image = null;
image_unload(inpaint_node_mask);
inpaint_node_mask = null;
inpaint_node_init();
}
if (photo_to_pbr_node_images != null) {
for (let i: i32 = 0; i < photo_to_pbr_node_images.length; ++i) {
let image: image_t = photo_to_pbr_node_images[i];
image_unload(image);
}
photo_to_pbr_node_images = null;
photo_to_pbr_node_init();
}
if (tiling_node_image != null) {
image_unload(tiling_node_image);
tiling_node_image = null;
tiling_node_init();
}
let texpaint_blend0_rt: render_target_t = map_get(render_path_render_targets, "texpaint_blend0");
image_unload(texpaint_blend0_rt._image);
texpaint_blend0_rt._image = image_create_render_target(config_get_texture_res_x(), config_get_texture_res_y(), tex_format_t.R8);
let texpaint_blend1_rt: render_target_t = map_get(render_path_render_targets, "texpaint_blend1");
image_unload(texpaint_blend1_rt._image);
texpaint_blend1_rt._image = image_create_render_target(config_get_texture_res_x(), config_get_texture_res_y(), tex_format_t.R8);
if (map_get(render_path_render_targets, "texpaint_node") != null) {
map_delete(render_path_render_targets, "texpaint_node");
}
if (map_get(render_path_render_targets, "texpaint_node_target") != null) {
map_delete(render_path_render_targets, "texpaint_node_target");
}
app_notify_on_next_frame(function () {
layers_init();
});
///if (arm_direct3d12 || arm_vulkan || arm_metal)
render_path_raytrace_ready = false;
///end
}
+117
View File
@@ -65,9 +65,126 @@ function brush_output_node_create(raw: ui_node_t, args: f32_array_t): brush_outp
}
brush_output_node_inst = n;
context_raw.run_brush = brush_output_node_run;
context_raw.parse_brush_inputs = brush_output_node_parse_inputs;
return n;
}
function brush_output_node_get_as_image(self: brush_output_node_t, from: i32): image_t {
return logic_node_input_get_as_image(self.base.inputs[from]);
}
function brush_output_node_run(from: i32) {
let left: f32 = 0.0;
let right: f32 = 1.0;
// First time init
if (context_raw.last_paint_x < 0 || context_raw.last_paint_y < 0) {
context_raw.last_paint_vec_x = context_raw.paint_vec.x;
context_raw.last_paint_vec_y = context_raw.paint_vec.y;
}
let nodes: ui_nodes_t = ui_nodes_get_nodes();
let canvas: ui_node_canvas_t = ui_nodes_get_canvas(true);
let inpaint: bool = nodes.nodes_selected_id.length > 0 && ui_get_node(canvas.nodes, nodes.nodes_selected_id[0]).type == "inpaint_node";
// Paint bounds
if (inpaint &&
context_raw.paint_vec.x > left &&
context_raw.paint_vec.x < right &&
context_raw.paint_vec.y > 0 &&
context_raw.paint_vec.y < 1 &&
!base_is_dragging &&
!base_is_resizing &&
!base_is_scrolling() &&
!base_is_combo_selected()) {
let down: bool = mouse_down() || pen_down();
// Prevent painting the same spot
let same_spot: bool = context_raw.paint_vec.x == context_raw.last_paint_x && context_raw.paint_vec.y == context_raw.last_paint_y;
if (down && same_spot) {
context_raw.painted++;
}
else {
context_raw.painted = 0;
}
context_raw.last_paint_x = context_raw.paint_vec.x;
context_raw.last_paint_y = context_raw.paint_vec.y;
if (context_raw.painted == 0) {
brush_output_node_parse_inputs();
}
if (context_raw.painted <= 1) {
context_raw.pdirty = 1;
context_raw.rdirty = 2;
}
}
}
function brush_output_node_parse_inputs() {
if (!context_raw.registered) {
context_raw.registered = true;
app_notify_on_update(brush_output_node_update);
}
context_raw.paint_vec = context_raw.coords;
}
function brush_output_node_update() {
let paint_x: f32 = mouse_view_x() / app_w();
let paint_y: f32 = mouse_view_y() / app_h();
if (mouse_started()) {
context_raw.start_x = mouse_view_x() / app_w();
context_raw.start_y = mouse_view_y() / app_h();
}
if (pen_down()) {
paint_x = pen_view_x() / app_w();
paint_y = pen_view_y() / app_h();
}
if (pen_started()) {
context_raw.start_x = pen_view_x() / app_w();
context_raw.start_y = pen_view_y() / app_h();
}
if (operator_shortcut(map_get(config_keymap, "brush_ruler") + "+" + map_get(config_keymap, "action_paint"), shortcut_type_t.DOWN)) {
if (context_raw.lock_x) {
paint_x = context_raw.start_x;
}
if (context_raw.lock_y) {
paint_y = context_raw.start_y;
}
}
context_raw.coords.x = paint_x;
context_raw.coords.y = paint_y;
if (context_raw.lock_begin) {
let dx: i32 = math_abs(context_raw.lock_start_x - mouse_view_x());
let dy: i32 = math_abs(context_raw.lock_start_y - mouse_view_y());
if (dx > 1 || dy > 1) {
context_raw.lock_begin = false;
if (dx > dy) {
context_raw.lock_y = true;
}
else {
context_raw.lock_x = true;
}
}
}
if (keyboard_started(map_get(config_keymap, "brush_ruler"))) {
context_raw.lock_start_x = mouse_view_x();
context_raw.lock_start_y = mouse_view_y();
context_raw.lock_begin = true;
}
else if (keyboard_released(map_get(config_keymap, "brush_ruler"))) {
context_raw.lock_x = context_raw.lock_y = context_raw.lock_begin = false;
}
brush_output_node_parse_inputs();
}
+1 -1
View File
@@ -120,7 +120,7 @@ function ui_nodes_ext_draw_buttons(ew: f32, start_y: f32) {
///end
if (base_res_handle.changed) {
base_on_layers_resized();
layers_on_resized();
}
ui._x += ew + 3;
ui._y = 2 + start_y;