summaryrefslogtreecommitdiff
path: root/scene/3d/baked_lightmap.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/3d/baked_lightmap.cpp')
-rw-r--r--scene/3d/baked_lightmap.cpp69
1 files changed, 53 insertions, 16 deletions
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);
}
}