[英]Show children of invisible parents
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. 但是,当我设置
parent.visible = false
three.js行为正确并且在层次结构中不显示任何元素。
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. 我希望子对象在其可见性为
true
时显示,即使父对象被隐藏也是true
。
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. 看不见的父母的孩子是不可见的。
There is a reasonable workaround, however: set the material visibility to false. 但是,有一个合理的解决方法:将材料可见性设置为false。
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. 您将需要
clone()
每个对象的材质,但这没关系,因为对象(在WebGLRenderer
的情况下)仍然共享相同的着色器程序。
var material = new THREE.MeshPhongMaterial();
parent = new THREE.Mesh( geometry, material.clone() );
parent.material.visible = false;
child = new THREE.Mesh( geometry, material.clone() );
EDIT: Updated answer based on OP suggestion (see comments) and recent pull request. 编辑:根据OP建议(请参阅注释)和最近的拉取请求更新答案。
three.js r.68 (r.69dev for CanvasRenderer
) three.js r.68(CanvasRenderer的
CanvasRenderer
)
Another workaround would be to change the objects relationship slightly. 另一种解决方法是稍微改变对象关系。
The nodes that you want to become transparent should be container nodes, that have children , but that have no visual representation. 您希望变为透明的节点应该是容器节点,它们具有子节点,但没有可视化表示。 And the mesh of this container is a child with an special name, like self or something like that.
而这个容器的网格是一个具有特殊名称的孩子,比如self或类似的东西。
this way setting the node to transparent is a function that turns the self child to transparent, but this one has no children and then there is no problem 这样将节点设置为透明是一个将自己的孩子变为透明的功能,但这个没有孩子然后没有问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.