Game Development Reference
In-Depth Information
mesh using even fewer bytes. Suppose we scan a mesh and do some
analysis. When scanning the mesh we look for two things: the bounding
volume and the shortest edge. As an example, suppose that after such a
scan we find that the bounding volume is (0.835, 1.824, 0.234) >>
(-0.835, 0.000, -0.35) and the shortest edge is 0.002. If we use a 2-byte
integer value we can store 65 536 different values. Will this number of
values give sufficient accuracy to display the mesh without destroying the
overall look? The answer in most cases is yes. Given that the maximum
dimension of the bounding box is less than 2, if we represent 2 using
65 536 then we can represent 1 using 32 768. The maximum accuracy we
can therefore achieve is 1/32 768, approximately 0.00003. If we think of a
value of 1 as being 1 metre in world space, then we can resolve the
accuracy to 3/100 mm. For a real-time game that is more than enough
accuracy. Generally, you will find that a 2-byte integer will give enough
accuracy to display objects in the 3D environment. To use this method
effectively you will need a scaling factor that compares the stored integer
values with actual values in world coordinate space. In this example,
every value must be divided by 32 768 to give a close approximation to
the original vertex values. Therefore, the compression strategy would be
to precede each point list with a scaling value stored as a 4-byte floating-
point value. Since we save 2 bytes every vertex, this means that with a
point list containing just three values we have already experienced some
compression and as the point list increases in number the compression
gets nearer to 50 per cent over floats and 25 per cent over doubles. With
a real world example of around 5000 vertices per scene across six
scenes, Table 18.1 gives an approximation to the bytes needed to store
the point list.
Table 18.1 Point list compression
using doubles, floats and shorts
Doubles
703K
Floats
351K
Two-byte integers
176K
The next list to consider is the polygon list. We allow three- and four-
sided polygons. A polygon contains either three or four indices into the
point list that must be byte accurate or the mesh will be deformed, plus a
polygon needs to know what surface it is using to define its appearance.
If we were content that the vertex list would not exceed 255, then we could
use 1 byte to define the vertex index. This is not likely and future proofing
 
Search Nedrilad ::




Custom Search