> From: Laurent Perato <[EMAIL PROTECTED]>
> 
> I want to add (or remove) a behavior in my scene graph AT ANY TIME
> I mean : NOT JUST before the scene graph become alive or compiled.


To add/remove a subgraph at runtime you need to put the stuff to be 
added/removed into a BranchGroup and set the capability bits on the parent and 
child to allow the runtime changes:

        Behavior yourBehavior; // this is what you want to remove
        Group    parent;       // this is where you want to add/remove
        
        BranchGroup removableBehavior = new BranchGroup();
        removeableBehavior.addChild(yourBehavior);
        removeableBehavior.setCapability(BranchGroup.ALLOW_DETACH);
        
        parent.setCapability(Group.ALLOW_CHILDREN_READ);
        parent.setCapability(Group.ALLOW_CHILDREN_WRITE);
        parent.setCapability(Group.ALLOW_CHILDREN_EXTEND);
        parent.addChild(removeableBehavior);
        
With this, you can now add/remove after the scene graph is live. Call 
removableBehavior.detach() to remove the behavior from the scene and 
parent.addChild(removeableBehavior) to add it.
        
Note: you may not need to add/remove the behavior from the graph. In many cases 
you can use the setEnable() method to turn the behavior on and off.

Doug Gehringer
Sun Microsystems

=====================================================================
To subscribe/unsubscribe, send mail to [EMAIL PROTECTED]
Java 3D Home Page: http://java.sun.com/products/java-media/3D/

Reply via email to