psx.wiki

TMD (Modeling Data for OS Library): Difference between revisions

Revision as of 02:22, 23 October 2026
RemmyLee
(Hardware and system software pages from the Sony manuals)
Revision as of 02:27, 23 October 2026
RemmyLee
(File format pages from the Sony File Formats manual)
Line 1:Line 1:
+---
+title: TMD (Modeling Data for OS Library)
+type: format
+summary: 3D modeling data for the extended graphics library (libgs).
+category: File formats
+info: Extension = .TMD
+info: ID = 0x00000041
+info: Created by = RSDLINK
+---
+
+## Overview
+
+The TMD format holds 3D modeling data for the PlayStation extended graphics library (libgs).[^ff224]
+
+TMD data is loaded into memory and passed as an argument to libgs functions.[^ff224]
+
+The RSDLINK utility creates TMD files. It reads an RSD file made by the SCE 3D Graphics Tool or a comparable program.[^ff224]
+
+A TMD file holds the polygons and lines that make up a 3D object. One TMD file can hold one or more objects.[^ff224]
+
+## Coordinate Values
+
+TMD coordinates follow the 3D coordinate space of the 3D graphics library.[^ff224]
+
+The positive X axis points right. The positive Y axis points down, and the positive Z axis points into the depth.[^ff224]
+
+Each spatial coordinate is a signed 16-bit integer from -32768 to +32767.[^ff224]
+
+RSD stores vertices as floating point values. Conversion from RSD to TMD scales the vertex values as needed.[^ff224]
+
+The scale used is stored in the object structure. The current version of libgs ignores it.[^ff224]
+
+## File Format
+
+A TMD file has 4 blocks. An object table is followed by three kinds of data: PRIMITIVE, VERTEX and NORMAL.[^ff224]
+
+### Header
+
+The header is three words (12 bytes) of data about the structure.[^ff225]
+
+The header fields are as follows:
+
+Table: 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.[^ff225]
+
+### Obj Table
+
+The OBJ TABLE is a table of object structures. Each one points to the data of one object.[^ff225]
+
+The object structure is as follows:
+
+Table: 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.[^ff225]
+
+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.[^ff226]
+
+The scale value returns the model to its scale at design time.[^ff226]
+
+### Primitive
+
+The PRIMITIVE section is a list of drawing packets. One packet is one primitive.[^ff226]
+
+TMD primitives differ from the drawing primitives of libgpu. libgs converts a TMD primitive to a drawing primitive by perspective transformation.[^ff226]
+
+Each packet has a variable length. Its size and structure depend on the primitive type.[^ff226]
+
+A packet holds the following items:
+
+Table: 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.[^ff226]
+
+The CODE values are as follows:
+
+Table: Mode CODE values
+
+| CODE | Primitive |
+| --- | --- |
+| 001 | Polygon (triangle, quadrilateral) |
+| 010 | Straight line |
+| 011 | Sprite |
+
+The Flag bits are as follows:[^ff226]
+
+Table: 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.[^ff227]
+
+Table: 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.[^ff227]
+
+### Normal
+
+The normal section is a list of normal structures.[^ff227]
+
+Table: 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.[^ff227]
+
+The fixed-point format is as follows:
+
+Table: 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:[^ff228]
+
+Table: 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.[^ff228]
+
+### TSB
+
+TSB holds the texture page and its modes.[^ff228]
+
+Table: 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:[^ff228]
+
+Table: 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.[^ff228]
+
+Table: 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.[^ff229][^ff230]
+
+The polygon mode bits are as follows:
+
+Table: 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.[^ff230]
+
+The values are as follows:
+
+Table: 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.[^ff230]
+
+A packet with light source calculation holds a normal for each vertex in Gouraud mode and one normal in flat mode.[^ff230]
+
+A packet without light source calculation holds no normals. It holds the color to draw with.[^ff232]
+
+### Straight Line
+
+From the MSB, a line Mode has the bits 0 1 0 IIP 0 0 ABE 0.[^ff233]
+
+The line mode bits are as follows:
+
+Table: 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:[^ff234]
+
+Table: 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.[^ff234]
+
+From the MSB, the 3D sprite Mode has the fields 0 1 1 SIZ 1 ABE 0.[^ff234]
+
+The SIZ values are as follows:
+
+Table: 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
+
+[^ff224]: Sony Computer Entertainment Inc. File Formats. November 1998. Page 2-24.
+[^ff225]: Sony Computer Entertainment Inc. File Formats. November 1998. Page 2-25, Figures 55 and 56.
+[^ff226]: Sony Computer Entertainment Inc. File Formats. November 1998. Page 2-26, Figures 58 and 59.
+[^ff227]: Sony Computer Entertainment Inc. File Formats. November 1998. Page 2-27, Figures 60 to 62.
+[^ff228]: Sony Computer Entertainment Inc. File Formats. November 1998. Page 2-28, Figures 63 and 64.
+[^ff229]: Sony Computer Entertainment Inc. File Formats. November 1998. Page 2-29, Figure 65.
+[^ff230]: Sony Computer Entertainment Inc. File Formats. November 1998. Page 2-30, Figures 66 and 67.
+[^ff232]: Sony Computer Entertainment Inc. File Formats. November 1998. Page 2-32, Figure 70.
+[^ff233]: Sony Computer Entertainment Inc. File Formats. November 1998. Page 2-33, Figure 73.
+[^ff234]: Sony Computer Entertainment Inc. File Formats. November 1998. Page 2-34, Figures 74 and 75.