xnaml model and animation

May 23, 2008 at 11:17 PM
I like the oops framework and have a rudimentary working game for tryout purposes. I'm using my normal model import methods. But I was looking at the content pipeline project and found that I don't know what xnaml model or xnaml animation are. Is this a format that is unique to oops? If so is there a file specification? I did a search and got no results although the xnaml name sounds familiar. Is it something I should already know about? I ask because I would consider using it. I use blender for modeling and it's pretty easy to write export scripts for a particular format. Thanks for any information.
Coordinator
May 25, 2008 at 4:32 PM
The xnaml format is something I came up with so I could quickly write an exporter for Animation Master.  It's loosely based on the MD5 format from the Doom3 engine. 

I actually just started using blender for modeling and created a Python script and content importer for an xml based MD5 format.  I'll probably be updating the source and releasing another beta of Oops!.  I'll include the Python script as well.

FYI - The next beta version (probably will move it back to alpha) of Oops Physics Component is much improved and has true multi-threaded support and static mesh support.  I'm testing it on XBOX360 right now and should be releasing the source in June.  The usage of the framwork remains mostly the same except that the CollisonRay is not a CollisionShape anymore (how I had it a few releases ago) and that a RigidBody is not required for static CollisionShapes.

Good luck!
May 27, 2008 at 6:06 PM
Thanks for the information! I'll look forward to the new (alpha)beta release. I'm in the process of trying to use different parts of the framework (except for the animation) to determine how hard it will be to add functionality I need while remaining consistent with your components and interfaces. It still looks promising. Your code is nicely organized.

A random thought on blender: their community is the best I've ever worked with. It's big and active and extremely helpful.
Jul 24, 2009 at 3:28 PM

Hi, we are currently using the default model loader to load our assets which have been made in Maya with the FBXExporter. I can't find any examples of "xnaml" for the animation data. Where would I be able to find this and are there any examples of getting this working in the framework?

 

Thanks

Nistur

http://boogey-ground.com

Coordinator
Jul 28, 2009 at 11:14 PM

Hey Nistur, Boogey Grounds is looking awesome!

The xnaml file format was "invented" by myself to export animations from a software package called Animations Master quickly.  The company has since pretty much dropped the SDK for newer versions of the software.  So I dropped them.

The bad news is the only way to use the xnaml code is exporting animations in the "xnaml" file format with a custom exporter for Maya.  The good news is I already rewrote my animation code to use the animation data exported from regular x and fbx files.  If you give me a few days, I'll upload the code and create an example of using the code.

The code also contains some fixes to the physics code as well.

Jul 31, 2009 at 4:08 PM

Thanks, will the code be in the latest release or will you post a link here?

Apologies if I seem a little impatient, we're just in crunch right now and nothing seems to work :S

 

Thanks again

Nistur

Coordinator
Jul 31, 2009 at 8:42 PM

I'll post it in the latest release and source code.  I should have it ready this weekend.

Just a heads up, I removed the Quaternion sections from the physics code (#if QUATERION_ROTATION).  It runs much quicker with Matrices.  I also removed methods marked as <Obsolete>.  I also made the CollisionMesh transformable so you can orient and position it.  This will help if you have many nonmovable objects of the same type.  A tree, for example, used in many places in a level.

Coordinator
Aug 1, 2009 at 8:16 PM

I changed my mind.  The updated code is just in source code.  A few other caveats:

- Mesh-to-Box when the mesh is oriented is not implemented yet.\

Let me know if you have any questions or issues.

Aug 1, 2009 at 10:01 PM

Awesome, have downloaded the sourcecode and tested the animation, am just adding the DLL to our project and then I'll begin the work adding animations :)

Thanks again for how fast you've updated. Just one problem I have noticed so far, the 360 build fails as it's missing the files in Net. For us it's not a problem _right now_ (much bigger problems before we get to testing on the 360) but it would be useful if the files appeared :P

Thanks yet again

Nistur

Aug 1, 2009 at 10:20 PM

Hrmmm, things didn't go as smoothly as I had hoped.

I don't know whether it's because your models are exported to .X (we have .fbx at the momemt) or whether you're just using different export options, but I'm getting Model.Tag as null all the time.

Thanks

Nistur

Coordinator
Aug 1, 2009 at 11:06 PM

Make sure you include the Oops.Xna.Framework.Content.Pipeline project as reference in your content project, then make sure your model uses the "Skinned Model - Oops! Frameork" as the processor (select it in the properties after selecting the model file in your solution).

Aug 2, 2009 at 12:01 AM

Thanks. I hadn't added the Content Pipeline dll before as I couldn't find it. I just assumed it was compiled into the main dll... turns out it was compiling the x86 dll to the Zune directory :S

It still isn't animating but I'll have to see to that tomorrow. Starting to fall asleep tonight...

Thanks

Nistur

Aug 5, 2009 at 12:05 AM

Ok then.

So, we got an animated model working. The bind pose was a little broken but it moved more or less like it should. But yeah, I was collecting animated models from our artists, replaced the slightly broken wardrobe I had... and _nothing_ works...

All models will load fine using the XNA Content Processor however when I change them to use the Oops! Skinned Model then most of them don't add a texture to the model in question (it's bright white), and breaks depth sorting somehow. Nothing is in the right position in the Z buffer, some look like their normals are reversed, some are drawn behind everything else. Some models dont' even load at all, complaining that bitmap size < 0

