The getRoot()
method is a function provided by the Three.js library that is used to retrieve the root of the target object hierarchy for a given AnimationAction
instance.
getRoot(): Object3D
The getRoot()
function returns an instance of the Object3D
class, which represents the root of the target object hierarchy.
The getRoot()
function is often used in conjunction with the AnimationMixer
class, which is used to manage and play back multiple AnimationAction
instances.
To get the root of the target object hierarchy for a given AnimationAction
, you first need to create an instance of the AnimationMixer
class:
const mixer = new THREE.AnimationMixer( scene );
Next, you need to create an instance of the AnimationAction
class and add it to the mixer:
const action = mixer.clipAction( animationClip );
Finally, you can use the getRoot()
function to retrieve the root of the target object hierarchy:
const root = action.getRoot();
The root
object can then be used to manipulate the target object hierarchy, for example by adding or removing children, changing their positions, rotations or scales, or applying other types of transformations.
The following example shows how to use the getRoot()
function to get the root of the target object hierarchy for a AnimationAction
instance:
const mixer = new THREE.AnimationMixer( scene );
const action = mixer.clipAction( animationClip );
const root = action.getRoot();
console.log( root );
In this example, the mixer
instance is created first, followed by an action
instance that is added to the mixer. The getRoot()
function is then called on the action
instance, and the result is printed to the console.
The getRoot()
function is an important method provided by the Three.js library, which allows developers to retrieve the root of the target object hierarchy for a given AnimationAction
instance. By using this method, developers can manipulate the target objects in a more flexible and efficient way, and achieve a wide range of animation effects.