展示隐形父母的孩子 [英] Show children of invisible parents
问题描述
在我的场景中,我有一个对象图,我将子对象添加到父对象中。但是,当我设置 parent.visible = false
时,three.js行为正确并且在层次结构中没有显示任何元素。
In my scene I have an object graph, where I add child objects to parents. However, when I set parent.visible = false
three.js behaves correctly and shows no element in the hierarchy.
但对于我的项目,我想要一个不同的行为。我希望子对象出现,当他们的可见性 true
时,即使父对象被隐藏。
But for my project I want a different behavior. I want that child objects show up, when their visibility is true
, even when parent objects are hidden.
什么这将是实现这一目标的最佳方式吗?我想到为父对象分配一个透明材质,但我听说这会在渲染场景时引起问题,应该省略。
What would be the best way to achieve this? I thought of assigning a transparent material to parent objects, but I heard that this can cause problems when rendering the scene and should be omitted.
推荐答案
隐形父母的孩子不可见。
Children of an invisible parent are not visible.
但是有一个合理的解决方法:将材料可见性设置为false。
There is a reasonable workaround, however: set the material visibility to false.
你需要 clone()
每个对象的材料,但没关系,因为对象会(在<$ c的情况下) $ c> WebGLRenderer )仍然共享相同的着色器程序。
You will need to clone()
the material for each object, but that is OK, because the objects will (in the case of WebGLRenderer
) still share the same shader program.
var material = new THREE.MeshPhongMaterial();
parent = new THREE.Mesh( geometry, material.clone() );
parent.material.visible = false;
child = new THREE.Mesh( geometry, material.clone() );
编辑:根据OP建议(见评论)和最近的拉取请求更新答案。
Updated answer based on OP suggestion (see comments) and recent pull request.
three.js r.68(r.69dev for CanvasRenderer
)
three.js r.68 (r.69dev for CanvasRenderer
)
这篇关于展示隐形父母的孩子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!