diff options
Diffstat (limited to 'scene/3d/skeleton.cpp')
-rw-r--r-- | scene/3d/skeleton.cpp | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/scene/3d/skeleton.cpp b/scene/3d/skeleton.cpp index 3d40bb299a..ef60a2151d 100644 --- a/scene/3d/skeleton.cpp +++ b/scene/3d/skeleton.cpp @@ -5,8 +5,8 @@ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ -/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ +/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */ /* */ /* Permission is hereby granted, free of charge, to any person obtaining */ /* a copy of this software and associated documentation files (the */ @@ -153,6 +153,24 @@ void Skeleton::_notification(int p_what) { case NOTIFICATION_EXIT_WORLD: { } break; + case NOTIFICATION_TRANSFORM_CHANGED: { + + if (dirty) + break; //will be eventually updated + + //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: { VisualServer *vs = VisualServer::get_singleton(); @@ -242,9 +260,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()) { @@ -548,6 +565,7 @@ Skeleton::Skeleton() { rest_global_inverse_dirty = true; dirty = false; skeleton = VisualServer::get_singleton()->skeleton_create(); + set_notify_transform(true); } Skeleton::~Skeleton() { |