diff options
Diffstat (limited to 'scene')
-rw-r--r-- | scene/3d/skeleton.cpp | 27 | ||||
-rw-r--r-- | scene/3d/skeleton.h | 7 |
2 files changed, 33 insertions, 1 deletions
diff --git a/scene/3d/skeleton.cpp b/scene/3d/skeleton.cpp index ead1e69f90..b0f567f183 100644 --- a/scene/3d/skeleton.cpp +++ b/scene/3d/skeleton.cpp @@ -245,6 +245,9 @@ void Skeleton::_notification(int p_what) { if (b.enabled) { Transform pose = b.pose; + if (b.custom_pose_enable) { + pose = b.custom_pose * pose; + } if (b.parent >= 0) { b.pose_global = bonesptr[b.parent].pose_global * pose; @@ -267,7 +270,9 @@ void Skeleton::_notification(int p_what) { if (b.enabled) { Transform pose = b.pose; - + if (b.custom_pose_enable) { + pose = b.custom_pose * pose; + } if (b.parent >= 0) { b.pose_global = bonesptr[b.parent].pose_global * (b.rest * pose); @@ -533,6 +538,23 @@ Transform Skeleton::get_bone_pose(int p_bone) const { return bones[p_bone].pose; } +void Skeleton::set_bone_custom_pose(int p_bone, const Transform &p_custom_pose) { + + ERR_FAIL_INDEX(p_bone, bones.size()); + //ERR_FAIL_COND( !is_inside_scene() ); + + bones.write[p_bone].custom_pose_enable = (p_custom_pose != Transform()); + bones.write[p_bone].custom_pose = p_custom_pose; + + _make_dirty(); +} + +Transform Skeleton::get_bone_custom_pose(int p_bone) const { + + ERR_FAIL_INDEX_V(p_bone, bones.size(), Transform()); + return bones[p_bone].custom_pose; +} + void Skeleton::_make_dirty() { if (dirty) @@ -808,6 +830,9 @@ void Skeleton::_bind_methods() { ClassDB::bind_method(D_METHOD("set_bone_global_pose_override", "bone_idx", "pose", "amount", "persistent"), &Skeleton::set_bone_global_pose_override, DEFVAL(false)); ClassDB::bind_method(D_METHOD("get_bone_global_pose", "bone_idx"), &Skeleton::get_bone_global_pose); + ClassDB::bind_method(D_METHOD("get_bone_custom_pose", "bone_idx"), &Skeleton::get_bone_custom_pose); + ClassDB::bind_method(D_METHOD("set_bone_custom_pose", "bone_idx", "custom_pose"), &Skeleton::set_bone_custom_pose); + #ifndef _3D_DISABLED ClassDB::bind_method(D_METHOD("physical_bones_stop_simulation"), &Skeleton::physical_bones_stop_simulation); diff --git a/scene/3d/skeleton.h b/scene/3d/skeleton.h index f20c550055..824d9567fa 100644 --- a/scene/3d/skeleton.h +++ b/scene/3d/skeleton.h @@ -87,6 +87,9 @@ private: Transform pose; Transform pose_global; + bool custom_pose_enable; + Transform custom_pose; + float global_pose_override_amount; bool global_pose_override_reset; Transform global_pose_override; @@ -102,6 +105,7 @@ private: parent = -1; enabled = true; disable_rest = false; + custom_pose_enable = false; global_pose_override_amount = 0; global_pose_override_reset = false; #ifndef _3D_DISABLED @@ -184,6 +188,9 @@ public: void set_bone_pose(int p_bone, const Transform &p_pose); Transform get_bone_pose(int p_bone) const; + void set_bone_custom_pose(int p_bone, const Transform &p_custom_pose); + Transform get_bone_custom_pose(int p_bone) const; + void localize_rests(); // used for loaders and tools int get_process_order(int p_idx); |