Control a Marquee Selection through Script

Say I want to determine what, if any, components live at, or near, a specfic location in UV Space.
Can I perform a selection through python/API/mel/pymel given only a location and a shape node?

In psuedo code:

def getComponentAtLocation(shape=None, location=None, space=‘uv’, expand=None)
# pad the location with the expand amount to create a selection bounding box
# find any faces that cross the bounding box
# find any uv coordinates contained within the box
# return found components

getComponentAtLocation(shape=‘pSphereShape1’, location=[0.25, 0.75], space=‘uv’, expand=0.1)

Result: [‘pSphereShape1.f[2:5]’, ‘pSphereShape1.f[8]’, ‘pSphereShape1.map[4]’]

Thanks,

Just spit-balling here, but what about something like:

  • Get the uv bounding box for the query
  • Get all uvs on the object that fall within that boundingbox
  • Get all faces that are connected to those uvs

Would that give you what you wanted?

Something like this?

def getComponentAtLocation(shape=None, location=None, space='uv', expand=None):
    bb_min = location[0] - expand, location[1] - expand
    bb_max = location[0] + expand, location[1] + expand
    
    uv_coords = cmds.polyEditUV('%s.map[li]' % shape, q=True, u=True, v=True)
[/li]    uvs = []
    uv_num = 0
    for u, v in zip(*[iter(uv_coords)]*2):
        if u > bb_min[0] and u < bb_max[0] and v > bb_min[1] and v < bb_max[1]:
            uvs.append('%s.map[%d]' % (shape, uv_num))
        uv_num += 1

    faces = []
    if uvs:
        faces = cmds.polyListComponentConversion(uvs, fuv=True, tf=True)

    return faces, uvs

my first thought was to iterate over the uvs and test if the coordinates are inside the region. But i was hoping to avoid this route since it could be quite slow on large meshes/scenes.
I am hoping for some of function or node that wouldn’t need to iterate over the meshes.

Also, checking just the UV coordinates for inclusion with in the bounding region doesn’t find me polygons who cross the bounding region, but don’t contain any UVs with in it.

If you need to do poly-poly intersections look at GPC (there are python bindings in the cheeseshop) . This has C components so distribution may be tricky.

Planarhas a pure python version so it’s easy to package. It does not have a poly-poly intersection method. However you can use it to do half space tests and 2d - bounding box checks so it’s “easy” to make your own poly - poly intersection checker

thanks for the links!

I’d be curious to see what your solution ends up being if you feel like updating along the way.