Posts Tagged ‘c#’
zAnimation – a simple XNA animation library
Before XNA 3.1, there was a bunch of animation frameworks which could to tons of stuff like interpolation between animations and stuff like that. When the 3.1 came out all of these became obsolete – except kw animation which comes with a 3ds max exporter and is great if you’re using max, but I’m using Maya and I needed to write my own animation foundation. zAnimation is a XNA library for animating skinned models exported from Maya. It supports customizable pre-clip interpolation, and per-bone animation. No interpolation between frames or animations yet.
Pre-clip interpolation:
Before a clip is played, the model interpolates over a customizable number of frames to the starting position. It delays an animation a bit but removes jerky transitions between animations.
Per-bone animation:
When defining a clip within the animation, you also define what bones does the clip affect. Based on that you can play an animation that animates all the bones in a model, and easily override the animation on one or more bones to make them move in a different way.
Below I’m listing a couple of things that I encountered while writing zAnimation:
Maya gets all your animation keyframes and exports it in a single take called “Take 001″.
To deal with this I introduced another file (the take definition file) which contains where does a certain animation start and end, and also what bones does it affect.
XNA FBX Importer removes redundant bones.
If a bone has no weights defined on a skin it gets deleted. The same thing happens if the bone doesn’t move (change) in the keyframes. So I introduced 2 special parts of the animation, the “Bind” part and the “Init” part. The bind part acts like a starting transform, and the init part is just there so you don’t forget that you have to animate a bone if you want to have it.
So based on that there are a few rules and limitations to zAnimation:
- smooth binding only
- each bone in each skin has to have some weights, so no root bones with no weights (or it won’t be imported as a bone)
- each bone has to have at least 2 keyframes that are not the same (or it won’t show up in the keyframes at all)
- strictly defined animation timeline:
-at frames 0 and 1 keyframe every bone at its bind pose position. This is the position your animation starts with.
-at frame 3 you should keyframe every bone it any position other than its bind pose. I select all my bones and rotate them in the x-axis about 45 deg.
-at frame 4 you should keyframe your bind pose again.
- after frame 4 animate your model as you wish
- when importing a model create a takes.def file in the same directory as your exported fbx is in the XNA content folders, set its build action to none from Visual Studio
- takes.def file has a specific structure that is line delimited, so the first line should look like this:
Bind, 0, 2, AffectedBone0, AffectedBone1, AffectedBone2
and each line after that should look like this:
AnimationName, StartFrame, EndFrame, AffectedBone0, AffectedBone1, AffectedBone2
here’s an example of a takes file
Bind, 0, 2, root, door Open, 4, 34, door Opened, 34, 36, door Close, 36, 66, door
That’s more or less it. I’ll release it on codeplex in a couple of days. Check it out if you’re a XNA developer working with Maya.
Abandoned: Terrain 3 and Skydome
The diffuse shader is done on the terrain, and I have a system for the texturing. You can now put patches of grass and asphalt anywhere on the map. The amount of grass or asphalt texture on that point is determined by a texture lookup to a texture map which kinda looks like this:
The green pixel determine where the grass pixel are going to be, and the blue ones where the asphalt is going to be. I also passed the grass and the asphalt textures along with their detail textures to the shader, but after drawing that the framerate fell to about 50. So I removed the grass and asphalt detail textures and made them use the normal ground detail, and the framerate rose to 100 again. The terrain diffuse system looks kinda weird at this point because there’s no shadowing so surfaces get lit irregularly, and the skydome is finished. No that’s not atmospheric scattering on the screenshots, I just have a DayColor and NightColor and lerp between those 2 with the sun y position. This looks almost as good at atmospheric scattering and is like 10 times faster. Enjoy the screenshots!
Abandoned: Terrain 2
I had to rewrite the terrain all over again. Twice. The inability to draw mountains was hanging over me like an axe, and this morning it hit me hard. I had to have mountains!
First I was following this great article from Catalin Zima here: http://www.catalinzima.com/?page_id=85, and got the whole terrain rendering from a heightmap on the GPU. Nice. But one drawback to that. It required pixel shaders 3.0. And my game isn’t going to be the next Far Cry, in fact, I’d probably use shaders 3.0 just for the terrain. So as I was free from one axe, another started hanging over my head.
So now I’m using modeled terrains and no axe yet. This works better for lightning and artists (me). I’d post some new pics but I’m too lazy. Tommorow!
I just hope your day was productive as mine was!







