Forum Stats

  • 3,852,338 Users
  • 2,264,093 Discussions
  • 7,905,035 Comments

Discussions

BranchGroup - detach and attach

843799
843799 Member Posts: 49,999
edited Jun 13, 2010 5:59PM in Java 3D
Hi,

in the API I found the sentence:

• A BranchGroup that is contained within another subgraph may be reparented or detached at run time if the appropriate capabilities are set.

What happens when a BG is detached? Is it removed by means deleted and therefore unusable for further processing? If so, it seems that one has to store a reference to the BG after creation to be able to attache it later again... But why naming a method detach(), would be better something like removeBG() or deleteBG() or so...

Thx!

Comments

  • 843799
    843799 Member Posts: 49,999
    edited Jun 13, 2010 5:59PM
    From what I know, a BranchGroup that has been detached is still the same except for one thing: It doesn't have a parent. This could mean that it isn't visible.
    Example:
    SimpleUniverse milkyWay;
    BranchGroup sceneBG, aBG;
    
    public class DetachTester {
         public static void main(String[] args) {
              go();
         }
         public void go() {
              milkyWay = new SimpleUniverse();
              sceneBG = new BranchGroup();
              aBG = new BranchGroup();
              aBG.setCapability(BranchGroup.ALLOW_DETACH);
              sceneBG.addChild(aBG);
              milkyWay.addBranchGraph(sceneBG); //If I had a Canvas3D, sceneBG, with its child aBG, would be visible
              aBG.detach(); //aBG is no longer a part of sceneBG, but it still exists as aBG
         }
    }
    So, to answer your questions:
    When a BranchGroup is detached, it is not deleted and can still be used.
    You only need the original reference to use it.
    You can later attach it with the original reference.
    The method is named detach() because the BranchGroup that you call the method on is the one that is detached.

    Edited by: trozamon on Jun 13, 2010 5:56 PM
This discussion has been closed.