Skip to main content

Removing Children from a BranchGroup

7 replies [Last post]
markfvdl1
Offline
Joined: 2006-04-03
Points: 0

There were many topics on this website that talked about this but I still cant figure out what I am doing wrong. I am tryng to remove children from a branchGroup and I am getting this error

Exception in thread "AWT-EventQueue-0" javax.media.j3d.RestrictedAccessException: Group: only a BranchGroup node may be removed
at javax.media.j3d.Group.removeAllChildren(Group.java:384)

Here is my code

public BranchGroup createSceneGraph() {
branchGroup = new BranchGroup();
branchGroup.setCapability(BranchGroup.ALLOW_CHILDREN_READ);
branchGroup.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE);
branchGroup.setCapability(BranchGroup.ALLOW_DETACH);

Shape3D shape = new ColorCube(.5);
branchGroup.addChild(shape);
objRoot.addChild(branchGroup);
return objRoot;
}

In a button press event I call
branchGroup.removeAllChildren()

and thats when I get the exception

Please help its driving me nuts. I have a feeling its with the capability setting but I dont know what they are

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
pkjana
Offline
Joined: 2011-04-24
Points: 0

Live scenegraph doesn't allow to editing, removing children
So, when you edit your graph ,you should follow the following steps:
1. Detach it from live scene graph
2. Edit your graph(adding/modifing/removing children in graph)
3. Add your graph to SimpleUniverse
4. View the scene graph

BranchGroup objRoot = new BranchGroup();
objRoot.setCapability(BranchGroup.ALLOW_DETACH);
objRoot.setCapability(BranchGroup.ALLOW_CHILDREN_READ);
objRoot.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE);
objRoot.setCapability(BranchGroup.ALLOW_CHILDREN_EXTEND);
objRoot.setCapability(BranchGroup.ALLOW_BOUNDS_READ);
objRoot.setCapability(BranchGroup.ALLOW_BOUNDS_WRITE);

Transform3D trans = new Transform3D();
TransformGroup tg = new TransformGroup(trans);
objRoot.addChild(tg);
objRoot.detach();

someObj.modifyNode(link); // link is another TransformGroup

simpleU.addBranchGraph(objRoot );
simpleU.getViewingPlatform().setNominalViewingTransform();

markfvdl1
Offline
Joined: 2006-04-03
Points: 0

Thanks for your help, I got it to finally work. In the simple example I gave it does create a shape on a branchgroup then add the branchgroup to the root. All I did was place branchGroup.detach() before brachGroup.removeAllChildren() and it worked great.

FYI in your email you said one shape per brachgroup, I added two and it worked

Again thanks for helping me with this headache

Chet Urata

I suppose that is another way: if you detach the BranchGroup, it is no
longer part of a live scene graph (which I don't think would work if it were
compiled). Therefore, you can remove the children.

You are also right that you can add multiple items under a single detachable
BranchGroup, not just Shape3D objects, but darn near anything.

Nice work!

c h e t !

-----Original Message-----
From: java3d-interest@javadesktop.org
[mailto:java3d-interest@javadesktop.org]
Sent: Wednesday, April 05, 2006 7:24 AM
To: interest@java3d.dev.java.net
Subject: Re: RE: RE: Removing Children from a BranchGroup

Thanks for your help, I got it to finally work. In the simple example I gave
it does create a shape on a branchgroup then add the branchgroup to the
root. All I did was place branchGroup.detach() before
brachGroup.removeAllChildren() and it worked great.

FYI in your email you said one shape per brachgroup, I added two and it
worked

Again thanks for helping me with this headache
[Message sent by forum member 'markfvdl1' (markfvdl1)]

http://forums.java.net/jive/thread.jspa?messageID=101144

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@java3d.dev.java.net
For additional commands, e-mail: interest-help@java3d.dev.java.net

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@java3d.dev.java.net
For additional commands, e-mail: interest-help@java3d.dev.java.net

Chet Urata

Your code attempts to remove a Shape3D object rather than a BranchGroup.
The exception message says "only a BranchGroup node may be removed."

What you are attempting to do is removing the children *from* a BranchGroup,
which is not the same thing as removing the BranchGroup from its parent.

Therefore,

objRoot.remove( branchGroup );

will work.

