Graphics Reference
In-Depth Information
3.
Within the MeshRenderer.DoRender method, we will now calculate the skin
transforms for each of the bones, and then update the armature constant buffer.
Let's add this code just before the existing material loop.
// Calculate skin matrices for each bone
ConstantBuffers.PerArmature skinMatrices = new ConstantBuffers.
PerArmature();
if (mesh.Bones != null)
{
... Calculate skin matrices
}
// Update constant buffer with skin matrices of each bone
context.UpdateSubresource(skinMatrices.Bones,
PerArmatureBuffer);
// Draw sub-meshes grouped by material
for (var mIndx = 0; mIndx < mesh.Materials.Count; mIndx++)
...
Within the previous if statement, we will perform the following operations:
1.
First, we load the bone's local transform (which is currently in the bone's local
bind pose/rest pose space) using the following code snippet:
// Retrieve each bone's local transform
for (var i = 0; i < mesh.Bones.Count; i++)
{
skinMatrices.Bones[i] = mesh.Bones[i].BoneLocalTransform;
}
2.
Next, we apply the transform of the parent bone upon each child bone, making the
assumption that each parent bone appears before its children in the list of bones.
// TODO: Load bone transforms from animation frames here
// Apply parent bone transforms.
// We assume here that the first bone has no parent
// and that each parent bone appears before children
for (var i = 1; i < mesh.Bones.Count; i++)
{
var bone = mesh.Bones[i];
// ParentIndex == -1 means this is a root bone
if (bone.ParentIndex > -1)
{
 
Search WWH ::




Custom Search