Recognise different UV islands from UV coordinates array?

Is there any way to recognize different uv islands by going through the values of geometry.attributes.uv.array ?

End goal is to get an image with each island with a different color

like this (this model and texture is just for reference , any model can be input)

How the output should look

maybe some way to apply a vertex color on each island ? , then i could just capture a an image of the 2d/uv coordinate mesh with a perfectly framed orthographic camera

the difficult part is recognizing when one island is over and another one starts since the uv coordinates are just random triangles in a sequence

is this even possible ?

You can go through each triangle in the geometry, grab the UVs and draw the triangle on a 2D canvas using 2D API, no rendering is required for that. Then recognize islands on a flat image and colorize them.

If you use vertex colors in Blender and include them in export settings for .glb and import into THREE, they will appear under mesh.geometry.attributes.color.array so you can also pick up triangle color on the fly, then no island recognition is needed.

1 Like

yes , i can draw all the triangles on the canvas like this example with filled color ,
which will give the image with all islands having same color

now whats an efficient way to identify the different islands from the colored shapes from a canvas ?

I’m not sure what you mean by “identify”. If you already have an image with islands of different color you could scan it horizontally and vertically pixel by pixel and check for gaps as in horizontal / vertical lines that don’t have any colorized pixels. That way you can build a set of rectangular patches on the image containing islands. That’s more like a programming question, I don’t know the most efficient algorithm do to that, might depend on the language too.

I’m pretty sure (82%) you can use Python in Blender and find islands positions / dimensions and output them in a file, since Blender has a concept of an island there should be a Python API for them - that’s another option.

1 Like

the blender image i provided is just for reference for how the output should look, any model can be input(there are hundreds) & it might have an image or no image

and i would like to make this run on client side if possible

i will try pixel by pixel method using canvas first

if no method is found i’ll resort to blender make and store the island mask images
(blender has a “select linked” > “seam” options which selects faces of an uv island under the mouse pointer scripting - How to get lists of UV island from Python script? - Blender Stack Exchange )


1 Like