Hide Sphere -- How to?

Hi, all:

I created a Sphere

sphs = new Sphere(0.02f, someAppearance);

In my application, I would like there is a “switch” to display or to hide this Sphere.

But, how to hide a Sphere?
Or, how to set this Sphere 100% transparent?

Please help.

Best Regards
JIA

Just don’t draw it.

:slight_smile:

Or if you want it to be transparent (waste) set the 3D color’s alpha to 0.

You can add it to a Switch node. Then use setWhichChild(Switch.CHILD_ALL) to show it and setWhichChild(Switch.CHILD_NONE) to hide.

Setting the alpha to 0 will probably be slower since the sphere will still be rendered. Another difference is that using a Switch will disable picking on the hidden children.

Hi, do you mean that
a Sphere is able to inherit setWhichChild method?

I tried but error reported:

Sphere sphs;
sphs.setWhichChild(Switch.CHILD_NONE);

So, any further suggestions?

Rgds
JIA

No!


Sphere sphere = new Sphere(...);
Switch visibleSwitch = new Switch();
visibleSwitch.addChild(sphere);
visibleSwitch.setWhichChild(Switch.CHILD_NONE);

Thanks very much.

However, what’s the relationship between a Switch and the TransformGroup/BranchGroup/Universe?

Because my Sphere sphere is in a TransformGroup, and then a BranchGroup, which is finally shown in the Universe.
How to organize the Switch visibleSwitch and my TransformGroup/BranchGroup/Universe?

Cheers
JIA


//myTG.addChild(sphere)
myTG.addChild(sphereSwitch);

Switch inherits from Group.

You should read up on how the scenegraph works. Might be something about in the Java3D totorials:

http://java.sun.com/developer/onlineTraining/java3d/

Hi, Thanks. problem solved.

Cheers
JIA