admin管理员组文章数量:1202373
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.
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.
2 Answers
Reset to default 11simply 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,..
Try this:
object.visible = false; //Invisible
object.visible = true; //Visible
本文标签: javascriptHow to hide and show an object on scene in threejsStack Overflow
版权声明:本文标题:javascript - How to hide and show an object on scene in three.js - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738647750a2104688.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
Object3D
has a.visible
attribute. From (r84) threejs.org/docs/index.html?q=object3#Reference/Core/Object3D – gaitat Commented Mar 5, 2017 at 14:35true
orfalse
? – prisoner849 Commented Mar 5, 2017 at 15:03