Troubles getting the animation to display

Apr 4, 2008 at 8:17 PM
I am trying to integrate the animated dwarf from the tutorial into another project and I am having troubles getting the animation to display. When I try to run the program currently I get this error: "The given key was not present in the dictionary". The dwarfmodelanimation.xml has been added to the project.

I have a matrix called World and MatrixPalette, I have added the skin function to the shader and called it within the vertex shaders ( I am doing shadow mapping so I have two techniques).

This is basically the code in question beyond the shader. Any ideas as to what I could try?

LoadContent()
{
...
viewMatrix = Matrix.CreateLookAt(CameraPos, new Vector3(0, 0, 0), new Vector3(0, 1, 0));
projectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, (float)this.Window.ClientBounds.Width / (float)this.Window.ClientBounds.Height, 1.0f, 500.0f);

testChar.load("Models//Dwarf//dwarfmodel");
testChar.setupAnimation();
..
}

public void setupAnimation()
{
dwarfAnimator = new ModelAnimator(thisGamePtr, model);
idle = new AnimationController(thisGamePtr, dwarfAnimator.Animations"idle0");
RunController(dwarfAnimator, idle);
}



Apr 4, 2008 at 8:35 PM
The exception that your getting is generated when you try to perform a lookup on a collection of objects that uses a key value pair for storage... such as a dictionary or sorted list...etc...

from the code you posted... I only see one thing that looks like it might be a collection of objects.

" idle = new AnimationController(thisGamePtr, dwarfAnimator.Animations"idle0");"

which is removing the '[' which is part of the wiki markup
Apr 4, 2008 at 8:45 PM
Oh sorry- yes that is the line that gives me the error. Is it possible that it isnt loading the dwarfmodelanimation.xml right? I have a working copy of the tutorial separately, and they didnt seem to do anything with the file beyond include it in the content pipeline. I have done a search on their code and it isnt referenced anywhere that I could find though....

Thanks
Apr 4, 2008 at 11:45 PM
Hey Talusryn, I had that problem a lot, and there are a couple of different ways to get it, but I think that what missleControl is saying is that it looks like you forgot the sqaure brackers () around the String "idle0". Your line should read like this:

idle = new AnimationController(thisGamePtr, dwarfAnimator.Animations"idle0");

The other thing that comes to mind is check and make sure that the xml file containing your animations is named appropriately (in this case it looks like it should be dwarfmodelanimation.xml), and in the right extension. I find it works best to go directly into the directory through the desktop and paste the xml file there. It doesn't need to show up on your solution explorer in XNA, and in fact usually causes an error (ok, that might have all seemed pretty obvious, but it took me a while to figure out >_<)

Apr 5, 2008 at 12:08 AM
Edited Apr 5, 2008 at 12:09 AM
The square brackets are missing because it seems that this forum filters them out for some reason- I directly copied from the code (Which was in turn directly copied from a working program), which definetly has them. The only change is how I have referenced the main game (thisGamePtr), which I do not believe is the issue as I have run it through the game class as well with the same error. I was reading that part of missiles post simply as pointing out to me that the forum does this.

About the other part you mentioned- where exactly in the directory structure for the project should I place it? Alongside the source files, or in the same folder as the model?

Also, how do I tell what the right filename is? As I noted, I have done text searches on the source files and model files, and can find no reference to this file anywhere. (I pretty sure I did this on the working copy of the tutorial, though I will check that)

When I try to view the data in dwarfAnimator.animations[] while it is debugging I get that the array is one long, with the single element having the name AnimationSet0. If I use that instead of Idle0, the program compiles, it just doesnt display any animation. So I can tell at some level the file isnt ending up in this array, I just dont see how this is supposed to end up there...

Thanks again =)
Apr 5, 2008 at 5:24 PM
Edited Apr 5, 2008 at 5:32 PM
Talusryn,

regarding your last post...

>> "About the other part you mentioned- where exactly in the directory structure for the project should I place it? Alongside the source files, or in the same folder as the model?"
the xml file should be in the same folder as your .X or .FBX file as the case may be. I believe that you've named the file properly... if your model file is "dwarfmodel.x" then your animation file should be "dwarfmodelanimation.xml"
one thing worth noting is that you don't have to actually "add" the xml file to your project, as you stated in your first post. It just needs to be in the same directory.

>> "Also, how do I tell what the right filename is? As I noted, I have done text searches on the source files and model files, and can find no reference to this file anywhere. (I pretty sure I did this on the working copy of the tutorial, though I will check that)"
As to how the animation lib references this file.... take a look at ReadAnimationXML and SubdivideAnimations methods in AnimatedModelProcessor.cs.... I'd suggest that you put a call to attach a debugger by placing "System.Diagnostics.Debugger.Launch();" within one of these methods... then recompile the content DLL and then rebuild your project that contains the dwarfmodel.

>>"When I try to view the data in dwarfAnimator.animations[] while it is debugging I get that the array is one long, with the single element having the name AnimationSet0. If I use that instead of Idle0, the program compiles, it just doesnt display any animation. So I can tell at some level the file isnt ending up in this array, I just dont see how this is supposed to end up there..."
after reading this... I can tell you that your xml file is incorrectly formatted. I'd try getting a newer version... Below is a how your xml should basically look... The "AnimationSet0" property and the tickspersecond value is based on how the .X file was exported. You should only be modifying the and adding more "animationsubset" elements.

