// =========================================================================== // 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: June 2003 // // Description: // This is an simple example script for the Artisan Script Paint // tool. It will paint Cones onto the selected surfaces taking direction // into consideration. The alignment of the Cones are controlled by the paint // direction. The rest of the job is similar to "spherePaint". // // Usage: // 1) Place this script into your scripts directory (usually the // maya/scripts directory in your home directory // 2) Select the Script Paint Tool (Modify->Script Paint Tool) // and bring up the Tool Settings window // 3) Go to the Setup tab and enter "conePaint" into the // "Tool Setup Cmd" field and hit enter // 4) Paint cones // // Tips: // Once you have the cone Paint Tool setup you may want to drag // it from the minibar to the shelf so that it is always accessible // // These are global variables used to keep track of multiple // surfaces and the name prefixes used for the cones on each // surface // global string $gConeNamePrefix[]; global int $gConePaintFreeSlot = 0; global int $gConePaintSlots = 0; // This procedure should be set as the "Tool Setup Cmd" in the // Setup tab of the Maya Artisan Script Paint tool's tool settings // window. The tool context is supplied as an argument. // global proc conePaint( string $context ) { // initialize all the other commands in this scriptable // paint tool context. // artUserPaintCtx -e -ic "initConePaint" -fc "finishConePaint" -svc "setConePaintValue" -gvc "getConePaintValue" -gsc "" -cc "" -tcc "" -gac "" $context; } // This is the "Initialize Cmd". This procedure is called once // for every selected surface when an intial click is received // on any surface. The argument is the name of the surface. This // procedure returns a string which indicates to the scriptable // tool how to behave for the duration of the stroke. // global proc string initConePaint( string $name ) { global string $gConeNamePrefix[]; global int $gConePaintFreeSlot; global int $gConePaintSlots; int $slot; // find a free slot for this surface in the global arrays // for ( $slot = $gConePaintFreeSlot; $slot < $gConePaintSlots; $slot++ ) { if ( $gConeNamePrefix[$slot] == "" ) { break; } } if ( $slot == $gConePaintSlots ) { $gConePaintSlots++; $gConePaintFreeSlot = $gConePaintSlots; } if ( `nodeType $name` == "nurbsSurface" || `nodeType $name` == "mesh" ) { // save the name of the parent of this shape as well // as a prefix to use when creating the cones // string $parent[] = `listRelatives -p $name`; $gConeNamePrefix[$slot] = $parent[0] + "cone"; } // Return an argument string which: // - tells the tool what surface ID to use for this surface // - indicates that values should be distributed on a 20x20 // grid on the surface // - indicate that the associated world space position // should also be passed to the "Set Value Cmd". // // Tells the tool to use direction & position of stamp // in world space. See documentation for other available // options . // return ( "-id " + $slot + " -grid 20 20 " + " -position world " + "-directionType worldV " + "-stampPosition world " ); } // This is the "Finalize Cmd". This procedure is called at the // end of the stroke. It is passed the surface ID, that was // generated by the "Initialize Cmd". // global proc finishConePaint( int $slot ) { global string $gConeNamePrefix[]; global int $gConePaintFreeSlot; // clear out the slot that was used for this surface // $gConeNamePrefix[$slot] = ""; if ( $slot < $gConePaintFreeSlot ) { $gConePaintFreeSlot = $slot; } } // This is the "Set Value Cmd". It is called everytime a value // on the surface is changed. A surface ID, a grid index // on the surface and the value associated with that grid index // is passed. There can be additional arguments depending on the // options generated by the return value of the "Initialize Cmd". // In this case the // - (x,y,z) refers to surface position for this grid point // - (u,v,w) refers to the stroke direction // - (spX,spY, spZ) and stamp positions // // global proc setConePaintValue( int $slot, int $index, float $val, float $x, float $y, float $z, float $u, float $v, float $w, float $spX, float $spY, float $spZ ) { global string $gConeNamePrefix[]; if ( $gConeNamePrefix[$slot] != "" ) { // determine the name of the cone associated with this // grid location // string $objname = $gConeNamePrefix[$slot] + $index; if ( `objExists $objname` ) { // if the cone already exists, use the value to // adjust the size of the cone. If the value is // 0, the cone is deleted // // re-orient the cones if already exist. // The history should be ON to do this. // cone -e -axis $u $v $w $objname; if ( $val > 0 ) { scale $val $val $val $objname; } else { delete $objname; } } else if ( $val > 0 ) { // the cone doesn't exist // string $sname[]; // create a cone with the proper name, scale it by // the passed value and parent the cone to the same // parent as the surface we are painting on // // Align the cone axis with the paint direction // // Keep the history to re-orient the cones later // // $sname=`cone -r .5 -hr 5.0 -ch on -name $objname -axis $u $v $w`; if ( $sname[0] != $objname ) { string $coneError = (uiRes("m_conePaint.kConeNameFailed")); catch (error (`format -s $objname -s $sname[0] $coneError`) ); } scale $val $val $val; move $x $y $z; } } } // This is the "Get Value Cmd". It is called everytime a value // on the surface is needed by the scriptable paint tool. A // surface ID and a grid index is passed in. This procedure should // return the value for this grid location on the specified surface. // global proc float getConePaintValue( int $slot, int $index ) { global string $gConeNamePrefix[]; if ( $gConeNamePrefix[$slot] != "" ) { // if this slot is valid, generate the name for the // cone at this grid index // string $objname = $gConeNamePrefix[$slot] + $index; if ( `objExists $objname` ) { // if the cone exists, return the X scale factor // as the value for this grid location // return `getAttr ($objname + ".sx")`; } else { // the cone doesn't exist, therefore return 0 as // the value for this grid location // return 0.0; } } else { return 0.0; } }