Upcoming Events
Unite 2010
11/10 - 11/12 @ Montréal, Canada

GDC China
12/5 - 12/7 @ Shanghai, China

Asia Game Show 2010
12/24 - 12/27  

GDC 2011
2/28 - 3/4 @ San Francisco, CA

More events...
Quick Stats
84 people currently visiting GDNet.
2406 articles in the reference section.

Help us fight cancer!
Join SETI Team GDNet!
Link to us Events 4 Gamers
Intel sponsors gamedev.net search:

The Implementation

Now we're ready to start writing our code for implementing skin meshes. The most important part in the implementation is the design. The following figure shows the design of our code:

The figure doesn't show all the members of the classes, it shows only the important ones. As it's shown in the figure, the classes CMeshNode and CFrameNode are both derived from CObject. The purpose of CObject is to provide the link tree mechanism; any object derived from CObject will have the abilities to be linked into a link tree. CFrameNode is the building element of our scene hierarchy and CMeshNode holds the mesh itself. CMeshNode is contained inside CFrameNode, which is contained inside CSkinMesh. The whole scene starts in the CSkinMesh because it holds the root frame. All the operations related to skin meshes will be initiated in the CSkinMesh class which in turn will pass control to the hierarchy as required, hence, the main program will deal only with CSkinMesh; CFrameNode and CMeshNode will be reached only by CSkinMesh.

The following algorithms show how the scene is built from the X file:

CSkinMesh::Create()
Begin
  Initialize X file API
  Register D3DRM templates
  Open the X file
  For every top level template in the X file
  Begin
    Retrieve the X file data object
    Pass the data object to RootFrame.Load
  End 
  Link the bones to the skin mesh(es)
End

CFrameNode::Load()
Begin
  Check the type of the data object
  If the type is Mesh
  Begin
    Create new CMeshNode object
    Attach the new object to the frame
    Pass the data object to CMeshNode::Create of the new mesh
  End
  Else if type is FrameTransformationMatrix
    Load the transformation matrix
  Else if type is Frame
  Begin
    Create new CFrameNode object
    Attach the new object to this frame
    Set the name of the child frame to the name of the template
    For every child template of the current
    Begin
      Retrieve the X file data object
      Pass it to newframe.Load
    End
  End
End

CMeshNode::Create()
Begin
  Set the name of the object to the name of the template
  Load the skin mesh
  Generate blended mesh from this skin mesh object
  Load materials
End

After building the skin mesh, we can start rendering it. The rendering operation will consist of two phases. During the first phase, the world matrix of all the bones is computed (via matrix multiplication) and stored in the CMeshNode object. During the second phase, the skin mesh will be rendered. The following algorithms show this operation:

CSkinMesh::Render()
Begin
  Calculate the world matrix of all the frames
  Call CMeshNode::Render of all mesh nodes in the hierarchy
End

CMeshNode::Render
Begin
  Enable vertex blending
  For every subset in the skin mesh
  Begin
    Set the bones' transformation matrices to the device
    Set the material
    Render
  End
  Set vertex blending back to disabled 
End




Animation

Contents
  Overview of Skin Meshes
  Skin Meshes and DirectX 8
  The Implementation
  Animation

  Source code
  Printable version
  Discuss this article