Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
391 views
in Technique[技术] by (71.8m points)

javascript - 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.

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...