global proc meshOut(string $path)
{
// Find maya selection and count verts of that selection
string $obj[] = `ls -sl`;
int $num[] = `polyEvaluate -v $obj[0]`;
string $shp[] = `listRelatives -shapes $obj[0]`;
string $shape = $shp[0];
// Open file and write curve header
int $fileid = fopen($path, "w");
fprint($fileid, "AttributeBegin\n");
fprint($fileid, "Basis \"b-spline\" 1 \"b-spline\" 1 \n\tCurves \"cubic\" [" + $num[0] + "] \"nonperiodic\" \n\"P\" [");
// Loop over verts, jitter their position, and write those positions to the file
for($n = 0; $n < $num[0]; $n++) {
$vert = $shape + ".vtx[" + $n + "]";
$pos = `pointPosition -local $vert`;
float $jitter = sqrt($n+1)*(0.0000005*$n);
$x = rand(-$jitter, $jitter);
$y = rand(-$jitter, $jitter);
$z = rand(-$jitter, $jitter);
$str = ($pos[0] + $x) + " " +
($pos[1] + $y) + " " +
($pos[2] + $z) + "\n";
fprint($fileid, $str);
}
// Write curve footer and close file
fprint($fileid, "]\n\"constantwidth\" [0.005] \n");
fprint($fileid, "AttributeEnd\n");
fclose($fileid);
print "\nI'm working!\n";
}
// Run procedure
string $path = "/stuhome/vsfx419/archives/test.rib";
meshOut($path); |