KiloWatt Animation 20081128 / 20100307

jwatte's picture

This is the fourth release of the KiloWatt Animation library, as of 2011-02-13. It is intended as a companion to the kW X-port 3ds Max X file exporter, to be used with Microsoft XNA Game Studio. This release is for version 4.0 for Windows and Xbox 360. Sorry, Windows Phone 7 doesn't support custom shaders. It might be possible to update the processor to use the built-in skinned mesh shader -- keep in touch for future possibilities!

Click here to download.

The most important feature update is the animation processor, which now will remove sequences of identical keyframes from the end of an animation, to work around the "one second minimum length" bug. Yay! There may also be a working octree-based triangle mesh collider processor included, but if so, it's totally not a supported part of kW Animation (it's still released under the same license).

The KiloWatt Animation Library is different from the XNA Skinning sample code in several ways, including:

  • KiloWatt Animation stores animation keyframes as position, rotation and scale (for a total of 10 floats), instead of the full matrix used by the Animation Components.
  • KiloWatt Animation removes unnecessary keyframes (down to a tolerance that you can specify), for a usually quite significant savings in file size.
  • KiloWatt Animation does interpolation between animation keyframes using quaternions, which means that slow-motion and varispeed playback will still look smooth.
  • KiloWatt Animation supports composition (blending) of animations to generate the final output pose for a given Model.
  • KiloWatt Animation replaces the Effect used for your Model only when you tell it to.
  • KiloWatt Animation does not make any specific demands of your geometry; you can (and should) use it to animate rigid objects such as windmills, catapults etc. in addition to skinned meshes.

Release 2011-02-12 is updated for XNA 4.0, and the projects are re-built for Visual Studio 2010.

Find more documentation in the download, and please let me know what works for you and what doesn't. Note, however, that this is a power tool for programmers who understand 3D animation; it is not a step-by-step tutorial on the basics of what skinning, skeletons or animation blending are.

AttachmentSize
KiloWatt.Animation.zip4.44 MB

Comments

Common shaders

Hrm, I'm having some trouble with shader file exports. This is actually a kwExport-problem, but since that site is more or less down this seems to best spot to comment.

I want to store all my model shaders in a common location, Content\Shaders. This seems impossible with the newest version of the exporter since it always copies the shaders to the export location and directs the model to use those shaders. I guess I could simply put all models in the same location and thus avoid the problem, but I'd prefer not to since it's a cluttery way to do it and I'm automatically adding models and setting properties (i.e. ForceSkinnedShader for all models in the ModelsSkinned dir) depending on where they're found.

Any workarounds for this? How do you guys usually structure your content?

Great library!

Man, I looked everywhere for a model loader that supported all my requirements. Thanks for your work on this!

/Olle

A question for the author.

Brilliant library. Been using the regular skinned mesh one from apphubs but it's failed on my newest character so this has saved my life. Could I ask how one would go about controlling the bone positions programmatically? I'm intent on writing an animation editor in the near future so any pointers would save me a lot of reverse engineering. Thanks.

jwatte's picture

The bone positions are copied

The bone positions are copied into an array of bone matrices, which are then set as a parameter to the shader. You can change the values of those matrices to "programatically" update the pose of the skeleton.

Problem on Rendering other Objects

Hi!

First of all, great job for the libraries!

I'm building a game engine with your animaition component, and it works well so far in my project. Unfortunately, the ModelDraw objects can't work with my Skybox. The Skybox is rendered firstly, it work nice itself. But, as soon as ModelDraw.SceneDraw() or ModelDraw.SceneDrawTransparent() executed, the skybox just disappear.

I found that a ModelDraw must use ModelDraw.Attatch() to connect with the IScene, otherwise, it can't be rendered correctly. Is that leads to the problem? How can I fix it?

Thanks!:-)

jwatte's picture

I think you should debug your

I think you should debug your problem with PIX for Windows. My guess is that the ModelDraw changes some state, and your skybox does not change that state back before it draws during the next frame.

Animation Doesn't Play?

Hi, thanks for the great projects!
I'm trying to animate my model, I've gotten her to show up in the AnimationViewer, but when I press the } key to go to the next animation, the text at the bottom changes to show the anim name, but my model doesn't move. Anyone have a solution to this, or a suggestion for where to start debugging?
If it helps, my model also looks ugly b/c I didn't give her any effects, would that be a problem? Is there a way to just use BasicEffect?
I really appreciate any help!

jwatte's picture

If the animation is skinned,

If the animation is skinned, the it will need a skinned effect to actually show movement. If the model has a bunch of rigid elements, tied to different individual bones, then it should animate even without an effect.

How to tell if model is off-camera?

Hi, I wanted to see if my model works with your library, but I'm not seeing it get drawn.
All I did was take your sample project (KiloWatt solution) and added my model into the modelViewer content w/ the correct processor. When I run it, I see all the correct info about my model in text at the bottom, but can't see the model. I think she may be off camera, but how can I test this theory?
I've tried scaling her to various different sizes and looking around using the camera controls, but I need a more precise way to tell. Is there a way to see the world space location of her so I can look there and know for sure? Has anyone encountered other cases similar to this?
I appreciate any help very much!

jwatte's picture

In these kinds of cases, what

In these kinds of cases, what I generally end up doing is capturing a frame in PIX for Windows, and stepping through it to see where the geometry is being rendered and transformed.

Hi man, Just to let you know

Hi man,

Just to let you know I tested your code with a 3ds max object that has a bunch of sub objects in it.

One of them is animated.

The animation worked, but the relative position of all the sub objects was wrong so it all ended up as a huge blob.

I guess your content importer is trashing the matrices.

Easy work around though, I just split my model into two, one static and one animated.

Cheers

Stainless

jwatte's picture

Thanks for the feedback! You

Thanks for the feedback!

You have to extract the bone matrices from the Model you've imported, and explicitly set those bone matrices on the effects when drawing each individual piece, or all the pieces will be drawn at the same offset.

The animation content processor just reads the data imported by XNA, just like the regular content processor; it just adds the animation information; so if the object works with the regular pipeline, it should work with the animation pipeline. If you can isolate the problem a little deeper, that would be useful.

XNA 4.0

Hello,

I'm trying to put out an update for a game published with KiloWatt animation under XNA 3.0. Since upgrading to 4.0, I'm getting the following error at runtime when trying to load the model content:

"Cannot deserialize KiloWatt.Base.Animation.Animation.Tracks because it is both null and read-only."

I've noticed that the compiled version of the model is currently about half as large (320 KB now vs. 654 KB when compiled under 3.0). Debugging the AnimationProcessor has been difficult so far, so I can't tell you exactly what's missing.

Any help or direction would be appreciated. Thank you!

EDIT:

I actually figured it out. It appears that the project upgrade routines failed to bring over AnimationWriter.cs (and apparently no compiler errors are given if it's missing). I added it back in and all is right with the world again. The lesson here is one we should all know already...don't trust Microsoft! :-)

jwatte's picture

