繁体   English   中英

XNA 3D模型显示为残破

[英]xna 3d model shown broken

我只是尝试在xna 4.0中使用basicEffect绘制一个简单的3D模型(许多模型(.fbx)测试),并且没有其他对象,如2d spritebatchs或text或...但它没有正确显示,我搜索并做了一些解决方案,但没有人像一套

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

虽然我什么也没画! 有趣的是,我已经可以毫无问题地使用3D模型了! 这是我的绘图代码和结果截图

 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);
        }

结果另一种模式

腾出你的时间

投影矩阵中的近剪辑值很可能导致此问题。 尝试将其设置为1.0f而不是0.0001f。 如果这不能完全解决问题,请将远程剪辑降至10000f以下。

编辑 - 注意到您的相机距离您的模型超过1000个单位,您甚至可以将近剪辑设置为5f或10f以获得深度读取精度(如果需要)。

它是深度缓冲区的问题,你使用spritebrite来绘制一些可以改变默认深度缓冲区的东西。

在绘制3D模型网格之前将其启用。

在调用SpriteBatch.End()之后,添加以下代码:

device.DepthStencilState = DepthStencilState.Default;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM