Tutorial: How to get XNA's SkinnedSample working with MonoGame

Hi. First and foremost, I want to give shout outs to Alkher and KonajuGames for explaining this entire process to me. A slight disclaimer: this tutorial is in no way written by a professional on the subject. It’s entirely possible I used the wrong terminology at points, or missed explaining why something is done. I hope the images I’ve included clear up any confusion.

I recently had a need to get 3D .fbx animations into my game. However, all the information I could find on the subject was either outdated or didn’t work for me for one reason or another. I’ve also seen many people in my situation, so now I’ll do my best to show how to add the Skinned Model Processor into MonoGame.

I will be using MonoGame 3.5 for this, as well as SkinningSample_4_0.

First off, you’ll need to create a new MonoGame Pipeline Extension Project in Visual Studio. I called my project MGSkinnedModelPipeline

Your Solution Explorer will look like this.

Now, you’re going to need to right-click your solution, and go Add > New Project, and create another MonoGame Pipeline Extension Project. I called mine MGSkinnedModel. This project will contain the class definitions used by MGSkinnedModelProcessor.

This should be your Solution Explorer now.

MGSkinnedModelPipeline will need to know about MGSkinnedModel, so right click it’s References and Add Reference > Projects > MG Skinned Model.

Now, the next step is rather easy. Remove the .cs files from both projects, and then add the .cs files from XNA’s SkinningSample_4_0 to their respective project (SkinnedModelPipeline’s go to MGSkinnedModelPipeline; SkinnedModel’s go to SkinnedModel). Also, you can go ahead and remove the MonoGame.Framework.Content.Pipeline reference from MGSkinnedModel as it doesn’t need it.

Your Solution Explorer should look like this:

Now, for a very minor code change. Open SkinnedModelProcessor.cs and add the following instead of line 29:

[ContentProcessor(DisplayName = "Skinned Model Processor")]

The pipeline tool will then use this name when you’re selecting processors.

Now, there’s still one more step. Be sure that your project is saved, then right click on both projects and set their Target framework to be .Net Framework 4.5.

Check that your Configuration Manager has both projects compiling to either Any CPU or x64, and then build the project! You shouldn’t get any errors (great!). You’re now ready to add the new processor to MonoGames pipeline tool.

Open your real game project and then open its Content.mgcb file.

Click Content, then in References you’re going to add the MGSkinnedModelPipeline.dll that your build generated. You should now be able to select it as a processor for your imported .fbx’s (you may need to close and re-open the tool before it appears):

Hooray! Your project can now import animated models! In order to draw them, have a look at how the SkinningSample project included in XNA’s SkinningSample_4_0 does it. Don’t forget to include your MGSkinnedModel project in your game project (and remember to have it reference it).

4 Likes

Nice one :wink: I may need in a near future

1 Like

Thanks, but don’t get too excited. Turns out no matter what I do Blender will STILL export its .fbxs with wonky weights unless you’re extreeeeeeemely careful (how you be extremely careful I don’t know. All I know is I just made a really simple wiggling worm animation and it imported perfectly, but the more detailed stuff I had previously distorts beyond recognition).

The older versions of Blender had an animation fix for that (which has since been removed), but those older versions are incompatible with MonoGame.

Still, good knowledge to have if you plan on using other processors.

When I was using Blender last year in a Unity project (wasn’t my choice of dev environment), I had to use a third-party FBX plug-in because the default Blender FBX stripped all sorts of essential info from the model.

1 Like

Hm… that’s odd. Blender FBXs have never caused any trouble for me in Unity in the past (though I never really used complex animations). What kind of things did you have your animations do?

I’ll definitely look into getting a third party-plugin. Will report which has the best results (I’m trying to get this animation working, so it’s no wonder MonoGame is having trouble):


^ Of about 10 different alternatives this was the best looking one. It’s not uncommon to have infinite-vertices or just unrecognizable clouds.

One thing I think helps is having your model and armature in their default pose when you export them in Blender. If you have it mid-way through an animation, it seems to affect it.

Skinned Model Processor was never in the default XNA, right?

Still if we can reproduce a robust import procedure I think it’s worth adding the SkinnedModelProcessor to the main Monogame Framework, right? Any reasons why not to?

Question: why is it called Skinned ? And not Animated or Skeletal ? I have never catched the trick. When i started with xna years ago this induced me to error.
Skinned would be a better name if it reproduced skin with all effects and parameters (reflectance, transmittance, etc) implied on a model like the demos on nvidia or ue4 for character faces.

