In this project I had to create an object procedurally using MEL scripting. I created a swing. The following is the turntable of the swing that I created in MEL.
BREAKDOWN
Reference:
I chose to create swing because I though that creating something representative would be tricky and would
be fun. The user would also like to play with an object that he is familiar with.
For my reference I researched on swings and finally decided to the stick to the above design.
Following are few images of the various swings, the chain links and the seat.
BREAKDOWN
Reference:
I chose to create swing because I though that creating something representative would be tricky and would
be fun. The user would also like to play with an object that he is familiar with.
For my reference I researched on swings and finally decided to the stick to the above design.
Following are few images of the various swings, the chain links and the seat.
Procedure:
I first started creating a single link. I created it from a torus and scaled it to make it look like a chain link. I gave variables to the torus so that values of torus can be flexible therefore making the whole chain link flexible. I then put the single link in a loop so that it duplicates it, moves upwards, rotates in a particular fashion.
The code is as follows:
///Loop for 1st chain link///
for($i = 0; $i < $numLinks; $i++)
{
/// POLYTORUS ///
/// Makes Polytorus ///
polyTorus -n link
-r $radius
-sr $secRadius
-sx $tessalation
-sy $tessalation;
scale 0.5 0.8 0.8;
rotate -r -os 90 0 0 ;
if( $i % 2 == 0)
{
rotate -r 0 90 0;
}
float $temp = $gap*$i;
move 0 $temp 0;
}
This created the whole chain. The next step was to create a loop to connect the chain link and the seat.
The following is the code for the same:
polyTorus -n loop
-sx 30
-sy 15
-r $loopradius
-sr 0.2;
rotate -r -os 90 0 0 ;
move 0 (-$radius/1.5) 0;
Next was to duplicate the whole chain link and move it over to the other side.
select -all;
group -n set1;
xform -os -piv 0 0 0;
move (-$distlink/2) 0 0;
duplicate set1;
move ($distlink/2) 0 0 ;
After this I created the seat of the swing.For this I created a Poly cube and gave it bevel. Then moved it so that it sits perfectly between the two chain links. Even if the user changes the distance between the chain links, the seat would expand along with it.
The code for this was:
polyCube -n seat -w $seatlength -h 1.03098 -d 11.268869 -cuv 4 -sx 2 -sy 2 -sz 2;
polyBevel -offset 0.1;
move 0 (-$radius/1.5 - $loopradius -$secRadius -0.2) 0;
The next was the tricky part of figuring out how to duplicate the swings and move them forward so that
they dont duplicate and sit over each other.
After a bit of brainstorming, I used the technique of assigning a variable. I assigned a variable for the space between two swings and came up with the following code which helps duplicate the whole swing any number of times without siting on top of each other.
select -all;
group -n swingset;
for ($j=0; $j<$swingsetnum; $j++)
{
duplicate swingset;
select swingset;
move -x ($space*$j);
}
The following is an image of the above code that works
After the main design was done, I focused on creating details. I created a small flat cube on seats so that
it looks like the chain link is attached to the seat by that panel. The code for the same was:
polyCube -n attachement
-w 2
-h 0.4
-d 4;
move (-$distlink/2) (-$radius/2.5 - $loopradius -$secRadius -0.2) 0;
duplicate attachement;
move ($distlink/2) (-$radius/2.5 - $loopradius -$secRadius -0.2) 0;
Following is the picture of the panel.
Lighting/Shading:
I tried applying shaders to the model through MEL but couldn't keep it consistent.I could see the shaders being assigned on the world space but when I tried to run the script again, all the shaders would disappear. After a bit searching, I realized the shaders were getting deleted because of the following particular command:
select -all;
delete;
GUI:
After the code was created, I made a Graphic User Interface. This interface helps the user to control the variables of the design and therefore can manipulate and modify it.
The code for making a GUI is as follows:
if (`window -exists myWindow`) deleteUI myWindow;
window -title "SWINGS" - widthHeight 300 200 myWindow;
columnLayout ;
//Makes different parameters in the GUI
floatSliderGrp - label "Number of Links" -min 10 -max 100 -value 40 -field true -changeCommand "swings" numLinks;
floatSliderGrp - label "Radius of link" -min 1 -max 2 -value 1.6 -field true -changeCommand "swings" radius;
floatSliderGrp - label "Link section radius" -min 0.1 -max 1 -value 0.5 -field true -changeCommand "swings" secRadius;
floatSliderGrp - label "Tessalation" -min 10 -max 30 -value 20 -field true -changeCommand "swings" tessalation;
floatSliderGrp - label "Gap between links" -min 1 -max 2 -value 1.8 -field true -changeCommand "swings" gap;
floatSliderGrp - label "Distance between chains" -min 10 -max 30 -value 20 -field true -changeCommand "swings" distlink;
floatSliderGrp - label "Number of swings" -min 0 -max 10 -value 0 -field true -changeCommand "swings" swingsetnum;
floatSliderGrp - label "Space between swings" -min 5 -max 50 -value 10 -field true -changeCommand "swings" space;
/// CALLS THE WINDOW ///
showWindow myWindow;
/// VARIABLES///
///Assign Variables///
float $numLinks = `floatSliderGrp - q - value numLinks`;
float $radius = `floatSliderGrp - q - value radius`;
float $secRadius = `floatSliderGrp - q - value secRadius`;
float $tessalation = `floatSliderGrp - q - value tessalation`;
float $gap = `floatSliderGrp - q - value gap`;
float $distlink = `floatSliderGrp - q - value distlink`;
float $seatoffset=2;
float $seatlength=$distlink+2*$seatoffset;
float $loopradius = 1;
float $swingsetnum = `floatSliderGrp - q - value swingsetnum`;
float $space = `floatSliderGrp - q - value space`;
int $i;
Conclusion:
I enjoyed working on this project. Creating a representational object is difficult rather than making an abstract form. Making an algorithm helped me in deciding my variables and the control I wanted the user to have. It also helped me in writing the code. The tricky part was figuring out how to duplicating the whole swing number of times and moving over but finally managed to achieve it.I would like to further explore in creating complicated swing patterns like the following:
I would also like to experiment with lighting and shading it procedurally. I think MEL is a great scripting language and there are a variety of things a person can accomplish through MEL.