psx.wiki

TMD (Modeling Data for OS Library)

3D modeling data for the extended graphics library (libgs).

TMD (Modeling Data for OS Library)
Extension.TMD
ID0x00000041
Created byRSDLINK

This is an old revision of this page, as edited by RemmyLee at 02:27, 23 October 2026. Edit this revision | Latest revision

Overview

The TMD format holds 3D modeling data for the PlayStation extended graphics library (libgs).1

TMD data is loaded into memory and passed as an argument to libgs functions.1

The RSDLINK utility creates TMD files. It reads an RSD file made by the SCE 3D Graphics Tool or a comparable program.1

A TMD file holds the polygons and lines that make up a 3D object. One TMD file can hold one or more objects.1

Coordinate Values

TMD coordinates follow the 3D coordinate space of the 3D graphics library.1

The positive X axis points right. The positive Y axis points down, and the positive Z axis points into the depth.1

Each spatial coordinate is a signed 16-bit integer from -32768 to +32767.1

RSD stores vertices as floating point values. Conversion from RSD to TMD scales the vertex values as needed.1

The scale used is stored in the object structure. The current version of libgs ignores it.1

File Format

A TMD file has 4 blocks. An object table is followed by three kinds of data: PRIMITIVE, VERTEX and NORMAL.1

The header is three words (12 bytes) of data about the structure.2

The header fields are as follows:

Table 1: TMD header
Field Contents
ID Version of the TMD file, 32 bits. The current version is 0x00000041.
FLAGS 32 bits. Bit 0 is FIXP. The other bits are reserved and zero.
NOBJ Number of objects

FIXP sets whether the pointers in the OBJECT structures are real addresses. 1 is a real address, and 0 is an offset from the start.2

Obj Table

The OBJ TABLE is a table of object structures. Each one points to the data of one object.2

The object structure is as follows:

Table 2: Object structure
Member Type Contents
vert_top u_long * Start address of the vertices
n_vert u_long Number of vertices
normal_top u_long * Start address of the normals
n_normal u_long Number of normals
primitive_top u_long * Start address of the primitives
n_primitive u_long Number of primitives
scale long Scaling factor

With FIXP 1 the three pointers are real addresses. With FIXP 0 they are relative to the top of the OBJECT block.2

The scale value is 2 raised to the scaling factor. A factor of 0 gives 1, a factor of 2 gives 4, and -1 gives 1/2.3

The scale value returns the model to its scale at design time.3

Primitive

The PRIMITIVE section is a list of drawing packets. One packet is one primitive.3

TMD primitives differ from the drawing primitives of libgpu. libgs converts a TMD primitive to a drawing primitive by perspective transformation.3

Each packet has a variable length. Its size and structure depend on the primitive type.3

A packet holds the following items:

Table 3: Drawing packet items
Item Size Contents
Mode 8 bits Type of primitive and its attributes
Flag 8 bits Options for rendering
Ilen 8 bits Length of the packet data section in words
Olen 8 bits Word length of the 2D drawing primitive made by intermediate processing
Packet data Ilen words Vertex and normal parameters

The top 3 bits of Mode are CODE. CODE gives the entity type.3

The CODE values are as follows:

Table 4: Mode CODE values
CODE Primitive
001 Polygon (triangle, quadrilateral)
010 Straight line
011 Sprite

The Flag bits are as follows:3

Table 5: Flag bits
Bit Name Contents
0 LGT 1 no light source calculation, 0 light source calculation
1 FCE 1 double-faced polygon, 0 single-faced polygon. Valid only for polygons.
2 GRD 1 gradation polygon, 0 single-color polygon. Valid only for an untextured polygon with light source calculation.
3..7 0

Vertex

The vertex section is a list of vertex structures.4

Table 6: Vertex structure
Word Upper 16 bits Lower 16 bits
0 VY VX
1 VZ

VX, VY and VZ are the x, y and z coordinates of the vertex as 16-bit integers.4

Normal

The normal section is a list of normal structures.4

Table 7: Normal structure
Word Upper 16 bits Lower 16 bits
0 NY NX
1 NZ

NX, NY and NZ are signed 16-bit fixed-point values in which 4096 is 1.0.4

The fixed-point format is as follows:

Table 8: Fixed-point format
Bits Part
15 Sign (1 bit)
12..14 Integral part (3 bits)
0..11 Decimal part (12 bits)

Packet Data

The packet data section holds the following parameters:5

Table 9: Packet data parameters
Parameter Contents
Vertex(n) 16-bit index of a vertex, counted from the start of the object's vertex section
Normal(n) 16-bit index of a normal, counted in the same way
Un, Vn X and Y coordinates of each vertex in the texture source space
Rn, Gn, Bn Polygon color as unsigned 8-bit integers
TSB Texture page and sprite pattern information
CBA Position of the CLUT in VRAM

Without light source calculation, Rn, Gn and Bn must hold the brightness to draw with.5

TSB

TSB holds the texture page and its modes.5

Table 10: TSB fields
Field Contents
TPAGE Texture page number (0 to 31)
ABR Semi-transparency rate. Valid only when ABE is 1.
TPF Color mode: 00 4-bit, 01 8-bit, 10 15-bit

The ABR values are as follows:5

Table 11: ABR semi-transparency rates
ABR Mixture
00 50% back + 50% polygon
01 100% back + 100% polygon
10 100% back - 100% polygon
11 100% back + 25% polygon

CBA

CBA gives the position of the CLUT in VRAM.5

Table 12: CBA fields
Bits Field Contents
0..5 CLX Upper 6 bits of the 10-bit X coordinate of the CLUT
6..14 CLY 9-bit Y coordinate of the CLUT

Primitive Types

Polygons

From the MSB, a polygon Mode has the bits 0 0 1 IIP Q TME ABE TGE. Q (bit 3) is set for a 4-vertex polygon.67

The polygon mode bits are as follows:

Table 13: Polygon mode bits
Bit Name Contents
0 TGE Brightness calculation at texture mapping: 0 on, 1 off (draws the texture as is)
1 ABE Translucency processing: 0 off, 1 on
2 TME Texture: 0 off, 1 on
3 1 for a 4-vertex primitive
4 IIP Shading mode: 0 flat, 1 Gouraud
5..7 CODE 001

The manual gives header values for 3-vertex polygons with light source calculation.7

The values are as follows:

Table 14: 3-vertex polygon packets with light source calculation
Packet Mode Flag Ilen Olen
Flat, no texture (solid) 0x20 0x00 0x03 0x04
Gouraud, no texture (solid) 0x30 0x00 0x04 0x06
Flat, no texture (gradation) 0x20 0x04 0x05 0x06
Gouraud, no texture (gradation) 0x30 0x04 0x06 0x06
Flat, texture 0x24 0x00 0x05 0x07
Gouraud, texture 0x34 0x00 0x06 0x09

These values are for a single-faced polygon without semi-transparency processing.7

A packet with light source calculation holds a normal for each vertex in Gouraud mode and one normal in flat mode.7

A packet without light source calculation holds no normals. It holds the color to draw with.8

Straight Line

From the MSB, a line Mode has the bits 0 1 0 IIP 0 0 ABE 0.9

The line mode bits are as follows:

Table 15: Straight line mode bits
Bit Name Contents
1 ABE Translucency processing: 0 off, 1 on
4 IIP Gradation: 0 off (monochrome), 1 on

The manual gives the following line packet headers:10

Table 16: Straight line packets
Packet Mode Flag Ilen Olen
Gradation off 0x40 0x01 0x02 0x03
Gradation on 0x50 0x01 0x03 0x04

3D Sprite

A 3D sprite has 3D coordinates. It draws the same as a normal sprite.10

From the MSB, the 3D sprite Mode has the fields 0 1 1 SIZ 1 ABE 0.10

The SIZ values are as follows:

Table 17: 3D sprite SIZ values
SIZ Sprite size
00 Free size (specified by W, H)
01 1 x 1
10 8 x 8
11 16 x 16

References


  1. ^ a b c d e f g h i j Sony Computer Entertainment Inc. File Formats. November 1998. Page 2-24.

  2. ^ a b c d Sony Computer Entertainment Inc. File Formats. November 1998. Page 2-25, Figures 55 and 56.

  3. ^ a b c d e f g Sony Computer Entertainment Inc. File Formats. November 1998. Page 2-26, Figures 58 and 59.

  4. ^ a b c d Sony Computer Entertainment Inc. File Formats. November 1998. Page 2-27, Figures 60 to 62.

  5. ^ a b c d e Sony Computer Entertainment Inc. File Formats. November 1998. Page 2-28, Figures 63 and 64.

  6. ^ Sony Computer Entertainment Inc. File Formats. November 1998. Page 2-29, Figure 65.

  7. ^ a b c d Sony Computer Entertainment Inc. File Formats. November 1998. Page 2-30, Figures 66 and 67.

  8. ^ Sony Computer Entertainment Inc. File Formats. November 1998. Page 2-32, Figure 70.

  9. ^ Sony Computer Entertainment Inc. File Formats. November 1998. Page 2-33, Figure 73.

  10. ^ a b c Sony Computer Entertainment Inc. File Formats. November 1998. Page 2-34, Figures 74 and 75.

Categories: File formats