Melyy3
Melyy3

Reputation: 29

three.js Switching objects on click

I want to hide/reveal objects with the click of a button. i.e. click button on a GUI and obj1 is hidden and obj2 is revealed. I was told to do this using

 object.traverse(object.visible=false);

but it does not seem to work.

Here is how I'm rendering my objects

var gal = jsonLoader.load( "model/galmodel.js", addModelToScene ) ;
gal.traverse(gal.visible = false);

Can anyone point me into the right direction on how to make this work? And the command that will hide/reveal the objects on click?

Thank you very much.

Upvotes: 0

Views: 1241

Answers (1)

GuyGood
GuyGood

Reputation: 1377

Last time i checked, the traverse function was a callback. So you would need to do something like this:

gal.traverse(function(child){
   child.visible = false;
});

Upvotes: 1

Related Questions