How to get unanimated position/scale/rotation?

When an animation is playing, it is possible for my program to save the scene to a file at the same time. The problem is that it saves the object’s position/rotation/scale, which if it is animating, doesn’t represent the object’s default unanimated state.
How do I access the unanimated values of an Object, while it is being animated? I know this is somehow possible, because when the animation is stopped, the objects revert to their unanimated states. So how do I access those values while an animation is playing?

The Object3D or Mesh class does not store its pre-animation state, it has only position/rotation/scale properties and animation modifies these.

If your animation is coming from the three.js animation system rather than custom code or shaders, then what you have is a series of KeyframeTrack classes modifying a single property of a single object. Each track has an initial keyframe, and other keyframes that it reaches at specific times.

Going through all the tracks and applying their initial state to every object would be a bit painful. I think a better way to go here would be to keep two AnimationMixer classes:

  • active mixer: update with actual clock time before rendering
  • inactive mixer: keep it at time=0, call update before saving the scene to revert to initial state

Hm… Sounds interesting. If the second mixer is always set at time = 0… Would that work if an object’s animation has a property set at time 0 that isn’t the default value for that object?
For example: One action of an object has keyframe at time 0 that sets the object a position of x=5, however, the default position of the object is x=10 when the animation is stopped.
If I update the second mixer to time = 0, wouldn’t it just set the object position to x=5? I need to get the default values of everything as they would be when they aren’t being animated.

Typically you don’t make animations that way — you want them to loop smoothly — but yes it’s possible. A skinned character would perhaps have something like this, a T-Pose in its default state and an idle/relaxed state as its first frame. If you have no control over that then I think you would need to traverse the scene and save initial positions somewhere in your application.

I understand that, but I’m asking how to retrieve the default values. I take it then that it isn’t possible with a second mixer as you originally suggested? Since it would only set to the animation’s values by setting time to 0. What I’m interested in retrieving is the unanimated values.

When the animation is stopped, it reverts everything to the values that were there before the animation was started.

I want to be able to retrieve those values while the animation is playing.
I’m guessing that I’ll need to store those values before the animation starts I guess? Though it seems odd that the mixer is capable of restoring them when the animation is stopped… Why do I need to store them?

It looks like that’s stored with the (internal) PropertyMixer class and applied with restoreOriginalState(). That is an internal API, I’m not sure if it’s exposed for public access – there is no method I know of that temporarily reverts everything to a pre-animation state without also resetting in-progress animation. Saving state manually, by comparison:

const positionCache = new Map();
const rotationCache = new Map();
scene.traverse((object) => {
  positionCache.set(object, object.position.toArray());
  rotationCache.set(object, object.rotation.toArray());

Thanks- Just to clarify, I don’t need to revert the animation, I just need the values. I guess I am stuck with recording the values whenever I change them. Kind of weird since the values are already there somewhere, hehe…