Last active
December 16, 2021 11:09
-
-
Save Onefabis/313b86810a02ce4bfcada717932ceef0 to your computer and use it in GitHub Desktop.
Transfer UVs from unskinned to skinned mesh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import maya.cmds as mc | |
''' | |
Just copy and paste this code into script editor, select the source mesh with correct UVs, then select target skinned mesh and execute the code | |
If you run transfetUVs(1) if will transfer UVs according to the mesh topology, if you will run it with transfetUVs(0) it will transfer UVs according to the | |
mesh components. It may not work correctly if the vertex order somehow changed, so keep in mind that 'Topology' method works more correct, hence recommended usage is | |
transfetUVs(1). Also keep in mind that it works in 99.5% cases, but is is not silver bullet in cases where topology and components are different, so check every mesh after | |
UV transferring. | |
''' | |
def transfetUVs( mode=0 ): | |
objs = mc.ls(sl=1) | |
shapes = mc.listRelatives( objs[-1], s=1) | |
print shapes | |
orig = [ s for s in shapes if 'Orig' in s ] | |
mc.setAttr( orig[0] + '.intermediateObject', 0 ) | |
if mode == 0: | |
mc.transferAttributes( objs[0], orig[0], transferPositions=0, transferNormals=0, transferUVs=2, transferColors=2, sampleSpace=4, sourceUvSpace="UVChannel_1", searchMethod=3, flipUVs=0, colorBorders=1 ) | |
else: | |
mc.transferAttributes( objs[0], orig[0], transferPositions=0, transferNormals=0, transferUVs=2, transferColors=2, sampleSpace=5, sourceUvSpace="UVChannel_1", searchMethod=3, flipUVs=0, colorBorders=1 ) | |
mc.delete( orig[0], ch=1 ) | |
mc.setAttr( orig[0] + '.intermediateObject', 1 ) | |
transfetUVs(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment