================================
0. INTRO
================================
G3D is a binary format used for Glest for 3D models and animations. Currently a plugin for 3dsmax exists. Glest is using version 4 of this format.
Many people asked us to make a plugin for Blender but we don't have the time for doing it, however this is the spec for G3Dv4 in the case anyone wants to take a look at it.
Glest uses a rather simple 3D format, in many ways similar to MD2 (the Quake 2 format).
The Glest code for loading 3D models is in model_header.h and model.h/cpp files in the "Glest Shared Library" graphics module.
EDIT: This spec refers to the latest version of the format, since it has changed in Glest 1.1.0 release candidates.
================================
1. DATA TYPES
================================
G3D files use the following data types:
uint8: 8 bit unsigned integer
EDIT: uint16: 16 bit unsigned integer
uint32: 32 bit unsigned integer
float32: 32 bit floating point
================================
2. OVERALL STRUCTURE
================================
- File header
- Model header
- Mesh header
- Texture names
- Mesh data
================================
2. FILE HEADER
================================
EDIT: All structures are assumed to be packed.
struct FileHeader{
uint8 id[3];
uint8 version;
};
This header is shared among all the versions of G3D, it identifies this file as a G3D model and provides information of the version.
id: must be "G3D"
version: must be 4, in binary (not '4')
================================
3. MODEL HEADER
================================
struct ModelHeader{
uint16 meshCount;
uint8 type;
};
meshCount: number of meshes in this model
type: must be 0
================================
4. MESH HEADER
================================
There is a mesh header for each mesh, there must be "meshCount" headers in a file but they are not consecutive, texture names and mesh data are stored in between.
struct MeshHeader{
uint8 name[64];
uint32 frameCount;
uint32 vertexCount;
uint32 indexCount;
float32 diffuseColor[3];
float32 specularColor[3];
float32 specularPower;
float32 opacity;
uint32 properties;
uint32 textures;
};
name: name of the mesh
frameCount: number of keyframes in this mesh
vertexCount: number of vertices in each frame
indexCount: number of indices in this mesh (the number of triangles is indexCount/3)
diffuseColor: RGB diffuse color
specularColor: RGB specular color (currently unused)
specularPower: specular power (currently unused)
properties: property flags
enum MeshPropertyFlag{
mpfCustomColor= 1,
mpfTwoSided= 2
};
mpfTwoSided: meshes in this mesh are rendered by both sides, if this flag is not present only "counter clockwise" faces are rendered
mpfCustomColor: alpha in this model is replaced by a custom color, usually the player color
textures: texture flags, only 0x1 is currently used, indicating that there is a diffuse texture in this mesh.
================================
4. TEXTURE NAMES
================================
A list of uint8[64] texture name values. One for each texture in the mesh. If there are no textures in the mesh no texture names are present. In practice since Glest only uses 1 texture for each mesh the number of texture names should be 0 or 1.
================================
5. MESH DATA
================================
After each mesh header and texture names the mesh data is placed.
vertices: frameCount * vertexCount * 3, float32 values representing the x, y, z vertex coords for all frames
normals: frameCount * vertexCount * 3, float32 values representing the x, y, z normal coords for all frames
texture coords: vertexCount * 2, float32 values representing the s, t tex coords for all frames (only present if the mesh has 1 texture at least)
indices: indexCount, uint32 values representing the indices
================================
6. G3D EXPORTER
================================
Working G3D exporter for Blender 2.6x as a python script:
DownloadDocumentation:
G3D supportEdit by Omega: Fixed error as noted by Yggdrasil here