纹理地形会导致Windows Phone崩溃(没有例外)或之后不会绘制模型

时间:2011-11-20 12:25:34

标签: xna-4.0

我在LoadContent()上调用此方法 - 加载heightMap纹理后:

    private void setEffect(Texture2D heightMap)
    {
        m_BasicEffect = new BasicEffect(this.GraphicsDevice);
        m_BasicEffect.EnableDefaultLighting();
        m_BasicEffect.FogEnabled = true;
        m_BasicEffect.FogStart = 300f;
        m_BasicEffect.FogEnd = 1000f;
        m_BasicEffect.FogColor = Color.Black.ToVector3();
        m_BasicEffect.TextureEnabled = true;         
        m_BasicEffect.World = Matrix.Identity;
        m_BasicEffect.Texture = heightMap;
    }

现在,如果我更改“m_BasicEffect.TextureEnabled = true;” to“m_BasicEffect.TextureEnabled = false;”它有效,但纹理(当然)没有显示。

Draw方法如下所示:

    public override void Draw(Microsoft.Xna.Framework.GameTime i_GameTime)
    {
        Matrix worldMatrix = Matrix.CreateTranslation(-m_TerrainWidth / 2.0f, 0, m_TerrainHeight / 2.0f) * Matrix.CreateRotationY(m_Angle);

        m_BasicEffect.View = MyCamera.View;
        m_BasicEffect.Projection = MyCamera.Projection;
        m_BasicEffect.World = worldMatrix;

        foreach (EffectPass pass in m_BasicEffect.CurrentTechnique.Passes)
        {
            pass.Apply();
            Game.GraphicsDevice.Indices = myIndexBuffer;
            Game.GraphicsDevice.SetVertexBuffer(myVertexBuffer);
            Game.GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, m_VerticesNormalLength, 0, m_IndicesLength / 3);               
        }
    }

此外,如果我尝试绘制模型后缀,它会引发异常: “当前顶点声明不包括当前顶点着色器所需的所有元素。” 我尝试绘制模型的方式:

    public override void Draw(GameTime i_GameTime)
    {
        Matrix[] transforms = new Matrix[MyModel.Bones.Count];
        MyModel.CopyAbsoluteBoneTransformsTo(transforms);
        foreach (ModelMesh mesh in MyModel.Meshes)
        {               
            foreach (BasicEffect be in mesh.Effects)
            {
                be.EnableDefaultLighting();
                be.Projection = MyCamera.Projection;
                be.View = MyCamera.View;                    
                be.World = GetWorld() * mesh.ParentBone.Transform;
            }                
            mesh.Draw();
        }
    }

你怎么看? 提前谢谢。

0 个答案:

没有答案