如何使用 Three.js 版本 54 隐藏/显示对象? [英] How to Hide/Show Objects using Three.js release 54?

查看:31
本文介绍了如何使用 Three.js 版本 54 隐藏/显示对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将这个问题作为巨大问题的一部分提出,但建议分部分提出.这是我上一个问题的一部分.我之前的问题是:

mesh.traverse(function(child) {var z = document.getElementById("cameras").selectedIndex * 5 - 10;如果(z === -10){child.visible = true;} else if (child.position.z !== z) {child.visible = false;} 别的 {child.visible = true;};});

I've asked this question as a part of Huge question but was recommended to ask in parts. Here comes the part of my previous question. My previous question was: Here

I've been using Three.js Release 50 and able to show/hide the objects (In my application, it is a mesh child) with the help of:

THREE.SceneUtils.traverseHierarchy(mesh,function(child){
var z = document.getElementById("cameras").selectedIndex*5 -10;
if (z === -10){
    child.visible = true;
} else if (child.position.z !== z){
    child.visible = false;
} else {

    child.visible = true;
};
}); 

But while using release 54, it is said that to use, object.traverse but found very difficult to the same. How to replace the above code using release 54? The error I'm getting while using release 54 is:

Please help me to sort this out.

解决方案

Is the 'mesh' variable you are sending the 'traverseHierarchy' function an Object3d? If so have you tried 'mesh.children' which should return an array of child objects, or you could use the traverse function on the mesh object.

See: http://mrdoob.github.com/three.js/docs/54/#Reference/Core/Object3D

mesh.traverse(function(child) {
    var z = document.getElementById("cameras").selectedIndex * 5 - 10;
    if (z === -10) {
        child.visible = true;
    } else if (child.position.z !== z) {
        child.visible = false;
    } else {
        child.visible = true;
    };
});

这篇关于如何使用 Three.js 版本 54 隐藏/显示对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