def __init__(self, name='leg', parent=None, *args, **kwargs): Profiler.getInstance().push("Construct Leg Guide Component:" + name) super(LegComponentGuide, self).__init__(name, parent, *args, **kwargs) # ========= # Controls # ========= guideSettingsAttrGrp = AttributeGroup("GuideSettings", parent=self) # Guide Controls self.femurCtrl = Control('femur', parent=self.ctrlCmpGrp, shape="sphere") self.kneeCtrl = Control('knee', parent=self.ctrlCmpGrp, shape="sphere") self.ankleCtrl = Control('ankle', parent=self.ctrlCmpGrp, shape="sphere") armGuideSettingsAttrGrp = AttributeGroup("DisplayInfo_ArmSettings", parent=self.femurCtrl) self.armGuideDebugAttr = BoolAttribute('drawDebug', value=True, parent=armGuideSettingsAttrGrp) self.guideOpHost = Transform('guideOpHost', self.ctrlCmpGrp) # Guide Operator self.legGuideKLOp = KLOperator('guide', 'TwoBoneIKGuideSolver', 'Kraken') self.addOperator(self.legGuideKLOp) # Add Att Inputs self.legGuideKLOp.setInput('drawDebug', self.armGuideDebugAttr) self.legGuideKLOp.setInput('rigScale', self.rigScaleInputAttr) # Add Source Inputs self.legGuideKLOp.setInput('root', self.femurCtrl) self.legGuideKLOp.setInput('mid', self.kneeCtrl) self.legGuideKLOp.setInput('end', self.ankleCtrl) # Add Target Outputs self.legGuideKLOp.setOutput('guideOpHost', self.guideOpHost) self.default_data = { "name": name, "location": "L", "createIKHandle": False, "femurXfo": Xfo(Vec3(1.0, 9.75, -0.5)), "kneeXfo": Xfo(Vec3(1.5, 5.5, -0.5)), "ankleXfo": Xfo(Vec3(1.75, 1.15, -1.25)) } self.loadData(self.default_data) Profiler.getInstance().pop()
def setNumTransforms(self, numTransforms): numTransforms += 1 # Add more transforms if numTransforms > len(self.transforms): for i in xrange(len(self.transforms), numTransforms): name = 'transform' + str(i + 1).zfill(2) transform = Transform(name, parent=self.outputHrcGrp) self.transforms.append(transform) # Remove extra transforms elif numTransforms < len(self.transforms): numExtraTransforms = len(self.transforms) - numTransforms for i in xrange(numExtraTransforms): extraTransform = self.transforms.pop() extraTransform.getParent().removeChild(extraTransform) return True
def __init__(self, name='head', parent=None): Profiler.getInstance().push("Construct Head Rig Component:" + name) super(HeadComponentRig, self).__init__(name, parent) # ========= # Controls # ========= # Head self.headCtrl = Control('head', parent=self.ctrlCmpGrp, shape='circle') self.headCtrl.lockScale(x=True, y=True, z=True) self.headCtrl.lockTranslation(x=True, y=True, z=True) self.headCtrlSpace = self.headCtrl.insertCtrlSpace() self.headCtrl.rotatePoints(0, 0, 90) self.headCtrl.scalePoints(Vec3(3, 3, 3)) self.headCtrl.translatePoints(Vec3(0, 1, 0.25)) # Eye Left self.eyeLeftCtrl = Control('eyeLeft', parent=self.ctrlCmpGrp, shape='sphere') self.eyeLeftCtrl.lockScale(x=True, y=True, z=True) self.eyeLeftCtrl.lockTranslation(x=True, y=True, z=True) self.eyeLeftCtrlSpace = self.eyeLeftCtrl.insertCtrlSpace() self.eyeLeftCtrl.rotatePoints(0, 90, 0) self.eyeLeftCtrl.scalePoints(Vec3(0.5, 0.5, 0.5)) self.eyeLeftCtrl.setColor('blueMedium') # Eye Right self.eyeRightCtrl = Control('eyeRight', parent=self.ctrlCmpGrp, shape='sphere') self.eyeRightCtrl.lockScale(x=True, y=True, z=True) self.eyeRightCtrl.lockTranslation(x=True, y=True, z=True) self.eyeRightCtrlSpace = self.eyeRightCtrl.insertCtrlSpace() self.eyeRightCtrl.rotatePoints(0, 90, 0) self.eyeRightCtrl.scalePoints(Vec3(0.5, 0.5, 0.5)) self.eyeRightCtrl.setColor('blueMedium') # LookAt Control self.lookAtCtrl = Control('lookAt', parent=self.ctrlCmpGrp, shape='square') self.lookAtCtrl.lockScale(x=True, y=True, z=True) self.lookAtCtrl.rotatePoints(90, 0, 0) self.lookAtCtrlSpace = self.lookAtCtrl.insertCtrlSpace() self.eyeLeftBase = Transform('eyeLeftBase', parent=self.headCtrl) self.eyeRightBase = Transform('eyeRightBase', parent=self.headCtrl) self.eyeLeftUpV = Transform('eyeLeftUpV', parent=self.headCtrl) self.eyeRightUpV = Transform('eyeRightUpV', parent=self.headCtrl) self.eyeLeftAtV = Transform('eyeLeftAtV', parent=self.lookAtCtrl) self.eyeRightAtV = Transform('eyeRightAtV', parent=self.lookAtCtrl) # Jaw self.jawCtrl = Control('jaw', parent=self.headCtrl, shape='cube') self.jawCtrlSpace = self.jawCtrl.insertCtrlSpace() self.jawCtrl.lockScale(x=True, y=True, z=True) self.jawCtrl.lockTranslation(x=True, y=True, z=True) self.jawCtrl.alignOnYAxis(negative=True) self.jawCtrl.alignOnZAxis() self.jawCtrl.scalePoints(Vec3(1.45, 0.65, 1.25)) self.jawCtrl.translatePoints(Vec3(0, -0.25, 0)) self.jawCtrl.setColor('orange') # ========== # Deformers # ========== deformersLayer = self.getOrCreateLayer('deformers') self.defCmpGrp = ComponentGroup(self.getName(), self, parent=deformersLayer) self.addItem('defCmpGrp', self.defCmpGrp) headDef = Joint('head', parent=self.defCmpGrp) headDef.setComponent(self) jawDef = Joint('jaw', parent=self.defCmpGrp) jawDef.setComponent(self) eyeLeftDef = Joint('eyeLeft', parent=self.defCmpGrp) eyeLeftDef.setComponent(self) eyeRightDef = Joint('eyeRight', parent=self.defCmpGrp) eyeRightDef.setComponent(self) # ============== # Constrain I/O # ============== # Constraint inputs self.headInputConstraint = PoseConstraint('_'.join([ self.headCtrlSpace.getName(), 'To', self.neckRefInputTgt.getName() ])) self.headInputConstraint.setMaintainOffset(True) self.headInputConstraint.addConstrainer(self.neckRefInputTgt) self.headCtrlSpace.addConstraint(self.headInputConstraint) # Constraint outputs self.headOutputConstraint = PoseConstraint('_'.join( [self.headOutputTgt.getName(), 'To', self.headCtrl.getName()])) self.headOutputConstraint.addConstrainer(self.headCtrl) self.headOutputTgt.addConstraint(self.headOutputConstraint) self.jawOutputConstraint = PoseConstraint('_'.join( [self.jawOutputTgt.getName(), 'To', self.jawCtrl.getName()])) self.jawOutputConstraint.addConstrainer(self.jawCtrl) self.jawOutputTgt.addConstraint(self.jawOutputConstraint) self.eyeLOutputConstraint = PoseConstraint('_'.join( [self.eyeLOutputTgt.getName(), 'To', self.eyeLeftCtrl.getName()])) self.eyeLOutputConstraint.addConstrainer(self.eyeLeftCtrl) self.eyeLOutputTgt.addConstraint(self.eyeLOutputConstraint) self.eyeROutputConstraint = PoseConstraint('_'.join( [self.eyeROutputTgt.getName(), 'To', self.eyeRightCtrl.getName()])) self.eyeROutputConstraint.addConstrainer(self.eyeRightCtrl) self.eyeROutputTgt.addConstraint(self.eyeROutputConstraint) # Add Eye Left Direction KL Op self.eyeLeftDirKLOp = KLOperator('eyeLeftDirKLOp', 'DirectionConstraintSolver', 'Kraken') self.addOperator(self.eyeLeftDirKLOp) # Add Att Inputs self.eyeLeftDirKLOp.setInput('drawDebug', self.drawDebugInputAttr) self.eyeLeftDirKLOp.setInput('rigScale', self.rigScaleInputAttr) # Add Xfo Inputs self.eyeLeftDirKLOp.setInput('position', self.eyeLeftBase) self.eyeLeftDirKLOp.setInput('upVector', self.eyeLeftUpV) self.eyeLeftDirKLOp.setInput('atVector', self.eyeLeftAtV) # Add Xfo Outputs self.eyeLeftDirKLOp.setOutput('constrainee', self.eyeLeftCtrlSpace) # Add Eye Right Direction KL Op self.eyeRightDirKLOp = KLOperator('eyeRightDirKLOp', 'DirectionConstraintSolver', 'Kraken') self.addOperator(self.eyeRightDirKLOp) # Add Att Inputs self.eyeRightDirKLOp.setInput('drawDebug', self.drawDebugInputAttr) self.eyeRightDirKLOp.setInput('rigScale', self.rigScaleInputAttr) # Add Xfo Inputs self.eyeRightDirKLOp.setInput('position', self.eyeRightBase) self.eyeRightDirKLOp.setInput('upVector', self.eyeRightUpV) self.eyeRightDirKLOp.setInput('atVector', self.eyeRightAtV) # Add Xfo Outputs self.eyeRightDirKLOp.setOutput('constrainee', self.eyeRightCtrlSpace) # Add Deformer Joints KL Op self.outputsToDeformersKLOp = KLOperator('headDeformerKLOp', 'MultiPoseConstraintSolver', 'Kraken') self.addOperator(self.outputsToDeformersKLOp) # Add Att Inputs self.outputsToDeformersKLOp.setInput('drawDebug', self.drawDebugInputAttr) self.outputsToDeformersKLOp.setInput('rigScale', self.rigScaleInputAttr) # Add Xfo Inputs self.outputsToDeformersKLOp.setInput('constrainers', [ self.headOutputTgt, self.jawOutputTgt, self.eyeROutputTgt, self.eyeLOutputTgt ]) # Add Xfo Outputs self.outputsToDeformersKLOp.setOutput( 'constrainees', [headDef, jawDef, eyeRightDef, eyeLeftDef]) Profiler.getInstance().pop()
def __init__(self, name='leg', parent=None): Profiler.getInstance().push("Construct Leg Rig Component:" + name) super(LegComponentRig, self).__init__(name, parent) # ========= # Controls # ========= # Femur self.femurFKCtrlSpace = CtrlSpace('femurFK', parent=self.ctrlCmpGrp) self.femurFKCtrl = Control('femurFK', parent=self.femurFKCtrlSpace, shape="cube") self.femurFKCtrl.alignOnXAxis() self.femurFKCtrl.lockTranslation(True, True, True) self.femurFKCtrl.lockScale(True, True, True) # Shin self.shinFKCtrlSpace = CtrlSpace('shinFK', parent=self.femurFKCtrl) self.shinFKCtrl = Control('shinFK', parent=self.shinFKCtrlSpace, shape="cube") self.shinFKCtrl.alignOnXAxis() self.shinFKCtrl.lockTranslation(True, True, True) self.shinFKCtrl.lockScale(True, True, True) # IK Handle self.legIKCtrlSpace = CtrlSpace('IK', parent=self.ctrlCmpGrp) self.legIKCtrl = Control('IK', parent=self.legIKCtrlSpace, shape="pin") self.legIKCtrl.lockScale(True, True, True) # Add Component Params to IK control legSettingsAttrGrp = AttributeGroup("DisplayInfo_LegSettings", parent=self.legIKCtrl) legDrawDebugInputAttr = BoolAttribute('drawDebug', value=False, parent=legSettingsAttrGrp) self.legRightSideInputAttr = BoolAttribute('rightSide', value=False, parent=legSettingsAttrGrp) self.legBone0LenInputAttr = ScalarAttribute('bone0Len', value=1.0, parent=legSettingsAttrGrp) self.legBone1LenInputAttr = ScalarAttribute('bone1Len', value=1.0, parent=legSettingsAttrGrp) legIKBlendInputAttr = ScalarAttribute('ikblend', value=1.0, minValue=0.0, maxValue=1.0, parent=legSettingsAttrGrp) # Util Objects self.ikRootPosition = Transform("ikRootPosition", parent=self.ctrlCmpGrp) # Connect Input Attrs self.drawDebugInputAttr.connect(legDrawDebugInputAttr) # Connect Output Attrs self.drawDebugOutputAttr.connect(legDrawDebugInputAttr) self.ikBlendOutputAttr.connect(legIKBlendInputAttr) # UpV self.legUpVCtrlSpace = CtrlSpace('UpV', parent=self.ctrlCmpGrp) self.legUpVCtrl = Control('UpV', parent=self.legUpVCtrlSpace, shape="triangle") self.legUpVCtrl.alignOnZAxis() self.legUpVCtrl.lockRotation(True, True, True) self.legUpVCtrl.lockScale(True, True, True) # ========== # Deformers # ========== deformersLayer = self.getOrCreateLayer('deformers') self.defCmpGrp = ComponentGroup(self.getName(), self, parent=deformersLayer) self.addItem('defCmpGrp', self.defCmpGrp) femurDef = Joint('femur', parent=self.defCmpGrp) femurDef.setComponent(self) kneeDef = Joint('knee', parent=self.defCmpGrp) kneeDef.setComponent(self) shinDef = Joint('shin', parent=self.defCmpGrp) shinDef.setComponent(self) # ============== # Constrain I/O # ============== # Constraint inputs self.legIKCtrlSpaceInputConstraint = PoseConstraint('_'.join([self.legIKCtrlSpace.getName(), 'To', self.globalSRTInputTgt.getName()])) self.legIKCtrlSpaceInputConstraint.setMaintainOffset(True) self.legIKCtrlSpaceInputConstraint.addConstrainer(self.globalSRTInputTgt) self.legIKCtrlSpace.addConstraint(self.legIKCtrlSpaceInputConstraint) self.legUpVCtrlSpaceInputConstraint = PoseConstraint('_'.join([self.legUpVCtrlSpace.getName(), 'To', self.globalSRTInputTgt.getName()])) self.legUpVCtrlSpaceInputConstraint.setMaintainOffset(True) self.legUpVCtrlSpaceInputConstraint.addConstrainer(self.globalSRTInputTgt) self.legUpVCtrlSpace.addConstraint(self.legUpVCtrlSpaceInputConstraint) self.legRootInputConstraint = PoseConstraint('_'.join([self.femurFKCtrlSpace.getName(), 'To', self.legPelvisInputTgt.getName()])) self.legRootInputConstraint.setMaintainOffset(True) self.legRootInputConstraint.addConstrainer(self.legPelvisInputTgt) self.femurFKCtrlSpace.addConstraint(self.legRootInputConstraint) self.ikRootPosInputConstraint = PoseConstraint('_'.join([self.ikRootPosition.getName(), 'To', self.legPelvisInputTgt.getName()])) self.ikRootPosInputConstraint.setMaintainOffset(True) self.ikRootPosInputConstraint.addConstrainer(self.legPelvisInputTgt) self.ikRootPosition.addConstraint(self.ikRootPosInputConstraint) # Constraint outputs self.legEndFKOutputConstraint = PoseConstraint('_'.join([self.legEndFKOutputTgt.getName(), 'To', self.shinFKCtrl.getName()])) self.legEndFKOutputConstraint.setMaintainOffset(True) self.legEndFKOutputConstraint.addConstrainer(self.shinFKCtrl) self.legEndFKOutputTgt.addConstraint(self.legEndFKOutputConstraint) self.ikHandleOutputConstraint = PoseConstraint('_'.join([self.ikHandleOutputTgt.getName(), 'To', self.legIKCtrl.getName()])) self.ikHandleOutputConstraint.setMaintainOffset(True) self.ikHandleOutputConstraint.addConstrainer(self.legIKCtrl) self.ikHandleOutputTgt.addConstraint(self.ikHandleOutputConstraint) # =============== # Add Splice Ops # =============== # Add Leg Splice Op self.legIKKLOp = KLOperator('legKLOp', 'TwoBoneIKSolver', 'Kraken') self.addOperator(self.legIKKLOp) # Add Att Inputs self.legIKKLOp.setInput('drawDebug', self.drawDebugInputAttr) self.legIKKLOp.setInput('rigScale', self.rigScaleInputAttr) self.legIKKLOp.setInput('bone0Len', self.legBone0LenInputAttr) self.legIKKLOp.setInput('bone1Len', self.legBone1LenInputAttr) self.legIKKLOp.setInput('ikblend', legIKBlendInputAttr) self.legIKKLOp.setInput('rightSide', self.legRightSideInputAttr) # Add Xfo Inputs self.legIKKLOp.setInput('root', self.ikRootPosition) self.legIKKLOp.setInput('bone0FK', self.femurFKCtrl) self.legIKKLOp.setInput('bone1FK', self.shinFKCtrl) self.legIKKLOp.setInput('ikHandle', self.legIKTargetInputTgt) self.legIKKLOp.setInput('upV', self.legUpVCtrl) # Add Xfo Outputs self.legIKKLOp.setOutput('bone0Out', self.femurOutputTgt) self.legIKKLOp.setOutput('bone1Out', self.shinOutputTgt) self.legIKKLOp.setOutput('bone2Out', self.legEndOutputTgt) self.legIKKLOp.setOutput('midJointOut', self.kneeOutputTgt) # Add Leg Deformer Splice Op self.outputsToDeformersKLOp = KLOperator('legDeformerKLOp', 'MultiPoseConstraintSolver', 'Kraken') self.addOperator(self.outputsToDeformersKLOp) # Add Att Inputs self.outputsToDeformersKLOp.setInput('drawDebug', self.drawDebugInputAttr) self.outputsToDeformersKLOp.setInput('rigScale', self.rigScaleInputAttr) # Add Xfo Inputs self.outputsToDeformersKLOp.setInput('constrainers', [self.femurOutputTgt, self.kneeOutputTgt, self.shinOutputTgt]) # Add Xfo Outputs self.outputsToDeformersKLOp.setOutput('constrainees', [femurDef, kneeDef, shinDef]) Profiler.getInstance().pop()
class LegComponentRig(LegComponent): """Leg Component""" def __init__(self, name='leg', parent=None): Profiler.getInstance().push("Construct Leg Rig Component:" + name) super(LegComponentRig, self).__init__(name, parent) # ========= # Controls # ========= # Femur self.femurFKCtrlSpace = CtrlSpace('femurFK', parent=self.ctrlCmpGrp) self.femurFKCtrl = Control('femurFK', parent=self.femurFKCtrlSpace, shape="cube") self.femurFKCtrl.alignOnXAxis() self.femurFKCtrl.lockTranslation(True, True, True) self.femurFKCtrl.lockScale(True, True, True) # Shin self.shinFKCtrlSpace = CtrlSpace('shinFK', parent=self.femurFKCtrl) self.shinFKCtrl = Control('shinFK', parent=self.shinFKCtrlSpace, shape="cube") self.shinFKCtrl.alignOnXAxis() self.shinFKCtrl.lockTranslation(True, True, True) self.shinFKCtrl.lockScale(True, True, True) # IK Handle self.legIKCtrlSpace = CtrlSpace('IK', parent=self.ctrlCmpGrp) self.legIKCtrl = Control('IK', parent=self.legIKCtrlSpace, shape="pin") self.legIKCtrl.lockScale(True, True, True) # Add Component Params to IK control legSettingsAttrGrp = AttributeGroup("DisplayInfo_LegSettings", parent=self.legIKCtrl) legDrawDebugInputAttr = BoolAttribute('drawDebug', value=False, parent=legSettingsAttrGrp) self.legRightSideInputAttr = BoolAttribute('rightSide', value=False, parent=legSettingsAttrGrp) self.legBone0LenInputAttr = ScalarAttribute('bone0Len', value=1.0, parent=legSettingsAttrGrp) self.legBone1LenInputAttr = ScalarAttribute('bone1Len', value=1.0, parent=legSettingsAttrGrp) legIKBlendInputAttr = ScalarAttribute('ikblend', value=1.0, minValue=0.0, maxValue=1.0, parent=legSettingsAttrGrp) # Util Objects self.ikRootPosition = Transform("ikRootPosition", parent=self.ctrlCmpGrp) # Connect Input Attrs self.drawDebugInputAttr.connect(legDrawDebugInputAttr) # Connect Output Attrs self.drawDebugOutputAttr.connect(legDrawDebugInputAttr) self.ikBlendOutputAttr.connect(legIKBlendInputAttr) # UpV self.legUpVCtrlSpace = CtrlSpace('UpV', parent=self.ctrlCmpGrp) self.legUpVCtrl = Control('UpV', parent=self.legUpVCtrlSpace, shape="triangle") self.legUpVCtrl.alignOnZAxis() self.legUpVCtrl.lockRotation(True, True, True) self.legUpVCtrl.lockScale(True, True, True) # ========== # Deformers # ========== deformersLayer = self.getOrCreateLayer('deformers') self.defCmpGrp = ComponentGroup(self.getName(), self, parent=deformersLayer) self.addItem('defCmpGrp', self.defCmpGrp) femurDef = Joint('femur', parent=self.defCmpGrp) femurDef.setComponent(self) kneeDef = Joint('knee', parent=self.defCmpGrp) kneeDef.setComponent(self) shinDef = Joint('shin', parent=self.defCmpGrp) shinDef.setComponent(self) # ============== # Constrain I/O # ============== # Constraint inputs self.legIKCtrlSpaceInputConstraint = PoseConstraint('_'.join([self.legIKCtrlSpace.getName(), 'To', self.globalSRTInputTgt.getName()])) self.legIKCtrlSpaceInputConstraint.setMaintainOffset(True) self.legIKCtrlSpaceInputConstraint.addConstrainer(self.globalSRTInputTgt) self.legIKCtrlSpace.addConstraint(self.legIKCtrlSpaceInputConstraint) self.legUpVCtrlSpaceInputConstraint = PoseConstraint('_'.join([self.legUpVCtrlSpace.getName(), 'To', self.globalSRTInputTgt.getName()])) self.legUpVCtrlSpaceInputConstraint.setMaintainOffset(True) self.legUpVCtrlSpaceInputConstraint.addConstrainer(self.globalSRTInputTgt) self.legUpVCtrlSpace.addConstraint(self.legUpVCtrlSpaceInputConstraint) self.legRootInputConstraint = PoseConstraint('_'.join([self.femurFKCtrlSpace.getName(), 'To', self.legPelvisInputTgt.getName()])) self.legRootInputConstraint.setMaintainOffset(True) self.legRootInputConstraint.addConstrainer(self.legPelvisInputTgt) self.femurFKCtrlSpace.addConstraint(self.legRootInputConstraint) self.ikRootPosInputConstraint = PoseConstraint('_'.join([self.ikRootPosition.getName(), 'To', self.legPelvisInputTgt.getName()])) self.ikRootPosInputConstraint.setMaintainOffset(True) self.ikRootPosInputConstraint.addConstrainer(self.legPelvisInputTgt) self.ikRootPosition.addConstraint(self.ikRootPosInputConstraint) # Constraint outputs self.legEndFKOutputConstraint = PoseConstraint('_'.join([self.legEndFKOutputTgt.getName(), 'To', self.shinFKCtrl.getName()])) self.legEndFKOutputConstraint.setMaintainOffset(True) self.legEndFKOutputConstraint.addConstrainer(self.shinFKCtrl) self.legEndFKOutputTgt.addConstraint(self.legEndFKOutputConstraint) self.ikHandleOutputConstraint = PoseConstraint('_'.join([self.ikHandleOutputTgt.getName(), 'To', self.legIKCtrl.getName()])) self.ikHandleOutputConstraint.setMaintainOffset(True) self.ikHandleOutputConstraint.addConstrainer(self.legIKCtrl) self.ikHandleOutputTgt.addConstraint(self.ikHandleOutputConstraint) # =============== # Add Splice Ops # =============== # Add Leg Splice Op self.legIKKLOp = KLOperator('legKLOp', 'TwoBoneIKSolver', 'Kraken') self.addOperator(self.legIKKLOp) # Add Att Inputs self.legIKKLOp.setInput('drawDebug', self.drawDebugInputAttr) self.legIKKLOp.setInput('rigScale', self.rigScaleInputAttr) self.legIKKLOp.setInput('bone0Len', self.legBone0LenInputAttr) self.legIKKLOp.setInput('bone1Len', self.legBone1LenInputAttr) self.legIKKLOp.setInput('ikblend', legIKBlendInputAttr) self.legIKKLOp.setInput('rightSide', self.legRightSideInputAttr) # Add Xfo Inputs self.legIKKLOp.setInput('root', self.ikRootPosition) self.legIKKLOp.setInput('bone0FK', self.femurFKCtrl) self.legIKKLOp.setInput('bone1FK', self.shinFKCtrl) self.legIKKLOp.setInput('ikHandle', self.legIKTargetInputTgt) self.legIKKLOp.setInput('upV', self.legUpVCtrl) # Add Xfo Outputs self.legIKKLOp.setOutput('bone0Out', self.femurOutputTgt) self.legIKKLOp.setOutput('bone1Out', self.shinOutputTgt) self.legIKKLOp.setOutput('bone2Out', self.legEndOutputTgt) self.legIKKLOp.setOutput('midJointOut', self.kneeOutputTgt) # Add Leg Deformer Splice Op self.outputsToDeformersKLOp = KLOperator('legDeformerKLOp', 'MultiPoseConstraintSolver', 'Kraken') self.addOperator(self.outputsToDeformersKLOp) # Add Att Inputs self.outputsToDeformersKLOp.setInput('drawDebug', self.drawDebugInputAttr) self.outputsToDeformersKLOp.setInput('rigScale', self.rigScaleInputAttr) # Add Xfo Inputs self.outputsToDeformersKLOp.setInput('constrainers', [self.femurOutputTgt, self.kneeOutputTgt, self.shinOutputTgt]) # Add Xfo Outputs self.outputsToDeformersKLOp.setOutput('constrainees', [femurDef, kneeDef, shinDef]) Profiler.getInstance().pop() # ============= # Data Methods # ============= def loadData(self, data=None): """Load a saved guide representation from persisted data. Arguments: data -- object, The JSON data object. Return: True if successful. """ super(LegComponentRig, self).loadData( data ) createIKHandle = data.get('createIKHandle') femurXfo = data.get('femurXfo') kneeXfo = data.get('kneeXfo') handleXfo = data.get('handleXfo') upVXfo = data.get('upVXfo') femurLen = data.get('femurLen') shinLen = data.get('shinLen') self.femurFKCtrlSpace.xfo = femurXfo self.femurFKCtrl.xfo = femurXfo self.femurFKCtrl.scalePoints(Vec3(femurLen, 1.75, 1.75)) self.femurOutputTgt.xfo = femurXfo self.shinOutputTgt.xfo = kneeXfo self.shinFKCtrlSpace.xfo = kneeXfo self.shinFKCtrl.xfo = kneeXfo self.shinFKCtrl.scalePoints(Vec3(shinLen, 1.5, 1.5)) self.legEndFKOutputTgt.xfo.tr = handleXfo.tr self.legEndFKOutputTgt.xfo.ori = kneeXfo.ori self.ikHandleOutputTgt.xfo = handleXfo self.ikRootPosition.xfo = femurXfo self.legIKCtrlSpace.xfo = handleXfo self.legIKCtrl.xfo = handleXfo if self.getLocation() == 'R': self.legIKCtrl.rotatePoints(0, 90, 0) self.legIKCtrl.translatePoints(Vec3(-1.0, 0.0, 0.0)) else: self.legIKCtrl.rotatePoints(0, -90, 0) self.legIKCtrl.translatePoints(Vec3(1.0, 0.0, 0.0)) self.legUpVCtrlSpace.xfo.tr = upVXfo.tr self.legUpVCtrl.xfo.tr = upVXfo.tr self.legRightSideInputAttr.setValue(self.getLocation() is 'R') self.legBone0LenInputAttr.setMin(0.0) self.legBone0LenInputAttr.setMax(femurLen * 3.0) self.legBone0LenInputAttr.setValue(femurLen) self.legBone1LenInputAttr.setMin(0.0) self.legBone1LenInputAttr.setMax(shinLen * 3.0) self.legBone1LenInputAttr.setValue(shinLen) self.legPelvisInputTgt.xfo = femurXfo self.legIKTargetInputTgt.xfo = handleXfo # TODO: We need the Rig class to be modified to handle the ability to # query if the ports are connected during loadData. Currently just a # place holder until that happens. # If IK Target input is not connected, switch to legIKCtrl # ikTargetInput = self.getInputByName('ikTarget') # if not ikTargetInput.isConnected(): # self.legIKKLOp.setInput('ikHandle', self.legIKCtrl) # Eval Input Constraints self.ikRootPosInputConstraint.evaluate() self.legIKCtrlSpaceInputConstraint.evaluate() self.legUpVCtrlSpaceInputConstraint.evaluate() self.legRootInputConstraint.evaluate() # Eval Operators self.legIKKLOp.evaluate() self.outputsToDeformersKLOp.evaluate() # Eval Output Constraints self.legEndFKOutputConstraint.evaluate() self.ikHandleOutputConstraint.evaluate()
def __init__(self, name='arm', parent=None, *args, **kwargs): Profiler.getInstance().push("Construct Arm Guide Component:" + name) super(ArmComponentGuide, self).__init__(name, parent, *args, **kwargs) # =========== # Attributes # =========== # Add Component Params to IK control guideSettingsAttrGrp = AttributeGroup("GuideSettings", parent=self) self.bicepFKCtrlSizeInputAttr = ScalarAttribute( 'bicepFKCtrlSize', value=1.75, minValue=0.0, maxValue=10.0, parent=guideSettingsAttrGrp) self.forearmFKCtrlSizeInputAttr = ScalarAttribute( 'forearmFKCtrlSize', value=1.5, minValue=0.0, maxValue=10.0, parent=guideSettingsAttrGrp) # ========= # Controls # ========= # Guide Controls self.bicepCtrl = Control('bicep', parent=self.ctrlCmpGrp, shape="sphere") self.bicepCtrl.setColor('blue') self.forearmCtrl = Control('forearm', parent=self.ctrlCmpGrp, shape="sphere") self.forearmCtrl.setColor('blue') self.wristCtrl = Control('wrist', parent=self.ctrlCmpGrp, shape="sphere") self.wristCtrl.setColor('blue') armGuideSettingsAttrGrp = AttributeGroup("DisplayInfo_ArmSettings", parent=self.bicepCtrl) self.armGuideDebugAttr = BoolAttribute('drawDebug', value=True, parent=armGuideSettingsAttrGrp) self.guideOpHost = Transform('guideOpHost', self.ctrlCmpGrp) # Guide Operator self.armGuideKLOp = KLOperator('guide', 'TwoBoneIKGuideSolver', 'Kraken') self.addOperator(self.armGuideKLOp) # Add Att Inputs self.armGuideKLOp.setInput('drawDebug', self.armGuideDebugAttr) self.armGuideKLOp.setInput('rigScale', self.rigScaleInputAttr) # Add Source Inputs self.armGuideKLOp.setInput('root', self.bicepCtrl) self.armGuideKLOp.setInput('mid', self.forearmCtrl) self.armGuideKLOp.setInput('end', self.wristCtrl) # Add Target Outputs self.armGuideKLOp.setOutput('guideOpHost', self.guideOpHost) self.default_data = { "name": name, "location": "L", "bicepXfo": Xfo(Vec3(2.275, 15.3, -0.75)), "forearmXfo": Xfo(Vec3(5.0, 13.5, -0.75)), "wristXfo": Xfo(Vec3(7.2, 12.25, 0.5)), "bicepFKCtrlSize": self.bicepFKCtrlSizeInputAttr.getValue(), "forearmFKCtrlSize": self.forearmFKCtrlSizeInputAttr.getValue() } self.loadData(self.default_data) Profiler.getInstance().pop()
def __init__(self, name='arm', parent=None): Profiler.getInstance().push("Construct Arm Rig Component:" + name) super(ArmComponentRig, self).__init__(name, parent) # ========= # Controls # ========= # Bicep self.bicepFKCtrlSpace = CtrlSpace('bicepFK', parent=self.ctrlCmpGrp) self.bicepFKCtrl = Control('bicepFK', parent=self.bicepFKCtrlSpace, shape="cube") self.bicepFKCtrl.alignOnXAxis() self.bicepFKCtrl.lockScale(True, True, True) self.bicepFKCtrl.lockTranslation(True, True, True) # Forearm self.forearmFKCtrlSpace = CtrlSpace('forearmFK', parent=self.bicepFKCtrl) self.forearmFKCtrl = Control('forearmFK', parent=self.forearmFKCtrlSpace, shape="cube") self.forearmFKCtrl.alignOnXAxis() self.forearmFKCtrl.lockScale(True, True, True) self.forearmFKCtrl.lockTranslation(True, True, True) # Arm IK self.armIKCtrlSpace = CtrlSpace('IK', parent=self.ctrlCmpGrp) self.armIKCtrl = Control('IK', parent=self.armIKCtrlSpace, shape="jack") self.armIKCtrl.scalePoints(Vec3(2.0, 2.0, 2.0)) self.armIKCtrl.lockScale(True, True, True) # Add Params to IK control armSettingsAttrGrp = AttributeGroup("DisplayInfo_ArmSettings", parent=self.armIKCtrl) self.armDebugInputAttr = BoolAttribute('drawDebug', value=False, parent=armSettingsAttrGrp) self.armBone0LenInputAttr = ScalarAttribute('bone1Len', value=0.0, parent=armSettingsAttrGrp) self.armBone1LenInputAttr = ScalarAttribute('bone2Len', value=0.0, parent=armSettingsAttrGrp) self.armIKBlendInputAttr = ScalarAttribute('fkik', value=0.0, minValue=0.0, maxValue=1.0, parent=armSettingsAttrGrp) # Util Objects self.ikRootPosition = Transform("ikPosition", parent=self.ctrlCmpGrp) # Connect Input Attrs self.drawDebugInputAttr.connect(self.armDebugInputAttr) # Connect Output Attrs self.drawDebugOutputAttr.connect(self.armDebugInputAttr) self.ikBlendOutputAttr.connect(self.armIKBlendInputAttr) # UpV self.armUpVCtrlSpace = CtrlSpace('UpV', parent=self.ctrlCmpGrp) self.armUpVCtrl = Control('UpV', parent=self.armUpVCtrlSpace, shape="triangle") self.armUpVCtrl.alignOnZAxis() self.armUpVCtrl.rotatePoints(180, 0, 0) self.armIKCtrl.lockScale(True, True, True) self.armIKCtrl.lockRotation(True, True, True) # ========== # Deformers # ========== self.deformersLayer = self.getOrCreateLayer('deformers') self.defCmpGrp = ComponentGroup(self.getName(), self, parent=self.deformersLayer) self.addItem('defCmpGrp', self.defCmpGrp) self.bicepDef = Joint('bicep', parent=self.defCmpGrp) self.bicepDef.setComponent(self) self.elbowDef = Joint('elbow', parent=self.defCmpGrp) self.elbowDef.setComponent(self) self.forearmDef = Joint('forearm', parent=self.defCmpGrp) self.forearmDef.setComponent(self) self.wristDef = Joint('wrist', parent=self.defCmpGrp) self.wristDef.setComponent(self) # ============== # Constrain I/O # ============== # Constraint inputs self.armIKCtrlSpaceInputConstraint = PoseConstraint('_'.join([ self.armIKCtrlSpace.getName(), 'To', self.globalSRTInputTgt.getName() ])) self.armIKCtrlSpaceInputConstraint.setMaintainOffset(True) self.armIKCtrlSpaceInputConstraint.addConstrainer( self.globalSRTInputTgt) self.armIKCtrlSpace.addConstraint(self.armIKCtrlSpaceInputConstraint) self.armUpVCtrlSpaceInputConstraint = PoseConstraint('_'.join([ self.armUpVCtrlSpace.getName(), 'To', self.globalSRTInputTgt.getName() ])) self.armUpVCtrlSpaceInputConstraint.setMaintainOffset(True) self.armUpVCtrlSpaceInputConstraint.addConstrainer( self.globalSRTInputTgt) self.armUpVCtrlSpace.addConstraint(self.armUpVCtrlSpaceInputConstraint) self.armRootInputConstraint = PoseConstraint('_'.join([ self.bicepFKCtrlSpace.getName(), 'To', self.rootInputTgt.getName() ])) self.armRootInputConstraint.setMaintainOffset(True) self.armRootInputConstraint.addConstrainer(self.rootInputTgt) self.bicepFKCtrlSpace.addConstraint(self.armRootInputConstraint) self.ikPosInputConstraint = PoseConstraint('_'.join( [self.ikRootPosition.getName(), 'To', self.rootInputTgt.getName()])) self.ikPosInputConstraint.setMaintainOffset(True) self.ikPosInputConstraint.addConstrainer(self.rootInputTgt) self.ikRootPosition.addConstraint(self.ikPosInputConstraint) # Constraint outputs # =============== # Add Splice Ops # =============== # Add Splice Op self.armSolverKLOperator = KLOperator('ikSolver', 'TwoBoneIKSolver', 'Kraken') self.addOperator(self.armSolverKLOperator) # Add Att Inputs self.armSolverKLOperator.setInput('drawDebug', self.drawDebugInputAttr) self.armSolverKLOperator.setInput('rigScale', self.rigScaleInputAttr) self.armSolverKLOperator.setInput('bone0Len', self.armBone0LenInputAttr) self.armSolverKLOperator.setInput('bone1Len', self.armBone1LenInputAttr) self.armSolverKLOperator.setInput('ikblend', self.armIKBlendInputAttr) self.armSolverKLOperator.setInput('rightSide', self.rightSideInputAttr) # Add Xfo Inputs self.armSolverKLOperator.setInput('root', self.ikRootPosition) self.armSolverKLOperator.setInput('bone0FK', self.bicepFKCtrl) self.armSolverKLOperator.setInput('bone1FK', self.forearmFKCtrl) self.armSolverKLOperator.setInput('ikHandle', self.armIKCtrl) self.armSolverKLOperator.setInput('upV', self.armUpVCtrl) # Add Xfo Outputs self.armSolverKLOperator.setOutput('bone0Out', self.bicepOutputTgt) self.armSolverKLOperator.setOutput('bone1Out', self.forearmOutputTgt) self.armSolverKLOperator.setOutput('bone2Out', self.wristOutputTgt) self.armSolverKLOperator.setOutput('midJointOut', self.elbowOutputTgt) # Add Deformer Splice Op self.outputsToDeformersKLOp = KLOperator('defConstraint', 'MultiPoseConstraintSolver', 'Kraken') self.addOperator(self.outputsToDeformersKLOp) # Add Att Inputs self.outputsToDeformersKLOp.setInput('drawDebug', self.drawDebugInputAttr) self.outputsToDeformersKLOp.setInput('rigScale', self.rigScaleInputAttr) # Add Xfo Inputs self.outputsToDeformersKLOp.setInput('constrainers', [ self.bicepOutputTgt, self.elbowOutputTgt, self.forearmOutputTgt, self.wristOutputTgt ]) # Add Xfo Outputs self.outputsToDeformersKLOp.setOutput( 'constrainees', [self.bicepDef, self.elbowDef, self.forearmDef, self.wristDef]) Profiler.getInstance().pop()
class ArmComponentRig(ArmComponent): """Arm Component Rig""" def __init__(self, name='arm', parent=None): Profiler.getInstance().push("Construct Arm Rig Component:" + name) super(ArmComponentRig, self).__init__(name, parent) # ========= # Controls # ========= # Bicep self.bicepFKCtrlSpace = CtrlSpace('bicepFK', parent=self.ctrlCmpGrp) self.bicepFKCtrl = Control('bicepFK', parent=self.bicepFKCtrlSpace, shape="cube") self.bicepFKCtrl.alignOnXAxis() self.bicepFKCtrl.lockScale(True, True, True) self.bicepFKCtrl.lockTranslation(True, True, True) # Forearm self.forearmFKCtrlSpace = CtrlSpace('forearmFK', parent=self.bicepFKCtrl) self.forearmFKCtrl = Control('forearmFK', parent=self.forearmFKCtrlSpace, shape="cube") self.forearmFKCtrl.alignOnXAxis() self.forearmFKCtrl.lockScale(True, True, True) self.forearmFKCtrl.lockTranslation(True, True, True) # Arm IK self.armIKCtrlSpace = CtrlSpace('IK', parent=self.ctrlCmpGrp) self.armIKCtrl = Control('IK', parent=self.armIKCtrlSpace, shape="jack") self.armIKCtrl.scalePoints(Vec3(2.0, 2.0, 2.0)) self.armIKCtrl.lockScale(True, True, True) # Add Params to IK control armSettingsAttrGrp = AttributeGroup("DisplayInfo_ArmSettings", parent=self.armIKCtrl) self.armDebugInputAttr = BoolAttribute('drawDebug', value=False, parent=armSettingsAttrGrp) self.armBone0LenInputAttr = ScalarAttribute('bone1Len', value=0.0, parent=armSettingsAttrGrp) self.armBone1LenInputAttr = ScalarAttribute('bone2Len', value=0.0, parent=armSettingsAttrGrp) self.armIKBlendInputAttr = ScalarAttribute('fkik', value=0.0, minValue=0.0, maxValue=1.0, parent=armSettingsAttrGrp) # Util Objects self.ikRootPosition = Transform("ikPosition", parent=self.ctrlCmpGrp) # Connect Input Attrs self.drawDebugInputAttr.connect(self.armDebugInputAttr) # Connect Output Attrs self.drawDebugOutputAttr.connect(self.armDebugInputAttr) self.ikBlendOutputAttr.connect(self.armIKBlendInputAttr) # UpV self.armUpVCtrlSpace = CtrlSpace('UpV', parent=self.ctrlCmpGrp) self.armUpVCtrl = Control('UpV', parent=self.armUpVCtrlSpace, shape="triangle") self.armUpVCtrl.alignOnZAxis() self.armUpVCtrl.rotatePoints(180, 0, 0) self.armIKCtrl.lockScale(True, True, True) self.armIKCtrl.lockRotation(True, True, True) # ========== # Deformers # ========== self.deformersLayer = self.getOrCreateLayer('deformers') self.defCmpGrp = ComponentGroup(self.getName(), self, parent=self.deformersLayer) self.addItem('defCmpGrp', self.defCmpGrp) self.bicepDef = Joint('bicep', parent=self.defCmpGrp) self.bicepDef.setComponent(self) self.elbowDef = Joint('elbow', parent=self.defCmpGrp) self.elbowDef.setComponent(self) self.forearmDef = Joint('forearm', parent=self.defCmpGrp) self.forearmDef.setComponent(self) self.wristDef = Joint('wrist', parent=self.defCmpGrp) self.wristDef.setComponent(self) # ============== # Constrain I/O # ============== # Constraint inputs self.armIKCtrlSpaceInputConstraint = PoseConstraint('_'.join([ self.armIKCtrlSpace.getName(), 'To', self.globalSRTInputTgt.getName() ])) self.armIKCtrlSpaceInputConstraint.setMaintainOffset(True) self.armIKCtrlSpaceInputConstraint.addConstrainer( self.globalSRTInputTgt) self.armIKCtrlSpace.addConstraint(self.armIKCtrlSpaceInputConstraint) self.armUpVCtrlSpaceInputConstraint = PoseConstraint('_'.join([ self.armUpVCtrlSpace.getName(), 'To', self.globalSRTInputTgt.getName() ])) self.armUpVCtrlSpaceInputConstraint.setMaintainOffset(True) self.armUpVCtrlSpaceInputConstraint.addConstrainer( self.globalSRTInputTgt) self.armUpVCtrlSpace.addConstraint(self.armUpVCtrlSpaceInputConstraint) self.armRootInputConstraint = PoseConstraint('_'.join([ self.bicepFKCtrlSpace.getName(), 'To', self.rootInputTgt.getName() ])) self.armRootInputConstraint.setMaintainOffset(True) self.armRootInputConstraint.addConstrainer(self.rootInputTgt) self.bicepFKCtrlSpace.addConstraint(self.armRootInputConstraint) self.ikPosInputConstraint = PoseConstraint('_'.join( [self.ikRootPosition.getName(), 'To', self.rootInputTgt.getName()])) self.ikPosInputConstraint.setMaintainOffset(True) self.ikPosInputConstraint.addConstrainer(self.rootInputTgt) self.ikRootPosition.addConstraint(self.ikPosInputConstraint) # Constraint outputs # =============== # Add Splice Ops # =============== # Add Splice Op self.armSolverKLOperator = KLOperator('ikSolver', 'TwoBoneIKSolver', 'Kraken') self.addOperator(self.armSolverKLOperator) # Add Att Inputs self.armSolverKLOperator.setInput('drawDebug', self.drawDebugInputAttr) self.armSolverKLOperator.setInput('rigScale', self.rigScaleInputAttr) self.armSolverKLOperator.setInput('bone0Len', self.armBone0LenInputAttr) self.armSolverKLOperator.setInput('bone1Len', self.armBone1LenInputAttr) self.armSolverKLOperator.setInput('ikblend', self.armIKBlendInputAttr) self.armSolverKLOperator.setInput('rightSide', self.rightSideInputAttr) # Add Xfo Inputs self.armSolverKLOperator.setInput('root', self.ikRootPosition) self.armSolverKLOperator.setInput('bone0FK', self.bicepFKCtrl) self.armSolverKLOperator.setInput('bone1FK', self.forearmFKCtrl) self.armSolverKLOperator.setInput('ikHandle', self.armIKCtrl) self.armSolverKLOperator.setInput('upV', self.armUpVCtrl) # Add Xfo Outputs self.armSolverKLOperator.setOutput('bone0Out', self.bicepOutputTgt) self.armSolverKLOperator.setOutput('bone1Out', self.forearmOutputTgt) self.armSolverKLOperator.setOutput('bone2Out', self.wristOutputTgt) self.armSolverKLOperator.setOutput('midJointOut', self.elbowOutputTgt) # Add Deformer Splice Op self.outputsToDeformersKLOp = KLOperator('defConstraint', 'MultiPoseConstraintSolver', 'Kraken') self.addOperator(self.outputsToDeformersKLOp) # Add Att Inputs self.outputsToDeformersKLOp.setInput('drawDebug', self.drawDebugInputAttr) self.outputsToDeformersKLOp.setInput('rigScale', self.rigScaleInputAttr) # Add Xfo Inputs self.outputsToDeformersKLOp.setInput('constrainers', [ self.bicepOutputTgt, self.elbowOutputTgt, self.forearmOutputTgt, self.wristOutputTgt ]) # Add Xfo Outputs self.outputsToDeformersKLOp.setOutput( 'constrainees', [self.bicepDef, self.elbowDef, self.forearmDef, self.wristDef]) Profiler.getInstance().pop() def loadData(self, data=None): """Load a saved guide representation from persisted data. Arguments: data -- object, The JSON data object. Return: True if successful. """ super(ArmComponentRig, self).loadData(data) bicepXfo = data.get('bicepXfo') forearmXfo = data.get('forearmXfo') wristXfo = data.get('wristXfo') upVXfo = data.get('upVXfo') bicepLen = data.get('bicepLen') forearmLen = data.get('forearmLen') bicepFKCtrlSize = data.get('bicepFKCtrlSize') forearmFKCtrlSize = data.get('forearmFKCtrlSize') self.rootInputTgt.xfo.tr = bicepXfo.tr self.bicepFKCtrlSpace.xfo = bicepXfo self.bicepFKCtrl.xfo = bicepXfo self.bicepFKCtrl.scalePoints( Vec3(bicepLen, bicepFKCtrlSize, bicepFKCtrlSize)) self.forearmFKCtrlSpace.xfo = forearmXfo self.forearmFKCtrl.xfo = forearmXfo self.forearmFKCtrl.scalePoints( Vec3(forearmLen, forearmFKCtrlSize, forearmFKCtrlSize)) self.ikRootPosition.xfo = bicepXfo self.armIKCtrlSpace.xfo.tr = wristXfo.tr self.armIKCtrl.xfo.tr = wristXfo.tr if self.getLocation() == "R": self.armIKCtrl.rotatePoints(0, 90, 0) else: self.armIKCtrl.rotatePoints(0, -90, 0) self.armUpVCtrlSpace.xfo.tr = upVXfo.tr self.armUpVCtrl.xfo.tr = upVXfo.tr self.rightSideInputAttr.setValue(self.getLocation() is 'R') self.armBone0LenInputAttr.setMin(0.0) self.armBone0LenInputAttr.setMax(bicepLen * 3.0) self.armBone0LenInputAttr.setValue(bicepLen) self.armBone1LenInputAttr.setMin(0.0) self.armBone1LenInputAttr.setMax(forearmLen * 3.0) self.armBone1LenInputAttr.setValue(forearmLen) # Outputs self.bicepOutputTgt.xfo = bicepXfo self.forearmOutputTgt.xfo = forearmXfo self.wristOutputTgt.xfo = wristXfo # Eval Constraints self.ikPosInputConstraint.evaluate() self.armIKCtrlSpaceInputConstraint.evaluate() self.armUpVCtrlSpaceInputConstraint.evaluate() self.armRootInputConstraint.evaluate() self.armRootInputConstraint.evaluate() # Eval Operators self.armSolverKLOperator.evaluate() self.outputsToDeformersKLOp.evaluate()
def __init__(self, name="spine", parent=None): Profiler.getInstance().push("Construct Spine Rig Component:" + name) super(TwistComponentRig, self).__init__(name, parent) # ========= # Controls # ========= self.originTransform = Transform('origin', parent=self.ctrlCmpGrp) self.originUpVTransform = Transform('originUpV', parent=self.ctrlCmpGrp) self.insertTransform = Transform('insert', parent=self.ctrlCmpGrp) self.insertUpVTransform = Transform('insertUpV', parent=self.ctrlCmpGrp) # Add Params to origin transform twistSettings = AttributeGroup("DisplayInfo_TwistSettings", parent=self.originTransform) self.blendBiasInputAttr = ScalarAttribute('blendBias', value=0.0, minValue=0.0, maxValue=1.0, parent=twistSettings) # ========== # Deformers # ========== deformersLayer = self.getOrCreateLayer('deformers') self.defCmpGrp = ComponentGroup(self.getName(), self, parent=deformersLayer) self.addItem('defCmpGrp', self.defCmpGrp) self.deformerJoints = [] self.twistOutputs = [] self.setNumDeformers(1) # ===================== # Create Component I/O # ===================== # Setup component Xfo I/O's self.twistJointOutput.setTarget(self.twistOutputs) # ============ # Constraints # ============ # Constrain inputs # Origin and Insert constraintName = '_'.join([self.originTransform.getName(), 'To', self.originInputTgt.getName()]) self.originInputConstraint = self.originTransform.constrainTo( self.originInputTgt, constraintType='Position', maintainOffset=True, name=constraintName) constraintName = '_'.join([self.insertTransform.getName(), 'To', self.insertInputTgt.getName()]) self.insertInputConstraint = self.insertTransform.constrainTo( self.insertInputTgt, constraintType='Position', maintainOffset=True, name=constraintName) # Up Vectors constraintName = '_'.join([self.originUpVTransform.getName(), 'To', self.originInputTgt.getName()]) self.originUpVInputConstraint = self.originUpVTransform.constrainTo( self.originInputTgt, constraintType='Pose', maintainOffset=True, name=constraintName) constraintName = '_'.join([self.insertUpVTransform.getName(), 'To', self.insertInputTgt.getName()]) self.insertUpVInputConstraint = self.insertUpVTransform.constrainTo( self.insertInputTgt, constraintType='Pose', maintainOffset=True, name=constraintName) # Constrain outputs # =============== # Add Splice Ops # =============== # Add Spine Splice Op self.twistKLOp = KLOperator('TwistOp', 'TwistSolver', 'Kraken') self.addOperator(self.twistKLOp) # Add Att Inputs self.twistKLOp.setInput('drawDebug', self.drawDebugInputAttr) self.twistKLOp.setInput('rigScale', self.rigScaleInputAttr) self.twistKLOp.setInput('blendBias', self.blendBiasInputAttr) # Add Xfo Inputs self.twistKLOp.setInput('origin', self.originTransform) self.twistKLOp.setInput('originUpV', self.originUpVTransform) self.twistKLOp.setInput('insert', self.insertTransform) self.twistKLOp.setInput('insertUpV', self.insertUpVTransform) # Add Xfo Outputs self.twistKLOp.setOutput('pose', self.twistOutputs) # # Add Deformer Splice Op self.deformersToOutputsKLOp = KLOperator('twistDeformerKLOp', 'MultiPoseConstraintSolver', 'Kraken') self.addOperator(self.deformersToOutputsKLOp) # Add Att Inputs self.deformersToOutputsKLOp.setInput('drawDebug', self.drawDebugInputAttr) self.deformersToOutputsKLOp.setInput('rigScale', self.rigScaleInputAttr) # Add Xfo Outputs self.deformersToOutputsKLOp.setInput('constrainers', self.twistOutputs) # Add Xfo Outputs self.deformersToOutputsKLOp.setOutput('constrainees', self.deformerJoints) Profiler.getInstance().pop()
class TwistComponentRig(TwistComponent): """Twist Component""" def __init__(self, name="spine", parent=None): Profiler.getInstance().push("Construct Spine Rig Component:" + name) super(TwistComponentRig, self).__init__(name, parent) # ========= # Controls # ========= self.originTransform = Transform('origin', parent=self.ctrlCmpGrp) self.originUpVTransform = Transform('originUpV', parent=self.ctrlCmpGrp) self.insertTransform = Transform('insert', parent=self.ctrlCmpGrp) self.insertUpVTransform = Transform('insertUpV', parent=self.ctrlCmpGrp) # Add Params to origin transform twistSettings = AttributeGroup("DisplayInfo_TwistSettings", parent=self.originTransform) self.blendBiasInputAttr = ScalarAttribute('blendBias', value=0.0, minValue=0.0, maxValue=1.0, parent=twistSettings) # ========== # Deformers # ========== deformersLayer = self.getOrCreateLayer('deformers') self.defCmpGrp = ComponentGroup(self.getName(), self, parent=deformersLayer) self.addItem('defCmpGrp', self.defCmpGrp) self.deformerJoints = [] self.twistOutputs = [] self.setNumDeformers(1) # ===================== # Create Component I/O # ===================== # Setup component Xfo I/O's self.twistJointOutput.setTarget(self.twistOutputs) # ============ # Constraints # ============ # Constrain inputs # Origin and Insert constraintName = '_'.join([self.originTransform.getName(), 'To', self.originInputTgt.getName()]) self.originInputConstraint = self.originTransform.constrainTo( self.originInputTgt, constraintType='Position', maintainOffset=True, name=constraintName) constraintName = '_'.join([self.insertTransform.getName(), 'To', self.insertInputTgt.getName()]) self.insertInputConstraint = self.insertTransform.constrainTo( self.insertInputTgt, constraintType='Position', maintainOffset=True, name=constraintName) # Up Vectors constraintName = '_'.join([self.originUpVTransform.getName(), 'To', self.originInputTgt.getName()]) self.originUpVInputConstraint = self.originUpVTransform.constrainTo( self.originInputTgt, constraintType='Pose', maintainOffset=True, name=constraintName) constraintName = '_'.join([self.insertUpVTransform.getName(), 'To', self.insertInputTgt.getName()]) self.insertUpVInputConstraint = self.insertUpVTransform.constrainTo( self.insertInputTgt, constraintType='Pose', maintainOffset=True, name=constraintName) # Constrain outputs # =============== # Add Splice Ops # =============== # Add Spine Splice Op self.twistKLOp = KLOperator('TwistOp', 'TwistSolver', 'Kraken') self.addOperator(self.twistKLOp) # Add Att Inputs self.twistKLOp.setInput('drawDebug', self.drawDebugInputAttr) self.twistKLOp.setInput('rigScale', self.rigScaleInputAttr) self.twistKLOp.setInput('blendBias', self.blendBiasInputAttr) # Add Xfo Inputs self.twistKLOp.setInput('origin', self.originTransform) self.twistKLOp.setInput('originUpV', self.originUpVTransform) self.twistKLOp.setInput('insert', self.insertTransform) self.twistKLOp.setInput('insertUpV', self.insertUpVTransform) # Add Xfo Outputs self.twistKLOp.setOutput('pose', self.twistOutputs) # # Add Deformer Splice Op self.deformersToOutputsKLOp = KLOperator('twistDeformerKLOp', 'MultiPoseConstraintSolver', 'Kraken') self.addOperator(self.deformersToOutputsKLOp) # Add Att Inputs self.deformersToOutputsKLOp.setInput('drawDebug', self.drawDebugInputAttr) self.deformersToOutputsKLOp.setInput('rigScale', self.rigScaleInputAttr) # Add Xfo Outputs self.deformersToOutputsKLOp.setInput('constrainers', self.twistOutputs) # Add Xfo Outputs self.deformersToOutputsKLOp.setOutput('constrainees', self.deformerJoints) Profiler.getInstance().pop() def setNumDeformers(self, numDeformers): # Add new deformers and outputs for i in xrange(len(self.twistOutputs), numDeformers): name = 'twist' + str(i + 1).zfill(2) spineOutput = ComponentOutput(name, parent=self.outputHrcGrp) self.twistOutputs.append(spineOutput) for i in xrange(len(self.deformerJoints), numDeformers): name = 'twist' + str(i + 1).zfill(2) spineDef = Joint(name, parent=self.defCmpGrp) spineDef.setComponent(self) self.deformerJoints.append(spineDef) return True def loadData(self, data=None): """Load a saved guide representation from persisted data. Arguments: data -- object, The JSON data object. Return: True if successful. """ super(TwistComponentRig, self).loadData(data) blendBias = data.get('blendBias') originXfo = data.get('originXfo') insertXfo = data.get('insertXfo') originUpVXfo = data.get('originUpVXfo') insertUpVXfo = data.get('insertUpVXfo') numDeformers = data.get('numDeformers') self.blendBiasInputAttr.setValue(blendBias) self.originTransform.xfo = originXfo self.originUpVTransform.xfo = originUpVXfo self.insertTransform.xfo = insertXfo self.insertUpVTransform.xfo = insertUpVXfo self.originInputTgt.xfo = originXfo self.insertInputTgt.xfo = insertXfo # Update number of deformers and outputs self.setNumDeformers(numDeformers) # Evaluate Constraints self.originInputConstraint.evaluate() self.insertInputConstraint.evaluate() self.originUpVInputConstraint.evaluate() self.insertUpVInputConstraint.evaluate() # Evaluate Operators # self.twistKLOp.evaluate() self.deformersToOutputsKLOp.evaluate()
def __init__(self, name="spine", parent=None): Profiler.getInstance().push("Construct Spine Rig Component:" + name) super(TwistComponentRig, self).__init__(name, parent) # ========= # Controls # ========= self.originTransform = Transform('origin', parent=self.ctrlCmpGrp) self.originUpVTransform = Transform('originUpV', parent=self.ctrlCmpGrp) self.insertTransform = Transform('insert', parent=self.ctrlCmpGrp) self.insertUpVTransform = Transform('insertUpV', parent=self.ctrlCmpGrp) # Add Params to origin transform twistSettings = AttributeGroup("DisplayInfo_TwistSettings", parent=self.originTransform) self.blendBiasInputAttr = ScalarAttribute('blendBias', value=0.0, minValue=0.0, maxValue=1.0, parent=twistSettings) # ========== # Deformers # ========== deformersLayer = self.getOrCreateLayer('deformers') self.defCmpGrp = ComponentGroup(self.getName(), self, parent=deformersLayer) self.addItem('defCmpGrp', self.defCmpGrp) self.deformerJoints = [] self.twistOutputs = [] self.setNumDeformers(1) # ===================== # Create Component I/O # ===================== # Setup component Xfo I/O's self.twistJointOutput.setTarget(self.twistOutputs) # ============ # Constraints # ============ # Constrain inputs # Origin and Insert constraintName = '_'.join([ self.originTransform.getName(), 'To', self.originInputTgt.getName() ]) self.originInputConstraint = self.originTransform.constrainTo( self.originInputTgt, constraintType='Position', maintainOffset=True, name=constraintName) constraintName = '_'.join([ self.insertTransform.getName(), 'To', self.insertInputTgt.getName() ]) self.insertInputConstraint = self.insertTransform.constrainTo( self.insertInputTgt, constraintType='Position', maintainOffset=True, name=constraintName) # Up Vectors constraintName = '_'.join([ self.originUpVTransform.getName(), 'To', self.originInputTgt.getName() ]) self.originUpVInputConstraint = self.originUpVTransform.constrainTo( self.originInputTgt, constraintType='Pose', maintainOffset=True, name=constraintName) constraintName = '_'.join([ self.insertUpVTransform.getName(), 'To', self.insertInputTgt.getName() ]) self.insertUpVInputConstraint = self.insertUpVTransform.constrainTo( self.insertInputTgt, constraintType='Pose', maintainOffset=True, name=constraintName) # Constrain outputs # =============== # Add Splice Ops # =============== # Add Spine Splice Op self.twistKLOp = KLOperator('TwistOp', 'TwistSolver', 'Kraken') self.addOperator(self.twistKLOp) # Add Att Inputs self.twistKLOp.setInput('drawDebug', self.drawDebugInputAttr) self.twistKLOp.setInput('rigScale', self.rigScaleInputAttr) self.twistKLOp.setInput('blendBias', self.blendBiasInputAttr) # Add Xfo Inputs self.twistKLOp.setInput('origin', self.originTransform) self.twistKLOp.setInput('originUpV', self.originUpVTransform) self.twistKLOp.setInput('insert', self.insertTransform) self.twistKLOp.setInput('insertUpV', self.insertUpVTransform) # Add Xfo Outputs self.twistKLOp.setOutput('pose', self.twistOutputs) # # Add Deformer Splice Op self.deformersToOutputsKLOp = KLOperator('twistDeformerKLOp', 'MultiPoseConstraintSolver', 'Kraken') self.addOperator(self.deformersToOutputsKLOp) # Add Att Inputs self.deformersToOutputsKLOp.setInput('drawDebug', self.drawDebugInputAttr) self.deformersToOutputsKLOp.setInput('rigScale', self.rigScaleInputAttr) # Add Xfo Outputs self.deformersToOutputsKLOp.setInput('constrainers', self.twistOutputs) # Add Xfo Outputs self.deformersToOutputsKLOp.setOutput('constrainees', self.deformerJoints) Profiler.getInstance().pop()
class TwistComponentRig(TwistComponent): """Twist Component""" def __init__(self, name="spine", parent=None): Profiler.getInstance().push("Construct Spine Rig Component:" + name) super(TwistComponentRig, self).__init__(name, parent) # ========= # Controls # ========= self.originTransform = Transform('origin', parent=self.ctrlCmpGrp) self.originUpVTransform = Transform('originUpV', parent=self.ctrlCmpGrp) self.insertTransform = Transform('insert', parent=self.ctrlCmpGrp) self.insertUpVTransform = Transform('insertUpV', parent=self.ctrlCmpGrp) # Add Params to origin transform twistSettings = AttributeGroup("DisplayInfo_TwistSettings", parent=self.originTransform) self.blendBiasInputAttr = ScalarAttribute('blendBias', value=0.0, minValue=0.0, maxValue=1.0, parent=twistSettings) # ========== # Deformers # ========== deformersLayer = self.getOrCreateLayer('deformers') self.defCmpGrp = ComponentGroup(self.getName(), self, parent=deformersLayer) self.addItem('defCmpGrp', self.defCmpGrp) self.deformerJoints = [] self.twistOutputs = [] self.setNumDeformers(1) # ===================== # Create Component I/O # ===================== # Setup component Xfo I/O's self.twistJointOutput.setTarget(self.twistOutputs) # ============ # Constraints # ============ # Constrain inputs # Origin and Insert constraintName = '_'.join([ self.originTransform.getName(), 'To', self.originInputTgt.getName() ]) self.originInputConstraint = self.originTransform.constrainTo( self.originInputTgt, constraintType='Position', maintainOffset=True, name=constraintName) constraintName = '_'.join([ self.insertTransform.getName(), 'To', self.insertInputTgt.getName() ]) self.insertInputConstraint = self.insertTransform.constrainTo( self.insertInputTgt, constraintType='Position', maintainOffset=True, name=constraintName) # Up Vectors constraintName = '_'.join([ self.originUpVTransform.getName(), 'To', self.originInputTgt.getName() ]) self.originUpVInputConstraint = self.originUpVTransform.constrainTo( self.originInputTgt, constraintType='Pose', maintainOffset=True, name=constraintName) constraintName = '_'.join([ self.insertUpVTransform.getName(), 'To', self.insertInputTgt.getName() ]) self.insertUpVInputConstraint = self.insertUpVTransform.constrainTo( self.insertInputTgt, constraintType='Pose', maintainOffset=True, name=constraintName) # Constrain outputs # =============== # Add Splice Ops # =============== # Add Spine Splice Op self.twistKLOp = KLOperator('TwistOp', 'TwistSolver', 'Kraken') self.addOperator(self.twistKLOp) # Add Att Inputs self.twistKLOp.setInput('drawDebug', self.drawDebugInputAttr) self.twistKLOp.setInput('rigScale', self.rigScaleInputAttr) self.twistKLOp.setInput('blendBias', self.blendBiasInputAttr) # Add Xfo Inputs self.twistKLOp.setInput('origin', self.originTransform) self.twistKLOp.setInput('originUpV', self.originUpVTransform) self.twistKLOp.setInput('insert', self.insertTransform) self.twistKLOp.setInput('insertUpV', self.insertUpVTransform) # Add Xfo Outputs self.twistKLOp.setOutput('pose', self.twistOutputs) # # Add Deformer Splice Op self.deformersToOutputsKLOp = KLOperator('twistDeformerKLOp', 'MultiPoseConstraintSolver', 'Kraken') self.addOperator(self.deformersToOutputsKLOp) # Add Att Inputs self.deformersToOutputsKLOp.setInput('drawDebug', self.drawDebugInputAttr) self.deformersToOutputsKLOp.setInput('rigScale', self.rigScaleInputAttr) # Add Xfo Outputs self.deformersToOutputsKLOp.setInput('constrainers', self.twistOutputs) # Add Xfo Outputs self.deformersToOutputsKLOp.setOutput('constrainees', self.deformerJoints) Profiler.getInstance().pop() def setNumDeformers(self, numDeformers): # Add new deformers and outputs for i in xrange(len(self.twistOutputs), numDeformers): name = 'twist' + str(i + 1).zfill(2) spineOutput = ComponentOutput(name, parent=self.outputHrcGrp) self.twistOutputs.append(spineOutput) for i in xrange(len(self.deformerJoints), numDeformers): name = 'twist' + str(i + 1).zfill(2) spineDef = Joint(name, parent=self.defCmpGrp) spineDef.setComponent(self) self.deformerJoints.append(spineDef) return True def loadData(self, data=None): """Load a saved guide representation from persisted data. Arguments: data -- object, The JSON data object. Return: True if successful. """ super(TwistComponentRig, self).loadData(data) blendBias = data.get('blendBias') originXfo = data.get('originXfo') insertXfo = data.get('insertXfo') originUpVXfo = data.get('originUpVXfo') insertUpVXfo = data.get('insertUpVXfo') numDeformers = data.get('numDeformers') self.blendBiasInputAttr.setValue(blendBias) self.originTransform.xfo = originXfo self.originUpVTransform.xfo = originUpVXfo self.insertTransform.xfo = insertXfo self.insertUpVTransform.xfo = insertUpVXfo self.originInputTgt.xfo = originXfo self.insertInputTgt.xfo = insertXfo # Update number of deformers and outputs self.setNumDeformers(numDeformers) # Evaluate Constraints self.originInputConstraint.evaluate() self.insertInputConstraint.evaluate() self.originUpVInputConstraint.evaluate() self.insertUpVInputConstraint.evaluate() # Evaluate Operators # self.twistKLOp.evaluate() self.deformersToOutputsKLOp.evaluate()
from kraken import plugins from kraken.core.objects.transform import Transform from kraken.core.objects.control import Control from kraken.helpers.utility_methods import logHierarchy # Build builder = plugins.getBuilder() config = builder.getConfig() config.setExplicitNaming(True) ctrlParent = Transform("controls") ctrlShapes = config.getControlShapes() i = 0 j = 0 for k, v in ctrlShapes.iteritems(): ctrl = Control(k + '_shape', shape=k, parent=ctrlParent) ctrl.xfo.tr.x = i % 5 * 2 ctrl.xfo.tr.z = j * 2 if i % 5 == 4: j += 1 i += 1 builder.build(ctrlParent) logHierarchy(ctrlParent)