On January 27th, this site will be read-only as we migrate to Oracle Forums for an improved community experience. You will not be able to initiate activity until January 30th, when you will be able to use this site as normal.

    Forum Stats

  • 3,889,532 Users
  • 2,269,755 Discussions


get the Shape3D in a Scene

843799 Member Posts: 49,999
edited Jul 17, 2001 3:09PM in Java 3D
I use the ObjectFile loader and i need to manipulate the objects separatly. How can i do that ?


  • 843799
    843799 Member Posts: 49,999
    Hi Ed,

    What you want to do is traverse your scene graph.

    For each Node of the scene graph you need to know whether it is a Group node or a Leaf node. If it is a Leaf node then you could do a further test, such as:
    if (node instanceof Leaf) {
    if (node instanceof Shape3D) ...
    else if (node instanceof Group) {

    However, if the node is a Group then you can use the methods:
    int numChildren() and
    Node getChild(int index) to traverse the graph.

    You will need to use recursion. Here is a simple outline of how to do it.

    public void findShapes(java.util.Vector v, BranchGroup node) {

    if (node instanceof Group) {
    int numChildren = ((Group) node).numChildren();
    for (int i = 0; i < numChildren; i++)
    findShapes(v, ((Group) node).getChild(i));
    else if (node instanceof Leaf) {
    // test if it is Shape3D
    // if so add it to the vector


    ** - this code has not been tested

    Hope this helps.
This discussion has been closed.