BabylonJS/Babylon.js · error · Error

MOTION expected

Error message

MOTION expected

What it means

After parsing the HIERARCHY section and the root node tree via ReadNode, ReadBvh requires the next line to be the 'MOTION' keyword, which begins the animation frame section. This error is thrown when the line following the hierarchy's closing brace is missing or is not 'MOTION'. It indicates the BVH file has a skeleton description but no valid motion-section header.

Source

Thrown at packages/dev/loaders/src/BVH/bvhLoader.ts:353

    const context = new LoaderContext(skeleton);
    context.loopMode = loopMode;

    // read model structure
    const firstLine = lines.shift();
    if (!firstLine || firstLine.trim().toUpperCase() !== _HierarchyNode) {
        throw new Error("HIERARCHY expected");
    }

    const nodeLine = lines.shift();
    if (!nodeLine) {
        throw new Error("Unexpected end of file after HIERARCHY");
    }
    const root = ReadNode(lines, nodeLine.trim(), null, context);

    // read motion data
    const motionLine = lines.shift();
    if (!motionLine || motionLine.trim().toUpperCase() !== _MotionNode) {
        throw new Error("MOTION expected");
    }

    const framesLine = lines.shift();
    if (!framesLine) {
        throw new Error("Unexpected end of file before frame count");
    }
    const framesTokens = framesLine.trim().split(/[\s]+/);
    if (framesTokens.length < 2) {
        throw new Error("Invalid frame count line");
    }

    // number of frames
    const numFrames = parseInt(framesTokens[1]);
    if (isNaN(numFrames)) {
        throw new Error("Failed to read number of frames.");
    }
    context.numFrames = numFrames;

View on GitHub (pinned to 0592b347b8)

Solutions

  1. Inspect the file right after the hierarchy's final closing brace: ensure the exact line 'MOTION' (case-insensitive first token alone) appears; re-export with animation/motion data enabled.
  2. Check the exporter settings (e.g. Blender BVH export: keep 'Animation' enabled) so the MOTION section is written.
  3. Remove or comment-free any junk between the last '}' of the hierarchy and the MOTION line.
  4. If the intent is skeleton-only loading, switch to a format/loader that supports it — this BVH parser requires the MOTION section.
  5. Pre-validate with a regex like /\bMOTION\b/i before calling ReadBvh to fail fast with your own message.

Example fix

// before (skeleton-only export)
HIERARCHY
ROOT Hips
{
...
}
// (file ends)

// after (re-export with animation)
HIERARCHY
ROOT Hips
{
...
}
MOTION
Frames: 120
Frame Time: 0.033333
Defensive patterns

Strategy: validation

Validate before calling

function hasMotionSection(text: string): boolean {
    return /\n\s*MOTION\s*(\n|$)/i.test(text);
}
if (!hasMotionSection(bvhText)) {
    throw new Error("BVH file has no MOTION section: re-export with animation enabled");
}
const skeleton = ReadBvh(bvhText, scene, null, options);

Try / catch

let skeleton: Skeleton;
try {
    skeleton = ReadBvh(bvhText, scene, null, options);
} catch (e) {
    if (e instanceof Error && e.message === "MOTION expected") {
        console.error("BVH hierarchy-only file (no MOTION section)", e);
        skeleton = buildSkeletonWithoutAnimation(scene);
    } else {
        throw e;
    }
}

Prevention

When it happens

Trigger: Calling ReadBvh with a file where 'MOTION' is misspelled or has stray tokens on the line (e.g. 'MOTION Section'), a hierarchy-only BVH (skeleton exported without animation), or an extra line (comment/blank with content) inserted between the closing '}' and 'MOTION' that gets consumed as the root/next node line and shifts the expected position.

Common situations: Exporting skeleton-only BVH from a DCC tool (Blender/Maya exporter options with 'no animation' checked), hand-edited BVH files where the MOTION block was deleted or reordered, files from tools that emit 'Motion' followed by extra text or lowercase variants with appended tokens, or concatenating two BVH files incorrectly.

Related errors


AI-assisted analysis of BabylonJS/Babylon.js@0592b347b8 (2026-08-30). Data as JSON: /api/errors/e676d4f50cda497d. Report an issue: GitHub.