2012-06-12 87 views
2

,所以我試圖與2D精靈一個3D遊戲。 在混合器我創建了一個平面,並且使用UV映射到映射到子畫面平面中的一個。當我按f12並渲染飛機時,顯示精靈。出口紋理的3D模型和紋理從攪拌機XNA 4.0

我確信創造的材料的平面和我做了一定要加紋理以及使UV貼圖用正確的UV貼圖。

我導出的文件模型.FBX文件,並把這個用在我的項目的內容文件夾中的紋理圖像一起。

然而,當我使我的模型,而不是紋理的顯示面爲純黑色。

這可能是什麼原因造成的?我的畫看起來像這樣:

public void Draw(Matrix View, Matrix Projection) 
{ 
    // Calculate the base transformation by combining 
    // translation, rotation, and scaling 
    Matrix baseWorld = Matrix.CreateScale(Scale) 
    * Matrix.CreateFromYawPitchRoll(
    Rotation.Y, Rotation.X, Rotation.Z) 
    * Matrix.CreateTranslation(Position); 

    foreach (ModelMesh mesh in Model.Meshes) 
    { 
     Matrix localWorld = modelTransforms[mesh.ParentBone.Index] 
     * baseWorld; 
     foreach (ModelMeshPart meshPart in mesh.MeshParts) 
     { 
      BasicEffect effect = (BasicEffect)meshPart.Effect; 

      effect.World = localWorld; 
      effect.View = View; 
      effect.Projection = Projection; 
      effect.EnableDefaultLighting(); 
     } 
     mesh.Draw(); 
    } 
} 

回答

2

我想通了。在我的模型沒有顯示我的質地的原因是因爲我沒有設置正確effect.world

我改變我設置了世界矩陣和編輯我的一些模型類代碼的方式。 如果任何人想渲染紋理模型用一個漂亮的類

public class CModel 
{ 
    public Matrix Position { get; set; } 
    public Vector3 Rotation { get; set; } 
    public Vector3 Scale { get; set; } 
    public Model Model { get; private set; } 
    private Matrix[] modelTransforms; 




    public CModel(Model Model, Vector3 Position) 
    { 
    this.Model = Model; 
    modelTransforms = new Matrix[Model.Bones.Count]; 
    Model.CopyAbsoluteBoneTransformsTo(modelTransforms); 
    this.Position = Matrix.CreateTranslation(Position); 

    } 

    public void Draw(Matrix viewMatrix, Matrix proMatrix) 
    { 

    foreach (ModelMesh mesh in Model.Meshes) 
    { 
     foreach (BasicEffect effect in mesh.Effects) 
     { 
      effect.EnableDefaultLighting(); 

      effect.View = viewMatrix; 
      effect.Projection = proMatrix; 
      effect.World = modelTransforms[mesh.ParentBone.Index] * Position; 
     } 

     mesh.Draw(); 
    } 
    } 

在指定位置繪製模型。如果你想要任何其他效果,你可以很容易地將它們添加到繪圖中。