2024-03-14 15:31:22 +01:00
|
|
|
|
|
|
|
|
function import_folder_run(path: string) {
|
2025-10-15 18:39:55 +02:00
|
|
|
let files: string[] = file_read_directory(path);
|
|
|
|
|
let mapbase: string = "";
|
|
|
|
|
let mapopac: string = "";
|
|
|
|
|
let mapnor: string = "";
|
|
|
|
|
let mapocc: string = "";
|
|
|
|
|
let maprough: string = "";
|
|
|
|
|
let mapmet: string = "";
|
2024-03-14 15:31:22 +01:00
|
|
|
let mapheight: string = "";
|
|
|
|
|
|
|
|
|
|
let found_texture: bool = false;
|
|
|
|
|
// Import maps
|
2024-03-21 21:06:41 +01:00
|
|
|
for (let i: i32 = 0; i < files.length; ++i) {
|
|
|
|
|
let f: string = files[i];
|
2024-03-20 16:13:54 +01:00
|
|
|
if (!path_is_texture(f)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2024-03-14 15:31:22 +01:00
|
|
|
|
|
|
|
|
// TODO: handle -albedo
|
|
|
|
|
|
2024-03-20 16:13:54 +01:00
|
|
|
let base: string = to_lower_case(substring(f, 0, string_last_index_of(f, ".")));
|
2025-10-15 18:39:55 +02:00
|
|
|
let valid: bool = false;
|
2024-03-14 15:31:22 +01:00
|
|
|
if (mapbase == "" && path_is_base_color_tex(base)) {
|
|
|
|
|
mapbase = f;
|
2025-10-15 18:39:55 +02:00
|
|
|
valid = true;
|
2024-03-14 15:31:22 +01:00
|
|
|
}
|
|
|
|
|
if (mapopac == "" && path_is_opacity_tex(base)) {
|
|
|
|
|
mapopac = f;
|
2025-10-15 18:39:55 +02:00
|
|
|
valid = true;
|
2024-03-14 15:31:22 +01:00
|
|
|
}
|
|
|
|
|
if (mapnor == "" && path_is_normal_map_tex(base)) {
|
|
|
|
|
mapnor = f;
|
2025-10-15 18:39:55 +02:00
|
|
|
valid = true;
|
2024-03-14 15:31:22 +01:00
|
|
|
}
|
|
|
|
|
if (mapocc == "" && path_is_occlusion_tex(base)) {
|
|
|
|
|
mapocc = f;
|
2025-10-15 18:39:55 +02:00
|
|
|
valid = true;
|
2024-03-14 15:31:22 +01:00
|
|
|
}
|
|
|
|
|
if (maprough == "" && path_is_roughness_tex(base)) {
|
|
|
|
|
maprough = f;
|
2025-10-15 18:39:55 +02:00
|
|
|
valid = true;
|
2024-03-14 15:31:22 +01:00
|
|
|
}
|
|
|
|
|
if (mapmet == "" && path_is_metallic_tex(base)) {
|
|
|
|
|
mapmet = f;
|
2025-10-15 18:39:55 +02:00
|
|
|
valid = true;
|
2024-03-14 15:31:22 +01:00
|
|
|
}
|
|
|
|
|
if (mapheight == "" && path_is_displacement_tex(base)) {
|
|
|
|
|
mapheight = f;
|
2025-10-15 18:39:55 +02:00
|
|
|
valid = true;
|
2024-03-14 15:31:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (valid) {
|
|
|
|
|
import_texture_run(path + path_sep + f, false);
|
|
|
|
|
found_texture = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!found_texture) {
|
|
|
|
|
console_info(tr("Folder does not contain textures"));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Create material
|
|
|
|
|
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);
|
2025-10-15 18:39:55 +02:00
|
|
|
let nodes: ui_nodes_t = context_raw.material.nodes;
|
2024-09-03 15:52:05 +02:00
|
|
|
let canvas: ui_node_canvas_t = context_raw.material.canvas;
|
2025-10-15 18:39:55 +02:00
|
|
|
let dirs: string[] = string_split(path, path_sep);
|
|
|
|
|
canvas.name = dirs[dirs.length - 1];
|
|
|
|
|
let nout: ui_node_t = null;
|
2024-03-21 21:06:41 +01:00
|
|
|
for (let i: i32 = 0; i < canvas.nodes.length; ++i) {
|
2024-09-03 15:52:05 +02:00
|
|
|
let n: ui_node_t = canvas.nodes[i];
|
2024-03-14 15:31:22 +01:00
|
|
|
if (n.type == "OUTPUT_MATERIAL_PBR") {
|
|
|
|
|
nout = n;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-03-21 21:06:41 +01:00
|
|
|
for (let i: i32 = 0; i < canvas.nodes.length; ++i) {
|
2024-09-03 15:52:05 +02:00
|
|
|
let n: ui_node_t = canvas.nodes[i];
|
2024-03-14 15:31:22 +01:00
|
|
|
if (n.name == "RGB") {
|
2024-09-03 15:52:05 +02:00
|
|
|
ui_remove_node(n, canvas);
|
2024-03-14 15:31:22 +01:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Place nodes
|
2025-10-15 18:39:55 +02:00
|
|
|
let pos: i32 = 0;
|
2024-03-14 15:31:22 +01:00
|
|
|
let start_y: i32 = 100;
|
2025-10-15 18:39:55 +02:00
|
|
|
let node_h: i32 = 164;
|
2024-03-14 15:31:22 +01:00
|
|
|
if (mapbase != "") {
|
|
|
|
|
import_folder_place_image_node(nodes, canvas, mapbase, start_y + node_h * pos, nout.id, 0);
|
|
|
|
|
pos++;
|
|
|
|
|
}
|
|
|
|
|
if (mapopac != "") {
|
|
|
|
|
import_folder_place_image_node(nodes, canvas, mapopac, start_y + node_h * pos, nout.id, 1);
|
|
|
|
|
pos++;
|
|
|
|
|
}
|
|
|
|
|
if (mapocc != "") {
|
|
|
|
|
import_folder_place_image_node(nodes, canvas, mapocc, start_y + node_h * pos, nout.id, 2);
|
|
|
|
|
pos++;
|
|
|
|
|
}
|
|
|
|
|
if (maprough != "") {
|
|
|
|
|
import_folder_place_image_node(nodes, canvas, maprough, start_y + node_h * pos, nout.id, 3);
|
|
|
|
|
pos++;
|
|
|
|
|
}
|
|
|
|
|
if (mapmet != "") {
|
|
|
|
|
import_folder_place_image_node(nodes, canvas, mapmet, start_y + node_h * pos, nout.id, 4);
|
|
|
|
|
pos++;
|
|
|
|
|
}
|
|
|
|
|
if (mapnor != "") {
|
|
|
|
|
import_folder_place_image_node(nodes, canvas, mapnor, start_y + node_h * pos, nout.id, 5);
|
|
|
|
|
pos++;
|
|
|
|
|
}
|
|
|
|
|
if (mapheight != "") {
|
|
|
|
|
import_folder_place_image_node(nodes, canvas, mapheight, start_y + node_h * pos, nout.id, 7);
|
|
|
|
|
pos++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
make_material_parse_paint_material();
|
|
|
|
|
util_render_make_material_preview();
|
|
|
|
|
ui_base_hwnds[1].redraws = 2;
|
|
|
|
|
history_new_material();
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-03 15:52:05 +02:00
|
|
|
function import_folder_place_image_node(nodes: ui_nodes_t, canvas: ui_node_canvas_t, asset: string, ny: i32, to_id: i32, to_socket: i32) {
|
2025-10-15 18:39:55 +02:00
|
|
|
let n: ui_node_t = nodes_material_create_node("TEX_IMAGE");
|
2024-04-24 12:14:47 +02:00
|
|
|
n.buttons[0].default_value = f32_array_create_x(base_get_asset_index(asset));
|
2025-10-15 18:39:55 +02:00
|
|
|
n.x = 72;
|
|
|
|
|
n.y = ny;
|
|
|
|
|
let l: ui_node_link_t = {id : ui_next_link_id(canvas.links), from_id : n.id, from_socket : 0, to_id : to_id, to_socket : to_socket};
|
2024-03-20 16:13:54 +01:00
|
|
|
array_push(canvas.links, l);
|
2024-03-14 15:31:22 +01:00
|
|
|
}
|