FBX模型在XNA 4.0中显示不正确

3
最近,我发了一个相同的问题,即我的FBX模型在XNA中没有正确地显示。我得到了问题的答案,并且模型显示得稍微好些了,但仍然没有正确地显示。
它应该看起来像这样:https://docs.google.com/open?id=0B54ow8GRluDUYTBubTQ4bjBramM,但它显示为:https://docs.google.com/open?id=0B54ow8GRluDUNXR5bmJUMVJFTUk
我的绘制代码是:
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();
   }
}

有人可以帮忙吗!感谢。


我没有谷歌文档账户,无法查看您的链接。下次请使用Imgur。 - LightStriker
您不需要谷歌账户。 - Antony
好的,当我点击链接时,它要求我登录。 - LightStriker
前往此处:http://www.flickr.com/photos/89965250@N02/ - Antony
1
嗯...我的第一个猜测是你的三角形法线被翻转了,导致它们被渲染成内部。但是如果不能移动并查看,很难确定。 - LightStriker
显示剩余2条评论
2个回答

3

根据您之前的问题,Xna渲染图像显示您正在呈现2D和3D物品,因此在2D和3D之间重置一些图形状态非常重要。

特别是,在呈现2D内容后,请添加以下几行代码:

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

这些设置对于3D是必要的,但在调用SpriteBatch.Begin()时会被更改,因此在使用3D内容之前需要将它们改回来。
以下是解释这一点的博客文章: http://blogs.msdn.com/b/shawnhar/archive/2010/06/18/spritebatch-and-renderstates-in-xna-game-studio-4-0.aspx

3
这是我的解决方案:
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;
}

根据你的需求,你可能需要添加以下代码: GraphicsDevice.SamplerStates[0] = SamplerState.LinearWrap; - Shredder2500
谢谢,抱歉我回复晚了。 - Antony

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接