KiloWatt Animation 20081128

jwatte's picture

This is the third release of the KiloWatt Animation library. 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 3.0 for Windows and Xbox 360. Sorry, no Zune support :-)

Click here to download.

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.

New in release 20080703 is full support for skinned meshes, more documentation, and more sample art.

New in release 20081128 is an upgrade to XNA Game Studio version 3.0, and pre-made Xbox 360 projects for those who don't want to do it themselves.

Find more documentation in the download, and please let me know what works for you and what doesn't. This is the third release, and there were no known bugs between second and third release. 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.20081128.zip4.4 MB

Comments

Next Release

Is there another release planned or is KiloWatt Animation 20081128 the final version? Thanks!

~IonDave

I don't "plan" releases. When

I don't "plan" releases. When a few bug fixes accumulate, I build new installers and release them. Also, there may be new releases for new versions of 3ds Max.
Currently, the only annoying outstanding bug is the "one second animation" problem, which I don't have a lot of motivation to fix because I have a work-around in my XNA processor.
Is there anything in particular you're interested in?

No, nothing in particular.

No, nothing in particular. The only reason that I asked was that the latest release is from 2008. I now assume that the functionality is "right where you want it" and that the current version is complete...until changes XNA and/or 3dsmax or .X warrant an update.

Thanks for the response. I look forward to integrating your libraries into our framework.

~Dave

problem with exporting/importing

hi
i'm using latest version of kwxport, max 2010 32 bit and win xp.
when i export my animated model (with kwxport and settings from your screens) and display it in animation viewer it looks like this:

http://img210.imageshack.us/img210/5083/badi.jpg

animations are mess too, what am i doing wrong?

great library btw!

jwatte's picture

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.

Model without animation

I am trying to test the exporter with a very simple object using 3dsMax 2010 64bits.
I created a box and did not assign any material.
I exported the box and checked "export material" and "colors as diffuse" and unchecked
"export animation" and "export shader".
The .x works perfectly using DXViewer, but IF i try to load it in the Project,
it gives me an error:" Model {0} was not processed with the AnimationProcessor."
Doesn't the AnimationViewer support non animated objects, as I thought the Plant was not animated
and it works fine.

jwatte's picture

The animation viewer supports

The animation viewer supports non-animated objects, but they still need to be processed by the animation processor, and have a suitable shader. Basically, that processor should replace the model processor for everything rendered through that system.

Model rendering wrong

I've been trying to move from XNAnimation to the KiloWatt anmation library for a few days now, but I'm having trouble. When I render the model using diffuseonly.fx and SceneDraw() the model renders correctly. When I set the shader to use "+-skinned" the model looks like this: http://fwheel.net/cnk/images/model_wrong.jpg

The model renders correctly in the Animation Viewer, but not in my game. As far as I can tell my code is basically the same. I'm just setting up a DrawDetails object, then using SceneDraw() to draw the model. Is there something stupid I'm missing?

jwatte's picture

If it works in the animation

If it works in the animation viewer, then your game is doing something wrong. Perhaps not deriving or applying the animated pose correctly?

I had the same problem

I had the same problem recently. It took me a while to solve it.
I did not set up my RenderStates properly before drawing. So you can try that.

RenderState.AlphaTestEnable;
RenderState.AlphaFunction;
RenderState.ReferenceAlpha;
RenderState.CullMode;

These renderstates above where the ones that i needed to change.

Model rendering wrong

I've been trying to get the animation library to work for a few days now. I'm using SceneDraw() to render the model without any animations (baby steps), but I can't get it to work with the skinned shader. It looks like this: http://fwheel.net/cnk/images/model_wrong.jpg The model looks perfect when I set the shader to diffuseonly.fx.

Is there something obvious that I'm doing wrong?

Model draws fine but without animation

Hello! I have a couple of problems animating models with kW Animation/xport. I read every related post on this page and the kwxport forum and couldn't find a solution, so here goes:
1. I have an animated character model with some bones and a skin modifier (I have collapsed everything but the skin) and the model.fx effect for the materials, something similar to the example archer model. I export it to .x, specifying the animation start/length and with the export skinning/hidden options checked. I put the .x file into the AnimationViewer content folder, and set the processor to "Animation Processor - KiloWatt". But when I compile the project, the Keyframe.CreateFromMatrix method throws an exception stating "Matrix could not be properly decomposed into TRS keyframe."
2. I try to circumvent the first problem by putting a #define MATRIXFRAMES in Keyframe.cs and AnimationWriters.cs, as this way the place where the exception is thrown is skipped. The AnimationViewer now compiles and the character displays properly but... without animation. (yes, I press "]" to start it)
3. So, to pinpoint the issue, I create in Max a simple cylinder, convert it to an editable poly, rig it with two bones and a skin modifier, animate it to bend and twist in the middle and export it the same way. The cylinder again displays properly but again there is no animation. This time, though, the project compiles without the #define MATRIXFRAMES. So I'm now officially stuck and any help will be greatly appriciated.
But except these nuisances, this seems to be a great library with the blending/compositing features being real ass-savers.
Cheers,
Orlin

