allright, here it goes. it was easier than I expected, thanks to python dictionary.
Just select you geometry and run it. Every shell will be normalized to 0-1, aligned along U, and extracted to separate mesh.
import maya.cmds as cmds
import maya.mel as mel
import string
#extract index from name like that: pCube|pCubeShape.map[666]
def extractIndex(path):
bracePos= path.rfind("[")
return string.atoi(path[bracePos+1:-1])
#returns a list of uv shells, where each shell is represented by exactly one UV point
def mfGetUVShells(shape):
shells= {}
uvCount= cmds.polyEvaluate(shape, uv=1)
allUVs= range(uvCount)
uv= 0
uvMax= allUVs[-1]
while(uv<=uvMax):
#select uv shell
cmds.select(shape + ".map[" + str(uv) + "]")
mel.eval("polySelectBorderShell 0")
uvs_names= cmds.ls(sl=1, l=1, fl=1)
#get indices of selected uvs
uvs= map(extractIndex, uvs_names)
#remove this shell's uvs from further inspection
for u in uvs:
if(u in allUVs):
allUVs.remove(u)
shells[uvs[0]]= 1
if(not len(allUVs)): break
#reset range
uv= allUVs[0]
uvMax= allUVs[-1]
# go home
return shells.keys()
#layouts shells ina U-Row
def RowLayoutShells(shape, shells):
offset= 0;
for shell in shells:
cmds.select(shape + ".map[" + str(shell) + "]")
mel.eval("polySelectBorderShell 0")
cmds.polyNormalizeUV(normalizeType=1, preserveAspectRatio= 1)
cmds.polyEditUV(relative=1, u=offset)
offset += 1
#split each shell into separate mesh
def BustShellsIntoObjects(shape, shells):
copyL= cmds.duplicate(shape)
shape= copyL[0]
for shell in shells:
cmds.select(shape + ".map[" + str(shell) + "]")
mel.eval("polySelectBorderShell 0")
cmds.select(cmds.polyListComponentConversion(tf=1))#convert to faces
cmds.polyChipOff(dup=1,ch=0,kft=1)
cmds.polySeparate(shape, rs=0)
def RowLayoutShellsSL():
sl= cmds.ls(sl=1, l=1)
for o in sl:
shells= mfGetUVShells(o)
print "Shells count: " + str(len(shells))
RowLayoutShells(o, shells)
BustShellsIntoObjects(o, shells)
RowLayoutShellsSL()