Created
July 8, 2014 09:39
-
-
Save paulwinex/9e4770982ad1951ca363 to your computer and use it in GitHub Desktop.
Get all UV shells from mesh object
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.OpenMaya as om | |
import maya.cmds as cmds | |
def getUvShelList(name): | |
selList = om.MSelectionList() | |
selList.add(name) | |
selListIter = om.MItSelectionList(selList, om.MFn.kMesh) | |
pathToShape = om.MDagPath() | |
selListIter.getDagPath(pathToShape) | |
meshNode = pathToShape.fullPathName() | |
uvSets = cmds.polyUVSet(meshNode, query=True, allUVSets =True) | |
allSets = [] | |
for uvset in uvSets: | |
shapeFn = om.MFnMesh(pathToShape) | |
shells = om.MScriptUtil() | |
shells.createFromInt(0) | |
# shellsPtr = shells.asUintPtr() | |
nbUvShells = shells.asUintPtr() | |
uArray = om.MFloatArray() #array for U coords | |
vArray = om.MFloatArray() #array for V coords | |
uvShellIds = om.MIntArray() #The container for the uv shell Ids | |
shapeFn.getUVs(uArray, vArray) | |
shapeFn.getUvShellsIds(uvShellIds, nbUvShells, uvset) | |
# shellCount = shells.getUint(shellsPtr) | |
shells = {} | |
for i, n in enumerate(uvShellIds): | |
if n in shells: | |
shells[n].append([uArray[i],vArray[i]]) | |
else: | |
shells[n] = [[uArray[i],vArray[i]]] | |
allSets.append({uvset: shells}) | |
return allSets |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment