<s> """<STR_LIT>""" <EOL> import re <EOL> import maya . cmds as cmds <EOL> import maya . mel as mel <EOL> import maya . OpenMaya as om <EOL> __oneOverTwoFiftyFive = ( <NUM_LIT:1.0> / <NUM_LIT> ) <EOL> def exportBlendShapes ( ) : <EOL> """<STR_LIT>""" <EOL> models = om . MSelectionList ( ) <EOL> for model in cmds . ls ( transforms = True ) : models . add ( model ) <EOL> modelsWithBlendShapeDeformers = { } <EOL> dagPath = om . MDagPath ( ) <EOL> iter = om . MItSelectionList ( models ) <EOL> while not iter . isDone ( ) : <EOL> iter . getDagPath ( dagPath ) <EOL> model = om . MDagPath ( dagPath ) <EOL> try : <EOL> dagPath . extendToShape ( ) <EOL> dg = om . MItDependencyGraph ( dagPath . node ( ) , om . MFn . kBlendShape , om . MItDependencyGraph . kUpstream ) <EOL> while not dg . isDone ( ) : <EOL> if not modelsWithBlendShapeDeformers . has_key ( model ) : <EOL> modelsWithBlendShapeDeformers [ model ] = [ ] <EOL> modelsWithBlendShapeDeformers [ model ] . append ( dg . currentItem ( ) ) <EOL> dg . next ( ) <EOL> except : pass <EOL> iter . next ( ) <EOL> for model in modelsWithBlendShapeDeformers . keys ( ) : <EOL> cmds . select ( model . partialPathName ( ) ) <EOL> mel . eval ( '<STR_LIT>' ) <EOL> cmds . select ( cl = True ) <EOL> for blendNode in modelsWithBlendShapeDeformers [ model ] : <EOL> fn = om . MFnDependencyNode ( blendNode ) <EOL> aliases = cmds . aliasAttr ( fn . name ( ) , q = True ) <EOL> for alias in aliases : <EOL> if not re . match ( '<STR_LIT>' , alias ) : continue <EOL> dest = '<STR_LIT>' % ( fn . name ( ) , alias ) <EOL> source = cmds . listConnections ( dest , p = True ) <EOL> if source : cmds . disconnectAttr ( source [ <NUM_LIT:0> ] , dest ) <EOL> cmds . setAttr ( dest , <NUM_LIT:0.0> ) <EOL> taggedBaseMesh = cmds . duplicate ( model . partialPathName ( ) ) [ <NUM_LIT:0> ] <EOL> taggedBaseMesh = cmds . rename ( taggedBaseMesh , model . partialPathName ( ) + '<STR_LIT>' ) <EOL> customAttrs = cmds . listAttr ( taggedBaseMesh , ud = True ) <EOL> if ( customAttrs ) : <EOL> for attr in customAttrs : <EOL> try : cmds . deleteAttr ( taggedBaseMesh , at = attr ) <EOL> except : pass <EOL> cmds . addAttr ( taggedBaseMesh , ln = '<STR_LIT>' , dt = '<STR_LIT:string>' ) <EOL> cmds . setAttr ( '<STR_LIT>' % taggedBaseMesh , model . partialPathName ( ) , type = '<STR_LIT:string>' ) <EOL> dagPath = om . MDagPath ( ) <EOL> sel = om . MSelectionList ( ) <EOL> sel . add ( taggedBaseMesh ) <EOL> sel . getDagPath ( <NUM_LIT:0> , dagPath ) <EOL> dagPath . extendToShape ( ) <EOL> tagMesh ( dagPath ) <EOL> seamlessBaseMesh = cmds . duplicate ( taggedBaseMesh ) [ <NUM_LIT:0> ] <EOL> seamlessBaseMesh = cmds . rename ( seamlessBaseMesh , model . partialPathName ( ) + '<STR_LIT>' ) <EOL> for attr in cmds . listAttr ( seamlessBaseMesh , ud = True ) : <EOL> try : cmds . deleteAttr ( seamlessBaseMesh , at = attr ) <EOL> except : pass <EOL> makeSeamless ( seamlessBaseMesh ) <EOL> cmds . addAttr ( seamlessBaseMesh , ln = '<STR_LIT>' , dt = '<STR_LIT:string>' ) <EOL> cmds . setAttr ( '<STR_LIT>' % seamlessBaseMesh , taggedBaseMesh , type = '<STR_LIT:string>' ) <EOL> cmds . parent ( seamlessBaseMesh , taggedBaseMesh ) <EOL> for blendNode in modelsWithBlendShapeDeformers [ model ] : <EOL> fn = om . MFnDependencyNode ( blendNode ) <EOL> aliases = cmds . aliasAttr ( fn . name ( ) , q = True ) <EOL> for alias in aliases : <EOL> if re . match ( '<STR_LIT>' , alias ) : continue <EOL> cmds . setAttr ( '<STR_LIT>' % ( fn . name ( ) , alias ) , <NUM_LIT:1.0> ) <EOL> taggedTarget = cmds . duplicate ( model . partialPathName ( ) ) [ <NUM_LIT:0> ] <EOL> attrs = cmds . listAttr ( taggedTarget , ud = True ) <EOL> if ( attrs ) : <EOL> for attr in attrs : <EOL> try : cmds . deleteAttr ( taggedTarget , at = attr ) <EOL> except : pass <EOL> taggedTarget = cmds . rename ( taggedTarget , '<STR_LIT>' % ( model . partialPathName ( ) , alias ) ) <EOL> makeSeamless ( taggedTarget ) <EOL> cmds . setAttr ( '<STR_LIT>' % ( fn . name ( ) , alias ) , <NUM_LIT:0.0> ) <EOL> dagPath = om . MDagPath ( ) <EOL> sel = om . MSelectionList ( ) <EOL> sel . add ( taggedTarget ) <EOL> sel . getDagPath ( <NUM_LIT:0> , dagPath ) <EOL> dagPath . extendToShape ( ) <EOL> tagMesh ( dagPath ) <EOL> cmds . addAttr ( taggedTarget , ln = '<STR_LIT>' , dt = '<STR_LIT:string>' ) <EOL> cmds . setAttr ( '<STR_LIT>' % taggedTarget , taggedBaseMesh , type = '<STR_LIT:string>' ) <EOL> cmds . parent ( taggedTarget , taggedBaseMesh ) <EOL> cmds . parent ( taggedBaseMesh , model . partialPathName ( ) ) <EOL> def makeSeamless ( meshName ) : <EOL> """<STR_LIT>""" <EOL> uvs = cmds . polyUVSet ( meshName , q = True , auv = True ) <EOL> for uv in uvs : <EOL> try : cmds . polyUVSet ( meshName , e = True , uvSet = uv , delete = True ) <EOL> except : pass <EOL> uvSet = cmds . polyUVSet ( meshName , q = True , auv = True ) [ <NUM_LIT:0> ] <EOL> sel = om . MSelectionList ( ) <EOL> sel . add ( meshName ) <EOL> dagPath = om . MDagPath ( ) <EOL> sel . getDagPath ( <NUM_LIT:0> , dagPath ) <EOL> fn = om . MFnMesh ( dagPath ) <EOL> fn . clearUVs ( uvSet ) <EOL> cmds . polySoftEdge ( meshName , a = <NUM_LIT> , ch = True ) <EOL> cmds . polyTriangulate ( meshName ) <EOL> cmds . sets ( meshName , e = True , forceElement = '<STR_LIT>' ) <EOL> cmds . delete ( meshName , ch = True ) <EOL> cmds . select ( clear = True ) <EOL> def tagMesh ( meshDagPath ) : <EOL> """<STR_LIT>""" <EOL> try : cmds . polyColorSet ( meshDagPath . partialPathName ( ) , e = True , delete = True , acs = True ) <EOL> except : pass <EOL> meshFn = om . MFnMesh ( meshDagPath ) <EOL> vertexCount = om . MIntArray ( ) <EOL> vertexList = om . MIntArray ( ) <EOL> meshFn . getVertices ( vertexCount , vertexList ) <EOL> vertexColors = om . MColorArray ( meshFn . numVertices ( ) , om . MColor ( <NUM_LIT:0.0> , <NUM_LIT:0.0> , <NUM_LIT:1.0> , <NUM_LIT:1.0> ) ) <EOL> for i in xrange ( meshFn . numVertices ( ) ) : <EOL> col = om . MColor ( tagIndexToColor ( i ) ) <EOL> vertexColors [ i ] . r = col . r <EOL> vertexColors [ i ] . g = col . g <EOL> meshFn . createColorSetWithName ( '<STR_LIT>' ) <EOL> meshFn . setColors ( vertexColors , '<STR_LIT>' ) <EOL> meshFn . assignColors ( vertexList ) <EOL> def tagIndexToColor ( i ) : <EOL> """<STR_LIT>""" <EOL> asHex = hex ( i ) <EOL> digits = asHex [ asHex . find ( '<STR_LIT:x>' ) + <NUM_LIT:1> : : ] [ : : - <NUM_LIT:1> ] <EOL> while len ( digits ) < <NUM_LIT:4> : digits += '<STR_LIT:0>' <EOL> digits = digits [ : : - <NUM_LIT:1> ] <EOL> return om . MColor ( <EOL> int ( '<STR_LIT>' % digits [ <NUM_LIT:2> : <NUM_LIT:4> ] , <NUM_LIT:16> ) * __oneOverTwoFiftyFive , <EOL> int ( '<STR_LIT>' % digits [ <NUM_LIT:0> : <NUM_LIT:2> ] , <NUM_LIT:16> ) * __oneOverTwoFiftyFive , <EOL> <NUM_LIT:1.0> , <EOL> <NUM_LIT:1.0> ) <EOL> def colorToTagIndex ( col ) : <EOL> """<STR_LIT>""" <EOL> r = hex ( int ( round ( col . r * <NUM_LIT> ) ) ) [ : : - <NUM_LIT:1> ] <EOL> while len ( r ) < <NUM_LIT:4> : r += '<STR_LIT:0>' <EOL> r = r [ : : - <NUM_LIT:1> ] <EOL> g = hex ( int ( round ( col . g * <NUM_LIT> ) ) ) [ : : - <NUM_LIT:1> ] <EOL> while len ( g ) < <NUM_LIT:4> : g += '<STR_LIT:0>' <EOL> g = g [ : : - <NUM_LIT:1> ] <EOL> return int ( '<STR_LIT>' % ( g [ g . find ( '<STR_LIT:x>' ) + <NUM_LIT:1> : : ] , r [ r . find ( '<STR_LIT:x>' ) + <NUM_LIT:1> : : ] ) , <NUM_LIT:16> ) </s>
