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.
Solved! Go to Solution.
Solved by osidedan. Go to Solution.
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)
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)
I think a more definite answer to this question would be to,
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.