def createControlOverride(transform, prefix=None): """ Create mocap anim override transforms for the specified control transform. @param transform: Control transform to create mocap override transforms for @type transform: str @param prefix: Name prefix for override nodes created by function. If empty, prefix is taken from the input transform name. @type prefix: str """ # ========== # - Checks - # ========== if not cmds.objExists(transform): raise Exception('Rig control transform "' + transform + '" does not exist!') if not prefix: prefix = glTools.utils.stringUtils.stripSuffix(transform) # ====================================== # - Create Control Override Transforms - # ====================================== overrideTarget = buildOverrideTransform(transform, prefix=prefix + '_overrideTarget') overrideTransform = buildOverrideTransform(transform, prefix=prefix + '_overrideTransform') # Set Channel States channelState = glTools.utils.channelState.ChannelState() channelState.setFlags([0, 0, 0, 0, 0, 0, 2, 2, 2, 1], objectList=[overrideTarget]) channelState.setFlags([1, 1, 1, 1, 1, 1, 2, 2, 2, 1], objectList=[overrideTransform]) channelState.set(1, [overrideTarget, overrideTransform]) # Parent Control to Override Transform cmds.parent(transform, overrideTransform) # ====================================== # - Create Control Override Constraint - # ====================================== # Create ParentConstraint overrideConstraint = \ cmds.parentConstraint(overrideTarget, overrideTransform, n=prefix + '_overrideTransform_parentConstraint')[0] overrideAlias = cmds.parentConstraint(overrideConstraint, q=True, wal=True) # Reset Rest Values cmds.setAttr(overrideConstraint + '.restTranslate', 0, 0, 0) cmds.setAttr(overrideConstraint + '.restRotate', 0, 0, 0) # ========================== # - Create Override Toggle - # ========================== # Create Toggle Attribute overrideAttr = overrideAttribute() if cmds.objExists(transform + '.' + overrideAttr): cmds.deleteAttr(transform + '.' + overrideAttr) cmds.addAttr(transform, ln=overrideAttr, at='bool') cmds.setAttr(transform + '.' + overrideAttr, False) # Connect Toggle Attribute cmds.connectAttr(transform + '.' + overrideAttr, overrideConstraint + '.' + overrideAlias[0], f=True) # ========================== # - Create Override Offset - # ========================== offsetAttr = overrideOffsetAttribute() if cmds.objExists(transform + '.' + offsetAttr): cmds.deleteAttr(transform + '.' + offsetAttr) cmds.addAttr(transform, ln=offsetAttr, at='double3') cmds.addAttr(transform, ln=offsetAttr + 'X', at='double', p=offsetAttr, dv=0) cmds.addAttr(transform, ln=offsetAttr + 'Y', at='double', p=offsetAttr, dv=0) cmds.addAttr(transform, ln=offsetAttr + 'Z', at='double', p=offsetAttr, dv=0) # Connect Offset cmds.connectAttr(transform + '.' + offsetAttr, overrideConstraint + '.target[0].targetOffsetTranslate', f=True) # ================= # - Return Result - # ================= result = {} result['overrideTarget'] = overrideTarget result['overrideTransform'] = overrideTransform result['overrideConstraint'] = overrideConstraint return result
def addTarget(parentCtrl, targetTransform, matchTransform='', label=''): ''' Add a constraint target to a specified constraint target control parent transform @param parentCtrl: Parent constraint target control to add constraint target to @type parentCtrl: str @param targetTransform: Constraint target transform @type targetTransform: str @param matchTransform: The transform to match the new constraint target transform to. Used to set specific orientational and translational offsets. @type matchTransform: str @param label: Constraint target label @type label: str ''' # ========== # - Checks - # ========== # Check Parent Control if not mc.objExists(parentCtrl + '.constraintTarget'): raise Exception( 'Object "' + parentCtrl + '" is not a valid constraint target control parent transform!') # Check Constraint Target List constraintTargetList = getConstraintTargets(parentCtrl) if constraintTargetList.count(targetTransform): raise Exception('Constraint target control "' + parentCtrl + '" is already connected to target "' + targetTransform + '"!') if matchTransform and not mc.objExists(matchTransform): raise Exception('Constraint target match transform "' + matchTransform + '" does not exist!') # Check Target Label if mc.objExists(targetTransform + '.targetLabel'): targetLabelCon = mc.listConnections(targetTransform + '.targetLabel', s=True, d=False) if targetLabelCon: raise Exception('Target transform "' + targetTransform + '" is already a constraint target!') # ========================= # - Add Constraint Target - # ========================= # Create Label Annotation targetShape = mc.createNode('annotationShape', n=targetTransform + '_targetShape') target = mc.listRelatives(targetShape, p=True, pa=True)[0] target = mc.rename(target, targetTransform + '_target') mc.parent(target, targetTransform) glTools.utils.colorize.setColour(targetShape) # Set Annotation Attributes mc.setAttr(targetShape + '.text', label, type='string') mc.setAttr(targetShape + '.displayArrow', 0, l=True) # Add Label String Attribute if not mc.objExists(target + '.label'): mc.addAttr(target, ln='label', dt='string') mc.setAttr(target + '.label', label, type='string', l=True) # Connect Label to Target Transform if not mc.objExists(targetTransform + '.targetLabel'): mc.addAttr(targetTransform, ln='targetLabel', at='message') mc.connectAttr(target + '.message', targetTransform + '.targetLabel', f=True) # Match Transform if matchTransform: glTools.utils.transform.match(target, matchTransform) else: glTools.utils.transform.match(target, targetTransform) # Set Channel State channelState = glTools.utils.channelState.ChannelState() channelState.setFlags([2, 2, 2, 2, 2, 2, 2, 2, 2, 1], objectList=[target]) # ============================= # - Connect to Parent Control - # ============================= # Connect Label Vis mc.connectAttr(parentCtrl + '.displayLabels', targetShape + '.v', f=True) # Connect Target Message connIndex = mc.getAttr(parentCtrl + '.constraintTarget', s=True) mc.connectAttr(targetTransform + '.message', parentCtrl + '.constraintTarget[' + str(connIndex) + ']', f=True) # Connect Label Message connIndex = mc.getAttr(parentCtrl + '.constraintLabel', s=True) mc.connectAttr(target + '.message', parentCtrl + '.constraintLabel[' + str(connIndex) + ']', f=True) # ================= # - Return Result - # ================= return target
def addTarget(parentCtrl,targetTransform,matchTransform='',label=''): ''' Add a constraint target to a specified constraint target control parent transform @param parentCtrl: Parent constraint target control to add constraint target to @type parentCtrl: str @param targetTransform: Constraint target transform @type targetTransform: str @param matchTransform: The transform to match the new constraint target transform to. Used to set specific orientational and translational offsets. @type matchTransform: str @param label: Constraint target label @type label: str ''' # ========== # - Checks - # ========== # Check Parent Control if not mc.objExists(parentCtrl+'.constraintTarget'): raise Exception('Object "'+parentCtrl+'" is not a valid constraint target control parent transform!') # Check Constraint Target List constraintTargetList = getConstraintTargets(parentCtrl) if constraintTargetList.count(targetTransform): raise Exception('Constraint target control "'+parentCtrl+'" is already connected to target "'+targetTransform+'"!') if matchTransform and not mc.objExists(matchTransform): raise Exception('Constraint target match transform "'+matchTransform+'" does not exist!') # Check Target Label if mc.objExists(targetTransform+'.targetLabel'): targetLabelCon = mc.listConnections(targetTransform+'.targetLabel',s=True,d=False) if targetLabelCon: raise Exception('Target transform "'+targetTransform+'" is already a constraint target!') # ========================= # - Add Constraint Target - # ========================= # Create Label Annotation targetShape = mc.createNode('annotationShape',n=targetTransform+'_targetShape') target = mc.listRelatives(targetShape,p=True,pa=True)[0] target = mc.rename(target,targetTransform+'_target') mc.parent(target,targetTransform) glTools.utils.colorize.setColour(targetShape) # Set Annotation Attributes mc.setAttr(targetShape+'.text',label,type='string') mc.setAttr(targetShape+'.displayArrow',0,l=True) # Add Label String Attribute if not mc.objExists(target+'.label'): mc.addAttr(target,ln='label',dt='string') mc.setAttr(target+'.label',label,type='string',l=True) # Connect Label to Target Transform if not mc.objExists(targetTransform+'.targetLabel'): mc.addAttr(targetTransform,ln='targetLabel',at='message') mc.connectAttr(target+'.message',targetTransform+'.targetLabel',f=True) # Match Transform if matchTransform: glTools.utils.transform.match(target,matchTransform) else: glTools.utils.transform.match(target,targetTransform) # Set Channel State channelState = glTools.utils.channelState.ChannelState() channelState.setFlags([2,2,2,2,2,2,2,2,2,1],objectList=[target]) # ============================= # - Connect to Parent Control - # ============================= # Connect Label Vis mc.connectAttr(parentCtrl+'.displayLabels',targetShape+'.v',f=True) # Connect Target Message connIndex = mc.getAttr(parentCtrl+'.constraintTarget',s=True) mc.connectAttr(targetTransform+'.message',parentCtrl+'.constraintTarget['+str(connIndex)+']',f=True) # Connect Label Message connIndex = mc.getAttr(parentCtrl+'.constraintLabel',s=True) mc.connectAttr(target+'.message',parentCtrl+'.constraintLabel['+str(connIndex)+']',f=True) # ================= # - Return Result - # ================= return target
def createControlOverride(transform, prefix=None): ''' Create mocap anim override transforms for the specified control transform. @param transform: Control transform to create mocap override transforms for @type transform: str @param prefix: Name prefix for override nodes created by function. If empty, prefix is taken from the input transform name. @type prefix: str ''' # ========== # - Checks - # ========== if not mc.objExists(transform): raise Exception('Rig control transform "' + transform + '" does not exist!') if not prefix: prefix = glTools.utils.stringUtils.stripSuffix(transform) # ====================================== # - Create Control Override Transforms - # ====================================== overrideTarget = buildOverrideTransform(transform, prefix=prefix + '_overrideTarget') overrideTransform = buildOverrideTransform(transform, prefix=prefix + '_overrideTransform') # Set Channel States channelState = glTools.utils.channelState.ChannelState() channelState.setFlags([0, 0, 0, 0, 0, 0, 2, 2, 2, 1], objectList=[overrideTarget]) channelState.setFlags([1, 1, 1, 1, 1, 1, 2, 2, 2, 1], objectList=[overrideTransform]) channelState.set(1, [overrideTarget, overrideTransform]) # Parent Control to Override Transform mc.parent(transform, overrideTransform) # ====================================== # - Create Control Override Constraint - # ====================================== # Create ParentConstraint overrideConstraint = mc.parentConstraint( overrideTarget, overrideTransform, n=prefix + '_overrideTransform_parentConstraint')[0] overrideAlias = mc.parentConstraint(overrideConstraint, q=True, wal=True) # Reset Rest Values mc.setAttr(overrideConstraint + '.restTranslate', 0, 0, 0) mc.setAttr(overrideConstraint + '.restRotate', 0, 0, 0) # ========================== # - Create Override Toggle - # ========================== # Create Toggle Attribute overrideAttr = overrideAttribute() if mc.objExists(transform + '.' + overrideAttr): mc.deleteAttr(transform + '.' + overrideAttr) mc.addAttr(transform, ln=overrideAttr, at='bool') mc.setAttr(transform + '.' + overrideAttr, False) # Connect Toggle Attribute mc.connectAttr(transform + '.' + overrideAttr, overrideConstraint + '.' + overrideAlias[0], f=True) # ========================== # - Create Override Offset - # ========================== offsetAttr = overrideOffsetAttribute() if mc.objExists(transform + '.' + offsetAttr): mc.deleteAttr(transform + '.' + offsetAttr) mc.addAttr(transform, ln=offsetAttr, at='double3') mc.addAttr(transform, ln=offsetAttr + 'X', at='double', p=offsetAttr, dv=0) mc.addAttr(transform, ln=offsetAttr + 'Y', at='double', p=offsetAttr, dv=0) mc.addAttr(transform, ln=offsetAttr + 'Z', at='double', p=offsetAttr, dv=0) # Connect Offset mc.connectAttr(transform + '.' + offsetAttr, overrideConstraint + '.target[0].targetOffsetTranslate', f=True) # ================= # - Return Result - # ================= result = {} result['overrideTarget'] = overrideTarget result['overrideTransform'] = overrideTransform result['overrideConstraint'] = overrideConstraint return result