FBX Parser for JavaScript/TypeScript
This parser will parse FBX text files and convert them into a JavaScript-Object structure.
Installation
npm install fbx-parser
Usage
import * as FBXParser from 'fbx-parser'
import * as fs from 'fs'
const fbx = parseText(fbxString)
const fbx = parseBinary(fbxUint8Array)
const file = 'file.fbx'
let fbx: FBX
try {
fbx = parse(await fs.readFileSync(file))
} catch (e) {
fbx = parse(await fs.readFileSync(file, 'utf-8'))
}
Calling the parser will return the same raw structure of the FBX file, starting with the root node named ''
:
type FBX = FBXNode[]
interface FBXNode {
name: string
props: FBXProperty[]
nodes: FBXNode[]
}
type FBXProperty = boolean | number | BigInt | boolean[] | number[] | BigInt[] | string
const globalSettings = fbx.subnodes.find((v) => v.name === 'GlobalSettings')
const properties70 = globalSettings.subnodes.find((v) => v.name === 'Properties70')
const upAxis = properties70.subnodes.find((v) => v.name === 'P' && v.properties[0] === '"UpAxis"').properties[4]
const connections = fbx.subnodes.find((v) => v.name === 'Connections')
const connectionsOnRoot = connections.subnodes.filter((v) => v.properties[2] === '0')
for (const connection of connectionsOnRoot) {
const objectId = connection.properties[1]
}
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
License
MIT
Developer Documentation
FBX Documentation
Resources
Tools