If you want to remove the Shape3D object from "branchGroup," you would need
to put another BranchGroup (with its BranchGroup.ALLOW_DETACH capability
set) between "branchGroup" and "shape."

Good luck!

c h e t !

-----Original Message-----
From: java3d-interest@javadesktop.org
[mailto:java3d-interest@javadesktop.org]
Sent: Tuesday, April 04, 2006 8:15 PM
To: interest@java3d.dev.java.net
Subject: Removing Children from a BranchGroup

There were many topics on this website that talked about this but I still
cant figure out what I am doing wrong. I am tryng to remove children from a
branchGroup and I am getting this error

Exception in thread "AWT-EventQueue-0"
javax.media.j3d.RestrictedAccessException: Group: only a BranchGroup node
may be removed
at javax.media.j3d.Group.removeAllChildren(Group.java:384)

Here is my code

public BranchGroup createSceneGraph() {
branchGroup = new BranchGroup();
branchGroup.setCapability(BranchGroup.ALLOW_CHILDREN_READ);
branchGroup.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE);
branchGroup.setCapability(BranchGroup.ALLOW_DETACH);

Shape3D shape = new ColorCube(.5);
branchGroup.addChild(shape);
objRoot.addChild(branchGroup);
return objRoot;
}

In a button press event I call
branchGroup.removeAllChildren()

and thats when I get the exception

Please help its driving me nuts. I have a feeling its with the capability
setting but I dont know what they are
[Message sent by forum member 'markfvdl1' (markfvdl1)]

http://forums.java.net/jive/thread.jspa?messageID=100945

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@java3d.dev.java.net
For additional commands, e-mail: interest-help@java3d.dev.java.net

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@java3d.dev.java.net
For additional commands, e-mail: interest-help@java3d.dev.java.net

markfvdl1
Offline
Joined: 2006-04-03
Points: 0

My problem is not detaching the branch group from the root node, I have that part working. The problem is that I have created shapes, added them to a branch group and added that branchgroup to the root node, then in a later process detaching the branchgroup from the root node, create a new branchgroup and try to re-attach those shapes to the new branchgroup and thats when I get the error that the shapes already have a parent. The solution is supposed to be remove the children from the brachgroup with this call branchgroup.removeAllChildren(). I am still going to try the Swithable groups but I am not there yet. I need to solve this issue first

If I place branchGroup.removeAllChildren() in this method then it works. Its a problem only after I can gone live is when I get the error that the shapes already have a parent

public BranchGroup createSceneGraph() {
branchGroup = new BranchGroup();
branchGroup.setCapability(BranchGroup.ALLOW_CHILDREN_READ);
branchGroup.setCapability(BranchGroup.ALLOW_CHILDREN_WRITE);
branchGroup.setCapability(BranchGroup.ALLOW_DETACH);

Shape3D shape = new ColorCube(.5);
branchGroup.addChild(shape);
[b]branchGroup.removeAllChildren()[/b]
objRoot.addChild(branchGroup);
return objRoot;
}

Chet Urata

Actually, you nailed it on the head when you indicated that the problem
occurred after you had gone "live." I should have pointed this out before,
but that was what I was talking about. In case you are not yet aware of it,
some methods which work on non-live (hmm, unconceived?), un-compiled scene
graphs refuse to operate on live or compiled scene graphs, except under
certain conditions, if any.

The clue to this is actually in the javadoc for the removeAllChildren()
method of the Group class
(http://download.java.net/media/java3d/javadoc/1.4.0-latest/javax/media/j3d/
Group.html#removeAllChildren()):

RestrictedAccessException - if this group node is part of live or
compiled scene graph and any of the children being removed are not
BranchGroup nodes

Therefore, to reiterate, you would need to put a BranchGroup (with the
DETACH capability) between your root node ("branchGroup") and each Shape3D
child (e.g., "shape") in order to do "branchGroup.removeAllChildren();".

c h e t !

---------------------------------------------------------------------
To unsubscribe, e-mail: interest-unsubscribe@java3d.dev.java.net
For additional commands, e-mail: interest-help@java3d.dev.java.net

Thierry Milard

My problem is not detaching the branch group from the root node, I have that
part working.

+AD0APQA+- Ok your issue is the second level (the son of the Root BG).

1)+ACI-The problem is that I have created shapes, added them to a branch group
and added that branchgroup to the root node+ACI-,

