Fixes to baker, restored xatlas and fixed bake options.
This commit is contained in:
parent
a41cf404a9
commit
f12cb82e0f
8 changed files with 93 additions and 25 deletions
|
@ -647,3 +647,5 @@ bool ResourceLoader::timestamp_on_load = false;
|
||||||
SelfList<Resource>::List ResourceLoader::remapped_list;
|
SelfList<Resource>::List ResourceLoader::remapped_list;
|
||||||
HashMap<String, Vector<String> > ResourceLoader::translation_remaps;
|
HashMap<String, Vector<String> > ResourceLoader::translation_remaps;
|
||||||
HashMap<String, String> ResourceLoader::path_remaps;
|
HashMap<String, String> ResourceLoader::path_remaps;
|
||||||
|
|
||||||
|
ResourceLoaderImport ResourceLoader::import = NULL;
|
||||||
|
|
|
@ -77,6 +77,8 @@ public:
|
||||||
typedef void (*ResourceLoadErrorNotify)(void *p_ud, const String &p_text);
|
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 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 {
|
class ResourceLoader {
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
|
@ -147,6 +149,8 @@ public:
|
||||||
static void reload_translation_remaps();
|
static void reload_translation_remaps();
|
||||||
static void load_translation_remaps();
|
static void load_translation_remaps();
|
||||||
static void clear_translation_remaps();
|
static void clear_translation_remaps();
|
||||||
|
|
||||||
|
static ResourceLoaderImport import;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1705,6 +1705,17 @@ void EditorFileSystem::reimport_files(const Vector<String> &p_files) {
|
||||||
emit_signal("resources_reimported", 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() {
|
void EditorFileSystem::_bind_methods() {
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("get_filesystem"), &EditorFileSystem::get_filesystem);
|
ClassDB::bind_method(D_METHOD("get_filesystem"), &EditorFileSystem::get_filesystem);
|
||||||
|
@ -1744,6 +1755,7 @@ void EditorFileSystem::_update_extensions() {
|
||||||
|
|
||||||
EditorFileSystem::EditorFileSystem() {
|
EditorFileSystem::EditorFileSystem() {
|
||||||
|
|
||||||
|
ResourceLoader::import = _resource_import;
|
||||||
reimport_on_missing_imported_files = GLOBAL_DEF("editor/reimport_missing_imported_files", true);
|
reimport_on_missing_imported_files = GLOBAL_DEF("editor/reimport_missing_imported_files", true);
|
||||||
|
|
||||||
singleton = this;
|
singleton = this;
|
||||||
|
|
|
@ -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;
|
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:
|
protected:
|
||||||
void _notification(int p_what);
|
void _notification(int p_what);
|
||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
def can_build(env, platform):
|
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):
|
def configure(env):
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
def can_build(env, platform):
|
def can_build(env, platform):
|
||||||
return False #xatlas is buggy
|
#return False #xatlas is buggy
|
||||||
#return (env['tools'] and platform not in ["android", "ios"])
|
return (env['tools'] and platform not in ["android", "ios"])
|
||||||
|
|
||||||
def configure(env):
|
def configure(env):
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -75,8 +75,9 @@ bool xatlas_mesh_lightmap_unwrap_callback(float p_texel_size, const float *p_ver
|
||||||
xatlas::CharterOptions chart_options;
|
xatlas::CharterOptions chart_options;
|
||||||
xatlas::PackerOptions pack_options;
|
xatlas::PackerOptions pack_options;
|
||||||
|
|
||||||
|
pack_options.method = xatlas::PackMethod::TexelArea;
|
||||||
pack_options.texelArea = 1.0 / p_texel_size;
|
pack_options.texelArea = 1.0 / p_texel_size;
|
||||||
pack_options.quality = 4;
|
pack_options.quality = 3;
|
||||||
|
|
||||||
xatlas::Atlas *atlas = xatlas::Create();
|
xatlas::Atlas *atlas = xatlas::Create();
|
||||||
printf("adding mesh..\n");
|
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 w = *r_size_hint_x;
|
||||||
float h = *r_size_hint_y;
|
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 *const *output_meshes = xatlas::GetOutputMeshes(atlas);
|
||||||
|
|
||||||
const xatlas::OutputMesh *output = output_meshes[0];
|
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_uv = (float *)malloc(sizeof(float) * output->vertexCount * 2);
|
||||||
*r_index = (int *)malloc(sizeof(int) * output->indexCount);
|
*r_index = (int *)malloc(sizeof(int) * output->indexCount);
|
||||||
|
|
||||||
|
float max_x = 0;
|
||||||
|
float max_y = 0;
|
||||||
for (int i = 0; i < output->vertexCount; i++) {
|
for (int i = 0; i < output->vertexCount; i++) {
|
||||||
(*r_vertex)[i] = output->vertexArray[i].xref;
|
(*r_vertex)[i] = output->vertexArray[i].xref;
|
||||||
(*r_uv)[i * 2 + 0] = output->vertexArray[i].uv[0];
|
(*r_uv)[i * 2 + 0] = output->vertexArray[i].uv[0] / w;
|
||||||
(*r_uv)[i * 2 + 1] = output->vertexArray[i].uv[1];
|
(*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;
|
*r_vertex_count = output->vertexCount;
|
||||||
|
|
||||||
for (int i = 0; i < output->indexCount; i++) {
|
for (int i = 0; i < output->indexCount; i++) {
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
/*************************************************************************/
|
/*************************************************************************/
|
||||||
|
|
||||||
#include "baked_lightmap.h"
|
#include "baked_lightmap.h"
|
||||||
|
#include "core/io/config_file.h"
|
||||||
#include "core/io/resource_saver.h"
|
#include "core/io/resource_saver.h"
|
||||||
#include "core/os/dir_access.h"
|
#include "core/os/dir_access.h"
|
||||||
#include "core/os/os.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;
|
tex_flags |= Texture::FLAG_CONVERT_TO_LINEAR;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ref<ImageTexture> tex;
|
String image_path = save_path.plus_file(mesh_name);
|
||||||
String image_path = save_path.plus_file(mesh_name + ".tex");
|
Ref<Texture> texture;
|
||||||
bool set_path = true;
|
|
||||||
if (ResourceCache::has(image_path)) {
|
if (ResourceLoader::import) {
|
||||||
tex = Ref<Resource>((Resource *)ResourceCache::get(image_path));
|
|
||||||
set_path = false;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
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 {
|
||||||
|
|
||||||
|
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 (!tex.is_valid()) {
|
|
||||||
tex.instance();
|
|
||||||
}
|
|
||||||
|
|
||||||
tex->create_from_image(image, tex_flags);
|
|
||||||
|
|
||||||
err = ResourceSaver::save(image_path, tex, ResourceSaver::FLAG_CHANGE_PATH);
|
|
||||||
if (err != OK) {
|
if (err != OK) {
|
||||||
if (bake_end_function) {
|
if (bake_end_function) {
|
||||||
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);
|
ERR_FAIL_COND_V(err != OK, BAKE_ERROR_CANT_CREATE_IMAGE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (set_path) {
|
new_light_data->add_user(E->get().path, texture, E->get().instance_idx);
|
||||||
tex->set_path(image_path);
|
|
||||||
}
|
|
||||||
new_light_data->add_user(E->get().path, tex, E->get().instance_idx);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue