View Full Version : select vertices from x,y,z coords?

 ktpr05 May 2003, 12:54 AMsorry to be posting so much but I'm beginning to realize that your only as good as you knowledge of the mel library and I just started. Does anyone know of a way to select a vertex by supplying coords? cheers ktpr
Hugh
05 May 2003, 01:08 AM
Would this be on the currently selected poly object?

You'd have to select all of the vertices on the object and cycle through them, and return the closest one to the point you give....

ktpr
05 May 2003, 01:17 AM

yeah I would have two objects, but aren't exactly the same: What I want to do is iterate through the set of points of one object and for each point find the closest point on the other object. It would really easy if I could just say select all points w/in this x,y,z box....

Another alternative, I'm thinking is to do a binary search on the points of the other object but i don't really want to do that ... :)

cheers
ktpr

Hugh
05 May 2003, 01:20 AM
Pseudocode:

global proc int getClosestVertex(float \$searchPos[3], string \$searchObject)
{
int \$numVertices = getNumVerts(\$searchObject);
int \$vertex;
float \$dist = 9999.9;
int \$currentClosest = -1;

for(\$vertex = 0; \$vertex < \$numVertices; \$vertex++)
{
float \$vertPos[3];
\$vertPos = `xform -q -ws -t (\$searchObject+".cv["+\$vertex+"]")`;
\$thisDist = getDistance(\$vertPos, \$searchPos);
if(\$thisDist < \$dist)
{
\$currentClosest = \$vertex;
\$dist = \$thisDist;
}
}

return \$currentClosest;
}

global proc float getDistance(float \$point1[], float \$point2[])
{
float \$distance[3];
float \$tot_dist = 0;
int \$i;

for(\$i=0; \$i<3; \$i++)
{
\$distance[\$i] = \$point1[\$i] - \$point2[\$i];
\$tot_dist += \$distance[\$i] * \$distance[\$i];
}

return sqrt(\$tot_dist);
}

you'll have to work out the getNumVerts proc yourself - and I did say this was pseudocode - I make no guarentees that it will work straight off, but it should point you in the right direction...

I've got into a bad habit of using float[3] instead of vector, so you might want to conver that....

Should all work, though...

Hugh
05 May 2003, 01:22 AM
Ah - all points within a box is probably easier....

Instead of checking the distance in the function above, check whether the X is in a certain range, and the same for Y and Z. If they are all in the desired range, then it is in the box...

And rather than just returning a vertex number at the end, as you find them, select them.

ktpr
05 May 2003, 01:42 AM
thanks for the puesdo code. I'll see what I can do with it; I can't have any user interaction and I don't want to search through the entire object.

cheers
ktpr

wrend
05 May 2003, 08:46 AM
yeah, a developed volume select tool set would be tre-grande!
... but there are some rudiments already, the selectionConstraints ..... for poly components only = (
.. but you can build dummy, point matching, polys.

a cple of steps to do a box, but you can do spherical off the bat.

if you cactch more than one point, you can just pull your space down till its just one.

i've just started to use this, can be a fug load quicker than other approaches.

campbell.

ktpr
05 May 2003, 01:52 PM
Hmm I wonder why it doesn't work with anything but polys. Doesn't even mention that limitation in the documentation. damn

Is there a way to get the points affected by a sculpt deformer? If so I could select all the points of one object, create a sculpt at a vertex location of the other, move the sculpt like a centimeter, and read what points were affected and pick the closest one. Perhaps some kind of event callback?

ktpr

CGTalk Moderation
01 January 2006, 06:00 AM
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.

1