Rubik's Cube Texturing

Modelling -- Texturing -- Rigging -- Animating -- Files

Note: Instructions in bold indicate using Maya's menus.

After my previous Rubik's Cube tutorials, a question arose about how to get each "face" of the cube textured using a single file. It's straightforward enough to do. You need to change the materials on the geometry to use textures for their color, and then you need to update the UV mapping on the geometry itself to only map the section of the file appropriate to each block face. This the basic technique, but it needs to be modified to fit the exact geometry in your Rubik's Cube.

Note: I'm using a much simpler model here to make it clear what I'm doing. This model just has 26 typical polygon cubes for its geometry. (This is the geometry that is on the download files page.

The Textured Cube

The goal of this part is to show how to get each face (all of the block faces that share a color) to use a single Maya texture file node for their coloring.

This allows a lot of flexibility, and you can create a whole new cube by just changing the six images on the faces of your cubes.

Below are the six images that I've used to texture the cube in the pictures to the sides. You can see that as the cube turns the sections of each texture travel with it.

Using Textures with Materials

The basic materials on the Rubik's Cube are just Lambert shaders with a color set to one of the six Rubik's colors. The first step is to get them to use a texture file instead.

If you open the Hypershade (Window -> Rendering Editors -> Hypershade), you can see the six shaders for the cube. Select one of them (yellowMaterial, for example), and open the Attribute Editor (Ctrl + A).

Clicking the "checkerboard" button next to any of the attributes in the shader will allow you to map a number of nodes to that attribute.

When you click on it, Maya will bring up the Create Render Node window. This lets you create all kinds of procedural textures and complicated shading networks. It also is where you create a File nodes that read in texture files into your shading networks. IMPORTANT: Make sure that you are creating the node in "Normal" mode instead of as a projection (1). That done, click on the File button (2).

This creates a node called file1 and makes a connection from its output to the color input of the yellowMaterial material node. Select file1 in the Hypershade work area and bring it up in the Attribute Editor. Click on the "file folder" icon next to the Image Name attribute (3). In the dialog box that opens up, find and select the image file you want to use as a texture for the yellow side of your Rubik's Cube. I'm using sourceimages/gYellow.tif . You can change the Maya viewport to show textures on your models by selecting Shading -> Hardware Texturing or pressing the 6 key.

Repeat this process for the other five shaders for the other colors of the cube. (I'm leaving just the yellow material textured for clarity later on)

The Basics of Maya UV Mapping

This is the real key to making a single texture work. We'll be adjusting the UV mapping of the texture to the surface to make sure that each face of a block is mapped to the right region of UV space. Then, when that face is assigned to the correct material (as it already is in this tutorial), that block face will show the right fraction of the texture no matter where it turns as the cube animates.

Select a cube, then choose Window -> UV Texture Window. This window will show you the mapping between the faces and UV space. Selecting any of the faces on the cube will highlight the section of the UV space where that face maps. This image shows the mapping for block1Geom at this point. When the selected object or face has a texture on its material, the UV Texture Window will show the texture in the background behind the lines showing the UV map.

The eventual goal is this mapping on the left, where each face corresponds to 1/9th of the UV space. This is the mapping for block1Geom at the end fo the tutorial. Three of the faces correspond to the upper left, upper right, and lower right corners. The other three faces are all mapped to the center 1/9th of the UV space, but those are interior faces, and we don't care where they're mapped.

This is counterintuitive at first, and these images don't make it really clear, but the material & shader on a block face determines which texture it uses, but the UV mapping determines which part of any texture is used by that block face.

The orange face is mapped to piece "1", the red face is mapped to piece "3", and the yellow face is mapped to piece "9". Their shaders then assign them to be using the right texture.

To manipulate the UVs, you can select them similarly to how you select vertices or faces. You can right-click-and-hold over an object, and select UVs from the pop-up menu. You can also press F12 to change into UV selection mode. A technique that will be useful to us here is to select a face, then press Ctrl + F12 to select the selected face's UVs.

Some Nifty UV Remapping

Since we're working with very nice square shapes, there are some easy ways to manipulate the UVs by MEL commands more accurately than trying to move them manually.

Select all 26 of the geometry blocks

In the UV Texture Editor, choose Polygons -> Unitize. This will snap each face's UVs to cover the whole unit UV space from 0 to 1 in both directions.

For this basic cube, each block takes 1/3rd of the height, and 1/3rd of the width of the texture for each face. A more complicated geometry (like the kind shown in the Modelling section) will use slightly less than 1/3rd in each dimension. Our next step is to scale all of the UVs so they cover only 1/3rd.

Select all 26 of the geometry blocks (again).

Press Ctrl+12 to convert your selection to the UVs corresponding to those blocks. With those UVs selected, run this MEL command in the Script Editor or Command Line, which will shrink the unit UVs so that they only cover the middle 1/3rd of each dimension. NOTE: If you're using more complicated geometry than simple cubes, you may need to adjust the scaling here to a lower value, since the outward face of your geometry won't fill an entire 1/3rd of the face of the Rubik's Cube.

polyEditUV -pu 0.5 -pv 0.5 -su 0.333333 -sv 0.333333 ;

Now all we have remaining to do is to move each block face's UVs to match up with the part of the texture it should be mapped to. Now, there are 8 corner blocks and 12 edge blocks, with a total of 48 faces to adjust (There's no need to adjust the center faces). It's a little tedious, but moving the UVs for each face manually at this point isn't the worst task. It could be scripted, but I'll leave that as an exercise to the scripting-enthusiastic reader...

However, for everyone else, here's the shortcut that really sped up the task for me.

Copy this block of code into the Script Editor. If you're familiar with how to make shelf buttons, making a shelf button for each of these lines was well worth the minimal effort it takes.

//Move RIGHT in UV space
polyEditUV -u 0.333333 -v 0 ;

//Move LEFT in UV space
polyEditUV -u -0.333333 -v 0 ;

//Move UP in UV space
polyEditUV -u 0 -v 0.333333 ;

//Move DOWN in UV space
polyEditUV -u 0 -v -0.333333 ;

Select a face on block1Geom. Press Ctrl + F12 to convert that selection to UVs.

With those UVs selected, run the appropriate commands from the four above to move the face's UVs through UV space. They will move exactly 1/3 of the way through U or V space at a time, allowing you to quickly and precisely align them to the piece of the texture they should show.

Note: To run only a part of what you have in the Script Editor input box, select that line of text, and press Ctrl + Enter. This will execute the code without erasing it from the input box.

Work your way around the whole cube from block to block, moving each of the faces to its new position. It's helpful to use a utility texture while you're doing this, so you can see in the viewport if the face is matched to the right position.


Voila! You're all finished texturing!

Your cube should now have 6 textures that show on all 26 blocks as they move around during animation. I've added my textured cube example to the Files page for downloading, as well as the textures I used to help with the re-mapping.

Let me know if I've skipped a step, or if part of this is unclear.


1) Modelling
2) Texturing
3) Rigging
4) Animating
5) File Download

The Rubik's Cube is copyright, I think, of Seven Towns, Ltd., who retains all rights, etc., that they haven't licensed to other folks. The use of the name here is without permission. If the appropriate people are annoyed by this, I'll make the appropriate modifications. | WebSite by  |  Valid CSS  |  Valid HTML