Today's project shows off using Blender, a free open source 3D design utility, and XNA. Two great tastes that taste great together...
There are some good examples around that show how to make animations in a 3D package and play them back in XNA, but what if you want your animations to be more than standard 'walk', 'run', 'jump', etc.? What if you want your 3D model to interact with its 3D environment? Well, then you need to be able to animate single parts of your 3D model through manipulating the model with your code. This tutorial attempts to show you how to develop a simple 3D Model using Blender, put in some armature bones, and finally how to manipulate them in XNA using C#.
First, what I hope to do here is to show you how to:
- Generate a simple Mesh in Blender (a tube)
- Add a Skin to the Mesh using UV unwrapping
- Add Armatures (Bones) to the Mesh
- Tell the Mesh how to deform when the Armatures/Bones move
- Export the Mesh, Armatures, and Skin in a format that XNA can use
- Bring the Model into XNA with a custom content pipeline
- Through code, manipulate the Mesh through moving the Armatures
- Step 1: Create our Cylinder
- Step 2: Add skin to our Mesh using UV unwrapping on our tube
- Step 3: Subdivide our cylinder
- Step 4: Create our Bones
- Step 5: Bind your Cylinder to your Bones
- Step 6: Play with dem Bones!
- Step 7: Export to XNA
So we now have a Model that we should be able to use in XNA. To get the Model into our game, we need to import it through the content pipeline. The content pipeline takes our content and normalises it so that it appears to our game as standard structured objects that we can use in our game. I'm basing the XNA part of this project on the sample provided by MS. The skinned model sample uses an existing model that has a built-in animation (walk) that the code runs. While this is great, I want to demonstrate how you might manipulate one joint on its own rather than run a pre-defined animation (incidentally, if you use the same code as I'm demonstrating with the 'dude' model, you can get the 'dude' to do so very unlikely gymnastics!).
The Skinned model sample loads it's 'dude.fdx' model through a custom content pipeline. We are going to make some modifications to the pipeline so that it doesn't load the animations from our 'tube' model because we don't have any. To do this, open the Skinned Model solution, go to the SkinnedModelPipeline project, and remove the methods
ProcessAnimations(both) and comment out the initialisation of the animation's dictionary.
If you're interested in using XNA with 3D models from a tool like Blender, this story should be right up your alley...
Comments have been closed since this content was published more than 30 days ago, but if you'd like to send us feedback you can Contact Us.