//////////////////////////////////////////////////////////////////////////////// // // change this to the filename of the output file // //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// // // some global variable to hold data between various odd callbacks, kinda a bit // easier than messing about with passing extra variables between callbacks. // //////////////////////////////////////////////////////////////////////////////// // global string to hold the output filename global string $file = ""; // use global string array to hold names of transforms to output global string $transformsToWangInFile[]; // this global array will hold the names of the t global string $transformsInOrderedList[]; // global variable used to determine how many tabs are required global int $indent = 0; // global list of normals and the poly indices for them // // This is required because there is no way in mel to get the list of normals. // therefore we build the list instead and assign our own indices. // global float $g_NormalList[]; global int $g_NormalIndices[]; //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// // Proc : multMatrix // Params : $matrix - the matrix transformation // $pos - the vertex to be transformed // Returns : the transformed position // Notes : transforms the specified vector by the matrix //////////////////////////////////////////////////////////////////////////////// proc float[] multMatrix(float $matrix[],float $pos[]) { float $v[3]; $v[0] = $matrix[0] * $pos[0] + $matrix[4] * $pos[1] + $matrix[ 8] * $pos[2] + $matrix[12]; $v[1] = $matrix[1] * $pos[0] + $matrix[5] * $pos[1] + $matrix[ 9] * $pos[2] + $matrix[13]; $v[2] = $matrix[2] * $pos[0] + $matrix[6] * $pos[1] + $matrix[10] * $pos[2] + $matrix[14]; return $v; } //////////////////////////////////////////////////////////////////////////////// // Proc : multMatrixNormal // Params : $matrix - the matrix transformation // $pos - the normal to be transformed // Returns : the transformed normal // Notes : transforms the specified normal by the matrix //////////////////////////////////////////////////////////////////////////////// proc float[] multMatrixNormal(float $matrix[],float $pos[]) { float $v[3]; $v[0] = $matrix[0] * $pos[0] + $matrix[4] * $pos[1] + $matrix[ 8] * $pos[2]; $v[1] = $matrix[1] * $pos[0] + $matrix[5] * $pos[1] + $matrix[ 9] * $pos[2]; $v[2] = $matrix[2] * $pos[0] + $matrix[6] * $pos[1] + $matrix[10] * $pos[2]; return $v; } //////////////////////////////////////////////////////////////////////////////// // Proc : getConnectedMaterial // Params : $shape - the surface to query for a material assigned // Returns : the name of the material or none // Notes : has a flaw in that it will only return the first material found and // not for each polygon face. Fuck it I say..... //////////////////////////////////////////////////////////////////////////////// proc string getConnectedMaterial( string $shape ) { string $connections[] = `listConnections -type shadingEngine $shape`; if(size($connections) == 0) { return "none"; } string $shadingEngineConns[] = `listConnections -type lambert $connections[0]`; return $shadingEngineConns[0]; } //////////////////////////////////////////////////////////////////////////////// // proc : getNurbsSurfaceKnots // args : $surface - the name of nurbs surface to query // $uKnots - an array of floats to be filled with the u Knot vals // $vKnots - an array of floats to be filled with the v Knot vals // returns : true or false depending on if failed or not // notes : Creates a surface info node that is attached to the nurbs surface // to allow you to read back the values. Bear in mind that Maya // ignores the first and last knot values so you should add an // additional knot at the beginning and one at the end if you are // exporting this data anywhere else. //////////////////////////////////////////////////////////////////////////////// proc int getNurbsSurfaceKnots( string $surface, float $uKnots[], float $vKnots[] ) { // create info Node. // string $infoNode ; if( catch( $infoNode = `createNode surfaceInfo` ) ) { return 0; // failed } // connect surface on to the info node. // string $outAttr = $surface + ".local" ; string $inAttr = $infoNode + ".is" ; connectAttr $outAttr $inAttr ; // read the knots. // $uKnots = `getAttr ($infoNode + ".knotsU")`; $vKnots = `getAttr ($infoNode + ".knotsV")`; // delete surface info node. // delete $infoNode ; // worked // return 1; } //////////////////////////////////////////////////////////////////////////////// // proc : getSurfaceKnotsAsString // args : $surface - the name of nurbs surface to query // returns : data string // notes : takes all the nurbs surface information and creates a data string // with it that it then returns. Inserts the additional knots that // maya ignores. //////////////////////////////////////////////////////////////////////////////// proc string getSurfaceKnotsAsString( string $surface ) { float $uKnots[],$vKnots[]; string $returnValue; if( !(`getNurbsSurfaceKnots $surface $uKnots $vKnots`) ) { return $returnValue; } { // check to see if the knots are periodic or closed // $returnValue += "\t\tKnotsInU: " + (size($uKnots)+2) +"\n\t\t"; // insert the knot that maya ignores that should be there! // if($uKnots[0] == $uKnots[1]) { $returnValue += $uKnots[0]; } else { $returnValue += ($uKnots[0]-1); } // output all of the u knot values to the string // for($i=0;$i0) { // select the parents of this transform // select -add $parents; // recursively select the parents of the parents for a laugh // for($i=0;$i $g_NormalList[$i ] - 0.001 && $x < $g_NormalList[$i ] + 0.001 && $y > $g_NormalList[$i+1] - 0.001 && $y < $g_NormalList[$i+1] + 0.001 && $z > $g_NormalList[$i+2] - 0.001 && $z < $g_NormalList[$i+2] + 0.001 ) { return $actual; } } $g_NormalList[$i ] = $x; $g_NormalList[$i+1] = $y; $g_NormalList[$i+2] = $z; return $actual; } //////////////////////////////////////////////////////////////////////////////// // Proc : NumNormals // Params : // Returns : the number of normals currently present // Notes : //////////////////////////////////////////////////////////////////////////////// proc int NumNormals() { global float $g_NormalList[]; return size( $g_NormalList )/3; } //////////////////////////////////////////////////////////////////////////////// // Proc : WriteNormalList // Params : $fp - the file handle to output to // Returns : // Notes : Writes the polygon normals out to the requested file handle //////////////////////////////////////////////////////////////////////////////// proc WriteNormalList(int $fp) { global float $g_NormalList[]; fprint $fp ("\n\t\tNORMALS "+ `NumNormals` +"\n"); for($i=0;$i0) { // output the number of meshes // fprint $fp ("MESH_COUNT "+$meshCount+"\n{\n"); for( $i=0;$i0 ) { select -r $meshes[$i]; int $triangleCount[] = `polyEvaluate -f`; int $tC = 0; // use some very hacky methods to calculate the number of triangles within // the mesh // for( $k=0;$k<$triangleCount[0];$k++) { // select the current face // select -r ( $meshes[$i]+".f["+$i+"]"); // query polyInfo to return an info string about the vertex indices // of this face. We need to split the string so that we can figure // out how many triangles there are // string $vinds[] = `polyInfo -fv`; string $split[]; tokenize $vinds[0] $split; // calculate how many triangles this face will tessellate to // $tC += size($split) - 4; } // output mesh name and material used // fprint $fp ("\tMESH "+$meshes[$i]+"\n\t{\n"); fprint $fp ("\t\tUSES_MATERIAL "+$materials[ ($meshUsed[$i]-1) ]+"\n"); outputVertices $fp $meshes[$i] 0; outputNormals $fp $meshes[$i] 0; outputTexturingCoords $fp $meshes[$i]; fprint $fp ("\n\t\tTRIANGLES "+$tC+"\n"); outputFaces $fp $meshes[$i]; fprint $fp ("\t}\n"); } } fprint $fp ("}\n\n"); } exportNurbsData $fp; // output the root transforms // if(size($transformsToWangInFile)>0) { fprint $fp ("NUMBER_OF_ROOT_JOINTS "+size($transformsToWangInFile)+"\n{\n"); $indent++; for( $i=0; $i0) { fprint $fp ("NUMBER_OF_SKIN_CLUSTERS "+size($skinClusters)+"\n{\n"); for($i=0;$i