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

keyframeTrack.trim()

The keyframeTrack.trim() method in Three.js is used to trim a KeyframeTrack object by removing or keeping a specified range of keyframes.

Syntax

keyframeTrack.trim(startTime, endTime);

Parameters

  • startTime - The start time in seconds from which keyframes should be kept. Keyframes before this time are removed.
  • endTime - The end time in seconds until which keyframes should be kept. Keyframes after this time are removed.

Return Value

This method does not return anything. It modifies the KeyframeTrack object on which it is called.

Example

// Create a KeyframeTrack object
const positionTrack = new THREE.KeyframeTrack(
  '.position',
  [0, 1, 2, 3],
  [0, 0, 0, 1, 1, 1, 0, 0, 0, -1, -1, -1]
);

// Trim the track to keep keyframes between 1 and 2 seconds
positionTrack.trim(1, 2);

In this example, we create a KeyframeTrack object for the position of an object, with 4 keyframes at times 0, 1, 2, and 3 seconds. The positions at these keyframes are specified as (0, 0, 0), (1, 1, 1), (0, 0, 0), and (-1, -1, -1) respectively.

We then call the trim() method on this track to keep only the keyframes between 1 and 2 seconds. This removes the first and last keyframes, so that the track now only has 2 keyframes at times 1 and 2 seconds.

Notes

  • If the start time or end time parameter is outside the range of available keyframes, no keyframes will be removed.
  • If the start time and end time parameters are the same, no keyframes will be removed.