Reputation: 199
Recently I have posted the same question that my FBX model was not showing correctly in XNA. I got a answer to the question and the model was displayed slightly better, but it is still not displaying correctly.
What it should look like is this: https://docs.google.com/open?id=0B54ow8GRluDUYTBubTQ4bjBramM But it shows as: https://docs.google.com/open?id=0B54ow8GRluDUNXR5bmJUMVJFTUk
My drawing code is:
public void Draw(Matrix projection, Matrix view)
{
Matrix[] transforms = new Matrix[model.Bones.Count];
model.CopyAbsoluteBoneTransformsTo(transforms);
foreach (ModelMesh mesh in model.Meshes)
{
foreach (BasicEffect effect in mesh.Effects)
{
effect.EnableDefaultLighting();
effect.View = view;
effect.Projection = projection;
effect.World = Matrix.CreateRotationX(-270) *
transforms[mesh.ParentBone.Index] *
Matrix.CreateTranslation(Position);
}
mesh.Draw();
}
}
Can someone please help! Thanks.
Upvotes: 3
Views: 1862
Reputation: 194
This is my solution:
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
#region ResetGraphic
ResetGraphic();
#endregion
#region render 3D
BeginRender3D();
//Render 3D here
#endregion
#region render 2D
//Render 2D here
#endregion
}
public void ResetGraphic()
{
GraphicsDevice.BlendState = BlendState.AlphaBlend;
GraphicsDevice.DepthStencilState = DepthStencilState.None;
GraphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise;
GraphicsDevice.SamplerStates[0] = SamplerState.AnisotropicWrap;
}
public void BeginRender3D()
{
GraphicsDevice.BlendState = BlendState.Opaque;
GraphicsDevice.DepthStencilState = DepthStencilState.Default;
}
Upvotes: 3
Reputation: 5519
Based on your previous question where the Xna rendered image showed that you were rendering 2d and 3d items, it is important to reset some graphics states between 2d & 3d.
Specifically, after rendering the 2d stuff, add these lines:
GraphicsDevice.BlendState = BlendState.Opaque;
GraphicsDevice.DepthStencilState = DepthStencilState.Default;
These settings are necessary for 3d but they get changed when calling SpriteBatch.Begin() so it is necessary to change them back before the 3d stuff.
Here is the blog post explaining it: http://blogs.msdn.com/b/shawnhar/archive/2010/06/18/spritebatch-and-renderstates-in-xna-game-studio-4-0.aspx
Upvotes: 3