BufferGeometry
Object3D
Raycaster
Camera
CubeCamera
PerspectiveCamera
OrthographicCamera
StereoCamera
Clock
Curve
CurvePath
Path
Shape
ShapePath
ArrowHelper
AxesHelper
BoxHelper
Box3Helper
CameraHelper
DirectionalLightHelper
GridHelper
PolarGridHelper
HemisphereLightHelper
PlaneHelper
PointLightHelper
SkeletonHelper
SpotLightHelper
Light
PointLight
RectAreaLight
SpotLight
DirectionalLight
HemisphereLight
LightShadow
PointLightShadow
AnimationLoader
AudioLoader
BufferGeometryLoader
CompressedTextureLoader
CubeTextureLoader
DataTextureLoader
FileLoader
ImageBitmapLoader
ImageLoader
Loader
LoaderUtils
MaterialLoader
ObjectLoader
TextureLoader
LoadingManager
Material
Box2
Box3
Color
Cylindrical
Euler
Frustum
Interpolant
Line3
MathUtils
Matrix3
Matrix4
Plane
Quaternion
AnimationAction
AnimationClip
AnimationMixer
AnimationObjectGroup
AnimationUtils
keyframeTrack
PropertyBinding
PropertyMixer
BooleanKeyframeTrack
QuaternionKeyframeTrack
StringKeyframeTrack
Audio
AudioAnalyser
AudioContext
AudioListener
PositionalAudio

AnimationAction.getRoot()

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.

Syntax

getRoot(): Object3D

Return Value

The getRoot() function returns an instance of the Object3D class, which represents the root of the target object hierarchy.

Usage

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.

Example

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.

Conclusion

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.