BabylonJS/Babylon.js · error · Error

Expected opening { after type & name

Error message

Expected opening { after type & name

What it means

ReadNode parses the BVH HIERARCHY section recursively. Immediately after a node's type/name line (e.g. "JOINT hip" or "ROOT spine"), the BVH format requires an opening "{" on its own line. If the next line consumed from the file is not exactly "{" after trimming, this error is thrown, meaning the file's structure is malformed.

Source

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

function ReadNode(lines: string[], firstLine: string, parent: Nullable<IBVHNode>, context: LoaderContext): IBVHNode {
    const node = CreateBVHNode();
    node.parent = parent;
    context.list.push(node);

    // parse node type and name.
    let tokens: string[] | undefined = firstLine.trim().split(/\s+/);

    if (tokens[0].toUpperCase() === "END" && tokens[1].toUpperCase() === "SITE") {
        node.type = "ENDSITE";
        node.name = "ENDSITE"; // bvh end sites have no name
    } else {
        node.name = tokens[1];
        node.type = tokens[0].toUpperCase();
    }

    // opening bracket
    if (lines.shift()?.trim() != "{") {
        throw new Error("Expected opening { after type & name");
    }

    // parse OFFSET
    const tokensSplit = lines.shift()?.trim().split(/\s+/);
    if (!tokensSplit) {
        throw new Error("Unexpected end of file: missing OFFSET");
    }
    tokens = tokensSplit;

    if (tokens[0].toUpperCase() != "OFFSET") {
        throw new Error("Expected OFFSET, but got: " + tokens[0]);
    }
    if (tokens.length != 4) {
        throw new Error("OFFSET: Invalid number of values");
    }

    const offset = new Vector3(parseFloat(tokens[1]), parseFloat(tokens[2]), parseFloat(tokens[3]));

View on GitHub (pinned to 0592b347b8)

Solutions

  1. Open the .bvh in a text editor and verify every ROOT/JOINT line is followed by a line containing only "{".
  2. Re-export the BVH from the original motion-capture tool with default settings.
  3. Check the file was not truncated or corrupted in transfer (compare byte size with source).
  4. Ensure you are loading a BVH file, not another skeleton format, into the BVH loader.
  5. Normalize line endings (CRLF vs LF) if the file came from Windows tooling and appears flattened.

Example fix

// before (malformed BVH)
ROOT Hips
  OFFSET 0 0 0
// after (valid BVH)
ROOT Hips
{
  OFFSET 0 0 0
Defensive patterns

Strategy: validation

Validate before calling

function assertBvhNodeBraces(text: string): void {
  const lines = text.split(/\r?\n/).map((l) => l.trim());
  for (let i = 0; i < lines.length; i++) {
    const t = lines[i].toUpperCase();
    if (t.startsWith("ROOT ") || t.startsWith("JOINT ") || t === "END SITE") {
      if (lines[i + 1] !== "{") {
        throw new Error(`Line ${i + 2}: expected "{" after "${lines[i]}"`);
      }
    }
  }
}
// run before ReadBvh: assertBvhNodeBraces(bvhText);

Type guard

function isOpenBraceLine(line: string | undefined): boolean {
  return line?.trim() === "{";
}

Try / catch

try {
  const skeleton = ReadBvh(text, scene, null, options);
} catch (e) {
  if (e instanceof Error && e.message.includes("Expected opening {")) {
    console.error("BVH hierarchy is malformed: a node is missing its opening brace.");
  } else { throw e; }
}

Prevention

When it happens

Trigger: Calling the BVH loader (ReadBvh / skeleton loading) on a file where a ROOT/JOINT/ENDSITE (or MOTION placeholder) header line is followed by anything other than a bare "{" line — e.g. missing brace, brace on the same line as the name, or stray content between the name and the brace.

Common situations: Hand-edited BVH files; files exported by tools that omit braces; files mangled by line-ending/encoding conversion (e.g. single-line-flattened files); truncated or partially downloaded .bvh files; attempting to load a non-BVH (e.g. BVH with CRLF handled fine, but JSON or FBX) file through the BVH loader.

Related errors


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