Community
Maya Programming
Welcome to Autodesk’s Maya Forums. Share your knowledge, ask questions, and explore popular Maya SDK topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
Anonymous
2028 Views, 6 Replies

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

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.

 

 

6 REPLIES 6
Message 2 of 7
osidedan
in reply to: Anonymous

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)
Message 3 of 7
osidedan
in reply to: osidedan

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)

 

Message 4 of 7
olarn
in reply to: Anonymous

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
Message 5 of 7
Anonymous
in reply to: osidedan

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

Message 6 of 7
thiagogroo
in reply to: osidedan

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

Thanks a lot @osidedan ! 😄 😄 😄 

 

Message 7 of 7
adityakumar7024
in reply to: osidedan

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?

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report