Sounds like you have never worked in customer service. 😉 Spinebot solves simple user problems, giving users a solution immediately. That saves the user from having to wait for an answer and it saves us significant time from having to answer the same simple questions, day after day -- giving us more time to answer the more advanced questions. If a Spinebot answer is poor, we delete it.
If you were using a single animation, it would be a lot easier, but when using AnimationState the results can be complex. Eg, there could be multiple tracks, some could be in the middle of transitions to other animations, etc. The only 100% accurate solution is to step the AnimationState forward and pose the skeleton with it.
The AnimationState has state (surprise!) that would not be easy to revert (eg track entries that have ended) so you would need a copy, as you mentioned. We don't currently have copy constructors, though that wouldn't be super hard to add.
When AnimationState is applied normally, it doesn't leave the skeleton in an unknown state. If a property will no longer be animated, it gets set back to the setup pose (unless you use clearTrack
, clearTracks
, or trackEnd
). If you were to pose the skeleton with an AnimationState, discard the AnimationState, then go back to using an older AnimationState, it could leave the skeleton with state from the discarded AnimationState. For example, an attachment might remain visible.
Cloning the skeleton could be a way around this (and we have copy constructors), but that's pretty heavy. You could reset the skeleton to the setup pose, or I think you could call setEmptyAnimations(0)
and apply the AnimationState again before discarding it. Either of those should cover everything except physics.
First you'd want to revert the skeleton time. Then if you called updateWorldTransform
with Physics.update
, it advances the physics state (which is actually stored on the constraint, not the skeleton). You would need to do that to be 100% accurate if you are using physics, in which case you'd need to restore these values for each PhysicsConstraint to revert advancing physics:
float ux, uy, cx, cy, tx, ty;
float xOffset, xVelocity;
float yOffset, yVelocity;
float rotateOffset, rotateVelocity;
float scaleOffset, scaleVelocity;
float remaining, lastTime;
If you use Physics.pose
instead, physics won't advance. That's a little easier, if its acceptable to not have exactly the right pose.