picking wireframes

Started by
7 comments, last by slowburn 16 years, 11 months ago
Hi, I'm trying to determine the best way to do picking on a wireframe object. I would like it so that clicking on the empty area between the wireframe lines does not select the object. 3DSMax and Maya both seem to implement such functionality. Does anyone know the standard approach to this? Thanks
Advertisement
Quote:Original post by slowburn
Does anyone know the standard approach to this?
I don't know if there's a standard solution (or what it might be), but for the problem of selecting vertices or edges of a mesh, I'd use a picking volume.

Using a picking volume will give you a little 'play' in picking the features in question, and will result in uniform picking behavior regardless of the 'depth' of the feature (that is, in the case of perspective projection, features that are further away won't be more difficult to pick).

For vertices, you would simply test the corresponding point for containment in the volume. For edges, you would perform a boolean intersection test between the corresponding line segment and the volume (using e.g. the SAT, or a clipping-based test). Also, this method should work equally well for both perspective and orthographic projections.

Again, this is just speculative - it may be that the modeling applications you mentioned use an entirely different method.
Standard raycasting picking algorithms won't work well for wire frames. Your best bet is some sort of technique that renders an ID corresponding to the object you are rendering to an offscreen buffer. If you are using OpenGL, I'd recommend using selection mode. Check out this page for more information on how to use selection mode. If you are using some other API, you can simply render to a texture using a different color for each object. Then you read the texel at the corresponding mouse location and see what object has the color of the texel. I suppose this technique would break down if you had a tremendous amount of objects to select from. If you have <256 objects you shouldn't even have to worry about how to pack their ID's into multiple color channels.
Quote:Standard raycasting picking algorithms won't work well for wire frames.
Just to be clear, I wasn't recommending using a pick ray, but rather a pick volume.
Quote:Your best bet is some sort of technique that renders an ID corresponding to the object you are rendering to an offscreen buffer. If you are using OpenGL, I'd recommend using selection mode.
But wouldn't this require clicking directly on a pixel associated with a particular edge? This sounds quite difficult to me.

Again, I claim no knowledge of how feature picking is typically implemented in modeling applications, but I would lean towards a geometrical method of some sort (as I suggested), rather than a pixel-based method. For example, I just played around with blender a bit, and you do not have to click directly on an edge or vertex to select it, so I highly doubt that a pixel-based method is being used.

As for geometrical methods, I suppose another option would be to do the picking in screen space (i.e. against circles and capsules built from the projected vertices and edges, respectively).
Thanks for the replies.

jyk, you can do 'fuzzy' picking with the color-buffer by checking the color of the picked pixel and all the ones around it. This method can also be used to do box-selections.

The color-buffer method nearly solves what I want. But, it doesn't work if an object is occluded by another. I would like it to somehow lists all the objects covering the pixel, rather than just one object.

GL's selection mode does work for occluded objects and in fact lists all objects covering that pixel. However it has another problem. When you render an object in wireframe mode, the spaces between the wireframe also counts as part of the object. This behavior is unlike the color-buffer mode.

Any ideas? Thanks.
You can transform the edges into screen space and determine the distance to each of them using a 2D closest-point-on-a-line algorithm. If the lowest distance found falls outside some minimum treshold, nothing was clicked. Note that your engine should somehow be aware of the 'edge' concept, otherwise you have to iterate through each polygon and possibly visit the same edge multiple times.

This is just theory as I haven't implemented this myself yet, but I'm pretty sure it works and suspect it's the way Max is doing it as well. Hope it helps.
Quote:Original post by Prototype
You can transform the edges into screen space and determine the distance to each of them using a 2D closest-point-on-a-line algorithm. If the lowest distance found falls outside some minimum treshold, nothing was clicked.
Yeah, I actually suggested this earlier in the thread.

IMO, this approach would probably be more flexible (and perhaps easier to implement as well, depending on the circumstances) than using OpenGL's selection mode.
Quote:Original post by slowburn
GL's selection mode does work for occluded objects and in fact lists all objects covering that pixel. However it has another problem. When you render an object in wireframe mode, the spaces between the wireframe also counts as part of the object. This behavior is unlike the color-buffer mode.


Not entirely sure what you mean by this, but, are you rendering normal polygons just with the render mode set to wireframe?
What if instead you 'manually' replaced all polygons with sets of gl lines?.
Quote:Original post by haphazardlynamed
Not entirely sure what you mean by this, but, are you rendering normal polygons just with the render mode set to wireframe?
What if instead you 'manually' replaced all polygons with sets of gl lines?.


I'm just using the rendermode set to wireframe. Your suggestion to replace all polygons manually with gl lines would work. I'm considering that as an option... However, it would be tricky for nurbs surfaces... If I were to manually draw the wireframe lines for that, I would have to do the tessellation as well.

This topic is closed to new replies.

Advertisement