Return to The Java 3D FAQ

Extended Picking Utilities

This page has links to picking utilities which can be used to pick lines and points using Java3D 1.1. Java3D 1.2 will have better support for picking, including new picking utilities with a different interface than is included here. The new utilities will be part of the Java3D 1.2 packages by the time J3D 1.2 beta is released (they will not be in the 1.2 alpha version).

See below for some new notes on limitations of this implementation along with some general notes about the package.

To download this jar file, please press the "shift" key on your keyboard when you click on the link. If you have trouble with the jar file, try the zip file. The jar file and the zip file have the same contents: the source to the pickingExt package, documentation for the package, an updated version of the PickTest demo and program which shows how to do pick highlighting and how to workaround a problem with the current picking implementation.

Be sure to add the directory "pickingExt" to your CLASSPATH, or you'll get errors when you compile the test programs.

A limitiation: The pickingExt packages make it possible to pick lines and points in J3D 1.1, but there is still a problem: individual points, horizontal and vertical lines can be difficult or impossible to pick. This is because the intersection between a PickRay and a "thin" bounding box is unlikely (just as ray/line intersections are unlikely). A workaround to this problem is shown in the PickHighlight example. The BoundingBox for the Shape3D is calculated and made slightly larger to make it more likely that the shape can be picked. This is not a perfect fix, but it is the best we can do until Java3D 1.2 is here.

Here are some general notes from when the packages were first published.:


Picking lines and points requires a PickShape which can intersect with the 
primtives.  J3D 1.1 supports picking using a Bounds object for the pick shape 
and a BoundingPolytope can be used to make a volume represents the area around 
the mouse position.  The problems is that the picking utilities in J3D 1.1 only 
understand how to generate PickRay's, not PickBounds.

The pickingExt package extends the com.sun.j3d.utils.behaviors.picking package 
to support line/point picking using a pick "aperture".  The aperture is a closed 
loop of points around 0,0 in window coordinates (see PickObject.java).  When 
using an aperture, the utility will generate a bounding polytope which extends 
from the eye through the edges of the pick aperature.  

The default aperture is a 4 pixel square around the mouse point. The result is 
similar to using a pick cylinder as other emails have suggested.

A couple notes:

1) We are distributing the updated version of the picking utilities as source 
since we can't update the "official" utilities until J3D 1.2.  If you like, you 
can change the package for the utilities to 
com.sun.j3d.utils.behaviors.pickingExt, but you are responsible for building and 
maintaining the extended utilities.  I'll be posting updated versions of these 
utilities to the interest alias if bug fixes or extensions are needed.

2) Both the SHAPE_RAY and SHAPE_APERTURE modes work correctly under parallel and 
perspective views.

3) J3D 1.1.1 has a couple bugs which show up when using these utilties.  First, 
only the endpoints of lines can be picked for SHAPE_APERTURE picking.  Second, 
the "bounds" picking test will fail for SHAPE_APERTURE picking, so use 
SHAPE_RAY_APERTURE for best results.  Both these bugs have fixed in the 
1.1.2 release.

4) For doing pick aperture picking, the best performance comes from using 
SHAPE_RAY_APERTURE mode.  This uses a pick ray for the "bounds" phase of picking 
and then a pick aperture for the "geometry" phase of picking.

Hope this helps.  Let me know if you have problems,
Doug Gehringer
Sun Microsystems

Return to The Java 3D FAQ