mX64
mX64

Reputation: 388

xna 3d model shown broken

i just try draw a simple 3d model(many model (.fbx) tested) with basicEffect in xna 4.0 , and there is no other object like 2d spritebatchs or text or ... but it does not shown correctly , i searched it and did some solution but no one work like set

graphics.GraphicsDevice.BlendState = BlendState.Opaque;
graphics.GraphicsDevice.DepthStencilState = DepthStencilState.Default;

although i did not draw anything else ! and what is funny i already work with 3d model without problem ! here is my draw code and a result screenshot

 protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.White);
            graphics.GraphicsDevice.BlendState = BlendState.Opaque;
            graphics.GraphicsDevice.DepthStencilState = DepthStencilState.Default;
            foreach (ModelMesh mesh in m_Model.Meshes)
            {
                foreach (ModelMeshPart meshPart in mesh.MeshParts)
                {
                    BasicEffect effect = (BasicEffect)meshPart.Effect;
                    effect.View = Matrix.CreateLookAt(new Vector3(0, 100, 1000), Vector3.Zero, Vector3.Up);
                    effect.World = bones[mesh.ParentBone.Index] * (Matrix.CreateWorld(Vector3.Zero, Vector3.Right, Vector3.Up));
                    effect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, GraphicsDevice.Viewport.AspectRatio, 0.0001f, 1000000f);
                    effect.EnableDefaultLighting();
                }
                mesh.Draw();
            }
            base.Draw(gameTime);
        }

result another model

ty for your time

Upvotes: 1

Views: 696

Answers (2)

varun palekar
varun palekar

Reputation: 106

Its the problem of depth buffer, you are using the spritebrite to draw something which changes your default depth buffer off.

Make it on before drawing 3d model mesh.

After calling SpriteBatch.End(), add this code:

device.DepthStencilState = DepthStencilState.Default;

Upvotes: 1

Steve H
Steve H

Reputation: 5519

The near clip value in your projection Matrix is most likely causing this. Try setting it to 1.0f instead of 0.0001f. If that doesn't solve the problem completely, bring the far clip down to something like 10000f.

edit - noticing that your camera is over 1000 units away from your model, you can even set the near clip to 5f or 10f to gain depth read precision if needed.

Upvotes: 2

Related Questions