def treeBendingRig( topJnt ): children = topJnt.listRelatives( c=1, ad=1 ) lastChild = children[0] ctl = sgCmds.makeController( sgModel.Controller.diamondPoints, 1, makeParent=1 ) pCtl = ctl.getParent() pymel.core.xform( pCtl, ws=1, matrix=lastChild.wm.get() ) treeBendingLookAtConnect( ctl, topJnt )
def createRect(width, height): rect = sgCmds.makeController(sgModel.Controller.planePoints, 1, makeParent=1) rect.setAttr('shape_sx', width) rect.setAttr('shape_sz', height) rect.setAttr('shape_rx', 90) return rect.name()
def addHipController(): sideList = ['_L_', '_R_'] baseCtl = pymel.core.ls( 'anim_pelvis0' )[0] for side in sideList: ctl = sgCmds.makeController( sgModel.Controller.pinPoints, n='Ctl_Hip%s' % side, makeParent=1 ) pCtl = ctl.getParent() pCtl.setParent( baseCtl ) ikLeg = pymel.core.ls( 'jnt%sleg0_IK' % side )[0] pymel.core.xform( pCtl, ws=1, matrix= pymel.core.xform( ikLeg, q=1, ws=1, matrix=1 ) ) if side == '_L_': ctl.shape_rx.set( 90 ) else: ctl.shape_rx.set( -90 ) sgCmds.constrain_point( ctl, ikLeg )
def buildBearHipController(): baseCtl = 'Pelvis_CTRL' for side in ['_L_', '_R_']: ikJnt = pymel.core.ls( 'Leg01%sIK_JNT' % side )[0] fkGrp = pymel.core.ls( 'Leg%sFK_CTRL_GP' % side )[0] ctl = sgCmds.makeController( sgModel.Controller.pinPoints, n='Ctl_Hip%s' % side, makeParent=1 ) pCtl = ctl.getParent() pymel.core.xform( pCtl, ws=1, matrix=ikJnt.wm.get() ) rotValue = 90 if side == '_R_': rotValue = -90 ctl.shape_rx.set( rotValue ) ctl.shape_sx.set( 9 ) ctl.shape_sy.set( 9 ) ctl.shape_sz.set( 9 ) pCtl.setParent( baseCtl ) pymel.core.pointConstraint( ctl, ikJnt ) pymel.core.pointConstraint( ctl, fkGrp )
def buildBearHipController(): baseCtl = 'Pelvis_CTRL' for side in ['_L_', '_R_']: ikJnt = pymel.core.ls('Leg01%sIK_JNT' % side)[0] fkGrp = pymel.core.ls('Leg%sFK_CTRL_GP' % side)[0] ctl = sgCmds.makeController(sgModel.Controller.pinPoints, n='Ctl_Hip%s' % side, makeParent=1) pCtl = ctl.getParent() pymel.core.xform(pCtl, ws=1, matrix=ikJnt.wm.get()) rotValue = 90 if side == '_R_': rotValue = -90 ctl.shape_rx.set(rotValue) ctl.shape_sx.set(9) ctl.shape_sy.set(9) ctl.shape_sz.set(9) pCtl.setParent(baseCtl) pymel.core.pointConstraint(ctl, ikJnt) pymel.core.pointConstraint(ctl, fkGrp)
def addHipController(): sideList = ['_L_', '_R_'] baseCtl = pymel.core.ls('anim_pelvis0')[0] for side in sideList: ctl = sgCmds.makeController(sgModel.Controller.pinPoints, n='Ctl_Hip%s' % side, makeParent=1) pCtl = ctl.getParent() pCtl.setParent(baseCtl) ikLeg = pymel.core.ls('jnt%sleg0_IK' % side)[0] pymel.core.xform(pCtl, ws=1, matrix=pymel.core.xform(ikLeg, q=1, ws=1, matrix=1)) if side == '_L_': ctl.shape_rx.set(90) else: ctl.shape_rx.set(-90) sgCmds.constrain_point(ctl, ikLeg)
from sgMaya import sgCmds, sgModel import pymel.core sels = pymel.core.ls(sl=1) target = sels[0] pymel.core.delete(target.getShape()) circle = sgCmds.makeController(sgModel.Controller.circlePoints, 5) circle.shape_rz.set(90) pymel.core.parent(circle.getShape(), target, add=1, shape=1) sgCmds.setIndexColor(target, 13) pymel.core.refresh() pymel.core.delete(circle) pymel.core.select(target)
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, sgModel import pymel.core sels = pymel.core.ls(sl=1) moveCtls = [] for sel in sels: bb = pymel.core.exactWorldBoundingBox(sel.getShape()) xDist = bb[3] - bb[0] yDist = bb[4] - bb[1] zDist = bb[5] - bb[2] size = max(xDist, yDist, zDist) moveCtl = sgCmds.makeController(sgModel.Controller.pinPoints, size / 1.5, makeParent=1) if xDist == size: moveCtl.getShape() moveCtl.rename(sel + '_move') moveCtl.getParent().setParent(sel) sgCmds.setTransformDefault(moveCtl.getParent()) moveCtls.append(moveCtl) pymel.core.select(moveCtls)
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, sgModel import pymel.core sels = pymel.core.ls( sl=1 ) ctls = [] for sel in sels: ctlCurtain = sgCmds.makeController( sgModel.Controller.spherePoints, 1, makeParent=1, n = sel.replace( 'detail', 'Curtain' ) ) pymel.core.xform( ctlCurtain.getParent(), ws=1, matrix= sel.wm.get() ) ctls.append( ctlCurtain ) pymel.core.select( ctls )
def createRect( width, height ): rect = sgCmds.makeController( sgModel.Controller.planePoints, 1, makeParent=1 ) rect.setAttr( 'shape_sx', width ) rect.setAttr( 'shape_sz', height ) rect.setAttr( 'shape_rx', 90 ) return rect.name()
from sgMaya import sgCmds, sgModel import pymel.core from maya import cmds slider = sgCmds.makeController( sgModel.Controller.move2Points, 0.5 ) sliderBase = sgCmds.createSliderBase('x') slider.setParent( sliderBase ) cmds.transformLimits( slider.name(), tx=[0,1], etx=[1,0] ) cmds.transformLimits( slider.name(), ty=[0,1], ety=[1,0] ) keyAttrs = cmds.listAttr( slider.name(), k=1, sn=1 ) keyAttrs += cmds.listAttr( slider.name(), cb=1, sn=1 ) for keyAttr in keyAttrs: if keyAttr in ['tx','ty'] : continue cmds.setAttr( slider.attr( keyAttr ).name(), e=1, lock=1, k=0 ) cmds.setAttr( slider.attr( keyAttr ).name(), e=1, cb=0 ) sliderBaseParent = sgCmds.makeParent( sliderBase ) pymel.core.select( sliderBaseParent )
import pymel.core from sgMaya import sgCmds, sgModel sels = pymel.core.ls(sl=1) newCtls = [] for sel in sels: subCtl = sel.message.listConnections(s=0, d=1, p=1)[0] mm = subCtl.node().wm.listConnections(s=0, d=1, type='multMatrix')[0] dcmp = mm.o.listConnections(s=0, d=1, type='decomposeMatrix')[0] jnt = dcmp.listConnections(s=0, d=1, type='transform')[0] moveSubCtl = pymel.core.createNode('transform') moveSubCtl.setParent(subCtl.node()) sgCmds.setTransformDefault(moveSubCtl) moveCtl = sgCmds.makeController(sgModel.Controller.pinPoints, 2, makeParent=1, n=sel + '_Move') moveCtl.t >> moveSubCtl.t moveCtl.r >> moveSubCtl.r moveCtl.s >> moveSubCtl.s moveCtl.getParent().setParent(sel) sgCmds.setTransformDefault(moveCtl.getParent()) newCtls.append(moveCtl) pymel.core.delete(dcmp) sgCmds.constrain(moveSubCtl, jnt, ct=1, cr=1, cs=1, csh=1) pymel.core.select(newCtls)
def getXYSlider( width, height, colorIndex = None, texturePath = '' ): slider = sgCmds.makeController( sgModel.Controller.move2Points, 0.5 ) sliderBase = sgCmds.SliderBase().create( 'xy' ) pymel.core.parent( slider, sliderBase ) cmds.rename( sliderBase.name(), 'Ctl_Facial' ) cmds.transformLimits( slider.name(), tx=[0,1], etx=[1,0] ) cmds.transformLimits( slider.name(), ty=[0,1], ety=[1,0] ) keyAttrs = cmds.listAttr( slider.name(), k=1, sn=1 ) if not keyAttrs : keyAttrs = [] chAttrs = cmds.listAttr( slider.name(), cb=1, sn=1 ) if not chAttrs : chAttrs = [] keyAttrs += chAttrs for keyAttr in keyAttrs: if keyAttr in ['tx', 'ty'] : continue cmds.setAttr( slider.attr( keyAttr ).name(), e=1, lock=1, k=0 ) cmds.setAttr( slider.attr( keyAttr ).name(), e=1, cb=0 ) sliderBaseParent = sgCmds.makeParent( sliderBase ) pymel.core.select( sliderBaseParent ) sliderBase.setAttr( 'slideSizeX', width ) sliderBase.setAttr( 'slideSizeY', height ) pPlane = cmds.polyPlane( w=1, h=1, sx=1, sy=1, ax=[0,0,1], cuv=2, ch=1 )[0] shape = cmds.listRelatives( pPlane, s=1, f=1 )[0] cmds.setAttr( shape + '.castsShadows', 0 ) cmds.setAttr( shape + '.receiveShadows', 0 ) cmds.setAttr( shape + '.motionBlur', 0 ) cmds.setAttr( shape + '.primaryVisibility', 0 ) cmds.setAttr( shape + '.smoothShading', 0 ) cmds.setAttr( shape + '.visibleInReflections', 0 ) cmds.setAttr( shape + '.visibleInRefractions', 0 ) cmds.setAttr( pPlane + '.overrideEnabled', 1 ) cmds.setAttr( pPlane + '.overrideDisplayType', 2 ) av = cmds.createNode( 'plusMinusAverage' ) md = cmds.createNode( 'multiplyDivide' ) cmds.connectAttr( sliderBase.attr( 'slideSizeX' ).name(), av + '.input2D[0].input2Dx' ) cmds.connectAttr( sliderBase.attr( 'slideSizeY' ).name(), av + '.input2D[0].input2Dy' ) cmds.setAttr( av + '.input2D[1].input2Dx', 1 ) cmds.setAttr( av + '.input2D[1].input2Dy', 1 ) cmds.connectAttr( sliderBase.attr( 'slideSizeX' ).name(), md + '.input1X' ) cmds.connectAttr( sliderBase.attr( 'slideSizeY' ).name(), md + '.input1Y' ) cmds.setAttr( md + '.input2X', 0.5 ) cmds.setAttr( md + '.input2Y', 0.5 ) cmds.connectAttr( av + '.output2Dx', pPlane+'.sx' ) cmds.connectAttr( av + '.output2Dy', pPlane+'.sy' ) cmds.connectAttr( md + '.outputX', pPlane+'.tx' ) cmds.connectAttr( md + '.outputY', pPlane+'.ty' ) cmds.parent( pPlane, sliderBase.name() ) if colorIndex: cmds.setAttr( slider.name() + '.overrideEnabled', 1 ) cmds.setAttr( slider.name() + '.overrideColor', colorIndex ) cmds.setAttr( sliderBase.name() + '.overrideEnabled', 1 ) cmds.setAttr( sliderBase.name() + '.overrideColor', 1 ) mouthShader = cmds.shadingNode( 'lambert', asShader=1 ) mouthShaderSg = cmds.sets( renderable=True, noSurfaceShader=True, empty=1, n=mouthShader + 'SG' ) cmds.connectAttr( mouthShader + '.outColor', mouthShaderSg + '.surfaceShader' ) cmds.sets( pPlane, e=1, forceElement = mouthShaderSg ) eyeFileNode, textureNode = sgCmds.createTextureFileNode( texturePath ) cmds.connectAttr( eyeFileNode + '.outColor', mouthShader + '.color' ) cmds.transformLimits( slider.name(), tx=[0,5], etx=[1,1], ty=[0,4], ety=[1,1] ) return slider, sliderBaseParent
from sgMaya import sgCmds, sgModel import pymel.core sels = pymel.core.ls( sl=1 ) for sel in sels: selIndex = sels.index( sel ) cvs = pymel.core.ls( sel + '.cv[*]', fl=1 ) for cv in cvs: pos = pymel.core.xform( cv, q=1, ws=1, t=1 )[:3] ctl = sgCmds.makeController( sgModel.Controller.spherePoints, 1, makeParent=1, n='Ctl_detail_%d_%d' %( selIndex, cv.index() ) ) ctlP = ctl.getParent() ctlP.t.set( pos ) dcmp = pymel.core.createNode( 'decomposeMatrix' ) ctl.wm >> dcmp.imat dcmp.ot >> sel.getShape().attr( 'controlPoints[%d]' % cv.index() )
from sgMaya import sgCmds, sgModel sels = pymel.core.ls(sl=1) geo = sels[0] ctl = sels[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)
from sgMaya import sgCmds, sgModel import pymel.core sels = pymel.core.ls(sl=1) ctls = [] for sel in sels: ctlCurtain = sgCmds.makeController(sgModel.Controller.spherePoints, 1, makeParent=1, n=sel.replace('detail', 'Curtain')) pymel.core.xform(ctlCurtain.getParent(), ws=1, matrix=sel.wm.get()) ctls.append(ctlCurtain) pymel.core.select(ctls)
from sgMaya import sgCmds, sgModel sels = pymel.core.ls( sl=1 ) geo = sels[0] ctl = sels[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 )
from sgMaya import sgCmds, sgModel import pymel.core sels = pymel.core.ls( sl=1 ) moveCtls = [] for sel in sels: bb = pymel.core.exactWorldBoundingBox( sel.getShape() ) xDist = bb[3]-bb[0] yDist = bb[4]-bb[1] zDist = bb[5]-bb[2] size = max( xDist, yDist, zDist ) moveCtl = sgCmds.makeController( sgModel.Controller.pinPoints, size / 1.5, makeParent=1 ) if xDist == size: moveCtl.getShape() moveCtl.rename( sel + '_move' ) moveCtl.getParent().setParent( sel ) sgCmds.setTransformDefault( moveCtl.getParent() ) moveCtls.append( moveCtl ) pymel.core.select( moveCtls )
from sgMaya import sgModel, sgCmds import pymel.core sels = pymel.core.ls( sl=1 ) mtx = sgCmds.getMatrixFromSelection( sels ) circleR = sgCmds.makeController( sgModel.Controller.circlePoints ) circleG = sgCmds.makeController( sgModel.Controller.circlePoints ) circleB = sgCmds.makeController( sgModel.Controller.circlePoints ) lineR = sgCmds.makeController( sgModel.Controller.linePoints ) lineG = sgCmds.makeController( sgModel.Controller.linePoints ) lineB = sgCmds.makeController( sgModel.Controller.linePoints ) base = sgCmds.makeController( sgModel.Controller.planPoints ) circleR.setAttr( 'shape_sx', 0.08 );circleR.setAttr( 'shape_sy', 0.16 );circleR.setAttr( 'shape_sz', 0.16 ) circleG.setAttr( 'shape_sx', 0.08 );circleG.setAttr( 'shape_sy', 0.16 );circleG.setAttr( 'shape_sz', 0.16 ) circleB.setAttr( 'shape_sx', 0.08 );circleB.setAttr( 'shape_sy', 0.16 );circleB.setAttr( 'shape_sz', 0.16 ) lineR.setAttr( 'shape_sz', 0.01 );lineR.setAttr( 'tz', -0.5 ) lineG.setAttr( 'shape_sz', 0.01 );lineG.setAttr( 'tz', 0.0 ) lineB.setAttr( 'shape_sz', 0.01 );lineB.setAttr( 'tz', 0.5 ) base.setAttr( 'shape_sx', 1.5 ) pCircleR = sgCmds.makeParent( circleR );pCircleR.setAttr( 'tx', -1 );pCircleR.setAttr( 'tz', -0.5 );pCircleR.setAttr( 'sx', 2 ) pCircleG = sgCmds.makeParent( circleG );pCircleG.setAttr( 'tx', -1 );pCircleG.setAttr( 'tz', 0.0 );pCircleG.setAttr( 'sx', 2 ) pCircleB = sgCmds.makeParent( circleB );pCircleB.setAttr( 'tx', -1 );pCircleB.setAttr( 'tz', 0.5 );pCircleB.setAttr( 'sx', 2 ) pymel.core.parent( pCircleR, pCircleG, pCircleB, lineR, lineG, lineB, base ) cmds.transformLimits( circleR.name(), tx=[0,1], etx=[1,1] ) cmds.transformLimits( circleG.name(), tx=[0,1], etx=[1,1] ) cmds.transformLimits( circleB.name(), tx=[0,1], etx=[1,1] )
import pymel.core from sgMaya import sgCmds, sgModel sels = pymel.core.ls(sl=1) for sel in sels: endCtl = sel bb = pymel.core.exactWorldBoundingBox(endCtl) bbmin = sgCmds.getMPoint(bb[:3]) bbmax = sgCmds.getMPoint(bb[3:]) dist = bbmin.distanceTo(bbmax) mainCtl = sgCmds.makeController(sgModel.Controller.diamondPoints, dist / 4.0, makeParent=1) pMainCtl = mainCtl.getParent() pymel.core.xform(pMainCtl, ws=1, matrix=sels[0].wm.get()) mainCtl.rename('_'.join(endCtl.split('_')[:-1]) + '_main') firstCtl = pymel.core.ls('_'.join(endCtl.split('_')[:-1]) + '_0')[0] pFirstCtl = firstCtl.getParent() 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)
def getXYSlider(width, height, colorIndex=None, texturePath=''): slider = sgCmds.makeController(sgModel.Controller.move2Points, 0.5) sliderBase = sgCmds.SliderBase().create('xy') pymel.core.parent(slider, sliderBase) cmds.rename(sliderBase.name(), 'Ctl_Facial') cmds.transformLimits(slider.name(), tx=[0, 1], etx=[1, 0]) cmds.transformLimits(slider.name(), ty=[0, 1], ety=[1, 0]) keyAttrs = cmds.listAttr(slider.name(), k=1, sn=1) if not keyAttrs: keyAttrs = [] chAttrs = cmds.listAttr(slider.name(), cb=1, sn=1) if not chAttrs: chAttrs = [] keyAttrs += chAttrs for keyAttr in keyAttrs: if keyAttr in ['tx', 'ty']: continue cmds.setAttr(slider.attr(keyAttr).name(), e=1, lock=1, k=0) cmds.setAttr(slider.attr(keyAttr).name(), e=1, cb=0) sliderBaseParent = sgCmds.makeParent(sliderBase) pymel.core.select(sliderBaseParent) sliderBase.setAttr('slideSizeX', width) sliderBase.setAttr('slideSizeY', height) pPlane = cmds.polyPlane(w=1, h=1, sx=1, sy=1, ax=[0, 0, 1], cuv=2, ch=1)[0] shape = cmds.listRelatives(pPlane, s=1, f=1)[0] cmds.setAttr(shape + '.castsShadows', 0) cmds.setAttr(shape + '.receiveShadows', 0) cmds.setAttr(shape + '.motionBlur', 0) cmds.setAttr(shape + '.primaryVisibility', 0) cmds.setAttr(shape + '.smoothShading', 0) cmds.setAttr(shape + '.visibleInReflections', 0) cmds.setAttr(shape + '.visibleInRefractions', 0) cmds.setAttr(pPlane + '.overrideEnabled', 1) cmds.setAttr(pPlane + '.overrideDisplayType', 2) av = cmds.createNode('plusMinusAverage') md = cmds.createNode('multiplyDivide') cmds.connectAttr( sliderBase.attr('slideSizeX').name(), av + '.input2D[0].input2Dx') cmds.connectAttr( sliderBase.attr('slideSizeY').name(), av + '.input2D[0].input2Dy') cmds.setAttr(av + '.input2D[1].input2Dx', 1) cmds.setAttr(av + '.input2D[1].input2Dy', 1) cmds.connectAttr(sliderBase.attr('slideSizeX').name(), md + '.input1X') cmds.connectAttr(sliderBase.attr('slideSizeY').name(), md + '.input1Y') cmds.setAttr(md + '.input2X', 0.5) cmds.setAttr(md + '.input2Y', 0.5) cmds.connectAttr(av + '.output2Dx', pPlane + '.sx') cmds.connectAttr(av + '.output2Dy', pPlane + '.sy') cmds.connectAttr(md + '.outputX', pPlane + '.tx') cmds.connectAttr(md + '.outputY', pPlane + '.ty') cmds.parent(pPlane, sliderBase.name()) if colorIndex: cmds.setAttr(slider.name() + '.overrideEnabled', 1) cmds.setAttr(slider.name() + '.overrideColor', colorIndex) cmds.setAttr(sliderBase.name() + '.overrideEnabled', 1) cmds.setAttr(sliderBase.name() + '.overrideColor', 1) mouthShader = cmds.shadingNode('lambert', asShader=1) mouthShaderSg = cmds.sets(renderable=True, noSurfaceShader=True, empty=1, n=mouthShader + 'SG') cmds.connectAttr(mouthShader + '.outColor', mouthShaderSg + '.surfaceShader') cmds.sets(pPlane, e=1, forceElement=mouthShaderSg) eyeFileNode, textureNode = sgCmds.createTextureFileNode(texturePath) cmds.connectAttr(eyeFileNode + '.outColor', mouthShader + '.color') cmds.transformLimits(slider.name(), tx=[0, 5], etx=[1, 1], ty=[0, 4], ety=[1, 1]) return slider, sliderBaseParent
from sgMaya import sgCmds, sgModel import pymel.core sels = pymel.core.ls( sl=1 ) target = sels[0] pymel.core.delete( target.getShape() ) circle = sgCmds.makeController( sgModel.Controller.circlePoints, 5 ) circle.shape_rz.set( 90 ) pymel.core.parent( circle.getShape(), target, add=1, shape=1 ) sgCmds.setIndexColor( target, 13 ) pymel.core.refresh() pymel.core.delete( circle ) pymel.core.select( target )
from sgMaya import sgCmds, sgModel import pymel.core sels = pymel.core.ls(sl=1) for sel in sels: selIndex = sels.index(sel) cvs = pymel.core.ls(sel + '.cv[*]', fl=1) for cv in cvs: pos = pymel.core.xform(cv, q=1, ws=1, t=1)[:3] ctl = sgCmds.makeController(sgModel.Controller.spherePoints, 1, makeParent=1, n='Ctl_detail_%d_%d' % (selIndex, cv.index())) ctlP = ctl.getParent() ctlP.t.set(pos) dcmp = pymel.core.createNode('decomposeMatrix') ctl.wm >> dcmp.imat dcmp.ot >> sel.getShape().attr('controlPoints[%d]' % cv.index())
import pymel.core from sgMaya import sgCmds, sgModel sels = pymel.core.ls( sl=1 ) for sel in sels: endCtl = sel bb = pymel.core.exactWorldBoundingBox( endCtl ) bbmin = sgCmds.getMPoint( bb[:3] ) bbmax = sgCmds.getMPoint( bb[3:] ) dist = bbmin.distanceTo( bbmax ) mainCtl = sgCmds.makeController( sgModel.Controller.diamondPoints, dist/4.0, makeParent=1 ) pMainCtl = mainCtl.getParent() pymel.core.xform( pMainCtl, ws=1, matrix= sels[0].wm.get() ) mainCtl.rename( '_'.join( endCtl.split( '_' )[:-1] ) + '_main' ) firstCtl = pymel.core.ls( '_'.join( endCtl.split( '_' )[:-1] ) + '_0' )[0] pFirstCtl = firstCtl.getParent() 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 )
from sgMaya import sgCmds, sgModel import pymel.core sels = pymel.core.ls(sl=1) for sel in sels: bb = pymel.core.exactWorldBoundingBox(sel) bbmin = bb[:3] bbmax = bb[-3:] xLength = bbmax[0] - bbmin[0] zLength = bbmax[2] - bbmin[2] bbc = [(bbmin[i] + bbmax[i]) / 2.0 for i in range(3)] maxLength = max([xLength, zLength]) ctl = sgCmds.makeController(sgModel.Controller.circlePoints, maxLength / 2.0 * 1.2, makeParent=1) ctl.getParent().t.set(bbc) ctl.rename('Ctl_%s' % sel.name()) sgCmds.setIndexColor(ctl, 29) sgCmds.setGeometryMatrixToTarget(sel, ctl) sgCmds.constrain(ctl, sel, ct=1, cr=1, cs=1, csh=1)
import pymel.core from sgMaya import sgCmds, sgModel sels = pymel.core.ls( sl=1 ) newCtls = [] for sel in sels: subCtl = sel.message.listConnections( s=0, d=1, p=1 )[0] mm = subCtl.node().wm.listConnections( s=0, d=1, type='multMatrix' )[0] dcmp = mm.o.listConnections( s=0, d=1, type='decomposeMatrix' )[0] jnt = dcmp.listConnections( s=0, d=1, type='transform' )[0] moveSubCtl = pymel.core.createNode( 'transform' ) moveSubCtl.setParent( subCtl.node() ) sgCmds.setTransformDefault( moveSubCtl ) moveCtl = sgCmds.makeController( sgModel.Controller.pinPoints, 2, makeParent=1, n=sel + '_Move' ) moveCtl.t >> moveSubCtl.t moveCtl.r >> moveSubCtl.r moveCtl.s >> moveSubCtl.s moveCtl.getParent().setParent( sel ) sgCmds.setTransformDefault( moveCtl.getParent() ) newCtls.append( moveCtl ) pymel.core.delete( dcmp ) sgCmds.constrain( moveSubCtl, jnt, ct=1, cr=1, cs=1, csh=1) pymel.core.select( newCtls )