And here’s another pass at it. I figured out how to do everything I’ve been doing in about a tenth the code that’s actually much more flexible. Here we see 500 spheres created with a sin wave controlling their radius and 500 lights created with a cos wave controlling their color from red to cyan aligning with the center of the spheres. All objects are following the Klein_2 parametric formula from KSurf3D by animating along the surface of the bottle by incrementing the u and v values. Originally, my script was using the current selection to animate the objects which works in the viewport, but not with batch render. I eventually just wrote out keyframes for each frame for each object and this solved it.
Click To Play Fullscreen
The script to create objects:
int $i;
float $sini;
float $pi = 3.14159265;
for($i = 0; $i < 500; $i++)
{
$sini = sin(($i+1)/100.0*$pi);
print($sini);
sphere -radius $sini;
}
int $i;
float $red;
float $green;
float $blue;
float $pi = 3.14159265;
for($i = 0; $i < 500; $i++)
{
$red = (1+cos($i/100.0*2*$pi))/2;
$green = (1+cos($pi + ($i/100.0*2*$pi)))/2;
$blue = (1+cos($pi + ($i/100.0*2*$pi)))/2;
defaultPointLight(0.9, $red,$green,$blue, 2, 0, 0,0,0, 1);
}
The script to animate objects:
string $objects[] = `ls -sl`;
int $numObjects = size($objects);
float $speed = frame/12;
float $uinc = 0.025 ;
float $vinc = 0.1;
float $u = 0;
float $v = 0;
for($i = 0; $i < $numObjects; $i++)
{
setAttr($objects[$i] + “.translateX”, 5*(2 + cos(($speed+$u) / 2)* sin($v) - sin(($speed+$u))* sin(2 * $v))* cos(($speed+$u)));
setAttr($objects[$i] + “.translateY”, 5*(sin(($speed+$u) / 2)* sin($v) + cos(($speed+$u) / 2) *sin(2 * $v)));
setAttr($objects[$i] + “.translateZ”, 5*(2 + cos(($speed+$u) / 2)* sin($v) - sin(($speed+$u) / 2)* sin(2 * $v))* sin(($speed+$u)));
$u += $uinc;
$v += $vinc;
}
setKeyframe -e -at translateX;
setKeyframe -e -at translateY;
setKeyframe -e -at translateZ;