jwatte's picture

Here are my guesses as to

Here are my guesses as to what's happening:

1) You have some bone that either introduces mirroring, skew or some other non-Euclidean transform. In general, this is a bad idea in generated models; most animation runtime systems won't work well with that kind of skeleton.

2) For a model to actually animate when rendering, you need to use a shader that applies skinning. In the Archer example, this is done with the "Force Skinned Shader" option being set to "+-skinned" which will make it reference a shader named "model-skinned.fx" (which then needs to actually apply the skinning transform).

3) The bones in that cylinder are good, then :-) For the non-animation, please see 2) above.

Finally!

You were absolutely right! It turns out that you must never ever use the Mirror tool from the Max toolbar to mirror bones as it screws the whole animation. You shouldn't scale the bones once created, either (in fact, the mirror is just a -1 scale). For everyone interested, there is a special bone-specific mirror function from the main menu Animation -> Bone Tools -> Mirror. In that dialog is also the function to scale/transform bones that are already created ("Bone Edit Mode"). See http://www.ogre3d.org/addonforums/viewtopic.php?f=15&t=6103 for more info. I hope nobody else makes my mistake, it took me 3 days to fix everything. Many thanks for your timely response, jwatte!
Cheers,
Orlin

DrawScene Draws half model

Hi!

I got an issue trying to Draw Archer model from the AnimationViwer Example, on Draw Method I´ve got the following:

protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);

if (Modelo != null)
{

... DrawDetails dd definition...
loadedModel.SceneDraw(dd);

loadedModel.SceneDrawTransparent(dd);
}

// draw any components
base.Draw(gameTime);

}

I try to do this in the AnimationViewer Example and appears the same issue, model is partialy drawn.

jwatte's picture

If I understand you

If I understand you correctly, the AnimationViewer works fine as-is, but if you modify the code, then it doesn't work?
My guess is that there is some render state that should be set up, but isn't. Although it could be anything state related -- the pose array, not clearing the Z buffer, etc.
Can you modify it less and see what it is that doesn't work?
Can you track down what is going on using PIX for Windows?

Error on .x models

Hi, I was trying to open others .x files (that I download from TurboSquid) with AnimationViewer to try a simple test

- I added on Content the new files
- I change the animation processor to "Animation Processor - kilowatt" or "Dxt5 Model Processor"

The results are:

- in some cases I've got an error on AnimationProcessor, on :

      Dictionary<string, ModelBoneContent> nameToIndex = new Dictionary<string, ModelBoneContent>();
      foreach (ModelBoneContent mbc in output.Bones)
        nameToIndex.Add(GetBoneName(mbc), mbc);

for "duplicated key"

- in other cases all seems ok, but never is displayed when I select the model on menu.

Where I wrong? or there's something about this lib that I didn't understand?

Thanks!

jwatte's picture

The animation viewer, and the

The animation viewer, and the ModelDraw class that comes with the library, want the models to be teched with an effect that uses a certain set of parameters. You can look in the diffuseonly.fx and diffuseonly-skinned.fx files for examples of what those parameters are. If those parameters are not present, the animation viewer doesn't know how to display and render the model properly (this is a general problem when trying to port shaders between systems).

You can tell the animation processor to force a specific shader onto the model as it's being processed. Try forcing the diffuseonly.fx shader (copy it from the sample content directory), and see if it works better. If not, you'll have to trace through the code that loads and renders models in the debugger, to figure out where it's going wrong, and then fix that part.

Normals

When normals are added to a mesh and we force model.fx on the mesh, is kw writen to make lights react to the normal map or not?
If not how do i do this?
Also hw do i add this function to one of the skined fx files?

jwatte's picture

If you look in the shader,

If you look in the shader, you will see that it already skins and lights normals. In fact, it's almost impossible to export geometry from Max *without* normals.

