Skip to main content

refreshing and altering the scene graph content...

3 replies [Last post]
mandravinos
Offline
Joined: 2012-01-19
Points: 0

hi all!

i know my question may sound elementary, but it is not clearly addressed in the first four chapters of the tutorial (i need not read further for what i need java3d for) and everything i tried didn't seem to work...

i have a list of different house models, described by Room objects, each encapsulating its coordinates and dimensions. they are all supposed to be rectagle hexaedra.

what i want is with the selection of a Solution (comprising of a set of Room objects) in a Solution combobox, the previously rendered Solution in my canvas be cleared and the recently selected Solution be rendered.

what is the strategy to address that issue? i mean, since the scene has been compiled, which capabilities should i leave available and on which group node should i intervene in order to remove and then add my leaf nodes?

i am using a simple universe, and my scene graph is as follows.

(simple universei stuff)->(rootBranchGroup)->(siteTransformGroup)->(siteBranchGroup)->(set of LeafNode's)

i use the (siteTransformGroup) to add a Behavior to manipulate the site using the keyboard or mouse.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
mandravinos
Offline
Joined: 2012-01-19
Points: 0

i seem to have figured the solution myself so i make it available to the community.

i work with the simple universe recipe that incorporates a single Locale object.

  • create a reference to the current Locale
  • Locale tempLocale=simpleU.getLocale();
  • create a BranchGroup as a field that will be peristent throughout the lifetime of your SimpleUniverse object. do not bother to instantly initialize it.
  • BranchGroup currentBranchGroup;
  • create a method whose purpose will be to replace the previous branch graph with a new one
  • public renderNewBG() {/*all the following stuff happens in here...!*/}
  • create a temporary BranchGroup with your content and populate it at your discresion
  • BranchGroup tempBG=new BranchGroup();
    /*all add child nodes here...*/
  • in order to be able to attach and detach this BranchGroup at your discresion on the Locale, you have to set its detach capability
  • tempBG.setCapability(BranchGroup.ALLOW_DETACH);
  • and finally you compile the BranchGroup
  • tempBG.compile();

    the scenario goes like this: there's always a BranchGraph object attached to the Locale that is created by the SimpleUniverse. you want not to mingle with this particular BranchGroup cause if you get to remove it, your canvas becomes useless! so, you get to keep a reference of your most recently attached branch graph to the currentBranchGroup field so that you can use it to access the BranchGroup object that YOU have created and not the one SimpleUniverse has created for you.

    if (tempLocale.numBranchGraphs()>1) {
    tempLocale.removeBranchGraph(currentBranchGroup);
    currentBranchGraph=tempBG;
    simpleU.addBranchGraph(currentBranchGroup);
    }
    else {
    simpleU.addBranchGraph(tempBG);
    currentBranchGroup=tempBG;
    }

    all comments and/or corrections welcome! ;)

    mandravinos
    Offline
    Joined: 2012-01-19
    Points: 0

    in a nutshell what i want is to be able to intervene in the scene graph after createSceneGraph() has been called...

    anyone...?

    mikelizzi2
    Offline
    Joined: 2011-10-13
    Points: 0

    Yes, If I understand you correctly, that's the way I do it.

    For objects that I might want to remove from the scene after it is live, I set their BranchGroup Capability like this:

    branchGroup.setCapability(BranchGroup.ALLOW_DETACH);

    In order to be able to add objects after the scene is live, I set the capability on one of the permanent BranchGroups like this:

    branchGroup.setCapability( BranchGroup.ALLOW_CHILDREN_EXTEND );

    It took me a while to figure it out too.