Show children invisible parents

In my scene, I have an object graph where I add child objects to the parents. However, when I set parent.visible = false

three.js it behaves correctly and does not display any items in the hierarchy.

But for my project, I want a different behavior. I want the child objects to show when they are visible true

, even if the parent objects are hidden.

What would be the best way to achieve this? I was thinking about assigning a transparent material to parent objects, but I heard that this can cause problems when rendering the scene and should be left out.

+3


source to share


2 answers


The children of the invisible parent are not visible.

However, there is a reasonable workaround: set the visibility of the material to false.

You will need a clone()

material for each object, but that's okay, because the objects will (in case WebGLRenderer

) still use 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 the OP's suggestion (see comments) and a recent pull request.

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

)

+4


source


Another workaround would be to slightly change the object relationship.

The nodes you want to become transparent must be container nodes that have children but no visual representation. And the grid of this container is a child with a special name like "me" or something like that.



this way setting a transparent node function is a function that turns itself into transparent, but that has no children and then no problem.

0


source







All Articles