Get average color of the texture assigned to a mesh triangle

Hi,

I know how to get and assign mesh triangle colors, but is it possible to get the average color of the material covering a triangle. Is it even accessible? If so would that be a huge amount of data to trawl through and be impractical?

Any advice welcome!

Thanks.

Impractical? Probably! Possible? Probably!

I’ve never had to do anything which required accessing verts from a given triangle, but unless I’m badly mistaken, that’s easy. Then you’ve got the UVs of your three verts. You’d code a likewise-not-too-difficult function to examine each pixel within the triangle based on its 3 UV coordinates, collecting pixel data to then average.

Computation time would vary with relative triangle size and texture size. You could even examine every-other-pixel, like a checkerboard pattern, or just take N random samples to reduce cost at the expense of accuracy. The mesh class will give you access to all the mesh data you’ll need. Just make sure your texture has Read enabled in the import settings.