示例#1
0
def treeBendingLookAtConnect( inputLookTarget, inputRotTarget ):
    
    lookTarget = pymel.core.ls( inputLookTarget )[0]
    rotTarget  = pymel.core.ls( inputRotTarget )[0]
    
    rotTargetBase = rotTarget.getParent()
    rotTargetList = rotTarget.listRelatives( c=1, ad=1, type='joint' )
    map( lambda x : sgCmds.makeParent( x ) if x.getParent().nodeType() == 'joint' else None, rotTargetList )
    rotTargetPoints = map( lambda x : sgCmds.putObject( x ), rotTargetList )
    map( lambda x : x.dh.set( 0 ), rotTargetPoints )
    rotTargetPointsBase = sgCmds.makeChild( rotTargetBase )
    rotTargetList.append( rotTarget )
    
    sgCmds.lookAtConnect( lookTarget, rotTargetPointsBase )
    sgCmds.makeParent( rotTargetPointsBase )
    pymel.core.parent( rotTargetPoints, rotTargetPointsBase )
    
    rotTargetList.reverse()
    rotTargetPoints.reverse()
    
    numRotTargets = len( rotTargetList )
    sgCmds.addAttr( lookTarget, ln='bendWeight', min=0, max=1, dv=1, k=1 )
    sgCmds.addAttr( lookTarget, ln='powRate', min=0, max=2, dv=1, k=1 )
    
    for i in range( len( rotTargetList )-1 ):
        powRateBaseValue = ( i + 1.0 )/numRotTargets
        rotTargetH = rotTargetList[i]
        rotTargetHBase = rotTargetH.getParent()
        rotTargetChild = rotTargetH.listRelatives( c=1 )[0]
        aimCuPointPiv = sgCmds.makeChild( rotTargetHBase )
        aimCuPointBase = sgCmds.makeChild( aimCuPointPiv )
        aimCuPoint = sgCmds.makeChild( aimCuPointBase )
        pymel.core.xform( aimCuPointPiv, ws=1, matrix=rotTargetH.wm.get() )
        pymel.core.xform( aimCuPointBase, ws=1, matrix=rotTargetChild.wm.get() )
        
        rotTargetPoint = rotTargetPoints[i]
        dcmp = sgCmds.getLocalDecomposeMatrix( rotTargetPoint.wm, aimCuPointBase.wim )
        sgCmds.addAttr( rotTargetH, ln='lookWeight', min=0, max=1, k=1, dv= 1.0/numRotTargets )
        
        multEnv = pymel.core.createNode( 'multDoubleLinear' )
        multPow = pymel.core.createNode( 'multiplyDivide' ); multPow.op.set( 3 )
        multPowAndEnv = pymel.core.createNode( 'multDoubleLinear' )
        multEnv.output >> multPowAndEnv.input1
        multPow.outputX >> multPowAndEnv.input2
        multPow.input1X.set( powRateBaseValue )
        lookTarget.powRate >> multPow.input2X
        
        rotTargetH.lookWeight >> multEnv.input1
        lookTarget.bendWeight >> multEnv.input2
        
        multTrans = pymel.core.createNode( 'multiplyDivide' )
        dcmp.outputTranslate >> multTrans.input1
        multPowAndEnv.output >> multTrans.input2X
        multPowAndEnv.output >> multTrans.input2Y
        multPowAndEnv.output >> multTrans.input2Z
        multTrans.output >> aimCuPoint.t
        sgCmds.lookAtConnect( aimCuPoint, rotTargetH )
    
    sgCmds.addAttr( lookTarget, ln='rotTarget', at='message' )
    rotTargetPointsBase.message >> lookTarget.rotTarget
示例#2
0
 def getPointOneTwo( pointerCtl1, pointerCtl2, baseCtl ):
     
     point1Dcmp = sgCmds.getLocalDecomposeMatrix( pointerCtl1.wm, baseCtl.wim )
     point2Dcmp = sgCmds.getLocalDecomposeMatrix( pointerCtl2.wm, baseCtl.wim )
     
     point1 = sgCmds.makeChild( baseCtl, n='pointer1_' + baseCtl )
     point2 = sgCmds.makeChild( baseCtl, n='pointer2_' + baseCtl )
     
     point1Dcmp.otx >> point1.tx
     point2Dcmp.otx >> point2.tx
     
     sgCmds.convertMultDoubleConnection( point1.tx ).set( 0.5 )
     sgCmds.convertMultDoubleConnection( point2.tx ).set( 0.5 )
     
     point1.dh.set( 1 )
     point2.dh.set( 1 )
     
     return point1, point2
示例#3
0
        def getPointOneTwo(pointerCtl1, pointerCtl2, baseCtl):

            point1Dcmp = sgCmds.getLocalDecomposeMatrix(
                pointerCtl1.wm, baseCtl.wim)
            point2Dcmp = sgCmds.getLocalDecomposeMatrix(
                pointerCtl2.wm, baseCtl.wim)

            point1 = sgCmds.makeChild(baseCtl, n='pointer1_' + baseCtl)
            point2 = sgCmds.makeChild(baseCtl, n='pointer2_' + baseCtl)

            point1Dcmp.otx >> point1.tx
            point2Dcmp.otx >> point2.tx

            sgCmds.convertMultDoubleConnection(point1.tx).set(0.5)
            sgCmds.convertMultDoubleConnection(point2.tx).set(0.5)

            point1.dh.set(1)
            point2.dh.set(1)

            return point1, point2
示例#4
0
def buildArcControl( numJointUpper, numJointLower, typ='arm' ):
    
    armTops = []
    armMiddles = []
    armEnds = []
    fkIkCtls = []
    
    for side in ['_L_', '_R_' ]:
        armTops    += pymel.core.ls( 'jnt%s%s0' % ( side, typ ) )
        armMiddles += pymel.core.ls( 'jnt%s%s1' % ( side, typ ) )
        armEnds    += pymel.core.ls( 'jnt%s%s1_end' % ( side, typ ) )
        fkIkCtls += pymel.core.ls( 'anim%s%s_IKFK' % ( side, typ ) )

    if not armTops:
        for side in ['_L_', '_R_' ]:
            armTops    += pymel.core.ls( '%s01%sJNT' % ( typ.capitalize(), side ) )
            armMiddles += pymel.core.ls( '%s02%sJNT' % ( typ.capitalize(), side ) )
            armEnds    += pymel.core.ls( '%s03%sJNT' % ( typ.capitalize(), side ) )
            fkIkCtls += pymel.core.ls( '%s%sIKFKSwitch' % ( typ.capitalize(), side ) )

    for sideIndex in range( 2 ):
        coreGrp = pymel.core.createNode( 'transform', n='%sInterporationCoreGrp%s' % ( typ.capitalize(), ['_L_','_R_'][sideIndex] ) )
        pymel.core.xform( coreGrp, ws=1, matrix=pymel.core.xform( armTops[sideIndex], q=1, ws=1, matrix=1 ) )
        
        armTop = armTops[sideIndex]
        armMiddle = armMiddles[sideIndex]
        armEnd = armEnds[sideIndex]
        
        armUpper = sgCmds.addMiddleTranslateJoint( armMiddle, n='MiddleJnt_' + armMiddle )
        armRotMiddle = sgCmds.addMiddleJoint( armMiddle, n='MiddleRotJnt_' + armMiddle )
        armLower = sgCmds.addMiddleTranslateJoint( armEnd, n='MiddleJnt_' + armEnd )
        
        targets = [ armTop, armMiddle, armEnd ]
        circleSubCtls = []
        for i in range( len( targets ) ):
            circleSubCtl = pymel.core.circle( normal=[1,0,0], n=targets[i].replace( 'jnt_', 'sub_Ctl_' ), radius=0.1 )[0]
            circleSubCtlGrp = pymel.core.group( circleSubCtl, n='P' + circleSubCtl )
            pymel.core.parent( circleSubCtlGrp, coreGrp )
            pymel.core.xform( circleSubCtlGrp, ws=1, matrix=targets[i].wm.get() )
            circleSubCtls.append( circleSubCtl )
        
        firstSubCtl  = circleSubCtls[0]
        secondSubCtl = circleSubCtls[1]
        thirdSubCtl  = circleSubCtls[2]
        
        upperSubCtl = pymel.core.circle( normal=[1,0,0], n=secondSubCtl + '_upper', radius=0.1 )[0]
        upperSubCtlOffset = pymel.core.group( upperSubCtl, n='Offset' + upperSubCtl )
        upperSubCtlGrp = pymel.core.group( upperSubCtlOffset, n='P' + upperSubCtl )
        lowerSubCtl = pymel.core.circle( normal=[1,0,0], n=secondSubCtl + '_lower', radius=0.1 )[0]
        lowerSubCtlOffset = pymel.core.group( lowerSubCtl, n='Offset' + lowerSubCtl )
        lowerSubCtlGrp = pymel.core.group( lowerSubCtlOffset, n='P' + lowerSubCtl )
        
        pymel.core.parent( upperSubCtlGrp, coreGrp )
        pymel.core.parent( lowerSubCtlGrp, coreGrp )
        
        pymel.core.xform( upperSubCtlGrp, ws=1, matrix=firstSubCtl.wm.get() )
        pymel.core.xform( lowerSubCtlGrp, ws=1, matrix=secondSubCtl.wm.get() )
        
        firstPos = pymel.core.xform( firstSubCtl, q=1, ws=1, t=1 )
        secondPos = pymel.core.xform( secondSubCtl, q=1, ws=1, t=1 )
        thirdPos = pymel.core.xform( thirdSubCtl, q=1, ws=1, t=1 )
        
        upperPos = [ (firstPos[i] + secondPos[i])/2 for i in range( 3 ) ]
        lowerPos = [ (secondPos[i] + thirdPos[i])/2 for i in range( 3 ) ]
        
        pymel.core.xform( upperSubCtlGrp, ws=1, t=upperPos )
        pymel.core.xform( lowerSubCtlGrp, ws=1, t=lowerPos )

        def getPointOneTwo( pointerCtl1, pointerCtl2, baseCtl ):
            
            point1Dcmp = sgCmds.getLocalDecomposeMatrix( pointerCtl1.wm, baseCtl.wim )
            point2Dcmp = sgCmds.getLocalDecomposeMatrix( pointerCtl2.wm, baseCtl.wim )
            
            point1 = sgCmds.makeChild( baseCtl, n='pointer1_' + baseCtl )
            point2 = sgCmds.makeChild( baseCtl, n='pointer2_' + baseCtl )
            
            point1Dcmp.otx >> point1.tx
            point2Dcmp.otx >> point2.tx
            
            sgCmds.convertMultDoubleConnection( point1.tx ).set( 0.5 )
            sgCmds.convertMultDoubleConnection( point2.tx ).set( 0.5 )
            
            point1.dh.set( 1 )
            point2.dh.set( 1 )
            
            return point1, point2
        
        def disconnectRotate( inputNode ):
            node = pymel.core.ls( inputNode )[0]
            cons = node.r.listConnections( s=1, d=0, p=1 )
            if cons:
                cons[0] // node.r
        
        upperPoint1, upperPoint2 = getPointOneTwo( firstSubCtl, secondSubCtl, upperSubCtl )
        lowerPoint1, lowerPoint2 = getPointOneTwo( secondSubCtl, thirdSubCtl, lowerSubCtl )
        
        upperCurve = sgCmds.makeCurveFromObjects( firstSubCtl,  upperPoint1, upperPoint2, secondSubCtl )
        lowerCurve = sgCmds.makeCurveFromObjects( secondSubCtl, lowerPoint1, lowerPoint2, thirdSubCtl  )
        upperCurve.setParent( coreGrp ); upperCurve.t.set( 0,0,0 ); upperCurve.r.set( 0,0,0 )
        lowerCurve.setParent( coreGrp ); lowerCurve.t.set( 0,0,0 ); lowerCurve.r.set( 0,0,0 )
        
        upperJoints = sgCmds.createPointOnCurve( upperCurve, numJointUpper, nodeType='joint', vector=[1,0,0] )
        lowerJoints = sgCmds.createPointOnCurve( lowerCurve, numJointLower, nodeType='joint', vector=[1,0,0] )
        
        pymel.core.parent( upperJoints, coreGrp )
        pymel.core.parent( lowerJoints, coreGrp )
        for upperJoint in upperJoints:
            upperJoint.jo.set( 0,0,0 )
        for lowerJoint in lowerJoints:
            lowerJoint.jo.set( 0,0,0 )
        
        disconnectRotate( upperJoints[0] )
        pymel.core.delete( upperJoints[-1] )
        disconnectRotate( lowerJoints[0] )
        disconnectRotate( lowerJoints[-1] )
        
        sgCmds.blendTwoMatrixConnect( upperJoints[-2], lowerJoints[1], lowerJoints[0], ct=False )
        
        ctlGrp = pymel.core.createNode( 'transform', n='%sInterporationCtlGrp%s' % ( typ.capitalize(), ['_L_','_R_'][sideIndex] ) )
        sgCmds.constrain_all(armTop, ctlGrp)
        pymel.core.xform( ctlGrp, os=1, matrix= sgCmds.getDefaultMatrix() )
        sgCmds.addAttr( fkIkCtls[sideIndex], ln='showArcCtls', cb=1, min=0, max=1, at='long' )
        fkIkCtls[sideIndex].showArcCtls >> ctlGrp.v
        fkIkCtls[sideIndex].showArcCtls.set( 1 )
        sgCmds.addAttr( fkIkCtls[sideIndex], ln='arc', k=1, min=0, max=1 )
        
        circleCtls = []
        for i in range( len( targets ) ):
            circleCtl = pymel.core.circle( normal=[1,0,0], n=targets[i].replace( 'jnt_', 'Ctl_itp_' ), radius=0.5 )[0]
            circleCtlGrp = pymel.core.group( circleCtl, n='P' + circleCtl )
            pymel.core.parent( circleCtlGrp )
            pymel.core.xform( circleCtlGrp, ws=1, matrix=targets[i].wm.get() )
            circleCtls.append( circleCtl )
        
        for i in range( len( targets ) ):
            circleCtls[i].t >> circleSubCtls[i].t
            circleCtls[i].r >> circleSubCtls[i].r

        sgCmds.constrain_parent( armTop, circleCtls[0].getParent() )
        sgCmds.constrain_parent( armRotMiddle, circleCtls[1].getParent() )
        sgCmds.constrain_parent( armEnd, circleCtls[2].getParent() )

        upperCtl = pymel.core.circle( normal=[1,0,0], n=circleCtls[1] + '_upper', radius=0.5 )[0]
        upperCtlOffset = pymel.core.group( upperCtl, n='Offset' + upperCtl )
        upperCtlGrp = pymel.core.group( upperCtlOffset, n='P' + upperCtl )
        lowerCtl = pymel.core.circle( normal=[1,0,0], n=circleCtls[1] + '_lower', radius=0.5 )[0]
        lowerCtlOffset = pymel.core.group( lowerCtl, n='Offset' + lowerCtl )
        lowerCtlGrp = pymel.core.group( lowerCtlOffset, n='P' + lowerCtl )
        
        upperCtl.t >> upperSubCtl.t
        lowerCtl.t >> lowerSubCtl.t
        upperSubCtlOffset.t >> upperCtlOffset.t
        lowerSubCtlOffset.t >> lowerCtlOffset.t
        
        sgCmds.constrain_parent( armUpper, upperCtlGrp )
        sgCmds.constrain_parent( armLower, lowerCtlGrp )
        
        pymel.core.parent( circleCtls[0].getParent(), circleCtls[1].getParent(), circleCtls[2].getParent(), upperCtlGrp, lowerCtlGrp, ctlGrp )
        
        arcNode = pymel.core.createNode( 'makeThreePointCircularArc' )
        arcNode.point1.set( 0,0,0 )
        armMiddle.t >> arcNode.point2
        dcmpEnd = sgCmds.getLocalDecomposeMatrix( armEnd.wm, armTop.wim )
        rangeNode = pymel.core.createNode( 'setRange' )
        
        if sideIndex == 0:
            rangeNode.minZ.set( 0.001 ); rangeNode.maxZ.set( 10000 )
            rangeNode.oldMinZ.set( 0.001 ); rangeNode.oldMaxZ.set( 10000 )
        else:
            rangeNode.minZ.set( -100 ); rangeNode.maxZ.set( -0.001 )
            rangeNode.oldMinZ.set( -100 ); rangeNode.oldMaxZ.set( -0.001 )

        dcmpEnd.ot >> rangeNode.value
        rangeNode.outValue >> arcNode.point3

        curveShape = pymel.core.createNode( 'nurbsCurve' )
        curveTr = curveShape.getParent()
        curveTr.setParent( armTop )
        pymel.core.xform( curveTr, os=1, matrix=sgCmds.getDefaultMatrix() )
        
        arcNode.outputCurve >> curveShape.create
        
        middleTargets = [armUpper, armLower]
        offsetCtls = [upperSubCtlOffset, lowerSubCtlOffset]
        
        for i in range( 2 ):
            nearPointChild = pymel.core.createNode( 'transform' )
            nearPointChild.setParent( curveTr )
            nearCurve = pymel.core.createNode( 'nearestPointOnCurve' )
            curveShape.local >> nearCurve.inputCurve
            middleDcmp = sgCmds.getLocalDecomposeMatrix( middleTargets[i].wm, curveTr.wim )
            middleDcmp.ot >> nearCurve.inPosition
            nearCurve.position >> nearPointChild.t
            dcmp = sgCmds.getLocalDecomposeMatrix( nearPointChild.wm, middleTargets[i].wim )
            blendColor = pymel.core.createNode( 'blendColors' )
            dcmp.ot >> blendColor.color1
            blendColor.color2.set( 0,0,0 )
            fkIkCtls[sideIndex].arc >> blendColor.blender
            blendColor.output >> offsetCtls[i].t
        
        circleCtls[0].v.set(0)
        circleCtls[2].v.set(0)
        
        for joint in upperJoints[:-1] + lowerJoints[1:]:
            sgCmds.makeParent( joint )
            attrNameX = sgCmds.addMultDoubleLinearConnection( joint.rx )
            attrNameY = sgCmds.addMultDoubleLinearConnection( joint.ry )
            attrNameZ = sgCmds.addMultDoubleLinearConnection( joint.rz )
            if not attrNameX: continue
            attrNameX.set( 0.5 )
            attrNameY.set( 0.5 )
            attrNameZ.set( 0.5 )
示例#5
0
def buildLegArcController( numJoint ):
    
    sideList = ['_L_', '_R_']
    
    baseCtl = pymel.core.ls( 'anim_pelvis0' )[0]
    
    for side in sideList:
        
        mainGrp = pymel.core.createNode( 'transform' )
        
        legStart = pymel.core.ls( 'jnt%sleg1_2_IK' % side )[0]
        legEnd    = pymel.core.ls( 'jnt%sleg2_IK' % side )[0]
        legMiddle = sgCmds.addMiddleTranslateJoint( legEnd, n='MiddleJnt_' + legEnd )
        
        pymel.core.xform( mainGrp, ws=1, matrix= legStart.wm.get() )
        
        circleCtl, circleNode = pymel.core.circle( radius=0.5, normal=[1,0,0], n='Ctl_arc_Leg%s' % side )
        pCircleCtl = pymel.core.group( circleCtl, n='PCtl_arc_Leg%s' % side )
        
        pymel.core.parentConstraint( legMiddle, pCircleCtl )
    
        pointerStart = pymel.core.createNode( 'transform' )
        pointerMiddle = pymel.core.createNode( 'transform' )
        pointerEnd   = pymel.core.createNode( 'transform' )
        pPointMiddle = sgCmds.makeParent( pointerMiddle )
        
        pymel.core.xform( pointerStart, ws=1, matrix= legStart.wm.get() )
        pymel.core.xform( pPointMiddle, ws=1, matrix= legMiddle.wm.get() )
        pymel.core.xform( pointerEnd, ws=1, matrix= legEnd.wm.get() )
        
        middleChild0 = pymel.core.createNode( 'transform' ); middleChild0.dh.set( 1 )
        middleChild1 = pymel.core.createNode( 'transform' ); middleChild1.dh.set( 1 )        
        pymel.core.parent( middleChild0, middleChild1, pointerMiddle )
        pymel.core.xform( middleChild0, os=1, matrix=sgCmds.getDefaultMatrix() )
        pymel.core.xform( middleChild1, os=1, matrix=sgCmds.getDefaultMatrix() )
    
        dcmpStart = sgCmds.getLocalDecomposeMatrix( pointerStart.wm, pointerMiddle.wim )
        dcmpEnd   = sgCmds.getLocalDecomposeMatrix( pointerEnd.wm, pointerMiddle.wim )
        
        halfTxStart = pymel.core.createNode( 'multDoubleLinear' )
        halfTxEnd = pymel.core.createNode( 'multDoubleLinear' )
        dcmpStart.otx >> halfTxStart.input1
        dcmpEnd.otx >> halfTxEnd.input1
        halfTxStart.input2.set( 0.5 )
        halfTxEnd.input2.set( 0.5 )
        
        halfTxStart.output >> middleChild0.tx
        halfTxEnd.output >> middleChild1.tx
        
        circleCtl.t >> pointerMiddle.t
        
        curve = sgCmds.makeCurveFromObjects( pointerStart, middleChild0, middleChild1, pointerEnd )
        
        joints = sgCmds.createPointOnCurve( curve, numJoint, nodeType='joint', vector=[0,-1,0] )
        
        
        def disconnectRotate( inputNode ):
            node = pymel.core.ls( inputNode )[0]
            cons = node.r.listConnections( s=1, d=0, p=1 )
            if cons:
                cons[0] // node.r

        disconnectRotate( joints[0]  )
        disconnectRotate( joints[-1] )
        
        pymel.core.parent( joints, curve, pointerStart, pPointMiddle, pointerEnd, mainGrp )
        
        for joint in joints[1:-1]:
            joint.jo.set( 0,0,0 )
            sgCmds.makeParent( joint )
            rxMultAttr = sgCmds.addMultDoubleLinearConnection( joint.rx )
            ryMultAttr = sgCmds.addMultDoubleLinearConnection( joint.ry )
            rzMultAttr = sgCmds.addMultDoubleLinearConnection( joint.rz )
            rxMultAttr.set( 0.5 )
            ryMultAttr.set( 0.5 )
            rzMultAttr.set( 0.5 )
示例#6
0
def buildLegArcController(numJoint):

    sideList = ['_L_', '_R_']

    baseCtl = pymel.core.ls('anim_pelvis0')[0]

    for side in sideList:

        mainGrp = pymel.core.createNode('transform')

        legStart = pymel.core.ls('jnt%sleg1_2_IK' % side)[0]
        legEnd = pymel.core.ls('jnt%sleg2_IK' % side)[0]
        legMiddle = sgCmds.addMiddleTranslateJoint(legEnd,
                                                   n='MiddleJnt_' + legEnd)

        pymel.core.xform(mainGrp, ws=1, matrix=legStart.wm.get())

        circleCtl, circleNode = pymel.core.circle(radius=0.5,
                                                  normal=[1, 0, 0],
                                                  n='Ctl_arc_Leg%s' % side)
        pCircleCtl = pymel.core.group(circleCtl, n='PCtl_arc_Leg%s' % side)

        pymel.core.parentConstraint(legMiddle, pCircleCtl)

        pointerStart = pymel.core.createNode('transform')
        pointerMiddle = pymel.core.createNode('transform')
        pointerEnd = pymel.core.createNode('transform')
        pPointMiddle = sgCmds.makeParent(pointerMiddle)

        pymel.core.xform(pointerStart, ws=1, matrix=legStart.wm.get())
        pymel.core.xform(pPointMiddle, ws=1, matrix=legMiddle.wm.get())
        pymel.core.xform(pointerEnd, ws=1, matrix=legEnd.wm.get())

        middleChild0 = pymel.core.createNode('transform')
        middleChild0.dh.set(1)
        middleChild1 = pymel.core.createNode('transform')
        middleChild1.dh.set(1)
        pymel.core.parent(middleChild0, middleChild1, pointerMiddle)
        pymel.core.xform(middleChild0, os=1, matrix=sgCmds.getDefaultMatrix())
        pymel.core.xform(middleChild1, os=1, matrix=sgCmds.getDefaultMatrix())

        dcmpStart = sgCmds.getLocalDecomposeMatrix(pointerStart.wm,
                                                   pointerMiddle.wim)
        dcmpEnd = sgCmds.getLocalDecomposeMatrix(pointerEnd.wm,
                                                 pointerMiddle.wim)

        halfTxStart = pymel.core.createNode('multDoubleLinear')
        halfTxEnd = pymel.core.createNode('multDoubleLinear')
        dcmpStart.otx >> halfTxStart.input1
        dcmpEnd.otx >> halfTxEnd.input1
        halfTxStart.input2.set(0.5)
        halfTxEnd.input2.set(0.5)

        halfTxStart.output >> middleChild0.tx
        halfTxEnd.output >> middleChild1.tx

        circleCtl.t >> pointerMiddle.t

        curve = sgCmds.makeCurveFromObjects(pointerStart, middleChild0,
                                            middleChild1, pointerEnd)

        joints = sgCmds.createPointOnCurve(curve,
                                           numJoint,
                                           nodeType='joint',
                                           vector=[0, -1, 0])

        def disconnectRotate(inputNode):
            node = pymel.core.ls(inputNode)[0]
            cons = node.r.listConnections(s=1, d=0, p=1)
            if cons:
                cons[0] // node.r

        disconnectRotate(joints[0])
        disconnectRotate(joints[-1])

        pymel.core.parent(joints, curve, pointerStart, pPointMiddle,
                          pointerEnd, mainGrp)

        for joint in joints[1:-1]:
            joint.jo.set(0, 0, 0)
            sgCmds.makeParent(joint)
            rxMultAttr = sgCmds.addMultDoubleLinearConnection(joint.rx)
            ryMultAttr = sgCmds.addMultDoubleLinearConnection(joint.ry)
            rzMultAttr = sgCmds.addMultDoubleLinearConnection(joint.rz)
            rxMultAttr.set(0.5)
            ryMultAttr.set(0.5)
            rzMultAttr.set(0.5)
示例#7
0
def buildArcControl(numJointUpper, numJointLower, typ='arm'):

    armTops = []
    armMiddles = []
    armEnds = []
    fkIkCtls = []

    for side in ['_L_', '_R_']:
        armTops += pymel.core.ls('jnt%s%s0' % (side, typ))
        armMiddles += pymel.core.ls('jnt%s%s1' % (side, typ))
        armEnds += pymel.core.ls('jnt%s%s1_end' % (side, typ))
        fkIkCtls += pymel.core.ls('anim%s%s_IKFK' % (side, typ))

    if not armTops:
        for side in ['_L_', '_R_']:
            armTops += pymel.core.ls('%s01%sJNT' % (typ.capitalize(), side))
            armMiddles += pymel.core.ls('%s02%sJNT' % (typ.capitalize(), side))
            armEnds += pymel.core.ls('%s03%sJNT' % (typ.capitalize(), side))
            fkIkCtls += pymel.core.ls('%s%sIKFKSwitch' %
                                      (typ.capitalize(), side))

    for sideIndex in range(2):
        coreGrp = pymel.core.createNode(
            'transform',
            n='%sInterporationCoreGrp%s' %
            (typ.capitalize(), ['_L_', '_R_'][sideIndex]))
        pymel.core.xform(coreGrp,
                         ws=1,
                         matrix=pymel.core.xform(armTops[sideIndex],
                                                 q=1,
                                                 ws=1,
                                                 matrix=1))

        armTop = armTops[sideIndex]
        armMiddle = armMiddles[sideIndex]
        armEnd = armEnds[sideIndex]

        armUpper = sgCmds.addMiddleTranslateJoint(armMiddle,
                                                  n='MiddleJnt_' + armMiddle)
        armRotMiddle = sgCmds.addMiddleJoint(armMiddle,
                                             n='MiddleRotJnt_' + armMiddle)
        armLower = sgCmds.addMiddleTranslateJoint(armEnd,
                                                  n='MiddleJnt_' + armEnd)

        targets = [armTop, armMiddle, armEnd]
        circleSubCtls = []
        for i in range(len(targets)):
            circleSubCtl = pymel.core.circle(normal=[1, 0, 0],
                                             n=targets[i].replace(
                                                 'jnt_', 'sub_Ctl_'),
                                             radius=0.1)[0]
            circleSubCtlGrp = pymel.core.group(circleSubCtl,
                                               n='P' + circleSubCtl)
            pymel.core.parent(circleSubCtlGrp, coreGrp)
            pymel.core.xform(circleSubCtlGrp, ws=1, matrix=targets[i].wm.get())
            circleSubCtls.append(circleSubCtl)

        firstSubCtl = circleSubCtls[0]
        secondSubCtl = circleSubCtls[1]
        thirdSubCtl = circleSubCtls[2]

        upperSubCtl = pymel.core.circle(normal=[1, 0, 0],
                                        n=secondSubCtl + '_upper',
                                        radius=0.1)[0]
        upperSubCtlOffset = pymel.core.group(upperSubCtl,
                                             n='Offset' + upperSubCtl)
        upperSubCtlGrp = pymel.core.group(upperSubCtlOffset,
                                          n='P' + upperSubCtl)
        lowerSubCtl = pymel.core.circle(normal=[1, 0, 0],
                                        n=secondSubCtl + '_lower',
                                        radius=0.1)[0]
        lowerSubCtlOffset = pymel.core.group(lowerSubCtl,
                                             n='Offset' + lowerSubCtl)
        lowerSubCtlGrp = pymel.core.group(lowerSubCtlOffset,
                                          n='P' + lowerSubCtl)

        pymel.core.parent(upperSubCtlGrp, coreGrp)
        pymel.core.parent(lowerSubCtlGrp, coreGrp)

        pymel.core.xform(upperSubCtlGrp, ws=1, matrix=firstSubCtl.wm.get())
        pymel.core.xform(lowerSubCtlGrp, ws=1, matrix=secondSubCtl.wm.get())

        firstPos = pymel.core.xform(firstSubCtl, q=1, ws=1, t=1)
        secondPos = pymel.core.xform(secondSubCtl, q=1, ws=1, t=1)
        thirdPos = pymel.core.xform(thirdSubCtl, q=1, ws=1, t=1)

        upperPos = [(firstPos[i] + secondPos[i]) / 2 for i in range(3)]
        lowerPos = [(secondPos[i] + thirdPos[i]) / 2 for i in range(3)]

        pymel.core.xform(upperSubCtlGrp, ws=1, t=upperPos)
        pymel.core.xform(lowerSubCtlGrp, ws=1, t=lowerPos)

        def getPointOneTwo(pointerCtl1, pointerCtl2, baseCtl):

            point1Dcmp = sgCmds.getLocalDecomposeMatrix(
                pointerCtl1.wm, baseCtl.wim)
            point2Dcmp = sgCmds.getLocalDecomposeMatrix(
                pointerCtl2.wm, baseCtl.wim)

            point1 = sgCmds.makeChild(baseCtl, n='pointer1_' + baseCtl)
            point2 = sgCmds.makeChild(baseCtl, n='pointer2_' + baseCtl)

            point1Dcmp.otx >> point1.tx
            point2Dcmp.otx >> point2.tx

            sgCmds.convertMultDoubleConnection(point1.tx).set(0.5)
            sgCmds.convertMultDoubleConnection(point2.tx).set(0.5)

            point1.dh.set(1)
            point2.dh.set(1)

            return point1, point2

        def disconnectRotate(inputNode):
            node = pymel.core.ls(inputNode)[0]
            cons = node.r.listConnections(s=1, d=0, p=1)
            if cons:
                cons[0] // node.r

        upperPoint1, upperPoint2 = getPointOneTwo(firstSubCtl, secondSubCtl,
                                                  upperSubCtl)
        lowerPoint1, lowerPoint2 = getPointOneTwo(secondSubCtl, thirdSubCtl,
                                                  lowerSubCtl)

        upperCurve = sgCmds.makeCurveFromObjects(firstSubCtl, upperPoint1,
                                                 upperPoint2, secondSubCtl)
        lowerCurve = sgCmds.makeCurveFromObjects(secondSubCtl, lowerPoint1,
                                                 lowerPoint2, thirdSubCtl)
        upperCurve.setParent(coreGrp)
        upperCurve.t.set(0, 0, 0)
        upperCurve.r.set(0, 0, 0)
        lowerCurve.setParent(coreGrp)
        lowerCurve.t.set(0, 0, 0)
        lowerCurve.r.set(0, 0, 0)

        upperJoints = sgCmds.createPointOnCurve(upperCurve,
                                                numJointUpper,
                                                nodeType='joint',
                                                vector=[1, 0, 0])
        lowerJoints = sgCmds.createPointOnCurve(lowerCurve,
                                                numJointLower,
                                                nodeType='joint',
                                                vector=[1, 0, 0])

        pymel.core.parent(upperJoints, coreGrp)
        pymel.core.parent(lowerJoints, coreGrp)
        for upperJoint in upperJoints:
            upperJoint.jo.set(0, 0, 0)
        for lowerJoint in lowerJoints:
            lowerJoint.jo.set(0, 0, 0)

        disconnectRotate(upperJoints[0])
        pymel.core.delete(upperJoints[-1])
        disconnectRotate(lowerJoints[0])
        disconnectRotate(lowerJoints[-1])

        sgCmds.blendTwoMatrixConnect(upperJoints[-2],
                                     lowerJoints[1],
                                     lowerJoints[0],
                                     ct=False)

        ctlGrp = pymel.core.createNode(
            'transform',
            n='%sInterporationCtlGrp%s' %
            (typ.capitalize(), ['_L_', '_R_'][sideIndex]))
        sgCmds.constrain_all(armTop, ctlGrp)
        pymel.core.xform(ctlGrp, os=1, matrix=sgCmds.getDefaultMatrix())
        sgCmds.addAttr(fkIkCtls[sideIndex],
                       ln='showArcCtls',
                       cb=1,
                       min=0,
                       max=1,
                       at='long')
        fkIkCtls[sideIndex].showArcCtls >> ctlGrp.v
        fkIkCtls[sideIndex].showArcCtls.set(1)
        sgCmds.addAttr(fkIkCtls[sideIndex], ln='arc', k=1, min=0, max=1)

        circleCtls = []
        for i in range(len(targets)):
            circleCtl = pymel.core.circle(normal=[1, 0, 0],
                                          n=targets[i].replace(
                                              'jnt_', 'Ctl_itp_'),
                                          radius=0.5)[0]
            circleCtlGrp = pymel.core.group(circleCtl, n='P' + circleCtl)
            pymel.core.parent(circleCtlGrp)
            pymel.core.xform(circleCtlGrp, ws=1, matrix=targets[i].wm.get())
            circleCtls.append(circleCtl)

        for i in range(len(targets)):
            circleCtls[i].t >> circleSubCtls[i].t
            circleCtls[i].r >> circleSubCtls[i].r

        sgCmds.constrain_parent(armTop, circleCtls[0].getParent())
        sgCmds.constrain_parent(armRotMiddle, circleCtls[1].getParent())
        sgCmds.constrain_parent(armEnd, circleCtls[2].getParent())

        upperCtl = pymel.core.circle(normal=[1, 0, 0],
                                     n=circleCtls[1] + '_upper',
                                     radius=0.5)[0]
        upperCtlOffset = pymel.core.group(upperCtl, n='Offset' + upperCtl)
        upperCtlGrp = pymel.core.group(upperCtlOffset, n='P' + upperCtl)
        lowerCtl = pymel.core.circle(normal=[1, 0, 0],
                                     n=circleCtls[1] + '_lower',
                                     radius=0.5)[0]
        lowerCtlOffset = pymel.core.group(lowerCtl, n='Offset' + lowerCtl)
        lowerCtlGrp = pymel.core.group(lowerCtlOffset, n='P' + lowerCtl)

        upperCtl.t >> upperSubCtl.t
        lowerCtl.t >> lowerSubCtl.t
        upperSubCtlOffset.t >> upperCtlOffset.t
        lowerSubCtlOffset.t >> lowerCtlOffset.t

        sgCmds.constrain_parent(armUpper, upperCtlGrp)
        sgCmds.constrain_parent(armLower, lowerCtlGrp)

        pymel.core.parent(circleCtls[0].getParent(), circleCtls[1].getParent(),
                          circleCtls[2].getParent(), upperCtlGrp, lowerCtlGrp,
                          ctlGrp)

        arcNode = pymel.core.createNode('makeThreePointCircularArc')
        arcNode.point1.set(0, 0, 0)
        armMiddle.t >> arcNode.point2
        dcmpEnd = sgCmds.getLocalDecomposeMatrix(armEnd.wm, armTop.wim)
        rangeNode = pymel.core.createNode('setRange')

        if sideIndex == 0:
            rangeNode.minZ.set(0.001)
            rangeNode.maxZ.set(10000)
            rangeNode.oldMinZ.set(0.001)
            rangeNode.oldMaxZ.set(10000)
        else:
            rangeNode.minZ.set(-100)
            rangeNode.maxZ.set(-0.001)
            rangeNode.oldMinZ.set(-100)
            rangeNode.oldMaxZ.set(-0.001)

        dcmpEnd.ot >> rangeNode.value
        rangeNode.outValue >> arcNode.point3

        curveShape = pymel.core.createNode('nurbsCurve')
        curveTr = curveShape.getParent()
        curveTr.setParent(armTop)
        pymel.core.xform(curveTr, os=1, matrix=sgCmds.getDefaultMatrix())

        arcNode.outputCurve >> curveShape.create

        middleTargets = [armUpper, armLower]
        offsetCtls = [upperSubCtlOffset, lowerSubCtlOffset]

        for i in range(2):
            nearPointChild = pymel.core.createNode('transform')
            nearPointChild.setParent(curveTr)
            nearCurve = pymel.core.createNode('nearestPointOnCurve')
            curveShape.local >> nearCurve.inputCurve
            middleDcmp = sgCmds.getLocalDecomposeMatrix(
                middleTargets[i].wm, curveTr.wim)
            middleDcmp.ot >> nearCurve.inPosition
            nearCurve.position >> nearPointChild.t
            dcmp = sgCmds.getLocalDecomposeMatrix(nearPointChild.wm,
                                                  middleTargets[i].wim)
            blendColor = pymel.core.createNode('blendColors')
            dcmp.ot >> blendColor.color1
            blendColor.color2.set(0, 0, 0)
            fkIkCtls[sideIndex].arc >> blendColor.blender
            blendColor.output >> offsetCtls[i].t

        circleCtls[0].v.set(0)
        circleCtls[2].v.set(0)

        for joint in upperJoints[:-1] + lowerJoints[1:]:
            sgCmds.makeParent(joint)
            attrNameX = sgCmds.addMultDoubleLinearConnection(joint.rx)
            attrNameY = sgCmds.addMultDoubleLinearConnection(joint.ry)
            attrNameZ = sgCmds.addMultDoubleLinearConnection(joint.rz)
            if not attrNameX: continue
            attrNameX.set(0.5)
            attrNameY.set(0.5)
            attrNameZ.set(0.5)
示例#8
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)
示例#9
0
import pymel.core
from sgMaya import sgCmds

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

ctl = sels[0]
jnt = sels[1]

ctlBase = ctl.getParent().getParent()

dcmp = sgCmds.getLocalDecomposeMatrix(ctl.wm, ctlBase.wim)
dcmp.ot >> jnt.t
dcmp.outputRotate >> jnt.r

ctl.rename(ctl.replace('sub_', ''))
示例#10
0
from sgMaya import sgCmds
import pymel.core

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

ctlChild = sels[0]
ctlTarget = sels[1]

pCtlChild = ctlChild.getParent()
pCtlTarget = ctlTarget.getParent()

dcmpChild = pCtlChild.listConnections(s=1, d=0, type='decomposeMatrix')[0]
mChild = dcmpChild.listConnections(s=1, d=0, type='multMatrix')[0]
dcmpTarget = pCtlTarget.listConnections(s=1, d=0, type='decomposeMatrix')[0]
mTarget = dcmpTarget.listConnections(s=1, d=0, type='multMatrix')[0]

trChild = mChild.i[0].listConnections(s=1, d=0)[0]
trTarget = mTarget.i[0].listConnections(s=1, d=0)[0]

localDcmp = sgCmds.getLocalDecomposeMatrix(trChild.wm, trTarget.wim)
trChildLocal = pymel.core.createNode('transform')
trChildLocal.setParent(ctlTarget)
localDcmp.ot >> trChildLocal.t
localDcmp.outputRotate >> trChildLocal.r

pymel.core.delete(dcmpChild)
sgCmds.constrain(trChildLocal, pCtlChild, ct=1, cr=1, cs=1, csh=1)
from sgMaya import sgCmds
import pymel.core
sels = pymel.core.ls( sl=1 )

aimTarget = sels[0]
baseTarget = sels[1]
jntTarget = sels[2]

dcmp = sgCmds.getLocalDecomposeMatrix( aimTarget.wm, baseTarget.wim )
angleNode = sgCmds.getAngleNode( dcmp.ot )
compose = pymel.core.createNode( 'composeMatrix' )
angleNode.euler >> compose.ir
multMatrix = pymel.core.createNode( 'multMatrix' )
compose.outputMatrix >> multMatrix.i[0]
baseTarget.wm >> multMatrix.i[1]
jntTarget.pim >> multMatrix.i[2]
dcmp = sgCmds.getDecomposeMatrix( multMatrix.matrixSum )
dcmp.ot >> jntTarget.t
dcmp.outputRotate >> jntTarget.r
if jntTarget.nodeType() == 'joint':
    jntTarget.jo.set( 0,0,0 )
import pymel.core
from sgMaya import sgCmds

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

sel_0_p = sels[0].getParent()

dcmpChild  = sgCmds.getLocalDecomposeMatrix( sels[0].wm, sels[1].wim )
dcmpParent = sgCmds.getLocalDecomposeMatrix( sels[1].wm, sels[0].wim )

dirIndex = sgCmds.getDirectionIndex( dcmpChild.ot.get() )

multNodeValue = [0,0,0]
multNodeValue[ dirIndex%3 ] = 0.25

trChild = pymel.core.createNode( 'transform' )
trParent = pymel.core.createNode( 'transform' )
trChild.rename( 'trChild' )
trParent.rename( 'trParent' )

multNodeChild = pymel.core.createNode( 'multiplyDivide' )
multNodeParent = pymel.core.createNode( 'multiplyDivide' )

dcmpChild.ot >> multNodeChild.input1; multNodeChild.input2.set( multNodeValue )
dcmpParent.ot >> multNodeParent.input1; multNodeParent.input2.set( multNodeValue )

multNodeChild.output >> trChild.t
multNodeParent.output >> trParent.t

trChild.dh.set( 1 )
trParent.dh.set( 1 )
from sgMaya import sgCmds
import pymel.core
sels = pymel.core.ls( sl=1 )
localTarget = sels[0]
parentTarget = sels[1]
connectTarget = sels[2]
dcmp = sgCmds.getLocalDecomposeMatrix( localTarget.wm, parentTarget.wim )
dcmp.ot >> connectTarget.t
dcmp.outputRotate >> connectTarget.r
示例#14
0
import pymel.core
from sgMaya import sgCmds

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

bezierCurve = pymel.core.curve( bezier=1, d=3, p=[ [0,0,0] for i in range( len( sels ) ) ] )
curveShape = bezierCurve.getShape()

for i in range( len( sels ) ):
    dcmp = sgCmds.getLocalDecomposeMatrix( sels[i].wm, bezierCurve.wim )
    dcmp.ot >> curveShape.controlPoints[i]
from sgMaya import sgCmds
import pymel.core

sels = pymel.core.ls(sl=1)
localTarget = sels[0]
parentTarget = sels[1]
connectTarget = sels[2]
dcmp = sgCmds.getLocalDecomposeMatrix(localTarget.wm, parentTarget.wim)
dcmp.ot >> connectTarget.t
dcmp.outputRotate >> connectTarget.r
示例#16
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 )
    
    
    
from sgMaya import sgCmds
import pymel.core
sels = pymel.core.ls( sl=1 )

ctlChild = sels[0]
ctlTarget = sels[1]

pCtlChild = ctlChild.getParent()
pCtlTarget = ctlTarget.getParent()

dcmpChild = pCtlChild.listConnections( s=1, d=0, type='decomposeMatrix' )[0]
mChild = dcmpChild.listConnections( s=1, d=0, type='multMatrix' )[0]
dcmpTarget = pCtlTarget.listConnections( s=1, d=0, type='decomposeMatrix' )[0]
mTarget = dcmpTarget.listConnections( s=1, d=0, type='multMatrix' )[0]

trChild = mChild.i[0].listConnections( s=1, d=0 )[0]
trTarget = mTarget.i[0].listConnections( s=1, d=0 )[0]

localDcmp = sgCmds.getLocalDecomposeMatrix( trChild.wm, trTarget.wim )
trChildLocal = pymel.core.createNode( 'transform' )
trChildLocal.setParent( ctlTarget )
localDcmp.ot >> trChildLocal.t
localDcmp.outputRotate >> trChildLocal.r

pymel.core.delete( dcmpChild )
sgCmds.constrain( trChildLocal, pCtlChild, ct=1, cr=1, cs=1, csh=1 )
示例#18
0
from sgMaya import sgCmds
import pymel.core

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

aimTarget = sels[0]
baseTarget = sels[1]
jntTarget = sels[2]

dcmp = sgCmds.getLocalDecomposeMatrix(aimTarget.wm, baseTarget.wim)
angleNode = sgCmds.getAngleNode(dcmp.ot)
compose = pymel.core.createNode('composeMatrix')
angleNode.euler >> compose.ir
multMatrix = pymel.core.createNode('multMatrix')
compose.outputMatrix >> multMatrix.i[0]
baseTarget.wm >> multMatrix.i[1]
jntTarget.pim >> multMatrix.i[2]
dcmp = sgCmds.getDecomposeMatrix(multMatrix.matrixSum)
dcmp.ot >> jntTarget.t
dcmp.outputRotate >> jntTarget.r
if jntTarget.nodeType() == 'joint':
    jntTarget.jo.set(0, 0, 0)