diff options
-rw-r--r-- | core/io/resource_loader.cpp | 2 | ||||
-rw-r--r-- | core/io/resource_loader.h | 4 | ||||
-rw-r--r-- | editor/editor_file_system.cpp | 12 | ||||
-rw-r--r-- | editor/editor_file_system.h | 2 | ||||
-rw-r--r-- | modules/thekla_unwrap/config.py | 3 | ||||
-rw-r--r-- | modules/xatlas_unwrap/config.py | 4 | ||||
-rw-r--r-- | modules/xatlas_unwrap/register_types.cpp | 18 | ||||
-rw-r--r-- | scene/3d/baked_lightmap.cpp | 69 |
8 files changed, 91 insertions, 23 deletions
diff --git a/core/io/resource_loader.cpp b/core/io/resource_loader.cpp index 8c56d55e85..d156a9f4bd 100644 --- a/core/io/resource_loader.cpp +++ b/core/io/resource_loader.cpp @@ -647,3 +647,5 @@ bool ResourceLoader::timestamp_on_load = false; SelfList<Resource>::List ResourceLoader::remapped_list; HashMap<String, Vector<String> > ResourceLoader::translation_remaps; HashMap<String, String> ResourceLoader::path_remaps; + +ResourceLoaderImport ResourceLoader::import = NULL; diff --git a/core/io/resource_loader.h b/core/io/resource_loader.h index de0981350d..96bc6fa8dd 100644 --- a/core/io/resource_loader.h +++ b/core/io/resource_loader.h @@ -77,6 +77,8 @@ public: typedef void (*ResourceLoadErrorNotify)(void *p_ud, const String &p_text); typedef void (*DependencyErrorNotify)(void *p_ud, const String &p_loading, const String &p_which, const String &p_type); +typedef Error (*ResourceLoaderImport)(const String &p_path); + class ResourceLoader { enum { @@ -147,6 +149,8 @@ public: static void reload_translation_remaps(); static void load_translation_remaps(); static void clear_translation_remaps(); + + static ResourceLoaderImport import; }; #endif diff --git a/editor/editor_file_system.cpp b/editor/editor_file_system.cpp index ee20d95f25..d73bf86f64 100644 --- a/editor/editor_file_system.cpp +++ b/editor/editor_file_system.cpp @@ -1705,6 +1705,17 @@ void EditorFileSystem::reimport_files(const Vector<String> &p_files) { emit_signal("resources_reimported", p_files); } +Error EditorFileSystem::_resource_import(const String &p_path) { + + Vector<String> files; + files.push_back(p_path); + + singleton->update_file(p_path); + singleton->reimport_files(files); + + return OK; +} + void EditorFileSystem::_bind_methods() { ClassDB::bind_method(D_METHOD("get_filesystem"), &EditorFileSystem::get_filesystem); @@ -1744,6 +1755,7 @@ void EditorFileSystem::_update_extensions() { EditorFileSystem::EditorFileSystem() { + ResourceLoader::import = _resource_import; reimport_on_missing_imported_files = GLOBAL_DEF("editor/reimport_missing_imported_files", true); singleton = this; diff --git a/editor/editor_file_system.h b/editor/editor_file_system.h index f2f72eddbd..47077425a1 100644 --- a/editor/editor_file_system.h +++ b/editor/editor_file_system.h @@ -230,6 +230,8 @@ class EditorFileSystem : public Node { String _get_global_script_class(const String &p_type, const String &p_path, String *r_extends, String *r_icon_path) const; + static Error _resource_import(const String &p_path); + protected: void _notification(int p_what); static void _bind_methods(); diff --git a/modules/thekla_unwrap/config.py b/modules/thekla_unwrap/config.py index bd092bdc16..fad6095064 100644 --- a/modules/thekla_unwrap/config.py +++ b/modules/thekla_unwrap/config.py @@ -1,5 +1,6 @@ def can_build(env, platform): - return (env['tools'] and platform not in ["android", "ios"]) + #return (env['tools'] and platform not in ["android", "ios"]) + return False def configure(env): pass diff --git a/modules/xatlas_unwrap/config.py b/modules/xatlas_unwrap/config.py index 962d33280f..2dda5db7e0 100644 --- a/modules/xatlas_unwrap/config.py +++ b/modules/xatlas_unwrap/config.py @@ -1,6 +1,6 @@ def can_build(env, platform): - return False #xatlas is buggy - #return (env['tools'] and platform not in ["android", "ios"]) + #return False #xatlas is buggy + return (env['tools'] and platform not in ["android", "ios"]) def configure(env): pass diff --git a/modules/xatlas_unwrap/register_types.cpp b/modules/xatlas_unwrap/register_types.cpp index 9df16aac70..57eea4eda6 100644 --- a/modules/xatlas_unwrap/register_types.cpp +++ b/modules/xatlas_unwrap/register_types.cpp @@ -75,8 +75,9 @@ bool xatlas_mesh_lightmap_unwrap_callback(float p_texel_size, const float *p_ver xatlas::CharterOptions chart_options; xatlas::PackerOptions pack_options; + pack_options.method = xatlas::PackMethod::TexelArea; pack_options.texelArea = 1.0 / p_texel_size; - pack_options.quality = 4; + pack_options.quality = 3; xatlas::Atlas *atlas = xatlas::Create(); printf("adding mesh..\n"); @@ -93,7 +94,10 @@ bool xatlas_mesh_lightmap_unwrap_callback(float p_texel_size, const float *p_ver float w = *r_size_hint_x; float h = *r_size_hint_y; - printf("final texsize: %f,%f\n", w, h); + if (w == 0 || h == 0) { + return false; //could not bake + } + const xatlas::OutputMesh *const *output_meshes = xatlas::GetOutputMeshes(atlas); const xatlas::OutputMesh *output = output_meshes[0]; @@ -102,11 +106,17 @@ bool xatlas_mesh_lightmap_unwrap_callback(float p_texel_size, const float *p_ver *r_uv = (float *)malloc(sizeof(float) * output->vertexCount * 2); *r_index = (int *)malloc(sizeof(int) * output->indexCount); + float max_x = 0; + float max_y = 0; for (int i = 0; i < output->vertexCount; i++) { (*r_vertex)[i] = output->vertexArray[i].xref; - (*r_uv)[i * 2 + 0] = output->vertexArray[i].uv[0]; - (*r_uv)[i * 2 + 1] = output->vertexArray[i].uv[1]; + (*r_uv)[i * 2 + 0] = output->vertexArray[i].uv[0] / w; + (*r_uv)[i * 2 + 1] = output->vertexArray[i].uv[1] / h; + max_x = MAX(max_x, output->vertexArray[i].uv[0]); + max_y = MAX(max_y, output->vertexArray[i].uv[1]); } + + printf("final texsize: %f,%f - max %f,%f\n", w, h, max_x, max_y); *r_vertex_count = output->vertexCount; for (int i = 0; i < output->indexCount; i++) { diff --git a/scene/3d/baked_lightmap.cpp b/scene/3d/baked_lightmap.cpp index 8f3fe8577e..62589bd67e 100644 --- a/scene/3d/baked_lightmap.cpp +++ b/scene/3d/baked_lightmap.cpp @@ -29,6 +29,7 @@ /*************************************************************************/ #include "baked_lightmap.h" +#include "core/io/config_file.h" #include "core/io/resource_saver.h" #include "core/os/dir_access.h" #include "core/os/os.h" @@ -526,21 +527,60 @@ BakedLightmap::BakeError BakedLightmap::bake(Node *p_from_node, bool p_create_vi tex_flags |= Texture::FLAG_CONVERT_TO_LINEAR; } - Ref<ImageTexture> tex; - String image_path = save_path.plus_file(mesh_name + ".tex"); - bool set_path = true; - if (ResourceCache::has(image_path)) { - tex = Ref<Resource>((Resource *)ResourceCache::get(image_path)); - set_path = false; - } + String image_path = save_path.plus_file(mesh_name); + Ref<Texture> texture; - if (!tex.is_valid()) { - tex.instance(); - } + if (ResourceLoader::import) { + + bool srgb = false; + if (false && hdr) { + //save hdr + } else { + image_path += ".png"; + print_line("image path saving png: " + image_path); + image->save_png(image_path); + srgb = true; + } - tex->create_from_image(image, tex_flags); + if (!FileAccess::exists(image_path + ".import")) { + Ref<ConfigFile> config; + config.instance(); + config->set_value("remap", "importer", "texture"); + config->set_value("remap", "type", "StreamTexture"); + config->set_value("params", "compress/mode", 2); + config->set_value("params", "detect_3d", false); + config->set_value("params", "flags/repeat", false); + config->set_value("params", "flags/filter", true); + config->set_value("params", "flags/mipmaps", false); + config->set_value("params", "flags/srgb", srgb); + + config->save(image_path + ".import"); + } + + ResourceLoader::import(image_path); + texture = ResourceLoader::load(image_path); //if already loaded, it will be updated on refocus? + } else { - err = ResourceSaver::save(image_path, tex, ResourceSaver::FLAG_CHANGE_PATH); + image_path += ".text"; + Ref<ImageTexture> tex; + bool set_path = true; + if (ResourceCache::has(image_path)) { + tex = Ref<Resource>((Resource *)ResourceCache::get(image_path)); + set_path = false; + } + + if (!tex.is_valid()) { + tex.instance(); + } + + tex->create_from_image(image, tex_flags); + + err = ResourceSaver::save(image_path, tex, ResourceSaver::FLAG_CHANGE_PATH); + if (set_path) { + tex->set_path(image_path); + } + texture = tex; + } if (err != OK) { if (bake_end_function) { bake_end_function(); @@ -548,10 +588,7 @@ BakedLightmap::BakeError BakedLightmap::bake(Node *p_from_node, bool p_create_vi ERR_FAIL_COND_V(err != OK, BAKE_ERROR_CANT_CREATE_IMAGE); } - if (set_path) { - tex->set_path(image_path); - } - new_light_data->add_user(E->get().path, tex, E->get().instance_idx); + new_light_data->add_user(E->get().path, texture, E->get().instance_idx); } } |