From 27aaa700378122c52cd23d42d56441ae56d9da5d Mon Sep 17 00:00:00 2001 From: Relintai Date: Tue, 9 Aug 2022 18:31:47 +0200 Subject: [PATCH] Added back set_bone_pose to Skeleton, as I don't see any reason not to have it. Also improved it it. --- doc/classes/Skeleton.xml | 8 ++++++++ scene/3d/skeleton.cpp | 14 ++++++++++++++ scene/3d/skeleton.h | 2 +- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/doc/classes/Skeleton.xml b/doc/classes/Skeleton.xml index 8d9c03172..7b19d523d 100644 --- a/doc/classes/Skeleton.xml +++ b/doc/classes/Skeleton.xml @@ -190,6 +190,14 @@ [b]Note:[/b] [code]parent_idx[/code] must be less than [code]bone_idx[/code]. + + + + + + Sets the pose transform for bone [code]bone_idx[/code]. Prefer set_bone_pose_position, set_bone_pose_rotation, or set_bone_pose_scale instead. + + diff --git a/scene/3d/skeleton.cpp b/scene/3d/skeleton.cpp index 233323939..2cd4efc76 100644 --- a/scene/3d/skeleton.cpp +++ b/scene/3d/skeleton.cpp @@ -571,6 +571,19 @@ void Skeleton::clear_bones() { } // posing api +void Skeleton::set_bone_pose(int p_bone, const Transform &p_pose) { + const int bone_size = bones.size(); + ERR_FAIL_INDEX(p_bone, bone_size); + + bones.write[p_bone].pose_position = p_pose.origin; + bones.write[p_bone].pose_rotation = p_pose.basis.get_rotation_quat(); + bones.write[p_bone].pose_scale = p_pose.basis.get_scale(); + bones.write[p_bone].pose_cache_dirty = true; + + if (is_inside_tree()) { + _make_dirty(); + } +} void Skeleton::set_bone_pose_position(int p_bone, const Vector3 &p_position) { const int bone_size = bones.size(); @@ -983,6 +996,7 @@ void Skeleton::_bind_methods() { ClassDB::bind_method(D_METHOD("clear_bones"), &Skeleton::clear_bones); + ClassDB::bind_method(D_METHOD("set_bone_pose", "bone_idx", "pose"), &Skeleton::set_bone_pose); ClassDB::bind_method(D_METHOD("set_bone_pose_position", "bone_idx", "position"), &Skeleton::set_bone_pose_position); ClassDB::bind_method(D_METHOD("set_bone_pose_rotation", "bone_idx", "rotation"), &Skeleton::set_bone_pose_rotation); ClassDB::bind_method(D_METHOD("set_bone_pose_scale", "bone_idx", "scale"), &Skeleton::set_bone_pose_scale); diff --git a/scene/3d/skeleton.h b/scene/3d/skeleton.h index f46b84874..228df2c57 100644 --- a/scene/3d/skeleton.h +++ b/scene/3d/skeleton.h @@ -206,7 +206,7 @@ public: void clear_bones(); // posing api - + void set_bone_pose(int p_bone, const Transform &p_pose); void set_bone_pose_position(int p_bone, const Vector3 &p_position); void set_bone_pose_rotation(int p_bone, const Quat &p_rotation); void set_bone_pose_scale(int p_bone, const Vector3 &p_scale);