2024-03-13 23:50:11 +01:00
|
|
|
|
2024-04-25 22:04:43 +02:00
|
|
|
type import_texture_data_t = {
|
2024-04-07 09:52:45 +02:00
|
|
|
path: string;
|
2024-04-25 22:04:43 +02:00
|
|
|
image: image_t;
|
|
|
|
|
};
|
2024-04-07 09:52:45 +02:00
|
|
|
|
2024-03-13 23:50:11 +01:00
|
|
|
function import_texture_run(path: string, hdr_as_envmap: bool = true) {
|
|
|
|
|
if (!path_is_texture(path)) {
|
|
|
|
|
if (!context_enable_import_plugin(path)) {
|
|
|
|
|
console_error(strings_error1());
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-21 21:06:41 +01:00
|
|
|
for (let i: i32 = 0; i < project_assets.length; ++i) {
|
|
|
|
|
let a: asset_t = project_assets[i];
|
2024-03-13 23:50:11 +01:00
|
|
|
// Already imported
|
|
|
|
|
if (a.file == path) {
|
|
|
|
|
// Set as envmap
|
2024-03-20 16:13:54 +01:00
|
|
|
if (hdr_as_envmap && ends_with(to_lower_case(path), ".hdr")) {
|
2024-03-13 23:50:11 +01:00
|
|
|
let image: image_t = data_get_image(path);
|
2024-04-25 22:04:43 +02:00
|
|
|
let itd: import_texture_data_t = { path: path, image: image };
|
|
|
|
|
app_notify_on_next_frame(function (itd: import_texture_data_t) { // Make sure file browser process did finish
|
2024-04-07 09:52:45 +02:00
|
|
|
import_envmap_run(itd.path, itd.image);
|
|
|
|
|
}, itd);
|
2024-03-13 23:50:11 +01:00
|
|
|
}
|
|
|
|
|
console_info(strings_info0());
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-20 16:13:54 +01:00
|
|
|
let ext: string = substring(path, string_last_index_of(path, ".") + 1, path.length);
|
2024-08-24 11:17:02 +02:00
|
|
|
let importer: any = map_get(path_texture_importers, ext); // JSValue -> (s: string)=>image_t
|
2024-03-20 16:13:54 +01:00
|
|
|
let cached: bool = map_get(data_cached_images, path) != null; // Already loaded or pink texture for missing file
|
2024-08-24 11:17:02 +02:00
|
|
|
let image: image_t;
|
2024-03-20 16:13:54 +01:00
|
|
|
if (importer == null || cached) {
|
2024-08-24 11:17:02 +02:00
|
|
|
image = import_texture_default_importer(path);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
image = js_pcall_str(importer, path);
|
2024-03-20 16:13:54 +01:00
|
|
|
}
|
2024-03-13 23:50:11 +01:00
|
|
|
|
2024-04-02 15:45:49 +02:00
|
|
|
map_set(data_cached_images, path, image);
|
|
|
|
|
let ar: string[] = string_split(path, path_sep);
|
|
|
|
|
let name: string = ar[ar.length - 1];
|
|
|
|
|
let asset: asset_t = {name: name, file: path, id: project_asset_id++};
|
|
|
|
|
array_push(project_assets, asset);
|
|
|
|
|
if (context_raw.texture == null) {
|
|
|
|
|
context_raw.texture = asset;
|
|
|
|
|
}
|
|
|
|
|
array_push(project_asset_names, name);
|
|
|
|
|
map_set(project_asset_map, asset.id, image);
|
|
|
|
|
ui_base_hwnds[tab_area_t.STATUS].redraws = 2;
|
|
|
|
|
console_info(tr("Texture imported:") + " " + name);
|
2024-03-13 23:50:11 +01:00
|
|
|
|
2024-04-02 15:45:49 +02:00
|
|
|
// Set as envmap
|
|
|
|
|
if (hdr_as_envmap && ends_with(to_lower_case(path), ".hdr")) {
|
2024-04-25 22:04:43 +02:00
|
|
|
let itd: import_texture_data_t = { path: path, image: image };
|
|
|
|
|
app_notify_on_next_frame(function (itd: import_texture_data_t) { // Make sure file browser process did finish
|
2024-04-07 09:52:45 +02:00
|
|
|
import_envmap_run(itd.path, itd.image);
|
|
|
|
|
}, itd);
|
2024-04-02 15:45:49 +02:00
|
|
|
}
|
2024-03-13 23:50:11 +01:00
|
|
|
}
|
|
|
|
|
|
2024-04-02 15:45:49 +02:00
|
|
|
function import_texture_default_importer(path: string): image_t {
|
|
|
|
|
return data_get_image(path);
|
2024-03-13 23:50:11 +01:00
|
|
|
}
|