The keyframeTrack.trim()
method in Three.js is used to trim a KeyframeTrack object by removing or keeping a specified range of keyframes.
keyframeTrack.trim(startTime, endTime);
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.This method does not return anything. It modifies the KeyframeTrack object on which it is called.
// 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.