<animation>
<name>AnimationSet0</name>
<tickspersecond>15.0</tickspersecond>
- <animationsubset>
<name>walk</name>
<startframe>1</startframe>
<endframe>13</endframe>
</animationsubset>
</animation>
Apr 6, 2008 at 1:28 AM
Huge thanks, that definetly gives me things to look at. As soon as I have access to the code again on monday Ill try them out =)
Apr 6, 2008 at 3:40 AM

Talusryn wrote:
The square brackets are missing because it seems that this forum filters them out for some reason- I directly copied from the code (Which was in turn directly copied from a working program), which definetly has them. The only change is how I have referenced the main game (thisGamePtr), which I do not believe is the issue as I have run it through the game class as well with the same error. I was reading that part of missiles post simply as pointing out to me that the forum does this.


doh! sorry bout that.
Apr 7, 2008 at 7:44 PM
Edited Apr 7, 2008 at 7:54 PM
Ok... I moved the XML file to the same directory as the model, and rebuilt the project and it worked as far as getting past the key not found issue. The program runs and displays the scene... but the dwarf isnt there lol...

I'm not totally sure what this could be yet, but I do have one idea. I do two passes of the scene currently- once for creating the shadowmap and then another to render the scene with shadows. I am worried with the fact that the animation is being drawn behind the scenes that it is not being drawn for both passes. If it was just drawn to the shadow map it is quite possible given the scene that I just cant see the shadow left behind.

Is there a good way to check about this?

I saw in another post that you could stop the model from automatically rendering by setting dwarfAnimator.visible = false.

Edit: I just found the draw method in the ModelAnimator class (duh..) and added a call to that each pass, and set the ModelAnimator.Visible to false. This still doesnt display the dwarf however. ..
Apr 8, 2008 at 2:31 AM
Wow, I didn't see that Draw() method, that's pretty cool. I tried it, and it kinda worked for my model... although the view doesn't update when I rotate my camera... nor does my main character move with respect to the position of the camera that way... so it does give me some trouble.

however, I found that it didn't work if I didn't first set the projection and view of the model is that set for sure? also are you using XNA 1.0 or 2.0, cause you also have to apply a custom shader in order view your models when using XNA 2.0, but that's easy and El Sibor made one that everybody could use some time back, so if you need it I can get it to you as well.

hope this helps.
Apr 8, 2008 at 7:47 PM
Edited Apr 8, 2008 at 7:49 PM
Thanks for the reply.


however, I found that it didn't work if I didn't first set the projection and view of the model is that set for sure? also are you using XNA 1.0 or 2.0, cause you also have to apply a custom shader in order view your models when using XNA 2.0, but that's easy and El Sibor made one that everybody could use some time back, so if you need it I can get it to you as well.

hope this helps.


I am definetly using XNA 2.0, but I am using a custom shader already. Maybe I made a mistake in applying the stuff from the tutorials shader into my own shader, but I was pretty careful about that.

In my shader ShadowMap.fx:

I added float4x4 MatrixPalette{56};
Renamed my world matrix to float4x4 World;
Added the extra necessary arguments to the vertex input structure, indices and weights.
Added the SKIN_OUTPUT structure
Added the SKINOUTPUT Skin4( const SSVertexInput input) function.
Called this skin function within the vertex shader of both techniques: SKIN_OUTPUT skin = Skin4(input);

Is there anything else I should be doing in the shader for the skinning?

As far as setting the view and projection matrices, it is true that I missed that. However I believe I have added that now, and the code for my current loading function is below.

public void load(String name)
{
model = Content.Load<Model>(name);

int i = 0;
textures = new Texture2D200;
foreach (ModelMesh mesh in model.Meshes)
{
if (mesh.Effects0 is BasicPaletteEffect)
{
foreach (BasicPaletteEffect currenteffect in mesh.Effects)
{
currenteffect.View = viewMatrix;
currenteffect.Projection = projectionMatrix;
BasicPaletteEffect oldEffect = (BasicPaletteEffect)currenteffect;
texturesi++ = oldEffect.Texture;
}
}
else
{
foreach (BasicEffect currenteffect in mesh.Effects)
{
currenteffect.View = viewMatrix;
currenteffect.Projection = projectionMatrix;
BasicEffect oldEffect = (BasicEffect)currenteffect;
texturesi++ = oldEffect.Texture;
}
}
foreach (ModelMeshPart modmeshpart in mesh.MeshParts)
{
modmeshpart.Effect = effect.Clone(device);
}
}
}
Apr 8, 2008 at 9:43 PM
Thinking more on the loading function... I think I may have noticed a flaw in my structure. By cloning the current effect after setting values, I have erased all the work done to set those values... I guess I need to rethink how this function should be organized.
Apr 9, 2008 at 10:11 PM
I found the problems!

First off I wasnt setting all the parameters necessary for my shader. I was setting the view and projection settings, but I was failing to set other ones such as lighting and texturing. Still trying to get used to XNA shaders so I kinda completely didnt notice this problem. As soon as I got them all set, the dwarf rendered just fine, but wasnt animated.

The other error I made was to do with utilizing the skin values after calculating them. I added all the functions and structures necessary to calculate the skin values, and called them, but I couldnt see them used anywhere in the shader. I guess it kinda sounds silly now, but I just kinda assumed because I couldnt see them, that they were probably being used in the hidden draw function. When I finally noticed that yes, the shader does actually use this information everything fell together.

Yay for working projects =)