Files
armorpaint/base/sources/ts/slot_material.ts
T

87 lines
2.2 KiB
TypeScript
Raw Normal View History

2024-03-14 15:31:22 +01:00
2024-03-21 21:06:41 +01:00
type slot_material_t = {
2024-09-03 15:52:05 +02:00
nodes?: ui_nodes_t;
canvas?: ui_node_canvas_t;
2025-03-10 20:38:53 +01:00
image?: iron_gpu_texture_t;
image_icon?: iron_gpu_texture_t;
2024-03-21 21:06:41 +01:00
preview_ready?: bool;
data?: material_data_t;
id?: i32;
paint_base?: bool;
paint_opac?: bool;
paint_occ?: bool;
paint_rough?: bool;
paint_met?: bool;
paint_nor?: bool;
paint_height?: bool;
paint_emis?: bool;
paint_subs?: bool;
};
2024-03-14 15:31:22 +01:00
2024-03-20 16:13:54 +01:00
let slot_material_default_canvas: buffer_t = null;
2024-03-14 15:31:22 +01:00
2024-09-03 15:52:05 +02:00
function slot_material_create(m: material_data_t = null, c: ui_node_canvas_t = null): slot_material_t {
2024-03-21 21:06:41 +01:00
let raw: slot_material_t = {};
2024-09-03 15:52:05 +02:00
raw.nodes = ui_nodes_create();
2024-03-21 21:06:41 +01:00
raw.preview_ready = false;
raw.id = 0;
raw.paint_base = true;
raw.paint_opac = true;
raw.paint_occ = true;
raw.paint_rough = true;
raw.paint_met = true;
raw.paint_nor = true;
raw.paint_height = true;
raw.paint_emis = true;
raw.paint_subs = true;
for (let i: i32 = 0; i < project_materials.length; ++i) {
let mat: slot_material_t = project_materials[i];
2024-03-20 16:13:54 +01:00
if (mat.id >= raw.id) {
raw.id = mat.id + 1;
}
}
2024-03-14 15:31:22 +01:00
raw.data = m;
let w: i32 = util_render_material_preview_size;
let w_icon: i32 = 50;
2025-04-24 22:19:44 +02:00
raw.image = gpu_create_render_target(w, w, tex_format_t.RGBA64);
raw.image_icon = gpu_create_render_target(w_icon, w_icon, tex_format_t.RGBA64);
2024-03-14 15:31:22 +01:00
if (c == null) {
if (slot_material_default_canvas == null) { // Synchronous
2024-03-20 16:13:54 +01:00
let b: buffer_t = data_get_blob("default_material.arm");
2024-03-14 15:31:22 +01:00
slot_material_default_canvas = b;
}
raw.canvas = armpack_decode(slot_material_default_canvas);
2024-11-23 22:16:56 +01:00
raw.canvas = util_clone_canvas(raw.canvas); // Clone to create GC references
2024-05-03 21:29:39 +02:00
let id: i32 = (raw.id + 1);
raw.canvas.name = "Material " + id;
2024-03-14 15:31:22 +01:00
}
else {
2024-11-23 22:16:56 +01:00
raw.canvas = util_clone_canvas(c);
2024-03-14 15:31:22 +01:00
}
2024-09-06 21:11:46 +02:00
///if (arm_android || arm_ios)
2024-03-20 16:13:54 +01:00
raw.nodes.pan_x -= 50; // Center initial position
2024-03-14 15:31:22 +01:00
///end
return raw;
}
2024-03-20 16:13:54 +01:00
function slot_material_unload(raw: slot_material_t) {
2025-03-11 19:49:42 +01:00
sys_notify_on_next_frame(function (raw: slot_material_t) {
2025-03-06 20:42:54 +01:00
iron_unload_image(raw.image);
iron_unload_image(raw.image_icon);
2024-04-07 09:52:45 +02:00
}, raw);
2024-03-14 15:31:22 +01:00
}
2024-03-20 16:13:54 +01:00
function slot_material_delete(raw: slot_material_t) {
2024-03-14 15:31:22 +01:00
slot_material_unload(raw);
2024-03-20 16:13:54 +01:00
let mpos: i32 = array_index_of(project_materials, raw);
array_remove(project_materials, raw);
2024-03-14 15:31:22 +01:00
if (project_materials.length > 0) {
context_set_material(project_materials[mpos > 0 ? mpos - 1 : 0]);
}
}