The structure of a SHP file
1) Header
2) Surfaces/Faces
3) Vertex/Point Data
4) Footer (Materials)
Header:
|
Num Bytes |
Name Of Variable |
Comments |
|
2 |
Version |
Ranges from 12 to 16, if the value is 12 just ignore it (the file is probably not even used, and I haven’t figure out the correct format of it) |
|
2 |
? |
|
|
2 |
Vertex Size |
If its 0 or 1 just ignore it… otherwise set the VertexSize to this value |
|
2 |
? |
|
|
4 |
File Size |
The total file size of the SHP in bytes |
|
4 |
? |
Always 0 (?) |
|
4 |
Points Offset |
The offset in bytes from the beginning of the files to the vertices/points |
|
4 |
Faces Offset |
Offset to the surface/face data (always 82) |
|
4 |
Materials Offset |
… |
|
4 |
Bounding Sphere Radius (?) |
The second byte in this value seems to represent a bounding sphere which affects if the cockpits drawn and how far away the objects should be in the buy/sell menu. |
|
24 |
Bounding Box |
See Below |
The bounding box:
If the Version is 16 then it is in the format:
|
Num Bytes |
Name Of Variable |
Comments |
|
4 |
MinX |
|
|
4 |
MinY |
|
|
4 |
MinZ |
|
|
4 |
MaxX |
|
|
4 |
MaxY |
|
|
4 |
MaxZ |
|
Otherwise it is in the format of:
|
Num Bytes |
Name Of Variable |
Comments |
|
4 |
MinX |
|
|
4 |
MaxX |
|
|
4 |
MinY |
|
|
4 |
MaxY |
|
|
4 |
MinZ |
|
|
4 |
MaxZ |
|
Surfaces: (at Faces Offset)
There are 2 bytes specifying the number of surfaces
If the Version is more than 14 then the number of Surface structure is:
|
Num Bytes |
Name Of Variable |
Comments |
|
2 |
Flags |
Used mainly for WHP files in the WXP file. But might have an effect on where the landing gear is |
|
1 |
Material Index |
Links to which material this surface should be assigned to (see footer) |
|
1 |
? |
Linked to the material somehow? |
|
6 |
|
In the format of x,y,z with 2 bytes each |
|
1 |
NumPoints |
The number of points for this surface (doesn’t exist on some WHP files and is defaulted to 4) |
|
1 |
Texture Coords Flags |
If this surface has texture coords then this is set to -64 otherwise 64 (doesn’t exist in some WHP files) |
Otherwise the format is:
|
Num Bytes |
Name Of Variable |
Comments |
|
1 |
NumPoints |
(see above) |
|
1 |
Texture Coords Flags |
|
|
6 |
|
|
|
1 |
Material Index |
|
|
1 |
? |
Linked to the material somehow? |
|
2 |
Flags |
|
Then there is index data for the next 2*NumPoints bytes (note: can be just NumPoints bytes for certain Flags values although this is only in WHP files)
Next is the normals for 3*2*NumPoints with each component of the normal being 2 bytes long and in the format (x,y,z), (x,y,z), (x,y,z) etc…
If the Texture Coords Flags is set to -64 then there are NumPoints*2*2 bytes of texture coordinates in the form (u,v),(u,v),(u,v) etc… with u and v each being 2 bytes long.
In WHP files the Flags variable is set to various things which changes around the order of where things are placed, the size of things and removes other things entirely.
Vertices:
The first 2 bytes at the Points Offset are the Number of vertices.
If the Header::Version is 15 or 16 then the size of each vertex is 6 components if the version is 13 or 14 then the size is 4 components and if the version is 12 then its 3 components.
If the second unknown in the header (the one that’s normally 1 or 0) is more than 2 then the vertex size is equal to this.
Each vertex component is 2 bytes long and they are stored in the format (x,y,z,?,?,?),(x,y,z,?,?,?),(x,y,z,?,?,?) etc… the number of components depends on the vertex size (see above)
After the standard x,y,z part of each point the following bytes are node data (which is used for things like pilot position, landing gear, thrusters etc)
Footer:
The footer is at the Materials Offset and contains information on the materials.
Firstly theres 2 bytes saying how many materials there are then theres the materials in the format:
|
Num Bytes |
Name Of Variable |
Comments |
|
16 |
Name |
The name of the material |
|
1 |
ID |
Used to link surfaces to materials |
|
1 |
? |
|
The material is then linked to the material of the same name in the MAT files.