XNA MD2 Model Animator (Update)
A long time ago – back in 2007, during the early days of XNA – I created a library to help load and animate MD2 models within the XNA framework.
It was a minor hit at the time, but in its original form the code is very dated and not compatible with XNA 4. I thought it was about time for that to change.
I have simplified the code some what – merging the animator and model in to one class – and cleaned it up a little.
You can grab the updated code here:
It has been tested with a wide range of MD2 models, and seems to work fine. You will need to know what animations the model offers, but if you don’t already know, just debug in to the class; it loads them all in to a dictionary.
Using it is fairly simple, but here is a rough guide:
MD2Model model = new MD2Model(); model.LoadFromFile(@"Content\model.md2"); model.Position = new Vector3(0, 0, 0); model.Scale = 0.25f; model.Rotation = 0.0f; model.CurrentAnimation = "stand"; effect.Texture = Content.Load<Texture2D>("model-texture"); effect.World = model.WorldMatrix; GraphicsDevice.DrawUserPrimitives<VertexPositionTexture>(PrimitiveType.TriangleList, model.GetVertexBuffer(gameTime), 0, model.TriangleCount);
If you are interested, the original can still be found on SourceForge, but I warn you the code is quite dated.