// =========================================================================== // 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: // assigns passed in hairsystem to selected hair objects // proc string copyHairSystem(string $hsys) { string $hsysParent[] = `listTransforms $hsys`; string $newHsys; if( size($hsysParent) > 0 ){ string $dup[] = `duplicate -n ($hsys + "copy") $hsysParent[0]`; $dup = `ls -shapes -dag $dup[0]`; $newHsys = $dup[0]; } else { string $dup[] = `duplicate -n ($hsys + "copy") $hsysParent[0]`; $newHsys = $dup[0]; } string $outputPfx[] = `listConnections ($hsys + ".outputRenderHairs")`; if( size( $outputPfx ) > 0 ){ string $pfxHair = `createNode pfxHair`; setAttr ( $pfxHair + ".displayPercent") 100; setAttr ( $pfxHair + ".drawAsMesh") false; connectAttr ($newHsys + ".outputRenderHairs") ($pfxHair + ".renderHairs"); } return $newHsys; } global proc assignHairSystem( string $hsys ) { if( $hsys != "" ){ if( !objExists( $hsys ) ){ string $fmt = (uiRes("m_assignHairSystem.kInvalidHairSystem")); warning( `format -s $hsys $fmt` ); return; } if( nodeType( $hsys ) != "hairSystem" ){ string $shape[] = `ls -dag -shapes $hsys`; if( size( $shape ) > 0 ){ $hsys = $shape[0]; } if( nodeType( $hsys ) != "hairSystem" ){ string $fmt = (uiRes("m_assignHairSystem.kNotAHairSystem")); warning( `format -s $hsys $fmt` ); return; } } } string $sel[] = `ls -sl`; convertHairSelection( "follicles" ); string $follicles[] = `ls -sl`; int $lastIndex[] = {0}; if( size( $follicles ) > 0 ){ if( $hsys == "" ){ string $selHsys[] = getSelectedHairSystems(); if( size( $selHsys ) > 0 ){ $hsys = copyHairSystem( $selHsys[0] ); } else { $hsys = `createNode hairSystem`; } string $nucleus = getActiveNucleusNode( false, true ); addActiveToNSystem( $hsys, $nucleus); connectAttr ($nucleus + ".startFrame") ($hsys + ".startFrame"); connectAttr time1.outTime ($hsys + ".currentTime"); } attachFolliclesToHairSystem( $hsys, $follicles ); } else { // no follicles selected(directly or indirectly) // .. see if we have any curves that we could // make dynamic string $curves[] = `ls -dag -type nurbsCurve $sel`; if( size( $curves ) > 0 ){ if( $hsys == "" ){ $hsys = `createNode hairSystem`; string $nucleus = getActiveNucleusNode( false, true ); addActiveToNSystem( $hsys, $nucleus); connectAttr ($nucleus + ".startFrame") ($hsys + ".startFrame"); connectAttr time1.outTime ($hsys + ".currentTime"); } attachCurvesToHairSystem( $hsys, $curves, false ); } else { warning( (uiRes("m_assignHairSystem.kNoValidObjects")) ); } } select $sel; }