The uncacheRoot()
method of the AnimationMixer
class is used to remove the cached root object of the animation mixer. This method is called automatically when a new animation is added to the mixer, but can also be called manually when necessary.
mixer.uncacheRoot()
Before explaining the usage of this method, it's important to understand what the "root object" of an animation mixer is. The root object is the highest level object in the hierarchy of objects that are being animated. For example, if you have an animated model with multiple meshes and bones, the root object would be the top-level object that contains all the meshes and bones as children.
When an animation is added to an animation mixer, the uncacheRoot()
method is automatically called to cache the root object of the animated hierarchy. This is done so that the mixer can efficiently update the animation data for the entire hierarchy when necessary.
If you make changes to the hierarchy of objects being animated (for example, if you add or remove a mesh), you will need to call uncacheRoot()
manually to ensure that the mixer has the correct root object for the updated hierarchy. Calling this method will clear the cached root object and force the mixer to recalculate the root object the next time it is needed.
Here is an example of how to use the uncacheRoot()
method:
// Create an animation mixer
const mixer = new THREE.AnimationMixer(scene);
// Load an animated model and add it to the scene
const loader = new THREE.GLTFLoader();
loader.load('model.gltf', (gltf) => {
scene.add(gltf.scene);
// Get the root object of the animated hierarchy
const root = gltf.scene.children[0];
// Add the animation to the mixer
const animation = mixer.clipAction(gltf.animations[0]);
animation.play();
// Make changes to the hierarchy of objects being animated
root.add(new THREE.Mesh());
// Uncache the root object to ensure that the mixer has the correct hierarchy
mixer.uncacheRoot();
});
This method doesn't take any parameters.
This method doesn't return any value.
This method doesn't throw any exception.
This method is supported in all modern browsers.