Thanks for letting me (and

Thanks for letting me (and all readers) know!

XNA 4.0, the patch, and my progress.

Hey,

In September I ported your library to XNA 4.0 for the use in a project that I'm starting full time development now. I had the application up and running a while ago, and just recently wrote a couple wrapper classes to help work KWA into my framework. I remembered seeing a skip in the run animation of the archer asset packaged with the animation viewer, and didn't realize it was because of the one second animation limitation, until I just made my own run animation that was exactly one second.

So, I decided to come back here and read your post again, and somehow I managed to miss the fact that you posted a patch ages ago. I remembered seeing it when I first downloaded KWA, but I figured for some reason that that was for a previous version. I just sat down with winMerge and managed to come out of the ordeal with only about 6 or 7 errors, even with the slightly different code for XNA 4.0. I got them all solved, and building just fine, but now I'm getting crashes for a previously working model.

I crash in Animation.cs on AnimationTrackDictionary Read(ContentReader input, AnimationTrackDictionary existingInstance) the crash is a ArgumentException telling me that the existingInstance dictionary has the same key added already. I trap for that error, then it crashes when i == 9 (in a 40 some odd bone model) on input.ReadObject, simply telling me "Error loading " with a ContentLoadException.

I've been poking around with a couple ideas. I find this very curious, and I'm thinking its possible that its just my content project acting strange (I have 4 of them in a 14 project solution) so I'll keep looking into that and debugging; however if you have any insight you can offer me, I'm all ears.

Thanks for the great library, and thanks for your time. Cheers.

ragdoll

Hi
for about two weeks i'm trying to implement ragdoll using kilowatt and i still got nothing :( i have a simple question: let's say i have a capsule model with world matrix which i can manipulate (in world space) , and i want to apply its position to my skinned model arm, how to do this? in theory i think i should trasform bone to world space, aplly transformation and transform back to bone space, am i right?
for example:
wp = matrices_[inverseBindPose_[36].Index] * World; // this is my bone world space
wp*=capsuleWorld;
model_.Bones["Bip01_Arm"].Transform = ???

two questions

1. how can i manipulate specific bones scale (for example to make my character's head bigger), and bones transform to connect them to ragdoll?
2. how can i obtain mesh vertices list in current frame?

TIA
Przemek

jwatte's picture

You get the position of a

You get the position of a specific bone simply by looking at the matrix in the pose for that bone (each bone has an index).
The vertex positions are calculated by the vertex shader, so they are not available on the CPU. If you want to know exactly where the vertices will be on the CPU, you have to implement vertex skinning on the CPU, and do the calculations yourself.

AnimationViewer Issues

I'm also using the updated version of the KiloWatt animation system which seems to break the code in the AnimationViewer. I re-created the project successfully and got it running in XNA 3.1, but I'm also having the same issues that anjdreas is having.

I instinctually changed
loadedModel_.AnimationInstance = blender_;
to:
loadedModel_.CurrentAnimation = blender_;

but I'm not sure what to do for the following two lines:
loadedModel_.SceneDraw(dd);
loadedModel_.SceneDrawTransparent(dd);

I also tried 0 and 1 as parameters, but it seems as though it's expecting to be called from a shader. Is there an updated / fixed version of the AnimationViewer or does anyone actually know how to resolve this issue? Any help would be greatly appreciated!

anjdreas's picture

AnimationViewer in 20081128 / 20100307 not working

There are two issues when trying to compile and run the AnimationViewer tool included in the latest Animation library (20081128 / 20100307). I did apply the patch as instructed to.

1) Getting it to compile.
First, the AnimationViewer project is a GS 3.0 project and must be upgraded to GS 3.1.
Next, there are two compile errors (as commented in http://www.enchantedage.com/node/203#comment-545) that must be fixed in AnimationViewer.cs.

2) No model is rendered.
After fixing the compile errors, no models show up. Only the background color is rendered. Selecting different models in the list does not help either. This may be related to the compile errors, where I "fixed" a missing argument in two SceneDraw... methods by setting it to zero.

loadedModel_.SceneDraw(dd, 0);
loadedModel_.SceneDrawTransparent(dd, 0);

I could not figure out what argument it should take, and trying a set of plausible arguments (0,1,2,3,4) did not help.

Have I missed out on something, or is the current available AnimationViewer broken?
It seems its code is outdated since methods it is using have been refactored and since its project had an older GS version.

Edit: By NOT applying the 20100307 patch, the AnimationViewer demo works perfectly.

If God wanted us to be brave, why did he give us legs?

AnimationInstance Problem

I have a problem with loading the model.

Error message:
Error 1
'KiloWatt.Base.Animation.ModelDraw' does not contain a definition for 'AnimationInstance_' and no extension method 'AnimationInstance_' accepting a first argument of type 'KiloWatt.Base.Animation.ModelDraw' could be found (are you missing a using directive or an assembly reference?)

//  create a blender that can compose the animations for transition
blender_ = new AnimationBlender(loadedModel_.Model, loadedModel_.Name);
loadedModel_.AnimationInstance = blender_;

I didn`t change anything in the AnimationViewer.cs. If i comment the line with the AniamtionInstance the program starts and i can choose the model, but it will not be displayed.

maybe you know that problem.
thx anyway,
HU

It looks as if translations

It looks as if translations are being applied twice, or scale is not appropriately applied to the translations....
.. This can happen if the bones or mesh contain scale, and/or if the bones or mesh are not properly "reset transform" before attaching to the skin pose.

jwatte's picture

That's a good hint, btw.

That's a good hint, btw. Resetting transform of all bones and the skin before attaching the skin is always a very good idea when creating skinned objects.

Can't view model in AnimationViewer

I've encountered a problem and would like some help please. These are the steps I have taken when trying to create a view a model in the AnimationViewer project.

- I create a simple box in 3DS Max 2011 x64. (The dimensions are 1x1x1 meters)
- I then export the model using the kW Export Tool. (The mesh is right handed, y is up and the winding order is correct)
- I load the model in DirectX Viewer and it displays the model.
- I add the model to the AnimationViewer project and process it with the AnimationProcessor.

The model's name is displayed (as are the names of any animations I decide to export) but the model can't be seen from any distance when selected.

Why would the model not be displayed?

Have you fixed this as I am

Have you fixed this as I am running into the same problem?

jwatte's picture

If you run the animation

If you run the animation viewer using PIX for Windows, and capture all draw calls for a full frame, what does it say about the display of the model?

Simple cube draw call: [Pre

Simple cube draw call:

[Pre Vertex]

VTX	IDX	Position[0]	Position[1]	Position[2]	Position[3]	Diffuse	Normal[0]	Normal[1]	Normal[2]	TexCoord0[0]	TexCoord0[1]
0	0	-19.685	39.37	19.685	1	D3DCOLOR_ARGB(0xff,0xff,0xff,0xff)	-1	0	0	1	0
1	1	-19.685	0	-19.685	1	D3DCOLOR_ARGB(0xff,0xff,0xff,0xff)	-1	0	0	0	1
2	2	-19.685	39.37	-19.685	1	D3DCOLOR_ARGB(0xff,0xff,0xff,0xff)	-1	0	0	0	0

[Post Vertex]

Prim	VTX	IDX	Position[0]	Position[1]	Position[2]	Position[3]	Diffuse	Specular
0	0	0	0	0	0	0	D3DCOLOR_ARGB(0xff,0xe4,0x99,0xb8)	D3DCOLOR_ARGB(0x00,0x00,0x00,0x00)
0	1	1	0	0	0	0	D3DCOLOR_ARGB(0xff,0xe4,0x99,0xb8)	D3DCOLOR_ARGB(0x00,0x00,0x00,0x00)
0	2	2	0	0	0	0	D3DCOLOR_ARGB(0xff,0xe4,0x99,0xb8)	D3DCOLOR_ARGB(0x00,0x00,0x00,0x00)

Why would the position be set to 0,0,0 for all vertices?

jwatte's picture

This means the vertex shader

This means the vertex shader is smashing the vertices. Either the data for the vertex shader is wrong (say, the wrong or empty matrices are sent in), or the vertex shader itself has a bug.

regarding archer model

Hi, I want to ask if I could have the archer model in .3ds for reference purposes. I just want to compare with what I have on my end. Thx!

jwatte's picture

Sorry, no -- my license for

Sorry, no -- my license for the model does not allow re-distribution of the source art.

animation processor missing?

After I updated the files, I found myself having to recreate a new animation viewer project. But this I checked that the animation processor seems to be missing from the drop down menu.

jwatte's picture

The Content project is

The Content project is probably missing the reference to the Pipeline project that defines the animation processor.

MaxBones

HI
My project has a model with more than 72 bones.

Is this a hard limit or is it possible to increase it by recompiling the source?

Will this work? If not, do you have any recommendations on a good way to do this?

Thanks!
Pragya

jwatte's picture

The 72 bones come from the

The 72 bones come from the limitation on the number of vertex shader constants, which limits how large a pose you can send into a vertex shader.

You can push it up to about 110 by sending quaternion and offset (and no scale), and convert from quaternion to matrix in the shader. That will slow down the shader, though.

An alternative is to build your object as several separate meshes, each of which is less than 72 bones. That's what I would do, if I really, truly needed more than 72 bones for a single object.

Changing Pixel Shaders?

Is there a way to change Pixel shaders using kW... i haven't used it yet?

i just want to give different effects to the skinned models

jwatte's picture

kW Animation uses whatever

kW Animation uses whatever effect file you tell it to use (or already use in your imported model).
The example code uses a specific set of binding parameter names, but you can use your own if you want -- or just take the example shader and change it.

Max bones

HI
My project has characters with more than 72 bones

Is this a hard limit or is it possible to increase it by recompiling the source?
If not, do you have any recommendations on a good way to do this?

Thanks!
Pragya

Can't Draw My Model ?

First of all, Thanks for Great library!

i'm tryin to draw archer (same archer used in viewer) i copied all of the needed materials and models to my content folder, then try to draw it,

My Code: http://pastebin.org/321873

Where i'm doing wrong ?

jwatte's picture

I can't really debug your

I can't really debug your code for you :-)
I suggest you apply the normal debugging techniques:
- breakpoint and step through each line of drawing, verifying that it does what you think it should do
- capture a frame in PIX for Windows, and step through the drawing calls, verifying the device state for each call
- starting with something you know works (the animation viewer, say), and then mutate it one small step at a time towards what your current code does until it stops working -- then you know what broke

dirtysteve's picture

Animation control

How do I tie an animation to a specific key-press, ie. press Space, play punch animation.
I'd like to know how to load animations by name, is it anything like this code I used in an Ox Engine project ?

 else if (keyboardState.IsKeyDown(Keys.Space))           
 {
   Component.AnimationController.PlayClip(Component.SkinnedModel.AnimationClips["Punch"]);                                             
 }

Animation control

How do I tie an animation to a specific key-press, ie. press Space, play punch animation.
I'd like to know how to load animations by name, is it anything like this code I used in an Ox Engine project ?

 else if (keyboardState.IsKeyDown(Keys.Space))           
 {
   Component.AnimationController.PlayClip(Component.SkinnedModel.AnimationClips["Punch"]);                                             
 }

Quickstart

I've been picking apart the Model Viewer, trying to understand kilowatt. I was wondering, what's the bare minimum of code needed to display my model and it's animations?

Can I just do something like ,

DrawDetails dd = drawDetails_;
Model myModel = modelDraw("myModel","myModel");
myModel.SceneDraw(dd);
myModel.SceneDrawTransparent(dd); 

If anyone has simple code they can share, I would appreciate it.
I prefer to do this than use the paths like the viewer, I'm finding it tough to comprehend the code used in the viewer.

Also when I plugged my model into the viewer, I got some weird extra animations, possibly leftovers from Blender, can I use the Exclude Animations drop down to keep them from appearing?

I posted a similar comment earlier, but it didn't appear, sorry for the double post if it does.

jwatte's picture

One of the problems is that

One of the problems is that animation is something that is fairly complex. While it might be possible to create a "just do it" wrapper that drew one model with one animation, that would be totally useless as soon as you wanted to do anything real, which includes blending animations, easing in/out, etc. Thus, the sample and library do it "for real" rather than "for simple."

dirtysteve's picture

Fair Enough

What about my other question(posted above), how would I play the animations by name, rather than stepping through a list? Do I use an AnimationSet, an AnimationInstance, or do I need both?
I assume AnimationSet can be used to load all the animations contained in my .fbx, and AnimationInstance can be used refer to a specific animation by name.

Quickstart

I've been picking at the Animation Viewer, trying to get my head around kilowatt. Does anyone have any simpler code? I just want to start with the minimum required to load my model and play its animations.
I like to declare my models individually, rather than use the folder path like the viewer.

Also when I tested my model in the viewer, I got some strange animations, probably left over from Blender. How do I use the exclude animations field? (I assume that's what it's for)

Changing a model's position?

Hey there, Im Peter.

This might be a weird question, but how can i change the position of an animated model? I'm looking through the base class for days now and still cant find it. Ive tried to manipulate the matrices in the drawdetails class, but it was a failure... :)

Maybe i misunderstood the whole thing from the basics, but so far i created a new class for myself, with the blender, animationset and other things, including drawdetails for each instance. I thought Ill have my settings for each character in the game, but i couldnt figure out wheres the data for the drawing coordinates.

Am I doing it wrong from the start? How should I fix it?

Hope my post isnt a mess... :)

Thank you!
Peter

dirtysteve's picture

Any Luck?

Have you had any luck resolving your problem? What about dd.World in the Draw method? i think that's the position of the model. You could try various multiplications on that to test it.

changing bind pose position or sth

hi

i have animated model of my main hero in game, and it has hit animation
but doing this hit in place (without moving forward) looks bad

so now i have new hit animation in which along with hit (using hand) player is moving forward a little and then a method added to EndReached event sets current animation back to idle animation, but to blend it with model in idle animation this model should have new position (cause witch hit animation my character steps forward)

i hope you understood

TIA
with Regards
Przemek

jwatte's picture

Although there was no

Although there was no question, I'm going to assume you want to know "how do I do this" :-)

You have to extract the motion of the root bone from the animation, and apply it to your character's simulated position instead. This can't be done in the animation library, because the way that position of objects is simulated/updated varies wildly between different engines.

Easiest is to get the Translation of the bone at index 0 each frame, subtract from the value at the previous frame, and simply add that to the position of your object. Then set the Translation to Vector3.Zero before you actually hand the pose to the effect for drawing.

Trouble rendering a simple model

Hello, first of all thank you for making this library and also for being supportive with the people using it.
I'm new using kilowatt library and I have a problem loading a very simple model, its a cylinder with 3 bones a simple bend animation [24 frames], I followed the instructions in the readme file with the source, but I'm getting a not-so-explicit error with :
model = new ModelDraw(Content.Load<Model>("cylinder"), "cylinder");
I get the error
ContentLoadException was unhandled . Error loading "cylinder".
in this line:
AnimationTrack track = input.ReadObject<AnimationTrack>();
I tried to change the export settings in my model to match the ones in the archer example but nothing seems to work (I unchecked the export shaders option, don't know if that is causing the error), that model works fine with the skinned model example from creators club, so I'm out of ideas of whats happening.
It might be a dumb question but I can't figure out the answer :(
Any help is appreciated, if you need some more info or the sample model just let me know!
Thanks in advance!