From 727826efbabab16bd2b52064c5364f5a7e7c62d0 Mon Sep 17 00:00:00 2001 From: Relintai Date: Sat, 15 Apr 2023 13:52:21 +0200 Subject: [PATCH] Make sure Skeletons set up their initial pose. --- modules/skeleton_3d/nodes/skeleton.cpp | 22 +++++++++++++++++++--- modules/skeleton_3d/nodes/skeleton.h | 2 ++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/modules/skeleton_3d/nodes/skeleton.cpp b/modules/skeleton_3d/nodes/skeleton.cpp index dd884bdc9..752f8f62a 100644 --- a/modules/skeleton_3d/nodes/skeleton.cpp +++ b/modules/skeleton_3d/nodes/skeleton.cpp @@ -32,12 +32,12 @@ #include "core/object/message_queue.h" -#include "core/config/engine.h" -#include "core/config/project_settings.h" -#include "physical_bone.h" #include "../resources/skeleton_modification_3d.h" #include "../resources/skeleton_modification_stack_3d.h" #include "../resources/skin.h" +#include "core/config/engine.h" +#include "core/config/project_settings.h" +#include "physical_bone.h" #include "scene/resources/surface_tool.h" #include "scene/scene_string_names.h" @@ -375,6 +375,8 @@ void Skeleton::_notification(int p_what) { if (modification_stack.is_valid()) { set_modification_stack(modification_stack); } + + init_pose(); } break; #endif } @@ -1077,6 +1079,20 @@ Ref Skeleton::register_skin(const Ref &p_skin) { return skin_ref; } +void Skeleton::init_pose() { + const int bone_len = get_bone_count(); + if (!bone_len) { + return; + } + + for (int i = 0; i < bone_len; i++) { + Transform rest = get_bone_rest(i); + set_bone_pose_position(i, rest.origin); + set_bone_pose_rotation(i, rest.basis.get_rotation_quaternion()); + set_bone_pose_scale(i, rest.basis.get_scale()); + } +} + void Skeleton::force_update_all_dirty_bones() { if (dirty && updating == 0) { const_cast(this)->notification(NOTIFICATION_UPDATE_SKELETON); diff --git a/modules/skeleton_3d/nodes/skeleton.h b/modules/skeleton_3d/nodes/skeleton.h index f299b9518..2f8dfac47 100644 --- a/modules/skeleton_3d/nodes/skeleton.h +++ b/modules/skeleton_3d/nodes/skeleton.h @@ -248,6 +248,8 @@ public: Ref register_skin(const Ref &p_skin); + void init_pose(); + void force_update_all_dirty_bones(); void force_update_all_bone_transforms(); void force_update_bone_children_transforms(int bone_idx);