Announcements
Autodesk Community will be read-only between April 26 and April 27 as we complete essential maintenance. We will remove this banner once completed. Thanks for your understanding

UV - select uvs under certain amount U distance / V distance

Anonymous

UV - select uvs under certain amount U distance / V distance

Anonymous
Not applicable

Hey guys, i am trying to write a script for checking UVs which are really small. Basicaly i want to select all uv shells below for example 3px in 2048 map size.

 

 

0 Likes
Reply
Accepted solutions (1)
2,449 Views
6 Replies
Replies (6)

osidedan
Advocate
Advocate

This Python script should be able to do that. Just change the arguments passed into select_small_shells() to match what minimum size vs texture size you need, and have your meshes selected before you run it.

 

 

import maya.cmds as cmds
import maya.mel as mel

#This will select UV shells that are smaller than a minimum size in pixels, compared to a texture size in pixels
#Any uv shell smaller than the minimum size in either the U or V direction will be selected after the operation.

def select_small_shells(min_size, texture_size):
    sel = cmds.ls(sl=True)
    mel.eval('ConvertSelectionToUVs')
    mel.eval("global string $shells [];")
    shells = mel.eval("$shells =texGetShells();")
    min_size_normalized = float(min_size)/float(texture_size)
    small_shells = []
    for shell in shells:
        bounding_box_points = cmds.polyEvaluate(shell,bc2=True)
        u_dist = abs(bounding_box_points[0][1] - bounding_box_points[0][0])
        v_dist = abs(bounding_box_points[1][1] - bounding_box_points[1][0])
        if u_dist < min_size_normalized or v_dist < min_size_normalized:
            small_shells.append(shell)
    cmds.select(small_shells,r=True)

#change the arguments here to match min shell size, and texture size.
select_small_shells(3,2048)
0 Likes

osidedan
Advocate
Advocate
Accepted solution

Update:

Found a bug with the previous script related to how the Maya command texGetShells sometimes returns UV shells as a long string. Use this script instead to account for that:

import maya.cmds as cmds
import maya.mel as mel

#This will select UV shells that are smaller than a minimum size in pixels, compared to a texture size in pixels
#Any uv shell smaller than the minimum size in either the U or V direction will be selected after the operation.

def select_small_shells(min_size, texture_size):
    sel = cmds.ls(sl=True)
    mel.eval('ConvertSelectionToUVs')
    mel.eval("global string $shells [];")
    shells = mel.eval("$shells =texGetShells();")
    min_size_normalized = float(min_size)/float(texture_size)
    small_shells = []
    i = 0
    while i < len(shells):
        tokenized_shell = shells[i].split(' ')
        bounding_box_points = cmds.polyEvaluate(tokenized_shell,bc2=True)
        u_dist = abs(bounding_box_points[0][1] - bounding_box_points[0][0])
        v_dist = abs(bounding_box_points[1][1] - bounding_box_points[1][0])
        if u_dist < min_size_normalized or v_dist < min_size_normalized:
            for sub_shell in tokenized_shell:
                small_shells.append(sub_shell)
        i += 1
        
    cmds.select(small_shells,r=True)

#change the arguments here to match min shell size, and texture size.
select_small_shells(100,100)

 

olarn
Advocate
Advocate

https://help.autodesk.com/view/MAYAUL/2020/ENU/?guid=Maya_SDK_MERGED_py_ref_class_open_maya_1_1_m_fn...

 

I think a more definite answer to this question would be to, 

  1. Figure out in advance:
    1. All the internal triangles of the mesh, position
    2. What uv corresponds to which internal triangles verts, uv space position
    3. uv id belong to what uv shell 
  2. For each/target uv set:
    1. Look for degenerate uv triangle mapped to a mesh triangle in uv space according to your target pixel density (the uv triangle's area)
      1. Also look for reversed uv (winding order different from triangle vert's direction)
    2. Mark the whole shell with any offending uv triangles as bad, record triangle as necessary

Anonymous
Not applicable

Thanks a lot man! That works great!! ❤️ You rock 🤘

0 Likes

thiagogroo
Explorer
Explorer

OMG! This is exactly what I was looking for! It will speed my work a lot!

Thanks a lot @osidedan ! 😄 😄 😄 

 

adityakumar7024
Explorer
Explorer

Hi,

Even if UV shells have sufficient pixel distance, that is getting selected. And some if some uv shells are much closer, they are not getting detected. Any idea what could be the issue?

0 Likes

Type a product name