C# XNA使用索引缓冲区代替

C# XNA使用索引缓冲区代替,c#,xna,indexing,vertex-buffer,C#,Xna,Indexing,Vertex Buffer,我正在画3D纹理立方体。我想在立方体的每一侧应用不同的纹理。我通过以下操作创建了多维数据集: using VPNT = Microsoft.Xna.Framework.Graphics.VertexPositionNormalTexture; private void Initialize() { Vector3[] Vertices = { new Vector3(-1, -1, -1), //Bottom-Left Front. new Ve

我正在画3D纹理立方体。我想在立方体的每一侧应用不同的纹理。我通过以下操作创建了多维数据集:

using VPNT = Microsoft.Xna.Framework.Graphics.VertexPositionNormalTexture;

private void Initialize()
{
    Vector3[] Vertices =
    {
        new Vector3(-1, -1, -1), //Bottom-Left Front.
        new Vector3(-1, -1, 1),  //Bottom-Left Back.
        new Vector3(1, -1, -1),  //Bottom-Right Front.
        new Vector3(1, -1, 1),   //Bottom-Right Back.

        new Vector3(-1, 1, -1),  //Top-Left Front.
        new Vector3(-1, 1, 1),   //Top-Left Back.
        new Vector3(1, 1, -1),   //Top-Right Front.
        new Vector3(1, 1, 1)     //Top-Right Back.
    };

    Vector3[] Normals = 
    {
        Vector3.UnitY,      //Top
        -Vector3.UnitY,     //Bottom
        -Vector3.Forward,   //Front
        Vector3.Forward,    //Back
        -Vector3.UnitX,     //Left
        Vector3.UnitX,      //Right
    };

    Vector2[] TextureCoordinates = 
    {
        new Vector2(1, 0),  //Top-Left
        new Vector2(0, 0),  //Top-Right
        new Vector2(1, 1),  //Bottom-Left
        new Vector2(0, 1)   //Bottom-Right
    };

    VPNT[] FrontFace =
    {
        new VPNT(Vertices[4], Normals[2], TextureCoordinates[0]),  //Top-Left Front
        new VPNT(Vertices[0], Normals[2], TextureCoordinates[2]),  //Bottom-Left Front
        new VPNT(Vertices[6], Normals[2], TextureCoordinates[1]),  //Top-Right Front
        new VPNT(Vertices[0], Normals[2], TextureCoordinates[2]),  //Bottom-Left Front
        new VPNT(Vertices[2], Normals[2], TextureCoordinates[3]),  //Bottom-Right Front
        new VPNT(Vertices[6], Normals[2], TextureCoordinates[1])   //Top-Right Front
    };

    VPNT[] BackFace = 
    {
        new VPNT(Vertices[5], Normals[3], TextureCoordinates[1]),  //Top-Left Back
        new VPNT(Vertices[7], Normals[3], TextureCoordinates[0]),  //Top-Right Back
        new VPNT(Vertices[1], Normals[3], TextureCoordinates[3]),  //Bottom-Left Back
        new VPNT(Vertices[1], Normals[3], TextureCoordinates[3]),  //Bottom-Left Back
        new VPNT(Vertices[7], Normals[3], TextureCoordinates[0]),  //Top-Right Back
        new VPNT(Vertices[3], Normals[3], TextureCoordinates[2]),  //Bottom-Right Back
    };

    VPNT[] TopFace = 
    {
        new VPNT(Vertices[4], Normals[0], TextureCoordinates[2]),  //Top-Left Front
        new VPNT(Vertices[7], Normals[0], TextureCoordinates[1]),  //Top-Right Back
        new VPNT(Vertices[5], Normals[0], TextureCoordinates[0]),  //Top-Left Back
        new VPNT(Vertices[4], Normals[0], TextureCoordinates[2]),  //Top-Left Front
        new VPNT(Vertices[6], Normals[0], TextureCoordinates[3]),  //Top-Right Front
        new VPNT(Vertices[7], Normals[0], TextureCoordinates[1]),  //Top-Right Back
    };

    VPNT[] BottomFace = 
    {
        new VPNT(Vertices[0], Normals[1], TextureCoordinates[0]),  //Bottom-Left Front
        new VPNT(Vertices[1], Normals[1], TextureCoordinates[2]),  //Bottom-Left Back
        new VPNT(Vertices[3], Normals[1], TextureCoordinates[3]),  //Bottom-Right Back
        new VPNT(Vertices[0], Normals[1], TextureCoordinates[0]),  //Bottom-Left Front
        new VPNT(Vertices[3], Normals[1], TextureCoordinates[3]),  //Bottom-Right Back
        new VPNT(Vertices[2], Normals[1], TextureCoordinates[1]),  //Bottom-Right Front
    };

    VPNT[] LeftFace = 
    {
        new VPNT(Vertices[4], Normals[4], TextureCoordinates[1]),  //Top-Left Front
        new VPNT(Vertices[1], Normals[4], TextureCoordinates[2]),  //Bottom-Left Back
        new VPNT(Vertices[0], Normals[4], TextureCoordinates[3]),  //Bottom-Left Front
        new VPNT(Vertices[5], Normals[4], TextureCoordinates[0]),  //Top-Left Back
        new VPNT(Vertices[1], Normals[4], TextureCoordinates[2]),  //Bottom-Left Back
        new VPNT(Vertices[4], Normals[4], TextureCoordinates[1]),  //Top-Left Front
    };

    VPNT[] RightFace = 
    {
        new VPNT(Vertices[6], Normals[5], TextureCoordinates[0]),  //Top-Right Front
        new VPNT(Vertices[2], Normals[5], TextureCoordinates[2]),  //Bottom-Right Front
        new VPNT(Vertices[3], Normals[5], TextureCoordinates[3]),  //Bottom-Right Back
        new VPNT(Vertices[7], Normals[5], TextureCoordinates[1]),  //Top-Right Back
        new VPNT(Vertices[6], Normals[5], TextureCoordinates[0]),  //Top-Right Front
        new VPNT(Vertices[3], Normals[5], TextureCoordinates[3]),  //Bottom-Right Back
    };

    this.vertices.AddRange(FrontFace);
    this.vertices.AddRange(BackFace);
    this.vertices.AddRange(TopFace);
    this.vertices.AddRange(BottomFace);
    this.vertices.AddRange(LeftFace);
    this.vertices.AddRange(RightFace);

    this.vbo = new VertexBuffer(this.game.GraphicsDevice, VertexPositionNormalTexture.VertexDeclaration, this.vertices.Count, BufferUsage.WriteOnly);
    this.vbo.SetData(this.vertices.ToArray());
    this.vertices = null;
}
最后,我使用以下方法绘制:

this.game.GraphicsDevice.SetVertexBuffer(this.vbo);
this.game.GraphicsDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, this.vbo.VertexCount / 3);
我以前从未使用过索引缓冲区。如何将其保持为VertexPositionNormalTexture,但同时使用索引缓冲区使其绘制速度更快?此外,如何将纹理应用于特定的面