I have a method that generates a Shape3D. I want to regenerate that shape
and replace the Shape3D originally added to the scene graph with the newly
generated one. How do I do this?
tg = new TransformGroup();
tg.addChild(generateShape());
rootBranchGroup.addChild(tg);
I want to replace the Shape3D added to tg with a new one created by
generateShape().
Dave schrieb:
> I have a method that generates a Shape3D. I want to regenerate that shape
> and replace the Shape3D originally added to the scene graph with the newly
[quoted text clipped - 6 lines]
> I want to replace the Shape3D added to tg with a new one created by
> generateShape().
Hi Dave,
you can do this by
tg = new TransformGroup();
shape = generateShape();
tg.addChild(shape);
rootBranchGroup.addChild(tg);
and then replace the shape object by a shape2 object by
tg.removeChild(shape);
shape2 = generateShape();
tg.addChild(shape2);
But you have to be careful: after compiling the
rootBranchGroup by rootBranchGroup.compile() method
it is usually not be allowed to remove or add children
so you'll get an Exception like <<Capability not set>>
or something. Then you can set this capability by
rootBranchGroup.setCapability(Group.ALLOW_CHILDREN_EXTEND);
or something like that.
Bye,
Nick
Paul Drallos - 18 May 2006 00:52 GMT
Another thing you have to watch out for is that you can only add BranchGroups to a live scene. So before you add the shape to the scene, you have to put it in a BranchGroup and then add the BranchGroup to the scene (provided all the capabilities are set.)