// =========================================================================== // 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: // Make selected objects collide with selected hair systems // global proc makeCollideHair() { int $tess = 200; // default from dynSetFluidOptionVars.mel if(`optionVar -exists tessellationFactor`){ $tess = `optionVar -query tessellationFactor`; } string $selected[] = `ls -sl`; // Handle the case where the xform nodes are selected. string $nurbs[] = `listRelatives -ni -s -type "nurbsSurface" $selected`; string $meshs[] = `listRelatives -ni -s -type "mesh" $selected`; string $hairs[] = getSelectedHairSystems(); // Handle the case where the shape nodes are selected. string $select; for( $select in $selected ) { if( `nodeType $select` == "nurbsSurface" ) $nurbs[size($nurbs)] = $select; if( `nodeType $select` == "mesh" ) $meshs[size($meshs)] = $select; } if( size($nurbs) + size($meshs) == 0 ) { error (uiRes("m_makeCollideHair.kSelectNurbsOrMesh")); return; } if( size($hairs) == 0 ) { error (uiRes("m_makeCollideHair.kSelectHair")); return; } string $cmd; string $geometry; string $hair; string $alreadyCollidingStr = (uiRes("m_makeCollideHair.kAlreadyColliding")); for($geometry in $nurbs) { for($hair in $hairs) { if(`collision -q $geometry $hair`) { warning(`format -s $geometry -s $hair $alreadyCollidingStr`); continue; } $cmd = "createNode geoConnector;"; string $geo = evalEcho($cmd); setAttr ($geo + ".tessellationFactor") $tess; $cmd = "connectAttr " + $geometry + ".message " + $geo + ".owner;"; evalEcho($cmd); $cmd = "connectAttr " + $geometry + ".worldMatrix[0] " + $geo + ".worldMatrix;"; evalEcho($cmd); $cmd = "connectAttr " + $geometry + ".local " + $geo + ".localGeometry;"; evalEcho($cmd); $cmd = "connectAttr -na " + $geo + ".resilience " + $hair + ".collisionResilience;"; evalEcho($cmd); $cmd = "connectAttr -na " + $geo + ".friction " + $hair + ".collisionFriction;"; evalEcho($cmd); $cmd = "connectAttr -na " + $geo + ".sweptGeometry " + $hair + ".collisionGeometry;"; evalEcho($cmd); $cmd = "connectAttr time1.outTime " +$geo + ".currentTime"; evalEcho($cmd); } } for($geometry in $meshs) { for($hair in $hairs) { if(`collision -q $geometry $hair`) { warning(`format -s $geometry -s $hair $alreadyCollidingStr`); continue; } $cmd = "createNode geoConnector;"; string $geo = evalEcho($cmd); setAttr ($geo + ".tessellationFactor") $tess; $cmd = "connectAttr " + $geometry + ".message " + $geo + ".owner;"; evalEcho($cmd); $cmd = "connectAttr " + $geometry + ".worldMatrix[0] " + $geo + ".worldMatrix;"; evalEcho($cmd); $cmd = "connectAttr " + $geometry + ".outMesh " + $geo + ".localGeometry;"; evalEcho($cmd); $cmd = "connectAttr -na " + $geo + ".resilience " + $hair + ".collisionResilience;"; evalEcho($cmd); $cmd = "connectAttr -na " + $geo + ".friction " + $hair + ".collisionFriction;"; evalEcho($cmd); $cmd = "connectAttr -na " + $geo + ".sweptGeometry " + $hair + ".collisionGeometry;"; evalEcho($cmd); $cmd = "connectAttr time1.outTime " +$geo + ".currentTime"; evalEcho($cmd); } } }