//_______________________________________________________________________________________ // // TITLE : polyWeightImport.mel // // AUTHOR : Robert Bateman // // E-MAIL : robthebloke@hotmail.com // // DATE : 30/01/01 // // NOTES : imports polygonal mesh weights from a text file. // // USAGE : run the script. // // INFO : Meshes must exist to recieve weighting (as must skin clusters) // //_______________________________________________________________________________________ // // Copyright © 2001 Robert Bateman // All Rights Reserved // // For educational purposes only. // Please do not republish in electronic or print form without permission // Thanks - robthebloke@hotmail.com // //________________________________________________________________________________________________ //___________________________________________________________________ inputMeshWeights() ///////////////////////////////////////////////////////////////////// // // Takes the name of a mesh and inputs the weighting information // from the given file handle. // global proc inputMeshWeights( string $object , int $fH ) { string $in; $in = `fgetword $fH`; // // get number of verticies // int $vertexCount = `fgetword $fH`; // // should tell us if the surface has weighting info // ( impossible not to have...) // $in = `fgetword $fH`; $in = `fgetword $fH`; // // getlist of connections to the surface // string $conns[] = `listConnections $object`; int $len = size( $conns ); // // if connections exist. // if( $len > 0 ) { int $test =0; string $skin; // // find the skin cluster for that object // for ( $i = 0 ; $i < $len ; $i++ ) { string $type = `nodeType $conns[$i]`; int $res = `strcmp "skinCluster" $type`; if( $res == 0 ) { $test = 1; $skin = $conns[ $i ]; } } // // if skin cluster exists // if( $test == 1 ) { for($i=0;$i<$vertexCount;$i++) { int $vNum, $vCount; string $jointName; float $vWeight; $in = `fgetword $fH`; // "VERTEX_WEIGHT:" $vCount = `fgetword $fH`; // number of vertex weights for this surface. // // next comes pairs of - joint name / weight value // set the first one to one, this removes weightings // from any other joints // $jointName = `fgetword $fH`; $vWeight = `fgetword $fH`; $w = $object + ".vtx[" + $i +"]"; skinPercent -tv $jointName 1 $skin $w; for( $j=1; $j<$vCount; $j++ ) { $jointName = `fgetword $fH`; $vWeight = `fgetword $fH`; skinPercent -tv $jointName $vWeight $skin $w; } } } else { print "File Corrupt\n"; } } else { print "File Corrupt\n"; } }; //___________________________________________________________________ polyWeightImport() ///////////////////////////////////////////////////////////////////// // // Imports weighting info from the given file. Takes dummy arg also. // proc int polyWeightImport( string $filename , string $type ) { $fileId = `fopen $filename "r"`; string $in; string $meshName; int $meshCnt; $in = `fgetline $fileId`; $in = `fgetword $fileId`; $meshCnt = `fgetword $fileId`; for( $i=0; $i<$meshCnt; $i++ ) { $in = `fgetword $fileId`; $meshName = `fgetword $fileId`; inputMeshWeights( $meshName , $fileId ); } fclose $fileId; return 1; } // // Using file browser to get file input // fileBrowser ( "polyWeightImport" , "Import" , "Best Guess" , 0 );