The artists have been using this tutorial to export the animations: http://www.youtube.com/watch?v=-JRQTbdNMSE

Please

Please

Please say this is something you know about that is fixable.

Thanks in advance for your help

Coordinator
Aug 5, 2009 at 1:51 AM

Have you tried using your model in the example 8 (Example8Screen.cs) of the testing app?  If not I'd start there.  Add your model and associated textures in the content project's "Model" directory, make sure it's using "Skinned Model" processor and chang the code in Example8Screen.cs to load your model.

Also, you might try the skinning example on http://creators.xna.com with you model.  That might verify better that the model exported correctly.

If you've done those already and/or it doesn't work, the SkinnedModelProcessor.cs is probably the culprit.  It's pretty much coded against only models that I've exported, all being .X files.

You can attempt to debug the content pipeline by uncommenting the first //System.Diagnostics.Debugger.Launch(); in SkinnedModelProcessor.cs file.  If you want, you can send me a model (and textures) via email and I'll debug as well.  It's hard to guess what the issue might be.

But don't worry, I'm sure it's solvable.

Aug 5, 2009 at 11:23 AM
Edited Aug 5, 2009 at 12:29 PM

Hey, thanks a lot for the advice. I put the model into the TestingApp and it works... which is annoying... because I copied the code from there almost exactly...

That rules out SkinnedModelProcessor.cs, the model file, and everything else :S It _must_ be my code... are there any particular nuances on how your animation stuff (or the shader) work that I might have overlooked?

Thanks again

Nistur

Edit: I thought I'd mention that the model doesn't animate at all when it looks all broken... took me a while to find out, trying to find a direction our camera could point that could tell...

Coordinator
Aug 5, 2009 at 6:20 PM
Edited Aug 5, 2009 at 6:29 PM

If the model isn't animating, possibly not all the shader constants are being set from your code, particularly "AnimationFrame" and "AnimationTexture".

The mangled look of your model could be due to "World", "View" or "Projection" shader constants that are incorrect or malformed.  It could also be because of the render state of the GraphicsDevice.  Any chance your drawing something else that changes GraphicsDevice.RenderState?  the SpriteBatch changes it if you specifically tell during the Begin method to save the state.

 EDIT:

Also make sure you set all effect parameters of every mesh in the model.  Similar to this code from the example:

foreach (ModelMesh mesh in this.botModel.Meshes)
{
    foreach (Effect localEffect in mesh.Effects)
    {
       localEffect.Parameters["World"].SetValue(Matrix.CreateTranslation(Vector3.Up * 5.0f));
       localEffect.Parameters["View"].SetValue(this.viewpoint.ActiveCamera.View);
       localEffect.Parameters["Projection"].SetValue(this.viewpoint.ActiveCamera.Projection);
       localEffect.Parameters["AnimationTexture"].SetValue((this.botModel.Tag as SkinningData).AnimationTexture);
       localEffect.Parameters["AnimationFrame"].SetValue(this.animationPlayer.CurrentKeyframe);
    }
    mesh.Draw();
}

Aug 5, 2009 at 6:38 PM

Thanks for the reply.

You're right. I fixed the borked view of everything. For some reason drawing a model loaded through your content processor reverses the CullMode in the game :S I just re-set it at the beginning of drawing each entity and everything else works fine. My current draw code is as follows

 
public void draw(bool debug)
{
    RenderManager.getSingleton().graphicsDevice.RenderState.CullMode = CullMode.None;
    foreach (ModelMesh mesh in this.m_model.Meshes)
    {
        foreach (Effect localEffect in mesh.Effects)
        {
            localEffect.Parameters["World"].SetValue(m_BoneTransforms[mesh.ParentBone.Index]
                                                   * Matrix.CreateScale(scale) *
                                                   m_position);
            localEffect.Parameters["View"].SetValue(RenderManager.viewMatrix);
            localEffect.Parameters["Projection"].SetValue(RenderManager.projectionMatrix);
            if(this.m_model.Tag != null)
            {
                localEffect.Parameters["AnimationTexture"].SetValue((this.m_model.Tag as SkinningData).AnimationTexture);
                localEffect.Parameters["AnimationFrame"].SetValue(this.m_animation.CurrentKeyframe);
            }
            localEffect.Parameters["EyePosition"].SetValue(RenderManager.viewpoint.ActiveCamera.Position);
            localEffect.Parameters["FogEnabled"].SetValue(1.0f);
            localEffect.Parameters["FogEnd"].SetValue(50.0f);
        }
        mesh.Draw();
    }
}

And initialisation is done in the same way as in your example, although again testing for Tag != null as not all entities are animated or loaded as such.

I was talking to one of my artists earlier and suggested they look into exporting as .X as people seem to have had more luck with that. However the university has trained them both in Maya, and all our models are currently in maya format... and we can't seem to find any decent .X exporters for Maya. I was thinking of using Blender as a go-between, however, obj doesn't support animation so I'm stumped. Is there something you can suggest?

Thanks once again

Nistur

 

Coordinator
Aug 5, 2009 at 7:44 PM

So, it's drawing okay now but still not animating?  Try passing in differnt hard-coded values for "AnimationFrame" and see if changes things if that's the case.  You might also inspect the SkinnedData of the model and look at the dimensions of the AnimationTexture as well as the collection of AnimationClips.  Are they (roughly) what you expect?  AnimationClip.Durations?  StartRow and EndRow.

Is the m_animation.Update method being called every frame?

I've modeled in Blender.  There are a bunch of importers for it.  Maybe you can export in one of those formats from maya and import it into blender that way...to then export to an X file.  There's a special X exporter someone wrote on the blender website that was modified to work with XNA better.

Aug 5, 2009 at 8:50 PM
Edited Aug 5, 2009 at 9:15 PM

ok, obviously passing a hardcoded value for animation frame gives me (yet another) static model. I am not well aquianted enough with the 3D models in question to know precisely what position each frame looks like and artists are both offline at the moment, so I'll ask in a bit for some screenshots of a couple of frames... AnimationFrame is the frame number, right? It's lerp'd between them...

I had a look at some of the animation clips and the values for durations, startrow etc seem to make sense, although again, I can't be 100% sure, but they seem feasable. The AnimationTexture did however provide an interesting discovery. It claims it's 40x248 when in fact the texture is 512x512. Not entirely sure what that means.

It is not drawing correctly. I just worked out why the rest of everything was looking strange, it had set XNA to reverse the cullmode. The model processed as a skinned model shows up as pure white (screen is cleared to black and has sky drawn on it so it is actually drawing something) and it appears to be behind every model in the game. I think it's likely that there's something in the importing that's broken the shader, or set something in the graphics pipeline but I wouldn't know how I can reset it, doing it before the entity draws itself has no effect as it clearly sets it during the drawing...

Edit: m_animation.Update is called every frame. Also, I am having trouble finding anything maya can export to with animation that Blender can import. When I googled it people just suggested obj...

Edit2: I just checked the Testing App... it also claims it has 40x248 for the AnimationTexture, yet it still works... so it can't really be that

Edit3: Ok, I got some screenshots from one of the artists just now and checked it against a model of something with wings (nice and obvious in the game if they're moving) at frame 10 they should be quite obviously folded down, however then AnimationFrame is set to 10.0f they are up in the game.

Thanks

Nistur

Coordinator
Aug 5, 2009 at 9:19 PM

Yep.  AnimationFrame is the frame number though it's really a lookup into the AnimationTexture  and since all animations are combined into one AnimationTexture, the AnimationFrame will be the frame number plus some offset for all animations besides the first.

Also, check the processor properties on your model and compare them to the model in example 8 (select the model file in the solution explorer and expand the "Processor" property).  Maybe your building the model content differently.

Aug 5, 2009 at 9:29 PM

I checked the processor properties and they are identical for the 2 projects.

From what I can tell, all attributes in both projects in m_animation, in the SkinningData... all are identical, the animation is apparently updating, just nothing's working, it's stuck on the bind pose with no texture and no depth in the scene.

Is there a chance to catch you on some IM?

Thanks

Nistur

Coordinator
Aug 6, 2009 at 12:27 AM

Use fretboardoffury at yahoo or aim.  I won't be online too long tonight but I'll try to help as much as I can.

Aug 6, 2009 at 8:28 AM

Ok, so I don't know how many other people might have this problem, but just in case they do, I feel obliged to share the solution.

FretboardOfFury helped me debug for 3+ hours last night (for which I am forever grateful) and discovered that there was nothing wrong. Not a sausage. I was then suggested to move the game project into the Oops Solution. Neither of us could give a good reason why this might work but it was the last difference between the Test App and my game. And it worked.

I'm sure it will get fixed at some point, but for now, if you want animation, create the project inside the Oops Solution and link to the Oops.Framework and Oops.Framework.Content.Pipeline projects.

I hope this helps someone and causes less hair-pulling than it did for us

Nistur

http://nistur.com

http://boogey-ground.com