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

19,114

Solution 1

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,..

Solution 2

Try this:

object.visible = false; //Invisible
object.visible = true;  //Visible
Share:
19,114
Şeyma Yaman
Author by

Şeyma Yaman

Updated on June 19, 2022

Comments

  • Şeyma Yaman
    Şeyma Yaman almost 2 years

    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.

  • Şeyma Yaman
    Şeyma Yaman about 7 years
    Thank you. It is very helpful for me.