2011-11-26 97 views
1

我只是嘗試繪製一個簡單的3D模型(許多模型(.fbx)測試)與basicEffect在xna 4.0,並沒有其他對象像2d spritebatchs或文本或... 但它沒有正確顯示,我搜索它,並做了一些解決方案,但沒有一個工作 ,比如集合xna 3d模型破壞

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

result another model

TY您的時間

回答

2

在您的投影矩陣的近裁值是最有可能導致此。嘗試將其設置爲1.0f而不是0.0001f。如果這不能完全解決問題,請將遠端剪輯縮小到10000f。

編輯 - 注意你的相機距離你的模型超過1000個單位,甚至可以將近剪輯設置爲5f或10f,以在需要時獲得深度讀取精度。

+0

ty m8,yeah nearPlaneDistance太小了,發現剛發佈問題後,將0.0001f修改爲0.1f fixxed這個問題 – mX64

1

它的深度緩衝區的問題,你正在使用spritebrite繪製的東西,改變你的默認深度緩衝區關閉。

在繪製3d模型網格之前進行設置。

調用SpriteBatch.End()後,添加以下代碼:

device.DepthStencilState = DepthStencilState.Default;