TD-SDK Shift UVs

From The Foundry MODO SDK wiki
Revision as of 03:23, 17 May 2016 by Ivo.grigull (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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')