BLOGGER TEMPLATES AND TWITTER BACKGROUNDS »

Monday, October 11, 2010

Soft influence falloff for objects

These two procedures will take an object, and influence surrounding objects based on their distance from the object, and a falloff distance specified. Similar to how the Soft Modification Tool works for meshes, but this is for objects.

//
// TAKES A LOCATOR THAT INFLUENCES SURROUNDING OBJECTS BASED ON THEIR DISTANCE FROM IT
//

global proc jsCreateSoftSelectLoc(string $locator, string $objects[], float $falloffDistance) {

float $start[] = `xform -q -ws -piv $locator`;

for ($i=0;$i<size($objects);$i++) {
float $offsetVal[];
float $curPos[] = `xform -q -ws -piv $objects[$i]`;

// make a distance dimension node to find the distance, then find the ratio based of the input
string $dis[] = jsCreateMeasureTool($locator,$objects[$i]);
float $distance = `getAttr ($dis[0]+".distance")`;
float $disRatio = $distance / $falloffDistance;
if ($disRatio > 1) $disRatio = 1;
$disRatio = 1 - $disRatio;
delete $dis[0] $dis[1] $dis[2];

// get the original distance between them
$offsetVal[0] = $start[0] - $curPos[0];
$offsetVal[1] = $start[1] - $curPos[1];
$offsetVal[2] = $start[2] - $curPos[2];

// make it so we can just add a value to them by finding the orig pos
string $plusNode = `shadingNode -asUtility plusMinusAverage`;
connectAttr ($plusNode+".output3D") ($objects[$i]+".t");
setAttr ($plusNode+".input3D[0]") $curPos[0] $curPos[1] $curPos[2];

// add the distance minus the orignal offset
string $addNode = `shadingNode -asUtility plusMinusAverage`;
string $multNode = `shadingNode -asUtility multiplyDivide`;
connectAttr ($locator+".t") ($addNode+".input3D[0]");
setAttr ($plusNode+".input3D[1]") $offsetVal[0] $offsetVal[1] $offsetVal[2];
setAttr ($addNode+".operation") 2;
connectAttr ($addNode+".output3D") ($multNode+".input1");
setAttr ($multNode+".input2") $disRatio $disRatio $disRatio;
connectAttr ($multNode+".output") ($plusNode+".input3D[1]");
}
}

//
// CREATE A MEASUREMENT TOOL BETWEEN TWO OBJECTS
//

global proc string[] jsCreateMeasureTool(string $start, string $end) {
string $return[0];
float $startPos[0];
float $endPos[0];
$startPos = `xform -q -ws -rp $start`;
$endPos = `xform -q -ws -rp $end`;
$tmpLoc = `spaceLocator -name ($start + "_distanceStart")`;
$tmpLoc2 = `spaceLocator -name ($end + "_distanceEnd")`;
move -a -ws $startPos[0] $startPos[1] $startPos[2] $tmpLoc[0];
move -a -ws $endPos[0] $endPos[1] $endPos[2] $tmpLoc2[0];
$dimension = `createNode distanceDimShape `;
connectAttr ($tmpLoc[0] + ".worldPosition[0]") ($dimension + ".startPoint");
connectAttr ($tmpLoc2[0] + ".worldPosition[0]") ($dimension + ".endPoint");
$parent = `listRelatives -f -p $dimension`;
$newName = `rename $parent[0] ($start + "_distance")`;
$return[0] = $newName;
$return[1] = $tmpLoc[0];
$return[2] = $tmpLoc2[0];
return $return;
}

0 comments: