Game Development Reference
In-Depth Information
deformation of each vertex. As each bone is created, if it is going to
influence a vertex from the single mesh then it adds one to the weight for
this vertex. When we are deforming the single mesh object and find that
the weight parameter is greater than zero, then a bone must be deforming
the vertex. If the weight parameter is 2 then two bones are deforming the
vertex, if the weight parameter is 3 then three bones are deforming the
vertex, and so on.
Now, in our transformation loop, we first need to zero the world vertex
locations for each vertex in the single mesh object. Then we deform the
vertices pointed to by Bone01 summing the value with the existing world
value of the vertex. Because this is the first bone the existing value will
have each component ( wx , wy , wz ) set to 0.0. Having set the vertex
locations for Bone01, the software moves on to Bone02. If the scene was
more complex then we would simply iterate through all the bones in the
scene until all transformations were complete. At this stage, vertices 1-4
and 9-12 are already in their correct location because they have weights
of one. Vertices 5-8 are now set to the sum of the location of the vertex
in Bone01 and the vertex in Bone02. What we actually require is the
average of these two, which we can simply derive by dividing the x , y and
z values for the vertex by its weight; in this simple example the weight will
be 2. We need to check whether a vertex has a weight greater than 1 and
if so divide by its weight to get the correct location for all vertices in an
object that are being controlled in this way. This simple bone deformation
system has the merit that it has very little redundancy; all the calculations
performed are necessary for the required display. The problem with the
system is that as a developer you need to be able to import geometry from
a modeller package such as 3DS, Maya or Lightwave into your application
while retaining point index references for your bone assignments. This is
not easily achieved. How do you decide which vertices are those in the
arm and which in the neck, etc.? One way would be to write your own
plug-in for Lightwave or 3DS that creates a list of point indices from a point
selection and use this when creating your bones. See Chapter 10 for how
you could do just this for Lightwave. But there is an alternative that shares
the benefits of performance while allowing you to continue to use just
simple geometry for import and export, rather than requiring you to
familiarize yourself with yet another SDK.
An alternative to bone deformation
This alternative works in just the same way as the previously suggested
bone deformation system, the difference being the way that the point