Nero-One
Nero-One

Reputation: 127

Odd geometry with 3D models XNA + Blender

Ok, this is hard to explain without pictures. I made a very limited model of a glock in Blender with an extruded cube making up the base and a scaled cube making up the barrel. In Blender, It looks fine:

1

However, after exporting the model to .fbx and loading it into the compiler, it comes out like this:

2

I don't know exactly what is going on. Everything on the model is properly UV Mapped and the coordinates are correct, It just seems the translation is.. off..

Here is my drawModel code:

private void DrawModel(Model model, Matrix world, Matrix view, Matrix projection)
{
    foreach (ModelMesh mesh in model.Meshes)
    {
        foreach (BasicEffect effect in mesh.Effects)
        {
            effect.EnableDefaultLighting();                   
            effect.World = world;
            effect.View = view;
            effect.Projection = projection;
        }
        mesh.Draw();
    }
}

Any pointers will be helpful!

EDIT: After Applying rotation, location, and scale, I was able to get them in the right position, but why does it look transparent?

3

Thank you for all the help!

Upvotes: 2

Views: 634

Answers (3)

Neil Knight
Neil Knight

Reputation: 48587

As Nikola mentioned, in the later versions of Blender, they have proper XNA support.

Here's a screenshot of the settings I chose when exporting a model:

enter image description here

Upvotes: 1

Blau
Blau

Reputation: 5762

Enable depth buffer:

      GraphicsDevice.DepthStencilState = DepthStencilStates.Default;

And to Draw a model in Xna you can follow this tutorial, that shows how the bone transforms have to be applied to get the meshes in right position.

Upvotes: 0

Why this happens: Your Depth Buffer is not enabled, so when your GPU draws the barrel first, then the stock/handle, the handle is drawn on top of the barrel, even though some parts of it are supposed to be invisible because they would be hidden by the barrel.

How to fix: Enable Depth Buffer as other answer suggests. And/Or order meshes in your model based on distance from camera, and draw tehm in order from the nearset to the farthest. This may not seem usefull now, but when you start working with transparent objects, you will see why this is a good thing to learn.

Upvotes: 1

Related Questions