Navigation Menu

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show/hide Object3D ? #251

Closed
rdad opened this issue Jun 10, 2011 · 15 comments
Closed

Show/hide Object3D ? #251

rdad opened this issue Jun 10, 2011 · 15 comments
Labels

Comments

@rdad
Copy link

rdad commented Jun 10, 2011

I try to figure out how to show/hide Object3D ans his childrens at any moment.

  • with the visible property ?
  • translate it out of the frustrum ?
  • any idea ?
@mrdoob
Copy link
Owner

mrdoob commented Jun 10, 2011

Currently you can do that like this:

THREE.SceneUtils.traverseHierarchy( object, function ( object ) { object.visible = false; } );

@rdad
Copy link
Author

rdad commented Jun 10, 2011

Thanks! It works like a charm.

@rdad rdad closed this as completed Jun 10, 2011
@felixturner
Copy link
Contributor

FYI - To hide all children of myObject3D, snippet above should now read:

myObject3D.traverse( function ( object ) { object.visible = false; } );

@martindsq
Copy link

I think this functionality is not yet resolved. I want to hide an object (hiding all children) but the current way of doing it (traversing) isn't feasible because I want to maintain the visible status of its children. For example, some children are visible and others not; hiding the parent should hide all children but showing it again should show children that were previously visible.

@mrdoob
Copy link
Owner

mrdoob commented Dec 5, 2013

I agree. WebGLRenderer needs to accommodate that. It's something I have pending to do.

@felixturner
Copy link
Contributor

FYI: Setting visible on a parent now affects children also. (tested with r71)

@agnivade
Copy link
Contributor

agnivade commented Mar 1, 2016

Using r72. Setting visible on parent does not seem to affect children. Has the functionality changed again ?

@mrdoob
Copy link
Owner

mrdoob commented Mar 1, 2016

@agnivade no, it hasn't changed. Setting visible to false means that neither the object or its children will be renderer, regardless of the children visible. If visible is set to true then the children will render only if their visible is set to true.

@agnivade
Copy link
Contributor

agnivade commented Mar 2, 2016

Thanks. Must be something wrong with my code then, will check.

@Jairolaya12x
Copy link

Thanks

@TylerJGabb
Copy link

TylerJGabb commented Feb 6, 2018

You could just invoke
myObj3D.visible = false. This appears to hide everything that is a child of your Object3D

calling myObj3D.visible = true Shows everything.

albertl2 added a commit to albertl2/three.js that referenced this issue Apr 12, 2019
The `.setVisible` method is not in the Mesh documentation, or in the Object3D documentation. Changed this according to here: mrdoob#251 (comment)
@jscastro76
Copy link

It's an old discussion, but there's an important caveat here, set visible to false "only" hides the object and it's children for the camera, but they still visible for the raycaster, unless you use 2 different layers and you disable them from the layer the raycaster is observing. If you want to make them fully invisible is needed to disable them in the layer used by the raycaster.
I use layers 0 and 1 for camera, and only layer 0 for raycasting, so I can have objects visible and raycasted:
obj.layers.enable(0); obj.visible = true;

objects visible but not raycasted:
obj.layers.disable(0); obj.layers.enable(1); obj.visible = true;

and objects hidden and not raycasted:
obj.layers.disable(0); obj.layers.enable(1); obj.visible = false;

@mrdoob
Copy link
Owner

mrdoob commented Apr 18, 2020

@jscastro76 you may be interested in #19012

@jscastro76
Copy link

thanks, I'll take a look to it!

@asadullakkh
Copy link

It's an old discussion, but there's an important caveat here, set visible to false "only" hides the object and it's children for the camera, but they still visible for the raycaster, unless you use 2 different layers and you disable them from the layer the raycaster is observing. If you want to make them fully invisible is needed to disable them in the layer used by the raycaster. I use layers 0 and 1 for camera, and only layer 0 for raycasting, so I can have objects visible and raycasted: obj.layers.enable(0); obj.visible = true;

objects visible but not raycasted: obj.layers.disable(0); obj.layers.enable(1); obj.visible = true;

and objects hidden and not raycasted: obj.layers.disable(0); obj.layers.enable(1); obj.visible = false;

Thank you it works!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

9 participants