I’ve added some models to my project using the ASE loader and would like to be able to select them with the mouse. I have picking enabled all the way down the tree up to the point that the BranchGroup is returned from aseFile.getModel() but I noticed I couldn’t pick the model. I fixed this by getting the BranchGroups subnodes and naming them the same thing. Right now I only want to know if the model was picked, not which component of the model was picked. Is this the proper (or only) way to do this?
protected void buildBranch() {
// Default model position
float x = 50;
float y = 0;
float z = 50;
setPickable(true); // Because we want selection
// Our model
BranchGroup bg = aseFile.getModel();
bg.setPickable(true);
bg.setName("Truck");
// Iterate over the child nodes, naming each and setting pickable
List l = bg.getChildren();
Iterator i = l.iterator();
while(i.hasNext()) {
Node n = (Node) i.next();
n.setPickable(true);
n.setName("Truck");
}
TransformGroup tg1 = new TransformGroup();
tg1.setPickable(true);
Transform3D t1 = new Transform3D();
t1.setTranslation(new Vector3f(x, y, z));
tg1.setTransform(t1);
tg1.addChild(bg);
addChild(tg1);
}
As an addendum to this, what is a good way to manage the objects being picked? I have a primary GUI class that manages the mouse/keyboard interactions and scenegraph. The display and object model behind it are represented as layers that can display arbitrary data. These could be single nodes or whole subtrees of visualized data. Selections are intercepted via mouse clicks and I get an array of Nodes. If I want to modify the node (for example if I wanted to highlight my model), how can I do this in a nice object-oriented (ie NON-DEMO-ized) way?