select vertices from x,y,z coords?

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

Thread Tools Search this Thread Display Modes
Old 05 May 2003   #1
select vertices from x,y,z coords?

sorry 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?

Old 05 May 2003   #2
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....
Hugh Macdonald

Last edited by Hugh : 05 May 2003 at 01:20 AM.
Old 05 May 2003   #3

hheeh i just relpied to your thread.

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 ...

Old 05 May 2003   #4

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 Macdonald
Old 05 May 2003   #5
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.
Hugh Macdonald
Old 05 May 2003   #6
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.

Old 05 May 2003   #7
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.

Old 05 May 2003   #8
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?


Last edited by ktpr : 05 May 2003 at 02:26 PM.
Old 01 January 2006   #9
Thread automatically closed

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.
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
Thread Closed share thread

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Society of Digital Artists

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump

All times are GMT. The time now is 07:46 PM.

Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.