2

我在 Xna 上使用“ DrawUserIndexPrimitive ”类绘制纹理时遇到了一些问题。

我可以毫无问题地绘制我的立方体/模型。但我想在我的立方体上绘制不同的纹理。我循环应用到我的不同立方体的不同纹理的每个“ID”。但它不起作用。我每次都应用与我的类“GraphicData”不同的IndexBuffer 和vertexPosition。

要应用的最终纹理在我所有的立方体上都是相同的

谢谢你

这是我的函数“Draw”的代码

public void drawWorld(GameTime gameTime) 
    { 
        if (needToDraw) 
        { 
            int index = 0; 
            foreach (GraphicData data in graphicData) 
            { 

                effet.LightingEnabled = false; 
                effet.VertexColorEnabled = false; 
                effet.TextureEnabled = true; 
                effet.FogEnabled = false; 
                effet.FogStart = arcadia.camera.NearPlane; 
                effet.FogEnd = arcadia.camera.FarPlane; 
                effet.FogColor = new Vector3(1, 1, 1); 
                effet.View = arcadia.camera.View; 
                effet.Projection = arcadia.camera.Projection; 
                effet.Texture = data.Texture2D;
                //I hardcoded with a condition for check that the texture changes well in my loop
                /*
                if (index == 0) 
                { 
                    effet.Texture = Game.Content.Load<Texture2D>("Models\\Ground\\Land\\ground_land_text1"); 
                } 
                else 
                { 
                    effet.Texture = Game.Content.Load<Texture2D>("Models\\Ground\\Land\\ground_land_text2"); 
                } 
                */
                foreach (EffectPass pass in effet.CurrentTechnique.Passes) 
                { 
                    pass.Apply(); 
                    //Initialize et envoie à la carte graphique le buffer et les vertices 
                    if (data.vertexBuffer != null && data.indexBuffer != null) 
                    { 
                        Game.GraphicsDevice.SetVertexBuffer(data.vertexBuffer); 
                        Game.GraphicsDevice.Indices = data.indexBuffer; 
                        Game.GraphicsDevice.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, data.vertexPosition, 0, data.vertexPosition.Length, data.indices, 0, data.indices.Length / 3); 
                    } 

                } 
                index++; 
            } 
        } 


    } 
4

0 回答 0