Skip to main content

Get ALL nodes in the scene graph

5 replies [Last post]
jarodrussell
Offline
Joined: 2010-05-19

Hi,

how can I get a list of all nodes that exist in my virtual universe?
In other words, how can I traverse the Scene Graph on my own?

Basically, I created various subclasses of Shape3D that contain far more information.

For the postRender() method of the Canvas3D, I now want to traverse the entire scene graph, and every time the node is of such a subclass, I want to draw/display the additional information on the canvas.

First of all: how can I even get the entire Scene Graph? I can get a SceneGraphPath from a PickResult, but that only goes from the Locale to a terminal Node?

Any ideas?

Thanks in advance,
Jarod

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
jarodrussell
Offline
Joined: 2010-05-19

Thanks!

ralphld
Offline
Joined: 2010-08-02

How about Locale.getAllBranchGraphs() ?

Ralph

darwinjob
Offline
Joined: 2004-11-16

I guess Jarod needs something like breadth-first enumeration of ALL nodes in the graph. Am I right, Jarod?

jarodrussell
Offline
Joined: 2010-05-19

Exactly.

darwinjob
Offline
Joined: 2004-11-16

You can make use of recursive tree traversing methods on the nodes which extend javax.media.j3d.Group. The only thing you should add is
[code]
if node instanceof Group
[/code]
- you don't want to ask for children if there is none (javax.media.j3d.Leaf).

Alternative (and probably overkill) approach is to extend all j3d classes you use and add javax.swing.tree.DefaultMutableTreeNode field. All operations like addChild/insertChild/removeChild etc must be mirrored on that filed. Then when you need the list of the nodes for the particular node you just call

[code]
node.defaultMutableTreeNode.breadthFirstEnumeration()
[/code]

or

[code]
node.defaultMutableTreeNode.depthFirstEnumeration()
[/code]

or any method available in http://download-llnw.oracle.com/javase/6/docs/api/javax/swing/tree/Defau...