Graphics Reference
In-Depth Information
Getting ready
We can apply this recipe to any of our Direct3D applications. It is assumed that a class
descending from the
D3DApplicationBase
abstract class is being used, the C# vertex
structure is contained within the
Vertex
structure, and the C# structures for the constant
buffers are defined in
ConstantBuffers.cs
.
How to do it…
We will start by updating our C# vertex structure. So go ahead and open the
Vertex.cs
file for editing.
1. Update the member fields of the
Vertex
class to include a new property that
will store the skinning information for the vertex.
public Vector3 Position;
public Vector3 Normal;
public Color Color;
public Vector2 UV;
public Common.Mesh.SkinningVertex Skin;
2.
The
SkinningVertex
structure is based upon the internal format of a CMO
file, and it is included within the
Common.Mesh
class. For completeness, the
SkinningVertex
structure is shown in the following code snippet:
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct SkinningVertex
{
public uint BoneIndex0;
public uint BoneIndex1;
public uint BoneIndex2;
public uint BoneIndex3;
public float BoneWeight0;
public float BoneWeight1;
public float BoneWeight2;
public float BoneWeight3;
}
A CMO file supports up to four bone indices (unsigned integers)
and four bone weights (floats) that together add up to 1.0. Also,
four bone indices and weights fit nicely within a 4-component
HLSL such as
uint4
and
float4
respectively.