August 2013, by Alexander Gessler, reviewed by Campbell Barton. Published by Blender Foundation, as public domain information.
This is an incomplete specification for the binary FBX file format.
It has been tested with file versions starting 2011, but it should also work with earlier versions.
This document only describes the encoding of binary FBX files, not the interpretation of the data being encoded.
It should enable you to translate binary FBX files to ASCII text format (or an in-memory representation of it).
Text-Based File Structure
Knowledge of the text-based format is relevant for this document, so here is a quick writeup. The core hierarchical building block (node) of a text-based FBX document is
NodeType: SomeProperty0a, SomeProperty0b, ... , { NestedNodeType1 : SomeProperty1a, ... NestedNodeType2 : SomeProperty2a, ... , { ... Sub-scope } ... }
In other words, a document is essentially a nested list of nodes. Each node has…
- A NodeType identifier (class name)
- A tuple of properties associated with it, the tuple elements are the usual primitive data types: float, integer, string etc.
- A list which contains nodes in the same format (recursively).
At global level, there is an “implicit list” (i.e. the curly braces, the property list and the name are omitted) with some standard nodes defined. Each of these standard items consists only of a nested list, so a file might look like this
FBXHeaderExtension: {...} GlobalSettings: {...} Documents: {...} Definitions: {...} Connections: {...} ...
Applications have to parse the contents of these in order to access FBX geometry.
Binary File Structure
The first 27 bytes contain the header.
- Bytes 0 - 20: Kaydara FBX Binary \x00 (file-magic, with 2 spaces at the end, then a NULL terminator).
- Bytes 21 - 22: [0x1A, 0x00] (unknown but all observed files show these bytes).
- Bytes 23 - 26: unsigned int, the version number. 7300 for version 7.3 for example.
Directly after this data, there is the top-level object record. Unlike for the text file format, this is not omitted – a full node record with empty name and empty property list is written.
After that record (which recursively contains the entire file information) there is a footer with unknown contents.
Node Record Format
A named node record has the following memory layout:
Size (Bytes) Data Type Name 4 Uint32 EndOffset 4 Uint32 NumProperties 4 Uint32 PropertyListLen 1 Uint8t NameLen NameLen char Name ? ? Property[n], for n in 0:PropertyListLen Optional ? ? NestedList 13 uint8[] NULL-record
Where…
- EndOffset is the distance from the beginning of the file to the end of the node record (i.e. the first byte of whatever comes next). This can be used to easily skip over unknown or not required records.
- NumProperties is the number of properties in the value tuple associated with the node. A nested list as last element is not counted as property.
- PropertyListLen is the length of the property list. This is the size required for storing NumProperties properties, which depends on the data type of the properties.
- NameLen is the length of the object name, in characters. The only case where this is 0 seems to be the lists top-level.
- Name is the name of the object. There is no zero-termination.
- Property[n] is the n“th property. For the format, see section Property Record Format. Properties are written sequentially and with no padding.
- NestedList is the nested list, presence of which is indicated by a NULL–record at the very end.
Reading a node record up to and including the properties is straightforward. To determine whether a nested list entry exists, check if there is bytes left until the EndOffset is reached. If so, recursively read an object record directly following the last property. Behind that object record, there is 13 zero bytes, which should then match up with the EndOffset. (Note: it is not entirely clear why the NULL entry is required. This strongly hints at some FBX subtlety or format feature that not known to the authors of this document ….)
Property Record Format
A property record has the following memory layout:
Size (Bytes) Data Type Name 1 char TypeCode ? ? Data
where TypeCode can be one of the following character codes, which are ordered in groups that require similar handling.
i) Primitive Types
- Y: 2 byte signed Integer
- C: 1 bit boolean (1: true, 0: false) encoded as the LSB of a 1 Byte value.
- I: 4 byte signed Integer
- F: 4 byte single-precision IEEE 754 number
- D: 8 byte double-precision IEEE 754 number
- L: 8 byte signed Integer
For primitive scalar types the Data in the record is exactly the binary representation of the value, in little-endian byte order.
ii) Array types
- f: Array of 4 byte single-precision IEEE 754 number
- d: Array of 8 byte double-precision IEEE 754 number
- l: Array of 8 byte signed Integer
- i: Array of 4 byte signed Integer
- b: Array of 1 byte Booleans (always 0 or 1)
For array types, Data is more complex:
Size (Bytes) Data Type Name 4 Uint32 ArrayLength 4 Uint32 Encoding 4 Uint32 CompressedLength ? ? Contents
If Encoding is 0, the Contents is just ArrayLength times the array data type. If Encoding is 1, the Contents is a deflate/zip-compressed buffer of length CompressedLength bytes. The buffer can for example be decoded using zlib.
Values other than 0,1 for Encoding have not been observed.
iii) Special types
- S: String
- R: raw binary data
Both of these have the following interpretation:
Size (Bytes) Data Type Name 4 Uint32 Length Length byte/char Data
The string is not zero-terminated, and may well contain \0 characters (this is actually used in some FBX properties).
9 comments
Artistic Kamen Rider says:
Aug 13, 2013
Interesting. Lets hope documentation comes soon.
Erwin Coumans says:
Aug 18, 2013
Some old open source Irrlicht extension can read meshes from binary fbx files. See
http://sourceforge.net/p/irrext/code/91/tree/trunk/extensions/scene/IMeshLoader/fbx/
Campbell Barton says:
Aug 19, 2013
Updated info (figured out what ‘b’ type properties are),
@Erwin, ah, I wasn’t aware of other binary loaders, I had a quick look and they did indeed figure this out earlier on.
I’ve put together a standalone parser in Python (runs without Blender), hopefully will help anyone trying to figure this out in future (also includes example fbx2json converter).
https://github.com/ideasman42/pyfbx_i42
Rod Boyd says:
Aug 30, 2013
Straying slightly from topic, but… For my own game development purposes, I have modified the existing python FBX export script to support material textures, including layered colour textures, normal maps, specular maps, etc. I’ve also made a few other fixes here and there. I’m happy to pass it back for evaluation and possible integration into a future blender release, but I’m not sure to whom I should send it. Any thoughts?
ton says:
Sep 1, 2013
Check “get involved” on blender.org, or straight head to this page:
http://wiki.blender.org/index.php/Dev:Doc/Contact
Dale says:
Sep 19, 2013
Hey Rod: We were pondering doing exactly what you’ve already done – if you’d share, this would help us greatly and give the community another “set of eyes and hands” on it.
daleohays@gmail.com
Erlend Sogge Heggen says:
Sep 11, 2013
Some other projects worth a look:
https://github.com/libgdx/fbx-conv
https://github.com/dobkeratops/openfbx
Campbell Barton says:
Sep 20, 2013
@Erlend Sogge Heggen: I checked both links…
– `fbx-conv` uses Autodesks SDK, so not really interesting as far as being able to load FBX data goes.
– `openfbx` only reads ASCII files, This is OK, and we had a test ASCII importer in Blender for some years, but parsing large ascii files is slow and applications default to binary.
Not to speak negatively about either of these projects – but neither of them are doing anything very special as far as reading FBX files is concerned.
dirk says:
Jan 30, 2014
Please consider using FBX SDK. You will always be behind regarding new versions and features otherwise, and it would be much easier with the SDK.
License is no problem if you have fbx code in its own process, and IPC makes it slower but not much.
Looks at:
http://blenderartists.org/forum/showthread.php?274687-Another-FBX-Importer-Exporter-addon
The code is very simple and almost does the job. Why create something complex that will be hell to maintain (reverse engineering every change on FBX updates,..)?