Difference between revisions of "Block attributes"

From Mm2kiwi
Jump to: navigation, search
(Triangle fans)
(Added introduction and texture attribute, changed to reflect four bit attribute type + three bit subtype)
Line 1: Line 1:
==Common==
+
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 ''uword'' of the attribute data. The second byte is always zero.
  
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.  
+
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.
  
===Triangle fans===
+
==Common attributes==
[[Image:0x30-0x37 Triangle fan.jpg|thumbnail|350px|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.
 
  
The triangle attributes are, in fact, an entire family of attributes. Eight different attributes can be used depending on the number of vertices the surface requires. Attribute ''0x30'' is the most general one, this can handle any number of vertices. Attributes ''0x31'' - ''0x37'' are limited to 1 - 7 triangles respectively. Attribute ''0x31'' requires three vertices, attribute ''0x37'' requires nine vertices.
+
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.  
{{Clr}}
 
struct Attribute_0030
 
{
 
    ushort            id = 0x30;
 
    ushort            nVertices;
 
    ushort[nVertices] vertexRefs; // Indices in the vertex list
 
}
 
  
struct Attribute_0031
+
===Texture references===
{
 
    ushort    id = 0x31;
 
    ushort[3] vertexRefs; // Indices in the vertex list
 
}
 
  
struct Attribute_0032
+
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.
{
 
    ushort    id = 0x32;
 
    ushort[4] vertexRefs; // Indices in the vertex list
 
}
 
  
struct Attribute_0033
+
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.
{
 
    ushort    id = 0x33;
 
    ushort[5] vertexRefs; // Indices in the vertex list
 
}
 
  
  struct Attribute_0034
+
In a pseudo-C style structure, the texture attributes look like this:
 +
  struct TextureReference
 
  {
 
  {
     ushort   id = 0x34;
+
     bit   lastAttribute;
     ushort[6] vertexRefs; // Indices in the vertex list
+
    bit[4] type = 0x0a;
 +
     bit[3] subtype;
 +
    bit[8] padding = 0x00;
 +
    ushort data;
 
  }
 
  }
  
struct Attribute_0035
+
===Triangle fans===
{
+
[[Image:0x30-0x37 Triangle fan.jpg|thumbnail|350px|Triangle fan attribute]]
    ushort id = 0x35;
+
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.
    ushort[7] vertexRefs; // Indices in the vertex list
 
}
 
  
  struct Attribute_0036
+
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.
 +
{{Clr}}
 +
  struct TriangleFan
 
  {
 
  {
     ushort   id = 0x36;
+
    bit              lastAttribute;
     ushort[8] vertexRefs; // Indices in the vertex list
+
    bit[4]            type = 0x06;
 +
    bit[3]            subtype = 0x00;
 +
    bit[8]            padding = 0x00;
 +
     ushort           nVertices;  
 +
     ushort[nVertices] vertexRefs; // Indices in the vertex list
 
  }
 
  }
  
  struct Attribute_0037
+
  struct TriangleFan
 
  {
 
  {
     ushort    id = 0x37;
+
     bit                lastAttribute;
     ushort[9] vertexRefs; // Indices in the vertex list
+
    bit[4]              type = 0x06;
 +
    bit[3]              subtype != 0x00;
 +
    bit[8]              padding = 0x00;
 +
     ushort[subtype + 2] vertexRefs; // Indices in the vertex list
 
  }
 
  }

Revision as of 20:53, 12 August 2005

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 uword 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
}