how to select a vertex by its worldspace loc


Anyone know a way to select a vertex in an editable poly by its worldspace location?


The obvious answer is - you would have to loop through all vertices and compare their positions with the worldspace location you have. Because of possible precision limitations (roundoff errors) you would have to look for the closest vertex to that position, not just compare the two - they could be within 0.000001 units and still seen as different.
You could bail out of the loop if you find a vertex that has the exactly same position to save time.

Another possible way would be to create a ray that passes through the world space point and attempt to intersect with the object, but since the intersection methods (IntersectRayEx and RayMeshGridIntersect) require an Editable Mesh and not EPoly, you would have to resolve triface data into epoly faces to figure out the nearest vertex.

If you are looking for a vertex close (or equal) to a position very often and not just once, it might be worth it to encode all vertices into your own voxel structure and search only the voxel the world space point lies in to speed things up. Since the encoding of the data requires a single loop through all vertices, the encoding pass will be as expensive as the first method I suggested. But if you have to perform thousands or millions tests, the voxel approach will be orders of magnitude faster.


Right now I am looping through all verts looking for the closest, kind of like a mirror weights script. I just hoped there would be a better way. Thanks for your reply, is it me or do many more people use this forum instead of the AREA? I asked about copyPasteKeys, and some other things there and never got a reply. Can you show me a one line example of copyPasteKeys()? (I am only asking because you have a hand in the docs, right?)

Thanks for the reply,


Actually, I think using RayMeshGridIntersect you might get faster results looking for the closest vertex. I will see if I can write an example and benchmark it against a simple loop. How many vertices are you dealing with?

copyPasteKeys cannot be shown in one line - it needs at least two! :slight_smile:
First you need either a map function or a map struct to perform the retiming operation on each key. Then you call the function onto the controller you want to operate one. Don’t forget to select some keys on that track!

To test, I created a box and animated with Autokey on to create some keys, esp. on the Z axis position sub-controller. Then I selected some keys on that controller (and left one unselected in the middle of the selection).

My mapping function tells each key to shift its time by 10 frames. If you wanted to scale the time for example to half of its current time, you could pass 2 as the argument and use (theTime/theArg) in the function. The function is called automatically for each key and the first argument is automatically passed as the current key time, the second argument is the argument after the map function in the copyPasteKeys call (in my case, 10), and the result of the function is assigned as the new time of the key that has been copied and pasted. Since I said #insertKeys, the unselected key in the middle of my selection was moved PAST the new keys thus not screwing my function curve by remaining in the middle of the copied keys.

fn mapTheKeys theTime theArg = (theTime + theArg)
 copyPasteKeys $Box01.pos.controller[3].controller mapTheKeys 10 #insertKeys



Ok, so really the only way to use it normally is to create a null mapping? Like move the keys ‘0’? Sometimes I want to dump key info somewhere in memory, but I haven’t figured out how to. I make a dummy helper obj and copy the keys to it. Is this the right way?

Thanks for the tips! You rock :slight_smile:


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.