Game Development Reference
In-Depth Information
d . p os . z e r o ( ) ;
d . n o r m a l . z e r o ( ) ;
f o r
( i n t
j
=
0
;
j < s . boneCount
;
++ j )
{
/ /
L o c a t e
t h e
t r a n s f o r m
m a t r i x
c o n s t
M a t r i x 4 x 3
&boneToModel
=
b o n e T o M o d e l L i s t [ s . b o n e I n d e x [ j ] ] ;
/ /
T r a n s f o r m
from
bone
t o
model
space
( u s i n g
/ /
o v e r l o a d e d
v e c t o r
m a t r i x
o p e r a t o r
which
does
/ /
m a t r i x
m u l t i p l i c a t i o n ) ,
and sum
i n
t h i s
bone ' s
/ / c o n t r i b u t i o n
d . po s
+=
s . p o s I n B o n e S p a c e [ j ]
boneToModel
s . boneWeight [ j ] ;
R o t a t e
/ /
t h e
v e r t e x
i n t o
body
space ,
i g n o r i n g
t h e
/ /
t r a n s l a t i o n
p o r t i o n
o f
t h e
a f f i n e
t r a n s f o r m .
The
/ /
normal
i s
a
” v e c t o r ”
and
n o t
a
” p o i n t ” ,
so
i t
i s
n o t
/ / t r a n s l a t e d .
d . n o r m a l
+=
boneToModel . r o t a t e ( s . n o r m a l I n B o n e S p a c e [ j ] )
s . boneWeight [ j ] ;
}
/ /
Make
s u r e
t h e
normal
i s
n o r m a l i z e d
d . n o r m a l . n o r m a l i z e ( ) ;
}
}
Listing 10.7
A simple strategy for skinning vertices
Like all of the code snippets in this topic, the purpose of this code is
to explain principles, not to show how things are optimized in practice. In
reality, the skinning computations shown here are usually done in hardware
in a vertex shader; we'll show how this is done in Section 10.11.5. But
there's plenty more theory to talk about, so let's stay at a high level. As it
turns out, the technique just presented is easy to understand, but there's an
important high-level optimization. In practice, a slightly different technique
is used.
We'll get to the optimization in just a moment, but for now, let's back up
and ask ourselves where the bone space coordinates (the member variables
named posInBoneSpace and normalInBoneSpace in Listing 10.7) came
from in the first place. “That's easy,” you might say, “we just export them
directly from Maya!” But how did Maya determine them? The answer is
they come from the binding pose. The binding pose (sometimes called the
home pose) describes an orientation of the bones in some default position.
When an artist creates a character mesh, he starts by building a mesh
without any bones or skinning data, just like any other model. During this
process, he builds the character posed in the binding pose. Figure 10.35
shows our skinned model in her binding pose, along with the skeleton that
is used to animate her. Remember that bones are really just coordinate
spaces and don't have any actual geometry. The geometry you see exists
only as an aid to visualization
Search WWH ::




Custom Search