Rigging a Rubik's cube in Maya with MEL

1.9k Views Asked by At

I want to rig a Rubik's cube in Maya, so it can rotate in any direction and any number of times. Any rotation would be in 90 degree increments. These are the objects in my Outliner:

26 blocks (the center block of the cube is not necessary) 9 rotation controllers (3 for the rows/columns of height/width/depth) 1 root controller

The trick is passing the control of the individual blocks from one controller to the next. At any given time, a block can be influenced by 3 different controllers. However, after rotation, the controllers change.

I suppose I need to create a series of matrices (2D arrays), 9 of them - one for each controller. Assign the blocks to them, and then reassign after a rotation. I suppose I would need a temporary matrix for swapping. Beyond this, I don't know how to go about this. Should these matrices be a parameter of the root controller? Probably.

Any help in this matter would help. I am new to MEL but I have background in C/C++ and such. How would you rig a functional Rubik's cube?

3

There are 3 best solutions below

0
On

All you need is to turn the rotation interpolation to quaternion interpolation for your rotation, then key one packet at a time. Just make sure never go backwards when your keying the sequence tough.

0
On

Here is working Rubic's cube tool for download http://www.geonak.com/downloads/RubixCube.zip

0
On

You can also do it by blending constraint weights. The 6 center pieces are your controls. Parent constrain all the other cubes to all 6 controls. Each cube will now have a constraint node with 6 weight inputs that you can key. Set the weight for the controller you're going to rotate to 1 and all others to 0 for the cubes one the face you're rotating. Set all the weights to 0 for cubes that aren't involved in the current move.

If you want to get fancier, create a master layout control for the whole thing, add an attribute to set which controller is active with options 1 to 6, and have it update the weights on all the cubes when it gets changed. You can probably determine if a cube should be deactivated completely (all weights -> 0) by looking at its distance to the currently active controller cube; adjacent cubes on the active face will all be close, all others will be further away.