最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Show children of invisible parents - Stack Overflow

programmeradmin5浏览0评论

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.

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.

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.

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.

Share Improve this question edited Aug 29, 2014 at 11:29 Burkhard 14.7k22 gold badges90 silver badges113 bronze badges asked Aug 29, 2014 at 11:28 JonasJonas 1,3451 gold badge19 silver badges31 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 7

Children of an invisible parent are not visible.

There is a reasonable workaround, however: set the material visibility to 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.

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 ments) and recent pull request.

three.js r.68 (r.69dev for CanvasRenderer)

Another workaround would be to change the objects relationship slightly.

The nodes that you want to bee 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.

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

发布评论

评论列表(0)

  1. 暂无评论