SphereMatrix( "ball" );
global proc SphereLerp( string $name, int
$nbeg, int $nend, int $nstep ) {
SphereFill( $name,
$nbeg, $nend, $nstep );
LerpSphere( $name,
$nbeg, $nend, $nstep );
}
global proc SphereFill( string $name, int
$nbeg, int $nend, int $nstep ) {
string $attr, $n;
int $u, $v;
int $i, $k;
int $num;
float $pos[3], $pos1[3], $pos2[3];
$num = ($nend - $nbeg) / $nstep;
$n = $name + $nbeg;
$attr= $n + ".spansU";
$u = `getAttr $attr`;
$attr= $n + ".spansV";
$v = `getAttr $attr`;
$attr = $n + ".translate";
$pos1 = `getAttr $attr`;
print( $n + ": spansU=" + $u + ", spansV="
+ $v);
print( ", pos= (" + $pos1[0] + ","
+ $pos1[1] + "," + $pos1[2] + ")\n" );
$n = $name + $nend;
$attr = $n + ".translate";
$pos2 = `getAttr $attr`;
for ($i=$nbeg + $nstep; $i<$nend; $i += $nstep) {
$n = $name
+ $i;
for($k=0; $k < 3; $k++)
$pos[$k]
= ylerp( (float) $i, $nbeg, $nend,
$pos1[$k], $pos2[$k]
);
sphere -ax
0 1 0 -s $u -nsp $v -name $n;
move -a $pos[0] $pos[1] $pos[2];
}
}
global proc LerpSphere( string $name, int
$nbeg, int $nend, int $nstep )
{
string $attr, $n;
int $u, $v;
int $i, $j, $k, $m;
int $num;
string $attr, $attr1, $attr2;
string $at;
float $pt[3], $pt1[3], $pt2[3];
$num = ($nend - $nbeg) / $nstep;
$n = $name + $nbeg;
$attr= $n + ".spansU";
$u = `getAttr $attr`;
$attr= $n + ".spansV";
$v = `getAttr $attr`;
$attr = $n + ".translate";
$pos1 = `getAttr $attr`;
print( $n + ": spansU=" + $u + ", spansV="
+ $v + "\n");
$n1 = $n;
$n2 = $name + $nend;
for ($i=$nbeg + $nstep; $i<$nend; $i += $nstep) {
$n = $name + $i;
for($j=0; $j <= $u; $j++){
for($m=0; $m <= $v; $m++){
$n
= $name + $i;
$at = ".cv[" + $j + "]["
+ $m + "]";
$attr1 = $n1 + $at;
$pt1
= `getAttr
$attr1`;
$attr2
= $n2 + $at;
$pt2
= `getAttr
$attr2`;
for($k=0; $k < 3; $k++)
$pt[$k] = ylerp( (float) $i, $nbeg, $nend,
$pt1[$k], $pt2[$k] );
$attr
= $n + $at;
setAttr
$attr $pt[0] $pt[1] $pt[2];
}
}
}
}
global proc float ylerp( float $x, float
$x0, float $x1, float $y0, float $y1 )
{
float $slope, $y;
$slope = ($y1 - $y0) / ($x1 - $x0);
$y = $slope * ($x - $x0) + $y0;
return $y;
}
Using the above MEL script, we get the following result:
