MEL experiment – A Sphere of spheres

This was the output from recent experiment with MEL. MEL is powerful scripting language for Maya which is syntactically similar to Tcl and Perl.
Ever since I started to learn how to model in Maya I’ve always been fascinated with the arrangement of vertices in polygon structures, especially the spheres. This experiment was a learning exercise into understanding how they are arranged in 3D space.
Feel free to copy and paste the script below to generate your own.
$numOfInnerSpheres = 20;
$numOfRings = 20;
$sphereX = 0;
$sphereY = 0;
$sphereZ = 0;
$sphereOuterRadius = 70;
$sphereRadius = 0;
$sphereTwist = 0;
$sphereSize = 1;
for($i = 0; $i < $numOfRings; $i++){
$sphereRadius = sin(deg_to_rad($i * (180 / $numOfRings))) * $sphereOuterRadius;
$sphereTwist = cos(deg_to_rad($i * (180 / $numOfRings))) * $sphereOuterRadius;
for($j = 0; $j < $numOfInnerSpheres; $j++){
$sphereX = cos(deg_to_rad($sphereTwist + ($j * (360 / $numOfInnerSpheres)))) * $sphereRadius;
$sphereY = sin(deg_to_rad($sphereTwist + ($j * (360 / $numOfInnerSpheres)))) * $sphereRadius;
$sphereZ = cos(deg_to_rad($i * (180 / $numOfRings))) * $sphereOuterRadius;
polySphere -sx 12 -sy 12;
move $sphereX $sphereY $sphereZ;
scale $sphereSize $sphereSize $sphereSize;
}
}
This entry was posted in Work and tagged Maya, MEL, Sphere
Follow any comments here with the RSS feed for this postPost a comment or leave a trackback: Trackback URL

2 comments for “MEL experiment – A Sphere of spheres”
Anil Camci
Dear David, I took the liberty of porting your code to Processing and thought I should follow the spirit of sharing:
import processing.opengl.*; int numOfInnerSpheres = 20; int numOfRings = 20; float sphereX = 0; float sphereY = 0; float sphereZ = 0; int sphereOuterRadius = 180; float sphereRadius = 0; float sphereTwist = 0; int sphereSize = 1; void setup(){ size(1280, 720, OPENGL); } void draw(){ background(70); translate(width/2, height/2, 0); rotateX(radians(-100)); rotateY(radians(-10)); noStroke(); pointLight(200, 200, 200, 0, -300, 100); for(int i = 0; i < numOfRings; i++){ sphereRadius = sin(radians(i*(180./numOfRings)))*sphereOuterRadius; sphereTwist = cos(radians(i*(180./numOfRings)))*sphereOuterRadius; for(int j = 0; j < numOfInnerSpheres; j++){ sphereX = cos(radians(sphereTwist+(j*(360./numOfInnerSpheres))))*sphereRadius; sphereY = sin(radians(sphereTwist+(j*(360./numOfInnerSpheres))))*sphereRadius; sphereZ = cos(radians(i*(180./numOfRings)))*sphereOuterRadius; pushMatrix(); translate(sphereX, sphereY, sphereZ); scale(sphereSize); sphere(2); popMatrix(); } } }David
Hi Anil,
Thanks for sharing this. I’ve wrapped it up with pre tags :)