More fbx help

Ok. I gave the exporter anuva go but it stil doesnt wrk. So, bak t fbx.
Used a standard material instead of an fx and stil nothin. Although xna wik complain od a misin asset if i remove the texture.
I cant get either x or fbx to wrk with this lib. Wel skined mesh and animation wrks gr8. Hence why i wish to use this lib

jwatte's picture

Well, there's not much I can

Well, there's not much I can help you with there. I suggest putting a breakpoint in the drawing function, and tracing through what is being done to draw the model. My first suggestion is to make sure that the bone matrices are correct, even though you're not playing an animation on it.

Fbx help

Hello again
I'm having trouble using this library with my FBX model. Skinning works fine as does the animation. But the model is jet black. Im tryin t use diffuseonly-skinning.fx.
Is there a specific way a model should be set up prior t exporting? Inc materials. I am new to this so as much detail as pos wud be appreciated

jwatte's picture

I really don't know much

I really don't know much about the FBX path, unfortunately. Is the character using a shader in Max, or not? You might want to try without a shader, and see if it works better.
Other than that, I recommend debugging the kW model processor (start a second copy of visual studio and target the first one while it's processing), to see how the textures are found (or not found) while processing.

Anim help

Is the animation of thd archer suposed 2 start when the model loads?
If so mine isnt n i aint changed no code

jwatte's picture

There are controls to select

There are controls to select which animation to play. See the code for more details.

Im new

Im just trying to use this 4 the 1st time and was wonderin that wen u fire up the sample, is the archer suposed t start movin as in mine it doesn't. Oh and the runtime recource doesnt exist.
Regards
Jay

Weird naming error when exporting and short animation problem

I keep getting this kind of error when trying to export with X file exporter - it cant copy the shader file i specify and somehow randomly changes file name to weird stuff... (each time different...)

For example:
Can't open the file C:\Users\Stormiks\Desktop\Content\diffusà for copying.

If i open my X file in visual studio and try to find shader name i tried to specify i find interesting line :

EffectInstance Effect {
"diffus\340\à ";

where "diffus\340\à" should be "diffusexparent.fx"

I can manually correct that line to "diffusexparent.fx", otherwise i got missing asset error when building project...

(XNA 3.1, Windows Vista 32bit, 3dsMax2010)

Also mentioned problem about animations jerking when looping (including included archer run animation)

That sounds like a bug that

That sounds like a bug that was in kw X-port version 1.4.0. I believe I have fixed it in 1.4.1, which you can download from the kW X-port site:
http://www.kwxport.org/download32
If it still happens with the latest version, then please report that as a bug on the kW X-port site.

Also, the short animation stutter problem is a bug in the .X file importer in XNA Game Studio, where it will pad any animation to be at least 1 second long. If you feel this is important, please vote on the Connect issue (which has been open for two years!):
https://connect.microsoft.com/feedback/ViewFeedback.aspx?FeedbackID=283038&SiteID=226

Hey, that path error still

Hey, that path error still seems to be there :) so, you have to edit the path to make it work. It also seems to work when you make the filename shorter.

Can you send me a copy of the

Can you send me a copy of the max file / textures / shaders that cause that problem?
I can't look into it without being able to reproduce it.
Also, what version of Windows, and what version of 3ds Max, are you using?

sure, what mail should I send

sure, what mail should I send it too?
using 3dsmax 2010 and vista home basic 32 bit.

I was going to e-mail you my

I was going to e-mail you my mail address, but you seem to not be registered. Please register with a good e-mail address, and I'll contact you.

ah, I tried to log in but i

ah, I tried to log in but i forgot my password, and your site doesnt seem to want to re send me the password again.

Anyway, it seems the path becomes wrong when the path goes above 50 characters or so. If I assign the shader so that the total size of the name + path is less than 50 (or around there), then it works.
os
btw, I have an additional question. I have a character that I want to move around, and rotate.
And currently I use:
activePlayer.anim.Mod.AnimationInstance.CurrentPose[0].Ori =
Quaternion.CreateFromYawPitchRoll(activePlayer.avatarDirection.Y, 0, 0);

and

activePlayer.anim.Mod.AnimationInstance.CurrentPose[0].Pos = Game1.activePlayer.avatarPosition;

and, the character moves, but uncorrectly. I have a reference sphere which I just set directly to the avatarPosition, and they do not match up. It almost seems like when I set the position ot the currentpose[0].pos, then it's sort of doubled.

So, am I on the right path doing something like above or is there a better way?

Kjetil

If you can let me know your

If you can let me know your registered user name or e-mail address, I can look it up in the database :-)

If I remember correctly, there is a "World" matrix and a set of "Pose" matrices in the drawing code. You're probably better off leaving the "pose" untouched, and only moving the avatar by changing the "World" matrix.

How many animated models can you display with good performance?

I haven't used this library yet, but how many animated models should you be able to produce on the screen without dipping below the 60 FPS mark? Right now I am using XNAnimation, but I haven't really found a way to produce, say 100 animated models effectively without a huge hit in performance. This was mostly in drawing the model and updating the animation. Would this still happen with this library or would you say this is more optimized?

jwatte's picture

I haven't compared the

I haven't compared the library to XNAnimation, so I have no idea as for the answer to your question. I can tell you that, while writing kW Animation, I did have performance in mind, but I have not attempted any major trickery to make it "ultra optimized." Also, kW Animation uses SRT keyframes, not matrix keyframes -- I don't know what XNAnimation uses.

Finally, your question is lacking certain parameters: How many bones per model? How many animations are being blended? Are you cloning animations (the same pose applied to multiple model instances), or running one animation per model? What target hardware: Xbox or PC?

getting any animation to display

Hi there - very interesting site and animation project. Sadly I can't get anything to display. I exported the sample spinning cube that comes with the exporter and then added it to the same project that contains the archer, plant and cube3 models/anims. I asked XNA to import it using the Kilowatt animation import. It doesn't show up anywhere, on any amount of zoom. Perhaps I'm doing something horrible obvious. I can't find the original max file for the archer so I have nothing with which to compare it. I haven't forced shader or skinning shaders in the solution explorer - perhaps I need to set them to something built in to your library - after all a shader must be hidden away in there somewhere or your archer would not display. Its a bit of a head scratcher. I can code a bit in XNA but not shaders - been happy so far using BasicEffect. A hint about what I'm ballsing up would be much appreciated :-)

Cheers,

Robin.

The viewer application

The viewer application assumes that the shader in use follows the conventions of the sample shaders that ship with the library. If you attempt to render geometry imported for BasicEffect with the sample app, it won't work.

I can't re-distribute the Max file for the archer, but you can purchase it at a low cost from 3dbud.com.

cheers for the tip

Bit of a misunderstanding over BasicEffect - I wasn't expecting the built in shader to work - just curious about how I set the x file up for the various shaders in your project. diffuse skinning and metalfx for instance. I exported a model with no animation and forced it to use mtlshader.fx - and it displays, which is a great first step. For anybody having that first step problem I turned off almost every option in the exporter, including tangents and animation - and exported a left handed mesh. This may help anybody using a model imported from Blender. I also used dxt5 model processor for the file in the solution explorer and forced mtlshader.fx. I'll buy that archer and hopefully learn a bit about how to export an animation. I know nothing about Max as I'm used to Blender - it seems wilfully complicated in comparison. Still can't get the cube which is on the kilowatt exporter website to display - perhaps the options are more complicated for animation.

I think it's important that

I think it's important that you understand how bindings between shaders and host applications generally work. There are a set of defined, named parameters that have specified meanings (world transform, diffuse texture, etc). All of those parameters have a given name in the host application, and the shader needs to match. Because each host application renderer generally has different requirements from other games, there's no real standard to these names, so you can't expect to take a shader from one place, and expect it to work in another, except possibly by accident.

If you look in KiloWatt/Base/Graphics/EffectConfig.cs, you will find the names of parameters that the animation viewer is looking for. Hopefully, the names will be self-explanatory as for what the meaning of each of the parameters is. You need to make sure that the shader that you apply to the object, either upon export, or upon processing with the kW model processor, matches those names requested by the application.

Maya Exporter?

I realise the raw stupidity of this request, so I'll apologise now and I resign myself to the answer i know is forthcoming.

Would you ever consider writing that exporter for Maya? I've tried so many and they all miss this, or that, one even openly corrupted our skinning data, another mutilated our uv's, it's a nightmare out there. There is not much love for Maya from the XNA community.

Failing that, possibly another solution.

One of the guys in our team is a Maya MEL programmer and would take a crack at it, but really doesnt know enough about how to export these files. If you have no interest in writing a Maya exporter, do you think we could work together with our MEL scripter to do so? I think it would be super valuable.

BUT, i realise how these things go. I can dream cant i?

