FBX with Tangents/Binormals not supported?

Hi guys,

I recently started working with Monogame and I am pretty happy with my progress.

But now i hit a bump and i believe it is a bug in the monogame content pipeline tool that is causing the trouble.

If I try to import an .fbx model file which was exported with tangents/binormals the solution will build fine, BUT the model I read ingame has 0 meshes then. It doesn’t exist. In content.mgcb it has no impact changing the parameters to “generateTangentFrames”.

The same .fbx without the tangent/binormal export works fine, however, for advanced lighting calculations i need the binormal/tangents.


Here is how i work:

  • Create model in blender. UV the model. Export to .fbx with FBX 7.4 Binary
  • Convert to 2013 FBX format with Autodesk FBX converter
  • In MGCB add the file.
  • Build MGCB
  • Import model via model = content.Load(“Art/model”);

Works well.
However, if in Blender I add Tangent Space to the export options the same model that just worked does not exist any more.

Same thing in 3dsMax. Exporting with “tangents and binormals” checked, the same thing happens.

Maybe it’s still possible I have done something wrong with the model itself, but usually tangents and binormals can be created with a simple UV unwrap, right? Any ideas/help?

I don’t think that this is related to Assimp or MonoGame. It seems to be a bug in the Blender FBX exporter. When I open the resulting FBX in the Autodesk FBX Viewer, the scene is also empty.

To use Tangents/Binormals:

  • Disable the “Tangent Space” option during export.
  • Enable “GenerateTangentFrames” for the MonoGame ModelProcessor.

Side note: You don’t need to convert the FBX to FBX 2013 format. The format produced by Blender (FBX 7.4 Binary) should be fine, in my experience.

Hey,

thanks for the response. Because I thought it maybe just my blenderversion, I got the newest one again (2.76b). My monogame is the latest binary 3.4.

I did exactly as you said. Export to 7.4 binary and export tangent space unchecked.

Because i was curious i checked it in FBX viewer and it was invisible, even without tangent space. I converted it to fbx 2013 and i could see it in FBX viewer. Ok?

Anyways continuing with the unconverted blender fbx.

I load it in the content view and check generate tangent frames. I load it in the game and apply a basic shader, it works. Yay.

Then I change the effect to the effect which requires Binormals/tangents (like seen in this tutorial http://rbwhitaker.wikidot.com/bump-map-shader-2 and/or some samples by microsoft)

and it crashes and says

which indicates the model has no tangent binormal information. Since it should work from the get go. My terrain i create with Tangents/Binormals in the vertex information and it works.

Is it possible I do something wrong in blender? The tangents/binormals should be created without any additional input, right?

Could you maybe provide an FBX which works for you? Just to test if it’s something I do wrong here in Blender.

EDIT: BRB porting to a newer Monogame. Didn’t even notice there was a newer one. Why not just add 3.5 and stuff to the main page binary downloads? Smh

That’s weird. I use Blender 2.76b and usually don’t have any problems viewing the exported model in the FBX viewer (Autodesk FBX Review).

I did a quick test. Enabling “GenerateTangentFrames” works with my version (MonoGame develop branch from December 2015).

That’s not strictly true !

The exception (not a crash) indicate the generated data structure does not include ONE or more of the REQUIRED element(s) (it could be normals AND/OR texture AND/OR color), see riemers website for more explanation as it has more “low-level” tutorials than RB Whitaker (especially some nice terrain tutorials) or primitives tutorials (the vertex shader need to use something like VertexPositionColor structure used in drawing triangle tutorial just with more data).

Anyway, without a single piece of code, it may not be easy to help.

Well I create the Shader myself, so I know it’s just missing these two things.

Anyways, upgrading to the newest development build fixed the issue :slight_smile:

It is there on the download page under “Development Builds”. It just isn’t labeled 3.5.

I’ll consider refactoring how that is presented to make it more like the rest, but still clearly labeled as a potentially unstable development version.

Apologies if I’m bumping an old subject, but a search indicated that I am having exactly the same issue.

I created a few models using blender a few months ago, and those models work fine (tangents space and uv are imported and work into monogame without issue)

Now I formatted my drive, and installed the latest version of blender (2.78a), and the latest development build of monogame (I also merged pr 5218), and I cannot find a way to create new models and import those into monogame.

Here are the presets I use to export my fbx in blender :

If, in the content tool, I check the “generate tangeant frames” for the model, I get this error on build :

If I uncheck the box, I don’t get an error on build, but I do get an error when trying to draw the model :

The error message seems really weird to me, as my shader is a custom shadow map creation shader, and I know for a fact the vertex input is declared as only needing position :

struct InstancingVSinput { float4 Position : POSITION0; };

struct InstancingVSoutput
{
float4 Position : POSITION0;
float Depth : TEXCOORD0;
};

InstancingVSoutput InstancingVS(InstancingVSinput input, float4 HighlightColor : TEXCOORD1, float4x4 World : TEXCOORD2)
{
InstancingVSoutput output;

float4 pos = mul(mul(input.Position, World), WorldViewProjection);

output.Position = pos;
output.Depth = pos.z / pos.w;

return output;

}

float4 InstancingPS(InstancingVSoutput input) : COLOR0
{
return float4(input.Depth, input.Depth, input.Depth, 1);
}

Can someone try using in monogame a fbx model generated with the latest version of blender, and let me know if they succeed?

My understanding is that currently Monogame computes tangents/bitangents when models are imported in the content pipeline, as implemented here in MeshHelper.cs

So my guess is that you don’t need export these, as they are computed by the Monogame’s content importer.

EDIT:

So CalculateTangentFrames is called from ModelProcessor.cs if the mesh doesn’t contain these information. Which means that there is a bug indeed when these are included in the fbx. As a work around, they will be computed if you don’t include them.

EDIT:

digging a bit further, Monogame is importing any mesh using a component called “Assimp” which handles a lot of formats, gathered in one generic importer which is OpenAssetImporter.cs.

There is a big comment block stating all assimp limitations, but I can’t see anything about Tangents/binormals:

 // Assimp has a few limitations (not all FBX files are supported):
    // FBX files reference objects using IDs. Therefore, it is possible to resolve
    // bones even if multiple bones/nodes have the same name. But Assimp references
    // bones only by name!
    // --> Limitation #1: A model cannot have more than one skeleton!
    // --> Limitation #2: Bone names need to be unique!
    //
    // Bones are represented by regular nodes, but there is no flag indicating whether
    // a node is a bone. A mesh in Assimp references deformation bones (= bones that
    // affect vertices) by name. That means, we can identify the nodes that represent
    // deformation bones. But there is no way to identify helper bones (= bones that 
    // belong to the skeleton, but do not affect vertices). As described in 
    // http://assimp.sourceforge.net/lib_html/data.html and 
    // http://gamedev.stackexchange.com/questions/26382/i-cant-figure-out-how-to-animate-my-loaded-model-with-assimp/26442#26442
    // we can only guess which nodes belong to a skeleton:
    // --> Limitation #3: The skeleton needs to be a direct child of the root node or
    //                    the mesh node!
    //
    // Node.Transform is irrelevant for bones. This transform is just the pose of the
    // bone at the time of the export. This could be one of the animation frames. It
    // is not necessarily the bind pose (rest pose)! For example, XNA's Dude.fbx does
    // NOT store the skeleton in bind pose.
    // The correct transform is stored in Mesh.Bones[i].OffsetMatrix. However, this
    // information is only available for deformation bones, not for helper bones.
    // --> Limitation #4: The skeleton either must not contain helper bones, or it must
    //                    be guaranteed that the skeleton is exported in bind pose!
    //
    // An FBX file does not directly store all animation values. In some FBX scene it
    // is insufficient to simply read the animation data from the file. Instead, the
    // animation properties of all relevant objects in the scene need to be evaluated.
    // For example, some animations are the result of the current skeleton pose + the
    // current animation. The current skeleton pose is not imported/processed by XNA.
    // Assimp does not include an "animation evaluater" that automatically bakes these
    // animations.
    // --> Limitation #5: All bones included in an animation need to be key framed.
    //                    (There is no automatic evaluation.)
    //
    // In FBX it is possible to define animations curves for some transform components
    // (e.g. translation X and Y) and leave other components (e.g. translation Z) undefined.
    // Assimp does not pick the right defaults for undefined components.
    // --> Limitation #6: When scale, rotation, or translation is animated, all components
    //                    X, Y, Z need to be key framed.

I found out the following rules apply when importing a fbx file created with monogame, and checking the “generate tangeant space” box :

  • If you export the tangent space with blender, building the xnb with monogame will fail
  • If you export the object without UV mapping, building the xnb with monogame will fail (this means the model in blender must have a material and a texture, and an UV unwrap)

I haven’t figured out the second error yet (monogame warns me that my model doesn’t have all the required vertex info) when the box is unchecked, even though my shader only needs position info. It seems to be related to hardware instancing, I didn’t get this error when drawing my skybox to a simple cube.

For now, I’ll just build my models with tangent info, even for models that do not need it (I am drawing low poly version of my models to my shadow map, those typically don’t need tangent space info)

`[quote=“mazetlouis, post:10, topic:7136”]
I haven’t figured out the second error yet (monogame warns me that my model doesn’t have all the required vertex info) when the box is unchecked, even though my shader only needs position info. It seems to be related to hardware instancing, I didn’t get this error when drawing my skybox to a simple cube.
[/quote]

Yeah, I’ve never had problems with building the solution, are you sure it fails in the build phase or only when starting the game? I’m pretty sure I’ve used lots of objects without UVs at first

https://forum.unity.com/threads/cant-calculate-tangents-because-mesh-doesnt-contain-normals.747638/

Check this it may help