// =========================================================================== // Copyright 2018 Autodesk, Inc. All rights reserved. // // Use of this software is subject to the terms of the Autodesk license // agreement provided at the time of installation or download, or which // otherwise accompanies this software in either electronic or hard copy form. // =========================================================================== // // Procedure name: // getShape // // Description: // Returns the name of the first selected object of type $type // // Input Arguments: // $type - the type of node the be returned // // Return Value: // The name of the first selected object of type $type. // proc string getShape() { string $theShape = ""; string $theShapes[] = `ls -selection -long -dagObjects -shapes`; if (size($theShapes) > 0) { $theShape = $theShapes[0]; } return $theShape; } // // Procedure name: // closestPointOn // // Description: // Creates either a closestPointOnMesh, nearestPointOnCurve, or // closestPointOnSurface, depending on the selection. Optionally // creates locators and hooks them up to the node we're interested in. // // Input Arguments: // $doSpaceLocator - if true, create and hook up a locator for the closest point's // input position // $doObjLocator - if true, create and hook up a locator for the closest point's // output position. // // Return Value: // The name of the first selected object of type $type. // global proc closestPointOn(int $doSpaceLocator, int $doObjLocator) { string $theShape = ""; string $shapeAttr = ""; string $inputAttr = ""; string $nodeType = ""; string $type = ""; $theShape = getShape(); if ($theShape != "") { $type = `nodeType $theShape`; } if ($type=="mesh") { $shapeAttr = "worldMesh"; $inputAttr = "inMesh"; $nodeType = "closestPointOnMesh"; } else if ($type=="nurbsCurve" || $type=="bezierCurve") { $shapeAttr = "worldSpace"; $inputAttr = "inputCurve"; $nodeType = "nearestPointOnCurve"; } else if ($type=="nurbsSurface") { $shapeAttr = "worldSpace"; $inputAttr = "inputSurface"; $nodeType = "closestPointOnSurface"; } if ($nodeType == "") { warning (uiRes("m_closestPointOn.kNoSelectionWarning")); return; } string $closestPointNode = `createNode ($nodeType)`; connectAttr($theShape+"."+$shapeAttr) ($closestPointNode+"."+$inputAttr); if ($type=="mesh") { connectAttr($theShape+".worldMatrix") ($closestPointNode+".inputMatrix"); } if ($doSpaceLocator) { string $locator[] = `spaceLocator -name cpConstraintIn`; connectAttr($locator[0]+".translate") ($closestPointNode+".inPosition"); } if ($doObjLocator) { string $locator[] = `spaceLocator -name cpConstraintPos`; connectAttr($closestPointNode+".position") ($locator[0]+".translate"); } }