summaryrefslogtreecommitdiffstats
path: root/editor
diff options
context:
space:
mode:
authorLyuma <xn.lyuma@gmail.com>2024-02-25 00:36:39 -0800
committerLyuma <xn.lyuma@gmail.com>2024-02-26 03:06:07 -0800
commit652ef966f99de0a915a601b686378f98c1a49b08 (patch)
tree9c71c9f70b14e674315763dd8dcf6653544ee818 /editor
parent2e7fc81315bfa8d0a15f60adff2a12b6f3104236 (diff)
downloadredot-engine-652ef966f99de0a915a601b686378f98c1a49b08.tar.gz
Add new scene import option to import as Skeleton
Adds a bool import option `nodes/import_as_skeleton_bones`. This is supported in all FBX or GLTF document based formats. It is especially useful for retargeting and importing animations.
Diffstat (limited to 'editor')
-rw-r--r--editor/import/3d/resource_importer_scene.cpp1
-rw-r--r--editor/import/3d/scene_import_settings.cpp16
-rw-r--r--editor/import/3d/scene_import_settings.h1
3 files changed, 18 insertions, 0 deletions
diff --git a/editor/import/3d/resource_importer_scene.cpp b/editor/import/3d/resource_importer_scene.cpp
index 7a51394bbc..b7b82f5f76 100644
--- a/editor/import/3d/resource_importer_scene.cpp
+++ b/editor/import/3d/resource_importer_scene.cpp
@@ -1932,6 +1932,7 @@ void ResourceImporterScene::get_import_options(const String &p_path, List<Import
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "nodes/apply_root_scale"), true));
r_options->push_back(ImportOption(PropertyInfo(Variant::FLOAT, "nodes/root_scale", PROPERTY_HINT_RANGE, "0.001,1000,0.001"), 1.0));
+ r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "nodes/import_as_skeleton_bones"), false));
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "meshes/ensure_tangents"), true));
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "meshes/generate_lods"), true));
r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "meshes/create_shadow_meshes"), true));
diff --git a/editor/import/3d/scene_import_settings.cpp b/editor/import/3d/scene_import_settings.cpp
index 53d7e63dbb..b270424513 100644
--- a/editor/import/3d/scene_import_settings.cpp
+++ b/editor/import/3d/scene_import_settings.cpp
@@ -432,6 +432,16 @@ void SceneImportSettingsDialog::_update_view_gizmos() {
if (!is_visible()) {
return;
}
+ const HashMap<StringName, Variant> &main_settings = scene_import_settings_data->current;
+ if (main_settings.has("nodes/import_as_skeleton_bones")) {
+ bool new_import_as_skeleton = main_settings["nodes/import_as_skeleton_bones"];
+ if (new_import_as_skeleton != previous_import_as_skeleton) {
+ previous_import_as_skeleton = new_import_as_skeleton;
+ _re_import();
+ open_settings(base_path);
+ }
+ return;
+ }
for (const KeyValue<String, NodeData> &e : node_map) {
bool show_collider_view = false;
if (e.value.settings.has(SNAME("generate/physics"))) {
@@ -591,6 +601,7 @@ void SceneImportSettingsDialog::update_view() {
void SceneImportSettingsDialog::open_settings(const String &p_path, bool p_for_animation) {
if (scene) {
+ _cleanup();
memdelete(scene);
scene = nullptr;
}
@@ -667,6 +678,10 @@ void SceneImportSettingsDialog::open_settings(const String &p_path, bool p_for_a
first_aabb = false;
}
+ const HashMap<StringName, Variant> &main_settings = scene_import_settings_data->current;
+ if (main_settings.has("nodes/import_as_skeleton_bones")) {
+ previous_import_as_skeleton = main_settings["nodes/import_as_skeleton_bones"];
+ }
popup_centered_ratio();
_update_view_gizmos();
_update_camera();
@@ -1137,6 +1152,7 @@ void SceneImportSettingsDialog::_re_import() {
main_settings["_subresources"] = subresources;
}
+ _cleanup(); // Prevent skeletons and other pointers from pointing to dangling references.
EditorFileSystem::get_singleton()->reimport_file_with_custom_parameters(base_path, editing_animation ? "animation_library" : "scene", main_settings);
}
diff --git a/editor/import/3d/scene_import_settings.h b/editor/import/3d/scene_import_settings.h
index c6c416daba..db3a2229f4 100644
--- a/editor/import/3d/scene_import_settings.h
+++ b/editor/import/3d/scene_import_settings.h
@@ -96,6 +96,7 @@ class SceneImportSettingsDialog : public ConfirmationDialog {
Button *animation_stop_button = nullptr;
Animation::LoopMode animation_loop_mode = Animation::LOOP_NONE;
bool animation_pingpong = false;
+ bool previous_import_as_skeleton = false;
Ref<StandardMaterial3D> collider_mat;