Game Development Reference
In-Depth Information
tends to lead us to think that even a 2-byte integer value for the point
index is likely to be exceeded relatively quickly. A polygon list also needs
to store any texture coordinates that are used. The technique used is to
use the first byte in a polygon as a flag, with the following bit pattern:
Bit 7
Not used
6
Texture coordinates stored as short integer
5
Texture coordinates stored
4 and 3
Number of bytes used to store surface index
2 and 1
Number of bytes used to store point index
0
Quad if set
Bits 1 and 2 store the number of bytes used to store the point index. This
allows between 1 and 4 bytes for a point index. Using this technique the
current requirement of around 5000-10 000 vertices per scene is
accommodated using 2 bytes but future proofed to allow for over 16
million vertices!
A similar technique is used when dealing with the surface index for a
polygon. Some scenes are going to have less than 256 surfaces. By
reading bits 3 and 4 of the flag, we know whether to read 1, 2, 3 or 4 bytes
when reading the surface index.
Another aspect of the polygon list is the texture coordinates used by a
polygon. Texture coordinates are only used when a texture is present, so
we use bit 5 of the flag to indicate this. If we are storing texture
coordinates then we can use the method indicated for the point list for
storing a floating-point value. Texture coordinates are numbers between 0
and 1. By storing these as a 2-byte integer value, we save half the file size
we would use if floats were adopted. Again, because we are dealing with
relatively crude levels of detail, this loss of precision should not create any
major problems. For completeness we use a bit in our flag to indicate
whether texture coordinates are stored as short integers or floats.
Finally, we have the surface list. Here we have some potential for
compression. There are many reasons why object level surface lists are
to be recommended, but file size is not one of them. In a character with
many segments there could easily be many repetitions of the same
surface. When compressing surfaces it is best to create a scene level
surface list by iterating through all the objects in a scene and checking the
surface list against a global level list that is created on the fly. When
creating a global surface list we must ensure that the polygon surface
indices refer to the global list of surfaces, not the object level. By adding
a member to the object level surface structure that gives a global index for
the surface, this can be updated as the surfaces are checked. You should
Search Nedrilad ::




Custom Search