diff options
author | jfons <joan.fonssanchez@gmail.com> | 2021-09-07 17:44:50 +0200 |
---|---|---|
committer | jfons <joan.fonssanchez@gmail.com> | 2021-09-27 17:04:56 +0200 |
commit | 9e1810695c926286ddfe3e1614a6a54044583ac0 (patch) | |
tree | 210e6b684ae8bda9daf0c1e0e06246fb4f13fc2b /editor/import/resource_importer_scene.cpp | |
parent | 10801b90f99eb67b2999e3dc8f42cc82c7799f3e (diff) |
Auto LOD fixes and improvements
* Fixed LODs for shadow meshes.
* Added a merging step before simplification. This helps with tesselated
meshes that were previously left untouched. The angle difference at
wich edges ar considered "hard" can be tweaked as an import setting.
* LODs will now start with the highest decimation possible and keep
doubling (approximately) the number of triangles from there. This
makes sure that very low triangle counts are included when possible.
* Given more weight to normal preservation.
* Modified MeshOptimizer to report distance-based error instead of
including attributes in the reported metrics.
* Added attribute transference between the original mesh and the
various LODs. Right now only normals are taken into account,
but it could be expanded to other attributes in the future.
Diffstat (limited to 'editor/import/resource_importer_scene.cpp')
-rw-r--r-- | editor/import/resource_importer_scene.cpp | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/editor/import/resource_importer_scene.cpp b/editor/import/resource_importer_scene.cpp index c48d9bb117..2c9bc7dadf 100644 --- a/editor/import/resource_importer_scene.cpp +++ b/editor/import/resource_importer_scene.cpp @@ -980,6 +980,8 @@ void ResourceImporterScene::get_internal_import_options(InternalImportCategory p r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "generate/shadow_meshes", PROPERTY_HINT_ENUM, "Default,Enable,Disable"), 0)); r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "generate/lightmap_uv", PROPERTY_HINT_ENUM, "Default,Enable,Disable"), 0)); r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "generate/lods", PROPERTY_HINT_ENUM, "Default,Enable,Disable"), 0)); + r_options->push_back(ImportOption(PropertyInfo(Variant::FLOAT, "lods/normal_split_angle", PROPERTY_HINT_RANGE, "0,180,0.1,degrees"), 25.0f)); + r_options->push_back(ImportOption(PropertyInfo(Variant::FLOAT, "lods/normal_merge_angle", PROPERTY_HINT_RANGE, "0,180,0.1,degrees"), 60.0f)); } break; case INTERNAL_IMPORT_CATEGORY_MATERIAL: { r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "use_external/enabled", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), false)); @@ -1259,6 +1261,8 @@ void ResourceImporterScene::_generate_meshes(Node *p_node, const Dictionary &p_m //do mesh processing bool generate_lods = p_generate_lods; + float split_angle = 25.0f; + float merge_angle = 60.0f; bool create_shadow_meshes = p_create_shadow_meshes; bool bake_lightmaps = p_light_bake_mode == LIGHT_BAKE_STATIC_LIGHTMAPS; String save_to_file; @@ -1301,6 +1305,14 @@ void ResourceImporterScene::_generate_meshes(Node *p_node, const Dictionary &p_m } } + if (mesh_settings.has("lods/normal_split_angle")) { + split_angle = mesh_settings["lods/normal_split_angle"]; + } + + if (mesh_settings.has("lods/normal_merge_angle")) { + merge_angle = mesh_settings["lods/normal_merge_angle"]; + } + if (mesh_settings.has("save_to_file/enabled") && bool(mesh_settings["save_to_file/enabled"]) && mesh_settings.has("save_to_file/path")) { save_to_file = mesh_settings["save_to_file/path"]; if (!save_to_file.is_resource_file()) { @@ -1310,8 +1322,9 @@ void ResourceImporterScene::_generate_meshes(Node *p_node, const Dictionary &p_m } if (generate_lods) { - src_mesh_node->get_mesh()->generate_lods(); + src_mesh_node->get_mesh()->generate_lods(merge_angle, split_angle); } + if (create_shadow_meshes) { src_mesh_node->get_mesh()->create_shadow_mesh(); } |