【问题标题】:xna 3d model shown brokenxna 3d 模型显示已损坏
【发布时间】:2012-01-06 18:57:00
【问题描述】:

我只是尝试在 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);
        }

你的时间

【问题讨论】:

    标签: c# xna xna-4.0


    【解决方案1】:

    投影矩阵中的近剪辑值最有可能导致此问题。尝试将其设置为 1.0f 而不是 0.0001f。如果这不能完全解决问题,请将远剪辑降低到 10000f 左右。

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

    【讨论】:

    • ty m8,是的,nearPlaneDistance太小了,发现刚发完问题,把0.0001f改成0.1f就解决了这个问题
    【解决方案2】:

    这是深度缓冲区的问题,您正在使用 spritebrite 绘制一些东西,这会改变您的默认深度缓冲区。

    在绘制 3d 模型网格之前进行。

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

    device.DepthStencilState = DepthStencilState.Default;

    【讨论】:

      猜你喜欢
      • 2011-12-22
      • 2017-10-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多