how to ignore the objects that masked by others when i do selection with gl?

Started by
5 comments, last by DrakeSlayer 17 years, 8 months ago
hello guys, i'm working on my simple 3d modeller, and i want to use the opengl selection functions to implement the selection. but how to ignore those objects that masked by others when i use the opengl selection ? i found this feature is very common in commercial software like 3d max, there is a option called "ignore backfacing", and if checked, you won't select objects that masked by others. the zbuffer seems to be diabled in selection mode, so how can i do this? thank you.
Advertisement
selection works with depth test. how do you setup your selection?
The depth buffer is effectively disabled in the built in selection mechanism, becuase when in selection mode, no fragments are produced, and hence no depth buffer tests can be performed. The selection mode is purely a geometrical selection; anything intersecting the view volume after transformation is a hit. If you need a pixel-based visibility test, then the built in selection won't get you anywhere.

Now depending on how the selection is performed and what kind of result you want, it may be enough to just pick the closest object in the hit record. If this is not what you want, you may have to change selection mechanism, and use, for example, a color based selection. Draw each object in a unique color, read back a part of the scene and determine which colors are present.
Quote:Original post by Brother Bob
The depth buffer is effectively disabled in the built in selection mechanism, becuase when in selection mode, no fragments are produced, and hence no depth buffer tests can be performed. The selection mode is purely a geometrical selection; anything intersecting the view volume after transformation is a hit. If you need a pixel-based visibility test, then the built in selection won't get you anywhere.

Now depending on how the selection is performed and what kind of result you want, it may be enough to just pick the closest object in the hit record. If this is not what you want, you may have to change selection mechanism, and use, for example, a color based selection. Draw each object in a unique color, read back a part of the scene and determine which colors are present.


hi, thank you for replying , i cannot pick up the closest object, because i will allow people to pick up severial objects at once as, long as they are visible. and about the color selection, is this the common solution of commercial 3d modeller? thank you.
I actually have no idea whan kind of selection they use. But color selection is a solution, but not necessarily the solution.
Quote:i found this feature is very common in commercial software like 3d max, there is a option called "ignore backfacing", and if checked, you won't select objects that masked by others.

Actually 3dsmax doesn't do that at all. You just can't select stuff of which the normal is facing away (essentially backface culling). Actually 3dsmax SHOULD have had this feature a long long time ago, most of my modeling time is spend on de-selecting stuff I didn't want to select, and checking and unchecking "ignore backfacing" thing. 3dsmax...yuk!

On topic: I did implement something like this in a character rigging tool. I was using color selection, by rendering vertices/polygons each in an unique color, then reading back a few pixels under the cursor, converting the color back into an index. If you do this, you get selection blocking thing for free. Color selection has one major problem; if you run the app when in 16-bit display mode you have to do really tricky stuff to ensure you can still convert the color back to a valid index. This is one of the reasons I dropped color selection, it didn't prove relyable on all hardware.

Another method is this:
* render solid geometry
* render vertices as points
* project (glProject()) all your vertices to screen each frame, this will also give you the distance to nearplane

When selecting stuff, loop through the projected points, do a simple bounds check to see if the cursor is over a vertex. If it is, read back the z-buffer value at that pixel coordinate. Then you have to do some voodoo to convert that value back to linear distance value (the z-buffer is not linear). Then compare that z-depth to the projected screen pos z, to determine it was behind, or in front of geometry.

So there really isn't a simple solution. Another alternative is to do ray-tri tests, everything in in software, but that ain't easy either.
Commercial packages don't use the openGL selection functions. A better solution is to construct a ray that goes from the camera and correspond to the position of the cursor. Then you use ray vs bounding volume intersection tests to roughly find wich objects can collide the ray, and ray vs triangle to determine wich triangles are under the cursor.

Then you select the object with the closest intersection point, ignoring backfacing triangles (you use the normals to test it). I think this is what 3dsMax does. This way, you are not limited by the openGL selection functions.

This topic is closed to new replies.

Advertisement