TD-SDK Shift UVs

From The Foundry MODO SDK wiki
Jump to: navigation, search


Example of using modo.Polygon.setUV /getUV from the TD-SDK


import modo
def shiftUVs (UVoffset, geometry, vertexIndex, UVMapName='Texture'):
    '''Shift vertex UVs on by a given offset'''
    if not geometry.vmaps[UVMapName]:
        raise LookupError
    uvmap  = geometry.vmaps[UVMapName][0]
    vertex = geometry.vertices[vertexIndex]
    UV = uvmap[vertexIndex]
    # If the UV tuple consists purely of numbers, then it is a continuous (shared) UV
    if all (isinstance(i, (float, int, long)) for i in UV):	
        u,v = UV
        uvmap[vertexIndex] = (u+UVoffset[0], v+UVoffset[1])
    # If it is discontinuous, iterate over all connected polygons
        for polygon in vertex.polygons:
            u,v = polygon.getUV(vertex, uvmap=UVMapName)
            polygon.setUV ( (u+UVoffset[0], v+UVoffset[1]), vertex, uvmap=UVMapName)
with modo.Mesh().geometry as geo:
    for i in xrange (len(geo.vertices)):
        shiftUVs ((0.1, 0), geo, vertexIndex=i, UVMapName='Texture')