【问题标题】:XNA 4.0 Model texture issueXNA 4.0 模型纹理问题
【发布时间】:2012-01-24 09:42:37
【问题描述】:

我有一个问题。 当我尝试在 XNA 4.0 中渲染我的模型时,我的纹理的某些地方是透明的。纹理本身有问题还是我做错了什么?模型和纹理从 Blender 中导出。我尝试禁用颜色键或预乘 alpha,但没有运气。

截图:

http://i43.tinypic.com/2evg56u.jpg

这是我的绘制方法:

    protected override void Draw(GameTime gameTime)
    {
        GraphicsDevice.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.CornflowerBlue, 1.0f, 0);

        DrawModel(model, position);

        spriteBatch.Begin();
        spriteBatch.DrawString(font, "Camera\nX = " + cameraPosition.X.ToString() +
                                     "\nY = " + cameraPosition.Y.ToString() +
                                     "\nZ = " + cameraPosition.Z.ToString(), new Vector2(10, 10), Color.White);
        spriteBatch.DrawString(font, "Look at\nX = " + cameraLookAt.X.ToString() +
                                     "\nY = " + cameraLookAt.Y.ToString() +
                                     "\nZ = " + cameraLookAt.Z.ToString(), new Vector2(10, 150), Color.White);
        spriteBatch.End();

        base.Draw(gameTime);
    }

    void DrawModel(Model model, Vector3 position)
    {
        foreach (ModelMesh mesh in model.Meshes)
        {
            foreach (BasicEffect effect in mesh.Effects)
            {
                effect.EnableDefaultLighting();
                effect.SpecularColor = new Vector3(0.25f);
                effect.SpecularPower = 16;

                effect.World = Matrix.CreateTranslation(position);
                effect.Projection = projection;
                effect.View = view;
            }

            mesh.Draw();
        }
    }

【问题讨论】:

  • 您是否启用了深度缓冲区?你考虑过 CullMode 状态吗?
  • 感谢您的回复。我尝试了 CullMode 但这没有帮助,我认为默认情况下应该启用深度缓冲区,但是 Neil Knigh 的回答解决了我的问题。

标签: c# model 3d xna textures


【解决方案1】:

检查您的DepthStencilState,因为这将在调用SpriteBatch 对象后发生变化。在SpriteBatch.End() 调用之后,您可能需要重置它Default。

【讨论】:

  • 谢谢,这解决了我的问题 :) 我没有意识到 DepthStencilState 在调用 SpriteBatch 时会发生变化。
猜你喜欢
  • 2014-01-14
  • 1970-01-01
  • 1970-01-01
  • 2012-06-15
  • 1970-01-01
  • 1970-01-01
  • 2012-09-23
  • 1970-01-01
  • 2018-10-09
相关资源
最近更新 更多