2012-11-12 100 views
2

最近我發佈了同樣的問題,我的FBX模型在XNA中無法正確顯示。我得到了這個問題的答案,模型顯示稍微好一些,但仍然無法正確顯示。FBX模型在XNA 4.0中無法正確顯示

什麼它看起來應該是這樣的: 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(); 
    } 
} 

能有人請幫助! 謝謝。

+0

我沒有一個谷歌文檔帳戶,我看不到你的鏈接。下次使用Imgur。 – LightStriker

+0

你不需要一個谷歌帳戶 – Antony

+0

那麼,當我點擊鏈接,它要求我登錄。 – LightStriker

回答

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

也取決於你的藝術,你可能需要添加這個 GraphicsDevice.SamplerStates [0] = SamplerState.LinearWrap; – Shredder2500

+0

謝謝,對不起,我花了這麼久回去 – Antony

+0

不客氣! – HaiTrieu

2

根據您先前的問題,Xna渲染圖像顯示您正在渲染2D和3D物品,因此重置2D渲染圖像之間的某些狀態非常重要。

具體來說,渲染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