Module b3d_reader
parse .b3d files into a lua table.
note: capitlization of name indicates a "chunk" defined by the blitz3d format (see b3d_specification.txt)
Functions
mtul.b3d_reader.read_model (modelname, node_only) | read b3d models by their name. |
mtul.b3d_reader.read_from_stream (stream, ignore_chunks) | read directly from file |
Tables
chunks | an unordered list of the following string chunks. |
VRTS | vertices |
TRIS | triangle/poly sets |
MESH | the mesh chunk table |
BONE | bone table a list of vertex weights indexed by their vertex_id |
KEYS | keyframes |
keyframe | table which specifies a keyframe |
ANIM | defines the animation of a model |
NODE | node a node chunk possibly containing the following chunks. |
BB3D | b3d table note: in the b3d writer the node_paths field is ignored |
node_paths | node paths a list of nodes indexed by a hieracrchy of nodes i.e. |
Functions
- mtul.b3d_reader.read_model (modelname, node_only)
-
read b3d models by their name. This simplifies readfromstream.
Parameters:
- modelname string, the name of model you are trying to read.
- node_only bool, specifies wether to ignore textures, meshes, or anything else. Use this if you're only trying to solve bone transforms.
Returns:
-
b3d table (documentation needed!)
- mtul.b3d_reader.read_from_stream (stream, ignore_chunks)
-
read directly from file
Parameters:
- stream the file object (from the io library) to read from. Make sure you open it as "rb" (read binary.)
- ignore_chunks a list of chunks to be ignored (documentation needed)
Returns:
-
BB3D (documentation needed!)
Tables
- chunks
-
an unordered list of the following string chunks.
"NODE" and "BB3D" are ommitted as they are not allowed.
Fields:
- 1 "TEXS" texture information
- 2 "BRUS" brushes (materials)
- 3 "MESH" (sub-chunks of "MESH" include "VERTS" & "TRIS")
- 4 "TRIS" sets of triangles
- 5 "VRTS" vertices
- 6 "BONE" node vertex weights
- 7 "ANIM" animation information
- 8 "KEYS" keyframes
- VRTS
-
vertices
Fields:
- flags uknown
- tex_coord_sets the number of texture coordinate sets
- tex_coord_set_size unknown
- ... a list of vertices, the integer index defines their vertexids { pos={x,y,z}, color={r, g, b, a}, texcoords=... }
- TRIS
-
triangle/poly sets
Fields:
- brush_id
- vertex_ids a list of three vertex IDs {i, j, k} which make it up
- MESH
-
the mesh chunk table
Fields:
- BONE
- bone table a list of vertex weights indexed by their vertex_id
- KEYS
-
keyframes
Fields:
- flags defines if position rotation and scale exists (further explanation needed)
- ... a list of keyframes
- keyframe
- table which specifies a keyframe
- ANIM
-
defines the animation of a model
Fields:
- flags unused?
- frames number of frames
- fps framerate of the model
- NODE
-
node
a node chunk possibly containing the following chunks.
there are three possible "types" of nodes. All bones will contain the following chunks:
position, rotation, scale. Bones will have a
bone field which will contain IDs from it's parent node's mesh chunk.
Fields:
- name
- type string which is either "pivot", "bone" or "mesh"
- children a list of child nodes, Transoformations (position, rotation, scale) will be applied to the children.
- position position {x, y, z} of the bone
- rotation quaternion {x, y, z, w} rotation of the bone at rest
- scale {x, y, z} scale of the bone at rest
- mesh MESH chunk. Found in mesh node
- bone BONE chunk. Found in bone node
- keys KEYS chunk. Found in bone node
- animation ANIM chunk. Typically found in root node (uknown wether it can be elsewhere.)
- parent the parent node. (The node in which this node is in the children table)
- BB3D
-
b3d table
note: in the b3d writer the node_paths field is ignored
Fields:
- node_paths
-
node paths
a list of nodes indexed by a hieracrchy of nodes i.e. "path.to.node"
Fields:
- ... ) node