Monthly Archives: May 2012

Animation System – Import Animated characters from 3DSMax & Implement various Animation Techniques

One of the last things remaining in completion of Phase 1 of my Collision Detection System is that of Character Models and Animated Character Models imported from external 3d packages like 3Ds Max, blender etc. So i went in to check my existing animation system first and found i need to update it because of slow performance, little messy code and also Indexed Skinning was buggy.

So i already had my character loading and animation system working. I am using X files format to import stuff. Before that i coded loader for .OBJ also but .OBJ format was very limiting compared to X Files. There are other formats out there like FBX, Collada, etc which are arguably better than X files but since I am working with DirectX 9 i can use some D3DX helper interfaces and functions to speed up the process.

Well if just want to load a static model mesh from X file without its hierarchy or anything else its just a function call. But if we want to load the model properly conserving its hierarchy, bones, texture & material information, etc. It requires some considerable work. Also if we are using our own Mesh Classes instead of default D3DXMESH interface it again increases the amount of work required. But still D3DX makes process a lot quicker compared to work required in implementing loaders for other formats.

So as i mentioned above i already had my character loading and animation system working but it contained a mix code to support both fixed function and programmable pipeline modes of my engine. Fixed Function pipeline specific code creates alot of extra checking for caps here and there making code little dirty. Like if we are implementing NonIndexed Skinning we have to check MaxVertexBlend available on device and then we have to check same for mesh of model & may have to modify to fit it into limits, etc.

Also as i was working on Collision Detection i removed Fixed Function Pipeline code from other parts of the engine to make it only Shader Based. So this is the last area left with fixed function code that i wanted to eliminate.

So here’s what i got in animation system already before –

  • Software Skinning working both in Fixed Function and Shader Based code paths.
  • Non Indexed Skinning working in Fixed Function path.
  • Indexed Skinning in Shader Based code path but it was buggy.
  • Also Animation without bones was working in both modes.
  • Code was little messy because of 2 code paths and specially because of many checks in Fixed Function Path.
  • Fixed Function Code was eliminated from other parts of the engine already as a process of making it completely shader based.

So I dumped the whole thing except few helper functions and some function declaration for loading & Initializations. For reference I used couple of Samples that come with DirectX SDK –

  • SkinnedMesh
  • MultiAnimation

Current Status of new Model Loading and Animation System

As of now i have completed the new Animation system which is much cleaner faster and compact (because all those caps checking and work around need for fixed function pipeline has been removed). So from user perspective i got where it was before but in better optimized way and it got some more new features now. Here’s a list of things i have in the new system –

  • Animation of Meshes / objects without bones.
  • Software Skinning
  • Indexed Skinning (Yes its working now)
  • Debug Rendering of Bones
  • Way to share same Animation Controller between multiple objects for Multiple animated characters.
  • Loading Textures from XFiles
  • Loading Effects from XFiles
  • Mesh is optimized at loading time
  • Different meshes can share same resources. If we load same character multiple times or couple of different model sharing same texture or effect , all those resources will be allocated once and will be shared.
  • A way to render Parts of models having same materials at once. Kind of high level batching. Made it to be a part of whole scene level batching later on.

Things that are removed –

  • NonIndexed Skinning (This technique is kind of useless when we are doing skinning on GPU with shaders).
  • Removed all finxed function Code.

Here are some screenshots –

(Note :- Skeleton Structure has been outlines in white. Bones are represented by white lines and white spheres represent the joints.)

Performence Comparision Between OLD and New Animation System

OLD Code at 165 FPS

Same model with new Animation Code at 600 FPS (even with debug rendering of bones in form of lines and spheres)

(Note : – These comparision screenshots have been taken using Software Skinning technique as it was the only common technique being used in old and new animation system. Shader based Indexed Skinning Mode in new Animation system is even faster.)

So the new animation system is not only shader based and cleaner , its much more optimized than the earlier.