The AnimationClip.validate()
method in Three.js is used to validate an animation clip by checking for duplicate AnimationMixer
instance names and ensuring that all the defined tracks are valid.
AnimationClip.validate(clip: AnimationClip): boolean
clip
: AnimationClip - The animation clip to validate.boolean
- Returns true
if the animation clip is valid, otherwise false
is returned.The AnimationClip.validate()
method checks an animation clip for any issues that could arise when using it with an AnimationMixer
. It is recommended to always validate an animation clip before using it in the AnimationMixer
to avoid unexpected behavior.
The method checks for any duplicate AnimationMixer
instance names defined in the clip. If any duplicates are found, an error will be thrown indicating which instance names are duplicates.
The method also checks all the defined tracks in the clip to ensure that they are valid. Invalid tracks are those that have an undefined target object or no keys defined. If any invalid tracks are found, they will be removed from the clip.
import { AnimationClip } from 'three';
const animationClip = new AnimationClip('my clip', /* duration */ 5.0, [
/* array of AnimationTracks */
]);
const isValid = AnimationClip.validate(animationClip);
if (!isValid) {
console.error('Animation clip is invalid');
}
In the above example, a new animation clip is created and then validated using the AnimationClip.validate()
method. If the clip is invalid, an error message is logged to the console.