I'm wondering if it's possible to select an object/a vertex just by knowing it's position?

Lets say pSphere1.vtx[213] is positioned at wordspace position 21.31 4.22 4.66, is it then possible to select that vertex without knowing the name of the object?

The reason why I'm asking, is that I want to create a 'Mirror Cluster' script. So if the object is symetrical and positioned in the center of the scene, I should be able to get the position (vertexes) on the other side.

aguirre

10 October 2010, 08:05 PM

hey, this should actually work

give a list of vertices that could be on that position
and a pos (eg.: [0, 1, 0])

Agh. This always happens to me :cry: I'm such a slow coder (i.e. not a coder at all, hence I have to look up every function as I go along) that it takes me ages to write a simple script. In that time someone else comes along and answers the question, rendering my solution obsolete...

You select one vertex (and one only...)
The script analyses that vertex's position, adding an optional tolerance margin and the option to specify the mirror axis of your object, then uses the polySelectConstraint command to select any vertex that lies on either side of a mirror plane (defined by the mirror axis) that has the same distance (to the mirror plane) as the originally selected vertex.
After that it stores the new (mirrored) vertex in a variable ($mVtx) for further usage and prints its ID.

The tolerance margin was added because I somehow don't trust Maya's internal rounding algorithms in conjunction with polySelectConstrain. As an example, if the original vertex is at X = 65.23242253 and the tolerance margin is $tol = 0.001, then the script will search for the new vertex between 65.231 and 65.233. For ultra-dense meshes simply set a very low tolerance or delete that part of the script entirely.

I sincerely hope this was at all useful :)

shcmack

10 October 2010, 12:51 PM

Nyro: Hey thanks for your answere :) I can't really get the mirroring to work correctly though, not even with a simple pCube. When I select a vertex on the positive Y/X axis, it thinks the mirror-vertex is the negative Y/X axis. If I try it with a pSphere, it seems to just select a random vertex as long as it's negative X.

First of all: I'm not quite sure what an "X/Y axis" is. Maybe you're referring to a plane?
Anyhow, you're right. My script fails in a very specific case: if the object is point-symmetrical, as opposed to axis/plane symmetry. Both the perfect cube (i.e. sides of same length) and the sphere fall into this specific case. My script simply selects any vertex that fulfils the condition "Vertex V lies on any side of the mirror plane A (which is centered to the world pivot 0,0,0) and has the distance d from the mirror plane."

Obviously, any of the vertices of a cube fulfil that condition, disregarding what the mirror plane is set to.
The Sphere, being the perfect symmetrical object, has the same problem. A polygonal sphere will have multiple vertices that lie at the same distance d opposite the mirror plane (depending on sphere resolution and tolerance value, this could be quite many).
Comment out the last line of my script ("// polySelectConstraint -d 0;") and run the script on any vertex of a sphere. It will probably show a selection of multiple vertices. These are the candidates the script finds (the script only outputs the first vertex in that list). If you now view the model from the top orthogonal view, you'll notice that all vertices lie roughly the same distance from the mirror plane, i.e. you could draw a line through them on either side and they'd all lie on the line.

Try my script with an arbitrary, slightly more organic mesh that is symmetrical only across a specific mirror plane and centered to [0,0,0]. Then my script should work flawlessly.

The reason I chose not to iterate through every vertex in the mesh is just the problem you're encountering: it's slow, especially on very complex meshes. My script executes immediatley, because it's basically just a selection conversion coupled with six simple math functions.

By the way, I just noticed that I only implemented the tolerance function in the "Case: X" case, not for "Y" and "Z".

CGTalk Moderation

10 October 2010, 03:08 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.

Follow Us On:

The CGSociety

The CGSociety is the most respected and accessible global organization for creative digital artists. The CGS supports artists at every level by offering a range of services to connect, inform, educate and promote digital artists worldwide. More about us on TheArtSociety.com