// =========================================================================== // 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. // =========================================================================== proc int matchNclothTopology(string $poly, int $nNclothVertices) { // Try to get the topology on the poly object to match the // number of vertices on the nCloth by turning the history // nodes to "hasNoEffect". // string $histNodes[] = `listHistory -pdo true $poly`; string $currCtx = `currentCtx`; string $newCmd = ""; string $origCmd = ""; string $cmd[] = `artAttrCtx -q -toolOffProc $currCtx`; if (size($cmd) > 0) { $newCmd = $cmd[0]; $origCmd = $cmd[0]; } for ($histNode in $histNodes) { int $nstate = `getAttr ($histNode+".nodeState")`; if ($nstate != 1) { setAttr ($histNode+".nodeState") 1; // save a command to re-enable the existing nodeState // $newCmd += ("setAttr "+$histNode+".nodeState "+$nstate+"; "); } } // Check if the vertex count matches now. // int $nVerticesToPaint[] = `polyEvaluate -v $poly`; if ($nVerticesToPaint[0] == $nNclothVertices) { // Vertex count matches. Allow the user to paint, and register the // nodeState re-enable as a toolOffProc. Also, in the toolOffProc, // restore it to its former value so that it does not keep // setting those node states during subsequent usages. // $newCmd += ("artAttrCtx -e -toolOffProc \""+$origCmd+"\" "+$currCtx+";"); artAttrCtx -e -toolOffProc $newCmd `currentCtx`; return 1; } // Vertex count didn't match. Re-enable the nodes and return failure. // eval $newCmd; return 0; } global proc NClothPaintCallback(string $attr) { global string $gArtAttrNClothCurrentAttr; if ($attr == "") { $attr = $gArtAttrNClothCurrentAttr; if ($attr == "") { $attr = "thickness"; } } else { if (! `exists nClothAttributeToPaint_uiToMel` ) { source "artAttrNClothProperties.mel"; } $attr = nClothAttributeToPaint_uiToMel($attr); } // The 1 to getNMeshToPaint means we accept component selections // string $tmp[] = `getNMeshToPaint "" 1`; if (size($tmp) > 1) { string $nodeType = `nodeType $tmp[1]`; makePaintable -activateAll false; makePaintable -activate true $nodeType ($attr+"PerVertex"); int $nVerticesToPaint[] = `polyEvaluate -v $tmp[0]`; int $nVerticesOnNcloth = `getAttr ($tmp[1]+".count")`; if ($nVerticesToPaint[0] != $nVerticesOnNcloth) { if (!matchNclothTopology($tmp[0],$nVerticesOnNcloth)) { error((uiRes("m_NClothPaintCallback.kNumVerticesDoesNotMatch"))); } } artAttrPaintInstSelectAllDN($nodeType,($tmp[1]+"."+$attr+"PerVertex")); } }