// This script takes an input curve on the xz plane and // -> extrudes it to create a reference nurbssurface // -> creates a nurbsPlane and trims it with the input curve // -> creates a polygon mesh from the resulted trimmed nurbsPlane // -> iterates through each vertex of the poly mesh, raising it as a function of distance from the edge of the curve // The distance is calulated by using the closespointonsurfacenode, using each vertex position as an input to the // closes point on surface node, relative to the extruded reference nurbsurface global proc int gelcapPolyPlane() { // ************************ // Ensure one object selected // ************************ $listOfSelectedObjects = `ls -sl`; if (size($listOfSelectedObjects) >1) { print ("More than one object selected - Please select one nurbs curve.\n"); return 0; }; // ************************ // reveal object found // ************************ print ($listOfSelectedObjects[0]+"\n"); // ************************ // ensure object is nurbsCurve shape // ************************ $listOfObjectType = `ls -st $listOfSelectedObjects[0]`; string $targetCurve; if ($listOfObjectType[1] != "nurbsCurve") { pickWalk -d down; $listOfSelectedObjects = `ls -sl`; $listOfObjectType = `ls -st $listOfSelectedObjects[0]`; if ($listOfObjectType[1] != "nurbsCurve") { print ("Object selected is not a nurbsCurve - please select one nurbsCurve.\n"); return 0; }; }; $targetCurve = $listOfSelectedObjects[0]; print ("Target curve is: "+ $targetCurve+"\n"); // ************************ // extrude the curve // ************************ select $targetCurve; extrude -n templateSurface -ch true -rn false -po 0 -et 0 -upn 1 -length .001 -rotation 0 -scale 1 -dl 3 $targetCurve ; // ************************ //make a trimmed nurbssurface // ************************ nurbsPlane -p 0 0 0 -ax 0 1 0 -w 1 -lr 1 -d 3 -u 100 -v 100 -ch 1 -n nurbTemplate; scale -r 24 24 24; projectCurve -ch true -rn false -un true -tol 0.01 $targetCurve nurbTemplate; select nurbTemplate; trim -ch on -o on -rpo off -lu 0.1 -lv 0.1 -sl 1 -n trimmedTemplate nurbTemplateShape projectionCurve1_Shape1 ; delete nurbTemplate; // ************************ //make trimmed nurbssurface into a poly // ************************ nurbsToPoly -mnd 1 -ch 1 -f 2 -pt 0 -pc 200 -chr 0.1 -ft 0.01 -mel 0.001 -d 0.1 -ut 3 -un 3 -vt 3 -vn 3 -uch 0 -ucr 0 -cht 0.01 -es 0 -ntr 0 -uss 1 -n polyTrimmedTemplate "trimmedTemplate"; delete trimmedTemplate; // ************************ // place all poly verteces based on distance to extruded surface // ************************ $numberOfVerteces = `polyEvaluate -v polyTrimmedTemplate`; print ("Verts: "+$numberOfVerteces[0]+"\n"); if ($numberOfVerteces[0] <= 0) { print ("Error: No verts on poly surface - breaking out of hang loop. \n"); return 0; }; distanceDimension -sp 0 0 0 -ep 0 5 0; createNode -n myCloseNode closestPointOnSurface; connectAttr -f locator1.translateX myCloseNode.inPositionX; connectAttr -f locator1.translateY myCloseNode.inPositionY; connectAttr -f locator1.translateZ myCloseNode.inPositionZ; connectAttr -f templateSurface.local myCloseNode.inputSurface; // ************************ // Prescan to look for largest distance point // ************************ print ("Prescanning for Largest Distance."); $largestDistance = 0.0; $counter = 0; while ($counter < $numberOfVerteces[0]) { float $xyzPosition[3] = `xform -q -t -ws polyTrimmedTemplate.vtx[$counter]`; setAttr locator1.tx $xyzPosition[0]; setAttr locator1.ty $xyzPosition[1]; setAttr locator1.tz $xyzPosition[2]; setAttr locator2.tx `getAttr myCloseNode.positionX`; setAttr locator2.ty `getAttr myCloseNode.positionY`; setAttr locator2.tz `getAttr myCloseNode.positionZ`; float $currentDistance = `getAttr distanceDimension1.distance`; if ($currentDistance > $largestDistance) $largestDistance = $currentDistance; if (($counter%100)==0) print ("."); $counter++; }; print ("Done.\n"); // ************************ // Push all verteces up as a function of their distance // ************************ $radius = $largestDistance; $distanceUp = 0.0; $distanceAway = 0.0; $cosHolder = 0.0; $counter = 0; while ($counter < $numberOfVerteces[0]) { float $xyzPosition[] = `xform -q -t -ws polyTrimmedTemplate.vtx[$counter]`; setAttr locator1.tx $xyzPosition[0]; setAttr locator1.ty $xyzPosition[1]; setAttr locator1.tz $xyzPosition[2]; setAttr locator2.tx `getAttr myCloseNode.positionX`; setAttr locator2.ty `getAttr myCloseNode.positionY`; setAttr locator2.tz `getAttr myCloseNode.positionZ`; $distanceAway = `getAttr distanceDimension1.distance`; $cosHolder = (($radius-$distanceAway)/$radius); $distanceUp = $radius*(sin(acos(pow($cosHolder,2)))); select -r polyTrimmedTemplate.vtx[$counter] ; move -r 0 $distanceUp 0 ; select -cl; // if ($counter == 75) // // print ("cv Number 75 data : \n"); // print (`getAttr distanceDimension1.distance`+"\n"); // print ("Locator: "+ // `getAttr locator1.tx`+" "+ // `getAttr locator1.ty`+" "+ // `getAttr locator1.tz`+"\n"); // sphere -n vertexPosition; // move -a `getAttr locator1.tx` `getAttr locator1.ty` `getAttr locator1.tx`; // print ("Closest: "+ // `getAttr myCloseNode.positionX`+" "+ // `getAttr myCloseNode.positionY`+" "+ // `getAttr myCloseNode.positionZ`+"\n"); // sphere -n closest; // move -a `getAttr myCloseNode.positionX` `getAttr myCloseNode.positionY` `getAttr myCloseNode.positionZ`; // }; if (($counter%100)==0) refresh; $counter++; }; select -r myCloseNode; delete myCloseNode; return 1; }