Rubik's Cube AnimatingModelling -- Texturing -- Rigging -- Animating -- Files
Note: Instructions in bold indicate using Maya's menus.
This is separated out to its own page for folks who aren't interested in how the scripts drive the rig.
It's been pointed out that the Mental Ray render doesn't handle this rig well. I'm working on an update to the rig to work around that.
Animating the Rig
This is really pretty simple now that the rig is in place. You just animate the six axis cubes (shown in red). Now the importance of the various hierarchy levels becomes clearer.
Recall how in the rig the actual small block geometry is two transforms deep, so it can be easily replaced with other geometry. Make sure to animate the higher of the two transforms for each axis-block (that is, set keys on right1 rather than right2). The corner and edge blocks will follow along as the center "axis" blocks rotate.
Make sure to finish rotating one face before starting to rotate another face (except for parallel faces, which can be rotated at the same time). Otherwise the blocks won't be put back into the main bucket before they need to be moved to an axis block bucket.
Problem: An axis block rotates, but not all 8 sub blocks come with it. The most common problem you may encounter is having an axis block rotate without having 8 sub blocks rotate along with it. This is most commonly caused by beginning to rotate one face before the previous face is finished rotating. Check your keys and adjust them as necessary.
Problem: An axis block rotates, but the sub-blocks don't finish rotateing.If the sub-blocks don't quite finish rotating, it's possible that they got caught in a call to refreshCubes(). Check the Start Frame of the cube, and don't set your first keys for the cube until after the Start Frame.
For example, if the Start Frame is on frame 0, don't put any keys on frame 0. Start putting keys on frame 1. This lets the scripts execute in the right sequence, and should fix up the block rotation problem.
It's perfectly possible that I've made mistake somewhere else. Don't hesitate to let me know if part of this is broken, and I'll update it.
Resetting the Rig
Sometimes the rig will get messed up. To reset the rig, you can call the resetCubes() function. You can also set the rig's start frame. When Maya changes to the frame listed as the start frame of the rig (cubeGroup.startFrame shown in red), the expression automatically calls resetCubes(). To prevent this, change the start frame on the cubeGroup node to a frame you won't use (i.e. a negative frame).
Duplicating the Rig
You can fairly simply duplicate this cube to have multiple rigs in the scene. Duplicating the rig is simple -- just duplicate the top node of the rig.
You will need to edit the expression, however, but you don't have to know scripting to do it.
Open the Expression Editor by choosing Window -> Animation Editors -> Expression Editor.
On the first line of the expression, add the name of the new top-level node to the string array. Make sure to put it in quotes, and add commas between items in that list. The expression above is from a file that has two cube rigs in it already.
Click Edit to save the changes to the expression. Now both cubes will animate and reset properly.
An easy way to animate your cube "solving" itself is to reset the cube at the last frame of your animation, then play the animation backwards to the first frame. (Make sure that your cube's .startFrame is set so that you don't reset your cube doing this) Now play your scene forwards, and your cube will finish up "solved".
To batch render using this technique, save off a copy of your scene after playing backwards, and render that file. Presto!
There are a number of Rubik's Cube fan web sites, and even web-based cube solvers. You can use these to find the right combination of rotations to animate your cube to the right color combinations.
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.