paint: cleanup

This commit is contained in:
luboslenco
2026-04-06 14:52:30 +02:00
parent 123c12bd3e
commit 3bdee41cd7
6 changed files with 120 additions and 129 deletions
+9 -8
View File
@@ -4,12 +4,13 @@
f32 input_node_start_x = 0.0;
f32 input_node_start_y = 0.0;
// Brush ruler
bool input_node_lock_begin = false;
bool input_node_lock_x = false;
bool input_node_lock_y = false;
f32 input_node_lock_start_x = 0.0;
f32 input_node_lock_start_y = 0.0;
bool input_node_registered = false;
bool input_node_lock_begin = false;
bool input_node_lock_x = false;
bool input_node_lock_y = false;
f32 input_node_lock_start_x = 0.0;
f32 input_node_lock_start_y = 0.0;
bool input_node_registered = false;
vec4_t input_node_coords = (vec4_t){0.0, 0.0, 0.0, 1.0};
void input_node_update(float_node_t *self) {
if (g_context->split_view) {
@@ -19,7 +20,7 @@ void input_node_update(float_node_t *self) {
bool decal_mask = context_is_decal_mask_paint();
char *ruler_paint = string("%s+%s", any_map_get(config_keymap, "brush_ruler"), any_map_get(config_keymap, "action_paint"));
bool lazy_paint = g_context->brush_lazy_radius > 0 && (operator_shortcut(any_map_get(config_keymap, "action_paint"), SHORTCUT_TYPE_DOWN) ||
operator_shortcut(ruler_paint, SHORTCUT_TYPE_DOWN) || decal_mask);
operator_shortcut(ruler_paint, SHORTCUT_TYPE_DOWN) || decal_mask);
f32 paint_x = mouse_view_x() / (float)sys_w();
f32 paint_y = mouse_view_y() / (float)sys_h();
@@ -110,7 +111,7 @@ void input_node_update(float_node_t *self) {
logic_node_value_t *input_node_get(input_node_t *self, i32 from) {
g_context->brush_lazy_radius = logic_node_input_get(self->base->inputs->buffer[0])->_f32;
g_context->brush_lazy_step = logic_node_input_get(self->base->inputs->buffer[1])->_f32;
logic_node_value_t *v = GC_ALLOC_INIT(logic_node_value_t, {._vec4 = input_node_coords});
logic_node_value_t *v = GC_ALLOC_INIT(logic_node_value_t, {._vec4 = input_node_coords});
return v;
}
+4 -3
View File
@@ -1,9 +1,10 @@
#include "global.h"
i32 camera_redraws = 0;
f32 camera_ease = 1.0;
bool camera_controls_down = false;
i32 camera_redraws = 0;
f32 camera_ease = 1.0;
bool camera_controls_down = false;
vec4_t camera_dir = (vec4_t){0.0, 0.0, 0.0, 1.0};
static bool camera_wrap_mouse() {
if (mouse_view_x() < 0 || mouse_view_x() > sys_w() || mouse_view_y() < 0 || mouse_view_y() > sys_h()) {
+52 -48
View File
@@ -1,13 +1,18 @@
#include "global.h"
void gizmo_update() {
bool is_object = g_context->tool == TOOL_TYPE_GIZMO;
bool is_decal = base_is_decal_layer();
vec4_t gizmo_v = (vec4_t){0.0, 0.0, 0.0, 1.0};
vec4_t gizmo_v0 = (vec4_t){0.0, 0.0, 0.0, 1.0};
quat_t gizmo_q = (quat_t){0.0, 0.0, 0.0, 1.0};
quat_t gizmo_q0 = (quat_t){0.0, 0.0, 0.0, 1.0};
object_t *gizmo = g_context->gizmo;
bool hide = operator_shortcut(any_map_get(config_keymap, "stencil_hide"), SHORTCUT_TYPE_DOWN);
gizmo->visible = (is_object || is_decal) && !hide && g_config->workspace != WORKSPACE_PLAYER;
void gizmo_update() {
bool is_object = g_context->tool == TOOL_TYPE_GIZMO;
bool is_decal = base_is_decal_layer();
object_t *gizmo = g_context->gizmo;
bool hide = operator_shortcut(any_map_get(config_keymap, "stencil_hide"), SHORTCUT_TYPE_DOWN);
gizmo->visible = (is_object || is_decal) && !hide && g_config->workspace != WORKSPACE_PLAYER;
if (!gizmo->visible) {
return;
}
@@ -25,10 +30,10 @@ void gizmo_update() {
gizmo->transform->loc = (vec4_t){g_context->layer->decal_mat.m30, g_context->layer->decal_mat.m31, g_context->layer->decal_mat.m32, 1.0};
}
camera_object_t *cam = scene_camera;
f32 fov = cam->data->fov;
f32 dist = vec4_dist(cam->base->transform->loc, gizmo->transform->loc) / 8.0 * fov;
gizmo->transform->scale = (vec4_t){dist, dist, dist, 1.0};
camera_object_t *cam = scene_camera;
f32 fov = cam->data->fov;
f32 dist = vec4_dist(cam->base->transform->loc, gizmo->transform->loc) / 8.0 * fov;
gizmo->transform->scale = (vec4_t){dist, dist, dist, 1.0};
g_context->gizmo_translate_x->transform->scale = (vec4_t){dist, dist, dist, 1.0};
g_context->gizmo_translate_y->transform->scale = (vec4_t){dist, dist, dist, 1.0};
g_context->gizmo_translate_z->transform->scale = (vec4_t){dist, dist, dist, 1.0};
@@ -42,8 +47,8 @@ void gizmo_update() {
// Scene control
if (is_object) {
if (g_context->translate_x || g_context->translate_y || g_context->translate_z || g_context->scale_x || g_context->scale_y ||
g_context->scale_z || g_context->rotate_x || g_context->rotate_y || g_context->rotate_z) {
if (g_context->translate_x || g_context->translate_y || g_context->translate_z || g_context->scale_x || g_context->scale_y || g_context->scale_z ||
g_context->rotate_x || g_context->rotate_y || g_context->rotate_z) {
if (g_context->translate_x) {
paint_object->transform->loc.x = g_context->gizmo_drag;
}
@@ -86,8 +91,8 @@ void gizmo_update() {
}
// Decal layer control
else if (is_decal) {
if (g_context->translate_x || g_context->translate_y || g_context->translate_z || g_context->scale_x || g_context->scale_y ||
g_context->scale_z || g_context->rotate_x || g_context->rotate_y || g_context->rotate_z) {
if (g_context->translate_x || g_context->translate_y || g_context->translate_z || g_context->scale_x || g_context->scale_y || g_context->scale_z ||
g_context->rotate_x || g_context->rotate_y || g_context->rotate_z) {
if (g_context->translate_x) {
g_context->layer->decal_mat.m30 = g_context->gizmo_drag;
}
@@ -122,30 +127,30 @@ void gizmo_update() {
g_context->layer->decal_mat = mat4_compose(gizmo_v, gizmo_q, gizmo_v0);
}
else if (g_context->rotate_x) {
mat4_decomposed_t *dec = mat4_decompose(g_context->layer->decal_mat);
gizmo_v = dec->loc;
gizmo_q = dec->rot;
gizmo_v0 = dec->scl;
gizmo_q0 = quat_from_axis_angle(vec4_x_axis(), -g_context->gizmo_drag + g_context->gizmo_drag_last);
gizmo_q = quat_mult(gizmo_q0, gizmo_q);
mat4_decomposed_t *dec = mat4_decompose(g_context->layer->decal_mat);
gizmo_v = dec->loc;
gizmo_q = dec->rot;
gizmo_v0 = dec->scl;
gizmo_q0 = quat_from_axis_angle(vec4_x_axis(), -g_context->gizmo_drag + g_context->gizmo_drag_last);
gizmo_q = quat_mult(gizmo_q0, gizmo_q);
g_context->layer->decal_mat = mat4_compose(gizmo_v, gizmo_q, gizmo_v0);
}
else if (g_context->rotate_y) {
mat4_decomposed_t *dec = mat4_decompose(g_context->layer->decal_mat);
gizmo_v = dec->loc;
gizmo_q = dec->rot;
gizmo_v0 = dec->scl;
gizmo_q0 = quat_from_axis_angle(vec4_y_axis(), -g_context->gizmo_drag + g_context->gizmo_drag_last);
gizmo_q = quat_mult(gizmo_q0, gizmo_q);
mat4_decomposed_t *dec = mat4_decompose(g_context->layer->decal_mat);
gizmo_v = dec->loc;
gizmo_q = dec->rot;
gizmo_v0 = dec->scl;
gizmo_q0 = quat_from_axis_angle(vec4_y_axis(), -g_context->gizmo_drag + g_context->gizmo_drag_last);
gizmo_q = quat_mult(gizmo_q0, gizmo_q);
g_context->layer->decal_mat = mat4_compose(gizmo_v, gizmo_q, gizmo_v0);
}
else if (g_context->rotate_z) {
mat4_decomposed_t *dec = mat4_decompose(g_context->layer->decal_mat);
gizmo_v = dec->loc;
gizmo_q = dec->rot;
gizmo_v0 = dec->scl;
gizmo_q0 = quat_from_axis_angle(vec4_z_axis(), g_context->gizmo_drag - g_context->gizmo_drag_last);
gizmo_q = quat_mult(gizmo_q0, gizmo_q);
mat4_decomposed_t *dec = mat4_decompose(g_context->layer->decal_mat);
gizmo_v = dec->loc;
gizmo_q = dec->rot;
gizmo_v0 = dec->scl;
gizmo_q0 = quat_from_axis_angle(vec4_z_axis(), g_context->gizmo_drag - g_context->gizmo_drag_last);
gizmo_q = quat_mult(gizmo_q0, gizmo_q);
g_context->layer->decal_mat = mat4_compose(gizmo_v, gizmo_q, gizmo_v0);
}
g_context->gizmo_drag_last = g_context->gizmo_drag;
@@ -190,8 +195,7 @@ void gizmo_update() {
else if (hit->object == g_context->gizmo_scale_z) {
g_context->scale_z = true;
}
if (g_context->translate_x || g_context->translate_y || g_context->translate_z || g_context->scale_x || g_context->scale_y ||
g_context->scale_z) {
if (g_context->translate_x || g_context->translate_y || g_context->translate_z || g_context->scale_x || g_context->scale_y || g_context->scale_z) {
g_context->gizmo_offset = 0.0;
g_context->gizmo_started = true;
}
@@ -229,8 +233,8 @@ void gizmo_update() {
g_context->rotate_x = g_context->rotate_y = g_context->rotate_z = false;
}
if (g_context->translate_x || g_context->translate_y || g_context->translate_z || g_context->scale_x || g_context->scale_y ||
g_context->scale_z || g_context->rotate_x || g_context->rotate_y || g_context->rotate_z) {
if (g_context->translate_x || g_context->translate_y || g_context->translate_z || g_context->scale_x || g_context->scale_y || g_context->scale_z ||
g_context->rotate_x || g_context->rotate_y || g_context->rotate_z) {
g_context->rdirty = 2;
if (is_object) {
transform_t *t = paint_object->transform;
@@ -271,10 +275,10 @@ void gizmo_update() {
vec4_t hit = raycast_plane_intersect(vec4_x_axis(), gizmo_v, mouse_view_x(), mouse_view_y(), scene_camera);
if (!vec4_isnan(hit)) {
if (g_context->gizmo_started) {
mat4_decomposed_t *dec = mat4_decompose(g_context->layer->decal_mat);
gizmo_v = dec->loc;
gizmo_q = dec->rot;
gizmo_v0 = dec->scl;
mat4_decomposed_t *dec = mat4_decompose(g_context->layer->decal_mat);
gizmo_v = dec->loc;
gizmo_q = dec->rot;
gizmo_v0 = dec->scl;
g_context->gizmo_offset = math_atan2(hit.y - gizmo_v.y, hit.z - gizmo_v.z);
}
g_context->gizmo_drag = math_atan2(hit.y - gizmo_v.y, hit.z - gizmo_v.z) - g_context->gizmo_offset;
@@ -284,10 +288,10 @@ void gizmo_update() {
vec4_t hit = raycast_plane_intersect(vec4_y_axis(), gizmo_v, mouse_view_x(), mouse_view_y(), scene_camera);
if (!vec4_isnan(hit)) {
if (g_context->gizmo_started) {
mat4_decomposed_t *dec = mat4_decompose(g_context->layer->decal_mat);
gizmo_v = dec->loc;
gizmo_q = dec->rot;
gizmo_v0 = dec->scl;
mat4_decomposed_t *dec = mat4_decompose(g_context->layer->decal_mat);
gizmo_v = dec->loc;
gizmo_q = dec->rot;
gizmo_v0 = dec->scl;
g_context->gizmo_offset = math_atan2(hit.z - gizmo_v.z, hit.x - gizmo_v.x);
}
g_context->gizmo_drag = math_atan2(hit.z - gizmo_v.z, hit.x - gizmo_v.x) - g_context->gizmo_offset;
@@ -297,10 +301,10 @@ void gizmo_update() {
vec4_t hit = raycast_plane_intersect(vec4_z_axis(), gizmo_v, mouse_view_x(), mouse_view_y(), scene_camera);
if (!vec4_isnan(hit)) {
if (g_context->gizmo_started) {
mat4_decomposed_t *dec = mat4_decompose(g_context->layer->decal_mat);
gizmo_v = dec->loc;
gizmo_q = dec->rot;
gizmo_v0 = dec->scl;
mat4_decomposed_t *dec = mat4_decompose(g_context->layer->decal_mat);
gizmo_v = dec->loc;
gizmo_q = dec->rot;
gizmo_v0 = dec->scl;
g_context->gizmo_offset = math_atan2(hit.y - gizmo_v.y, hit.x - gizmo_v.x);
}
g_context->gizmo_drag = math_atan2(hit.y - gizmo_v.y, hit.x - gizmo_v.x) - g_context->gizmo_offset;
+49 -57
View File
@@ -109,10 +109,6 @@ i32 ui_base_viewport_col;
ui_handle_t_array_t *ui_base_hwnds;
ui_handle_t_array_t *ui_base_htabs;
tab_draw_array_t_array_t *ui_base_hwnd_tabs;
vec4_t gizmo_v;
vec4_t gizmo_v0;
quat_t gizmo_q;
quat_t gizmo_q0;
context_t *g_context;
i32 ui_toolbar_default_w = 36;
ui_handle_t *ui_toolbar_handle;
@@ -148,7 +144,7 @@ i32 render_path_base_taa_frame = 0;
i32 render_path_base_bloom_current_mip = 0;
f32 render_path_base_bloom_sample_scale;
bool render_path_base_buf_swapped = false;
project_t *g_project;
project_t *g_project;
char *project_filepath = "";
asset_t_array_t *project_assets;
string_array_t *project_asset_names;
@@ -330,7 +326,7 @@ fun pack_f32_i16(f: float, i: uint): float { \
} \
";
char *str_dither_bayer = "\
char *str_dither_bayer = "\
fun dither_bayer(uv: float2): float { \
var x: int = int(uv.x % 4.0); \
var y: int = int(uv.y % 4.0); \
@@ -382,49 +378,48 @@ fun dither_bayer(uv: float2): float { \
return 5.0 / 16.0; \
} \
";
i32 ui_sidebar_default_w_mini = 56;
i32 ui_sidebar_default_w_full = 280;
i32 ui_sidebar_default_w;
ui_handle_t *ui_sidebar_hminimized;
i32 ui_sidebar_w_mini;
char *console_message = "";
f32 console_message_timer = 0.0;
i32 console_message_color = 0x00000000;
string_array_t *console_last_traces;
vec4_t camera_origins[2];
mat4_t camera_views[2];
vec4_t camera_dir;
ui_handle_t *box_preferences_htab;
string_array_t *box_preferences_files_plugin = NULL;
ui_handle_t *box_preferences_h_theme;
ui_handle_t *box_preferences_h_preset;
slot_layer_t *render_path_paint_live_layer = NULL;
i32 render_path_paint_live_layer_drawn = 0;
bool render_path_paint_live_layer_locked = false;
bool render_path_paint_push_undo_last;
bool ui_box_show = false;
ui_handle_t *ui_box_hwnd;
bool ui_box_click_to_hide = true;
i32 ui_box_modalw = 400;
i32 ui_box_modalh = 170;
i32 _tab_scene_paint_object_length = 1;
ui_handle_t *tab_layers_layer_name_handle;
gpu_texture_t *util_uv_uvmap = NULL;
bool util_uv_uvmap_cached = false;
gpu_texture_t *util_uv_trianglemap = NULL;
bool util_uv_trianglemap_cached = false;
gpu_texture_t *util_uv_dilatemap = NULL;
bool util_uv_dilatemap_cached = false;
gpu_texture_t *util_uv_uvislandmap = NULL;
bool util_uv_uvislandmap_cached = false;
i32 render_path_raytrace_frame = 0;
bool render_path_raytrace_ready = false;
i32 render_path_raytrace_dirty = 0;
bool render_path_raytrace_init_shader = true;
f32_array_t *render_path_raytrace_f32a;
mat4_t render_path_raytrace_help_mat;
gpu_texture_t *render_path_raytrace_last_envmap = NULL;
bool render_path_raytrace_is_bake = false;
i32 ui_sidebar_default_w_mini = 56;
i32 ui_sidebar_default_w_full = 280;
i32 ui_sidebar_default_w;
ui_handle_t *ui_sidebar_hminimized;
i32 ui_sidebar_w_mini;
char *console_message = "";
f32 console_message_timer = 0.0;
i32 console_message_color = 0x00000000;
string_array_t *console_last_traces;
vec4_t camera_origins[2];
mat4_t camera_views[2];
ui_handle_t *box_preferences_htab;
string_array_t *box_preferences_files_plugin = NULL;
ui_handle_t *box_preferences_h_theme;
ui_handle_t *box_preferences_h_preset;
slot_layer_t *render_path_paint_live_layer = NULL;
i32 render_path_paint_live_layer_drawn = 0;
bool render_path_paint_live_layer_locked = false;
bool render_path_paint_push_undo_last;
bool ui_box_show = false;
ui_handle_t *ui_box_hwnd;
bool ui_box_click_to_hide = true;
i32 ui_box_modalw = 400;
i32 ui_box_modalh = 170;
i32 _tab_scene_paint_object_length = 1;
ui_handle_t *tab_layers_layer_name_handle;
gpu_texture_t *util_uv_uvmap = NULL;
bool util_uv_uvmap_cached = false;
gpu_texture_t *util_uv_trianglemap = NULL;
bool util_uv_trianglemap_cached = false;
gpu_texture_t *util_uv_dilatemap = NULL;
bool util_uv_dilatemap_cached = false;
gpu_texture_t *util_uv_uvislandmap = NULL;
bool util_uv_uvislandmap_cached = false;
i32 render_path_raytrace_frame = 0;
bool render_path_raytrace_ready = false;
i32 render_path_raytrace_dirty = 0;
bool render_path_raytrace_init_shader = true;
f32_array_t *render_path_raytrace_f32a;
mat4_t render_path_raytrace_help_mat;
gpu_texture_t *render_path_raytrace_last_envmap = NULL;
bool render_path_raytrace_is_bake = false;
#ifdef IRON_DIRECT3D12
char *render_path_raytrace_ext = ".cso";
@@ -434,13 +429,11 @@ char *render_path_raytrace_ext = ".metal";
char *render_path_raytrace_ext = ".spirv";
#endif
bool sculpt_push_undo = false;
i32 ui_statusbar_default_h = 33;
vec4_t import_envmap_params;
vec4_t import_envmap_n;
char *parser_material_bake_passthrough_strength = "0.0";
char *parser_material_bake_passthrough_radius = "0.0";
char *parser_material_bake_passthrough_offset = "0.0";
bool sculpt_push_undo = false;
i32 ui_statusbar_default_h = 33;
char *parser_material_bake_passthrough_strength = "0.0";
char *parser_material_bake_passthrough_radius = "0.0";
char *parser_material_bake_passthrough_offset = "0.0";
char *str_hue_sat = "\
fun hsv_to_rgb(c: float3): float3 { \
@@ -477,4 +470,3 @@ any_imap_t *neural_node_results;
ui_node_t *neural_node_current;
i32 neural_node_downloading = 0;
neural_node_model_t_array_t *neural_node_models = NULL;
vec4_t input_node_coords;
+5 -3
View File
@@ -6,7 +6,9 @@ i32 import_envmap_params_loc;
i32 import_envmap_radiance_loc;
gpu_texture_t *import_envmap_radiance = NULL;
i32 import_envmap_noise_loc;
gpu_texture_t_array_t *import_envmap_mips = NULL;
gpu_texture_t_array_t *import_envmap_mips = NULL;
vec4_t import_envmap_params = (vec4_t){0.0, 0.0, 0.0, 1.0};
vec4_t import_envmap_n = (vec4_t){0.0, 0.0, 0.0, 1.0};
void import_envmap_get_radiance_mip(gpu_texture_t *mip, i32 level, gpu_texture_t *radiance) {
#ifdef IRON_METAL
@@ -144,8 +146,8 @@ void import_envmap_run(char *path, gpu_texture_t *image) {
scene_world->envmap = string_copy(path);
scene_world->_->radiance = import_envmap_radiance;
scene_world->_->radiance_mipmaps = import_envmap_mips;
g_context->saved_envmap = image;
g_context->show_envmap = true;
g_context->saved_envmap = image;
g_context->show_envmap = true;
if (g_context->show_envmap_blur) {
scene_world->_->envmap = scene_world->_->radiance_mipmaps->buffer[0];
}
+1 -10
View File
@@ -88,10 +88,6 @@ void _kickstart() {
ui_base_hwnd_tabs = ui_base_init_hwnd_tabs();
gc_root(ui_base_hwnd_tabs);
gizmo_v = (vec4_t){0.0, 0.0, 0.0, 1.0};
gizmo_v0 = (vec4_t){0.0, 0.0, 0.0, 1.0};
gizmo_q = (quat_t){0.0, 0.0, 0.0, 1.0};
gizmo_q0 = (quat_t){0.0, 0.0, 0.0, 1.0};
ui_toolbar_handle = ui_handle_create();
gc_root(ui_toolbar_handle);
@@ -157,7 +153,7 @@ void _kickstart() {
ui_menubar_tab = ui_handle_create();
gc_root(ui_menubar_tab);
ui_menubar_w = ui_menubar_default_w;
ui_menubar_w = ui_menubar_default_w;
translator_translations = any_map_create();
gc_root(translator_translations);
@@ -315,7 +311,6 @@ void _kickstart() {
console_last_traces = any_array_create(0);
gc_root(console_last_traces);
camera_dir = (vec4_t){0.0, 0.0, 0.0, 1.0};
box_preferences_htab = ui_handle_create();
gc_root(box_preferences_htab);
@@ -330,12 +325,8 @@ void _kickstart() {
gc_root(render_path_raytrace_f32a);
render_path_raytrace_help_mat = mat4_identity();
import_envmap_params = (vec4_t){0.0, 0.0, 0.0, 1.0};
import_envmap_n = (vec4_t){0.0, 0.0, 0.0, 1.0};
neural_node_results = any_imap_create();
gc_root(neural_node_results);
input_node_coords = (vec4_t){0.0, 0.0, 0.0, 1.0};
sys_on_resize = base_on_resize;
sys_on_w = base_w;