Question

I have a problem with importing 3D model from FBX file.

Source model contains 575 objects + 1 camera and looks like this: http://habreffect.ru/files/23d/542fa7f67/source_model.png

In XNA prepared with content pipeline model contains 82 meshes, and 576 bones. So, when I draw my model, I see only part of source model. Result picture like following: http://habreffect.ru/files/28a/6e61c0215/Result_view.png

My drawing code:

GraphicsDevice.Clear(Color.CornflowerBlue);

Matrix[] transforms = new Matrix[_model.Bones.Count];
_model.CopyAbsoluteBoneTransformsTo(transforms);

foreach (var mesh in _model.Meshes)
{
    foreach (BasicEffect effect in mesh.Effects)
    {
        effect.LightingEnabled = true;
        effect.EnableDefaultLighting();
        effect.World = transforms[mesh.ParentBone.Index] * _world;
        effect.View = _view;
        effect.Projection = _proj;
    }
    mesh.Draw();
}
base.Draw(gameTime);

How can I get all 575 meshes in my Model instance in XNA?

Thanks!

UPD: I tried to import my FBX model to 3ds max, select all meshes and use "Export selected". Result FBX file is 11x bigger. Then I add it as content to XNA project, loaded model contains all 575 meshes, and it rendered correctly.

Unfortunately, this manual converting method don't suit me - I need to render varied fbx models from mutable repository.

So, what FBX file are "good" for XNA content processor (I use XNA 4)?

Was it helpful?

Solution

So, on MSDN I found that FbxImporter designed to work with 2006.11 version of FBX format.

Recently Autodesk released FBX Converter 2012.1, which contains other tools, like FBX Eplorer, FBX Viewer.

FBX explorer can show structure of FBX file, and I compare exported from 3D MAX file, and source FBX file. They have different internal format. I tried to make following conversion: FBX -> Collada -> FBX, and the result FBX file contains similar to exported from MAX data structure.

So, I simply add the result FBX to Content of my XNA app, and it's rendered well :)

Another way to make it work is to use Autodesk FBX SDK to manually read model, and draw it in XNA.

Conclusion:

  1. XNA FbxImporter correct work doesn't depend on version (2006, 2011, etc) and form (binary, ascii) of FBX file. Internal FBX data structure much more important.
  2. To make FBX "readable" for XNA Importer you can use double conversion like FBX -> Collada -> FBX
  3. You also can use FBX SDK to manually load data from FBX

OTHER TIPS

Open the 3d model in latest 3dx max 2012 and export it in .fbx format. This .fbx is loaded properly with the xna model loader. While exporting you can even embed the resources, so you dont have to add textures to it through XNA.

You are using instancing in 3DS MAX. This isn't supported directly by XNA. You have to draw the mesh for each instance bone yourself. Ideally you would instead use DirectX instancing to draw each mesh once per bone in a single Draw() call. But you have to roll your own code to do that, by converting the bones into instance vertices. By default XNA only supports the most basic operations.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top