////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // // // - L F d r a w p o l y T o o l v1.0 - // // By // // Landis R. Fields IV // Landis@LandisFields.com // www.LandisFields.com // // // SUMMARY // This script "draws" quad based polys individualy OR on the surface of the selected mesh (resurfacing). // // INSTALLATION: // Place this file into your scripts directory. // // For Windows your path should most likely be... // "C:\Documents and Settings\*user*\My Documents\maya\7.0\scripts\LFdrawpolyTool.mel" // // For the Mac your path should most likely be... // "Library\Preferences\Alias\maya\7.0\scripts\LFdrawpolyTool.mel" // // // PLEASE NOTE: // This script assumes the user intends to model in a "quad compatible" fashion therefore while using the // LFdrawpolyTool the user should be creating polygons that will result in an even numbered point count // that is greater than 2, otherwise you will end up with tri's which defeats the purpose all together. // The "resurfacing" feature only works on geometric objects for obvious reasons (NURBS, poly's, etc.). // If you are getting tri's when you should be getting quads then you most-likely need more resolution. // // USAGE: // Enter the LFdrawpolyTool by typing LFdrawpolyTool.mel OR use a shelf button. Once the tool is intialized // simply click to place each vertex and press Enter when your done. To use the "resurfacing" feature, select // a single mesh (only one object) before running the script in which case the LFdrawpolyTool will assume // you want to draw new polys directly on the surface of the selected geometry (a process that is very common // in the visual effects industry for resurfacing hi-resolution scan data of actors, props, bigatures, etc.). // // // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // LFdrawpolyTool Procedure ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// global proc LFdrawpolyTool () { //Clear Maya's "live" status by toggling it to "none" (any objects made live will no longer be live) makeLive -none; //Before we do anything we get the name of the currently selected object/s and store the result in an array variable string $LFdrawpolyToolSelectedObjectsList[] = `ls -sl`; //Next we check that variable to see if the user had more then one object selected and if so then... if(`size($LFdrawpolyToolSelectedObjectsList)` >= 2) { //...we assume the user is trying to resurface more than one object and we explain that this is not possible error "More then one object selected! The resurfacing feature of LFdrawpolyTool only works on one object at a time."; } //Otherwise (else) the user must have either 1 OR no objects selected so... else { //Weed out the scenario where the user has nothing selected by sending them on to use the tool if (`size($LFdrawpolyToolSelectedObjectsList)` == 0) { //Run the "LFdrawpolyToolProcessing" procedure LFdrawpolyToolContext; } //Otherwise (else) they must have only one object selected so... else { //Check to see if the object the user DOES have selected is infact geometry and if so then... //Check to see if the custom "LFdrawpolyToolLiveObject" attribute already exists on this object and if so then... if (`attributeExists "LFdrawpolyToolLiveObject" $LFdrawpolyToolSelectedObjectsList[0]` == 1) { //...we remove (delete) the attribute so we can... deleteAttr ($LFdrawpolyToolSelectedObjectsList[0] + ".LFdrawpolyToolLiveObject"); //...add a fresh one before we... addAttr -ln LFdrawpolyToolLiveObject -dt "string" ("|" + $LFdrawpolyToolSelectedObjectsList[0]); setAttr -e -keyable true ("|" + $LFdrawpolyToolSelectedObjectsList[0] + ".LFdrawpolyToolLiveObject"); //...make the object "live" and... makeLive $LFdrawpolyToolSelectedObjectsList[0]; //...run (jump to) the "LFdrawpolyToolProcessing" procedure LFdrawpolyToolContext; } //Otherwise (else) we dont need to delete it bofore we can add it so we can just... else { //...tag the selected object with our custom identity attribute... addAttr -ln LFdrawpolyToolLiveObject -dt "string" ("|" + $LFdrawpolyToolSelectedObjectsList[0]); setAttr -e -keyable true ("|" + $LFdrawpolyToolSelectedObjectsList[0] + ".LFdrawpolyToolLiveObject"); //...make the object "live" and... makeLive $LFdrawpolyToolSelectedObjectsList[0]; //...run (jump to) the "LFdrawpolyToolProcessing" procedure LFdrawpolyToolContext; } //Otherwise (else) tell the user that the resurfacing feature of LFdrawpolyTool only works on geometry. } } } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // LFdrawpolyToolContext Procedure ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// global proc LFdrawpolyToolContext () { //Enter the "CreatePolygonTool" CreatePolygonTool; //Create the "LFdrawpolyToolContext" scriptJob (the backbone of the script that alows us to use mel to make a Maya "tool") int $LFdrawpolyToolContextScriptJobId = `scriptJob -runOnce 1 -event "ToolChanged" "LFdrawpolyToolProcessing"`; //Give the user "Tool" feedback print "LFdrawpolyTool initialized. Click to place each vertex. To finish, press Enter."; } ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // LFdrawpolyToolProcessing Procedure ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// global proc LFdrawpolyToolProcessing () { //Toggle Maya's "live" status to "none" (any objects made live will no longer be live) makeLive -none; //Get the name of the currently selected object/s and store the result in an array variable string $LFdrawpolyToolProcessingSelectedObjectsList[] = `ls -sl`; //Loop through the list of selected objects and... for($LFdrawpolyToolProcessingEachObject in $LFdrawpolyToolProcessingSelectedObjectsList) { //Select each object select -r $LFdrawpolyToolProcessingEachObject; //Triangulate the poly object Triangulate -ch 0; //Get the triangle count for the poly object and store the result in variable int $LFdrawpolyToolProcessingEachPolygonTriangleCount[0] = `polyEvaluate -triangle`; //Subtract 1 from the array size to compensate for the fact that arrays start at "0" int $LFdrawpolyToolProcessingEachPolygonTriangleCountNew = $LFdrawpolyToolProcessingEachPolygonTriangleCount[0] - 1; //Quadrangulate the poly object using the default Quadrangulate options polyQuad -a 180 -kgb 1 -ktb 1 -khe 0 -ws 0 -ch 0 $LFdrawpolyToolProcessingEachObject ($LFdrawpolyToolProcessingEachObject + ".f[0:" + $LFdrawpolyToolProcessingEachPolygonTriangleCountNew + "]"); } //Clear the selction select -cl; //Select all of the geometry in the scene string $LFdrawpolyToolProcessingSelectedGeometry[] = `SelectAllGeometry`; //Now list the selected objects and store the result in a variable string $LFdrawpolyToolProcessingAllGeometry[] = `ls -sl`; //Clear the selction select -cl; //Loop through all strokes in the scene and... for($LFdrawpolyToolProcessingEachGeoObject in $LFdrawpolyToolProcessingAllGeometry) { //Check for the attribute that tells us if its ours and if not then... if (`attributeExists "LFdrawpolyToolLiveObject" $LFdrawpolyToolProcessingEachGeoObject` == 1) { //Select the object select -r $LFdrawpolyToolProcessingEachGeoObject; //Remove (delete) the attribute deleteAttr ($LFdrawpolyToolProcessingEachGeoObject + ".LFdrawpolyToolLiveObject"); } } //Give the user "Tool" feedback print "LFdrawpolyTool successfull! Press G to continue."; }