I’m using the STLLoader, have added a color attribute to the geometry and can successfully select single triangles or groups of triangles and change their vertex colors (see image). It seems opacity, however, is a material-wide property; I’ve discovered no way to change the opacity of only selected triangles. Is this possible?
You can set opacity as the 4th component of vertex colors — see Feature: Add vertex color alpha channel support. by chubei · Pull Request #20975 · mrdoob/three.js · GitHub. This requires that some use of opacity be enabled on the material, like .transparent=true
or .alphaTest>0
. The final opacity value of each pixel is a product of:
fragmentOpacity = <material opacity> ✖️ <material.map opacity> ✖️ <vertex opacity>
One thing to keep in mind is that enabling alpha blending (.transparent=true
) on opaque triangles (opacity = 1) may still have side effects due to sort-dependency, compared to if transparency were not enabled. This usually appears like an opaque surface on the back of the object is visible through an opaque surface on the front of the object. Try setting .transparent=true
without any change to opacity, rotating the object, and you may see what I mean.
If you can separate the transparent triangles into a different geometry with a different material, that’s often easier to manage.
Thank you very much for the prompt reply! I’ve indeed noticed odd behavior with opacity when rotating. I hadn’t thought of producing a separate geometry with selected triangles. I think I’ll give that a shot.