Gunship - Format of 3DB Files

These model files are very similar to EAW's 3DZ models, which are also used in Gunship.
The main differences are:
·	The models can contain up to 65535 elements and 65535 points, instead of the 256 allowed by 3DZ's.
·	All x,y,z coordinates are expressed as floating point values (and therefore take up 4 bytes instead of 2).
·	Texture mapping coordinates are also floating point values, ranging from 0 to 1.  In terms of the textures, coordinate (1,1) corresponds to the bottom right, and (0,0) to the top left.  To get the actual pixel coordinate, simply multiply by the size of the texture (normally 256).
·	All surface normals are normalised to 1 (using floating point values) instead of 16384 as in the 3DZs.
·	The 3DB format also includes "True Vertex Normals", which I don't know the use of - perhaps someone who is familiar with Gunship could fill in this blank?

Please see Paulo Morais’ original notes on the 3DZ structure for more detailed information about each section.

Gurney, 19/10/2003

All Location offsets are given as decimals

12 bytes UNKNOWN

HEADER
Offset at: 12 bytes
Length: 48 bytes

Type	Description
long	# Sub Matrices
long	# Points
long	# True Vertex Normals
long	# Elements

INSERTS
Offset at: 60 bytes
Length: (# Parts * 16) bytes

Type	Description
float	_y
float	_z
float	_x
byte	_cod
byte	_num
word	_term (always 0000)

POINTS
Offset at: 60 + (# Parts * 16) bytes
Length: (# Points * 16) bytes

Type	Description
float	_y
float	_z
float	_x
short	_b

TRUE VERTEX NORMALS
Offset at: 60 + (# Parts * 16) + (# Points * 16) bytes
Length: (# True Vertex Normals * 16) bytes

Type	Description
float	_y
float	_z
float	_x
float	??? (maybe _b as in nodes?)

NORMALS
Offset at: 60 + (# Parts * 16) + (# Points * 16) +(# True Vertex Normals * 16) bytes
Length: (# Elements * 20) bytes

Type	Description
float	_y
float	_z
float	_x
float	_d	*See note below
short	_f

* The _d value is actually a combination of the _c and _d values as read by 3DZ Studio.  Paulo Morais’ original notes incorrectly split this one value into the two above.  The _d value is actually the D value from the Plane Equation.

RENDERING SEQUENCE
Offset at: 60 + (# Parts * 16) + (# Points * 16) +(# True Vertex Normals * 16) + (# Elements * 20) bytes
Length: (# Elements+1 * 4) bytes

Type	Description
word	back element
word	front element

ELEMENT LOOKUP TABLE
Offset at: 60 + (# Parts * 16) + (# Points * 16) +(# True Vertex Normals * 16) + (# Elements * 20) + (# Elements+1 * 4) bytes
Length: (# Elements * 4) bytes

Type	Description
long	offset [+3C (60d) to get real offset]

ELEMENTS
Offset at: 0 (0d)
Length: ???

Type	Description
byte	_cod
byte	_crn
word	_att
word	_nod[0]
word	???? (is either 0100 or 0000)
float	_xmap[0]
float	_ymap[0]
long	_term (always FFFF FFFF)

UNKNOWN - ALWAYS THE SAME
Offset at: 60 + (# Parts * 16) + (# Points * 16) +(# True Vertex Normals * 16) + (# Elements * 20) + (# Elements+1 * 4) + (# Elements * 4) bytes
Length: 104 bytes

0000 803F x3
0000 7F43
00 x12
0100 0000 0000 0000
TEXTURE NAME char[14]
00 x14
0000 C042
00 x12
0400 0000
00 x20