// // // 2003. jan. 7 // Creator: Gergely Vass // Site: http://www.vassg.hu // // // Description: // This script generates UV texture values for poly surfaces based on // a "wrapper" NURBS surface. For each vertex the UV of the closest point // of the NURBS surface is taken. // // Usage: // After you placed this .mel file in one of your script directories // (or put it and run in the script editor) you can use the procedure. // You should first select the poly surface you want generate UVs for, and // then shift-select the nurbs surface. After that type "uvfromwrapper" in the // script editor and hit enter. (you can also make a button on your shelf for // this function). // If you keep the script editor open you can see how many time is left. // // Possible errors: // If something goes wrong (which will never) delete manually the wwwvassghucps node // // You can run this script for free at your own risk. Ask me if you want to publish // or reprint it. // global proc uvfromwrapper(){ //********************* variables ************************** string $mynurbs; string $mypoly; string $stuff[]; int $numstuff[]; int $numvertex; int $k; int $n; int $size; float $actpos[]; float $myu; float $myv; //**************************************** $stuff=`ls -sl`; $mynurbs=$stuff[1]; //get the user's selection $mypoly=$stuff[0]; if(nodeType($mynurbs)!="nurbsSurface") { select -r $mynurbs; //checking wheter the second was a NURBS or a transform above a NURBS pickWalk -d down; $stuff=`ls -sl`; if(nodeType($stuff[0])!="nurbsSurface") {error("No NURBS selected for the second object\n");exit;} $mynurbs=$stuff[0]; } if(nodeType($mypoly)!="mesh") { select -r $mypoly; //checking wheter the first was a mesh or a transform above a mesh pickWalk -d down; $stuff=`ls -sl`; if(nodeType($stuff[0])!="mesh") {error("No poly mesh selected for the first object\n");exit;} $mypoly=$stuff[0]; } // create the closestPointOnSurface node we will use with a fancy name referring to my site ;-) createNode "closestPointOnSurface" -n "wwwvassghucps"; //connect the selected NURBS shape into the closestPointOnSurface node eval("connectAttr -f "+$mynurbs+".worldSpace[0] wwwvassghucps.inputSurface"); // we find out how many vertices have to be set $numstuff=eval("polyEvaluate -v "+$mypoly); $numvertex=$numstuff[0]; print("\n The number of vertices: "+$numvertex+"\n"); // loop over all the vertices and set the uv based on the closest point of the NURBS for($k=0;$k<$numvertex;$k++) { print("Doing "+$k+" of "+$numvertex+"\n"); // where we are $actpos=eval("pointPosition -w "+$mypoly+".vtx["+$k+"]"); //actual position of the vertex setAttr "wwwvassghucps.inPositionX" $actpos[0]; setAttr "wwwvassghucps.inPositionY" $actpos[1]; setAttr "wwwvassghucps.inPositionZ" $actpos[2]; $myu = eval("getAttr wwwvassghucps.parameterU"); // getting the uvs of the closest point $myv = eval("getAttr wwwvassghucps.parameterV"); //finding the UV index of the current vertex (there might be more) $stuff = eval("polyListComponentConversion -fv -tuv "+$mypoly+".vtx["+$k+"]"); for($n=0;$n