Available on:PS2

Playstation 2 .X File Loader


PS2X is a DirectX (.x) File format loader for the Sony Playstation 2 console. The aim of the project was to demonstrate a detailed knowledge of the architecture of a games console and to show how that knowledge can be expressed through an efficient and effective application.

The program is written in two parts; a file loader, and a file renderer. The loader is written in standard C++ so can be used on any platform with a C++ compiler. The renderer uses the data read in by the loader and platform specific code (C++ and Vector Unit Assembly VSM) to display the contents of the X File on the Playstation 2 console.

Introducing The X File Format

The X File Format was introduced with the release of Microsoft DirectX 3.0 as a standard format for storing 3D model data, transformations, and animations within the DirectX API. Since its initial release, the format has gone through a number of versions with the current being 3.03 (introduced with DirectX 9.0c). While primarily used as a means of storing 3D model and animation data, the X File format itself is an architecture, and context‐free file format capable of storing any data. The X File format is template driven; a template defines how a data stream of the same type as the template is interpreted. A template has the following form:

template { ; ... ; [restrictions] }

The template name can be any alphanumeric name which may include the underscore character but may not begin with a number. The GUID (Globally Unique Identifier) member is a value which uniquely identifies the template surrounded by angled brackets, for example <3F2504E0‐4F89‐11D3‐9A0C‐0305E82C3301>.

Templates may be open, closed, or restricted. These restrictions determine which data types may appear in the immediate hierarchy of a data object defined by the template. An open template has no restrictions, a closed template rejects all data types, and a restricted template allows a named list of data types. Template members consist of a named data type followed by an optional name or an array of a named data type. Accepted primitive data types are:

Data TypeSize
WORD16 bits
DWORD32 bits
FLOATIEE Float
DOUBLE64 bits
CHAR8 bits
UCHAR8 btis
BYTE8 bits
STRINGNULL‐Terminated String

Additional data types, defined by other templates encountered earlier in the data stream, can also be referenced within a template definition. No forward references are allowed.

A data type may also be expressed in an array within a template definition. A standard array definition would consist of the following elements:

array [];

The data‐type of the array may be any of those listed in the table above or any previously defined template type. Size may be an integer or a reference to another template member whose value is then substituted. Arrays may be n-dimensional, where n is determined by the number of paired square brackets trailing the statement. For example:

array DWORD FixedHerd[24]; array DWORD Herd[nCows]; array FLOAT Matrix4x4[4][4];

While the DirectX API defines a number of standard templates, including Mesh, Frame, Material, & Animation among many others, the X File format is not restricted to, or limited by, this set of templates. As an open format, it is possible to create and register custom any valid new templates. Below is an example of how a Vector and MeshFace template are defined, and how these are used to compose the definition of the Mesh template:

// Vector template states that a vector holds 3 floats (x,y,z). Template is closed so cannot contain anything else. template Vector { // Template GUID < 3D82AB5E-62DA-11cf-AB39-0020AF71E433 > //Template Members float x; float y; float z; } // MeshFace template states that a MeshFace holds the DWORD nFaceVertexIndices containing the number of face indices of in the mesh face, and an array of DWORDS of size nFaceVertexIndices containing the face indices of this mesh face. Template is closed so cannot contain anything else. template MeshFace { // Template GUID < 3D82AB5F-62DA-11cf-AB39-0020AF71E433 > // Template primitive data Memeber DWORD nFaceVertexIndices; // Template Array Member array DWORD faceVertexIndices[nFaceVertexIndices]; } //The Mesh template is a open template containing at least a DWORD nVertices containing the number of vertices in the mesh, an array of type Vector (described by the Vector template), a DWORD contining the number of faces in the mesh and an array of type MeshFace (defined by the MeshFace template) of size nFaces. Template is open so can contain any other template. template Mesh { // Template GUID <3D82AB44-62DA-11cf-AB39-0020AF71E433> // Template primitive data member DWORD nVertices; // Template Array of Vector Type (reference to earlier definition of type Vector) array Vector vertices[nVertices]; // Template primitive data member. DWORD nFaces; // Template Array of type MeshFace (reference to earlier definition of MeshFace) array MeshFace faces[nFaces]; // Open restriction (can contain 0 or more other templates) [ ... ] }

Data objects contain the actual data with a corresponding template type which identifies how the data should be read. A Data Object, in this sense can be considered an instance of its respective template. A data object is defined by first its template name, then an optional instance name, followed by a pair of braces encapsulating the objects data:

// Data Object of type Mesh named CubeMesh. Mesh CubeMesh { 8; // nVertices = 8 1.000000;1.000000;-1.000000;, // vertices[0] = Vector{1.0;1.0;-1.0} -1.000000;1.000000;-1.000000;, // vertices[1] = Vector{-1.0;1.0;1.0} -1.000000;1.000000;1.000000;, 1.000000;1.000000;1.000000;, 1.000000;-1.000000;-1.000000;, -1.000000;-1.000000;-1.000000;, -1.000000;-1.000000;1.000000;, 1. 12; // nFaces = 12 3;0,1,2;, // face 0 has 3 3;0,2,3;, 3;0,4,5;, 3;0,5,1;, 3;1,5,6;, 3;1,6,2;, 3;2,6,7;, 3;2,7,3;, 3;3,7,4;, 3;3,4,0;, 3;4,7,6;, 3;4,6,5;; // ;; Indicates the end of a container. }

Data objects defiend by open templates may be nested either inline or by refrence to describe a hierarchy:

// Data Object o Mesh CubeMesh .. //Mesh contains an inst Mat { // Material Contains an instance of Texture File Name template Textu { “diffuse.bmp”; // Texture File Name data } // Material Contains an EffectInstance Template Instance EffectIntance { “reflection.fx”; // EffectInstance data EffectParamDWORD Time{ 100; // EffectParamDWORD data } } }

In the example above, the Material, TextureFileName, EffectInstance, and EffectParamDWord Templates are assumed to be defined.

An X File may be ASCII text or binary encoded, as defined in its Header template. In its ASCII form, an X file is easily human readable and editable. The X file is also a long established and widely used 3d model and animation format within the DirectX game development community, but, due to the lack of helper functions in other API’s it is less common. At this time, there are quite a few X File loaders for OpenGL but currently no public X File loader for the Playstation 2 (although it is likely one has been written within a game development company).

The documentation for PS2X is now available here: