|
global proc polyMeshBlobbyRI()
{
// Get the names of the shape and transform nodes
string $shapeNode = `rman ctxGetObject`;
string $parents[] = `listRelatives -parent $shapeNode`;
string $tformNode = $parents[0];
// The values from the interface
string $attr;
$attr = `rmanGetAttrName "pmb_cache"`;
int $pmb_cache = `getAttr($shapeNode + "." + $attr)`;
// User has selected "Disable"
if($pmb_cache == 2) {
print("Blobby will not be generated - Disable is active");
return;
}
$attr = `rmanGetAttrName "pmb_size"`;
float $pmb_size = `getAttr($shapeNode + "." + $attr)`;
$attr = `rmanGetAttrName "pmb_height"`;
float $pmb_height = `getAttr($shapeNode + "." + $attr)`;
// Get the number of vertices of the polymesh
int $num[] = `polyEvaluate -v $tformNode`;
// The path to the rib file containing the description of the
// Blobby consists of "RIB_Archive" directory, the scene name,
// the shape name of the polymesh and the frame number, for
// example,
// RIB_Archive/bathroom/shaving_cream.0001.rib
string $projPath = `workspace -q -rootDirectory`;
string $sceneName = `file -q -sceneName -shortName`;
if(size($sceneName) == 0)
$sceneName = "untitled";
int $frame = `currentTime -q`;
string $fStr = "." + $frame;
if($frame < 10)
$fStr = ".000" + $frame;
else if($frame < 100)
$fStr = ".00" + $frame;
string $archiveNme = $sceneName +"_"+ $shapeNode + $fStr + ".rib";
string $path = $projPath + "RIB_Archive/"+ $archiveNme;
// User has selected "Compute"
if($pmb_cache == 0) {
int $fileid = `fopen $path "w"`;
print("Writing Blobby archive to:\n");
print(" \"" + $path + "\"\n");
// Begin writing the Blobby to the archive
fprint($fileid, "Blobby " + $num[0] + " [\n");
// Make each blob an ellipsoid and provide its array
// index. The indices monotonously increment by 16.
for($n = 0; $n < $num[0]; $n++)
fprint($fileid, "1001 " + ($n * 16) + "\n");
// Add the blending code "0" and the number of blobs to blend.
fprint($fileid, "0 " + $num[0]);
// Specify the indices of all the blobs.
for($n = 0; $n < $num[0]; $n++)
fprint($fileid, " " + $n);
fprint($fileid, "]\n");
fprint($fileid, "[\n");
// Specify the transformations of each blob
string $row1, $row2, $row3;
for($n = 0; $n < $num[0]; $n++) {
string $vert = $shapeNode + ".vtx[" + $n + "]";
$pos = `pointPosition -local $vert`;
$row1 = $pmb_size + " 0 0 0 ";
$row2 = " 0 " + $pmb_size + " 0 0 ";
$row3 = " 0 0 " + $pmb_size + " 0 ";
$row4 = $pos[0] + " " +
($pos[1] * $pmb_height) + " " +
$pos[2] + " 1\n";
fprint($fileid, $row1 + $row2 + $row3 + $row4);
}
fprint($fileid, "]\n");
fprint($fileid, "[\"\"]\n");
fclose $fileid;
}
else
{
print("Attempting to reuse:\n");
print(" \"" + $path + "\"\n");
}
// Tell prman to render the Blobby
RiTransformBegin();
RiReadArchive($path);
RiTransformEnd();
// Make sure the polymesh is totally invisible
RiAttribute "visibility" "int camera" 0;
RiAttribute "visibility" "int transmission" 0;
RiAttribute "visibility" "int diffuse" 0;
RiAttribute "visibility" "int specular" 0;
RiAttribute "visibility" "int photon" 0;
}
|