ngilbert

I have a question and concern regarding the .fbx model exporting from Maya.

Problem: Whenever I load a model into my game that has been exported using the latest .fbx exporter plugin from Maya the model is arranged such that some of the pieces of the model are lined up along its x axis.

I did some research on the .fbx file format and found out that while it was designed to be an open document 3D model format, it has been grossly revised by just about all modeling programs which have edited it to suit. Which is why you can't export a model in Maya and then import it into Max and expect it to be the same.

My question is this, being that the .fbx file format is flaky at best; what make and version of the .fbx exporter/importer is XNA designed to use

I am also interested in alternative model solutions. However, I would like to avoid writing my own import/export plugin.


Thanks!
Nick


Re: XNA Framework Model Exporting From Maya (.fbx)

Shawn Hargreaves - MSFT

I wouldn't really agree that FBX is flakey: we've been testing the latest exporters from many packages with generally very good success.

What code are you using to render the model From your description it sounds like you might not be setting the World matrices correctly, so your rendering is ignoring the local transform matrices from the model bones data.





Re: XNA Framework Model Exporting From Maya (.fbx)

Sentientv2

I am new to working with XNA, and this isn't exactly a response to your question, but I know that the .x exporter for Maya works rather well. I had to develop some SAS compliant shaders for viewing in DXViewer. I used the .x converter in Maya so I could make some more interesting models to look at.

If I happen to work with the fbx format exporter for Maya, I will make sure to let you know what I find. I'm sure that will happen in the next few weeks. Take care,

-Burton





Re: XNA Framework Model Exporting From Maya (.fbx)

ngilbert

Shawn, I've looked over my draw code a couple of times and if I'm missing something then I must not be understanding something.

Here is the code I am using to create my world matrix.

effect.World = Matrix.CreateRotationY(Rotation_3D.Y) *
Matrix.CreateRotationX(Rotation_3D.X) *
Matrix.CreateRotationZ(Rotation_3D.Z) *
mesh.ParentBone.Transform *
Matrix.CreateTranslation(Position_3D);



Let me know what you make of this.

Thanks!




Re: XNA Framework Model Exporting From Maya (.fbx)

Shawn Hargreaves - MSFT

If your mesh has more than one level of nested objects, the ParentBone.Transform may be leaving out transform information from the grandparent nodes. To draw a model with a nested bone hierarchy, you should use the CopyAbsoluteBoneTransformsTo method, for instance:
  Matrix[] transforms = new Matrix[model.Bones.Count];

Model.CopyAbsoluteBoneTransformsTo(transforms);

foreach (ModelMesh mesh in model.Meshes)
{
foreach (BasicEffect effect in mesh.Effects)
{
effect.World = transforms[mesh.ParentBone.Index];
effect.View = viewMatrix;
effect.Projection = projectionMatrix;
}

mesh.Draw();
}
Alternatively, you could use a content pipeline processor to flatten all these transforms into a single coordinate system. I posted an example on my blog that shows how to do that.






Re: XNA Framework Model Exporting From Maya (.fbx)

gmcbay

I export from Maya to X and have no experience using the fbx importer, but just as a general rule you should make sure you freeze transformations on the model before exporting if you aren't planning on doing anything fancy with the model/mesh hierarchy.  Select model, select Modify Menu->Freeze Transformations, then export. 

Not sure if that helps at all, but give it a try if you aren't already doing that.






Re: XNA Framework Model Exporting From Maya (.fbx)

ngilbert

Currently our model only has one bone according to the Modelmesh, but the model has not been rigged.  But has animated parts. Would you recommend rigging the model to maintain its mesh   Because it seems to be dividing it out into its groups when I load it.




Re: XNA Framework Model Exporting From Maya (.fbx)

ngilbert

Well, I had my modeler rig the model last night and now everything is being rendered as it should. Can the XNA framework not display an animated mesh without it first being rigged




Re: XNA Framework Model Exporting From Maya (.fbx)

Shawn Hargreaves - MSFT

I don't understand why that wasn't working before - it sounds like the vertices were somehow getting exported in different coordinate systems for different parts of the mesh Very odd!





Re: XNA Framework Model Exporting From Maya (.fbx)

collada

You could also try the (open source) COLLADA plugin for Maya (http://www.feelingsoftware.com/component/option,com_docman/Itemid,80/lang,en/) and the corresponding (open source) XNA Model loader (https://collada.org/public_forum/viewtopic.php p=2264).




Re: XNA Framework Model Exporting From Maya (.fbx)

neiltrodden

Shawn, I am so glad I saw your response on this thread. I am experiencing a similar problem. I have used the code as given in the XNA documentation to draw the mesh (the How to: Render a model example):

    private void DrawModel(Model m)
    {
      Matrix[] transforms = new Matrix[m.Bones.Count];
      float aspectRatio = graphics.GraphicsDevice.Viewport.Width / graphics.GraphicsDevice.Viewport.Height;
      m.CopyAbsoluteBoneTransformsTo(transforms);
      Matrix projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f), aspectRatio, 1.0f, 10000.0f);
      Matrix view = Matrix.CreateLookAt(new Vector3(0.0f, 50.0f, Zoom), Vector3.Zero, Vector3.Up);

      foreach (ModelMesh mesh in m.Meshes)
      {
        foreach (BasicEffect effect in mesh.Effects)
        {
          effect.EnableDefaultLighting();

          effect.View = view;
          effect.Projection = projection;
          effect.World = MyWorldRotation * transforms[mesh.ParentBone.Index] * Matrix.CreateTranslation(Position);
        }
        mesh.Draw();
      }
    }

The effect I am getting (which is difficult to explain, but I'll try!) is that the meshes that make up the model are being drawn orientated incorrectly. The arms and legs end up the wrong way around, the eyes are stuck somewhere in the back of the head etc. When I rotate the model (as that example allows with the xbox controller) some parts of the model rotate correctly. The chest, for example, rotates as you would expect if someone was spinning around on the spot. The legs however, rotate along the wrong axis and rotate as if the model was back-flipping.

I have already used the example you gave for the flatten transform pipeline processor, and this seems to improve things. The whole model now rotates as one around it's origin but the component meshes are all just one big lump and the model as a whole has lost it's structure.

This is all from a free model of a cartoon character in the prone position in 3ds format, then exported as an fbx but I'm getting it on ever model I have tried which has multiple meshes in.

Thanks for your work on the content pipeline, by the way. For all the goodness in the XNA framework, this one thing has meant that there'll be less people out there having to spend months just drawing a wooden crate while they are learning!