Wednesday, August 22, 2012

Rubik's Cube: Part 1





How many times have you thought to yourself "Man, I can't believe nobody has used Revit to model a workable Rubik's Cube, my building depends on it!"

Probably just as many times as you have thought "I wish I had some mustard for this ice cream sandwich"

Regardless, I did it anyways (while eating an ice cream sandwich covered in mustard note* not really)
Anyways, if you are not into Rubik's Cubes, but are interested in learning how to paramaterize the rotation of an object in all three directions than you may still be interested.

I started out by modeling a single cubelet of the Rubik's Cube and giving it the appropriate parameters to control its dimensions.  Instead of using a simple square extrusion, I chose to use six sweeps (one for each side) and joined their geometry to create the rounded edges.  I then filled in each segment with an extrusion, each with a different color. 


















Now that the cubelete is finished it is time to give it the ability to move and rotate, to do this we must first make the component "work plane based" and turn off "always verticle" in the properties window (see below) then save as "Basic Cubelet".  The process we will use to control the movement and rotation of the cubelet, is through the use of nesting the component multiple times each time adding a new movement.  In the end the basic cubelet will be nested four times. (X,Y,Z movement, X rotation, Y rotation, and Z rotation) and linking the parameters between each level.



Next we create a new blank generic model and create a rig to control the movement of the cubelet in the x,y, and z directions.  Now you may think to yourself "Well, thats easy just create a reference plane with a parameter to control the distance."  While this may work in most cases, it doesn't work whe you need to input a negative value.  For that, we need to get a little bit fancy...

I got the method I used from here ---> http://dorevit.blogspot.com/2008/01/offsets-for-families.html

I first created 2 reference planes, one on each side of the centerline I then gave a dimension from the centerline to the right most reference plane and a dimension from the leftmost to the right most (see below)





















I then created a new distance parameter called "X" and used formulas to control "Xpos" and "Xneg" (see above) This allows the user to input a positive or negative value and the cublet will move accordingly.  I repeated this process for both the "Y" and "Z" directions and the locked the cubelet to the reference planes.
Now I can control my cubelte's location in all three directions! Hazah!

Now its time for the rotation parameters, make the component "work plane based" and turn off "always verticle" in the properties window and save as "Basic Cubelet-move"and then create a new blank generic model family.  Now we are going to make the rig to control the rotation in the "X" direction.  To do this we are going to use the revolve method so we can have values of both 0º and 360º without the model breaking.  For more info on this method go here:
or read my previous posts. 

Once the rig is complete load in "Basic Cubelet-move" and host it to the approroate face.  Now we need to link the parameters of the loaded family.  To do this we click on the cublet and in the properties window click on the little square to create new parameters (see below)




Now it is time to rinse and repeat, make the component "work plane based" and turn off "always verticle" in the properties window and save as "Basic Cubelet-Xrot"and then create a new blank generic model family. Create a new rotation rig, this time for the "Y" direction using the same steps as before, save that and then finally create a new generic model family for the "Z" direction.

In the end your cubelet model should be five levels deep (Zrot-->Yrot-->Xrot-->Movement-->Basic)

Now it is time to put it all together by creating a new generic model and loading in the Cubelet.
Place the first cube in the center then create a new copy and place it in the same location, then use the X,Y,and Z movement parametrs to put it in the right location (this allows the cubes to rotate around the same center point)

Once all nine 27 cubes are placed you can select the cubes you want to rotate and ajust the rotation parameter to rotate them.



note* this is just Part 1 and comes with some limitations I plan on working on the model further
  • The cubelets can only be rotated in the family environment
  • The cubelet's rotation gets finicky when rotated multiple times resulting in the user needing to rotate each cubelet individually
For Part 2, I plan on automating the whole thing using many, many "If,Then" statements or possibly using something like dynamo (although I kind of would like to keep it all native to standard Revit). The end version will have the user inputs what side to turn instead of selecting the blocks individually, the end result will let the user "play" with the cube in the project environment and fix the rotation errors

There are probably me efficent ways to go about creating these sort of things so if you have any input don't be afraid to comment!

If you want to check it out hands on you can download it here:

EDIT: Apparently it looks like the "Z" rotation is broken (I think I may have it oriented the same as the "Y" rotation, or I hosted the cubelet wrong), so i'll have to fix that eventually, regardless, you still might find it pretty neat to check out

No comments:

Post a Comment