Animation · function

extractRootMotion

Write the root's displacement between fromSec and toSec into out. Allocates nothing.

Explained in Animation.

function extractRootMotion(clip: AnimationClip, rootJoint: number, fromSec: number, toSec: number, out: RootMotion): void
import { extractRootMotion } from '@driftengine/animation';

Parameters

ParameterTypeDescription
clipAnimationClip
rootJointnumber
fromSecnumber
toSecnumber
outRootMotion

In depth

Loops are accumulated rather than subtracted, which is the whole difficulty. Sampling the root at both times and subtracting answers a full stride backwards every time the clip wraps, because the root snaps from the end of the cycle to the start of it. So the interval is split at every loop boundary it crosses and the pieces are composed.

toSec before fromSec is a clip running backwards and answers the negated motion, because a transition played in reverse is a real caller — the same reason wrapTime handles a negative time rather than assuming one cannot arrive.

Cost is linear in the number of whole cycles between the two times. A fixed-step caller crosses at most one boundary a frame, so that count is zero or one; a query spanning a hundred cycles composes a hundred times, which is arithmetic rather than a hazard.