//This script was written by Ben Bathen //www.benbathen.com //This Script creates blendShapes on polygonal objects //wich include only the vertices that have been moved //from their position on the original object. //This makes blendshapes run much quicker by removing excess vertices from the deformer set. global proc vertexBlendShape () { //put the selected objects into a string string $sel[] = `ls -sl`; //check how many objects are selected int $numObjects = `size $sel`; //put the original object into a string string $original = $sel[$numObjects -1]; int $originalNum = $numObjects -1; //check to make sure only polygonal objects are selected int $b; for ($b = 0;$b < $numObjects; $b++ ) { string $shape[] = `listRelatives -s $sel[$b]`; string $type = `nodeType $shape[0]`; if ($type != "mesh") { error "Sorry. This script only works on Polygons"; } } //check to make sure all the objects have the same number of faces int $originalFaceCount[] = `polyEvaluate -f $original`; for ($b = 0;$b < $numObjects; $b++ ) { int $blendFaceCount[] = `polyEvaluate -f $sel[$b]`; if ($blendFaceCount[0] != $originalFaceCount[0]) { error "Sorry. The objects must have the same face count"; } } //count the number of vertices in each object int $vertCount[] = `polyEvaluate -v $sel[0]`; //create a set to store the names of vertices that are different. string $listA[]; string $listB[]; int $a; int $i; for($a = 0; $a < $originalNum; $a++) { //create some empty sets to store the vertex information in. $listA[$a] = `sets -em -n ("differentVertices" + $i)`; $listB[$a] = `sets -em -n ("differentVertices" + $i)`; //loop through every vertex in each object and compare it to the original for($i = 0; $i < $vertCount[0]; $i++) { //put the first vertex on the original object into a variable. string $pointA = $original + ".vtx[" + $i + "]"; //find the position of that vertex in local space float $pointAPos[] = `pointPosition -l $pointA`; //convert that to a vector. vector $pointAVector = <<$pointAPos[0], $pointAPos[1], $pointAPos[2]>>; //put the corresponding vertex from the second object into a variable string $pointB = $sel[$a] + ".vtx[" + $i + "]"; //find the position of that vertex in local space float $pointBPos[] = `pointPosition -l $pointB`; //convert that to a vector. vector $pointBVector = <<$pointBPos[0], $pointBPos[1], $pointBPos[2]>>; //if the points are not in the same local space position add them to the set containing different vertices. if (!(equivalentTol ($pointBVector, $pointAVector, .001))) { select -r $pointA; sets -e -forceElement $listA[$a]; select -r $pointB; sets -e -forceElement $listB[$a]; } } } select -r $listB; select -add $listA; string $blend[] = `blendShape`; delete $listA; delete $listB; print ($blend[0] + " contains only the vertices which have been moved from their position on the original object."); }