Some preamble:
In a recent answer on blender stackexchange selected UV verts based on their coordinates.
The image shows a simple mesh with 9 vertices and 4 faces. A meshes "loops" is the verts in each face. So for this mesh it has 16 loops. A UV is associated with a loop.
import bpy
import numpy as np
ob = bpy.context.object
me = ob.data
uv_layer = me.uv_layers.active
# get uv values
uvs = np.empty((2 * len(me.loops), 1))
uv_layer.data.foreach_get("uv", uvs)
# select
u, v = uvs.reshape((-1, 2)).T
uv_layer.data.foreach_set(
"select",
np.logical_and(
(u >= 0) & (u <= 1),
(v >= 0) & (v <= 1)
)
)
End preamble
For example sake, the selected uv coords. (in loop order)
>>> uvlayer.data.foreach_get("select", uvselect)
>>> uvselect
array([[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], dtype=int32)
The vertex index associated with the loop. The middle vertex above is in 4 times (once for each face), there will be 4 with 2 entries and the four outer corners with 1. (again in loop order)
>>> me.loops.foreach_get("vertex_index", loop_vert_index)
>>> loop_vert_index
array([8, 6, 3, 7, 4, 8, 7, 2, 0, 5, 8, 4, 5, 1, 6, 8], dtype=int32)
The current selection of the 9 vertices.
>>> me.vertices.foreach_get("select", vert_select)
>>> vert_select
array([0, 0, 0, 0, 0, 0, 0, 0, 0], dtype=int32)
The question: how can I take the uv selection uvselect
, mapped with the loop_vert_index
to create the vert_select
if any of the loops associated with a vert is selected?. eg middle vert (index 8) selected if any of loops 0, 5, 10 or 15 are selected), in a "numpy" way.
EDIT.
Have found a way using the method outlined in Sum rows where value equal in column to get, via approach 2 of this answer if for example all loops were selected
vert_select = [1 1 1 1 2 2 2 2 4]
which can be used to select the mesh vertices. (Equiv of select vert if any
loop is selected).