2024-03-14 15:31:22 +01:00
|
|
|
|
2024-11-08 23:46:39 +01:00
|
|
|
let _tab_materials_draw_slots: i32;
|
|
|
|
|
|
2024-09-03 15:52:05 +02:00
|
|
|
function tab_materials_draw(htab: ui_handle_t) {
|
2025-10-21 21:07:28 +02:00
|
|
|
let mini: bool = ui._window_w <= ui_sidebar_w_mini;
|
2024-03-14 15:31:22 +01:00
|
|
|
mini ? tab_materials_draw_mini(htab) : tab_materials_draw_full(htab);
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-03 15:52:05 +02:00
|
|
|
function tab_materials_draw_mini(htab: ui_handle_t) {
|
|
|
|
|
ui_set_hovered_tab_name(tr("Materials"));
|
2024-03-14 15:31:22 +01:00
|
|
|
|
2024-09-03 15:52:05 +02:00
|
|
|
ui_begin_sticky();
|
|
|
|
|
ui_separator(5);
|
2024-03-14 15:31:22 +01:00
|
|
|
|
|
|
|
|
tab_materials_button_nodes();
|
|
|
|
|
tab_materials_button_new("+");
|
|
|
|
|
|
2024-09-03 15:52:05 +02:00
|
|
|
ui_end_sticky();
|
|
|
|
|
ui_separator(3, false);
|
2024-03-14 15:31:22 +01:00
|
|
|
tab_materials_draw_slots(true);
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-03 15:52:05 +02:00
|
|
|
function tab_materials_draw_full(htab: ui_handle_t) {
|
|
|
|
|
if (ui_tab(htab, tr("Materials"))) {
|
|
|
|
|
ui_begin_sticky();
|
2025-10-21 21:07:28 +02:00
|
|
|
let row: f32[] = [ -70, -70, -70 ];
|
2024-09-03 15:52:05 +02:00
|
|
|
ui_row(row);
|
2024-03-14 15:31:22 +01:00
|
|
|
|
|
|
|
|
tab_materials_button_new(tr("New"));
|
2024-09-03 15:52:05 +02:00
|
|
|
if (ui_button(tr("Import"))) {
|
2024-03-14 15:31:22 +01:00
|
|
|
project_import_material();
|
|
|
|
|
}
|
|
|
|
|
tab_materials_button_nodes();
|
|
|
|
|
|
2024-09-03 15:52:05 +02:00
|
|
|
ui_end_sticky();
|
|
|
|
|
ui_separator(3, false);
|
2024-03-14 15:31:22 +01:00
|
|
|
tab_materials_draw_slots(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function tab_materials_button_nodes() {
|
2024-09-03 15:52:05 +02:00
|
|
|
if (ui_button(tr("Nodes"))) {
|
2024-03-14 15:31:22 +01:00
|
|
|
ui_base_show_material_nodes();
|
|
|
|
|
}
|
2024-03-20 16:13:54 +01:00
|
|
|
else if (ui.is_hovered) {
|
2024-09-03 15:52:05 +02:00
|
|
|
ui_tooltip(tr("Show Node Editor") + " (" + map_get(config_keymap, "toggle_node_editor") + ")");
|
2024-03-20 16:13:54 +01:00
|
|
|
}
|
2024-03-14 15:31:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function tab_materials_draw_slots(mini: bool) {
|
2025-09-16 23:46:20 +02:00
|
|
|
let slotw: i32 = math_floor((51 + math_floor(config_raw.window_scale * 2)) * UI_SCALE());
|
2025-10-21 21:07:28 +02:00
|
|
|
let num: i32 = math_floor(ui._window_w / slotw);
|
2024-11-12 10:18:57 +01:00
|
|
|
if (num == 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-03-14 15:31:22 +01:00
|
|
|
|
|
|
|
|
for (let row: i32 = 0; row < math_floor(math_ceil(project_materials.length / num)); ++row) {
|
|
|
|
|
let mult: i32 = config_raw.show_asset_names ? 2 : 1;
|
|
|
|
|
let ar: f32[] = [];
|
2024-05-03 21:29:39 +02:00
|
|
|
for (let i: i32 = 0; i < num * mult; ++i) {
|
2024-03-20 16:13:54 +01:00
|
|
|
array_push(ar, 1 / num);
|
|
|
|
|
}
|
2024-09-03 15:52:05 +02:00
|
|
|
ui_row(ar);
|
2024-03-14 15:31:22 +01:00
|
|
|
|
|
|
|
|
ui._x += 2;
|
2025-08-15 22:04:07 +02:00
|
|
|
let off: f32 = config_raw.show_asset_names ? UI_ELEMENT_OFFSET() * 10.0 : 6;
|
2024-03-20 16:13:54 +01:00
|
|
|
if (row > 0) {
|
|
|
|
|
ui._y += off;
|
|
|
|
|
}
|
2024-03-14 15:31:22 +01:00
|
|
|
|
|
|
|
|
for (let j: i32 = 0; j < num; ++j) {
|
2025-08-15 22:04:07 +02:00
|
|
|
let imgw: i32 = math_floor(50 * UI_SCALE());
|
2025-10-15 18:39:55 +02:00
|
|
|
let i: i32 = j + row * num;
|
2024-03-14 15:31:22 +01:00
|
|
|
if (i >= project_materials.length) {
|
2025-08-15 22:04:07 +02:00
|
|
|
ui_end_element_of_size(imgw);
|
2024-03-20 16:13:54 +01:00
|
|
|
if (config_raw.show_asset_names) {
|
2025-08-15 22:04:07 +02:00
|
|
|
ui_end_element_of_size(0);
|
2024-03-20 16:13:54 +01:00
|
|
|
}
|
2024-03-14 15:31:22 +01:00
|
|
|
continue;
|
|
|
|
|
}
|
2025-10-15 18:39:55 +02:00
|
|
|
let img: gpu_texture_t = UI_SCALE() > 1 ? project_materials[i].image : project_materials[i].image_icon;
|
2025-06-19 19:55:16 +02:00
|
|
|
let img_full: gpu_texture_t = project_materials[i].image;
|
2024-03-14 15:31:22 +01:00
|
|
|
|
|
|
|
|
// Highligh selected
|
|
|
|
|
if (context_raw.material == project_materials[i]) {
|
|
|
|
|
if (mini) {
|
2025-08-15 22:04:07 +02:00
|
|
|
let w: f32 = ui._w / UI_SCALE();
|
2024-09-03 15:52:05 +02:00
|
|
|
ui_rect(0, -2, w - 2, w - 4, ui.ops.theme.HIGHLIGHT_COL, 3);
|
2024-03-14 15:31:22 +01:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
let off: i32 = row % 2 == 1 ? 1 : 0;
|
2025-10-15 18:39:55 +02:00
|
|
|
let w: i32 = 50 + math_floor(config_raw.window_scale * 2);
|
|
|
|
|
ui_fill(-1, -2, w + 3, 2, ui.ops.theme.HIGHLIGHT_COL);
|
|
|
|
|
ui_fill(-1, w - off, w + 3, 2 + off, ui.ops.theme.HIGHLIGHT_COL);
|
|
|
|
|
ui_fill(-1, -2, 2, w + 3, ui.ops.theme.HIGHLIGHT_COL);
|
|
|
|
|
ui_fill(w + 1, -2, 2, w + 4, ui.ops.theme.HIGHLIGHT_COL);
|
2024-03-14 15:31:22 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Draw material icon
|
2025-10-15 18:39:55 +02:00
|
|
|
let uix: f32 = ui._x;
|
|
|
|
|
let uiy: f32 = ui._y;
|
|
|
|
|
let tile: i32 = UI_SCALE() > 1 ? 100 : 50;
|
|
|
|
|
let imgh: f32 = mini ? ui_sidebar_default_w_mini * 0.85 * UI_SCALE() : 50 * UI_SCALE();
|
|
|
|
|
let state: ui_state_t = project_materials[i].preview_ready ? ui_image(img, 0xffffffff, imgh)
|
|
|
|
|
: ui_sub_image(resource_get("icons.k"), 0xffffffff, -1.0, tile, tile, tile, tile);
|
2024-03-14 15:31:22 +01:00
|
|
|
|
|
|
|
|
// Draw material numbers when selecting a material via keyboard shortcut
|
2025-08-15 22:04:07 +02:00
|
|
|
let is_typing: bool = ui.is_typing;
|
2024-03-14 15:31:22 +01:00
|
|
|
if (!is_typing) {
|
2024-04-08 17:40:32 +02:00
|
|
|
if (i < 9 && operator_shortcut(map_get(config_keymap, "select_material"), shortcut_type_t.DOWN)) {
|
2024-05-03 21:29:39 +02:00
|
|
|
let number: string = i32_to_string(i + 1);
|
2025-10-15 18:39:55 +02:00
|
|
|
let width: i32 = draw_string_width(ui.ops.font, ui.font_size, number) + 10;
|
|
|
|
|
let height: i32 = draw_font_height(ui.ops.font, ui.font_size);
|
2025-03-02 21:07:17 +01:00
|
|
|
draw_set_color(ui.ops.theme.TEXT_COL);
|
2025-03-02 19:44:26 +01:00
|
|
|
draw_filled_rect(uix, uiy, width, height);
|
2025-03-02 21:07:17 +01:00
|
|
|
draw_set_color(ui.ops.theme.BUTTON_COL);
|
2025-03-02 19:44:26 +01:00
|
|
|
draw_string(number, uix + 5, uiy);
|
2024-03-14 15:31:22 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Select material
|
2024-09-03 15:52:05 +02:00
|
|
|
if (state == ui_state_t.STARTED && ui.input_y > ui._window_y) {
|
2024-03-14 15:31:22 +01:00
|
|
|
if (context_raw.material != project_materials[i]) {
|
|
|
|
|
context_select_material(i);
|
2025-08-07 19:43:11 +02:00
|
|
|
if (context_raw.tool == tool_type_t.MATERIAL) {
|
2025-08-16 20:43:45 +02:00
|
|
|
sys_notify_on_next_frame(layers_update_fill_layers);
|
2024-03-14 15:31:22 +01:00
|
|
|
}
|
|
|
|
|
}
|
2025-10-15 18:39:55 +02:00
|
|
|
base_drag_off_x = -(mouse_x - uix - ui._window_x - 3);
|
|
|
|
|
base_drag_off_y = -(mouse_y - uiy - ui._window_y + 1);
|
2024-03-14 15:31:22 +01:00
|
|
|
base_drag_material = context_raw.material;
|
|
|
|
|
// Double click to show nodes
|
2025-09-26 17:42:01 +02:00
|
|
|
if (sys_time() - context_raw.select_time < 0.2) {
|
2024-03-14 15:31:22 +01:00
|
|
|
ui_base_show_material_nodes();
|
|
|
|
|
base_drag_material = null;
|
2025-10-15 18:39:55 +02:00
|
|
|
base_is_dragging = false;
|
2024-03-14 15:31:22 +01:00
|
|
|
}
|
2025-03-11 10:02:47 +01:00
|
|
|
context_raw.select_time = sys_time();
|
2024-03-14 15:31:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Context menu
|
|
|
|
|
if (ui.is_hovered && ui.input_released_r) {
|
|
|
|
|
context_select_material(i);
|
2024-04-07 09:52:45 +02:00
|
|
|
_tab_materials_draw_slots = i;
|
2024-03-14 15:31:22 +01:00
|
|
|
|
2025-10-15 18:39:55 +02:00
|
|
|
ui_menu_draw(function() {
|
|
|
|
|
let i: i32 = _tab_materials_draw_slots;
|
2024-03-20 16:13:54 +01:00
|
|
|
let m: slot_material_t = project_materials[i];
|
2024-03-14 15:31:22 +01:00
|
|
|
|
2025-02-26 08:47:09 +01:00
|
|
|
if (ui_menu_button(tr("To Fill Layer"))) {
|
2024-03-14 15:31:22 +01:00
|
|
|
context_select_material(i);
|
2024-11-10 16:53:36 +01:00
|
|
|
layers_create_fill_layer();
|
2024-03-14 15:31:22 +01:00
|
|
|
}
|
|
|
|
|
|
2025-02-26 08:47:09 +01:00
|
|
|
if (ui_menu_button(tr("Export"))) {
|
2024-03-14 15:31:22 +01:00
|
|
|
context_select_material(i);
|
|
|
|
|
box_export_show_material();
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-26 08:47:09 +01:00
|
|
|
if (ui_menu_button(tr("Bake"))) {
|
2024-03-14 15:31:22 +01:00
|
|
|
context_select_material(i);
|
|
|
|
|
box_export_show_bake_material();
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-26 08:47:09 +01:00
|
|
|
if (ui_menu_button(tr("Duplicate"))) {
|
2025-10-15 18:39:55 +02:00
|
|
|
sys_notify_on_next_frame(function() {
|
2024-04-07 09:52:45 +02:00
|
|
|
let i: i32 = _tab_materials_draw_slots;
|
|
|
|
|
|
2024-03-14 15:31:22 +01:00
|
|
|
context_raw.material = slot_material_create(project_materials[0].data);
|
2024-03-20 16:13:54 +01:00
|
|
|
array_push(project_materials, context_raw.material);
|
2024-09-03 15:52:05 +02:00
|
|
|
let cloned: ui_node_canvas_t = util_clone_canvas(project_materials[i].canvas);
|
2025-10-15 18:39:55 +02:00
|
|
|
context_raw.material.canvas = cloned;
|
2024-03-14 15:31:22 +01:00
|
|
|
tab_materials_update_material();
|
|
|
|
|
history_duplicate_material();
|
2024-04-07 09:52:45 +02:00
|
|
|
});
|
2024-03-14 15:31:22 +01:00
|
|
|
}
|
|
|
|
|
|
2025-02-26 08:47:09 +01:00
|
|
|
if (project_materials.length > 1 && ui_menu_button(tr("Delete"), "delete")) {
|
2024-03-14 15:31:22 +01:00
|
|
|
tab_materials_delete_material(m);
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-03 15:52:05 +02:00
|
|
|
let base_handle: ui_handle_t = ui_nest(ui_handle(__ID__), m.id);
|
2024-04-24 12:14:47 +02:00
|
|
|
if (base_handle.init) {
|
2025-09-23 21:44:39 +02:00
|
|
|
base_handle.b = m.paint_base;
|
2024-04-24 12:14:47 +02:00
|
|
|
}
|
|
|
|
|
|
2024-09-03 15:52:05 +02:00
|
|
|
let opac_handle: ui_handle_t = ui_nest(ui_handle(__ID__), m.id);
|
2024-04-24 12:14:47 +02:00
|
|
|
if (opac_handle.init) {
|
2025-09-23 21:44:39 +02:00
|
|
|
opac_handle.b = m.paint_opac;
|
2024-04-24 12:14:47 +02:00
|
|
|
}
|
|
|
|
|
|
2024-09-03 15:52:05 +02:00
|
|
|
let nor_handle: ui_handle_t = ui_nest(ui_handle(__ID__), m.id);
|
2024-04-24 12:14:47 +02:00
|
|
|
if (nor_handle.init) {
|
2025-09-23 21:44:39 +02:00
|
|
|
nor_handle.b = m.paint_nor;
|
2024-04-24 12:14:47 +02:00
|
|
|
}
|
|
|
|
|
|
2024-09-03 15:52:05 +02:00
|
|
|
let occ_handle: ui_handle_t = ui_nest(ui_handle(__ID__), m.id);
|
2024-04-24 12:14:47 +02:00
|
|
|
if (occ_handle.init) {
|
2025-09-23 21:44:39 +02:00
|
|
|
occ_handle.b = m.paint_occ;
|
2024-04-24 12:14:47 +02:00
|
|
|
}
|
|
|
|
|
|
2024-09-03 15:52:05 +02:00
|
|
|
let rough_handle: ui_handle_t = ui_nest(ui_handle(__ID__), m.id);
|
2024-04-24 12:14:47 +02:00
|
|
|
if (rough_handle.init) {
|
2025-09-23 21:44:39 +02:00
|
|
|
rough_handle.b = m.paint_rough;
|
2024-04-24 12:14:47 +02:00
|
|
|
}
|
|
|
|
|
|
2024-09-03 15:52:05 +02:00
|
|
|
let met_handle: ui_handle_t = ui_nest(ui_handle(__ID__), m.id);
|
2024-04-24 12:14:47 +02:00
|
|
|
if (met_handle.init) {
|
2025-09-23 21:44:39 +02:00
|
|
|
met_handle.b = m.paint_met;
|
2024-04-24 12:14:47 +02:00
|
|
|
}
|
|
|
|
|
|
2024-09-03 15:52:05 +02:00
|
|
|
let height_handle: ui_handle_t = ui_nest(ui_handle(__ID__), m.id);
|
2024-04-24 12:14:47 +02:00
|
|
|
if (height_handle.init) {
|
2025-09-23 21:44:39 +02:00
|
|
|
height_handle.b = m.paint_height;
|
2024-04-24 12:14:47 +02:00
|
|
|
}
|
|
|
|
|
|
2024-09-03 15:52:05 +02:00
|
|
|
let emis_handle: ui_handle_t = ui_nest(ui_handle(__ID__), m.id);
|
2024-04-24 12:14:47 +02:00
|
|
|
if (emis_handle.init) {
|
2025-09-23 21:44:39 +02:00
|
|
|
emis_handle.b = m.paint_emis;
|
2024-04-24 12:14:47 +02:00
|
|
|
}
|
|
|
|
|
|
2024-09-03 15:52:05 +02:00
|
|
|
let subs_handle: ui_handle_t = ui_nest(ui_handle(__ID__), m.id);
|
2024-04-24 12:14:47 +02:00
|
|
|
if (subs_handle.init) {
|
2025-09-23 21:44:39 +02:00
|
|
|
subs_handle.b = m.paint_subs;
|
2024-04-24 12:14:47 +02:00
|
|
|
}
|
|
|
|
|
|
2025-10-15 18:39:55 +02:00
|
|
|
m.paint_base = ui_check(base_handle, tr("Base Color"));
|
|
|
|
|
m.paint_opac = ui_check(opac_handle, tr("Opacity"));
|
|
|
|
|
m.paint_nor = ui_check(nor_handle, tr("Normal"));
|
|
|
|
|
m.paint_occ = ui_check(occ_handle, tr("Occlusion"));
|
|
|
|
|
m.paint_rough = ui_check(rough_handle, tr("Roughness"));
|
|
|
|
|
m.paint_met = ui_check(met_handle, tr("Metallic"));
|
2024-09-03 15:52:05 +02:00
|
|
|
m.paint_height = ui_check(height_handle, tr("Height"));
|
2025-10-15 18:39:55 +02:00
|
|
|
m.paint_emis = ui_check(emis_handle, tr("Emission"));
|
|
|
|
|
m.paint_subs = ui_check(subs_handle, tr("Subsurface"));
|
|
|
|
|
if (base_handle.changed || opac_handle.changed || nor_handle.changed || occ_handle.changed || rough_handle.changed || met_handle.changed ||
|
|
|
|
|
height_handle.changed || emis_handle.changed || subs_handle.changed) {
|
2024-03-14 15:31:22 +01:00
|
|
|
make_material_parse_paint_material();
|
|
|
|
|
ui_menu_keep_open = true;
|
|
|
|
|
}
|
2024-09-11 16:32:12 +02:00
|
|
|
});
|
2024-03-14 15:31:22 +01:00
|
|
|
}
|
|
|
|
|
if (ui.is_hovered) {
|
2025-03-10 22:13:30 +01:00
|
|
|
ui_tooltip_image(img_full);
|
2024-03-20 16:13:54 +01:00
|
|
|
if (i < 9) {
|
2024-05-03 21:29:39 +02:00
|
|
|
let i1: i32 = i + 1;
|
2024-09-03 15:52:05 +02:00
|
|
|
ui_tooltip(project_materials[i].canvas.name + " - (" + map_get(config_keymap, "select_material") + " " + i1 + ")");
|
2024-03-20 16:13:54 +01:00
|
|
|
}
|
|
|
|
|
else {
|
2024-09-03 15:52:05 +02:00
|
|
|
ui_tooltip(project_materials[i].canvas.name);
|
2024-03-20 16:13:54 +01:00
|
|
|
}
|
2024-03-14 15:31:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (config_raw.show_asset_names) {
|
|
|
|
|
ui._x = uix;
|
|
|
|
|
ui._y += slotw * 0.9;
|
2024-09-03 15:52:05 +02:00
|
|
|
ui_text(project_materials[i].canvas.name, ui_align_t.CENTER);
|
2024-03-14 15:31:22 +01:00
|
|
|
if (ui.is_hovered) {
|
2024-03-20 16:13:54 +01:00
|
|
|
if (i < 9) {
|
2024-05-03 21:29:39 +02:00
|
|
|
let i1: i32 = i + 1;
|
2024-09-03 15:52:05 +02:00
|
|
|
ui_tooltip(project_materials[i].canvas.name + " - (" + map_get(config_keymap, "select_material") + " " + i1 + ")");
|
2024-03-20 16:13:54 +01:00
|
|
|
}
|
|
|
|
|
else {
|
2024-09-03 15:52:05 +02:00
|
|
|
ui_tooltip(project_materials[i].canvas.name);
|
2024-03-20 16:13:54 +01:00
|
|
|
}
|
2024-03-14 15:31:22 +01:00
|
|
|
}
|
|
|
|
|
ui._y -= slotw * 0.9;
|
|
|
|
|
if (i == project_materials.length - 1) {
|
2025-08-15 22:04:07 +02:00
|
|
|
ui._y += j == num - 1 ? imgw : imgw + UI_ELEMENT_H() + UI_ELEMENT_OFFSET();
|
2024-03-14 15:31:22 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ui._y += mini ? 0 : 6;
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-15 18:39:55 +02:00
|
|
|
let in_focus: bool =
|
|
|
|
|
ui.input_x > ui._window_x && ui.input_x < ui._window_x + ui._window_w && ui.input_y > ui._window_y && ui.input_y < ui._window_y + ui._window_h;
|
2024-03-14 15:31:22 +01:00
|
|
|
if (in_focus && ui.is_delete_down && project_materials.length > 1) {
|
|
|
|
|
ui.is_delete_down = false;
|
|
|
|
|
tab_materials_delete_material(context_raw.material);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function tab_materials_button_new(text: string) {
|
2024-09-03 15:52:05 +02:00
|
|
|
if (ui_button(text)) {
|
2025-08-16 20:43:45 +02:00
|
|
|
sys_notify_on_next_frame(function() {
|
2024-08-26 22:14:53 +02:00
|
|
|
context_raw.material = slot_material_create(project_materials[0].data);
|
|
|
|
|
array_push(project_materials, context_raw.material);
|
|
|
|
|
tab_materials_update_material();
|
|
|
|
|
history_new_material();
|
|
|
|
|
});
|
2024-03-14 15:31:22 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function tab_materials_update_material() {
|
|
|
|
|
ui_header_handle.redraws = 2;
|
2025-10-15 18:39:55 +02:00
|
|
|
ui_nodes_hwnd.redraws = 2;
|
|
|
|
|
ui_nodes_group_stack = [];
|
2024-03-14 15:31:22 +01:00
|
|
|
make_material_parse_paint_material();
|
|
|
|
|
util_render_make_material_preview();
|
2024-11-09 11:31:18 +01:00
|
|
|
let decal: bool = context_is_decal();
|
2024-03-20 16:13:54 +01:00
|
|
|
if (decal) {
|
|
|
|
|
util_render_make_decal_preview();
|
|
|
|
|
}
|
2024-03-14 15:31:22 +01:00
|
|
|
}
|
|
|
|
|
|
2024-09-03 15:52:05 +02:00
|
|
|
function tab_materials_update_material_pointers(nodes: ui_node_t[], i: i32) {
|
2024-03-21 21:06:41 +01:00
|
|
|
for (let i: i32 = 0; i < nodes.length; ++i) {
|
2024-09-03 15:52:05 +02:00
|
|
|
let n: ui_node_t = nodes[i];
|
2024-03-14 15:31:22 +01:00
|
|
|
if (n.type == "MATERIAL") {
|
2024-04-24 12:14:47 +02:00
|
|
|
if (n.buttons[0].default_value[0] == i) {
|
|
|
|
|
n.buttons[0].default_value[0] = 9999; // Material deleted
|
2024-03-14 15:31:22 +01:00
|
|
|
}
|
2024-04-24 12:14:47 +02:00
|
|
|
else if (n.buttons[0].default_value[0] > i) {
|
|
|
|
|
n.buttons[0].default_value[0]--; // Offset by deleted material
|
2024-03-14 15:31:22 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-27 13:23:25 +02:00
|
|
|
function tab_materials_accept_swatch_drop(swatch: swatch_color_t) {
|
2024-03-14 15:31:22 +01:00
|
|
|
context_raw.material = slot_material_create(project_materials[0].data);
|
2024-03-21 21:06:41 +01:00
|
|
|
for (let i: i32 = 0; i < context_raw.material.canvas.nodes.length; ++i) {
|
2024-09-03 15:52:05 +02:00
|
|
|
let node: ui_node_t = context_raw.material.canvas.nodes[i];
|
2025-10-15 18:39:55 +02:00
|
|
|
if (node.type == "RGB") {
|
|
|
|
|
node.outputs[0].default_value = f32_array_create_xyzw(color_get_rb(swatch.base) / 255, color_get_gb(swatch.base) / 255,
|
|
|
|
|
color_get_bb(swatch.base) / 255, color_get_ab(swatch.base) / 255);
|
2024-03-14 15:31:22 +01:00
|
|
|
}
|
|
|
|
|
else if (node.type == "OUTPUT_MATERIAL_PBR") {
|
2024-04-24 12:14:47 +02:00
|
|
|
node.inputs[1].default_value[0] = swatch.opacity;
|
|
|
|
|
node.inputs[2].default_value[0] = swatch.occlusion;
|
|
|
|
|
node.inputs[3].default_value[0] = swatch.roughness;
|
|
|
|
|
node.inputs[4].default_value[0] = swatch.metallic;
|
|
|
|
|
node.inputs[7].default_value[0] = swatch.height;
|
2024-03-14 15:31:22 +01:00
|
|
|
}
|
|
|
|
|
}
|
2024-03-20 16:13:54 +01:00
|
|
|
array_push(project_materials, context_raw.material);
|
2024-03-14 15:31:22 +01:00
|
|
|
tab_materials_update_material();
|
|
|
|
|
history_new_material();
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-20 16:13:54 +01:00
|
|
|
function tab_materials_delete_material(m: slot_material_t) {
|
|
|
|
|
let i: i32 = array_index_of(project_materials, m);
|
2024-03-21 21:06:41 +01:00
|
|
|
for (let i: i32 = 0; i < project_layers.length; ++i) {
|
|
|
|
|
let l: slot_layer_t = project_layers[i];
|
2024-03-20 16:13:54 +01:00
|
|
|
if (l.fill_layer == m) {
|
|
|
|
|
l.fill_layer = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-03-14 15:31:22 +01:00
|
|
|
history_delete_material();
|
|
|
|
|
context_select_material(i == project_materials.length - 1 ? i - 1 : i + 1);
|
2024-03-20 16:13:54 +01:00
|
|
|
array_splice(project_materials, i, 1);
|
2024-03-14 15:31:22 +01:00
|
|
|
ui_base_hwnds[1].redraws = 2;
|
2024-03-21 21:06:41 +01:00
|
|
|
for (let i: i32 = 0; i < project_materials.length; ++i) {
|
|
|
|
|
let m: slot_material_t = project_materials[i];
|
2024-03-20 16:13:54 +01:00
|
|
|
tab_materials_update_material_pointers(m.canvas.nodes, i);
|
|
|
|
|
}
|
2025-09-28 17:50:13 +02:00
|
|
|
for (let i: i32 = 0; i < m.canvas.nodes.length; ++i) {
|
|
|
|
|
let n: ui_node_t = m.canvas.nodes[i];
|
|
|
|
|
ui_viewnodes_on_node_remove(n);
|
|
|
|
|
}
|
2024-03-14 15:31:22 +01:00
|
|
|
}
|