clip editing

Cutting a clip down to the part you want, and making it loop. A motion capture runs on: a BVH from a suit, a webcam take, ten seconds of someone waving. What a character plays is usually a piece of it, and an idle or a wave has to come round again without a pop. These are the edits, on the clip format every source shares (glb-clips's GlbClip), so they serve BVH, GLB clips and captures alike:

import { readBvh } from 'tosijs-3d/bvh'
import { trimClip, bestLoop, loopBlend } from 'tosijs-3d/clip-edit'

const source = readBvh(text)
const take = source.clips[0]
const { from, to } = bestLoop(source, take, { from: 2, to: 4.5 })
const loop = loopBlend(source, trimClip(take, from, to), 0.25)

The character builder does this from its playback row: drag the trim handles, best loop, loop blend, then keep the result as a clip of your own.

How the seam is measured

Two poses are as far apart as the sum, over every turning joint, of the angle between them, plus how differently the hips are moving (their velocity, in m/s, times velocityWeight, default 2): a walk whose legs match but whose body is stopping at one end and moving at the other still pops. Positions are not compared, since a clip that travels ends somewhere else by design.

How the blend keeps travel

Rotations are slerped and the hips' position lerped, eased in and out. A clip that travels (root motion) would be dragged back to where it began by a plain blend, so the head it fades into is moved on by how far the hips went across the loop, sideways only: their height blends straight, so the end meets the start.

Pure: no DOM, no Babylon.