Graphics Reference
In-Depth Information
// Retrieve and apply parent bone transform
var parentTransform =
skinMatrices.Bones[bone.ParentIndex];
skinMatrices.Bones[i] = (skinMatrices.Bones[i] *
parentTransform);
}
}
If the mesh's bones do not match the previous assumptions, then the
rendered mesh may end up looking strange in the final render. See the
screenshot in the How it works… section that shows the result of using
invalid skin transforms.
3.
Then, we convert the transform from bind pose space into bone space by using
the inverse of the bind pose for the bone loaded with the mesh.
// Change the bone transform from rest pose space into bone space
// (using the inverse of the bind/rest pose)
for (var i = 0; i < mesh.Bones.Count; i++)
{
skinMatrices.Bones[i] =
Matrix.Transpose(mesh.Bones[i].InvBindPose *
skinMatrices.Bones[i]);
}
// TODO: Check need to loop animation here
4.
Finally, we must update D3DApp.Run so that we are loading the correct mesh and
passing in the armature buffer when rendering. Instead of limiting the rendering
to only the first mesh found in the loaded CMO file, we will instead create a mesh
renderer for each mesh.
5.
Change the initialization of the mesh renderer to the following code:
// Create and initialize the mesh renderers
var loadedMesh = Common.Mesh.LoadFromFile(" Character.cmo ");
List<MeshRenderer> meshes = new List<MeshRenderer>();
meshes.AddRange((from mesh in loadedMesh
select ToDispose(new MeshRenderer(mesh))));
meshes.ForEach(m => m.Initialize(this));
var meshWorld = Matrix.Identity;
6.
Replace the rendering of the mesh within the render loop with:
foreach (var m in meshes)
{
... update perObjectBuffer
 
Search WWH ::




Custom Search