2.1.3 • Published 3 years ago

fbx-parser v2.1.3

Weekly downloads
59
License
MIT
Repository
github
Last release
3 years ago

FBX Parser for JavaScript/TypeScript

npm npm bundle size GitHub Workflow Status

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'

// when encoding is known
const fbx = parseText(fbxString)
const fbx = parseBinary(fbxUint8Array)

// when file encoding is unknown
import * as fs from 'fs'
const file = 'file.fbx'
let fbx: FBXData
try {
  // try binary file encoding
  fbx = parseBinary(fs.readFileSync(file))
} catch (e) {
  // try text file encoding
  fbx = parseText(fs.readFileSync(file, 'utf-8'))
}
// ...

Using FBXReader Util

const root = new FBXReader(fbx)

// Get Settings
const upAxis = root.node('GlobalSettings')?.node('Properties70')?.node('P', { 0: 'UpAxis' })?.prop(4, 'number')

const connectionsOnRoot = root.('Connections').nodes({ 2: 0 }) || []
for (const connection of connectionsOnRoot) {
  const objectId = connection.prop(1)
}

Consider checking out and contributing to the FBX project (npm install @picode/fbx) which provides an advanced interface to use the FBX data.

import { FBX, FBXAxes } from '@picode/fbx'
import * as FBXParser from 'fbx-parser'

const fbx = new FBX(FBXParser.parse(await fs.readFileSync(fbxFile)))
const upAxes = fbx.globalSettings.getUpAxes() ?? FBXAxes.Y

const model = fbx.getModel('MyModel')

const rotKeyY = model.getRotationKey(upAxes)
const rotationsYTimes = rotKeyY?.getTime()
const rotationsYValues = rotKeyY?.getValue()

Direct Access

// Get Settings
const globalSettings = fbx.nodes.find((v) => v.name === 'GlobalSettings')
const properties70 = globalSettings.nodes.find((v) => v.name === 'Properties70')
const upAxis = properties70.nodes.find((v) => v.name === 'P' && v.props[0] === '"UpAxis"').properties[4]

const connections = fbx.nodes.find((v) => v.name === 'Connections')
const connectionsOnRoot = connections.nodes.filter((v) => v.props[2] === '0')
for (const connection of connectionsOnRoot) {
  const objectId = connection.props[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

2.1.3

3 years ago

2.1.2

3 years ago

2.1.1

3 years ago

2.1.0

3 years ago

2.0.3

3 years ago

2.0.2

3 years ago

2.0.5

3 years ago

2.0.4

3 years ago

2.0.7

3 years ago

2.0.6

3 years ago

2.0.8

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago