sels = pymel.core.ls( sl=1 )

for mainCtl in sels:
    
    bb = pymel.core.exactWorldBoundingBox( mainCtl.getShape() )
    
    mainCtlPos = pymel.core.xform( mainCtl, q=1, ws=1, t=1 )
    
    minPoint = [ bb[0], 0, mainCtlPos[2] ]
    centerPoint = mainCtlPos
    maxPoint = [ bb[3], 0, mainCtlPos[2] ]
    
    minCenter, minMiddle, minEnd, minStatic, minMove = getPointers( centerPoint, minPoint )
    maxCenter, maxMiddle, maxEnd, maxStatic, maxMove = getPointers( centerPoint, maxPoint )
    
    sgCmds.addOptionAttribute( mainCtl )
    sgCmds.addAttr( mainCtl, ln='bendMin', k=1 )
    sgCmds.addAttr( mainCtl, ln='bendMax', k=1 )
    sgCmds.addAttr( mainCtl, ln='bendMinRounding', k=1, min=0, max=10, dv=10 )
    sgCmds.addAttr( mainCtl, ln='bendMaxRounding', k=1, min=0, max=10, dv=10 )

    multMax  = pymel.core.createNode( 'multDoubleLinear' )
    multMin  = pymel.core.createNode( 'multDoubleLinear' )
    multMaxRounging  = pymel.core.createNode( 'multDoubleLinear' )
    multMinRounging  = pymel.core.createNode( 'multDoubleLinear' )
    
    mainCtl.attr( 'bendMin' ) >> multMin.input1
    multMin.input2.set( -1 )
    multMin.output >> minCenter.rz
    
    mainCtl.attr( 'bendMax' ) >> multMax.input1
 for assetName in dirs:
     cmds.file( f=1, new=1 )
     
     gpuFile = getFile( root + '/' + assetName, 'gpu' )
     reduceFile = getFile( root + '/' + assetName, 'reduced' )
     origFile = getFile( root + '/' + assetName, 'orig' )
     cmds.file( gpuFile, i=1, type="mayaBinary",  ignoreVersion=1, ra=1, mergeNamespacesOnClash=1, namespace=":", options="v=0;",  pr=1 )
     cmds.file( reduceFile, i=1, type="mayaBinary",  ignoreVersion=1, ra=1, mergeNamespacesOnClash=1, namespace=":", options="v=0;",  pr=1 )
     cmds.file( origFile, i=1, type="mayaBinary",  ignoreVersion=1, ra=1, mergeNamespacesOnClash=1, namespace=":", options="v=0;",  pr=1 )
     
     gpuObj = getObject( 'gpu' )
     reduceObj = getObject( 'reduced' )
     origObj = getObject( 'orig' )
     set = pymel.core.group( gpuObj, reduceObj, origObj, n='SET' )
     
     sgCmds.addOptionAttribute(set)
     set.addAttr( "type", at="enum", en="hidden:gpu:reduce:orig:", k=1, dv=1 )
     
     conditionGpu = pymel.core.createNode( 'condition' )
     conditionReduce = pymel.core.createNode( 'condition' )
     conditionOrig = pymel.core.createNode( 'condition' )
     
     set.attr( "type" ) >> conditionGpu.firstTerm
     set.attr( "type" ) >> conditionReduce.firstTerm
     set.attr( "type" ) >> conditionOrig.firstTerm
     
     conditionGpu.secondTerm.set( 1 )
     conditionReduce.secondTerm.set( 2 )
     conditionOrig.secondTerm.set( 3 )
     
     conditionGpu.ctr.set( 1 )
        cmds.file(origFile,
                  i=1,
                  type="mayaBinary",
                  ignoreVersion=1,
                  ra=1,
                  mergeNamespacesOnClash=1,
                  namespace=":",
                  options="v=0;",
                  pr=1)

        gpuObj = getObject('gpu')
        reduceObj = getObject('reduced')
        origObj = getObject('orig')
        set = pymel.core.group(gpuObj, reduceObj, origObj, n='SET')

        sgCmds.addOptionAttribute(set)
        set.addAttr("type", at="enum", en="hidden:gpu:reduce:orig:", k=1, dv=1)

        conditionGpu = pymel.core.createNode('condition')
        conditionReduce = pymel.core.createNode('condition')
        conditionOrig = pymel.core.createNode('condition')

        set.attr("type") >> conditionGpu.firstTerm
        set.attr("type") >> conditionReduce.firstTerm
        set.attr("type") >> conditionOrig.firstTerm

        conditionGpu.secondTerm.set(1)
        conditionReduce.secondTerm.set(2)
        conditionOrig.secondTerm.set(3)

        conditionGpu.ctr.set(1)
for i in range( 2 ):
    bendCtl = sgCmds.makeController( sgModel.Controller.switchPoints, 1, makeParent=1, name= ctl.replace( 'Part', 'Bend%d' % i ) )
    pBendCtl = bendCtl.getParent()
    
    bendCtl.getShape().shape_ty.set( 0.5 )
    bendCtl.getShape().shape_rx.set( 90 )
    
    pBendCtl.setParent( ctl )
    sgCmds.setTransformDefault( pBendCtl )
    pBendCtl.r.set( 0, 90*i, 0 )
    bend1, handle1 = pymel.core.nonLinear( geo, type='bend' )
    handle1.setParent( bendCtl )
    sgCmds.setTransformDefault( handle1 )
    handle1.r.set( 0,0,90 )
    bend1.lowBound.set( 0 )
    sgCmds.addOptionAttribute( bendCtl )
    sgCmds.addAttr( bendCtl, ln='bend', k=1 )
    multNode = pymel.core.createNode( 'multDoubleLinear' )
    bendCtl.bend >> multNode.input1
    multNode.input2.set( 5 )
    multNode.output >> bend1.curvature
    handle1.v.set( 0 )
    
    sgCmds.addAttr( bendCtl, ln='lowBound', k=1, min=0, dv=1 )
    sgCmds.addAttr( bendCtl, ln='highBound', k=1, min=0, dv=1 )
    multLow = pymel.core.createNode( 'multDoubleLinear' )
    bendCtl.lowBound >> multLow.input1
    multLow.input2.set( -1 )
    multLow.output >> bend1.lowBound
    bendCtl.highBound >> bend1.highBound
import pymel.core
from sgMaya import sgCmds

eyeCtl = pymel.core.ls( 'EyeBDCtrl' )[0]

sgCmds.addOptionAttribute( eyeCtl )
sgCmds.addAttr( eyeCtl, ln='specMode', at='enum', en=':default:twinkle', k=1 )
sgCmds.addAttr( eyeCtl, ln='twinkleIndex', at='long', k=1 )

twinkleShader = pymel.core.ls( sl=1 )[0]

texturePath = os.path.dirname( cmds.file( q=1, sceneName=1 ) ) + '/texture'
twinklePath = texturePath + '/TwinkleEye.0001.png'
twinkleSmallPath = texturePath + '/TwinkleEye_small.0001.png'

newShaders = []
def convertTwincleTexture( twinkleShader ):
    files = twinkleShader.listConnections( s=1, d=0, type='file' )
    if not files: return None
    targetFile = files[0]
    
    fileConnections = targetFile.listConnections( s=0, d=1, p=1, c=1 )
    
    lambertShaderCon = None
    rsShaderCon = None
    for origCon, dstCon in fileConnections:
        if origCon.longName() == 'outColor':
            lambertShaderCon = dstCon
        elif origCon.longName() == 'outAlpha':
            rsShaderCon = dstCon
    
示例#6
0
文件: sw3.py 项目: jonntd/mayadev-1
def createGrassController( meshs, ground ):
    
    import pymel.core
    from sgMaya import sgCmds, sgModel
    reload( sgCmds )
    from maya import mel, cmds, OpenMaya
    
    curves = []
    ctlsList = []
    
    bbys = []
    for mesh in meshs:
        bb = pymel.core.exactWorldBoundingBox( mesh )
        bbys.append( bb[4] )
    meshMaxY = max( bbys )
    
    coreGrp = pymel.core.createNode( 'transform', n='grassRigCoreGrp' )
    pivCtls = []
    for mesh in meshs:
        pymel.core.select( mesh + '.e[15]' )
        mel.eval( 'SelectEdgeLoopSp;' )
        targetCurve = pymel.core.ls( mel.eval( 'polyToCurve -form 2 -degree 3;' )[0] )[0]
        curveCuted = sgCmds.cutCurve( targetCurve, ground )
        
        curveBB = pymel.core.exactWorldBoundingBox( curveCuted )
        curvePos = [ ( curveBB[0] + curveBB[3] )/2 , 0, ( curveBB[2] + curveBB[5] )/2 ]
        curveScaleY = meshMaxY/curveBB[4]
        curveP = pymel.core.createNode( 'transform' )
        curveP.t.set( curvePos )
        curveCuted.setParent( curveP )
        curveP.sy.set( curveScaleY )
        curveCuted.setParent( w=1 )
        pymel.core.makeIdentity( curveCuted, apply=1, t=1, r=1, s=1, n=0, pn=1 )
        pymel.core.delete( targetCurve, curveP )
        
        mel.eval( 'rebuildCurve -ch 1 -rpo 1 -rt 0 -end 1 -kr 0 -kcp 0 -kep 1 -kt 0 -s 7 -d 3 -tol 0.01 "%s";' % curveCuted.name() )
        wire = pymel.core.ls( mel.eval( 'wire -gw false -en 1.000000 -ce 0.000000 -li 0.000000 -w %s %s;' % ( curveCuted.name(), mesh ) )[0] )[0]
        pymel.core.setAttr( wire + '.dropoffDistance[0]', 10000 )
        curves = wire.listConnections( s=1, d=0, type='nurbsCurve' )
        
        ctls = sgCmds.createControllerByCurveCVs( curveCuted )
        
        curves.append( curveCuted )
        ctlsList.append( ctls )
        
        firstCtl = ctls[0]
        pFirstCtl = firstCtl.getParent()
        pivCtl = pymel.core.createNode( 'transform', n='Piv_' + firstCtl.nodeName() )
        pivCtl.t.set( pymel.core.xform( pFirstCtl, q=1, ws=1, t=1 ) )
        pFirstCtl.setParent( pivCtl )
        pivCtl.v.set( 0 )
        pivCtls.append( pivCtl )
        pymel.core.parent( curves, pivCtl, coreGrp )
        for curve in curves:
            curve.v.set( 0 )
    
    bbAllCtls = OpenMaya.MBoundingBox()
    for pivCtl in pivCtls:
        bbAllCtls.expand( OpenMaya.MPoint( *pymel.core.xform( pivCtl, q=1, ws=1, t=1 ) ) )
    duCurvePivPoint = bbAllCtls.center()
    duCurvePivPoint = [ duCurvePivPoint.x, duCurvePivPoint.y, duCurvePivPoint.z ]
    duCurveEndPoint = [ duCurvePivPoint[0], meshMaxY, duCurvePivPoint[2] ]
    
    duCurve = pymel.core.curve( p=[ duCurvePivPoint, duCurveEndPoint ], d=1 )
    duCurve.v.set( 0 )
    mel.eval( 'rebuildCurve -ch 1 -rpo 1 -rt 0 -end 1 -kr 0 -kcp 0 -kep 1 -kt 0 -s 7 -d 3 -tol 0.01 "%s";' % duCurve.name() )
    
    duCtls = sgCmds.createControllerByCurveCVs( duCurve )
    pivCtl = pymel.core.createNode( 'transform', n='Piv_' + duCtls[0].nodeName() )
    pivCtlPos = pymel.core.xform( duCtls[0], q=1, ws=1, t=1 )
    pivCtl.t.set( pivCtlPos )
    duCtls[0].getParent().setParent( pivCtl )
    sgCmds.makeParent( pivCtl )
    
    pivCtlMaxY = pymel.core.exactWorldBoundingBox( pivCtl )[4]
    lookAtCtl = sgCmds.makeController( sgModel.Controller.conePoints, makeParent=1, n='Ctl_LookAt_%s' % duCurve.nodeName() )
    lookAtCtl.getParent().t.set( pivCtlPos[0], pivCtlMaxY, pivCtlPos[2] )
    sgCmds.lookAtConnect( lookAtCtl, pivCtl )
    
    composeMatrix = pymel.core.createNode( 'composeMatrix' )
    wtAddMtx = pymel.core.createNode( 'wtAddMatrix' )
    composeMatrix.outputMatrix >> wtAddMtx.i[0].m
    wtAddMtx.i[0].w.set( 0.5 )
    lookAtCtl.matrix >> wtAddMtx.i[1].m
    wtAddMtx.i[1].w.set( 0.5)
    dcmpWtAdd = sgCmds.getDecomposeMatrix( wtAddMtx.matrixSum )
    
    for i in range( len( duCtls ) ):
        sgCmds.makeParent( duCtls[i].getParent(), n= 'Piv_' + duCtls[i].nodeName() )
        dcmpWtAdd.outputRotate >> duCtls[i].getParent().r
    
    for i in range( len( duCtls ) ):
        dcmp = sgCmds.getLocalDecomposeMatrix( duCtls[i].wm, duCtls[i].getParent().pim )
        for j in range( len( ctlsList ) ):
            dcmp.outputTranslate >> ctlsList[j][i].t
            dcmp.outputRotate >> ctlsList[j][i].r
            dcmp.outputScale >> ctlsList[j][i].s
    
    for eachPiv in pivCtls:
        pivCtl.r >> eachPiv.r
    
    sgCmds.addOptionAttribute( lookAtCtl )
    sgCmds.addAttr( lookAtCtl, ln='showDetail', k=1, min=0, max=1 )
    lookAtCtl.attr( 'showDetail' ) >> pivCtl.v
    
    pymel.core.parent( coreGrp )
    coreGrp.attr( 'inheritsTransform' ).set( 0 )
    coreGrp.t.set( lock=1 )
    coreGrp.r.set( lock=1 )
    coreGrp.s.set( lock=1 )
    
    mainGrp = pymel.core.createNode( 'transform', n='grassRigMainGrp' )
    jnt = pymel.core.joint()
    pymel.core.move( mainGrp, duCurvePivPoint[0], duCurvePivPoint[1], duCurvePivPoint[2], ws=1 )
    pymel.core.parent( duCurve, coreGrp, pivCtl.getParent(), lookAtCtl.getParent(), mainGrp )
    pymel.core.skinCluster( meshs, jnt )
    
    for duCtl in duCtls:
        sgCmds.setIndexColor( duCtl, 28 )

    sgCmds.setIndexColor( lookAtCtl, 22 )
    pymel.core.select( lookAtCtl )
    
    
    
示例#7
0
import pymel.core
from sgMaya import sgCmds

sels = pymel.core.ls(sl=1)
ctls = sels[:-1]
fbxRig = sels[-1]
ns = ''
if fbxRig.find(':') != -1:
    ns = ':'.join(fbxRig.split(':')[:-1])
fbxAttName = ns + ':FBXATT'

for ctl in ctls:
    if not pymel.core.objExists(fbxAttName):
        fbxAtt = pymel.core.createNode('transform', n=fbxAttName)
        fbxAtt.setParent(fbxRig)
    keyAttrs = fbxAtt.listAttr(k=1)
    for attr in keyAttrs:
        attr.setKeyable(False)
    else:
        fbxAtt = pymel.core.ls(fbxAttName)[0]

    attrs = ctl.listAttr(ud=1, k=1)
    sgCmds.addOptionAttribute(fbxAtt,
                              ctl.name().replace('FacialTitle', 'FacialCtl'))
    for attr in attrs:
        if attr.isLocked(): continue
        attrInfo = sgCmds.getAttrInfo(attr)
        sgCmds.createAttrByAttrInfo(attrInfo, fbxAtt)
        attr >> fbxAtt.attr(attr.attrName())
for sel in sels:
    
    poleVConst = sel.t.listConnections( s=0, d=1, type='poleVectorConstraint' )[0]
    
    ikHandle = poleVConst.constraintTranslateX.listConnections( s=0, d=1, type='ikHandle' )[0]
    
    endEffector = ikHandle.endEffector.listConnections( s=1, d=0 )[0]
    
    endJnt = endEffector.tx.listConnections( s=1, d=0 )[0]
    middleJnt = endEffector.getParent()
    
    mdMiddle = middleJnt.tx.listConnections( s=1, d=0 )[0]
    mdEnd    = endJnt.tx.listConnections( s=1, d=0 )[0]
    
    sgCmds.addOptionAttribute( sel, 'IK Length' )
    sgCmds.addAttr( sel, ln='ikUpperLength', k=1 )
    sgCmds.addAttr( sel, ln='ikLowerLength', k=1 )
    
    powMiddle = pymel.core.createNode( 'multiplyDivide' )
    powMiddle.input1X.set( 2 ); powMiddle.op.set( 3 )
    powEnd = pymel.core.createNode( 'multiplyDivide' )
    powEnd.input1X.set( 2 ); powEnd.op.set( 3 )
    sel.attr( 'ikUpperLength' ) >> powMiddle.input2X
    sel.attr( 'ikLowerLength' ) >> powEnd.input2X
    
    origDistMiddle = mdMiddle.input2Y.get()
    origDistEnd    = mdEnd.input2Y.get()
    
    multMid = pymel.core.createNode( 'multDoubleLinear' )
    multEnd = pymel.core.createNode( 'multDoubleLinear' )
from sgMaya import sgCmds
import pymel.core
sels = pymel.core.ls( sl=1 )

ctl = sels[0]
mod = sels[1]

sgCmds.addOptionAttribute( ctl )
sgCmds.addAttr( ctl, ln='modVis', k=1, min=0, max=1, dv=1, at='long' )
ctl.attr( 'modVis' ) >> mod.v
from sgMaya import sgCmds
import pymel.core
sels = pymel.core.ls(sl=1)
sgCmds.addOptionAttribute(sels[0], 'options')
sgCmds.addAttr(sels[0], ln='hide', min=0, max=1, k=1, at='long')
revNode = pymel.core.createNode('reverse')
sels[0].attr('hide') >> revNode.inputX
revNode.outputX >> sels[1].v
示例#11
0
                                    1,
                                    makeParent=1,
                                    name=ctl.replace('Part', 'Bend%d' % i))
    pBendCtl = bendCtl.getParent()

    bendCtl.getShape().shape_ty.set(0.5)
    bendCtl.getShape().shape_rx.set(90)

    pBendCtl.setParent(ctl)
    sgCmds.setTransformDefault(pBendCtl)
    pBendCtl.r.set(0, 90 * i, 0)
    bend1, handle1 = pymel.core.nonLinear(geo, type='bend')
    handle1.setParent(bendCtl)
    sgCmds.setTransformDefault(handle1)
    handle1.r.set(0, 0, 90)
    bend1.lowBound.set(0)
    sgCmds.addOptionAttribute(bendCtl)
    sgCmds.addAttr(bendCtl, ln='bend', k=1)
    multNode = pymel.core.createNode('multDoubleLinear')
    bendCtl.bend >> multNode.input1
    multNode.input2.set(5)
    multNode.output >> bend1.curvature
    handle1.v.set(0)

    sgCmds.addAttr(bendCtl, ln='lowBound', k=1, min=0, dv=1)
    sgCmds.addAttr(bendCtl, ln='highBound', k=1, min=0, dv=1)
    multLow = pymel.core.createNode('multDoubleLinear')
    bendCtl.lowBound >> multLow.input1
    multLow.input2.set(-1)
    multLow.output >> bend1.lowBound
    bendCtl.highBound >> bend1.highBound
import pymel.core
from sgMaya import sgCmds
sels = pymel.core.ls( sl=1 )
ctls = sels[:-1]
fbxRig = sels[-1]
ns = ''
if fbxRig.find( ':' ) != -1:
    ns = ':'.join( fbxRig.split( ':' )[:-1] )
fbxAttName = ns + ':FBXATT'

for ctl in ctls:
    if not pymel.core.objExists( fbxAttName ):
        fbxAtt = pymel.core.createNode( 'transform', n=fbxAttName )    
        fbxAtt.setParent( fbxRig )
    keyAttrs = fbxAtt.listAttr( k=1 )
    for attr in keyAttrs:
        attr.setKeyable( False )
    else:
        fbxAtt = pymel.core.ls( fbxAttName )[0]
    
    attrs = ctl.listAttr( ud=1, k=1 )
    sgCmds.addOptionAttribute( fbxAtt, ctl.name().replace( 'FacialTitle', 'FacialCtl' ) )
    for attr in attrs:
        if attr.isLocked(): continue
        attrInfo = sgCmds.getAttrInfo( attr )
        sgCmds.createAttrByAttrInfo( attrInfo, fbxAtt )
        attr >> fbxAtt.attr( attr.attrName() )
示例#13
0
def createGrassController(meshs, ground):

    import pymel.core
    from sgMaya import sgCmds, sgModel
    reload(sgCmds)
    from maya import mel, cmds, OpenMaya

    curves = []
    ctlsList = []

    bbys = []
    for mesh in meshs:
        bb = pymel.core.exactWorldBoundingBox(mesh)
        bbys.append(bb[4])
    meshMaxY = max(bbys)

    coreGrp = pymel.core.createNode('transform', n='grassRigCoreGrp')
    pivCtls = []
    for mesh in meshs:
        pymel.core.select(mesh + '.e[15]')
        mel.eval('SelectEdgeLoopSp;')
        targetCurve = pymel.core.ls(
            mel.eval('polyToCurve -form 2 -degree 3;')[0])[0]
        curveCuted = sgCmds.cutCurve(targetCurve, ground)

        curveBB = pymel.core.exactWorldBoundingBox(curveCuted)
        curvePos = [(curveBB[0] + curveBB[3]) / 2, 0,
                    (curveBB[2] + curveBB[5]) / 2]
        curveScaleY = meshMaxY / curveBB[4]
        curveP = pymel.core.createNode('transform')
        curveP.t.set(curvePos)
        curveCuted.setParent(curveP)
        curveP.sy.set(curveScaleY)
        curveCuted.setParent(w=1)
        pymel.core.makeIdentity(curveCuted, apply=1, t=1, r=1, s=1, n=0, pn=1)
        pymel.core.delete(targetCurve, curveP)

        mel.eval(
            'rebuildCurve -ch 1 -rpo 1 -rt 0 -end 1 -kr 0 -kcp 0 -kep 1 -kt 0 -s 7 -d 3 -tol 0.01 "%s";'
            % curveCuted.name())
        wire = pymel.core.ls(
            mel.eval(
                'wire -gw false -en 1.000000 -ce 0.000000 -li 0.000000 -w %s %s;'
                % (curveCuted.name(), mesh))[0])[0]
        pymel.core.setAttr(wire + '.dropoffDistance[0]', 10000)
        curves = wire.listConnections(s=1, d=0, type='nurbsCurve')

        ctls = sgCmds.createControllerByCurveCVs(curveCuted)

        curves.append(curveCuted)
        ctlsList.append(ctls)

        firstCtl = ctls[0]
        pFirstCtl = firstCtl.getParent()
        pivCtl = pymel.core.createNode('transform',
                                       n='Piv_' + firstCtl.nodeName())
        pivCtl.t.set(pymel.core.xform(pFirstCtl, q=1, ws=1, t=1))
        pFirstCtl.setParent(pivCtl)
        pivCtl.v.set(0)
        pivCtls.append(pivCtl)
        pymel.core.parent(curves, pivCtl, coreGrp)
        for curve in curves:
            curve.v.set(0)

    bbAllCtls = OpenMaya.MBoundingBox()
    for pivCtl in pivCtls:
        bbAllCtls.expand(
            OpenMaya.MPoint(*pymel.core.xform(pivCtl, q=1, ws=1, t=1)))
    duCurvePivPoint = bbAllCtls.center()
    duCurvePivPoint = [duCurvePivPoint.x, duCurvePivPoint.y, duCurvePivPoint.z]
    duCurveEndPoint = [duCurvePivPoint[0], meshMaxY, duCurvePivPoint[2]]

    duCurve = pymel.core.curve(p=[duCurvePivPoint, duCurveEndPoint], d=1)
    duCurve.v.set(0)
    mel.eval(
        'rebuildCurve -ch 1 -rpo 1 -rt 0 -end 1 -kr 0 -kcp 0 -kep 1 -kt 0 -s 7 -d 3 -tol 0.01 "%s";'
        % duCurve.name())

    duCtls = sgCmds.createControllerByCurveCVs(duCurve)
    pivCtl = pymel.core.createNode('transform',
                                   n='Piv_' + duCtls[0].nodeName())
    pivCtlPos = pymel.core.xform(duCtls[0], q=1, ws=1, t=1)
    pivCtl.t.set(pivCtlPos)
    duCtls[0].getParent().setParent(pivCtl)
    sgCmds.makeParent(pivCtl)

    pivCtlMaxY = pymel.core.exactWorldBoundingBox(pivCtl)[4]
    lookAtCtl = sgCmds.makeController(sgModel.Controller.conePoints,
                                      makeParent=1,
                                      n='Ctl_LookAt_%s' % duCurve.nodeName())
    lookAtCtl.getParent().t.set(pivCtlPos[0], pivCtlMaxY, pivCtlPos[2])
    sgCmds.lookAtConnect(lookAtCtl, pivCtl)

    composeMatrix = pymel.core.createNode('composeMatrix')
    wtAddMtx = pymel.core.createNode('wtAddMatrix')
    composeMatrix.outputMatrix >> wtAddMtx.i[0].m
    wtAddMtx.i[0].w.set(0.5)
    lookAtCtl.matrix >> wtAddMtx.i[1].m
    wtAddMtx.i[1].w.set(0.5)
    dcmpWtAdd = sgCmds.getDecomposeMatrix(wtAddMtx.matrixSum)

    for i in range(len(duCtls)):
        sgCmds.makeParent(duCtls[i].getParent(),
                          n='Piv_' + duCtls[i].nodeName())
        dcmpWtAdd.outputRotate >> duCtls[i].getParent().r

    for i in range(len(duCtls)):
        dcmp = sgCmds.getLocalDecomposeMatrix(duCtls[i].wm,
                                              duCtls[i].getParent().pim)
        for j in range(len(ctlsList)):
            dcmp.outputTranslate >> ctlsList[j][i].t
            dcmp.outputRotate >> ctlsList[j][i].r
            dcmp.outputScale >> ctlsList[j][i].s

    for eachPiv in pivCtls:
        pivCtl.r >> eachPiv.r

    sgCmds.addOptionAttribute(lookAtCtl)
    sgCmds.addAttr(lookAtCtl, ln='showDetail', k=1, min=0, max=1)
    lookAtCtl.attr('showDetail') >> pivCtl.v

    pymel.core.parent(coreGrp)
    coreGrp.attr('inheritsTransform').set(0)
    coreGrp.t.set(lock=1)
    coreGrp.r.set(lock=1)
    coreGrp.s.set(lock=1)

    mainGrp = pymel.core.createNode('transform', n='grassRigMainGrp')
    jnt = pymel.core.joint()
    pymel.core.move(mainGrp,
                    duCurvePivPoint[0],
                    duCurvePivPoint[1],
                    duCurvePivPoint[2],
                    ws=1)
    pymel.core.parent(duCurve, coreGrp, pivCtl.getParent(),
                      lookAtCtl.getParent(), mainGrp)
    pymel.core.skinCluster(meshs, jnt)

    for duCtl in duCtls:
        sgCmds.setIndexColor(duCtl, 28)

    sgCmds.setIndexColor(lookAtCtl, 22)
    pymel.core.select(lookAtCtl)
示例#14
0
    poleVConst = sel.t.listConnections(s=0, d=1,
                                       type='poleVectorConstraint')[0]

    ikHandle = poleVConst.constraintTranslateX.listConnections(
        s=0, d=1, type='ikHandle')[0]

    endEffector = ikHandle.endEffector.listConnections(s=1, d=0)[0]

    endJnt = endEffector.tx.listConnections(s=1, d=0)[0]
    middleJnt = endEffector.getParent()

    mdMiddle = middleJnt.tx.listConnections(s=1, d=0)[0]
    mdEnd = endJnt.tx.listConnections(s=1, d=0)[0]

    sgCmds.addOptionAttribute(sel, 'IK Length')
    sgCmds.addAttr(sel, ln='ikUpperLength', k=1)
    sgCmds.addAttr(sel, ln='ikLowerLength', k=1)

    powMiddle = pymel.core.createNode('multiplyDivide')
    powMiddle.input1X.set(2)
    powMiddle.op.set(3)
    powEnd = pymel.core.createNode('multiplyDivide')
    powEnd.input1X.set(2)
    powEnd.op.set(3)
    sel.attr('ikUpperLength') >> powMiddle.input2X
    sel.attr('ikLowerLength') >> powEnd.input2X

    origDistMiddle = mdMiddle.input2Y.get()
    origDistEnd = mdEnd.input2Y.get()
import pymel.core
from sgMaya import sgCmds

eyeCtl = pymel.core.ls('EyeBDCtrl')[0]

sgCmds.addOptionAttribute(eyeCtl)
sgCmds.addAttr(eyeCtl, ln='specMode', at='enum', en=':default:twinkle', k=1)
sgCmds.addAttr(eyeCtl, ln='twinkleIndex', at='long', k=1)

twinkleShader = pymel.core.ls(sl=1)[0]

texturePath = os.path.dirname(cmds.file(q=1, sceneName=1)) + '/texture'
twinklePath = texturePath + '/TwinkleEye.0001.png'
twinkleSmallPath = texturePath + '/TwinkleEye_small.0001.png'

newShaders = []


def convertTwincleTexture(twinkleShader):
    files = twinkleShader.listConnections(s=1, d=0, type='file')
    if not files: return None
    targetFile = files[0]

    fileConnections = targetFile.listConnections(s=0, d=1, p=1, c=1)

    lambertShaderCon = None
    rsShaderCon = None
    for origCon, dstCon in fileConnections:
        if origCon.longName() == 'outColor':
            lambertShaderCon = dstCon
        elif origCon.longName() == 'outAlpha':
from sgMaya import sgCmds
import pymel.core
sels = pymel.core.ls( sl=1 )
sgCmds.addOptionAttribute( sels[0], 'options' )
sgCmds.addAttr( sels[0], ln='hide', min=0, max=1, k=1, at='long' )
revNode = pymel.core.createNode( 'reverse' )
sels[0].attr( 'hide' ) >> revNode.inputX
revNode.outputX >> sels[1].v
    base = pFirstCtl.getParent()
    pMainCtl.setParent(base)

    lookAtBase = pymel.core.createNode('transform', n='lookAtBase_' + firstCtl)
    pymel.core.xform(lookAtBase, ws=1, matrix=firstCtl.wm.get())
    lookAtChild = sgCmds.makeLookAtChild(mainCtl, lookAtBase)
    lookAtChild.rename('lookAtChild_' + firstCtl)

    lookAtBase.setParent(base)
    pFirstCtl.setParent(lookAtChild)

    joints = sgCmds.createFkControlJoint(pFirstCtl)
    joints[0].v.set(0)

    mainCtlFriend = pymel.core.createNode('transform')
    pMainCtl = mainCtl.getParent()
    mainCtlFriend.setParent(pMainCtl)

    sgCmds.setTransformDefault(mainCtlFriend)

    blendNode = sgCmds.createBlendTwoMatrixNode(mainCtlFriend,
                                                mainCtl,
                                                local=1)
    dcmp = sgCmds.getDecomposeMatrix(blendNode.matrixSum)

    for joint in joints[1:]:
        dcmp.outputRotate >> joint.r

    sgCmds.addOptionAttribute(mainCtl)
    sgCmds.addAttr(mainCtl, ln='showDetail', min=0, max=1, at='long', cb=1)
    mainCtl.attr('showDetail') >> pFirstCtl.v