Use a different approach to update skeletons when transform changes

This commit is contained in:
Juan Linietsky 2017-12-29 11:34:36 -03:00
parent a54e3f72ce
commit 448b58ba4c
2 changed files with 17 additions and 3 deletions

View File

@ -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()) {

View File

@ -57,6 +57,8 @@ class Skeleton : public Spatial {
bool custom_pose_enable;
Transform custom_pose;
Transform transform_final;
List<uint32_t> nodes_bound;
Bone() {