.TMD - pmandin/reevengi-tools GitHub Wiki
The .TMD file format is the standard file format for 3D objects on Playstation. It is also used by many PC ports of Playstation games, like Resident Evil, Resident Evil 2, Resident Evil 3.
The values are stored in Little-Endian order.
A TMD file can contain several 3D models. It starts with this header:
typedef struct { unsigned long id; /* Constant = 0x41 */ unsigned long unknown; unsigned long num_objects; /* Number of objects in file */ } tmd_header_t;
Then are following the objects headers, as an array of tmd_object_t objects[num_objects].
typedef struct { unsigned long vertex_offset; /* Offset to vertex array coordinates */ unsigned long vertex_count; /* Number of vertices */ unsigned long normal_offset; /* Offset to normal array coordinates */ unsigned long normal_count; /* Number of normals */ unsigned long primitive_offset; /* Offsets to primitives */ unsigned long primitive_count; /* Number of primitives */ unsigned long unknown; } tmd_object_t;
Vertices and normals share the same format to holds the 3D coordinate:
typedef struct { short x; short y; short z; short zero; } tmd_vertex_t;
Each primitive starts with same header, and the rest depend on the primitive type:
typedef struct { unsigned char unknown0; unsigned char length; /* Length of following primitive in 32bit words */ unsigned char unknown1; unsigned char type; /* primitive type */ } tmd_prim_header_t;
unsigned short n0; /* Normal index */ unsigned short v0; /* Vertex index */ unsigned short v1; unsigned short v2; } tmd_flattriangle_t;
unsigned short n0; /* Normal index */ unsigned short v0; /* Vertex index */ unsigned short v1; unsigned short v2; } tmd_gouraudtriangle_t;
unsigned short n0; /* Normal index */ unsigned short v0; /* Vertex index */ unsigned short v1; unsigned short v2; unsigned short v3; } tmd_flatquad_t;
unsigned short n0; /* Normal index */ unsigned short v0; /* Vertex index */ unsigned short v1; unsigned short v2; unsigned short v3; unsigned short unk5; } tmd_gouraudquad_t;
unsigned short n0; /* Normal index */ unsigned short v0; /* Vertex index */ unsigned short n1; unsigned short v1; unsigned short n2; unsigned short v2; } tmd_flattriangle2_t;
unsigned short v0; /* Vertex index */ unsigned short n0; /* Normal index */ unsigned short v1; unsigned short n1; unsigned short v2; unsigned short n2; } tmd_txtriangle_t;
unsigned short n0; /* Normal index */ unsigned short v0; /* Vertex index */ unsigned short n1; unsigned short v1; unsigned short n2; unsigned short v2; unsigned short n3; unsigned short v3; } tmd_flatquad2_t;