Skip to content

fbx

stable

Detect, parse, and construct FBX 3D scene file data. Supports binary format detection, ASCII node parsing, and building node trees programmatically.

use plugin fbx::{detect_format, parse_fbx_ascii_nodes, create_node, …}
10 functions Graphics
/ filter jk navigate Esc clear
Functions (10)
  1. detect_format Detect if bytes are binary, ascii, or unknown FBX
  2. parse_fbx_ascii_nodes Parse ASCII FBX text into a node table
  3. create_node Create a new FBX node table
  4. node_name Get the name field of a node
  5. node_children Get the children table of a node
  6. node_properties Get the properties table of a node
  7. find_nodes_by_name Find all nodes with a given name
  8. node_count Count nodes in a table
  9. version_info Read FBX binary version from header bytes
  10. add_child Append a child node to a parent node

Overview

fbx is a lightweight toolkit for inspecting and assembling FBX 3D scene data without pulling in a full asset-import pipeline. It works at two layers: format detection and version probing for raw file bytes (detect_format, version_info), and a plain-table node model for reading ASCII FBX or building node trees by hand (parse_fbx_ascii_nodes, create_node, add_child). There is no opaque handle or stateful document — every node is just a table with name, properties, and children fields, so you can read, copy, and pass nodes around freely.

Use it when you need to sniff what kind of FBX file you are holding, walk the top-level structure of an ASCII export, or programmatically construct a small node tree to serialize or compare. The ASCII parser is intentionally shallow (one level of children), so it is best for header inspection and lightweight tooling rather than full scene reconstruction.

Common patterns

Probe an unknown file: detect the format, then read the version if it is binary.

use plugin fbx::{detect_format, version_info}

let fmt = detect_format(file_bytes)
print("FBX format: {fmt}")
if fmt == "binary" {
  let info = version_info(file_bytes)
  print("FBX version: {info["version"]}")
}

Parse an ASCII export and locate every node of a given kind.

use plugin fbx::{parse_fbx_ascii_nodes, find_nodes_by_name, node_count}

let nodes = parse_fbx_ascii_nodes(file_text)
print("top-level nodes: {node_count(nodes)}")
let models = find_nodes_by_name(nodes, "Model")
print("models found: {node_count(models)}")

Build a node tree by hand and walk its children.

use plugin fbx::{create_node, add_child, node_children, node_count, node_name}

let root  = create_node("Objects", [])
let mesh  = create_node("Mesh", ["MyMesh", 123456])
let scene = add_child(root, mesh)
print("{node_name(scene)} has {node_count(node_children(scene))} child")

Detect if bytes are binary, ascii, or unknown FBX

Detects whether raw bytes represent a binary FBX file, an ASCII FBX file, or an unknown format. Returns "binary", "ascii", or "unknown".

use plugin fbx::{detect_format}

// Assuming file_bytes is loaded from disk
let fmt = detect_format(file_bytes)
print("FBX format: {fmt}")

Branch on the result to pick the right reader:

use plugin fbx::{detect_format}

let fmt = detect_format(file_bytes)
if fmt == "ascii" {
  print("parse with parse_fbx_ascii_nodes")
} else if fmt == "binary" {
  print("read version with version_info")
} else {
  print("not an FBX file")
}

Parse ASCII FBX text into a node table

Parses ASCII FBX text into a shallow node tree. Each node has {name, properties, children} fields. Children are parsed one level deep.

use plugin fbx::{parse_fbx_ascii_nodes, node_count}

let fbx_text = "FBXHeaderExtension: {\n\tFBXHeaderVersion: 1003\n}\n"
let nodes = parse_fbx_ascii_nodes(fbx_text)
print("top-level nodes: {node_count(nodes)}")

Walk the parsed nodes and read each name and its children:

use plugin fbx::{parse_fbx_ascii_nodes, node_name, node_children, node_count}

let nodes = parse_fbx_ascii_nodes("Objects: {\n\tModel: \"Cube\" {\n}\n}\n")
for node in nodes {
  print("{node_name(node)} -> {node_count(node_children(node))} children")
}

Create a new FBX node table

Creates a new FBX node table with the given name and properties. The node starts with an empty children list. Use add_child to attach sub-nodes.

use plugin fbx::{create_node, add_child}

let root  = create_node("Objects", [])
let mesh  = create_node("Mesh", ["MyMesh", 123456])
let scene = add_child(root, mesh)
print(scene)

Get the name field of a node

Extracts the name field from a node table.

use plugin fbx::{parse_fbx_ascii_nodes, node_name}

let nodes = parse_fbx_ascii_nodes("Model: \"Cube\" {\n}\n")
let first = nodes[0]
print(node_name(first))  // Model

Get the children table of a node

Returns the children table of a node. Returns an empty table if there are no children.

use plugin fbx::{create_node, add_child, node_children, node_count}

let parent = create_node("Group", [])
let child  = create_node("Item", [])
let result = add_child(parent, child)
let kids   = node_children(result)
print(node_count(kids))  // 1

Get the properties table of a node

Returns the properties table of a node.

use plugin fbx::{create_node, node_properties}

let n    = create_node("Version", [200])
let props = node_properties(n)
print(props)

Find all nodes with a given name

Searches a node table for all nodes whose name field equals the given string. Returns a table of matching nodes.

use plugin fbx::{parse_fbx_ascii_nodes, find_nodes_by_name}

let text  = "Model: \"A\" {\n}\nModel: \"B\" {\n}\n"
let nodes = parse_fbx_ascii_nodes(text)
let models = find_nodes_by_name(nodes, "Model")
print("found {models}")

Count nodes in a table

Returns the number of entries in a node table.

use plugin fbx::{parse_fbx_ascii_nodes, node_count}

let nodes = parse_fbx_ascii_nodes("A: {\n}\nB: {\n}\n")
print(node_count(nodes))  // 2

Read FBX binary version from header bytes

Reads the FBX binary version number from the file header bytes (little-endian u32 just after the binary magic). Returns a {version} table, or nil if the bytes are not a valid binary FBX header.

use plugin fbx::{detect_format, version_info}

let fmt = detect_format(file_bytes)
if fmt == "binary" {
  let info = version_info(file_bytes)
  print("FBX version: {info["version"]}")
}

Append a child node to a parent node

Returns a new node table with child appended to the parent's children list. Does not mutate the original node.

use plugin fbx::{create_node, add_child, node_children, node_count}

let root   = create_node("Scene", [])
let mat    = create_node("Material", ["lambert"])
let light  = create_node("Light", ["point"])
let scene  = add_child(add_child(root, mat), light)
print(node_count(node_children(scene)))  // 2

Because add_child returns a fresh table, the original parent is unchanged:

use plugin fbx::{create_node, add_child, node_children, node_count}

let root  = create_node("Scene", [])
let added = add_child(root, create_node("Camera", []))
print(node_count(node_children(root)))   // 0 (original untouched)
print(node_count(node_children(added)))  // 1
enespt-br