Block attributes

From Mm2kiwi
Revision as of 00:30, 13 August 2005 by Fre-Ber (talk | contribs) (Roads with sidewalks: Linked to the correct image)

Jump to: navigation, search

Most block attributes are built in a similar way, all share a bit indicating that the attribute is the last one in the block, all have a four bit type indicator and all have a three bit sub type indicator. These parameters form the first byte of the first ushort of the attribute data. The second byte is always zero.

Typically, the subtype indicates the number of something for the attribute, for example, the number of points in a triangle fan, the number of cross-sections in a road and so on. The subtype zero usually means that the counter is instead stored in the following uword in the attribute data.

Common attributes

Most attributes of the PSDL-file are specialized, created for a specific purpose. Some, however, are general attributes with several uses. This section describes them.

Texture references

Most geometry primitives use texture mappings. The textures are identified by attributes of type 0xa. The data is just one byte and a padding zero byte. The byte is an eight bit index in the list of materials. In order to be able to use more than 256 textures, the subtype indicates a value to add to the byte to get the real index. This formula can be used to compute the real index, n: n = data + (256 * subtype) - 1. The data value 0 in subtype 0 is special, it is used in both SF and London, but the effect is unknown.

Several block attributes use more than one texture. In most cases the texture attribute references the first texture in a list. This texture index is referenced to as texture n and block attributes sometimes uses texture index n, n + 1, n + 2, n + 3 and so on.

In a pseudo-C style structure, the texture attributes look like this:

struct TextureReference
{
    bit    lastAttribute;
    bit[4] type = 0x0a;
    bit[3] subtype;
    bit[8] padding = 0x00;
    ushort data;
}

Triangle fans

Triangle fan attribute

To create ground surfaces triangle fans are usually used. These are constructed by a list of vertices surrounding a pivot vertex in a counter-clockwise order. Often the triangle fan is degenerated to a convex polygon. This means that the pivot vertex is located on the perimeter of the attribute.

Triangle fan attributes have type 0x06 and the sub type indicates the number of triangles present in the triangle fan. Sub type zero is special and means that the total number of vertices are stored in the following uword. Of course, there are no actual coordinates listed in the attribute, instead each uword in the data is an index in the vertex list of the PSDL file.

struct TriangleFan
{
    bit               lastAttribute;
    bit[4]            type = 0x06;
    bit[3]            subtype = 0x00;
    bit[8]            padding = 0x00;
    ushort            nVertices; 
    ushort[nVertices] vertexRefs; // Indices in the vertex list
}
struct TriangleFan
{
    bit                 lastAttribute;
    bit[4]              type = 0x06;
    bit[3]              subtype != 0x00;
    bit[8]              padding = 0x00;
    ushort[subtype + 2] vertexRefs; // Indices in the vertex list
}

Roads

In a racing game, the roads are one of the most important features. There are several geometric primitives for defining roads, this section describes them.

Roads with sidewalks

0x00-0x07 Road strip.jpg

The most common roads in an MM2 city are the ones with sidewalks on both sides. These are easily defined using cross-sections of the road. Attribute 0x00 defines cross sections of the particular road segment.

The vertices in each cross section are organized like this: First comes the vertex defining the position of the outer edge of the left sidewalk, then follows the outer edge of the left road surface, the outer edge of the right road surface and finally the outer edge of the right sidewalk. MM2 automatically renders the vertical sides of the sidewalks and the road surface vertices are expected to be located 15 cm below the sidewalk vertices.

This type of roads use three textures. The texture attribute points out texture n, this texture is used to render the road surface. This texture is mirrored along the center line of the road. The sidewalks are rendered using texture n + 1 and texture n + 2 is the texture used across the entire road in the lowest LOD, or level of detail, of the road segment.

struct Road
{
    bit                   lastAttribute;
    bit[4]                type = 0x00;
    bit[3]                subtype = 0x00;
    bit[8]                padding = 0x00;
    ushort                nSections;
    ushort[nSections * 4] vertexRefs; // Indices in the vertex list
}
struct Road
{
    bit                 lastAttribute;
    bit[4]              type = 0x00;
    bit[3]              subtype != 0x00;
    bit[8]              padding = 0x00;
    ushort[subtype * 4] vertexRefs; // Indices in the vertex list
}