I have a model that I made in Blender that has individual meshes in it. When I put it in an Xna project and try to move the model via Matrix translation, all the individual meshes go in seperate directions. My code basicly updates each mesh individually. Is there better code i should use to make the model's meshes move together?
If you call this:
private void DrawModel(Model model, Matrix worldMatrix)
{
//Matrix array for number of bones
Matrix[] modelTransformations = new Matrix[model.Bones.Count];
//Put bones into matrix array
model.CopyAbsoluteBoneTransformsTo(modelTransformations);
//for every model
foreach (ModelMesh mesh in model.Meshes)
{
foreach (BasicEffect effect in mesh.Effects)
{
//Add default lighting
effect.EnableDefaultLighting();
//Set default postion
effect.World = modelTransformations[mesh.ParentBone.Index] * worldMatrix;
//Set view
effect.View = camera.viewMatrix;
//Set projection
effect.Projection = camera.projectionMatrix;
}
//Draw Model
mesh.Draw();
}
}
And then translate the world matrix that you put in like this:
modelWorld *= Matrix.CreateTranslation(XDir, YDir, ZDir);
You should have no problems. At least, that's how I do it.