+AD0APQA+- Got it. Let's call this happy familly:

RootBG, BloodyBG ,Shape01 and Shape02.

You did :

+AHs- BloodyBG.addChild(Shape01)+ADs-

BloodyBG.addChild(Shape02)+ADs-

RootBG.addChild(BloodyBG)+ADs- +AH0-

Fine codding to me...

2) +ACI-then in a later process detaching the branchgroup from the root node,
create a new branchgroup and try to re-attach those shapes to the new
branchgroup and that's when I get the error that the shapes already have a
parent.+ACI-

+AD0APQA+- Logical error: your shapes are still attached (as a parent) to BloodyBG.

When you code later on:

+AHs- RootBG.removeChild(BloodyBG)+ADs-

BranchGroup aNewBloodyBG +AD0- new BranchGroup()

ANewBloodyBG .addChild(Shape01) // OUPSS +ACEAIQA7-

ANewBloodyBG .addChild(Shape02)+ADs- // OUPS +ACEAIQ-

RootBG.addchild(ANewBloodyBG )+ADs-

+AH0-

The last +ACI-OUPS+ACEAIQAi- lines will fail BECAUSE Shape01 and Shape02 are still
attached to your old friend: BloodyBG .

Solution: Add this line before :

+AHs- BloodyBG .removeChild(Shape01)+ADs-

BloodyBG .removeChild(Shape02)+ADsAfQ-

Then (and ONLY then) you can put your

+AHs- ANewBloodyBG .addChild(Shape01)+ADs-

ANewBloodyBG .addChild(Shape02)+ADs- +AH0-

+AH0-

Bye Thierry

-----------------------------------

The solution is supposed to be remove the children from the brachgroup with
this call branchgroup.removeAllChildren(). I am still going to try the
Swithable groups but I am not there yet. I need to solve this issue first

If I place branchGroup.removeAllChildren() in this method then it works. Its
a problem only after I can gone live is when I get the error that the shapes
already have a parent

Public BranchGroup createSceneGraph() +AHs-

BranchGroup +AD0- new BranchGroup()+ADs-

BranchGroup.setCapability(BranchGroup.ALLOW+AF8-CHILDREN+AF8-READ)+ADs-

BranchGroup.setCapability(BranchGroup.ALLOW+AF8-CHILDREN+AF8-WRITE)+ADs-

BranchGroup.setCapability(BranchGroup.ALLOW+AF8-DETACH)+ADs-

Shape3D shape +AD0- new ColorCube(.5)+ADs-

BranchGroup.addChild(shape)+ADs-

BranchGroup.removeAllChildren()

ObjRoot.addChild(branchGroup)+ADs-

Return objRoot+ADs-

+AH0-

-------Original Message-------

From: Chet Urata

Date: 04/05/06 14:56:20

To: interest+AEA-java3d.dev.java.net

Subject: RE: RE: Removing Children from a BranchGroup

Actually, you nailed it on the head when you indicated that the problem

occurred after you had gone +ACI-live.+ACI- I should have pointed this out before,

but that was what I was talking about. In case you are not yet aware of it,

some methods which work on non-live (hmm, unconceived?), un-compiled scene

graphs refuse to operate on live or compiled scene graphs, except under

certain conditions, if any.

The clue to this is actually in the javadoc for the removeAllChildren()

method of the Group class

(http://download.java.net/media/java3d/javadoc/1.4.0-latest/javax/media/j3d/

Group.html+ACM-removeAllChildren()):

RestrictedAccessException - if this group node is part of live or

compiled scene graph and any of the children being removed are not

BranchGroup nodes

Therefore, to reiterate, you would need to put a BranchGroup (with the

DETACH capability) between your root node (+ACI-branchGroup+ACI-) and each Shape3D

child (e.g., +ACI-shape+ACI-) in order to do +ACI-branchGroup.removeAllChildren()+ADsAIg-.

c h e t +ACE-

---------------------------------------------------------------------

To unsubscribe, e-mail: interest-unsubscribe+AEA-java3d.dev.java.net

For additional commands, e-mail: interest-help+AEA-java3d.dev.java.net

[att1.html]
[BackGrnd.jpg]
[imstp_heads_en.gif]