maya python script - how to check the UV boundaries of models?

时间:2018-07-24 10:18:41

标签: python maya

I'm looking for a python function or script which could check the borders of all uv shells in the scene, including exceeds the border or too close to the border.

The scripts I found are mainly used to find all uv shells in a selected object. https://polycount.com/discussion/196753/maya-python-get-a-list-of-all-uv-shells-in-a-selected-object

But I want to check the borders of all uv shells, and if there are any errors in the scene, it could show me exactly the model that is irregular.

Thanks,

1 个答案:

答案 0 :(得分:0)

这是一个非常基本的示例。它遍历场景中的所有网格,并使用cmds.polyEvaluate收集其UV边界框。如果发现任何东西超出提供的边界框,则会将其添加到列表中。它返回两件事:首先是整个场景的uv边界,其次是目标边界框之外的项目列表。

import maya.cmds as cmds
def scene_uv_bounds(target = (0,0,1,1)):
    umin, vmin, umax, vmax  = 0, 0, 0, 0

    for item in cmds.ls(type='mesh'):
        out_of_bounds = []
        # polyEvaluate -b2 returns [(umin, umax) , (vmin, vmas)]
        uvals, vvals = cmds.polyEvaluate(item, b2=True)
        #unpack into separate values
        uumin, uumax = uvals
        vvmin, vvmax = vvals

        if uumin < target[0] or vvmin < target[1] or uumax > target[2] or vvmax > target[3]:
            out_of_bounds.append(item)

        umin = min(umin, uumin)
        umax = max(umax, uumax)
        vmin = min(vmin, vvmin)
        vmax = max(vmax, vvmax)


    return (umin, vmin, umax, vmax), out_of_bounds

#usage
uv_bounds, out_of_bounds_meshes = scene_uv_bounds()

根据您的内容,您可能需要管理不同项目上的活动UV设置,但是对于简单的单通道情况,这会捕获大多数情况。