Adding a specific color to each facet in a mesh

Hello,
I have a specific mesh (.stl) I’m trying to load where each face (Facet) is a specific but different color. I can see how to find the normals and the facets like this:
https://www.babylonjs-playground.com/#1YTZAC#29
I suppose I could change the length of the normals and colors but I’d really just like to color the facet. I cannot color the vertex because this creates a multi-colored facet and isn’t what I need.
Any help/guidance would be appreciated.

1 Like

The reason for this is facets sharing vertices. See
https://doc.babylonjs.com/resources/facets
https://doc.babylonjs.com/resources/normals

The most straight forward way to separate facets is to use

mesh.convertToFlatShadedMesh()
1 Like

Example of coloring facets https://www.babylonjs-playground.com/#1YTZAC#32

By the way it seems that on icosphere is already flat shaded https://www.babylonjs-playground.com/#1YTZAC#33

3 Likes

Cool! Even a non-flat-shaded flat-shaded. (huh?)

Line 15 flat: false and no convert-to. How do they do that? :slight_smile:

It’s like the multiple lighting normals at each point… are direction-averaged and all get set to the averaged direction. See the difference in the specular of the light. interesting, huh?

In PG #35, each white “normals” line… is actually 6 normals/lines… averaged. Set line 15 flat: true, and see all 6 in un-averaged (un-summed?) form. Cool.

Thx for the per-face colors, John… very nice.

1 Like

This is really great! Thank you so much for putting this together.