However, if we were to just use maya's FBX exporter, which while fickle usually works, can I still use your animation library? How hard would it be, and what would the drawbacks be?

I'd just like to say that reading what your library is capable of is VERY exciting to us for out current project

Dave

jwatte's picture

That is not a stupid request,

That is not a stupid request, but I'm afraid it is futile. While I do have access to Maya at work through the Autodesk developer program, I really know very little about it, and I have no need for a .X exporter for Maya.

There's no reason I know of why FBX wouldn't work with the kW Animation library. The kW Animation library simply works on the data that you import into XNA, whichever way it gets imported. However, I have not tested the FBX path, so there may be unforeseen bugs. At least you do get the source code and can easily track those down, should they occur.

I guess a million dollars might change my priorities, though :-)

Strange draw...

Sorry for my english....
why now I've added the Kilowatt Animation draw work only for animated model, but no more for the others??

//Draw Sky
foreach (ModelMesh mesh in sky.Meshes)
{
foreach (BasicEffect effect in mesh.Effects)
{
//Transform
effect.View = camera.View;
effect.Projection = projection;
effect.World = world;
}

mesh.Draw();
}

//Draw Plane
foreach (ModelMesh mesh in plane.Meshes)
{
foreach (BasicEffect effect in mesh.Effects)
{
//Transform
effect.View = camera.View;
effect.Projection = projection;
effect.World = world;
}

mesh.Draw();
}

DrawObject(gameTime);
DrawMobiles(gameTime);
player.Draw3D(camera.View, projection, gameTime);
ModelAnimation.Draw(camera.View, projection);

Only ModelAnimation works fine, the previous draw call dont show nothing on screen.

Thanks in advance.

jwatte's picture

To debug draw state problems

To debug draw state problems with Direct3D in general, I highly recommend downloading and installing the Microsoft Direct3D SDK. It comes with a tool called PIX for Windows, which can start your application, and then capture all draw calls during one frame when you press a key. When you quit your application, you can single-step through all the draw calls, and see what gets sent to the screen, what the different renderstates on the graphics device is (culling, etc), what the contents of the vertex buffers are, etc. It's the absolutely best way to debug the kinds of problem you describe here.

tnx very much for reply The

tnx very much for reply
The problem is as follows:
With code

foreach (ModelDraw man in Human_Man)
{
Mobile mobile = null;
try
{
mobile = (Mobile )WorldObjectsManager.Mobiles[Convert.ToUInt32(man.Name)];
}
catch (Exception)
{
continue;
}
man.Transform = Matrix.CreateScale(.01f) * Matrix.CreateRotationZ((float)(mobile.Rotation * MathHelper.PiOver4 )) * Matrix.CreateTranslation(personaggio.RealPosition.X, personaggio.RealPosition.Y,
personaggio.RealPosition.Z);

uomo.SceneDraw(dd);
//uomo.SceneDrawTransparent(dd);
//Program.game.spriteBatch.Begin();
//Program.game.spriteBatch.End();
}

everything works perfectly, of course without transparency

if uncomment the last three lines are seen only parts animated transparent

thanks in advance

How to use this Library

Hello,

myself and a pal just wondering how it works. We downloadet it and try the AnmitationViewer and its great! But we still dont understand how to use the code with our animations and diddnt find any tutorials or something else that can help us.

What we need is a documentation how the code is used in simple Examples how to load a Model an the animationplayer and so on.

We tryed the XNAnimation Library but its doesnt work with XNA 3.0 so we want to use KiloWatt :)

plz help 2 frustrated students and many regards to your work

jwatte's picture

All the code for how to use

All the code for how to use the library can be found in the Animation Viewer application. You can just pick that apart to see how it works.
Note that the fact that there are no tutorials is a recognized property of the KiloWatt animation library. It's not intended as a teaching tool; it's production-grade code for real game production.

Where can I find info about the basic concepts?

Hello, I want to say thanks by this great job, I'm a C# programmer but new to 3D animation stuff, I want to get an animated models in very little game, however I've found hard to start, I have problems doing the rigth thing with the files that I've exported from 3D Max, I'd like to have a step by step tutorial on how to bring an animation from 3D Max to an XNA 3.0 games using this library, I don't now if something like that exists now, so, where can I find something similiar??

Again, thanks a lot¡¡¡¡

does it work with FBX too or only X?

hello and thanks for this great library.
i was wondering, does it work with FBX models too, or only X models?