// =========================================================================== // 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. // =========================================================================== // // // // // // moveCacheToInput( int $displayInput ) // // // None. // // // This command moves the cache for the selected nCloth object to a geometry cache on the // input mesh of the nCloth. It also enables inputMeshAttract so that the cloth simulation // is attracted to its input. One could map or modify the inputMeshAttract to allow for // local modifications of the cached simulation. Or the nCloth could be deleted so that one // would only have the input mesh with the cached simualtion. // // // $displayInput If true then display the input cloth mesh instead of the output. // // // moveCacheToInput false; // global proc moveCacheToInput(int $displayInput) { string $sel[] = `ls -sl`; if (size($sel) == 0) { error( (uiRes("m_moveCacheToInput.kMustSelectACloth"))); } string $upstreamSel[] = `listHistory`; string $nCloths[] = `ls -type nCloth $upstreamSel`; if( size( $nCloths ) < 1 ){ warning( (uiRes("m_moveCacheToInput.kNoClothSelected"))); return; } string $noCacheString = (uiRes("m_moveCacheToInput.kNoCache")); for( $cloth in $nCloths ) { string $con[] = `listConnections ($cloth + ".playFromCache")`; if( size( $con ) < 1 ){ string $warnMsg = `format -stringArg $cloth $noCacheString`; warning $warnMsg; continue; } string $currentCache = $con[0]; $con = `listConnections -shapes 1 ($cloth + ".inputMesh")`; if( size( $con ) < 1 ){ string $warnFormat = (uiRes("m_moveCacheToInput.kNoInputMesh")); string $warnMsg = `format -stringArg $cloth $warnFormat`; warning $warnMsg; continue; } string $inputMesh = $con[0]; // If the output mesh and the input mesh have a different parent, warn // the user. // string $outConns[] = `listConnections -shapes 1 ($cloth + ".outputMesh")`; if( size($outConns) >= 1 ){ string $outputMesh = $outConns[0]; string $inputParents[] = `listRelatives -parent $inputMesh`; string $outputParents[] = `listRelatives -parent $outputMesh`; if( size($inputParents) > 0 ){ if( size($outputParents) > 0 ){ if( $inputParents[0] != $outputParents[0] ){ string $wrnFormat = (uiRes("m_moveCacheToInput.kNotSibling")); string $wrnMsg = `format -s $inputMesh -s $outputMesh $wrnFormat`; warning $wrnMsg; } } } } setAttr ($inputMesh + ".visibility") true; setAttr ($inputMesh + ".intermediateObject") false; string $switch = createHistorySwitch( $inputMesh, false ); $switch = `rename $switch "cacheSwitch#"`; setAttr ($switch + ".ihi") 0; string $outCacheDataPlug[] = `listConnections -p on ($cloth + ".positions")`; if( size($outCacheDataPlug) != 1 ) { warning `format -stringArg $cloth $noCacheString`; continue; } connectAttr -f $outCacheDataPlug ($switch + ".inPositions[0]"); connectAttr -f ($currentCache + ".inRange") ($switch + ".playFromCache"); disconnectAttr $outCacheDataPlug ($cloth + ".positions"); disconnectAttr ($currentCache + ".inRange") ($cloth + ".playFromCache"); if( $displayInput ){ setAttr ($inputMesh + ".overrideEnabled") 1; setAttr ($inputMesh + ".overrideShading") 0; setAttr ($inputMesh + ".primaryVisibility") 0; setAttr ($inputMesh + ".castsShadows") 0; setAttr ($inputMesh + ".visibleInReflections") 0; setAttr ($inputMesh + ".visibleInRefractions") 0; } else { setAttr ($inputMesh + ".intermediateObject") true; } setAttr ($cloth + ".inputMeshAttract") 1.0; }//end for nCloth }