PDA

View Full Version : Query PolyFaceCenters


RaGzMaN
04-04-2006, 06:28 PM
Hi there, is there any way to query the position of the poly face center?

Im looking to create a particle at the center of extracted (and now seperated) faces from geometry. Ive tried the particlify script but it seems to place the particles miles away from my geometry....not sure whats gone on there but its just not working for me. On new geo, its fine, just on my current...it aint happening.

rokandic
04-05-2006, 12:00 PM
You could use xform for instance:
xform -q -ws -t pPoly.f[1];

It will return the array of positions of all face vertices ({vertex1.x,vertex1.y,vertex1.z,vertex2.x,vertex2.y,vertex2.z,...}). If you sum their positions and divide by their number you should have the center.

Hope this helps,
Rok

RaGzMaN
04-05-2006, 02:06 PM
Looking further at this code, i cant really seem to grasp why its not working.

When i create any standard geometry, it will work.

However, if i have create some geometry then split it up manually (instead of the shatter effect) it just does not seem to want to work.

Source this and try it out:


global proc particlify()
{
string $selObjs[], $item, $pCommand = "particle";
float $pos[3];
int $numObjs, $i = 0;
$selObjs = `ls -long -flatten -sl`;
$numObjs = `size $selObjs`;
if ( !$numObjs )
{
print ("Particlify(): Too few objects selected. You need to select at least one object to particlify it.\n");
return;
}
for ( $i = 0; $i < $numObjs; $i++ )
{
//$pos = eval ("getAttr " + $selObjs[$i] + ".center");
$pos = eval ("xform -q -a -ws -t " + $selObjs[$i]);
$pCommand += ( " -p " + $pos[0] + " " + $pos[1] + " " + $pos[2] );
}
eval $pCommand;
}


For example, make a plane, cut it up into 4 pieces so the pieces are separate.
Move them off the ground plane.
Select them all and in the command line paste:

particlify()



Any ideas?

rokandic
04-07-2006, 02:38 PM
But it works correct if you select components like vertices, faces? This problem only occurs if you select transforms, right?

I presume the problem is that geometry has freeze transformations applied thus the transform information is different. In that case I suggest to use rotate pivot as your object center, changing the line from:
$pos = eval ("xform -q -a -ws -t " + $selObjs[$i]);
to
$pos = eval ("xform -q -a -ws -rp " + $selObjs[$i]);

Hope this helps,
Rok

CGTalk Moderation
04-07-2006, 02:38 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.