1 Like

Animated is too broad, just rotating or translating sonething is animating as well.
Skeletal is too specific. I can have a car with bones for the wheels and it would be skinned but not have a skeleton

A skinned mesh can have each vertex attached to one or more bones with a specified weight. This means the vertex can be influenced by more than one bone, particularly useful around joints such as knees and shoulders where the mesh can deform more smoothly. The vertex might have 50% influence from one bone, 30% influence from a second bone and 20% influence from a third.

So… has anyone had any luck getting them to import and not be distorted?

Exhibit A:

Exhibit B:

EDIT:

Ok, I’ve kind of figured it out. The origin of each model in the armature has to be 0,0,0. Also, when exporting you need to have the armature be in its resting pose. In addition, parenting a mesh to bone doesn’t work. They all need to be weight painted to work. Oh, and disable “Transparency” from the material or the model will be invisible.

1 Like

I finally can import animated fbx with monogame! but…

Blender:

Monogame:

that not exactly what I expect… If anyone has ideas that may help ?

There’s a few things you need to make sure of before you import into your game:

  1. When you export, your armature must be in its resting pose in Blender (T-Pose). Aka, no rotation/scale/position can be applied to any bones. What I do is I create a 1 keyframe long animation called initial, and switch to it before exporting.

  2. Every face needs to have a weight applied to it. Non-weighted faces will distort the animation much like you’re seeing here. A really good way to make sure you have this is when you parent your armature, you select “Use Automatic Weights” when it asks you.

  3. I’m not sure about this one, but combining meshes into one tends to fix it if certain parts of the model aren’t visible.

  4. Use the latest version of Blender. I’m not sure how helpful this would be, but my (very similar to yours) problems stopped after I upgraded and did the above steps.


After trialing SkinnedSample for a while now, it seems to me that it’s a bit basic in certain areas (no animation blending or modification of playback speed, plus it does not smoothly animate between keyframes, resulting in jittery animation).

If I manage to get BetterSkinned running, I’ll post my findings here.

2 Likes

I think I make all thing you say correctly, but I can’t get what I want I just give up … I export multiple mesh like anim_0 anim_1 anim_2 and play theme to fake an animation that work and it’s good enough for the moment.

I will continue to follow this thread for any eventual update.

If you want you can upload your .blend file and I’ll have a go at importing it into my project.

Hello, sorry for delay, here my file if you want test: https://www.transfernow.net/40gytaga418q

let me know if you can play an animation with it :slight_smile:

Alright, I’m looking at your file now.

Now I don’t know exactly what most of these advanced things are (like how you got the eyes to “stick” to the mesh), but I’m pretty sure that’s a feature MG won’t support. Some other things I’m noticing is that the hair isn’t weight painted, and neither is most of the face. The shoes also are missing some weight painting, and the ears are parented to the head and not the armature (and are also not weight painted).

Now, I may be wrong about all these things being a problem (I also don’t know a lot about MG animation). However, the only time I’ve gotten good results is when every single part of my mesh has been weight painted, and parented to the armature. I’m afraid that’s the best advice I can give.

that model was made by a professional graphic designer for me and I don’t know how he made it I try to correct it for MG as you can see it’s not a real success so far…

like I say I will export only mesh and play them like an atlased texture, it’s easier like this

I will retry when MG will improve the animation support :unamused:

A bit of an update as to a potential reason for a model to throw errors during importing:

I made a nice, skinned model which imported just fine into MG. However, when I temporarily parented a cylinder to one of the bones on it to test the character holding onto an object, and then deleted that cylinder, the importer started giving errors when importing it (even though I returned the model to how it was before I added the cylinder).

I’ve not been able to recreate this bug with other models I’ve created, and as long as I never attach another mesh to my character model it seems to be fine (as in, I can add more animations/bones/weights and still import it into MonoGame). So if your model refuses to import for seemingly no reason, this could be it.

I tried using both Xna Skinned sample from Microsoft and Better skinned sample from this site but still my characters get distorted as seem below:

Any ideas of what could be the problem?

Have you tried these steps? Step 1 in particular seems to cause this the most (and is the easiest to fix). I just have a 1 frame animation in my project called “Initial” which has every bone un-rotated, un-transitioned and un-scaled, and I always switch to it before I export.