Skip to content

Instantly share code, notes, and snippets.

@MarkusMaal
Created May 17, 2025 17:38
Show Gist options
  • Select an option

  • Save MarkusMaal/aa2c85defe4fb61504e79ec9071b5863 to your computer and use it in GitHub Desktop.

Select an option

Save MarkusMaal/aa2c85defe4fb61504e79ec9071b5863 to your computer and use it in GitHub Desktop.
ImHex Pattern - PlayStation .TMD file format (3D models)
// based on:
// http://justsolve.archiveteam.org/wiki/TMD_(PlayStation)
struct FlatTriangleVertexNormals {
u8 r,g,b,unknown;
u16 n0;
u16 v0;
u16 n1;
u16 v1;
u16 n2;
u16 v2;
};
struct FlatQuadVertexNormals {
u8 r,g,b,unknown;
u16 n0;
u16 v0;
u16 n1;
u16 v1;
u16 n2;
u16 v2;
u16 n3;
u16 v3;
};
struct SingleColorQuad {
u8 r,g,b,unknown;
u16 n0;
u16 v0;
u16 v1;
u16 v2;
u16 v3;
};
struct GouraudQuad {
u8 r0,g0,b0,unk0;
u8 r1,g1,b1,unk1;
u8 r2,g2,b2,unk2;
u8 r3,g3,b3,unk3;
u16 n0;
u16 v0;
u16 v1;
u16 v2;
u16 v3;
};
struct GouraudTriangle {
u8 r0,g0,b0,unk0;
u8 r1,g1,b1,unk1;
u8 r2,g2,b2,unk2;
u16 n0;
u16 v0;
u16 v1;
u16 v2;
};
struct SingleColorTriangle {
u8 r,g,b,unknown;
u16 n0;
u16 v0;
u16 v1;
u16 v2;
};
struct TexturedTriangle {
u16 unk1;
u8 v0;
u8 u0;
u16 unk2;
u8 v1;
u8 u1;
u16 unk3;
u8 v2;
u8 u2;
u16 v0_;
u16 n0;
u16 v1_;
u16 n1;
u16 v2_;
u16 n2;
};
struct Primitive {
u8 unknown0;
u8 length;
u8 unknown1;
u8 type;
if ((type == 0x22) || (type == 0x20)) {
SingleColorTriangle triangle;
} else if (type == 0x24) {
GouraudTriangle triangle;
} else if (type == 0x28) {
SingleColorQuad quad;
} else if (type == 0x2c) {
GouraudQuad quad;
} else if (type == 0x30) {
FlatTriangleVertexNormals triangle;
} else if (type == 0x34) {
TexturedTriangle triangle;
} else if (type == 0x38) {
FlatQuadVertexNormals quad;
}
};
struct VertexNormal {
u16 x;
u16 y;
u16 z;
u16 zero;
};
struct Object {
u32 vertex_offset;
u32 vertex_count;
u32 normal_offset;
u32 normal_count;
u32 primitive_offset;
u32 primitive_count;
u32 unknown;
VertexNormal Vertices[vertex_count] @ vertex_offset + 0xC;
VertexNormal Normals[normal_count] @ normal_offset + 0xC;
Primitive Primitives[primitive_count] @ primitive_offset + 0xC;
};
struct Header {
u32 id;
u32 reserved;
u32 num_objects;
Object Objects[num_objects];
};
Header Tmd @ 0x00;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment