Skip to main content

Updating the BranchGroup in a PickCanvas

1 reply [Last post]
programkarl
Offline
Joined: 2010-11-11
Points: 0

Hi,
Whenever the user first clicks on the scene, the PickObject returns the Shape3D without a problem. There's some manipulation that is done to the scene. Once the user chooses to pick another Shape3D object in the scene, there is an error when trying to retrieve that object with the PickCanvas object:
Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: Picking can only work if BranchGroup is alive
at javax.media.j3d.BranchGroup.pickAll(BranchGroup.java:162)
at com.sun.j3d.utils.picking.PickTool.pickGeomAllSorted(PickTool.java:712)
at com.sun.j3d.utils.picking.PickTool.pickGeomClosest(PickTool.java:792)
at com.sun.j3d.utils.picking.PickTool.pickClosest(PickTool.java:574)
at org.osskbe.experimental.genesis.graphics.pick.GraphicsPick.mouseClicked(GraphicsPick.java:32)
Here's some example code of what I am doing. All Shape3D objects have been set with the folIowing capabilities:
// Enable picking
shape.setPickable(isPickable);
shape.setCapability(Node.ENABLE_PICK_REPORTING);
PickTool.setCapabilities(shape, PickTool.INTERSECT_FULL);
Here's the wrapper class, GraphicsPick, to wrap PickCanvas:
public class GraphicsPick extends MouseAdapter {
private final PickCanvas pickCanvas;

public GraphicsPick(Canvas3D canvas, BranchGroup root) {
pickCanvas = new PickCanvas(canvas, root);
pickCanvas.setMode(PickCanvas.GEOMETRY);
canvas.addMouseListener(this);
}

@Override
public void mouseClicked(MouseEvent mouseEvent) {
pickCanvas.setShapeLocation(mouseEvent);
PickResult result = pickCanvas.pickClosest();
if (result == null) {
System.out.println("Nothing picked");
} else {
System.out.println("x = " + mouseEvent.getX() + " y = " + mouseEvent.getY());
Primitive prim = (Primitive) result.getNode(PickResult.PRIMITIVE);
Shape3D shape = (Shape3D) result.getNode(PickResult.SHAPE3D);
// manipulate shape3D object
}

}
}

Any help would be greatly appreciated. Thanks.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
programkarl
Offline
Joined: 2010-11-11
Points: 0

I forgot to mention that I manipulate the Shape3D object whenever the user does a pick on the canvas. The first time goes fine, but the second time just returns the error above.
I was thinking that this was due to associcating the Canvas3D object with mutliple GraphicsPick (my wrapper class), but trying to limit this action didn't help since i get the same error. I assume the scenes are alive since I see them on the canvas as I'm attempting to pick a Shape3D object from the scene.
Any help would be greatly appreciated.