three.js Switching objects on click

萝らか妹 提交于 2019-12-25 07:23:27

问题


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.


回答1:


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;
});


来源:https://stackoverflow.com/questions/23521434/three-js-switching-objects-on-click

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!