Hi Cammm,
I would guess it has something to do with the memory. 800X800X6 setAttr calls probably gets expensive. Do you have bonus tools? If so there is a plugin in there called closestPointOnMesh.mll that you could use recursively to converge upon the solution. I wrote the following script which works on two 20k vert objects without problem. But not precisely sure what you are using this in conjunction with, so perhaps you could alter the following to your liking:
//note you can use an $end argument of 1000 or so to be super accurate, but i found 10 is usually more than enough
//select 2 poly objects
//mode 0 = points on surfaces
//mode 1 = faces on surfaces
//mode 2 = vertices on surfaces
global proc string closestPt(float $centerPt1[], float $centerPt2[],int $iter, int $end, float $dif1, float $dif2, string $poly1, string $poly2, int $mode)
{
if(!pluginInfo -q -loaded "closestPointOnMesh"
)
{
error "Please load closestPointOnMesh.mll from the Bonus Tools";
}
float $point1[3], $point2[3];
vector $vPt1, $vPt2, $vcPt1, $vcPt2;
//Test from user specified points for first pass (probably the center of objects)
if($iter==0)
{
$point1=`closestPointOnMesh -ip $centerPt2[0] $centerPt2[1] $centerPt2[2] -q -p -na $poly1`;
$point2=`closestPointOnMesh -ip $centerPt1[0] $centerPt1[1] $centerPt1[2] -q -p -na $poly2`;
$dif1=$dif2=1;
}
//Test for closest point to the last closest point until current and last points are the same
if(`abs ($dif1-0)`>1.0e-3||`abs ($dif2-0)`>1.0e-3)
{
$point1=`closestPointOnMesh -ip $point2[0] $point2[1] $point2[2] -q -p -na $poly1`;
$point2=`closestPointOnMesh -ip $point1[0] $point1[1] $point1[2] -q -p -na $poly2`;
//convert to vectors for comparison
$vPt1=$point1; $vPt2=$point2;
$vcPt1=$centerPt1; $vcPt2=$centerPt2;
$dif1=`mag($vPt1-$vcPt1)`;
$dif2=`mag($vPt2-$vcPt2)`;
//recursive call to converge upon the closest answer
if($iter<$end)
{closestPt($point1, $point2, ++$iter, $end, $dif1, $dif2, $poly1, $poly2, $mode);}
if($iter==$end)
{warning "Recursive iteration limit exceeded, increase $end argument for more accurate results!";}
}
string $retPt;
//for closest points to each surface
if($mode==0)
{
$retPt=($point1[0]+" "+ $point1[1]+" "+ $point1[2]+" "+ $point2[0]+" "+ $point2[1]+" "+ $point2[2]+"n");
}
//for closest faces on each surface
if($mode>0)
{
int $id1=`closestPointOnMesh -ip $point2[0] $point2[1] $point2[2] -q -f -na $poly1`;
int $id2=`closestPointOnMesh -ip $point1[0] $point1[1] $point1[2] -q -f -na $poly2`;
select -r ($poly1+".f["+$id1+"]");
select -add ($poly2+".f["+$id2+"]");
//for closest vertices on each surface
if($mode==2)
{
float $leastDist, $tempDist;
select -r ($poly1+".f["+$id1+"]");
ConvertSelectionToVertices;
string $vertList1[]=`ls -fl -sl`;
select -r ($poly2+".f["+$id2+"]");
ConvertSelectionToVertices;
string $vertList2[]=`ls -fl -sl`;
float $pos1[3], $pos2[3];
vector $list1[], $list2[];
//store first face vertex positions once
for($x=0; $x<`size $vertList1`; $x++)
{
$list1[$x]=`pointPosition $vertList1[$x]`;
}
for($j=0; $j<`size $vertList2`; $j++)
{
$list2[$j]=`pointPosition $vertList2[$j]`;
for($x=0; $x<`size $vertList1`; $x++)
{
$tempDist=`mag ($list1[$x]-$list2[$j])`;
if($j==0||`abs $tempDist`<$leastDist)
{
$leastDist=$tempDist;
select -r $vertList1[$x];
select -add $vertList2[$j];
}
}
}
}
string $sel[]=`ls -fl -sl`;
$retPt=`stringArrayToString $sel " "` ;
}
return $retPt;
}
//run command
string $objects[2]=filterExpand -sm 12
;
if(size $objects
<2)
{
error "Command requires 2 selected polygon meshes";
}
float $center1[3]=getAttr ($objects[0]+".center")
;
float $center2[3]=getAttr ($objects[1]+".center")
;
//change mode to find closest points, faces, or vertices
closestPt($center1, $center2, 0, 10, 1, 1, $objects[0], $objects[1], 2);