This project is read-only.

Multiple textures on different cube faces

Sep 10, 2010 at 9:25 AM


I'm trying to set different textures on different cube faces, i.e. i want to set the image a.jpg on top face and b.jpg on front face and so on. Since now, i can draw a texture on a single side of the cube.

Best regards,


Sep 11, 2010 at 6:01 AM

Just create 6 separate quads and assign different texture to each of them, or put all of the textures in one image file, and use texture coordinates to assign them appropriately. 

Otherwise, you need to create a .x or .fbx file that has those textures on each face since the ModelMesh class can contain separate textures for each ModelMeshPart.


Sep 13, 2010 at 9:16 AM

Setting the images in one file and paste it on the cube faces is the same thing I was supposed to do, but there's a problem; if i want to set the texture on the left, up and right faces i have to set TextureCoordinate points which correspond to the down face. As a result, the texture image containing the 3 images would be attached on the down face only without "passing" by the 3 cube faces. Is that right?

I paste here my code to let you all understand my situation:

       // Create 8 vertex positions that will be assigned to those 24 vertices
            Vector3 v0 = new Vector3(-halfExtent.X, -halfExtent.Y, -halfExtent.Z);
            Vector3 v1 = new Vector3(halfExtent.X, -halfExtent.Y, -halfExtent.Z);
            Vector3 v2 = new Vector3(-halfExtent.X, halfExtent.Y, -halfExtent.Z);
            Vector3 v3 = new Vector3(halfExtent.X, halfExtent.Y, -halfExtent.Z);
            Vector3 v4 = new Vector3(halfExtent.X, halfExtent.Y, halfExtent.Z);
            Vector3 v5 = new Vector3(-halfExtent.X, halfExtent.Y, halfExtent.Z);
            Vector3 v6 = new Vector3(halfExtent.X, -halfExtent.Y, halfExtent.Z);
            Vector3 v7 = new Vector3(-halfExtent.X, -halfExtent.Y, halfExtent.Z);
            Vector2 t0 = new Vector2(0, 0);
            Vector2 t1 = new Vector2(textCoord.X, 0);
            Vector2 t2 = new Vector2(0, textCoord.Y);
            Vector2 t3 = new Vector2(textCoord.X, textCoord.Y);

            vertices[0].Position = v0; vertices[1].Position = v1;
            vertices[2].Position = v2; vertices[3].Position = v3;

            vertices[4].Position = v0; vertices[5].Position = v7;
            vertices[6].Position = v2; vertices[7].Position = v5;

            vertices[8].Position = v4; vertices[9].Position = v5;
            vertices[10].Position = v7; vertices[11].Position = v6;

            vertices[12].Position = v4; vertices[13].Position = v3;
            vertices[14].Position = v1; vertices[15].Position = v6;

            vertices[16].Position = v2; vertices[17].Position = v4;
            vertices[18].Position = v5; vertices[19].Position = v3;

            vertices[20].Position = v0; vertices[21].Position = v1;
            vertices[22].Position = v6; vertices[23].Position = v7;

            // Assign the texture coordinates 
            vertices[8].TextureCoordinate = t2;
            vertices[9].TextureCoordinate = t0;
            vertices[10].TextureCoordinate = t1;
            vertices[11].TextureCoordinate = t3;