Skip to main content
Fixed the indentation, couldnt see the preview for some reason
Source Link
Bevin
  • 972
  • 6
  • 19
  • 35
 public class BasicShape {

  public Vector3 shapeSize;
  public Vector3 shapePosition;
  private VertexPositionNormalTexture[][] shapeVertices;
  private int shapeTriangles;
  private VertexBuffer shapeBuffer;
  public Texture2D topTexture;
  public Texture2D frontTexture;
  public Texture2D backTexture;
  public Texture2D leftTexture;
  public Texture2D rightTexture;
  public Texture2D bottomTexture;

  public BasicShape(Vector3 size, Vector3 position) {
   shapeSize = size;
   shapePosition = position;
  }

  private void BuildShape() {
   shapeTriangles = 12;

 public Vector3 shapeVerticesshapeSize;
 =public newVector3 VertexPositionNormalTexture[6][];shapePosition;
 private VertexPositionNormalTexture[][] for(shapeVertices;
 private int ishapeTriangles;
 =private 0;VertexBuffer ishapeBuffer;
 <public 6;Texture2D i++)topTexture;
 {public Texture2D frontTexture;
 public Texture2D backTexture;
 shapeVertices[i]public =Texture2D newleftTexture;
 VertexPositionNormalTexture[6];public Texture2D rightTexture;
 public Texture2D }bottomTexture;

   Vector3 topLeftFront = shapePosition +
    new Vector3(0.0f, 1.0f, 0.0f) * shapeSize;
   Vector3 bottomLeftFront = shapePosition +
    new Vector3(0.0f, 0.0f, 0.0f) * shapeSize;
   Vector3 topRightFront = shapePosition +
    newpublic Vector3BasicShape(1.0f, 1.0f, 0.0f) * shapeSize;
   Vector3 bottomRightFront = shapePosition +
    new Vector3(1.0f, 0.0fsize, 0.0f) * shapeSize;
   Vector3 topLeftBack = shapePosition +
    new Vector3(0.0f, 1.0f, 1.0fposition) * shapeSize;{
   Vector3 topRightBackshapeSize = shapePosition +
    new Vector3(1.0f, 1.0f, 1.0f) * shapeSize;size;
   Vector3 bottomLeftBack = shapePosition +
    new Vector3(0.0f, 0.0f, 1.0f) * shapeSize;
   Vector3 bottomRightBack = shapePosition +position;
    new Vector3(1.0f, 0.0f, 1.0f) * shapeSize;}

   Vector3 topLeftFront2 = shapePosition +
    new Vector3(0.0f, 1.0f, 0.0f) * shapeSize;
   Vector3 bottomLeftFront2 = shapePosition +
    new Vector3(0.0f, 0.0f, 0.0f) * shapeSize;
   Vector3 topRightFront2 = shapePosition +
    new Vector3(1.0f, 1.0f, 0.0f) * shapeSize;
   Vector3 bottomRightFront2 = shapePosition +
    new Vector3(1.0f, 0.0f, 0.0f) * shapeSize;
   Vector3 topLeftBack2 = shapePosition +
    new Vector3(0.0f, 1.0f, 1.0f) * shapeSize;
   Vector3 topRightBack2 = shapePosition +
    new Vector3(1.0f, 1.0f, 1.0f) * shapeSize;
   Vector3 bottomLeftBack2 = shapePosition +
   private newvoid Vector3BuildShape(0.0f, 0.0f, 1.0f) * shapeSize;{
   Vector3 bottomRightBack2shapeTriangles = shapePosition +
    new Vector3(1.0f, 0.0f, 1.0f) * shapeSize;12;

   Vector3 topLeftFront3 = shapePosition +
    new Vector3(0.0f, 1.0f, 0.0f) * shapeSize;
   Vector3 bottomLeftFront3 = shapePosition +
    new Vector3(0.0f, 0.0f, 0.0f) * shapeSize;
   Vector3 topRightFront3 = shapePosition +
    new Vector3(1.0f, 1.0f, 0.0f) * shapeSize;
   Vector3 bottomRightFront3 = shapePosition +
    new Vector3(1.0f, 0.0f, 0.0f) * shapeSize;
   Vector3 topLeftBack3 = shapePosition +
    new Vector3(0.0f, 1.0f, 1.0f) * shapeSize;
   Vector3 topRightBack3 = shapePosition +
    new Vector3(1.0f, 1.0f, 1.0f) * shapeSize;
   Vector3 bottomLeftBack3 = shapePosition +
    new Vector3(0.0f, 0.0f, 1.0f) * shapeSize;
   Vector3 bottomRightBack3shapeVertices = shapePosition +
    new Vector3(1.0f, 0.0f, 1.0f) * shapeSize;
   VertexPositionNormalTexture[6][];
   Vector3 frontNormal = new Vector3for(0.0f, 0.0f, 1.0f) * shapeSize;
   Vector3int backNormali = new Vector3(0.0f, 0.0f, -1.0f) * shapeSize;
   Vector3 topNormal =0; newi Vector3(0.0f,< 1.0f,6; 0.0fi++) * shapeSize;{
   Vector3 bottomNormal = new Vector3(0.0f, -1.0f, 0.0f) * shapeSize;
   Vector3 leftNormalshapeVertices[i] = new Vector3(-1.0f, 0.0f, 0.0f) * shapeSize;VertexPositionNormalTexture[6];
   Vector3 rightNormal = new Vector3(1.0f, 0.0f, 0.0f) * shapeSize;}

   Vector2 textureTopLeftVector3 topLeftFront = shapePosition +
     new Vector2Vector3(1f *0.0f, shapeSize1.X0f, 0.0f) * shapeSize.Y);shapeSize;
   Vector2 textureTopRightVector3 bottomLeftFront = shapePosition +
     new Vector2Vector3(0.0f *, shapeSize0.X0f, 0.0f) * shapeSizeshapeSize;
    Vector3 topRightFront = shapePosition +
     new Vector3(1.Y0f, 1.0f, 0.0f); * shapeSize;
   Vector2 textureBottomLeftVector3 bottomRightFront = shapePosition +
     new Vector2Vector3(1f1.0f, 0.0f, 0.0f) * shapeSizeshapeSize;
    Vector3 topLeftBack = shapePosition +
     new Vector3(0.X0f, 1f1.0f, 1.0f) * shapeSizeshapeSize;
    Vector3 topRightBack = shapePosition +
     new Vector3(1.Y0f, 1.0f, 1.0f); * shapeSize;
   Vector2 textureBottomRightVector3 bottomLeftBack = shapePosition +
     new Vector2Vector3(0.0f *, shapeSize0.X0f, 1f1.0f) * shapeSizeshapeSize;
    Vector3 bottomRightBack = shapePosition +
     new Vector3(1.Y0f, 0.0f, 1.0f); * shapeSize;

   // FrontVector3 face.topLeftFront2 = shapePosition +
   shapeVertices[0][0] = new VertexPositionNormalTextureVector3(0.0f, 1.0f, 0.0f) * shapeSize;
    topLeftFrontVector3 bottomLeftFront2 = shapePosition +
     new Vector3(0.0f, frontNormal0.0f, textureTopLeft0.0f); * shapeSize;
   shapeVertices[0][1] Vector3 topRightFront2 = newshapePosition VertexPositionNormalTexture(+
    bottomLeftFront new Vector3(1.0f, frontNormal1.0f, textureBottomLeft0.0f); * shapeSize;
   shapeVertices[0][2] Vector3 bottomRightFront2 = newshapePosition VertexPositionNormalTexture(+
    topRightFront new Vector3(1.0f, frontNormal0.0f, textureTopRight0.0f); * shapeSize;
   shapeVertices[0][3] Vector3 topLeftBack2 = newshapePosition VertexPositionNormalTexture(+
    bottomLeftFront new Vector3(0.0f, frontNormal1.0f, textureBottomLeft1.0f); * shapeSize;
   shapeVertices[0][4] Vector3 topRightBack2 = newshapePosition VertexPositionNormalTexture(+
    bottomRightFront new Vector3(1.0f, frontNormal1.0f, textureBottomRight1.0f); * shapeSize;
   shapeVertices[0][5] Vector3 bottomLeftBack2 = shapePosition +
     new VertexPositionNormalTextureVector3(0.0f, 0.0f, 1.0f) * shapeSize;
    topRightFrontVector3 bottomRightBack2 = shapePosition +
     new Vector3(1.0f, frontNormal0.0f, textureTopRight1.0f); * shapeSize;

   // BackVector3 face.topLeftFront3 = shapePosition +
   shapeVertices[1][0] = new VertexPositionNormalTextureVector3(0.0f, 1.0f, 0.0f) * shapeSize;
    topLeftBackVector3 bottomLeftFront3 = shapePosition +
     new Vector3(0.0f, backNormal0.0f, textureTopRight0.0f); * shapeSize;
   shapeVertices[1][1] Vector3 topRightFront3 = newshapePosition VertexPositionNormalTexture(+
    topRightBack new Vector3(1.0f, backNormal1.0f, textureTopLeft0.0f); * shapeSize;
   shapeVertices[1][2] Vector3 bottomRightFront3 = newshapePosition VertexPositionNormalTexture(+
    bottomLeftBack new Vector3(1.0f, backNormal0.0f, textureBottomRight0.0f); * shapeSize;
   shapeVertices[1][3] Vector3 topLeftBack3 = newshapePosition VertexPositionNormalTexture(+
    bottomLeftBack new Vector3(0.0f, backNormal1.0f, textureBottomRight1.0f); * shapeSize;
   shapeVertices[1][4] Vector3 topRightBack3 = newshapePosition VertexPositionNormalTexture(+
    topRightBack new Vector3(1.0f, backNormal1.0f, textureTopLeft1.0f); * shapeSize;
   shapeVertices[1][5] Vector3 bottomLeftBack3 = shapePosition +
     new VertexPositionNormalTextureVector3(0.0f, 0.0f, 1.0f) * shapeSize;
    bottomRightBackVector3 bottomRightBack3 = shapePosition +
     new Vector3(1.0f, backNormal0.0f, textureBottomLeft1.0f); * shapeSize;

   // Top face.
  Vector3 shapeVertices[2][0]frontNormal = new VertexPositionNormalTextureVector3(
    topLeftFront20.0f, topNormal0.0f, textureBottomLeft1.0f);
 * shapeSize;
 shapeVertices[2][1] = new VertexPositionNormalTexture(
Vector3 backNormal = new topRightBack2Vector3(0.0f, topNormal0.0f, textureTopRight-1.0f);
 * shapeSize;
 shapeVertices[2][2] = new VertexPositionNormalTexture(
Vector3 topNormal = new topLeftBack2Vector3(0.0f, topNormal1.0f, textureTopLeft0.0f);
 * shapeSize;
 shapeVertices[2][3] = new VertexPositionNormalTexture(
Vector3 bottomNormal = new topLeftFront2Vector3(0.0f, topNormal-1.0f, textureBottomLeft0.0f);
 * shapeSize;
 shapeVertices[2][4] = new VertexPositionNormalTexture(
Vector3 leftNormal = new topRightFront2Vector3(-1.0f, topNormal0.0f, textureBottomRight0.0f);
 * shapeSize;
 shapeVertices[2][5] = new VertexPositionNormalTexture(
Vector3 rightNormal = new topRightBack2Vector3(1.0f, topNormal0.0f, textureTopRight0.0f); * shapeSize;

   // Bottom face.
  Vector2 shapeVertices[3][0]textureTopLeft = new VertexPositionNormalTextureVector2(
  1f * bottomLeftFront2shapeSize.X, bottomNormal,0.0f textureTopLeft* shapeSize.Y);
   shapeVertices[3][1] = new VertexPositionNormalTexture(
    bottomLeftBack2, bottomNormal, textureBottomLeft);
  Vector2 shapeVertices[3][2]textureTopRight = new VertexPositionNormalTextureVector2(
  0.0f * bottomRightBack2shapeSize.X, bottomNormal,0.0f textureBottomRight* shapeSize.Y);
   shapeVertices[3][3] Vector2 textureBottomLeft = new VertexPositionNormalTextureVector2(
  1f * bottomLeftFront2shapeSize.X, bottomNormal,1f textureTopLeft* shapeSize.Y);
   shapeVertices[3][4] = new VertexPositionNormalTexture(
    bottomRightBack2, bottomNormal,Vector2 textureBottomRight);
   shapeVertices[3][5] = new VertexPositionNormalTextureVector2(
  0.0f * bottomRightFront2shapeSize.X, bottomNormal,1f textureTopRight* shapeSize.Y);

    // LeftFront face.
   shapeVertices[4][0] shapeVertices[0][0] = new VertexPositionNormalTexture(
    topLeftFront3 topLeftFront, leftNormalfrontNormal, textureTopRighttextureTopLeft);
   shapeVertices[4][1] shapeVertices[0][1] = new VertexPositionNormalTexture(
    bottomLeftBack3 bottomLeftFront, leftNormalfrontNormal, textureBottomLeft);
   shapeVertices[4][2] shapeVertices[0][2] = new VertexPositionNormalTexture(
    bottomLeftFront3 topRightFront, leftNormalfrontNormal, textureBottomRighttextureTopRight);
   shapeVertices[4][3] shapeVertices[0][3] = new VertexPositionNormalTexture(
    topLeftBack3 bottomLeftFront, leftNormalfrontNormal, textureTopLefttextureBottomLeft);
   shapeVertices[4][4] shapeVertices[0][4] = new VertexPositionNormalTexture(
    bottomLeftBack3 bottomRightFront, leftNormalfrontNormal, textureBottomLefttextureBottomRight);
   shapeVertices[4][5] shapeVertices[0][5] = new VertexPositionNormalTexture(
    topLeftFront3 topRightFront, leftNormalfrontNormal, textureTopRight);

    // RightBack face.
   shapeVertices[5][0] shapeVertices[1][0] = new VertexPositionNormalTexture(
    topRightFront3 topLeftBack, rightNormalbackNormal, textureTopLefttextureTopRight);
   shapeVertices[5][1] shapeVertices[1][1] = new VertexPositionNormalTexture(
    bottomRightFront3 topRightBack, rightNormalbackNormal, textureBottomLefttextureTopLeft);
   shapeVertices[5][2] shapeVertices[1][2] = new VertexPositionNormalTexture(
    bottomRightBack3 bottomLeftBack, rightNormalbackNormal, textureBottomRight);
   shapeVertices[5][3] shapeVertices[1][3] = new VertexPositionNormalTexture(
    topRightBack3 bottomLeftBack, rightNormalbackNormal, textureTopRighttextureBottomRight);
   shapeVertices[5][4] shapeVertices[1][4] = new VertexPositionNormalTexture(
    topRightFront3 topRightBack, rightNormalbackNormal, textureTopLeft);
   shapeVertices[5][5] shapeVertices[1][5] = new VertexPositionNormalTexture(
    bottomRightBack3 bottomRightBack, rightNormalbackNormal, textureBottomRighttextureBottomLeft);
  }

  public void SetTopTexture(Texture2D// tex)Top {face.
   topTexture shapeVertices[2][0] = tex;new VertexPositionNormalTexture(
  }
  public voidtopLeftFront2, SetSideTexture(Texture2DtopNormal, textextureBottomLeft) {;
   frontTexture shapeVertices[2][1] = tex;new VertexPositionNormalTexture(
   backTexture = tex;topRightBack2, topNormal, textureTopRight);
   leftTexture shapeVertices[2][2] = tex;new VertexPositionNormalTexture(
   rightTexture  topLeftBack2, topNormal, textureTopLeft);
    shapeVertices[2][3] = tex;new VertexPositionNormalTexture(
  }   topLeftFront2, topNormal, textureBottomLeft);
  public void SetBottomTextureshapeVertices[2][4] = new VertexPositionNormalTexture(Texture2D 
 tex) {   topRightFront2, topNormal, textureBottomRight);
   bottomTexture shapeVertices[2][5] = tex;new VertexPositionNormalTexture(
  }   topRightBack2, topNormal, textureTopRight);

  public void RenderShape// Bottom face.
    shapeVertices[3][0] = new VertexPositionNormalTexture(GraphicsDevice 
 device    bottomLeftFront2, EffectbottomNormal, effecttextureTopLeft);
 {   shapeVertices[3][1] = new VertexPositionNormalTexture(
   BuildShape  bottomLeftBack2, bottomNormal, textureBottomLeft);
    shapeVertices[3][2] = new VertexPositionNormalTexture(
     bottomRightBack2, bottomNormal, textureBottomRight);
    shapeVertices[3][3] = new VertexPositionNormalTexture(
     bottomLeftFront2, bottomNormal, textureTopLeft);
    shapeVertices[3][4] = new VertexPositionNormalTexture(
     bottomRightBack2, bottomNormal, textureBottomRight);
    shapeVertices[3][5] = new VertexPositionNormalTexture(
     bottomRightFront2, bottomNormal, textureTopRight);

    // Left face.
    shapeVertices[4][0] = new VertexPositionNormalTexture(
     topLeftFront3, leftNormal, textureTopRight);
    shapeVertices[4][1] = new VertexPositionNormalTexture(
     bottomLeftBack3, leftNormal, textureBottomLeft);
    shapeVertices[4][2] = new VertexPositionNormalTexture(
     bottomLeftFront3, leftNormal, textureBottomRight);
    shapeVertices[4][3] = new VertexPositionNormalTexture(
     topLeftBack3, leftNormal, textureTopLeft);
    shapeVertices[4][4] = new VertexPositionNormalTexture(
     bottomLeftBack3, leftNormal, textureBottomLeft);
    shapeVertices[4][5] = new VertexPositionNormalTexture(
     topLeftFront3, leftNormal, textureTopRight);

   effect.Parameters["xTexture"] // Right face.SetValue(topTexture);
   device.DrawUserPrimitives shapeVertices[5][0] = new VertexPositionNormalTexture(PrimitiveType.TriangleList, 
 shapeVertices[2]    topRightFront3, 0rightNormal, 2textureTopLeft);
   effect.Parameters["xTexture"].SetValue shapeVertices[5][1] = new VertexPositionNormalTexture(bottomTexture);
   device.DrawUserPrimitives(PrimitiveType.TriangleList, shapeVertices[3] bottomRightFront3, 0rightNormal, 2textureBottomLeft);
   effect.Parameters["xTexture"].SetValue shapeVertices[5][2] = new VertexPositionNormalTexture(frontTexture);
   device.DrawUserPrimitives(PrimitiveType.TriangleList, shapeVertices[0] bottomRightBack3, 0rightNormal, 2textureBottomRight);
   effect.Parameters["xTexture"].SetValue shapeVertices[5][3] = new VertexPositionNormalTexture(backTexture);
   device.DrawUserPrimitives(PrimitiveType.TriangleList, shapeVertices[1] topRightBack3, 0rightNormal, 2textureTopRight);
   effect.Parameters["xTexture"].SetValue shapeVertices[5][4] = new VertexPositionNormalTexture(leftTexture);
   device.DrawUserPrimitives(PrimitiveType.TriangleList, shapeVertices[4] topRightFront3, 0rightNormal, 2textureTopLeft);
   effect.Parameters["xTexture"].SetValue shapeVertices[5][5] = new VertexPositionNormalTexture(rightTexture);
   device.DrawUserPrimitives(PrimitiveType.TriangleList, shapeVertices[5] bottomRightBack3, 0rightNormal, 2textureBottomRight);
 }

 public }void SetTopTexture(Texture2D tex) {
    topTexture = tex;
 }
 public void SetSideTexture(Texture2D tex) {
    frontTexture = tex;
    backTexture = tex;
    leftTexture = tex;
    rightTexture = tex;
 }
 public void SetBottomTexture(Texture2D tex) {
    bottomTexture = tex;
 }

And inpublic thevoid DrawRenderShape(GraphicsDevice methoddevice, forEffect myeffect) game:{
    BuildShape();

 cubeEffect.CurrentTechnique = cubeEffect.Techniques["Textured"];
 foreach(EffectPass pass in cubeEffect.CurrentTechnique.Passes) {
  pass.Apply();
  BasicShape s = new BasicShape(new Vector3(1, 1, 1), new Vector3(0, 0, 3));
  s.SetTopTexture(TextureLoader.GetTexture(4));
  s.SetSideTexture(TextureLoader.GetTexture(35));
  s.SetBottomTexture(TextureLoader.GetTexture(4));
  s.RenderShape(GraphicsDevice, cubeEffect);   

    effect.Parameters["xTexture"].SetValue(topTexture);
    device.DrawUserPrimitives(PrimitiveType.TriangleList, shapeVertices[2], 0, 2);
    effect.Parameters["xTexture"].SetValue(bottomTexture);
    device.DrawUserPrimitives(PrimitiveType.TriangleList, shapeVertices[3], 0, 2);
    effect.Parameters["xTexture"].SetValue(frontTexture);
    device.DrawUserPrimitives(PrimitiveType.TriangleList, shapeVertices[0], 0, 2);
    effect.Parameters["xTexture"].SetValue(backTexture);
    device.DrawUserPrimitives(PrimitiveType.TriangleList, shapeVertices[1], 0, 2);
    effect.Parameters["xTexture"].SetValue(leftTexture);
    device.DrawUserPrimitives(PrimitiveType.TriangleList, shapeVertices[4], 0, 2);
    effect.Parameters["xTexture"].SetValue(rightTexture);
    device.DrawUserPrimitives(PrimitiveType.TriangleList, shapeVertices[5], 0, 2);

 }

}

And in the Draw method for my game:

cubeEffect.CurrentTechnique = cubeEffect.Techniques["Textured"];
   foreach(EffectPass pass in cubeEffect.CurrentTechnique.Passes) {
      pass.Apply();
      BasicShape s = new BasicShape(new Vector3(1, 1, 1), new Vector3(0, 0, 3));
      s.SetTopTexture(TextureLoader.GetTexture(4));
      s.SetSideTexture(TextureLoader.GetTexture(35));
      s.SetBottomTexture(TextureLoader.GetTexture(4));
      s.RenderShape(GraphicsDevice, cubeEffect);   

  }
 public class BasicShape {

  public Vector3 shapeSize;
  public Vector3 shapePosition;
  private VertexPositionNormalTexture[][] shapeVertices;
  private int shapeTriangles;
  private VertexBuffer shapeBuffer;
  public Texture2D topTexture;
  public Texture2D frontTexture;
  public Texture2D backTexture;
  public Texture2D leftTexture;
  public Texture2D rightTexture;
  public Texture2D bottomTexture;

  public BasicShape(Vector3 size, Vector3 position) {
   shapeSize = size;
   shapePosition = position;
  }

  private void BuildShape() {
   shapeTriangles = 12;

   shapeVertices = new VertexPositionNormalTexture[6][];
   for(int i = 0; i < 6; i++) {
    shapeVertices[i] = new VertexPositionNormalTexture[6];
   }

   Vector3 topLeftFront = shapePosition +
    new Vector3(0.0f, 1.0f, 0.0f) * shapeSize;
   Vector3 bottomLeftFront = shapePosition +
    new Vector3(0.0f, 0.0f, 0.0f) * shapeSize;
   Vector3 topRightFront = shapePosition +
    new Vector3(1.0f, 1.0f, 0.0f) * shapeSize;
   Vector3 bottomRightFront = shapePosition +
    new Vector3(1.0f, 0.0f, 0.0f) * shapeSize;
   Vector3 topLeftBack = shapePosition +
    new Vector3(0.0f, 1.0f, 1.0f) * shapeSize;
   Vector3 topRightBack = shapePosition +
    new Vector3(1.0f, 1.0f, 1.0f) * shapeSize;
   Vector3 bottomLeftBack = shapePosition +
    new Vector3(0.0f, 0.0f, 1.0f) * shapeSize;
   Vector3 bottomRightBack = shapePosition +
    new Vector3(1.0f, 0.0f, 1.0f) * shapeSize;

   Vector3 topLeftFront2 = shapePosition +
    new Vector3(0.0f, 1.0f, 0.0f) * shapeSize;
   Vector3 bottomLeftFront2 = shapePosition +
    new Vector3(0.0f, 0.0f, 0.0f) * shapeSize;
   Vector3 topRightFront2 = shapePosition +
    new Vector3(1.0f, 1.0f, 0.0f) * shapeSize;
   Vector3 bottomRightFront2 = shapePosition +
    new Vector3(1.0f, 0.0f, 0.0f) * shapeSize;
   Vector3 topLeftBack2 = shapePosition +
    new Vector3(0.0f, 1.0f, 1.0f) * shapeSize;
   Vector3 topRightBack2 = shapePosition +
    new Vector3(1.0f, 1.0f, 1.0f) * shapeSize;
   Vector3 bottomLeftBack2 = shapePosition +
    new Vector3(0.0f, 0.0f, 1.0f) * shapeSize;
   Vector3 bottomRightBack2 = shapePosition +
    new Vector3(1.0f, 0.0f, 1.0f) * shapeSize;

   Vector3 topLeftFront3 = shapePosition +
    new Vector3(0.0f, 1.0f, 0.0f) * shapeSize;
   Vector3 bottomLeftFront3 = shapePosition +
    new Vector3(0.0f, 0.0f, 0.0f) * shapeSize;
   Vector3 topRightFront3 = shapePosition +
    new Vector3(1.0f, 1.0f, 0.0f) * shapeSize;
   Vector3 bottomRightFront3 = shapePosition +
    new Vector3(1.0f, 0.0f, 0.0f) * shapeSize;
   Vector3 topLeftBack3 = shapePosition +
    new Vector3(0.0f, 1.0f, 1.0f) * shapeSize;
   Vector3 topRightBack3 = shapePosition +
    new Vector3(1.0f, 1.0f, 1.0f) * shapeSize;
   Vector3 bottomLeftBack3 = shapePosition +
    new Vector3(0.0f, 0.0f, 1.0f) * shapeSize;
   Vector3 bottomRightBack3 = shapePosition +
    new Vector3(1.0f, 0.0f, 1.0f) * shapeSize;
   
   Vector3 frontNormal = new Vector3(0.0f, 0.0f, 1.0f) * shapeSize;
   Vector3 backNormal = new Vector3(0.0f, 0.0f, -1.0f) * shapeSize;
   Vector3 topNormal = new Vector3(0.0f, 1.0f, 0.0f) * shapeSize;
   Vector3 bottomNormal = new Vector3(0.0f, -1.0f, 0.0f) * shapeSize;
   Vector3 leftNormal = new Vector3(-1.0f, 0.0f, 0.0f) * shapeSize;
   Vector3 rightNormal = new Vector3(1.0f, 0.0f, 0.0f) * shapeSize;

   Vector2 textureTopLeft = new Vector2(1f * shapeSize.X, 0.0f * shapeSize.Y);
   Vector2 textureTopRight = new Vector2(0.0f * shapeSize.X, 0.0f * shapeSize.Y);
   Vector2 textureBottomLeft = new Vector2(1f * shapeSize.X, 1f * shapeSize.Y);
   Vector2 textureBottomRight = new Vector2(0.0f * shapeSize.X, 1f * shapeSize.Y);

   // Front face.
   shapeVertices[0][0] = new VertexPositionNormalTexture(
    topLeftFront, frontNormal, textureTopLeft);
   shapeVertices[0][1] = new VertexPositionNormalTexture(
    bottomLeftFront, frontNormal, textureBottomLeft);
   shapeVertices[0][2] = new VertexPositionNormalTexture(
    topRightFront, frontNormal, textureTopRight);
   shapeVertices[0][3] = new VertexPositionNormalTexture(
    bottomLeftFront, frontNormal, textureBottomLeft);
   shapeVertices[0][4] = new VertexPositionNormalTexture(
    bottomRightFront, frontNormal, textureBottomRight);
   shapeVertices[0][5] = new VertexPositionNormalTexture(
    topRightFront, frontNormal, textureTopRight);

   // Back face.
   shapeVertices[1][0] = new VertexPositionNormalTexture(
    topLeftBack, backNormal, textureTopRight);
   shapeVertices[1][1] = new VertexPositionNormalTexture(
    topRightBack, backNormal, textureTopLeft);
   shapeVertices[1][2] = new VertexPositionNormalTexture(
    bottomLeftBack, backNormal, textureBottomRight);
   shapeVertices[1][3] = new VertexPositionNormalTexture(
    bottomLeftBack, backNormal, textureBottomRight);
   shapeVertices[1][4] = new VertexPositionNormalTexture(
    topRightBack, backNormal, textureTopLeft);
   shapeVertices[1][5] = new VertexPositionNormalTexture(
    bottomRightBack, backNormal, textureBottomLeft);

   // Top face.
   shapeVertices[2][0] = new VertexPositionNormalTexture(
    topLeftFront2, topNormal, textureBottomLeft);
   shapeVertices[2][1] = new VertexPositionNormalTexture(
    topRightBack2, topNormal, textureTopRight);
   shapeVertices[2][2] = new VertexPositionNormalTexture(
    topLeftBack2, topNormal, textureTopLeft);
   shapeVertices[2][3] = new VertexPositionNormalTexture(
    topLeftFront2, topNormal, textureBottomLeft);
   shapeVertices[2][4] = new VertexPositionNormalTexture(
    topRightFront2, topNormal, textureBottomRight);
   shapeVertices[2][5] = new VertexPositionNormalTexture(
    topRightBack2, topNormal, textureTopRight);

   // Bottom face.
   shapeVertices[3][0] = new VertexPositionNormalTexture(
    bottomLeftFront2, bottomNormal, textureTopLeft);
   shapeVertices[3][1] = new VertexPositionNormalTexture(
    bottomLeftBack2, bottomNormal, textureBottomLeft);
   shapeVertices[3][2] = new VertexPositionNormalTexture(
    bottomRightBack2, bottomNormal, textureBottomRight);
   shapeVertices[3][3] = new VertexPositionNormalTexture(
    bottomLeftFront2, bottomNormal, textureTopLeft);
   shapeVertices[3][4] = new VertexPositionNormalTexture(
    bottomRightBack2, bottomNormal, textureBottomRight);
   shapeVertices[3][5] = new VertexPositionNormalTexture(
    bottomRightFront2, bottomNormal, textureTopRight);

   // Left face.
   shapeVertices[4][0] = new VertexPositionNormalTexture(
    topLeftFront3, leftNormal, textureTopRight);
   shapeVertices[4][1] = new VertexPositionNormalTexture(
    bottomLeftBack3, leftNormal, textureBottomLeft);
   shapeVertices[4][2] = new VertexPositionNormalTexture(
    bottomLeftFront3, leftNormal, textureBottomRight);
   shapeVertices[4][3] = new VertexPositionNormalTexture(
    topLeftBack3, leftNormal, textureTopLeft);
   shapeVertices[4][4] = new VertexPositionNormalTexture(
    bottomLeftBack3, leftNormal, textureBottomLeft);
   shapeVertices[4][5] = new VertexPositionNormalTexture(
    topLeftFront3, leftNormal, textureTopRight);

   // Right face.
   shapeVertices[5][0] = new VertexPositionNormalTexture(
    topRightFront3, rightNormal, textureTopLeft);
   shapeVertices[5][1] = new VertexPositionNormalTexture(
    bottomRightFront3, rightNormal, textureBottomLeft);
   shapeVertices[5][2] = new VertexPositionNormalTexture(
    bottomRightBack3, rightNormal, textureBottomRight);
   shapeVertices[5][3] = new VertexPositionNormalTexture(
    topRightBack3, rightNormal, textureTopRight);
   shapeVertices[5][4] = new VertexPositionNormalTexture(
    topRightFront3, rightNormal, textureTopLeft);
   shapeVertices[5][5] = new VertexPositionNormalTexture(
    bottomRightBack3, rightNormal, textureBottomRight);
  }

  public void SetTopTexture(Texture2D tex) {
   topTexture = tex;
  }
  public void SetSideTexture(Texture2D tex) {
   frontTexture = tex;
   backTexture = tex;
   leftTexture = tex;
   rightTexture = tex;
  }
  public void SetBottomTexture(Texture2D tex) {
   bottomTexture = tex;
  }

  public void RenderShape(GraphicsDevice device, Effect effect) {
   BuildShape();


   effect.Parameters["xTexture"].SetValue(topTexture);
   device.DrawUserPrimitives(PrimitiveType.TriangleList, shapeVertices[2], 0, 2);
   effect.Parameters["xTexture"].SetValue(bottomTexture);
   device.DrawUserPrimitives(PrimitiveType.TriangleList, shapeVertices[3], 0, 2);
   effect.Parameters["xTexture"].SetValue(frontTexture);
   device.DrawUserPrimitives(PrimitiveType.TriangleList, shapeVertices[0], 0, 2);
   effect.Parameters["xTexture"].SetValue(backTexture);
   device.DrawUserPrimitives(PrimitiveType.TriangleList, shapeVertices[1], 0, 2);
   effect.Parameters["xTexture"].SetValue(leftTexture);
   device.DrawUserPrimitives(PrimitiveType.TriangleList, shapeVertices[4], 0, 2);
   effect.Parameters["xTexture"].SetValue(rightTexture);
   device.DrawUserPrimitives(PrimitiveType.TriangleList, shapeVertices[5], 0, 2);

  }
 }

And in the Draw method for my game:

 cubeEffect.CurrentTechnique = cubeEffect.Techniques["Textured"];
 foreach(EffectPass pass in cubeEffect.CurrentTechnique.Passes) {
  pass.Apply();
  BasicShape s = new BasicShape(new Vector3(1, 1, 1), new Vector3(0, 0, 3));
  s.SetTopTexture(TextureLoader.GetTexture(4));
  s.SetSideTexture(TextureLoader.GetTexture(35));
  s.SetBottomTexture(TextureLoader.GetTexture(4));
  s.RenderShape(GraphicsDevice, cubeEffect);   

 }
public class BasicShape {

 public Vector3 shapeSize;
 public Vector3 shapePosition;
 private VertexPositionNormalTexture[][] shapeVertices;
 private int shapeTriangles;
 private VertexBuffer shapeBuffer;
 public Texture2D topTexture;
 public Texture2D frontTexture;
 public Texture2D backTexture;
 public Texture2D leftTexture;
 public Texture2D rightTexture;
 public Texture2D bottomTexture;

 public BasicShape(Vector3 size, Vector3 position) {
    shapeSize = size;
    shapePosition = position;
 }

 private void BuildShape() {
    shapeTriangles = 12;

    shapeVertices = new VertexPositionNormalTexture[6][];
    for(int i = 0; i < 6; i++) {
        shapeVertices[i] = new VertexPositionNormalTexture[6];
    }

    Vector3 topLeftFront = shapePosition +
     new Vector3(0.0f, 1.0f, 0.0f) * shapeSize;
    Vector3 bottomLeftFront = shapePosition +
     new Vector3(0.0f, 0.0f, 0.0f) * shapeSize;
    Vector3 topRightFront = shapePosition +
     new Vector3(1.0f, 1.0f, 0.0f) * shapeSize;
    Vector3 bottomRightFront = shapePosition +
     new Vector3(1.0f, 0.0f, 0.0f) * shapeSize;
    Vector3 topLeftBack = shapePosition +
     new Vector3(0.0f, 1.0f, 1.0f) * shapeSize;
    Vector3 topRightBack = shapePosition +
     new Vector3(1.0f, 1.0f, 1.0f) * shapeSize;
    Vector3 bottomLeftBack = shapePosition +
     new Vector3(0.0f, 0.0f, 1.0f) * shapeSize;
    Vector3 bottomRightBack = shapePosition +
     new Vector3(1.0f, 0.0f, 1.0f) * shapeSize;

    Vector3 topLeftFront2 = shapePosition +
     new Vector3(0.0f, 1.0f, 0.0f) * shapeSize;
    Vector3 bottomLeftFront2 = shapePosition +
     new Vector3(0.0f, 0.0f, 0.0f) * shapeSize;
    Vector3 topRightFront2 = shapePosition +
     new Vector3(1.0f, 1.0f, 0.0f) * shapeSize;
    Vector3 bottomRightFront2 = shapePosition +
     new Vector3(1.0f, 0.0f, 0.0f) * shapeSize;
    Vector3 topLeftBack2 = shapePosition +
     new Vector3(0.0f, 1.0f, 1.0f) * shapeSize;
    Vector3 topRightBack2 = shapePosition +
     new Vector3(1.0f, 1.0f, 1.0f) * shapeSize;
    Vector3 bottomLeftBack2 = shapePosition +
     new Vector3(0.0f, 0.0f, 1.0f) * shapeSize;
    Vector3 bottomRightBack2 = shapePosition +
     new Vector3(1.0f, 0.0f, 1.0f) * shapeSize;

    Vector3 topLeftFront3 = shapePosition +
     new Vector3(0.0f, 1.0f, 0.0f) * shapeSize;
    Vector3 bottomLeftFront3 = shapePosition +
     new Vector3(0.0f, 0.0f, 0.0f) * shapeSize;
    Vector3 topRightFront3 = shapePosition +
     new Vector3(1.0f, 1.0f, 0.0f) * shapeSize;
    Vector3 bottomRightFront3 = shapePosition +
     new Vector3(1.0f, 0.0f, 0.0f) * shapeSize;
    Vector3 topLeftBack3 = shapePosition +
     new Vector3(0.0f, 1.0f, 1.0f) * shapeSize;
    Vector3 topRightBack3 = shapePosition +
     new Vector3(1.0f, 1.0f, 1.0f) * shapeSize;
    Vector3 bottomLeftBack3 = shapePosition +
     new Vector3(0.0f, 0.0f, 1.0f) * shapeSize;
    Vector3 bottomRightBack3 = shapePosition +
     new Vector3(1.0f, 0.0f, 1.0f) * shapeSize;

    Vector3 frontNormal = new Vector3(0.0f, 0.0f, 1.0f) * shapeSize;
    Vector3 backNormal = new Vector3(0.0f, 0.0f, -1.0f) * shapeSize;
    Vector3 topNormal = new Vector3(0.0f, 1.0f, 0.0f) * shapeSize;
    Vector3 bottomNormal = new Vector3(0.0f, -1.0f, 0.0f) * shapeSize;
    Vector3 leftNormal = new Vector3(-1.0f, 0.0f, 0.0f) * shapeSize;
    Vector3 rightNormal = new Vector3(1.0f, 0.0f, 0.0f) * shapeSize;

    Vector2 textureTopLeft = new Vector2(1f * shapeSize.X, 0.0f * shapeSize.Y);
    Vector2 textureTopRight = new Vector2(0.0f * shapeSize.X, 0.0f * shapeSize.Y);
    Vector2 textureBottomLeft = new Vector2(1f * shapeSize.X, 1f * shapeSize.Y);
    Vector2 textureBottomRight = new Vector2(0.0f * shapeSize.X, 1f * shapeSize.Y);

    // Front face.
    shapeVertices[0][0] = new VertexPositionNormalTexture(
     topLeftFront, frontNormal, textureTopLeft);
    shapeVertices[0][1] = new VertexPositionNormalTexture(
     bottomLeftFront, frontNormal, textureBottomLeft);
    shapeVertices[0][2] = new VertexPositionNormalTexture(
     topRightFront, frontNormal, textureTopRight);
    shapeVertices[0][3] = new VertexPositionNormalTexture(
     bottomLeftFront, frontNormal, textureBottomLeft);
    shapeVertices[0][4] = new VertexPositionNormalTexture(
     bottomRightFront, frontNormal, textureBottomRight);
    shapeVertices[0][5] = new VertexPositionNormalTexture(
     topRightFront, frontNormal, textureTopRight);

    // Back face.
    shapeVertices[1][0] = new VertexPositionNormalTexture(
     topLeftBack, backNormal, textureTopRight);
    shapeVertices[1][1] = new VertexPositionNormalTexture(
     topRightBack, backNormal, textureTopLeft);
    shapeVertices[1][2] = new VertexPositionNormalTexture(
     bottomLeftBack, backNormal, textureBottomRight);
    shapeVertices[1][3] = new VertexPositionNormalTexture(
     bottomLeftBack, backNormal, textureBottomRight);
    shapeVertices[1][4] = new VertexPositionNormalTexture(
     topRightBack, backNormal, textureTopLeft);
    shapeVertices[1][5] = new VertexPositionNormalTexture(
     bottomRightBack, backNormal, textureBottomLeft);

    // Top face.
    shapeVertices[2][0] = new VertexPositionNormalTexture(
     topLeftFront2, topNormal, textureBottomLeft);
    shapeVertices[2][1] = new VertexPositionNormalTexture(
     topRightBack2, topNormal, textureTopRight);
    shapeVertices[2][2] = new VertexPositionNormalTexture(
     topLeftBack2, topNormal, textureTopLeft);
    shapeVertices[2][3] = new VertexPositionNormalTexture(
     topLeftFront2, topNormal, textureBottomLeft);
    shapeVertices[2][4] = new VertexPositionNormalTexture( 
     topRightFront2, topNormal, textureBottomRight);
    shapeVertices[2][5] = new VertexPositionNormalTexture(
     topRightBack2, topNormal, textureTopRight);

    // Bottom face.
    shapeVertices[3][0] = new VertexPositionNormalTexture( 
     bottomLeftFront2, bottomNormal, textureTopLeft);
    shapeVertices[3][1] = new VertexPositionNormalTexture(
     bottomLeftBack2, bottomNormal, textureBottomLeft);
    shapeVertices[3][2] = new VertexPositionNormalTexture(
     bottomRightBack2, bottomNormal, textureBottomRight);
    shapeVertices[3][3] = new VertexPositionNormalTexture(
     bottomLeftFront2, bottomNormal, textureTopLeft);
    shapeVertices[3][4] = new VertexPositionNormalTexture(
     bottomRightBack2, bottomNormal, textureBottomRight);
    shapeVertices[3][5] = new VertexPositionNormalTexture(
     bottomRightFront2, bottomNormal, textureTopRight);

    // Left face.
    shapeVertices[4][0] = new VertexPositionNormalTexture(
     topLeftFront3, leftNormal, textureTopRight);
    shapeVertices[4][1] = new VertexPositionNormalTexture(
     bottomLeftBack3, leftNormal, textureBottomLeft);
    shapeVertices[4][2] = new VertexPositionNormalTexture(
     bottomLeftFront3, leftNormal, textureBottomRight);
    shapeVertices[4][3] = new VertexPositionNormalTexture(
     topLeftBack3, leftNormal, textureTopLeft);
    shapeVertices[4][4] = new VertexPositionNormalTexture(
     bottomLeftBack3, leftNormal, textureBottomLeft);
    shapeVertices[4][5] = new VertexPositionNormalTexture(
     topLeftFront3, leftNormal, textureTopRight);

    // Right face.
    shapeVertices[5][0] = new VertexPositionNormalTexture( 
     topRightFront3, rightNormal, textureTopLeft);
    shapeVertices[5][1] = new VertexPositionNormalTexture(
     bottomRightFront3, rightNormal, textureBottomLeft);
    shapeVertices[5][2] = new VertexPositionNormalTexture(
     bottomRightBack3, rightNormal, textureBottomRight);
    shapeVertices[5][3] = new VertexPositionNormalTexture(
     topRightBack3, rightNormal, textureTopRight);
    shapeVertices[5][4] = new VertexPositionNormalTexture(
     topRightFront3, rightNormal, textureTopLeft);
    shapeVertices[5][5] = new VertexPositionNormalTexture(
     bottomRightBack3, rightNormal, textureBottomRight);
 }

 public void SetTopTexture(Texture2D tex) {
    topTexture = tex;
 }
 public void SetSideTexture(Texture2D tex) {
    frontTexture = tex;
    backTexture = tex;
    leftTexture = tex;
    rightTexture = tex;
 }
 public void SetBottomTexture(Texture2D tex) {
    bottomTexture = tex;
 }

 public void RenderShape(GraphicsDevice device, Effect effect) {
    BuildShape();


    effect.Parameters["xTexture"].SetValue(topTexture);
    device.DrawUserPrimitives(PrimitiveType.TriangleList, shapeVertices[2], 0, 2);
    effect.Parameters["xTexture"].SetValue(bottomTexture);
    device.DrawUserPrimitives(PrimitiveType.TriangleList, shapeVertices[3], 0, 2);
    effect.Parameters["xTexture"].SetValue(frontTexture);
    device.DrawUserPrimitives(PrimitiveType.TriangleList, shapeVertices[0], 0, 2);
    effect.Parameters["xTexture"].SetValue(backTexture);
    device.DrawUserPrimitives(PrimitiveType.TriangleList, shapeVertices[1], 0, 2);
    effect.Parameters["xTexture"].SetValue(leftTexture);
    device.DrawUserPrimitives(PrimitiveType.TriangleList, shapeVertices[4], 0, 2);
    effect.Parameters["xTexture"].SetValue(rightTexture);
    device.DrawUserPrimitives(PrimitiveType.TriangleList, shapeVertices[5], 0, 2);

 }

}

And in the Draw method for my game:

cubeEffect.CurrentTechnique = cubeEffect.Techniques["Textured"];
   foreach(EffectPass pass in cubeEffect.CurrentTechnique.Passes) {
      pass.Apply();
      BasicShape s = new BasicShape(new Vector3(1, 1, 1), new Vector3(0, 0, 3));
      s.SetTopTexture(TextureLoader.GetTexture(4));
      s.SetSideTexture(TextureLoader.GetTexture(35));
      s.SetBottomTexture(TextureLoader.GetTexture(4));
      s.RenderShape(GraphicsDevice, cubeEffect);   

  }
code formatting
Source Link
ChrisF
  • 137.6k
  • 31
  • 265
  • 335

public class BasicShape {

public Vector3 shapeSize; public Vector3 shapePosition; private VertexPositionNormalTexture[][] shapeVertices; private int shapeTriangles; private VertexBuffer shapeBuffer; public Texture2D topTexture; public Texture2D frontTexture; public Texture2D backTexture; public Texture2D leftTexture; public Texture2D rightTexture; public Texture2D bottomTexture;

public BasicShape(Vector3 size, Vector3 position) { shapeSize = size; shapePosition = position; }

private void BuildShape() { shapeTriangles = 12;

shapeVertices = new VertexPositionNormalTexture[6][]; for(int i = 0; i < 6; i++) { shapeVertices[i] = new VertexPositionNormalTexture[6]; }

Vector3 topLeftFront = shapePosition + new Vector3(0.0f, 1.0f, 0.0f) * shapeSize; Vector3 bottomLeftFront = shapePosition + new Vector3(0.0f, 0.0f, 0.0f) * shapeSize; Vector3 topRightFront = shapePosition + new Vector3(1.0f, 1.0f, 0.0f) * shapeSize; Vector3 bottomRightFront = shapePosition + new Vector3(1.0f, 0.0f, 0.0f) * shapeSize; Vector3 topLeftBack = shapePosition + new Vector3(0.0f, 1.0f, 1.0f) * shapeSize; Vector3 topRightBack = shapePosition + new Vector3(1.0f, 1.0f, 1.0f) * shapeSize; Vector3 bottomLeftBack = shapePosition + new Vector3(0.0f, 0.0f, 1.0f) * shapeSize; Vector3 bottomRightBack = shapePosition + new Vector3(1.0f, 0.0f, 1.0f) * shapeSize;

Vector3 topLeftFront2 = shapePosition + new Vector3(0.0f, 1.0f, 0.0f) * shapeSize; Vector3 bottomLeftFront2 = shapePosition + new Vector3(0.0f, 0.0f, 0.0f) * shapeSize; Vector3 topRightFront2 = shapePosition + new Vector3(1.0f, 1.0f, 0.0f) * shapeSize; Vector3 bottomRightFront2 = shapePosition + new Vector3(1.0f, 0.0f, 0.0f) * shapeSize; Vector3 topLeftBack2 = shapePosition + new Vector3(0.0f, 1.0f, 1.0f) * shapeSize; Vector3 topRightBack2 = shapePosition + new Vector3(1.0f, 1.0f, 1.0f) * shapeSize; Vector3 bottomLeftBack2 = shapePosition + new Vector3(0.0f, 0.0f, 1.0f) * shapeSize; Vector3 bottomRightBack2 = shapePosition + new Vector3(1.0f, 0.0f, 1.0f) * shapeSize;

Vector3 topLeftFront3 = shapePosition + new Vector3(0.0f, 1.0f, 0.0f) * shapeSize; Vector3 bottomLeftFront3 = shapePosition + new Vector3(0.0f, 0.0f, 0.0f) * shapeSize; Vector3 topRightFront3 = shapePosition + new Vector3(1.0f, 1.0f, 0.0f) * shapeSize; Vector3 bottomRightFront3 = shapePosition + new Vector3(1.0f, 0.0f, 0.0f) * shapeSize; Vector3 topLeftBack3 = shapePosition + new Vector3(0.0f, 1.0f, 1.0f) * shapeSize; Vector3 topRightBack3 = shapePosition + new Vector3(1.0f, 1.0f, 1.0f) * shapeSize; Vector3 bottomLeftBack3 = shapePosition + new Vector3(0.0f, 0.0f, 1.0f) * shapeSize; Vector3 bottomRightBack3 = shapePosition + new Vector3(1.0f, 0.0f, 1.0f) * shapeSize;

Vector3 frontNormal = new Vector3(0.0f, 0.0f, 1.0f) * shapeSize; Vector3 backNormal = new Vector3(0.0f, 0.0f, -1.0f) * shapeSize; Vector3 topNormal = new Vector3(0.0f, 1.0f, 0.0f) * shapeSize; Vector3 bottomNormal = new Vector3(0.0f, -1.0f, 0.0f) * shapeSize; Vector3 leftNormal = new Vector3(-1.0f, 0.0f, 0.0f) * shapeSize; Vector3 rightNormal = new Vector3(1.0f, 0.0f, 0.0f) * shapeSize;

Vector2 textureTopLeft = new Vector2(1f * shapeSize.X, 0.0f * shapeSize.Y); Vector2 textureTopRight = new Vector2(0.0f * shapeSize.X, 0.0f * shapeSize.Y); Vector2 textureBottomLeft = new Vector2(1f * shapeSize.X, 1f * shapeSize.Y); Vector2 textureBottomRight = new Vector2(0.0f * shapeSize.X, 1f * shapeSize.Y);

// Front face. shapeVertices[0][0] = new VertexPositionNormalTexture( topLeftFront, frontNormal, textureTopLeft); shapeVertices0 = new VertexPositionNormalTexture( bottomLeftFront, frontNormal, textureBottomLeft); shapeVertices[0][2] = new VertexPositionNormalTexture( topRightFront, frontNormal, textureTopRight); shapeVertices[0][3] = new VertexPositionNormalTexture( bottomLeftFront, frontNormal, textureBottomLeft); shapeVertices[0][4] = new VertexPositionNormalTexture( bottomRightFront, frontNormal, textureBottomRight); shapeVertices[0][5] = new VertexPositionNormalTexture( topRightFront, frontNormal, textureTopRight);

// Back face. shapeVertices[1][0] = new VertexPositionNormalTexture( topLeftBack, backNormal, textureTopRight); shapeVertices1 = new VertexPositionNormalTexture( topRightBack, backNormal, textureTopLeft); shapeVertices[1][2] = new VertexPositionNormalTexture( bottomLeftBack, backNormal, textureBottomRight); shapeVertices[1][3] = new VertexPositionNormalTexture( bottomLeftBack, backNormal, textureBottomRight); shapeVertices[1][4] = new VertexPositionNormalTexture( topRightBack, backNormal, textureTopLeft); shapeVertices[1][5] = new VertexPositionNormalTexture( bottomRightBack, backNormal, textureBottomLeft);

// Top face. shapeVertices[2][0] = new VertexPositionNormalTexture( topLeftFront2, topNormal, textureBottomLeft); shapeVertices2 = new VertexPositionNormalTexture( topRightBack2, topNormal, textureTopRight); shapeVertices[2][2] = new VertexPositionNormalTexture( topLeftBack2, topNormal, textureTopLeft); shapeVertices[2][3] = new VertexPositionNormalTexture( topLeftFront2, topNormal, textureBottomLeft); shapeVertices[2][4] = new VertexPositionNormalTexture( topRightFront2, topNormal, textureBottomRight); shapeVertices[2][5] = new VertexPositionNormalTexture( topRightBack2, topNormal, textureTopRight);

// Bottom face. shapeVertices[3][0] = new VertexPositionNormalTexture( bottomLeftFront2, bottomNormal, textureTopLeft); shapeVertices3 = new VertexPositionNormalTexture( bottomLeftBack2, bottomNormal, textureBottomLeft); shapeVertices[3][2] = new VertexPositionNormalTexture( bottomRightBack2, bottomNormal, textureBottomRight); shapeVertices[3][3] = new VertexPositionNormalTexture( bottomLeftFront2, bottomNormal, textureTopLeft); shapeVertices[3][4] = new VertexPositionNormalTexture( bottomRightBack2, bottomNormal, textureBottomRight); shapeVertices[3][5] = new VertexPositionNormalTexture( bottomRightFront2, bottomNormal, textureTopRight);

// Left face. shapeVertices[4][0] = new VertexPositionNormalTexture( topLeftFront3, leftNormal, textureTopRight); shapeVertices4 = new VertexPositionNormalTexture( bottomLeftBack3, leftNormal, textureBottomLeft); shapeVertices[4][2] = new VertexPositionNormalTexture( bottomLeftFront3, leftNormal, textureBottomRight); shapeVertices[4][3] = new VertexPositionNormalTexture( topLeftBack3, leftNormal, textureTopLeft); shapeVertices[4][4] = new VertexPositionNormalTexture( bottomLeftBack3, leftNormal, textureBottomLeft); shapeVertices[4][5] = new VertexPositionNormalTexture( topLeftFront3, leftNormal, textureTopRight);

// Right face. shapeVertices[5][0] = new VertexPositionNormalTexture( topRightFront3, rightNormal, textureTopLeft); shapeVertices5 = new VertexPositionNormalTexture( bottomRightFront3, rightNormal, textureBottomLeft); shapeVertices[5][2] = new VertexPositionNormalTexture( bottomRightBack3, rightNormal, textureBottomRight); shapeVertices[5][3] = new VertexPositionNormalTexture( topRightBack3, rightNormal, textureTopRight); shapeVertices[5][4] = new VertexPositionNormalTexture( topRightFront3, rightNormal, textureTopLeft); shapeVertices[5][5] = new VertexPositionNormalTexture( bottomRightBack3, rightNormal, textureBottomRight); }

public void SetTopTexture(Texture2D tex) { topTexture = tex; } public void SetSideTexture(Texture2D tex) { frontTexture = tex; backTexture = tex; leftTexture = tex; rightTexture = tex; } public void SetBottomTexture(Texture2D tex) { bottomTexture = tex; }

public void RenderShape(GraphicsDevice device, Effect effect) { BuildShape();

effect.Parameters["xTexture"].SetValue(topTexture); device.DrawUserPrimitives(PrimitiveType.TriangleList, shapeVertices[2], 0, 2); effect.Parameters["xTexture"].SetValue(bottomTexture); device.DrawUserPrimitives(PrimitiveType.TriangleList, shapeVertices[3], 0, 2); effect.Parameters["xTexture"].SetValue(frontTexture); device.DrawUserPrimitives(PrimitiveType.TriangleList, shapeVertices[0], 0, 2); effect.Parameters["xTexture"].SetValue(backTexture); device.DrawUserPrimitives(PrimitiveType.TriangleList, shapeVertices1, 0, 2); effect.Parameters["xTexture"].SetValue(leftTexture); device.DrawUserPrimitives(PrimitiveType.TriangleList, shapeVertices[4], 0, 2); effect.Parameters["xTexture"].SetValue(rightTexture); device.DrawUserPrimitives(PrimitiveType.TriangleList, shapeVertices[5], 0, 2);

} }

And in the Draw method for my game:

cubeEffect.CurrentTechnique = cubeEffect.Techniques["Textured"]; foreach(EffectPass pass in cubeEffect.CurrentTechnique.Passes) { pass.Apply(); BasicShape s = new BasicShape(new Vector3(1, 1, 1), new Vector3(0, 0, 3)); s.SetTopTexture(TextureLoader.GetTexture(4)); s.SetSideTexture(TextureLoader.GetTexture(35)); s.SetBottomTexture(TextureLoader.GetTexture(4)); s.RenderShape(GraphicsDevice, cubeEffect);

}

 public class BasicShape {

  public Vector3 shapeSize;
  public Vector3 shapePosition;
  private VertexPositionNormalTexture[][] shapeVertices;
  private int shapeTriangles;
  private VertexBuffer shapeBuffer;
  public Texture2D topTexture;
  public Texture2D frontTexture;
  public Texture2D backTexture;
  public Texture2D leftTexture;
  public Texture2D rightTexture;
  public Texture2D bottomTexture;

  public BasicShape(Vector3 size, Vector3 position) {
   shapeSize = size;
   shapePosition = position;
  }

  private void BuildShape() {
   shapeTriangles = 12;

   shapeVertices = new VertexPositionNormalTexture[6][];
   for(int i = 0; i < 6; i++) {
    shapeVertices[i] = new VertexPositionNormalTexture[6];
   }

   Vector3 topLeftFront = shapePosition +
    new Vector3(0.0f, 1.0f, 0.0f) * shapeSize;
   Vector3 bottomLeftFront = shapePosition +
    new Vector3(0.0f, 0.0f, 0.0f) * shapeSize;
   Vector3 topRightFront = shapePosition +
    new Vector3(1.0f, 1.0f, 0.0f) * shapeSize;
   Vector3 bottomRightFront = shapePosition +
    new Vector3(1.0f, 0.0f, 0.0f) * shapeSize;
   Vector3 topLeftBack = shapePosition +
    new Vector3(0.0f, 1.0f, 1.0f) * shapeSize;
   Vector3 topRightBack = shapePosition +
    new Vector3(1.0f, 1.0f, 1.0f) * shapeSize;
   Vector3 bottomLeftBack = shapePosition +
    new Vector3(0.0f, 0.0f, 1.0f) * shapeSize;
   Vector3 bottomRightBack = shapePosition +
    new Vector3(1.0f, 0.0f, 1.0f) * shapeSize;

   Vector3 topLeftFront2 = shapePosition +
    new Vector3(0.0f, 1.0f, 0.0f) * shapeSize;
   Vector3 bottomLeftFront2 = shapePosition +
    new Vector3(0.0f, 0.0f, 0.0f) * shapeSize;
   Vector3 topRightFront2 = shapePosition +
    new Vector3(1.0f, 1.0f, 0.0f) * shapeSize;
   Vector3 bottomRightFront2 = shapePosition +
    new Vector3(1.0f, 0.0f, 0.0f) * shapeSize;
   Vector3 topLeftBack2 = shapePosition +
    new Vector3(0.0f, 1.0f, 1.0f) * shapeSize;
   Vector3 topRightBack2 = shapePosition +
    new Vector3(1.0f, 1.0f, 1.0f) * shapeSize;
   Vector3 bottomLeftBack2 = shapePosition +
    new Vector3(0.0f, 0.0f, 1.0f) * shapeSize;
   Vector3 bottomRightBack2 = shapePosition +
    new Vector3(1.0f, 0.0f, 1.0f) * shapeSize;

   Vector3 topLeftFront3 = shapePosition +
    new Vector3(0.0f, 1.0f, 0.0f) * shapeSize;
   Vector3 bottomLeftFront3 = shapePosition +
    new Vector3(0.0f, 0.0f, 0.0f) * shapeSize;
   Vector3 topRightFront3 = shapePosition +
    new Vector3(1.0f, 1.0f, 0.0f) * shapeSize;
   Vector3 bottomRightFront3 = shapePosition +
    new Vector3(1.0f, 0.0f, 0.0f) * shapeSize;
   Vector3 topLeftBack3 = shapePosition +
    new Vector3(0.0f, 1.0f, 1.0f) * shapeSize;
   Vector3 topRightBack3 = shapePosition +
    new Vector3(1.0f, 1.0f, 1.0f) * shapeSize;
   Vector3 bottomLeftBack3 = shapePosition +
    new Vector3(0.0f, 0.0f, 1.0f) * shapeSize;
   Vector3 bottomRightBack3 = shapePosition +
    new Vector3(1.0f, 0.0f, 1.0f) * shapeSize;
   
   Vector3 frontNormal = new Vector3(0.0f, 0.0f, 1.0f) * shapeSize;
   Vector3 backNormal = new Vector3(0.0f, 0.0f, -1.0f) * shapeSize;
   Vector3 topNormal = new Vector3(0.0f, 1.0f, 0.0f) * shapeSize;
   Vector3 bottomNormal = new Vector3(0.0f, -1.0f, 0.0f) * shapeSize;
   Vector3 leftNormal = new Vector3(-1.0f, 0.0f, 0.0f) * shapeSize;
   Vector3 rightNormal = new Vector3(1.0f, 0.0f, 0.0f) * shapeSize;

   Vector2 textureTopLeft = new Vector2(1f * shapeSize.X, 0.0f * shapeSize.Y);
   Vector2 textureTopRight = new Vector2(0.0f * shapeSize.X, 0.0f * shapeSize.Y);
   Vector2 textureBottomLeft = new Vector2(1f * shapeSize.X, 1f * shapeSize.Y);
   Vector2 textureBottomRight = new Vector2(0.0f * shapeSize.X, 1f * shapeSize.Y);

   // Front face.
   shapeVertices[0][0] = new VertexPositionNormalTexture(
    topLeftFront, frontNormal, textureTopLeft);
   shapeVertices[0][1] = new VertexPositionNormalTexture(
    bottomLeftFront, frontNormal, textureBottomLeft);
   shapeVertices[0][2] = new VertexPositionNormalTexture(
    topRightFront, frontNormal, textureTopRight);
   shapeVertices[0][3] = new VertexPositionNormalTexture(
    bottomLeftFront, frontNormal, textureBottomLeft);
   shapeVertices[0][4] = new VertexPositionNormalTexture(
    bottomRightFront, frontNormal, textureBottomRight);
   shapeVertices[0][5] = new VertexPositionNormalTexture(
    topRightFront, frontNormal, textureTopRight);

   // Back face.
   shapeVertices[1][0] = new VertexPositionNormalTexture(
    topLeftBack, backNormal, textureTopRight);
   shapeVertices[1][1] = new VertexPositionNormalTexture(
    topRightBack, backNormal, textureTopLeft);
   shapeVertices[1][2] = new VertexPositionNormalTexture(
    bottomLeftBack, backNormal, textureBottomRight);
   shapeVertices[1][3] = new VertexPositionNormalTexture(
    bottomLeftBack, backNormal, textureBottomRight);
   shapeVertices[1][4] = new VertexPositionNormalTexture(
    topRightBack, backNormal, textureTopLeft);
   shapeVertices[1][5] = new VertexPositionNormalTexture(
    bottomRightBack, backNormal, textureBottomLeft);

   // Top face.
   shapeVertices[2][0] = new VertexPositionNormalTexture(
    topLeftFront2, topNormal, textureBottomLeft);
   shapeVertices[2][1] = new VertexPositionNormalTexture(
    topRightBack2, topNormal, textureTopRight);
   shapeVertices[2][2] = new VertexPositionNormalTexture(
    topLeftBack2, topNormal, textureTopLeft);
   shapeVertices[2][3] = new VertexPositionNormalTexture(
    topLeftFront2, topNormal, textureBottomLeft);
   shapeVertices[2][4] = new VertexPositionNormalTexture(
    topRightFront2, topNormal, textureBottomRight);
   shapeVertices[2][5] = new VertexPositionNormalTexture(
    topRightBack2, topNormal, textureTopRight);

   // Bottom face.
   shapeVertices[3][0] = new VertexPositionNormalTexture(
    bottomLeftFront2, bottomNormal, textureTopLeft);
   shapeVertices[3][1] = new VertexPositionNormalTexture(
    bottomLeftBack2, bottomNormal, textureBottomLeft);
   shapeVertices[3][2] = new VertexPositionNormalTexture(
    bottomRightBack2, bottomNormal, textureBottomRight);
   shapeVertices[3][3] = new VertexPositionNormalTexture(
    bottomLeftFront2, bottomNormal, textureTopLeft);
   shapeVertices[3][4] = new VertexPositionNormalTexture(
    bottomRightBack2, bottomNormal, textureBottomRight);
   shapeVertices[3][5] = new VertexPositionNormalTexture(
    bottomRightFront2, bottomNormal, textureTopRight);

   // Left face.
   shapeVertices[4][0] = new VertexPositionNormalTexture(
    topLeftFront3, leftNormal, textureTopRight);
   shapeVertices[4][1] = new VertexPositionNormalTexture(
    bottomLeftBack3, leftNormal, textureBottomLeft);
   shapeVertices[4][2] = new VertexPositionNormalTexture(
    bottomLeftFront3, leftNormal, textureBottomRight);
   shapeVertices[4][3] = new VertexPositionNormalTexture(
    topLeftBack3, leftNormal, textureTopLeft);
   shapeVertices[4][4] = new VertexPositionNormalTexture(
    bottomLeftBack3, leftNormal, textureBottomLeft);
   shapeVertices[4][5] = new VertexPositionNormalTexture(
    topLeftFront3, leftNormal, textureTopRight);

   // Right face.
   shapeVertices[5][0] = new VertexPositionNormalTexture(
    topRightFront3, rightNormal, textureTopLeft);
   shapeVertices[5][1] = new VertexPositionNormalTexture(
    bottomRightFront3, rightNormal, textureBottomLeft);
   shapeVertices[5][2] = new VertexPositionNormalTexture(
    bottomRightBack3, rightNormal, textureBottomRight);
   shapeVertices[5][3] = new VertexPositionNormalTexture(
    topRightBack3, rightNormal, textureTopRight);
   shapeVertices[5][4] = new VertexPositionNormalTexture(
    topRightFront3, rightNormal, textureTopLeft);
   shapeVertices[5][5] = new VertexPositionNormalTexture(
    bottomRightBack3, rightNormal, textureBottomRight);
  }

  public void SetTopTexture(Texture2D tex) {
   topTexture = tex;
  }
  public void SetSideTexture(Texture2D tex) {
   frontTexture = tex;
   backTexture = tex;
   leftTexture = tex;
   rightTexture = tex;
  }
  public void SetBottomTexture(Texture2D tex) {
   bottomTexture = tex;
  }

  public void RenderShape(GraphicsDevice device, Effect effect) {
   BuildShape();


   effect.Parameters["xTexture"].SetValue(topTexture);
   device.DrawUserPrimitives(PrimitiveType.TriangleList, shapeVertices[2], 0, 2);
   effect.Parameters["xTexture"].SetValue(bottomTexture);
   device.DrawUserPrimitives(PrimitiveType.TriangleList, shapeVertices[3], 0, 2);
   effect.Parameters["xTexture"].SetValue(frontTexture);
   device.DrawUserPrimitives(PrimitiveType.TriangleList, shapeVertices[0], 0, 2);
   effect.Parameters["xTexture"].SetValue(backTexture);
   device.DrawUserPrimitives(PrimitiveType.TriangleList, shapeVertices[1], 0, 2);
   effect.Parameters["xTexture"].SetValue(leftTexture);
   device.DrawUserPrimitives(PrimitiveType.TriangleList, shapeVertices[4], 0, 2);
   effect.Parameters["xTexture"].SetValue(rightTexture);
   device.DrawUserPrimitives(PrimitiveType.TriangleList, shapeVertices[5], 0, 2);

  }
 }

And in the Draw method for my game:

 cubeEffect.CurrentTechnique = cubeEffect.Techniques["Textured"];
 foreach(EffectPass pass in cubeEffect.CurrentTechnique.Passes) {
  pass.Apply();
  BasicShape s = new BasicShape(new Vector3(1, 1, 1), new Vector3(0, 0, 3));
  s.SetTopTexture(TextureLoader.GetTexture(4));
  s.SetSideTexture(TextureLoader.GetTexture(35));
  s.SetBottomTexture(TextureLoader.GetTexture(4));
  s.RenderShape(GraphicsDevice, cubeEffect);   

 }

public class BasicShape {

public Vector3 shapeSize; public Vector3 shapePosition; private VertexPositionNormalTexture[][] shapeVertices; private int shapeTriangles; private VertexBuffer shapeBuffer; public Texture2D topTexture; public Texture2D frontTexture; public Texture2D backTexture; public Texture2D leftTexture; public Texture2D rightTexture; public Texture2D bottomTexture;

public BasicShape(Vector3 size, Vector3 position) { shapeSize = size; shapePosition = position; }

private void BuildShape() { shapeTriangles = 12;

shapeVertices = new VertexPositionNormalTexture[6][]; for(int i = 0; i < 6; i++) { shapeVertices[i] = new VertexPositionNormalTexture[6]; }

Vector3 topLeftFront = shapePosition + new Vector3(0.0f, 1.0f, 0.0f) * shapeSize; Vector3 bottomLeftFront = shapePosition + new Vector3(0.0f, 0.0f, 0.0f) * shapeSize; Vector3 topRightFront = shapePosition + new Vector3(1.0f, 1.0f, 0.0f) * shapeSize; Vector3 bottomRightFront = shapePosition + new Vector3(1.0f, 0.0f, 0.0f) * shapeSize; Vector3 topLeftBack = shapePosition + new Vector3(0.0f, 1.0f, 1.0f) * shapeSize; Vector3 topRightBack = shapePosition + new Vector3(1.0f, 1.0f, 1.0f) * shapeSize; Vector3 bottomLeftBack = shapePosition + new Vector3(0.0f, 0.0f, 1.0f) * shapeSize; Vector3 bottomRightBack = shapePosition + new Vector3(1.0f, 0.0f, 1.0f) * shapeSize;

Vector3 topLeftFront2 = shapePosition + new Vector3(0.0f, 1.0f, 0.0f) * shapeSize; Vector3 bottomLeftFront2 = shapePosition + new Vector3(0.0f, 0.0f, 0.0f) * shapeSize; Vector3 topRightFront2 = shapePosition + new Vector3(1.0f, 1.0f, 0.0f) * shapeSize; Vector3 bottomRightFront2 = shapePosition + new Vector3(1.0f, 0.0f, 0.0f) * shapeSize; Vector3 topLeftBack2 = shapePosition + new Vector3(0.0f, 1.0f, 1.0f) * shapeSize; Vector3 topRightBack2 = shapePosition + new Vector3(1.0f, 1.0f, 1.0f) * shapeSize; Vector3 bottomLeftBack2 = shapePosition + new Vector3(0.0f, 0.0f, 1.0f) * shapeSize; Vector3 bottomRightBack2 = shapePosition + new Vector3(1.0f, 0.0f, 1.0f) * shapeSize;

Vector3 topLeftFront3 = shapePosition + new Vector3(0.0f, 1.0f, 0.0f) * shapeSize; Vector3 bottomLeftFront3 = shapePosition + new Vector3(0.0f, 0.0f, 0.0f) * shapeSize; Vector3 topRightFront3 = shapePosition + new Vector3(1.0f, 1.0f, 0.0f) * shapeSize; Vector3 bottomRightFront3 = shapePosition + new Vector3(1.0f, 0.0f, 0.0f) * shapeSize; Vector3 topLeftBack3 = shapePosition + new Vector3(0.0f, 1.0f, 1.0f) * shapeSize; Vector3 topRightBack3 = shapePosition + new Vector3(1.0f, 1.0f, 1.0f) * shapeSize; Vector3 bottomLeftBack3 = shapePosition + new Vector3(0.0f, 0.0f, 1.0f) * shapeSize; Vector3 bottomRightBack3 = shapePosition + new Vector3(1.0f, 0.0f, 1.0f) * shapeSize;

Vector3 frontNormal = new Vector3(0.0f, 0.0f, 1.0f) * shapeSize; Vector3 backNormal = new Vector3(0.0f, 0.0f, -1.0f) * shapeSize; Vector3 topNormal = new Vector3(0.0f, 1.0f, 0.0f) * shapeSize; Vector3 bottomNormal = new Vector3(0.0f, -1.0f, 0.0f) * shapeSize; Vector3 leftNormal = new Vector3(-1.0f, 0.0f, 0.0f) * shapeSize; Vector3 rightNormal = new Vector3(1.0f, 0.0f, 0.0f) * shapeSize;

Vector2 textureTopLeft = new Vector2(1f * shapeSize.X, 0.0f * shapeSize.Y); Vector2 textureTopRight = new Vector2(0.0f * shapeSize.X, 0.0f * shapeSize.Y); Vector2 textureBottomLeft = new Vector2(1f * shapeSize.X, 1f * shapeSize.Y); Vector2 textureBottomRight = new Vector2(0.0f * shapeSize.X, 1f * shapeSize.Y);

// Front face. shapeVertices[0][0] = new VertexPositionNormalTexture( topLeftFront, frontNormal, textureTopLeft); shapeVertices0 = new VertexPositionNormalTexture( bottomLeftFront, frontNormal, textureBottomLeft); shapeVertices[0][2] = new VertexPositionNormalTexture( topRightFront, frontNormal, textureTopRight); shapeVertices[0][3] = new VertexPositionNormalTexture( bottomLeftFront, frontNormal, textureBottomLeft); shapeVertices[0][4] = new VertexPositionNormalTexture( bottomRightFront, frontNormal, textureBottomRight); shapeVertices[0][5] = new VertexPositionNormalTexture( topRightFront, frontNormal, textureTopRight);

// Back face. shapeVertices[1][0] = new VertexPositionNormalTexture( topLeftBack, backNormal, textureTopRight); shapeVertices1 = new VertexPositionNormalTexture( topRightBack, backNormal, textureTopLeft); shapeVertices[1][2] = new VertexPositionNormalTexture( bottomLeftBack, backNormal, textureBottomRight); shapeVertices[1][3] = new VertexPositionNormalTexture( bottomLeftBack, backNormal, textureBottomRight); shapeVertices[1][4] = new VertexPositionNormalTexture( topRightBack, backNormal, textureTopLeft); shapeVertices[1][5] = new VertexPositionNormalTexture( bottomRightBack, backNormal, textureBottomLeft);

// Top face. shapeVertices[2][0] = new VertexPositionNormalTexture( topLeftFront2, topNormal, textureBottomLeft); shapeVertices2 = new VertexPositionNormalTexture( topRightBack2, topNormal, textureTopRight); shapeVertices[2][2] = new VertexPositionNormalTexture( topLeftBack2, topNormal, textureTopLeft); shapeVertices[2][3] = new VertexPositionNormalTexture( topLeftFront2, topNormal, textureBottomLeft); shapeVertices[2][4] = new VertexPositionNormalTexture( topRightFront2, topNormal, textureBottomRight); shapeVertices[2][5] = new VertexPositionNormalTexture( topRightBack2, topNormal, textureTopRight);

// Bottom face. shapeVertices[3][0] = new VertexPositionNormalTexture( bottomLeftFront2, bottomNormal, textureTopLeft); shapeVertices3 = new VertexPositionNormalTexture( bottomLeftBack2, bottomNormal, textureBottomLeft); shapeVertices[3][2] = new VertexPositionNormalTexture( bottomRightBack2, bottomNormal, textureBottomRight); shapeVertices[3][3] = new VertexPositionNormalTexture( bottomLeftFront2, bottomNormal, textureTopLeft); shapeVertices[3][4] = new VertexPositionNormalTexture( bottomRightBack2, bottomNormal, textureBottomRight); shapeVertices[3][5] = new VertexPositionNormalTexture( bottomRightFront2, bottomNormal, textureTopRight);

// Left face. shapeVertices[4][0] = new VertexPositionNormalTexture( topLeftFront3, leftNormal, textureTopRight); shapeVertices4 = new VertexPositionNormalTexture( bottomLeftBack3, leftNormal, textureBottomLeft); shapeVertices[4][2] = new VertexPositionNormalTexture( bottomLeftFront3, leftNormal, textureBottomRight); shapeVertices[4][3] = new VertexPositionNormalTexture( topLeftBack3, leftNormal, textureTopLeft); shapeVertices[4][4] = new VertexPositionNormalTexture( bottomLeftBack3, leftNormal, textureBottomLeft); shapeVertices[4][5] = new VertexPositionNormalTexture( topLeftFront3, leftNormal, textureTopRight);

// Right face. shapeVertices[5][0] = new VertexPositionNormalTexture( topRightFront3, rightNormal, textureTopLeft); shapeVertices5 = new VertexPositionNormalTexture( bottomRightFront3, rightNormal, textureBottomLeft); shapeVertices[5][2] = new VertexPositionNormalTexture( bottomRightBack3, rightNormal, textureBottomRight); shapeVertices[5][3] = new VertexPositionNormalTexture( topRightBack3, rightNormal, textureTopRight); shapeVertices[5][4] = new VertexPositionNormalTexture( topRightFront3, rightNormal, textureTopLeft); shapeVertices[5][5] = new VertexPositionNormalTexture( bottomRightBack3, rightNormal, textureBottomRight); }

public void SetTopTexture(Texture2D tex) { topTexture = tex; } public void SetSideTexture(Texture2D tex) { frontTexture = tex; backTexture = tex; leftTexture = tex; rightTexture = tex; } public void SetBottomTexture(Texture2D tex) { bottomTexture = tex; }

public void RenderShape(GraphicsDevice device, Effect effect) { BuildShape();

effect.Parameters["xTexture"].SetValue(topTexture); device.DrawUserPrimitives(PrimitiveType.TriangleList, shapeVertices[2], 0, 2); effect.Parameters["xTexture"].SetValue(bottomTexture); device.DrawUserPrimitives(PrimitiveType.TriangleList, shapeVertices[3], 0, 2); effect.Parameters["xTexture"].SetValue(frontTexture); device.DrawUserPrimitives(PrimitiveType.TriangleList, shapeVertices[0], 0, 2); effect.Parameters["xTexture"].SetValue(backTexture); device.DrawUserPrimitives(PrimitiveType.TriangleList, shapeVertices1, 0, 2); effect.Parameters["xTexture"].SetValue(leftTexture); device.DrawUserPrimitives(PrimitiveType.TriangleList, shapeVertices[4], 0, 2); effect.Parameters["xTexture"].SetValue(rightTexture); device.DrawUserPrimitives(PrimitiveType.TriangleList, shapeVertices[5], 0, 2);

} }

And in the Draw method for my game:

cubeEffect.CurrentTechnique = cubeEffect.Techniques["Textured"]; foreach(EffectPass pass in cubeEffect.CurrentTechnique.Passes) { pass.Apply(); BasicShape s = new BasicShape(new Vector3(1, 1, 1), new Vector3(0, 0, 3)); s.SetTopTexture(TextureLoader.GetTexture(4)); s.SetSideTexture(TextureLoader.GetTexture(35)); s.SetBottomTexture(TextureLoader.GetTexture(4)); s.RenderShape(GraphicsDevice, cubeEffect);

}

 public class BasicShape {

  public Vector3 shapeSize;
  public Vector3 shapePosition;
  private VertexPositionNormalTexture[][] shapeVertices;
  private int shapeTriangles;
  private VertexBuffer shapeBuffer;
  public Texture2D topTexture;
  public Texture2D frontTexture;
  public Texture2D backTexture;
  public Texture2D leftTexture;
  public Texture2D rightTexture;
  public Texture2D bottomTexture;

  public BasicShape(Vector3 size, Vector3 position) {
   shapeSize = size;
   shapePosition = position;
  }

  private void BuildShape() {
   shapeTriangles = 12;

   shapeVertices = new VertexPositionNormalTexture[6][];
   for(int i = 0; i < 6; i++) {
    shapeVertices[i] = new VertexPositionNormalTexture[6];
   }

   Vector3 topLeftFront = shapePosition +
    new Vector3(0.0f, 1.0f, 0.0f) * shapeSize;
   Vector3 bottomLeftFront = shapePosition +
    new Vector3(0.0f, 0.0f, 0.0f) * shapeSize;
   Vector3 topRightFront = shapePosition +
    new Vector3(1.0f, 1.0f, 0.0f) * shapeSize;
   Vector3 bottomRightFront = shapePosition +
    new Vector3(1.0f, 0.0f, 0.0f) * shapeSize;
   Vector3 topLeftBack = shapePosition +
    new Vector3(0.0f, 1.0f, 1.0f) * shapeSize;
   Vector3 topRightBack = shapePosition +
    new Vector3(1.0f, 1.0f, 1.0f) * shapeSize;
   Vector3 bottomLeftBack = shapePosition +
    new Vector3(0.0f, 0.0f, 1.0f) * shapeSize;
   Vector3 bottomRightBack = shapePosition +
    new Vector3(1.0f, 0.0f, 1.0f) * shapeSize;

   Vector3 topLeftFront2 = shapePosition +
    new Vector3(0.0f, 1.0f, 0.0f) * shapeSize;
   Vector3 bottomLeftFront2 = shapePosition +
    new Vector3(0.0f, 0.0f, 0.0f) * shapeSize;
   Vector3 topRightFront2 = shapePosition +
    new Vector3(1.0f, 1.0f, 0.0f) * shapeSize;
   Vector3 bottomRightFront2 = shapePosition +
    new Vector3(1.0f, 0.0f, 0.0f) * shapeSize;
   Vector3 topLeftBack2 = shapePosition +
    new Vector3(0.0f, 1.0f, 1.0f) * shapeSize;
   Vector3 topRightBack2 = shapePosition +
    new Vector3(1.0f, 1.0f, 1.0f) * shapeSize;
   Vector3 bottomLeftBack2 = shapePosition +
    new Vector3(0.0f, 0.0f, 1.0f) * shapeSize;
   Vector3 bottomRightBack2 = shapePosition +
    new Vector3(1.0f, 0.0f, 1.0f) * shapeSize;

   Vector3 topLeftFront3 = shapePosition +
    new Vector3(0.0f, 1.0f, 0.0f) * shapeSize;
   Vector3 bottomLeftFront3 = shapePosition +
    new Vector3(0.0f, 0.0f, 0.0f) * shapeSize;
   Vector3 topRightFront3 = shapePosition +
    new Vector3(1.0f, 1.0f, 0.0f) * shapeSize;
   Vector3 bottomRightFront3 = shapePosition +
    new Vector3(1.0f, 0.0f, 0.0f) * shapeSize;
   Vector3 topLeftBack3 = shapePosition +
    new Vector3(0.0f, 1.0f, 1.0f) * shapeSize;
   Vector3 topRightBack3 = shapePosition +
    new Vector3(1.0f, 1.0f, 1.0f) * shapeSize;
   Vector3 bottomLeftBack3 = shapePosition +
    new Vector3(0.0f, 0.0f, 1.0f) * shapeSize;
   Vector3 bottomRightBack3 = shapePosition +
    new Vector3(1.0f, 0.0f, 1.0f) * shapeSize;
   
   Vector3 frontNormal = new Vector3(0.0f, 0.0f, 1.0f) * shapeSize;
   Vector3 backNormal = new Vector3(0.0f, 0.0f, -1.0f) * shapeSize;
   Vector3 topNormal = new Vector3(0.0f, 1.0f, 0.0f) * shapeSize;
   Vector3 bottomNormal = new Vector3(0.0f, -1.0f, 0.0f) * shapeSize;
   Vector3 leftNormal = new Vector3(-1.0f, 0.0f, 0.0f) * shapeSize;
   Vector3 rightNormal = new Vector3(1.0f, 0.0f, 0.0f) * shapeSize;

   Vector2 textureTopLeft = new Vector2(1f * shapeSize.X, 0.0f * shapeSize.Y);
   Vector2 textureTopRight = new Vector2(0.0f * shapeSize.X, 0.0f * shapeSize.Y);
   Vector2 textureBottomLeft = new Vector2(1f * shapeSize.X, 1f * shapeSize.Y);
   Vector2 textureBottomRight = new Vector2(0.0f * shapeSize.X, 1f * shapeSize.Y);

   // Front face.
   shapeVertices[0][0] = new VertexPositionNormalTexture(
    topLeftFront, frontNormal, textureTopLeft);
   shapeVertices[0][1] = new VertexPositionNormalTexture(
    bottomLeftFront, frontNormal, textureBottomLeft);
   shapeVertices[0][2] = new VertexPositionNormalTexture(
    topRightFront, frontNormal, textureTopRight);
   shapeVertices[0][3] = new VertexPositionNormalTexture(
    bottomLeftFront, frontNormal, textureBottomLeft);
   shapeVertices[0][4] = new VertexPositionNormalTexture(
    bottomRightFront, frontNormal, textureBottomRight);
   shapeVertices[0][5] = new VertexPositionNormalTexture(
    topRightFront, frontNormal, textureTopRight);

   // Back face.
   shapeVertices[1][0] = new VertexPositionNormalTexture(
    topLeftBack, backNormal, textureTopRight);
   shapeVertices[1][1] = new VertexPositionNormalTexture(
    topRightBack, backNormal, textureTopLeft);
   shapeVertices[1][2] = new VertexPositionNormalTexture(
    bottomLeftBack, backNormal, textureBottomRight);
   shapeVertices[1][3] = new VertexPositionNormalTexture(
    bottomLeftBack, backNormal, textureBottomRight);
   shapeVertices[1][4] = new VertexPositionNormalTexture(
    topRightBack, backNormal, textureTopLeft);
   shapeVertices[1][5] = new VertexPositionNormalTexture(
    bottomRightBack, backNormal, textureBottomLeft);

   // Top face.
   shapeVertices[2][0] = new VertexPositionNormalTexture(
    topLeftFront2, topNormal, textureBottomLeft);
   shapeVertices[2][1] = new VertexPositionNormalTexture(
    topRightBack2, topNormal, textureTopRight);
   shapeVertices[2][2] = new VertexPositionNormalTexture(
    topLeftBack2, topNormal, textureTopLeft);
   shapeVertices[2][3] = new VertexPositionNormalTexture(
    topLeftFront2, topNormal, textureBottomLeft);
   shapeVertices[2][4] = new VertexPositionNormalTexture(
    topRightFront2, topNormal, textureBottomRight);
   shapeVertices[2][5] = new VertexPositionNormalTexture(
    topRightBack2, topNormal, textureTopRight);

   // Bottom face.
   shapeVertices[3][0] = new VertexPositionNormalTexture(
    bottomLeftFront2, bottomNormal, textureTopLeft);
   shapeVertices[3][1] = new VertexPositionNormalTexture(
    bottomLeftBack2, bottomNormal, textureBottomLeft);
   shapeVertices[3][2] = new VertexPositionNormalTexture(
    bottomRightBack2, bottomNormal, textureBottomRight);
   shapeVertices[3][3] = new VertexPositionNormalTexture(
    bottomLeftFront2, bottomNormal, textureTopLeft);
   shapeVertices[3][4] = new VertexPositionNormalTexture(
    bottomRightBack2, bottomNormal, textureBottomRight);
   shapeVertices[3][5] = new VertexPositionNormalTexture(
    bottomRightFront2, bottomNormal, textureTopRight);

   // Left face.
   shapeVertices[4][0] = new VertexPositionNormalTexture(
    topLeftFront3, leftNormal, textureTopRight);
   shapeVertices[4][1] = new VertexPositionNormalTexture(
    bottomLeftBack3, leftNormal, textureBottomLeft);
   shapeVertices[4][2] = new VertexPositionNormalTexture(
    bottomLeftFront3, leftNormal, textureBottomRight);
   shapeVertices[4][3] = new VertexPositionNormalTexture(
    topLeftBack3, leftNormal, textureTopLeft);
   shapeVertices[4][4] = new VertexPositionNormalTexture(
    bottomLeftBack3, leftNormal, textureBottomLeft);
   shapeVertices[4][5] = new VertexPositionNormalTexture(
    topLeftFront3, leftNormal, textureTopRight);

   // Right face.
   shapeVertices[5][0] = new VertexPositionNormalTexture(
    topRightFront3, rightNormal, textureTopLeft);
   shapeVertices[5][1] = new VertexPositionNormalTexture(
    bottomRightFront3, rightNormal, textureBottomLeft);
   shapeVertices[5][2] = new VertexPositionNormalTexture(
    bottomRightBack3, rightNormal, textureBottomRight);
   shapeVertices[5][3] = new VertexPositionNormalTexture(
    topRightBack3, rightNormal, textureTopRight);
   shapeVertices[5][4] = new VertexPositionNormalTexture(
    topRightFront3, rightNormal, textureTopLeft);
   shapeVertices[5][5] = new VertexPositionNormalTexture(
    bottomRightBack3, rightNormal, textureBottomRight);
  }

  public void SetTopTexture(Texture2D tex) {
   topTexture = tex;
  }
  public void SetSideTexture(Texture2D tex) {
   frontTexture = tex;
   backTexture = tex;
   leftTexture = tex;
   rightTexture = tex;
  }
  public void SetBottomTexture(Texture2D tex) {
   bottomTexture = tex;
  }

  public void RenderShape(GraphicsDevice device, Effect effect) {
   BuildShape();


   effect.Parameters["xTexture"].SetValue(topTexture);
   device.DrawUserPrimitives(PrimitiveType.TriangleList, shapeVertices[2], 0, 2);
   effect.Parameters["xTexture"].SetValue(bottomTexture);
   device.DrawUserPrimitives(PrimitiveType.TriangleList, shapeVertices[3], 0, 2);
   effect.Parameters["xTexture"].SetValue(frontTexture);
   device.DrawUserPrimitives(PrimitiveType.TriangleList, shapeVertices[0], 0, 2);
   effect.Parameters["xTexture"].SetValue(backTexture);
   device.DrawUserPrimitives(PrimitiveType.TriangleList, shapeVertices[1], 0, 2);
   effect.Parameters["xTexture"].SetValue(leftTexture);
   device.DrawUserPrimitives(PrimitiveType.TriangleList, shapeVertices[4], 0, 2);
   effect.Parameters["xTexture"].SetValue(rightTexture);
   device.DrawUserPrimitives(PrimitiveType.TriangleList, shapeVertices[5], 0, 2);

  }
 }

And in the Draw method for my game:

 cubeEffect.CurrentTechnique = cubeEffect.Techniques["Textured"];
 foreach(EffectPass pass in cubeEffect.CurrentTechnique.Passes) {
  pass.Apply();
  BasicShape s = new BasicShape(new Vector3(1, 1, 1), new Vector3(0, 0, 3));
  s.SetTopTexture(TextureLoader.GetTexture(4));
  s.SetSideTexture(TextureLoader.GetTexture(35));
  s.SetBottomTexture(TextureLoader.GetTexture(4));
  s.RenderShape(GraphicsDevice, cubeEffect);   

 }
Source Link
Bevin
  • 972
  • 6
  • 19
  • 35

Drawing a textured cube with multiple sides in XNA 4.0

I have been banging my head against this problem for hours now. What I want to do is draw a cube, with different textures on each side; or more specifically, I want to be able to specify whatever texture I want per side. I used the example here to start with, and then attempted to develop it further, so I could have more than one texture. However, no matter what I do, it still only uses the last texture that is applied to the effect, and pays no heed to any previous assignments. Here is my shape class:

public class BasicShape {

public Vector3 shapeSize; public Vector3 shapePosition; private VertexPositionNormalTexture[][] shapeVertices; private int shapeTriangles; private VertexBuffer shapeBuffer; public Texture2D topTexture; public Texture2D frontTexture; public Texture2D backTexture; public Texture2D leftTexture; public Texture2D rightTexture; public Texture2D bottomTexture;

public BasicShape(Vector3 size, Vector3 position) { shapeSize = size; shapePosition = position; }

private void BuildShape() { shapeTriangles = 12;

shapeVertices = new VertexPositionNormalTexture[6][]; for(int i = 0; i < 6; i++) { shapeVertices[i] = new VertexPositionNormalTexture[6]; }

Vector3 topLeftFront = shapePosition + new Vector3(0.0f, 1.0f, 0.0f) * shapeSize; Vector3 bottomLeftFront = shapePosition + new Vector3(0.0f, 0.0f, 0.0f) * shapeSize; Vector3 topRightFront = shapePosition + new Vector3(1.0f, 1.0f, 0.0f) * shapeSize; Vector3 bottomRightFront = shapePosition + new Vector3(1.0f, 0.0f, 0.0f) * shapeSize; Vector3 topLeftBack = shapePosition + new Vector3(0.0f, 1.0f, 1.0f) * shapeSize; Vector3 topRightBack = shapePosition + new Vector3(1.0f, 1.0f, 1.0f) * shapeSize; Vector3 bottomLeftBack = shapePosition + new Vector3(0.0f, 0.0f, 1.0f) * shapeSize; Vector3 bottomRightBack = shapePosition + new Vector3(1.0f, 0.0f, 1.0f) * shapeSize;

Vector3 topLeftFront2 = shapePosition + new Vector3(0.0f, 1.0f, 0.0f) * shapeSize; Vector3 bottomLeftFront2 = shapePosition + new Vector3(0.0f, 0.0f, 0.0f) * shapeSize; Vector3 topRightFront2 = shapePosition + new Vector3(1.0f, 1.0f, 0.0f) * shapeSize; Vector3 bottomRightFront2 = shapePosition + new Vector3(1.0f, 0.0f, 0.0f) * shapeSize; Vector3 topLeftBack2 = shapePosition + new Vector3(0.0f, 1.0f, 1.0f) * shapeSize; Vector3 topRightBack2 = shapePosition + new Vector3(1.0f, 1.0f, 1.0f) * shapeSize; Vector3 bottomLeftBack2 = shapePosition + new Vector3(0.0f, 0.0f, 1.0f) * shapeSize; Vector3 bottomRightBack2 = shapePosition + new Vector3(1.0f, 0.0f, 1.0f) * shapeSize;

Vector3 topLeftFront3 = shapePosition + new Vector3(0.0f, 1.0f, 0.0f) * shapeSize; Vector3 bottomLeftFront3 = shapePosition + new Vector3(0.0f, 0.0f, 0.0f) * shapeSize; Vector3 topRightFront3 = shapePosition + new Vector3(1.0f, 1.0f, 0.0f) * shapeSize; Vector3 bottomRightFront3 = shapePosition + new Vector3(1.0f, 0.0f, 0.0f) * shapeSize; Vector3 topLeftBack3 = shapePosition + new Vector3(0.0f, 1.0f, 1.0f) * shapeSize; Vector3 topRightBack3 = shapePosition + new Vector3(1.0f, 1.0f, 1.0f) * shapeSize; Vector3 bottomLeftBack3 = shapePosition + new Vector3(0.0f, 0.0f, 1.0f) * shapeSize; Vector3 bottomRightBack3 = shapePosition + new Vector3(1.0f, 0.0f, 1.0f) * shapeSize;

Vector3 frontNormal = new Vector3(0.0f, 0.0f, 1.0f) * shapeSize; Vector3 backNormal = new Vector3(0.0f, 0.0f, -1.0f) * shapeSize; Vector3 topNormal = new Vector3(0.0f, 1.0f, 0.0f) * shapeSize; Vector3 bottomNormal = new Vector3(0.0f, -1.0f, 0.0f) * shapeSize; Vector3 leftNormal = new Vector3(-1.0f, 0.0f, 0.0f) * shapeSize; Vector3 rightNormal = new Vector3(1.0f, 0.0f, 0.0f) * shapeSize;

Vector2 textureTopLeft = new Vector2(1f * shapeSize.X, 0.0f * shapeSize.Y); Vector2 textureTopRight = new Vector2(0.0f * shapeSize.X, 0.0f * shapeSize.Y); Vector2 textureBottomLeft = new Vector2(1f * shapeSize.X, 1f * shapeSize.Y); Vector2 textureBottomRight = new Vector2(0.0f * shapeSize.X, 1f * shapeSize.Y);

// Front face. shapeVertices[0][0] = new VertexPositionNormalTexture( topLeftFront, frontNormal, textureTopLeft); shapeVertices0 = new VertexPositionNormalTexture( bottomLeftFront, frontNormal, textureBottomLeft); shapeVertices[0][2] = new VertexPositionNormalTexture( topRightFront, frontNormal, textureTopRight); shapeVertices[0][3] = new VertexPositionNormalTexture( bottomLeftFront, frontNormal, textureBottomLeft); shapeVertices[0][4] = new VertexPositionNormalTexture( bottomRightFront, frontNormal, textureBottomRight); shapeVertices[0][5] = new VertexPositionNormalTexture( topRightFront, frontNormal, textureTopRight);

// Back face. shapeVertices[1][0] = new VertexPositionNormalTexture( topLeftBack, backNormal, textureTopRight); shapeVertices1 = new VertexPositionNormalTexture( topRightBack, backNormal, textureTopLeft); shapeVertices[1][2] = new VertexPositionNormalTexture( bottomLeftBack, backNormal, textureBottomRight); shapeVertices[1][3] = new VertexPositionNormalTexture( bottomLeftBack, backNormal, textureBottomRight); shapeVertices[1][4] = new VertexPositionNormalTexture( topRightBack, backNormal, textureTopLeft); shapeVertices[1][5] = new VertexPositionNormalTexture( bottomRightBack, backNormal, textureBottomLeft);

// Top face. shapeVertices[2][0] = new VertexPositionNormalTexture( topLeftFront2, topNormal, textureBottomLeft); shapeVertices2 = new VertexPositionNormalTexture( topRightBack2, topNormal, textureTopRight); shapeVertices[2][2] = new VertexPositionNormalTexture( topLeftBack2, topNormal, textureTopLeft); shapeVertices[2][3] = new VertexPositionNormalTexture( topLeftFront2, topNormal, textureBottomLeft); shapeVertices[2][4] = new VertexPositionNormalTexture( topRightFront2, topNormal, textureBottomRight); shapeVertices[2][5] = new VertexPositionNormalTexture( topRightBack2, topNormal, textureTopRight);

// Bottom face. shapeVertices[3][0] = new VertexPositionNormalTexture( bottomLeftFront2, bottomNormal, textureTopLeft); shapeVertices3 = new VertexPositionNormalTexture( bottomLeftBack2, bottomNormal, textureBottomLeft); shapeVertices[3][2] = new VertexPositionNormalTexture( bottomRightBack2, bottomNormal, textureBottomRight); shapeVertices[3][3] = new VertexPositionNormalTexture( bottomLeftFront2, bottomNormal, textureTopLeft); shapeVertices[3][4] = new VertexPositionNormalTexture( bottomRightBack2, bottomNormal, textureBottomRight); shapeVertices[3][5] = new VertexPositionNormalTexture( bottomRightFront2, bottomNormal, textureTopRight);

// Left face. shapeVertices[4][0] = new VertexPositionNormalTexture( topLeftFront3, leftNormal, textureTopRight); shapeVertices4 = new VertexPositionNormalTexture( bottomLeftBack3, leftNormal, textureBottomLeft); shapeVertices[4][2] = new VertexPositionNormalTexture( bottomLeftFront3, leftNormal, textureBottomRight); shapeVertices[4][3] = new VertexPositionNormalTexture( topLeftBack3, leftNormal, textureTopLeft); shapeVertices[4][4] = new VertexPositionNormalTexture( bottomLeftBack3, leftNormal, textureBottomLeft); shapeVertices[4][5] = new VertexPositionNormalTexture( topLeftFront3, leftNormal, textureTopRight);

// Right face. shapeVertices[5][0] = new VertexPositionNormalTexture( topRightFront3, rightNormal, textureTopLeft); shapeVertices5 = new VertexPositionNormalTexture( bottomRightFront3, rightNormal, textureBottomLeft); shapeVertices[5][2] = new VertexPositionNormalTexture( bottomRightBack3, rightNormal, textureBottomRight); shapeVertices[5][3] = new VertexPositionNormalTexture( topRightBack3, rightNormal, textureTopRight); shapeVertices[5][4] = new VertexPositionNormalTexture( topRightFront3, rightNormal, textureTopLeft); shapeVertices[5][5] = new VertexPositionNormalTexture( bottomRightBack3, rightNormal, textureBottomRight); }

public void SetTopTexture(Texture2D tex) { topTexture = tex; } public void SetSideTexture(Texture2D tex) { frontTexture = tex; backTexture = tex; leftTexture = tex; rightTexture = tex; } public void SetBottomTexture(Texture2D tex) { bottomTexture = tex; }

public void RenderShape(GraphicsDevice device, Effect effect) { BuildShape();

effect.Parameters["xTexture"].SetValue(topTexture); device.DrawUserPrimitives(PrimitiveType.TriangleList, shapeVertices[2], 0, 2); effect.Parameters["xTexture"].SetValue(bottomTexture); device.DrawUserPrimitives(PrimitiveType.TriangleList, shapeVertices[3], 0, 2); effect.Parameters["xTexture"].SetValue(frontTexture); device.DrawUserPrimitives(PrimitiveType.TriangleList, shapeVertices[0], 0, 2); effect.Parameters["xTexture"].SetValue(backTexture); device.DrawUserPrimitives(PrimitiveType.TriangleList, shapeVertices1, 0, 2); effect.Parameters["xTexture"].SetValue(leftTexture); device.DrawUserPrimitives(PrimitiveType.TriangleList, shapeVertices[4], 0, 2); effect.Parameters["xTexture"].SetValue(rightTexture); device.DrawUserPrimitives(PrimitiveType.TriangleList, shapeVertices[5], 0, 2);

} }

And in the Draw method for my game:

cubeEffect.CurrentTechnique = cubeEffect.Techniques["Textured"]; foreach(EffectPass pass in cubeEffect.CurrentTechnique.Passes) { pass.Apply(); BasicShape s = new BasicShape(new Vector3(1, 1, 1), new Vector3(0, 0, 3)); s.SetTopTexture(TextureLoader.GetTexture(4)); s.SetSideTexture(TextureLoader.GetTexture(35)); s.SetBottomTexture(TextureLoader.GetTexture(4)); s.RenderShape(GraphicsDevice, cubeEffect);

}

As you can see, I am loading different textures, yet the result is this:

my cube http://www.tinyimg.org/images/769MinecraftClassic_2011_.bmp

I am sure that the textures are different, yet the same texture gets drawn on all sides. Do I need a separate effect for each side? That definitely seems like overkill.