三.js 点击时切换对象 [英] three.js Switching objects on click
本文介绍了三.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;
});
这篇关于三.js 点击时切换对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文