三.js 点击时切换对象

问题描述:

我想通过单击按钮来隐藏/显示对象.即单击 GUI 上的按钮,隐藏 obj1 并显示 obj2.我被告知要使用

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

但它似乎不起作用.

这是我渲染对象的方式

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?

非常感谢.

上次我检查,遍历函数是一个回调.所以你需要做这样的事情:

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