Use selection capabilities
Source file: SelectionExample
Source file: SelectionRenderer
JavaDoc: SelectionManagerInterface
JavaDoc: SelectionListener
JavaDoc: Selection
JavaDoc: DefaultMatrixSupport
jReality supports the selection pattern using the Selection
class. And in most cases an instance of Selection
is just an instance of SceneGraphPath
. This example deals with the latter case.
Notice that selection in jReality requires a scene graph path, that is, a path from the root to a specific node. Specifying an instance of SceneGraphComponent
is not enough, since the same instance can appear many times in the same scene graph. An instance of SceneGraphPath
on the other hand, specifies a unique instance of SceneGraphComponent, the last instance in the path.
To run: execute the main method.
- In the graphics window you should see a grid of 8 icosahedra, surrounded by a wireframe bounding box.
- Use the right mouse button to select one of the icosahedra.
- You should see a smaller wireframe bounding box surrounding just the one selected.
- Without moving the mouse, continue to click with the right mouse.
- Each click moves the truncates the selected scene graph path by one node.
- If the last scene graph component in the path has an appearance, then the diffuse polygon color is set to white.
- A rotate and a drag tool are also added to this component, which can be activated by the left and middle mouse buttons, respectively.
- Continuing to click will eventually bring the selection back to the full scene graph path.
- The set of white icosahedra at any point in the process are all the leaf nodes (those containing geometry) under the currently selected
SceneGraphPath
- Shift-click with the right mouse returns all transformations to their original states.
- See the class
DefaultMatrixSupport
for details on this feature.
- See the class
How it works: The following code sets up the selection manager and an instance of SelectionRenderer
to draw the bounding box:
sm = SelectionManager.selectionManagerForViewer(viewerApp.getViewer()); SceneGraphPath toWorld = SceneGraphUtility. getPathsBetween(viewerApp.getViewer().getSceneRoot(), world).get(0); sm.setDefaultSelection(new Selection(toWorld)); sr = new SelectionRenderer(viewerApp.getViewer() ); sr.setSelectionPath(sm.getSelectionPath()); sr.setVisible(true);
Note: Currently the SelectionManager should be able to render the selection himself; but this functionality will probably be removed in the future (since it doesn't work and the SelectionRenderer is a cleaner solution anyway).
The following images shows the example at startup, and then after the right mouse has been clicked several times. The current selected path contains two nodes with geometry.
|