- Home /
How to get all pixels used by the mesh UVs?
Hello,
I'm trying to get the number of red pixels in a mesh texture. I can get all the pixels using Texture2D.GetPixels(), but how can I get only the pixels covered by the mesh uv map?
Answer by Pangamini · Aug 21, 2019 at 08:52 AM
Getting pixels at the vertex UVs won't be enough, I guess you want to see all the red pixels inside the triangles as well? In that case, you'd need to go triangle by triangle; get the triangles from the mesh (the indices). Iterate over triangles and always get it's vertices' UVs. Project those UVs on the texture, use a 2D algorithm to 'draw' the triangle on the texture, but instead of drawing, just count the red pixels. Repeat for every triangle in the mesh, sum up the pixels.
Your answer
Follow this Question
Related Questions
Screen Coordinates to UI Texture Coordinates 0 Answers
How to match texture Scaling/offset to UV coordinates 1 Answer
How to get precise pixel values form a Texture2D using uv coordinates. 1 Answer
How to get uvCordinat of raycast hit without mesh collider 1 Answer
Mapping webcamTexture to only a part of a sphere, and adjusting it at runtime? 1 Answer