Mesh draw problem.

Hi folks. Here I am again with another model problem I don’t understand.

In Blender I created a simple object just for testing. It’s an icosphere surrounded by 5 other smaller icospheres, it looks like a few joined bubbles. I Joined all the objects, CTRL+J so there is only one mesh and exported them. So far so good.

When I get the model into my code it draws ok, but no matter what the orientation of the model the smaller spheres display behind the larger. So as I’m spinning the object the orbiting spheres always draw behind the larger.

The larger sphere was created first in Blender, but there are no parents or children or anything slightly complicated.

Any ideas?
Thanks.

I’m also getting whole objects closer to the camera being drawn behind those further away.

Do I have to observe draw order with 3D objects? I didn’t think you did.

Do you have any screenshot ?
How do you multiply your transformation matrices ?

You want to have a depth buffer so the gpu can test if objects are behind others and skip the pixels that aren’t visible. If you use SpriteBatch it will by default disable the depth testing. Try putting the following code before rendering your meshes:

GraphicsDevice.DepthStencilState = DepthStencilState.Default;

Thanks Jjagg, that did the trick.

So, I only have SpriteBatch in the code because it’s in the cobbled template I’m using, are you saying I shouldn’t be using it with a 3D environment? It’s part of the LoadContent and Draw routines. Handy in the draw routine as I want 2D text, but the mesh drawing is outside of the batch.

Thanks again…

Ah ! That’s the reason… I was wondering why I had to set DepthStencilState.Default when I did not change it.

No, it’s fine to use SpriteBatch, but you just need to reset the render state afterwards.