Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide and show an object on scene in three.js

I have an object which is composed of spheres on my scene. And I have a hide and show button.
The flow of my program is like that. For example, when I select one of the spheres (I used raycasting for select a sphere) then click the hide button, this sphere will be hidden. And after then click the show button it will be shown. But I don't know how can I do it.
I used three.js for creating my scene.
And I don't find any example for my question. How can I do it?
Thanks for your help.

like image 791
Şeyma Yaman Avatar asked Mar 05 '17 14:03

Şeyma Yaman


2 Answers

simply use the object traverse method to hide the mesh in three.js. In my code hide the object based on its name

object.traverse ( function (child) {
    if (child instanceof THREE.Mesh) {
        child.visible = true;
    }
});

Here is the working sample for Object show/hide option http://jsfiddle.net/ddbTy/287/

I think it should be helpful,..

like image 124
selvarajmas Avatar answered Oct 13 '22 21:10

selvarajmas


Try this:

object.visible = false; //Invisible
object.visible = true;  //Visible
like image 34
Francisco Gomes Avatar answered Oct 13 '22 21:10

Francisco Gomes