FBX模型在XNA 4.0中无法正确显示

时间:2012-11-12 10:52:14

标签: c# c#-4.0 xna xna-4.0 game-engine

最近我发布了同样的问题,我的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();
   }
}

有人可以帮忙! 感谢。

2 个答案:

答案 0 :(得分:2)

根据您之前的问题,Xna渲染图像显示您正在渲染2d和3d项目,重要的是重置2d和2之间的一些图形状态。 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

答案 1 :(得分:2)

这是我的解决方案:

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