// =========================================================================== // 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. // =========================================================================== // // // Creation Date: 2003 // // Description: Create hair constraint for selected hairs // global proc createHairConstraint(int $mode) { string $hsys[]; int $ind[] = selectedHairSystemIndices( $hsys ); int $numInd = size($ind); if( $numInd == 0 ){ warning( (uiRes("m_createHairConstraint.kNoHairCurvesSelected"))); return; } int $numPinInputs = `getAttr -size ($hsys[0] + ".inputHairPin" )`; float $bb[]; int $positionAtMidpoint = true; if( $positionAtMidpoint ){ string $htform[] = `listTransforms $hsys[0]`; if( size($htform) > 0 ){ select -d $htform[0]; } $bb= `exactWorldBoundingBox`; } string $hpin = `createNode hairConstraint`; if( $positionAtMidpoint ){ move (($bb[0] + $bb[3])*0.5) (($bb[1] + $bb[4])*0.5) (($bb[2] + $bb[5])*0.5) $hpin; } setAttr ($hpin + ".constraintMethod") ($mode+1); int $ci; for( $ci = 0; $ci < $numInd; $ci++ ){ setAttr ($hpin + ".curveIndices[" + $ci + "]") ($ind[ $ci ]); } int $pinInd; for( $pinInd = 0; $pinInd <= $numPinInputs; $pinInd++ ){ string $input = ($hsys[0] + ".inputHairPin[" + $pinInd +"]"); if( $pinInd < $numPinInputs ){ string $con = `connectionInfo -sfd $input`; if( size( $con ) > 0 ){ // already connected, keep looking continue; } } connectAttr ($hpin + ".outPin[0]") $input; break; } }