class fn:
def eye_rig(self, eyeObj,eyeTarget,controllers):
"Create EyeRig weighted between target (via aimContraint) and animation override"
# Create control hierarchy of groups or locators:
#controllers = ['anim','aim','out']
controlsList = []
testing = 0
# For each controller, create a locator and add it to the list of controllers
for control in controllers:
objTmp = eyeObj+'_'+control
cmds.spaceLocator(n=objTmp)
controlsList.append(objTmp)
#Final control (last item in list) will receive all the rotations and pass them to the eye via parentConstraint.
# It will have UD attrs to weight inputs of other controls
finalControl = controlsList[-1]
# For each controller, we'll create a multDiv. We pipe the control's rotation into the md, weight it w/UD attr on 'out' object.
# Rotations coming out of multDivs are added w/pma node and passed to 'out' object
# Create pma node first, so md can be connected when created:
sumNodeTmp = cmds.createNode('plusMinusAverage',n=eyeObj+'eyeRo t_sum')
print 'sumNodeTmp:',sumNodeTmp
# Summed rotations piped into 'out.rotate' (This is the last item in the 'controlsList' List):
cmds.connectAttr(sumNodeTmp+'.output3D',finalControl +'.rotate',force=1)
# Create _md node for each controller rotations, pipe intorotation sum
count = 0
while count < (len(controlsList)-1):
nodeTmp = controlsList[count]
attrTmp = controllers[count]
print 'nodeTmp:',nodeTmp
# For each controller, create a MultDiv to weight the rotation.
# They will be weighted by a custom attr on the 'out' object:
mdTmp = cmds.createNode('multiplyDivide',n=nodeTmp+'_md')
# Connect rotations to multDiv.input1 (more rotationinfluences can be added)
cmds.connectAttr(nodeTmp+'.rotate',mdTmp+'.input1' ,force=1)
# Pipe the md output to the rotation sum:
connectAttr(mdTmp+'.output',sumNodeTmp+'.input3D['+str(count)+']',force=1)
# Create UD attrs on 'out' (last item in list)to weight therotations of each controller.
# Pipe UD into the corresponding md nodes.
# Create UD Attrs on 'out'
cmds.addAttr(finalControl,ln=attrTmp,min=0,max=1,dv=1,at='float')
cmds.setAttr (finalControl+'.'+attrTmp, e=1, keyable=1)# Ifnot keyable, won't show in channel box
# Connect Anim, Aim to inputs of respective multDiv:
connectAttrsTmp =['2X','2Y','2Z']
for tmpConnectAttr in connectAttrsTmp:
cmds.connectAttr(finalControl+'.'+attrTmp,mdTmp+'.input'+tmpConnectAttr)
# If test, offset the controllers for visual testing:
if testing:
cmds.setAttr(nodeTmp+'.translateX',count+0.5)
count += 1
# Group the controllers
eyeRigGroupTmp = cmds.group(controlsList, n = eyeObj+'_eyeDir_grp')
# Position the eyeRig at the eye
self.parentUnparent (eyeObj,eyeRigGroupTmp)
# Setup aimConstraint for eye
cmds.aimConstraint (eyeTarget,eyeObj+'_aim',offset = [0, 0, 0],w = 1, aimVector = [1,0,0], upVector = [0,1,0], worldUpType ='vector', worldUpVector = [0,1,0])
# Constrain Eye to "out" control
cmds.parentConstraint (eyeObj,finalControl, offset = (0, 0,0 ), w = 1)
def parentUnparent(self, parent,children):
# Use temporary point-, scale- constraints to snap parent tofuture child
delete( cmds.pointConstraint (parent, children, offset = (0, 0,0 ), w = 1) )
delete( cmds.orientConstraint (parent, children, offset = (0,0, 0 ), w = 1) )
delete( cmds.scaleConstraint (parent, children, offset = (1, 1,1 ), w = 1) )
ins = fn()
ins.eye_rig('testX_eyeL','testX_eyeL_tgt',['anim','aim','out'])
--
http://
thatboy.me