diff options
author | Saracen <SaracenOne@gmail.com> | 2023-09-28 05:32:32 +0100 |
---|---|---|
committer | Saracen <SaracenOne@gmail.com> | 2023-10-27 20:34:01 +0100 |
commit | 4b671eec0ec1fcf503b3fd3b8924d0eceae32c1f (patch) | |
tree | 13b6d2a2634c88a7c3dbce5a0a7943324fcb98b3 | |
parent | b662d232a270cb6827e384ac778bf3a2f35794c7 (diff) | |
download | redot-engine-4b671eec0ec1fcf503b3fd3b8924d0eceae32c1f.tar.gz |
Reimport bone attachment fixes:
Assign bone_idx to GLTF importer to fix serialization.
Notifies Skeletons and BoneAttachments when reimporting.
Removes usage of NOTIFICATION_NODE_RECACHE_REQUESTED
-rw-r--r-- | editor/editor_node.cpp | 25 | ||||
-rw-r--r-- | editor/editor_node.h | 2 | ||||
-rw-r--r-- | modules/gltf/gltf_document.cpp | 8 | ||||
-rw-r--r-- | scene/3d/bone_attachment_3d.cpp | 10 | ||||
-rw-r--r-- | scene/3d/bone_attachment_3d.h | 4 |
5 files changed, 48 insertions, 1 deletions
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 4f87838014..525b139307 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -47,6 +47,7 @@ #include "core/version.h" #include "editor/editor_string_names.h" #include "main/main.h" +#include "scene/3d/bone_attachment_3d.h" #include "scene/gui/color_picker.h" #include "scene/gui/dialogs.h" #include "scene/gui/file_dialog.h" @@ -6070,6 +6071,27 @@ void EditorNode::_file_access_close_error_notify_impl(const String &p_str) { add_io_error(vformat(TTR("Unable to write to file '%s', file in use, locked or lacking permissions."), p_str)); } +// Since we felt that a bespoke NOTIFICATION might not be desirable, this function +// provides the hardcoded callbacks to address known bugs which occur on certain +// nodes during reimport. +// Ideally, we should probably agree on a standardized method name which could be +// called from here instead. +void EditorNode::_notify_scene_updated(Node *p_node) { + Skeleton3D *skel_3d = Object::cast_to<Skeleton3D>(p_node); + if (skel_3d) { + skel_3d->reset_bone_poses(); + } else { + BoneAttachment3D *attachment = Object::cast_to<BoneAttachment3D>(p_node); + if (attachment) { + attachment->notify_rebind_required(); + } + } + + for (int i = 0; i < p_node->get_child_count(); i++) { + _notify_scene_updated(p_node->get_child(i)); + } +} + void EditorNode::reload_scene(const String &p_path) { int scene_idx = -1; for (int i = 0; i < editor_data.get_edited_scene_count(); i++) { @@ -6453,10 +6475,11 @@ void EditorNode::reload_instances_with_path_in_edited_scenes(const String &p_ins } } } + // Cleanup the history of the changes. editor_history.cleanup_history(); - current_edited_scene->propagate_notification(NOTIFICATION_NODE_RECACHE_REQUESTED); + _notify_scene_updated(current_edited_scene); } edited_scene_map.clear(); } diff --git a/editor/editor_node.h b/editor/editor_node.h index bc7da69e75..33de096d35 100644 --- a/editor/editor_node.h +++ b/editor/editor_node.h @@ -692,6 +692,8 @@ private: void _begin_first_scan(); + void _notify_scene_updated(Node *p_node); + protected: friend class FileSystemDock; diff --git a/modules/gltf/gltf_document.cpp b/modules/gltf/gltf_document.cpp index 47fc58fe43..ecfb035b82 100644 --- a/modules/gltf/gltf_document.cpp +++ b/modules/gltf/gltf_document.cpp @@ -5846,6 +5846,10 @@ void GLTFDocument::_generate_scene_node(Ref<GLTFState> p_state, const GLTFNodeIn BoneAttachment3D *bone_attachment = _generate_bone_attachment(p_state, active_skeleton, p_node_index, gltf_node->parent); p_scene_parent->add_child(bone_attachment, true); + + // Find the correct bone_idx so we can properly serialize it. + bone_attachment->set_bone_idx(active_skeleton->find_bone(gltf_node->get_name())); + bone_attachment->set_owner(p_scene_root); // There is no gltf_node that represent this, so just directly create a unique name @@ -5949,6 +5953,10 @@ void GLTFDocument::_generate_skeleton_bone_node(Ref<GLTFState> p_state, const GL BoneAttachment3D *bone_attachment = _generate_bone_attachment(p_state, active_skeleton, p_node_index, p_node_index); p_scene_parent->add_child(bone_attachment, true); + + // Find the correct bone_idx so we can properly serialize it. + bone_attachment->set_bone_idx(active_skeleton->find_bone(gltf_node->get_name())); + bone_attachment->set_owner(p_scene_root); // There is no gltf_node that represent this, so just directly create a unique name diff --git a/scene/3d/bone_attachment_3d.cpp b/scene/3d/bone_attachment_3d.cpp index 60fb6f87c9..45de9b907c 100644 --- a/scene/3d/bone_attachment_3d.cpp +++ b/scene/3d/bone_attachment_3d.cpp @@ -349,6 +349,16 @@ void BoneAttachment3D::notify_skeleton_bones_renamed(Node *p_base_scene, Skeleto } } } + +void BoneAttachment3D::notify_rebind_required() { + // Ensures bindings are properly updated after a scene reload. + _check_unbind(); + if (use_external_skeleton) { + _update_external_skeleton_cache(); + } + bone_idx = -1; + _check_bind(); +} #endif // TOOLS_ENABLED BoneAttachment3D::BoneAttachment3D() { diff --git a/scene/3d/bone_attachment_3d.h b/scene/3d/bone_attachment_3d.h index bfa3db476d..1bf44c2756 100644 --- a/scene/3d/bone_attachment_3d.h +++ b/scene/3d/bone_attachment_3d.h @@ -89,6 +89,10 @@ public: virtual void on_bone_pose_update(int p_bone_index); +#ifdef TOOLS_ENABLED + virtual void notify_rebind_required(); +#endif + BoneAttachment3D(); }; |