diff options
author | Juan Linietsky <juan@godotengine.org> | 2017-12-29 11:34:36 -0300 |
---|---|---|
committer | Juan Linietsky <juan@godotengine.org> | 2017-12-29 11:34:36 -0300 |
commit | 448b58ba4c9b873e1dffc99e4fef10a4fa46c409 (patch) | |
tree | 976feab0ca88a3b329160728f858513bc4dc9d3d | |
parent | a54e3f72ce9d2427e413aa8fdf9633a49027747b (diff) |
Use a different approach to update skeletons when transform changes
-rw-r--r-- | scene/3d/skeleton.cpp | 18 | ||||
-rw-r--r-- | scene/3d/skeleton.h | 2 |
2 files changed, 17 insertions, 3 deletions
diff --git a/scene/3d/skeleton.cpp b/scene/3d/skeleton.cpp index 25e76efeb4..95478f0b02 100644 --- a/scene/3d/skeleton.cpp +++ b/scene/3d/skeleton.cpp @@ -154,7 +154,19 @@ void Skeleton::_notification(int p_what) { } break; case NOTIFICATION_TRANSFORM_CHANGED: { - _make_dirty(); + + //if moved, just update transforms + VisualServer *vs = VisualServer::get_singleton(); + Bone *bonesptr = &bones[0]; + int len = bones.size(); + Transform global_transform = get_global_transform(); + Transform global_transform_inverse = global_transform.affine_inverse(); + + for (int i = 0; i < len; i++) { + + Bone &b = bonesptr[i]; + vs->skeleton_bone_set_transform(skeleton, i, global_transform * (b.transform_final * global_transform_inverse)); + } } break; case NOTIFICATION_UPDATE_SKELETON: { @@ -245,8 +257,8 @@ void Skeleton::_notification(int p_what) { } } - Transform transform = b.pose_global * b.rest_global_inverse; - vs->skeleton_bone_set_transform(skeleton, i, global_transform * (transform * global_transform_inverse)); + b.transform_final = b.pose_global * b.rest_global_inverse; + vs->skeleton_bone_set_transform(skeleton, i, global_transform * (b.transform_final * global_transform_inverse)); for (List<uint32_t>::Element *E = b.nodes_bound.front(); E; E = E->next()) { diff --git a/scene/3d/skeleton.h b/scene/3d/skeleton.h index fdc1100472..11ff728474 100644 --- a/scene/3d/skeleton.h +++ b/scene/3d/skeleton.h @@ -57,6 +57,8 @@ class Skeleton : public Spatial { bool custom_pose_enable; Transform custom_pose; + Transform transform_final; + List<uint32_t> nodes_bound; Bone() { |