// =========================================================================== // 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. // =========================================================================== ////////////////////////////////////////////////////////////////////////////// // This file contains the MEL script to create the Paintable Attribute Menu ////////////////////////////////////////////////////////////////////////////// global proc artAttrCreateMenuItems( string $parent, string $paintAttr, string $excludeTypes[] ) // // Description: // Creates a menu that shows all the paintable attributes. // // NOTE: paintAttr are sorted by the paintable node type. // { string $artCommand = "artAttrCtx"; source "artisanUtilities.mel" ; string $paintableItems[]; tokenize( $paintAttr, " ", $paintableItems ); int $size = size($paintableItems); if ( $size == 0 ) return; string $menu, $menuLabel, $nodeMenuLabel; string $attrName; string $buffer[]; int $i, $j; // Submenu counters. int $setParentCount = 0; int $menuItemCount = 0; for( $i = 0; $i < $size; $i++ ) { if ( "" == $paintableItems[$i] ) continue; tokenize( $paintableItems[$i], ".", $buffer ); int $excludedType = 0; for ($nodeType in $excludeTypes) { if ($buffer[0] == $nodeType) { $excludedType = 1; break; } } if ($excludedType) { continue; } // Create a paintable node submenu // if necessary. if ( $buffer[0] != $nodeMenuLabel ) { // Get back to the proper parent widget. for ($j = 0; $j < $setParentCount; $j++ ) { setParent ..; } // Reset the submenu counters. $setParentCount = 0; $menuItemCount = 0; // End the previous node subMenu. if ( $i > 0 ) { setParent -m $parent; } // Start a new node Menu; $nodeMenuLabel = $buffer[0]; menuItem -subMenu true -l $nodeMenuLabel; } if ( $menuItemCount == 30 ) { // If there are more than 30 paintable nodes // we need to split the menu into submenus // - otherwise it does not fit on the // screen. menuItem -subMenu true -label (uiRes("m_artAttrCreateMenuItems.kMore")); $setParentCount ++; $menuItemCount = 0; } // bug #193246 fix. now we use complete object names. Hence we have to remove the ugly part // and display a nice name to the user. $menuLabel = getNodeNameFromAbsolutePath( $buffer[1] ) + "-" + $buffer[2] ; string $attribute = $buffer[0] + "." + $buffer[1] + "." + $buffer[2]; $menu = `menuItem -l $menuLabel`; menuItem -e -c ("artSetToolAndSelectAttr( \"" + $artCommand + "\", \"" + $attribute + "\" )") $menu; $menuItemCount ++; } // Get back to the proper parent widget. for ($i = 0; $i<$setParentCount; $i++ ) { setParent ..; } setParent -m $parent; } global proc artSetToolAndSelectAttr( string $artCommand, string $attribute ) // // Description: // Set a new tool if require and select an initial attribute. // { source "artAttrCallback.mel"; global string $gArtSelectObject ; string $currTool = ""; { string $currentContext = `currentCtx`; if (`contextInfo -exists $currTool`) $currTool = `contextInfo -c $currentContext`; } // bug 222358 // select the object if it is not already selected by the user if( size($gArtSelectObject) > 0 ) { select -r ($gArtSelectObject); $gArtSelectObject = "" ; } // Check if we are in the right tool. string $buf[]; tokenize( $attribute, ".", $buf ); if ( size($buf) < 3 ) return; string $paintableNodeType = $buf[0]; string $paintableNodeName = $buf[1]; string $paintableAttribute = $buf[2]; if ( $paintableNodeType == "skinCluster" ) { // Check if this is skin paint weight tool. if ( $currTool != "artAttrSkin" ) { // Set the Skin Paint Weight tool. artAttrSkinToolScript( 4 ); } }else if ($paintableNodeType == "blendShape") { // Check if this is blendShape paint weight tool. if ( $currTool != "artAttrBlendShape" ) { // Set the Skin Paint Weight tool. artAttrBlendShapeToolScript( 4 ); } }else if ( $paintableNodeType == "mesh" && ($paintableAttribute == "vertexColorRGB" || $paintableAttribute == "vertexFaceColorRGB" ) ) { // Check if this is paint vertex color tool. if ( $currTool != "artAttrColorPerVertex" ) { if ( $paintableAttribute == "vertexColorRGB" ) { // Set the Paint Vertex Color itool. artAttrColorPerVertexToolScript( 5 ); } else { artAttrColorPerVertexToolScript( 6 ); } } } else { // You can only paint weights for polyReduce on a mesh node // upstream of the polyReduce node. This is because painting weights // on the mesh being reduced changes the topology and scrambles the // painted vertices. // So, here, we march up stream from the reduce node until // a valid mesh is found, and set that as the mesh being painted. // // The recommended way for you to use paint weights is to invoke the // command with the replaceOriginal flag off (or the Keep Original // option checked). // if ( $paintableNodeType == "polyReduce" ) { // get all upstream nodes // string $upstreamNodes[] = `listHistory $paintableNodeName`; int $i = 0; string $node = ""; int $found = false; // march through upstream nodes looking for a valid mesh // for ($node in $upstreamNodes ) { string $nodeType = `nodeType $node`; // only poly meshes are valid for polyReduce // if ( $nodeType == "mesh" ) { int $isVisible = `getAttr( $node + ".visibility" )`; int $isIntermediate = `getAttr( $node + ".intermediateObject" )`; int $isTemplated = `getAttr( $node + ".template" )`; // the node must be visible and not intermediate // if ( $isVisible && !$isIntermediate ) { // Un-template an otherwise valid node (so we can select it) // if ( $isTemplated ) { setAttr( $node + ".template", false ); string $warningMsg = (uiRes("m_artAttrCreateMenuItems.kCannotAcceptNode")); warning(`format -s $paintableNodeName -s $node $warningMsg` ); } $found = true; break; } } } // No valid upstream meshes. // if ( !$found ) { error (uiRes("m_artAttrCreateMenuItems.kCantPaintWeights")); return; } else { // found a valid mesh. Pick it as the mesh being painted. // select $node; } } if ( $currTool != "artAttr" ) { // Set the general Attribue Paint Tool. artAttrToolScript( 4, "" ); } } // Set the selected attribute as paintable. artAttrSelected( $artCommand, $attribute ); }