// =========================================================================== // 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: 2012 // // Description: // Routine to attach mesh to nHair system, creating nRigid object if needed // global proc attachNObjectToHair( string $hsys, string $mesh, int $collide) { if(size($mesh) < 1){ return; } if(nodeType($mesh) != "mesh"){ // warning here if collide == true return; } // cache selection string $sl[] = `ls -sl`; string $nObject = ""; // check if mesh is already an nRigid or nCloth string $objs[] =`listConnections -type nBase -sh 1 ($mesh +".worldMesh[0]")`; if( size($objs) > 0 ){ $nObject = $objs[0]; } else { $objs =`listConnections -type nCloth -sh 1 ($mesh +".inMesh")`; } if( size($objs) > 0 ){ $nObject = $objs[0]; if( nodeType($nObject) == "nCloth") { $objs = `listConnections -type mesh -sh 1 ($nObject+".outputStartMesh")`; string $startMesh; if( size($objs) > 0 ){ $startMesh = $objs[0]; } else { string $meshTforms[] = `listTransforms $mesh`; string $tform = $meshTforms[0]; string $startMeshName = "outputStartCloth#"; int $worldspace = getAttr( $nObject + ".localSpaceOutput" ); if( $worldspace ){ $startMesh = `createNode mesh -parent $tform -name ($startMeshName)`; } else { $startMesh = `createNode mesh -name ($startMeshName)`; } connectAttr ($nObject+".outputStartMesh") ($startMesh + ".inMesh"); setAttr ($startMesh + ".intermediateObject") true; } if( size($startMesh) > 0 && $startMesh != $mesh ){ select -r $mesh; select -add $startMesh; transplantHair 1 0; } } } else { if( !$collide ){ return; } // If it is not yet an nObject create an nRigid select -r $mesh; makeCollideNCloth(); string $rigids[] = `ls -sl`; if( size( $rigids ) > 0 ){ $nObject = $rigids[0]; if( !$collide ){ setAttr ($nObject + ".collide") false; } } } if(size($nObject) != 0 ){ connectAttr ( $nObject + ".nucleusId" ) ($hsys+".attachObjectId"); } // restore selection; select -r $sl; }