BLOGGER TEMPLATES AND TWITTER BACKGROUNDS »

Tuesday, June 22, 2010

Make a perfect circle of objects in MEL

You can use this to duplicate a perfect circle of objects, draw lines or all sorts of stuff.

{
// Make a perfect circle of objects!
proc float magicTrigFunctionX(float $pointRatio){
return cos($pointRatio*2*3.14);
}
proc float magicTrigFunctionZ(float $pointRatio){
return sin($pointRatio*2*3.14);
}

proc drawCircle(float $centerX, float $centerZ, float $radius, float $sides){
// Move the original to the first point on the circle.
// Replace newCube with your object below
string $newCube[] = `polyCube`;
string $orig = $newCube[0];
xform -t ($centerX + $radius) 0 $centerZ $newCube[0];
// Run the loop to draw the circle
for($i=0; $i < $sides ; $i++){
float $pointRatio = $i/$sides;
float $xSteps = magicTrigFunctionX($pointRatio);
float $zSteps = magicTrigFunctionZ($pointRatio);
float $pointX = $centerX + $xSteps * $radius;
float $pointZ = $centerZ + $zSteps * $radius;
$newCube = `duplicate $newCube[0]`;
xform -t $pointX 0 $pointZ -ro 0 ($pointRatio*-360) 0 $newCube[0];
}
delete $orig;
}
// Arguments
// centerX, centerZ, radius, number of objects
drawCircle(0, 0, 200, 100);

}

0 comments: