class HeadComponentRig(HeadComponent): """Head Component Rig""" 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 loadData(self, data=None): """Load a saved guide representation from persisted data. Arguments: data -- object, The JSON data object. Return: True if successful. """ super(HeadComponentRig, self).loadData(data) headXfo = data.get('headXfo') headCrvData = data.get('headCrvData') eyeLeftXfo = data.get('eyeLeftXfo') eyeLeftCrvData = data.get('eyeLeftCrvData') eyeRightXfo = data.get('eyeRightXfo') eyeRightCrvData = data.get('eyeRightCrvData') jawXfo = data.get('jawXfo') jawCrvData = data.get('jawCrvData') self.headCtrlSpace.xfo = headXfo self.headCtrl.xfo = headXfo self.headCtrl.setCurveData(headCrvData) # self.eyeLeftCtrlSpace.xfo = eyeLeftXfo # self.eyeLeftCtrl.xfo = eyeLeftXfo self.eyeLeftCtrl.setCurveData(eyeLeftCrvData) # self.eyeRightCtrlSpace.xfo = eyeRightXfo # self.eyeRightCtrl.xfo = eyeRightXfo self.eyeRightCtrl.setCurveData(eyeRightCrvData) # LookAt eyeLeftRelXfo = headXfo.inverse() * eyeLeftXfo eyeRightRelXfo = headXfo.inverse() * eyeRightXfo eyeMidRelPos = eyeLeftRelXfo.tr.linearInterpolate( eyeRightRelXfo.tr, 0.5) eyeMidRelPos = eyeMidRelPos + Vec3(0.0, 0.0, 8.0) eyeLen = eyeLeftRelXfo.tr.distanceTo(eyeRightRelXfo.tr) self.eyeLeftBase.xfo = eyeLeftXfo self.eyeRightBase.xfo = eyeRightXfo self.eyeLeftUpV.xfo = eyeLeftXfo * Xfo(Vec3(0, 1, 0)) self.eyeRightUpV.xfo = eyeRightXfo * Xfo(Vec3(0, 1, 0)) self.eyeLeftAtV.xfo.tr = eyeLeftXfo.transformVector(Vec3( 8.0, 0.0, 0.0)) self.eyeRightAtV.xfo.tr = eyeRightXfo.transformVector( Vec3(8.0, 0.0, 0.0)) lookAtXfo = headXfo.clone() lookAtXfo.tr = headXfo.transformVector(eyeMidRelPos) self.lookAtCtrl.scalePoints(Vec3(eyeLen * 1.6, eyeLen * 0.65, 1.0)) self.lookAtCtrl.xfo = lookAtXfo self.lookAtCtrlSpace.xfo = lookAtXfo self.jawCtrlSpace.xfo = jawXfo self.jawCtrl.xfo = jawXfo self.jawCtrl.setCurveData(jawCrvData) # ============ # Set IO Xfos # ============ self.neckRefInputTgt.xfo = headXfo self.worldRefInputTgt.xfo = headXfo self.headOutputTgt.xfo = headXfo self.jawOutputTgt.xfo = jawXfo self.eyeLOutputTgt.xfo = eyeLeftXfo self.eyeROutputTgt.xfo = eyeRightXfo # Eval Constraints self.headInputConstraint.evaluate() self.headOutputConstraint.evaluate() self.jawOutputConstraint.evaluate() self.eyeLOutputConstraint.evaluate() self.eyeROutputConstraint.evaluate() # Eval Operators self.eyeLeftDirKLOp.evaluate() self.eyeRightDirKLOp.evaluate() self.outputsToDeformersKLOp.evaluate() # Have to set the eye control xfos to match the evaluated xfos from self.eyeLeftCtrl.xfo = self.eyeLeftCtrlSpace.xfo self.eyeRightCtrl.xfo = self.eyeRightCtrlSpace.xfo
class FabriceHeadGuide(FabriceHead): """Fabrice Head Component Guide""" def __init__(self, name='head', parent=None): Profiler.getInstance().push("Construct Head Guide Component:" + name) super(FabriceHeadGuide, self).__init__(name, parent) # ========= # Controls # ========= guideSettingsAttrGrp = AttributeGroup("GuideSettings", parent=self) self.headCtrl = Control('head', parent=self.ctrlCmpGrp, shape="circle") self.headCtrl.rotatePoints(90.0, 0.0, 0.0) self.headCtrl.scalePoints(Vec3(3.5, 3.5, 3.5)) self.jawCtrl = Control('jaw', parent=self.ctrlCmpGrp, shape="cube") self.jawCtrl.alignOnZAxis() self.jawCtrl.scalePoints(Vec3(2.0, 0.5, 2.0)) self.jawCtrl.alignOnYAxis(negative=True) self.jawCtrl.setColor('orange') data = { "name": name, "location": "M", "headXfo": Xfo(Vec3(0.0, 1.67, 1.75)), "headCtrlCrvData": self.headCtrl.getCurveData(), "jawPosition": Vec3(0.0, 1.2787, 2.0078), "jawCtrlCrvData": self.jawCtrl.getCurveData(), } self.loadData(data) Profiler.getInstance().pop() # ============= # Data Methods # ============= def saveData(self): """Save the data for the component to be persisted. Return: The JSON data object """ data = super(FabriceHeadGuide, self).saveData() data['headXfo'] = self.headCtrl.xfo data['headCtrlCrvData'] = self.headCtrl.getCurveData() data['jawPosition'] = self.jawCtrl.xfo.tr data['jawCtrlCrvData'] = self.jawCtrl.getCurveData() return data def loadData(self, data): """Load a saved guide representation from persisted data. Arguments: data -- object, The JSON data object. Return: True if successful. """ super(FabriceHeadGuide, self).loadData(data) self.headCtrl.xfo = data['headXfo'] self.headCtrl.setCurveData(data['headCtrlCrvData']) self.jawCtrl.xfo.tr = data['jawPosition'] self.jawCtrl.setCurveData(data['jawCtrlCrvData']) return True def getRigBuildData(self): """Returns the Guide data used by the Rig Component to define the layout of the final rig.. Return: The JSON rig data object. """ data = super(FabriceHeadGuide, self).getRigBuildData() data['headXfo'] = self.headCtrl.xfo data['headCtrlCrvData'] = self.headCtrl.getCurveData() data['jawPosition'] = self.jawCtrl.xfo.tr data['jawCtrlCrvData'] = self.jawCtrl.getCurveData() return data # ============== # Class Methods # ============== @classmethod def getComponentType(cls): """Enables introspection of the class prior to construction to determine if it is a guide component. Return: The true if this component is a guide component. """ return 'Guide' @classmethod def getRigComponentClass(cls): """Returns the corresponding rig component class for this guide component class Return: The rig component class. """ return FabriceHeadRig
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()
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() # Shin self.shinFKCtrlSpace = CtrlSpace('shinFK', parent=self.femurFKCtrl) self.shinFKCtrl = Control('shinFK', parent=self.shinFKCtrlSpace, shape="cube") self.shinFKCtrl.alignOnXAxis() # Ankle self.legIKCtrlSpace = CtrlSpace('IK', parent=self.ctrlCmpGrp) self.legIKCtrl = Control('IK', parent=self.legIKCtrlSpace, shape="pin") # FK Foot self.footCtrlSpace = CtrlSpace('foot', parent=self.ctrlCmpGrp) self.footCtrl = Control('foot', parent=self.footCtrlSpace, shape="cube") self.footCtrl.alignOnXAxis() # FK Toe self.toeCtrlSpace = CtrlSpace('toe', parent=self.footCtrl) self.toeCtrl = Control('toe', parent=self.toeCtrlSpace, shape="cube") self.toeCtrl.alignOnXAxis() # Rig Ref objects self.footRefSrt = Locator('footRef', parent=self.ctrlCmpGrp) # Add Component Params to IK control footSettingsAttrGrp = AttributeGroup("DisplayInfo_FootSettings", parent=self.footCtrl) footLinkToWorldInputAttr = ScalarAttribute('linkToWorld', 1.0, maxValue=1.0, parent=footSettingsAttrGrp) # Add Component Params to IK control legSettingsAttrGrp = AttributeGroup("DisplayInfo_LegSettings", parent=self.legIKCtrl) legDrawDebugInputAttr = BoolAttribute('drawDebug', 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) legSoftIKInputAttr = BoolAttribute('softIK', value=True, parent=legSettingsAttrGrp) legSoftDistInputAttr = ScalarAttribute('softDist', value=0.0, minValue=0.0, parent=legSettingsAttrGrp) legStretchInputAttr = BoolAttribute('stretch', value=True, parent=legSettingsAttrGrp) legStretchBlendInputAttr = ScalarAttribute('stretchBlend', value=0.0, minValue=0.0, maxValue=1.0, parent=legSettingsAttrGrp) self.drawDebugInputAttr.connect(legDrawDebugInputAttr) # UpV self.legUpVCtrlSpace = CtrlSpace('UpV', parent=self.ctrlCmpGrp) self.legUpVCtrl = Control('UpV', parent=self.legUpVCtrlSpace, shape="triangle") self.legUpVCtrl.alignOnZAxis() # ========== # Deformers # ========== deformersLayer = self.getOrCreateLayer('deformers') self.defCmpGrp = ComponentGroup(self.getName(), self, parent=deformersLayer) femurDef = Joint('femur', parent=self.defCmpGrp) femurDef.setComponent(self) shinDef = Joint('shin', parent=self.defCmpGrp) shinDef.setComponent(self) ankleDef = Joint('ankle', parent=self.defCmpGrp) ankleDef.setComponent(self) self.footDef = Joint('foot', parent=self.defCmpGrp) self.footDef.setComponent(self) self.toeDef = Joint('toe', parent=self.defCmpGrp) self.toeDef.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.legIKCtrl.getName(), 'To', self.legPelvisInputTgt.getName()])) self.legRootInputConstraint.setMaintainOffset(True) self.legRootInputConstraint.addConstrainer(self.legPelvisInputTgt) self.femurFKCtrlSpace.addConstraint(self.legRootInputConstraint) # Constraint outputs self.footOutputConstraint = PoseConstraint('_'.join([self.footOutputTgt.getName(), 'To', self.footCtrl.getName()])) self.footOutputConstraint.addConstrainer(self.footCtrl) self.footOutputTgt.addConstraint(self.footOutputConstraint) self.toeOutputConstraint = PoseConstraint('_'.join([self.toeOutputTgt.getName(), 'To', self.toeCtrl.getName()])) self.toeOutputConstraint.addConstrainer(self.toeCtrl) self.toeOutputTgt.addConstraint(self.toeOutputConstraint) # =============== # Add Splice Ops # =============== # Add Leg Splice Op self.legIKSpliceOp = SpliceOperator('legSpliceOp', 'TwoBoneIKSolver', 'Kraken') self.addOperator(self.legIKSpliceOp) # Add Att Inputs self.legIKSpliceOp.setInput('drawDebug', self.drawDebugInputAttr) self.legIKSpliceOp.setInput('rigScale', self.rigScaleInputAttr) self.legIKSpliceOp.setInput('bone0Len', self.legBone0LenInputAttr) self.legIKSpliceOp.setInput('bone1Len', self.legBone1LenInputAttr) self.legIKSpliceOp.setInput('ikblend', legIKBlendInputAttr) self.legIKSpliceOp.setInput('softIK', legSoftIKInputAttr) self.legIKSpliceOp.setInput('softDist', legSoftDistInputAttr) self.legIKSpliceOp.setInput('stretch', legStretchInputAttr) self.legIKSpliceOp.setInput('stretchBlend', legStretchBlendInputAttr) self.legIKSpliceOp.setInput('rightSide', self.rightSideInputAttr) # Add Xfo Inputs self.legIKSpliceOp.setInput('root', self.legPelvisInputTgt) self.legIKSpliceOp.setInput('bone0FK', self.femurFKCtrl) self.legIKSpliceOp.setInput('bone1FK', self.shinFKCtrl) self.legIKSpliceOp.setInput('ikHandle', self.legIKCtrl) self.legIKSpliceOp.setInput('upV', self.legUpVCtrl) # Add Xfo Outputs self.legIKSpliceOp.setOutput('bone0Out', self.femurOutputTgt) self.legIKSpliceOp.setOutput('bone1Out', self.shinOutputTgt) self.legIKSpliceOp.setOutput('bone2Out', self.legEndXfoOutputTgt) # Add Leg Deformer Splice Op self.outputsToDeformersSpliceOp = SpliceOperator('legDeformerSpliceOp', 'MultiPoseConstraintSolver', 'Kraken') self.addOperator(self.outputsToDeformersSpliceOp) # Add Att Inputs self.outputsToDeformersSpliceOp.setInput('drawDebug', self.drawDebugInputAttr) self.outputsToDeformersSpliceOp.setInput('rigScale', self.rigScaleInputAttr) # Add Xfo Inputs self.outputsToDeformersSpliceOp.setInput('constrainers', [self.femurOutputTgt, self.shinOutputTgt, self.legEndXfoOutputTgt]) # Add Xfo Outputs self.outputsToDeformersSpliceOp.setOutput('constrainees', [femurDef, shinDef, ankleDef]) # Add Foot Deformer Splice Op self.footDefSpliceOp = SpliceOperator('footDeformerSpliceOp', 'PoseConstraintSolver', 'Kraken') self.addOperator(self.footDefSpliceOp) # Add Att Inputs self.footDefSpliceOp.setInput('drawDebug', self.drawDebugInputAttr) self.footDefSpliceOp.setInput('rigScale', self.rigScaleInputAttr) # Add Xfo Inputs) self.footDefSpliceOp.setInput('constrainer', self.footOutputTgt) # Add Xfo Outputs self.footDefSpliceOp.setOutput('constrainee', self.footDef) # Add Toe Deformer Splice Op self.toeDefSpliceOp = SpliceOperator('toeDeformerSpliceOp', 'PoseConstraintSolver', 'Kraken') self.addOperator(self.toeDefSpliceOp) # Add Att Inputs self.toeDefSpliceOp.setInput('drawDebug', self.drawDebugInputAttr) self.toeDefSpliceOp.setInput('rigScale', self.rigScaleInputAttr) # Add Xfo Inputs self.toeDefSpliceOp.setInput('constrainer', self.toeOutputTgt) # Add Xfo Outputs self.toeDefSpliceOp.setOutput('constrainee', self.toeDef) 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 ) self.femurFKCtrlSpace.xfo = data['femurXfo'] self.femurFKCtrl.xfo = data['femurXfo'] self.femurFKCtrl.scalePoints(Vec3(data['femurLen'], 1.75, 1.75)) self.femurOutputTgt.xfo = data['femurXfo'] self.shinOutputTgt.xfo = data['kneeXfo'] self.shinFKCtrlSpace.xfo = data['kneeXfo'] self.shinFKCtrl.xfo = data['kneeXfo'] self.shinFKCtrl.scalePoints(Vec3(data['shinLen'], 1.5, 1.5)) self.footCtrlSpace.xfo.tr = data['ankleXfo'].tr self.footCtrl.xfo.tr = data['ankleXfo'].tr self.toeCtrlSpace.xfo = data['toeXfo'] self.toeCtrl.xfo = data['toeXfo'] self.legIKCtrlSpace.xfo.tr = data['ankleXfo'].tr self.legIKCtrl.xfo.tr = data['ankleXfo'].tr 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 = data['upVXfo'] self.legUpVCtrl.xfo = data['upVXfo'] self.rightSideInputAttr.setValue(self.getLocation() is 'R') self.legBone0LenInputAttr.setMin(0.0) self.legBone0LenInputAttr.setMax(data['femurLen'] * 3.0) self.legBone0LenInputAttr.setValue(data['femurLen']) self.legBone1LenInputAttr.setMin(0.0) self.legBone1LenInputAttr.setMax(data['shinLen'] * 3.0) self.legBone1LenInputAttr.setValue(data['shinLen']) self.legPelvisInputTgt.xfo = data['femurXfo'] # Eval Constraints self.legIKCtrlSpaceInputConstraint.evaluate() self.legUpVCtrlSpaceInputConstraint.evaluate() self.legRootInputConstraint.evaluate() self.footOutputConstraint.evaluate() self.toeOutputConstraint.evaluate() # Eval Operators self.legIKSpliceOp.evaluate() self.outputsToDeformersSpliceOp.evaluate() self.footDefSpliceOp.evaluate()
class InsectLegComponentRig(InsectLegComponent): """Insect Leg Rig""" def __init__(self, name='InsectLeg', parent=None): Profiler.getInstance().push("Construct InsectLeg Rig Component:" + name) super(InsectLegComponentRig, self).__init__(name, parent) # ========= # Controls # ========= # Chain Base self.chainBase = Locator('ChainBase', parent=self.ctrlCmpGrp) self.chainBase.setShapeVisibility(False) # FK self.fkCtrlSpaces = [] self.fkCtrls = [] self.setNumControls(4) # IK Control self.legIKCtrlSpace = CtrlSpace('IK', parent=self.ctrlCmpGrp) self.legIKCtrl = Control('IK', parent=self.legIKCtrlSpace, shape="pin") 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)) # Add Component Params to IK control legSettingsAttrGrp = AttributeGroup("DisplayInfo_LegSettings", parent=self.legIKCtrl) legdrawDebugInputAttr = BoolAttribute('drawDebug', value=False, parent=legSettingsAttrGrp) legUseInitPoseInputAttr = BoolAttribute('useInitPose', value=True, parent=legSettingsAttrGrp) self.rootIndexInputAttr = IntegerAttribute('rootIndex', value=0, parent=legSettingsAttrGrp) legFkikInputAttr = ScalarAttribute('fkik', value=1.0, minValue=0.0, maxValue=1.0, parent=legSettingsAttrGrp) # Connect IO to controls self.drawDebugInputAttr.connect(legdrawDebugInputAttr) # UpV self.legUpVCtrlSpace = CtrlSpace('UpV', parent=self.ctrlCmpGrp) self.legUpVCtrl = Control('UpV', parent=self.legUpVCtrlSpace, shape="triangle") self.legUpVCtrl.alignOnZAxis() self.legUpVCtrl.rotatePoints(0, 90, 0) # ========== # Deformers # ========== deformersLayer = self.getOrCreateLayer('deformers') self.defCmpGrp = ComponentGroup(self.getName(), self, parent=deformersLayer) self.addItem('defCmpGrp', self.defCmpGrp) self.deformerJoints = [] self.boneOutputsTgt = [] self.setNumDeformers(4) # ===================== # Create Component I/O # ===================== # Set IO Targets self.boneOutputs.setTarget(self.boneOutputsTgt) # ============== # Constrain I/O # ============== # Constraint inputs legRootInputConstraint = PoseConstraint('_'.join([ self.fkCtrlSpaces[0].getName(), 'To', self.rootInputTgt.getName() ])) legRootInputConstraint.setMaintainOffset(True) legRootInputConstraint.addConstrainer(self.rootInputTgt) self.fkCtrlSpaces[0].addConstraint(legRootInputConstraint) chainBaseInputConstraint = PoseConstraint('_'.join( [self.chainBase.getName(), 'To', self.rootInputTgt.getName()])) chainBaseInputConstraint.setMaintainOffset(True) chainBaseInputConstraint.addConstrainer(self.rootInputTgt) self.chainBase.addConstraint(chainBaseInputConstraint) # =============== # Add Canvas Ops # =============== # Add Canvas Op self.nBoneSolverKLOp = KLOperator('leg', 'NBoneIKSolver', 'Kraken') self.addOperator(self.nBoneSolverKLOp) # # Add Att Inputs self.nBoneSolverKLOp.setInput('drawDebug', self.drawDebugInputAttr) self.nBoneSolverKLOp.setInput('rigScale', self.rigScaleInputAttr) self.nBoneSolverKLOp.setInput('useInitPose', legUseInitPoseInputAttr) self.nBoneSolverKLOp.setInput('ikblend', legFkikInputAttr) self.nBoneSolverKLOp.setInput('rootIndex', self.rootIndexInputAttr) self.nBoneSolverKLOp.setInput('tipBoneLen', self.tipBoneLenInputAttr) # Add Xfo Inputs self.nBoneSolverKLOp.setInput('chainBase', self.chainBase) self.nBoneSolverKLOp.setInput('ikgoal', self.legIKCtrl) self.nBoneSolverKLOp.setInput('upVector', self.legUpVCtrl) self.nBoneSolverKLOp.setInput('fkcontrols', self.fkCtrls) # Add Xfo Outputs self.nBoneSolverKLOp.setOutput('pose', self.boneOutputsTgt) self.nBoneSolverKLOp.setOutput('legEnd', self.legEndPosOutputTgt) # Add Deformer Canvas 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.boneOutputsTgt) # Add Xfo Outputs self.outputsToDeformersKLOp.setOutput('constrainees', self.deformerJoints) Profiler.getInstance().pop() def setNumControls(self, numControls): # Add new control spaces and controls for i in xrange(len(self.fkCtrlSpaces), numControls): if i == 0: parent = self.ctrlCmpGrp else: parent = self.fkCtrls[i - 1] boneName = 'bone' + str(i + 1).zfill(2) + 'FK' fkCtrlSpace = CtrlSpace(boneName, parent=parent) fkCtrl = Control(boneName, parent=fkCtrlSpace, shape="cube") fkCtrl.alignOnXAxis() fkCtrl.lockScale(x=True, y=True, z=True) fkCtrl.lockTranslation(x=True, y=True, z=True) self.fkCtrlSpaces.append(fkCtrlSpace) self.fkCtrls.append(fkCtrl) def setNumDeformers(self, numDeformers): # Add new deformers and outputs for i in xrange(len(self.boneOutputsTgt), numDeformers): name = 'bone' + str(i + 1).zfill(2) legOutput = ComponentOutput(name, parent=self.outputHrcGrp) self.boneOutputsTgt.append(legOutput) for i in xrange(len(self.deformerJoints), numDeformers): name = 'bone' + str(i + 1).zfill(2) boneDef = Joint(name, parent=self.defCmpGrp) boneDef.setComponent(self) self.deformerJoints.append(boneDef) return True def calculateUpVXfo(self, boneXfos, endXfo): """Calculates the transform for the UpV control. Args: boneXfos (list): Bone transforms. endXfo (Xfo): Transform for the end of the chain. Returns: Xfo: Up Vector transform. """ # Calculate FW toFirst = boneXfos[1].tr.subtract(boneXfos[0].tr).unit() toTip = endXfo.tr.subtract(boneXfos[0].tr).unit() fw = toTip.cross(toFirst).unit() chainNormal = fw.cross(toTip).unit() chainZAxis = toTip.cross(chainNormal).unit() chainXfo = Xfo() chainXfo.setFromVectors(toTip.unit(), chainNormal, chainZAxis, boneXfos[0].tr) rootToTip = endXfo.tr.subtract(boneXfos[0].tr).length() upVXfo = Xfo() upVXfo.tr = chainXfo.transformVector( Vec3(rootToTip / 2.0, rootToTip / 2.0, 0.0)) return upVXfo 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(InsectLegComponentRig, self).loadData(data) boneXfos = data['boneXfos'] boneLengths = data['boneLengths'] numJoints = data['numJoints'] endXfo = data['endXfo'] # Add extra controls and outputs self.setNumControls(numJoints) self.setNumDeformers(numJoints) # Scale controls based on bone lengths for i, each in enumerate(self.fkCtrlSpaces): self.fkCtrlSpaces[i].xfo = boneXfos[i] self.fkCtrls[i].xfo = boneXfos[i] self.fkCtrls[i].scalePoints(Vec3(boneLengths[i], 1.75, 1.75)) self.chainBase.xfo = boneXfos[0] self.legIKCtrlSpace.xfo = endXfo self.legIKCtrl.xfo = endXfo upVXfo = self.calculateUpVXfo(boneXfos, endXfo) self.legUpVCtrlSpace.xfo = upVXfo self.legUpVCtrl.xfo = upVXfo # Set max on the rootIndex attribute self.rootIndexInputAttr.setMax(len(boneXfos)) # ============ # Set IO Xfos # ============ self.rootInputTgt.xfo = boneXfos[0] for i in xrange(len(boneLengths)): self.boneOutputsTgt[i].xfo = boneXfos[i] self.legEndXfoOutputTgt.xfo = endXfo self.legEndPosOutputTgt.xfo = endXfo # ============= # Set IO Attrs # ============= tipBoneLen = boneLengths[len(boneLengths) - 1] self.tipBoneLenInputAttr.setMax(tipBoneLen * 2.0) self.tipBoneLenInputAttr.setValue(tipBoneLen) # ==================== # Evaluate Splice Ops # ==================== # evaluate the nbone op so that all the output transforms are updated. self.nBoneSolverKLOp.evaluate() self.outputsToDeformersKLOp.evaluate()
class StretchyLimbComponentRig(StretchyLimbComponent): """StretchyLimb Component""" def __init__(self, name='limb', parent=None): Profiler.getInstance().push("Construct StretchyLimb Rig Component:" + name) super(StretchyLimbComponentRig, self).__init__(name, parent) # ========= # Controls # ========= # Upper (FK) self.upperFKCtrlSpace = CtrlSpace('upperFK', parent=self.ctrlCmpGrp) self.upperFKCtrl = Control('upperFK', parent=self.upperFKCtrlSpace, shape="cube") self.upperFKCtrl.alignOnXAxis() # Lower (FK) self.lowerFKCtrlSpace = CtrlSpace('lowerFK', parent=self.upperFKCtrl) self.lowerFKCtrl = Control('lowerFK', parent=self.lowerFKCtrlSpace, shape="cube") self.lowerFKCtrl.alignOnXAxis() # End (IK) self.limbIKCtrlSpace = CtrlSpace('IK', parent=self.ctrlCmpGrp) self.limbIKCtrl = Control('IK', parent=self.limbIKCtrlSpace, shape="pin") # Add Component Params to IK control # TODO: Move these separate control limbSettingsAttrGrp = AttributeGroup( "DisplayInfo_StretchyLimbSettings", parent=self.limbIKCtrl) limbDrawDebugInputAttr = BoolAttribute('drawDebug', value=False, parent=limbSettingsAttrGrp) self.limbBone0LenInputAttr = ScalarAttribute( 'bone0Len', value=1.0, parent=limbSettingsAttrGrp) self.limbBone1LenInputAttr = ScalarAttribute( 'bone1Len', value=1.0, parent=limbSettingsAttrGrp) limbIKBlendInputAttr = ScalarAttribute('ikblend', value=1.0, minValue=0.0, maxValue=1.0, parent=limbSettingsAttrGrp) limbSoftIKInputAttr = BoolAttribute('softIK', value=True, parent=limbSettingsAttrGrp) limbSoftRatioInputAttr = ScalarAttribute('softRatio', value=0.0, minValue=0.0, maxValue=1.0, parent=limbSettingsAttrGrp) limbStretchInputAttr = BoolAttribute('stretch', value=True, parent=limbSettingsAttrGrp) limbStretchBlendInputAttr = ScalarAttribute('stretchBlend', value=0.0, minValue=0.0, maxValue=1.0, parent=limbSettingsAttrGrp) limbSlideInputAttr = ScalarAttribute('slide', value=0.0, minValue=-1.0, maxValue=1.0, parent=limbSettingsAttrGrp) limbPinInputAttr = ScalarAttribute('pin', value=0.0, minValue=0.0, maxValue=1.0, parent=limbSettingsAttrGrp) self.rightSideInputAttr = BoolAttribute('rightSide', value=False, parent=limbSettingsAttrGrp) self.drawDebugInputAttr.connect(limbDrawDebugInputAttr) # UpV (IK Pole Vector) self.limbUpVCtrlSpace = CtrlSpace('UpV', parent=self.ctrlCmpGrp) self.limbUpVCtrl = Control('UpV', parent=self.limbUpVCtrlSpace, shape="triangle") self.limbUpVCtrl.alignOnZAxis() # ========== # Deformers # ========== deformersLayer = self.getOrCreateLayer('deformers') self.defCmpGrp = ComponentGroup(self.getName(), self, parent=deformersLayer) self.addItem('defCmpGrp', self.defCmpGrp) upperDef = Joint('upper', parent=self.defCmpGrp) upperDef.setComponent(self) lowerDef = Joint('lower', parent=self.defCmpGrp) lowerDef.setComponent(self) endDef = Joint('end', parent=self.defCmpGrp) endDef.setComponent(self) # ============== # Constrain I/O # ============== # Constraint inputs self.limbIKCtrlSpaceInputConstraint = PoseConstraint('_'.join([ self.limbIKCtrlSpace.getName(), 'To', self.globalSRTInputTgt.getName() ])) self.limbIKCtrlSpaceInputConstraint.setMaintainOffset(True) self.limbIKCtrlSpaceInputConstraint.addConstrainer( self.globalSRTInputTgt) self.limbIKCtrlSpace.addConstraint(self.limbIKCtrlSpaceInputConstraint) self.limbUpVCtrlSpaceInputConstraint = PoseConstraint('_'.join([ self.limbUpVCtrlSpace.getName(), 'To', self.globalSRTInputTgt.getName() ])) self.limbUpVCtrlSpaceInputConstraint.setMaintainOffset(True) self.limbUpVCtrlSpaceInputConstraint.addConstrainer( self.globalSRTInputTgt) self.limbUpVCtrlSpace.addConstraint( self.limbUpVCtrlSpaceInputConstraint) self.limbRootInputConstraint = PoseConstraint('_'.join([ self.limbIKCtrl.getName(), 'To', self.limbParentInputTgt.getName() ])) self.limbRootInputConstraint.setMaintainOffset(True) self.limbRootInputConstraint.addConstrainer(self.limbParentInputTgt) self.upperFKCtrlSpace.addConstraint(self.limbRootInputConstraint) # =============== # Add Splice Ops # =============== # Add StretchyLimb Splice Op self.limbIKKLOp = KLOperator('limbKLOp', 'TwoBoneStretchyIKSolver', 'Kraken') self.addOperator(self.limbIKKLOp) # Add Att Inputs self.limbIKKLOp.setInput('drawDebug', self.drawDebugInputAttr) self.limbIKKLOp.setInput('rigScale', self.rigScaleInputAttr) self.limbIKKLOp.setInput('bone0Len', self.limbBone0LenInputAttr) self.limbIKKLOp.setInput('bone1Len', self.limbBone1LenInputAttr) self.limbIKKLOp.setInput('ikblend', limbIKBlendInputAttr) self.limbIKKLOp.setInput('softIK', limbSoftIKInputAttr) self.limbIKKLOp.setInput('softRatio', limbSoftRatioInputAttr) self.limbIKKLOp.setInput('stretch', limbStretchInputAttr) self.limbIKKLOp.setInput('stretchBlend', limbStretchBlendInputAttr) self.limbIKKLOp.setInput('slide', limbSlideInputAttr) self.limbIKKLOp.setInput('pin', limbPinInputAttr) self.limbIKKLOp.setInput('rightSide', self.rightSideInputAttr) # Add Xfo Inputs self.limbIKKLOp.setInput('root', self.limbParentInputTgt) self.limbIKKLOp.setInput('bone0FK', self.upperFKCtrl) self.limbIKKLOp.setInput('bone1FK', self.lowerFKCtrl) self.limbIKKLOp.setInput('ikHandle', self.limbIKCtrl) self.limbIKKLOp.setInput('upV', self.limbUpVCtrl) # Add Xfo Outputs self.limbIKKLOp.setOutput('bone0Out', self.limbUpperOutputTgt) self.limbIKKLOp.setOutput('bone1Out', self.limbLowerOutputTgt) self.limbIKKLOp.setOutput('bone2Out', self.limbEndOutputTgt) # ===================== # Connect the deformers # ===================== # Add StretchyLimb Deformer Splice Op self.outputsToDeformersKLOp = KLOperator('limbDeformerKLOp', '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.limbUpperOutputTgt, self.limbLowerOutputTgt, self.limbEndOutputTgt ]) # Add Xfo Outputs self.outputsToDeformersKLOp.setOutput('constrainees', [upperDef, lowerDef, endDef]) 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(StretchyLimbComponentRig, self).loadData(data) upperXfo = data.get('upperXfo') upperLen = data.get('upperLen') lowerXfo = data.get('lowerXfo') lowerLen = data.get('lowerLen') endXfo = data.get('endXfo') upVXfo = data.get('upVXfo') self.upperFKCtrlSpace.xfo = upperXfo self.upperFKCtrl.xfo = upperXfo self.upperFKCtrl.scalePoints(Vec3(upperLen, 1.75, 1.75)) self.limbUpperOutputTgt.xfo = upperXfo self.limbLowerOutputTgt.xfo = lowerXfo self.lowerFKCtrlSpace.xfo = lowerXfo self.lowerFKCtrl.xfo = lowerXfo self.lowerFKCtrl.scalePoints(Vec3(lowerLen, 1.5, 1.5)) self.limbIKCtrlSpace.xfo.tr = endXfo.tr self.limbIKCtrl.xfo.tr = endXfo.tr if self.getLocation() == "R": self.limbIKCtrl.rotatePoints(0, 90, 0) self.limbIKCtrl.translatePoints(Vec3(-1.0, 0.0, 0.0)) else: self.limbIKCtrl.rotatePoints(0, -90, 0) self.limbIKCtrl.translatePoints(Vec3(1.0, 0.0, 0.0)) self.limbUpVCtrlSpace.xfo = upVXfo self.limbUpVCtrl.xfo = upVXfo self.limbBone0LenInputAttr.setMin(0.0) self.limbBone0LenInputAttr.setMax(upperLen * 3.0) self.limbBone0LenInputAttr.setValue(upperLen) self.limbBone1LenInputAttr.setMin(0.0) self.limbBone1LenInputAttr.setMax(lowerLen * 3.0) self.limbBone1LenInputAttr.setValue(lowerLen) self.limbParentInputTgt.xfo = upperXfo # Set Attrs self.rightSideInputAttr.setValue(self.getLocation() is 'R') # Eval Constraints self.limbIKCtrlSpaceInputConstraint.evaluate() self.limbUpVCtrlSpaceInputConstraint.evaluate() self.limbRootInputConstraint.evaluate() # Eval Operators self.limbIKKLOp.evaluate() self.outputsToDeformersKLOp.evaluate()
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() # Forearm self.forearmFKCtrlSpace = CtrlSpace("forearmFK", parent=self.bicepFKCtrl) self.forearmFKCtrl = Control("forearmFK", parent=self.forearmFKCtrlSpace, shape="cube") self.forearmFKCtrl.alignOnXAxis() self.handCtrlSpace = CtrlSpace("hand", parent=self.ctrlCmpGrp) self.handCtrl = Control("hand", parent=self.handCtrlSpace, shape="circle") self.handCtrl.rotatePoints(0, 0, 90) self.handCtrl.scalePoints(Vec3(1.0, 0.75, 0.75)) # Arm IK self.armIKCtrlSpace = CtrlSpace("IK", parent=self.ctrlCmpGrp) self.armIKCtrl = Control("IK", parent=self.armIKCtrlSpace, shape="pin") # Add Params to IK control armSettingsAttrGrp = AttributeGroup("DisplayInfo_ArmSettings", parent=self.armIKCtrl) 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) armIKBlendInputAttr = ScalarAttribute("fkik", value=0.0, minValue=0.0, maxValue=1.0, parent=armSettingsAttrGrp) armSoftIKInputAttr = BoolAttribute("softIK", value=True, parent=armSettingsAttrGrp) armSoftDistInputAttr = ScalarAttribute("softDist", value=0.0, minValue=0.0, parent=armSettingsAttrGrp) armStretchInputAttr = BoolAttribute("stretch", value=True, parent=armSettingsAttrGrp) armStretchBlendInputAttr = ScalarAttribute( "stretchBlend", value=0.0, minValue=0.0, maxValue=1.0, parent=armSettingsAttrGrp ) # Hand Params handSettingsAttrGrp = AttributeGroup("DisplayInfo_HandSettings", parent=self.handCtrl) handLinkToWorldInputAttr = ScalarAttribute("linkToWorld", 0.0, maxValue=1.0, parent=handSettingsAttrGrp) self.drawDebugInputAttr.connect(armDebugInputAttr) # 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) # ========== # Deformers # ========== deformersLayer = self.getOrCreateLayer("deformers") defCmpGrp = ComponentGroup(self.getName(), self, parent=deformersLayer) bicepDef = Joint("bicep", parent=defCmpGrp) bicepDef.setComponent(self) forearmDef = Joint("forearm", parent=defCmpGrp) forearmDef.setComponent(self) wristDef = Joint("wrist", parent=defCmpGrp) wristDef.setComponent(self) handDef = Joint("hand", parent=defCmpGrp) handDef.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.clavicleEndInputTgt.getName()]) ) self.armRootInputConstraint.setMaintainOffset(True) self.armRootInputConstraint.addConstrainer(self.clavicleEndInputTgt) self.bicepFKCtrlSpace.addConstraint(self.armRootInputConstraint) # Constraint outputs self.handConstraint = PoseConstraint("_".join([self.handOutputTgt.getName(), "To", self.handCtrl.getName()])) self.handConstraint.addConstrainer(self.handCtrl) self.handOutputTgt.addConstraint(self.handConstraint) self.handCtrlSpaceConstraint = PoseConstraint( "_".join([self.handCtrlSpace.getName(), "To", self.armEndXfoOutputTgt.getName()]) ) self.handCtrlSpaceConstraint.setMaintainOffset(True) self.handCtrlSpaceConstraint.addConstrainer(self.armEndXfoOutputTgt) self.handCtrlSpace.addConstraint(self.handCtrlSpaceConstraint) # =============== # Add Splice Ops # =============== # Add Splice Op self.spliceOp = SpliceOperator("armSpliceOp", "TwoBoneIKSolver", "Kraken") self.addOperator(self.spliceOp) # Add Att Inputs self.spliceOp.setInput("drawDebug", self.drawDebugInputAttr) self.spliceOp.setInput("rigScale", self.rigScaleInputAttr) self.spliceOp.setInput("bone0Len", self.armBone0LenInputAttr) self.spliceOp.setInput("bone1Len", self.armBone1LenInputAttr) self.spliceOp.setInput("ikblend", armIKBlendInputAttr) self.spliceOp.setInput("softIK", armSoftIKInputAttr) self.spliceOp.setInput("softDist", armSoftDistInputAttr) self.spliceOp.setInput("stretch", armStretchInputAttr) self.spliceOp.setInput("stretchBlend", armStretchBlendInputAttr) self.spliceOp.setInput("rightSide", self.rightSideInputAttr) # Add Xfo Inputs self.spliceOp.setInput("root", self.clavicleEndInputTgt) self.spliceOp.setInput("bone0FK", self.bicepFKCtrl) self.spliceOp.setInput("bone1FK", self.forearmFKCtrl) self.spliceOp.setInput("ikHandle", self.armIKCtrl) self.spliceOp.setInput("upV", self.armUpVCtrl) # Add Xfo Outputs self.spliceOp.setOutput("bone0Out", self.bicepOutputTgt) self.spliceOp.setOutput("bone1Out", self.forearmOutputTgt) self.spliceOp.setOutput("bone2Out", self.armEndXfoOutputTgt) # Add Deformer Splice Op self.outputsToDeformersSpliceOp = SpliceOperator("armDeformerSpliceOp", "MultiPoseConstraintSolver", "Kraken") self.addOperator(self.outputsToDeformersSpliceOp) # Add Att Inputs self.outputsToDeformersSpliceOp.setInput("drawDebug", self.drawDebugInputAttr) self.outputsToDeformersSpliceOp.setInput("rigScale", self.rigScaleInputAttr) # Add Xfo Inputs self.outputsToDeformersSpliceOp.setInput( "constrainers", [self.bicepOutputTgt, self.forearmOutputTgt, self.armEndXfoOutputTgt, self.handOutputTgt] ) # Add Xfo Outputs self.outputsToDeformersSpliceOp.setOutput("constrainees", [bicepDef, forearmDef, wristDef, handDef]) 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) self.clavicleEndInputTgt.xfo.tr = data["bicepXfo"].tr self.bicepFKCtrlSpace.xfo = data["bicepXfo"] self.bicepFKCtrl.xfo = data["bicepXfo"] self.bicepFKCtrl.scalePoints(Vec3(data["bicepLen"], data["bicepFKCtrlSize"], data["bicepFKCtrlSize"])) self.bicepOutputTgt.xfo = data["bicepXfo"] self.forearmOutputTgt.xfo = data["forearmXfo"] self.forearmFKCtrlSpace.xfo = data["forearmXfo"] self.forearmFKCtrl.xfo = data["forearmXfo"] self.forearmFKCtrl.scalePoints(Vec3(data["forearmLen"], data["forearmFKCtrlSize"], data["forearmFKCtrlSize"])) self.handCtrlSpace.xfo = data["handXfo"] self.handCtrl.xfo = data["handXfo"] self.armIKCtrlSpace.xfo.tr = data["armEndXfo"].tr self.armIKCtrl.xfo.tr = data["armEndXfo"].tr if self.getLocation() == "R": self.armIKCtrl.rotatePoints(0, 90, 0) else: self.armIKCtrl.rotatePoints(0, -90, 0) self.armUpVCtrlSpace.xfo = data["upVXfo"] self.armUpVCtrl.xfo = data["upVXfo"] self.rightSideInputAttr.setValue(self.getLocation() is "R") self.armBone0LenInputAttr.setMin(0.0) self.armBone0LenInputAttr.setMax(data["bicepLen"] * 3.0) self.armBone0LenInputAttr.setValue(data["bicepLen"]) self.armBone1LenInputAttr.setMin(0.0) self.armBone1LenInputAttr.setMax(data["forearmLen"] * 3.0) self.armBone1LenInputAttr.setValue(data["forearmLen"]) # Outputs self.handOutputTgt.xfo = data["handXfo"] # Eval Constraints self.armIKCtrlSpaceInputConstraint.evaluate() self.armUpVCtrlSpaceInputConstraint.evaluate() self.armRootInputConstraint.evaluate() self.armRootInputConstraint.evaluate() self.handConstraint.evaluate() self.handCtrlSpaceConstraint.evaluate() # Eval Operators self.spliceOp.evaluate() self.outputsToDeformersSpliceOp.evaluate()
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()
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() # Forearm self.forearmFKCtrlSpace = CtrlSpace('forearmFK', parent=self.bicepFKCtrl) self.forearmFKCtrl = Control('forearmFK', parent=self.forearmFKCtrlSpace, shape="cube") self.forearmFKCtrl.alignOnXAxis() self.handCtrlSpace = CtrlSpace('hand', parent=self.ctrlCmpGrp) self.handCtrl = Control('hand', parent=self.handCtrlSpace, shape="circle") self.handCtrl.rotatePoints(0, 0, 90) self.handCtrl.scalePoints(Vec3(1.0, 0.75, 0.75)) # Arm IK self.armIKCtrlSpace = CtrlSpace('IK', parent=self.ctrlCmpGrp) self.armIKCtrl = Control('IK', parent=self.armIKCtrlSpace, shape="pin") # Add Params to IK control armSettingsAttrGrp = AttributeGroup("DisplayInfo_ArmSettings", parent=self.armIKCtrl) 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) armIKBlendInputAttr = ScalarAttribute('fkik', value=0.0, minValue=0.0, maxValue=1.0, parent=armSettingsAttrGrp) armSoftIKInputAttr = BoolAttribute('softIK', value=True, parent=armSettingsAttrGrp) armSoftDistInputAttr = ScalarAttribute('softDist', value=0.0, minValue=0.0, parent=armSettingsAttrGrp) armStretchInputAttr = BoolAttribute('stretch', value=True, parent=armSettingsAttrGrp) armStretchBlendInputAttr = ScalarAttribute('stretchBlend', value=0.0, minValue=0.0, maxValue=1.0, parent=armSettingsAttrGrp) # Hand Params handSettingsAttrGrp = AttributeGroup("DisplayInfo_HandSettings", parent=self.handCtrl) handLinkToWorldInputAttr = ScalarAttribute('linkToWorld', 0.0, maxValue=1.0, parent=handSettingsAttrGrp) self.drawDebugInputAttr.connect(armDebugInputAttr) # 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) # ========== # Deformers # ========== deformersLayer = self.getOrCreateLayer('deformers') defCmpGrp = ComponentGroup(self.getName(), self, parent=deformersLayer) bicepDef = Joint('bicep', parent=defCmpGrp) bicepDef.setComponent(self) forearmDef = Joint('forearm', parent=defCmpGrp) forearmDef.setComponent(self) wristDef = Joint('wrist', parent=defCmpGrp) wristDef.setComponent(self) handDef = Joint('hand', parent=defCmpGrp) handDef.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.clavicleEndInputTgt.getName() ])) self.armRootInputConstraint.setMaintainOffset(True) self.armRootInputConstraint.addConstrainer(self.clavicleEndInputTgt) self.bicepFKCtrlSpace.addConstraint(self.armRootInputConstraint) # Constraint outputs self.handConstraint = PoseConstraint('_'.join( [self.handOutputTgt.getName(), 'To', self.handCtrl.getName()])) self.handConstraint.addConstrainer(self.handCtrl) self.handOutputTgt.addConstraint(self.handConstraint) self.handCtrlSpaceConstraint = PoseConstraint('_'.join([ self.handCtrlSpace.getName(), 'To', self.armEndXfoOutputTgt.getName() ])) self.handCtrlSpaceConstraint.setMaintainOffset(True) self.handCtrlSpaceConstraint.addConstrainer(self.armEndXfoOutputTgt) self.handCtrlSpace.addConstraint(self.handCtrlSpaceConstraint) # =============== # Add Splice Ops # =============== # Add Splice Op self.spliceOp = KLOperator('armKLOp', 'TwoBoneIKSolver', 'Kraken') self.addOperator(self.spliceOp) # Add Att Inputs self.spliceOp.setInput('drawDebug', self.drawDebugInputAttr) self.spliceOp.setInput('rigScale', self.rigScaleInputAttr) self.spliceOp.setInput('bone0Len', self.armBone0LenInputAttr) self.spliceOp.setInput('bone1Len', self.armBone1LenInputAttr) self.spliceOp.setInput('ikblend', armIKBlendInputAttr) self.spliceOp.setInput('softIK', armSoftIKInputAttr) self.spliceOp.setInput('softDist', armSoftDistInputAttr) self.spliceOp.setInput('stretch', armStretchInputAttr) self.spliceOp.setInput('stretchBlend', armStretchBlendInputAttr) self.spliceOp.setInput('rightSide', self.rightSideInputAttr) # Add Xfo Inputs self.spliceOp.setInput('root', self.clavicleEndInputTgt) self.spliceOp.setInput('bone0FK', self.bicepFKCtrl) self.spliceOp.setInput('bone1FK', self.forearmFKCtrl) self.spliceOp.setInput('ikHandle', self.armIKCtrl) self.spliceOp.setInput('upV', self.armUpVCtrl) # Add Xfo Outputs self.spliceOp.setOutput('bone0Out', self.bicepOutputTgt) self.spliceOp.setOutput('bone1Out', self.forearmOutputTgt) self.spliceOp.setOutput('bone2Out', self.armEndXfoOutputTgt) # Add Deformer Splice Op self.outputsToDeformersKLOp = KLOperator('armDeformerKLOp', '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.forearmOutputTgt, self.armEndXfoOutputTgt, self.handOutputTgt ]) # Add Xfo Outputs self.outputsToDeformersKLOp.setOutput( 'constrainees', [bicepDef, forearmDef, wristDef, handDef]) 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) self.clavicleEndInputTgt.xfo.tr = data['bicepXfo'].tr self.bicepFKCtrlSpace.xfo = data['bicepXfo'] self.bicepFKCtrl.xfo = data['bicepXfo'] self.bicepFKCtrl.scalePoints( Vec3(data['bicepLen'], data['bicepFKCtrlSize'], data['bicepFKCtrlSize'])) self.bicepOutputTgt.xfo = data['bicepXfo'] self.forearmOutputTgt.xfo = data['forearmXfo'] self.forearmFKCtrlSpace.xfo = data['forearmXfo'] self.forearmFKCtrl.xfo = data['forearmXfo'] self.forearmFKCtrl.scalePoints( Vec3(data['forearmLen'], data['forearmFKCtrlSize'], data['forearmFKCtrlSize'])) self.handCtrlSpace.xfo = data['handXfo'] self.handCtrl.xfo = data['handXfo'] self.armIKCtrlSpace.xfo.tr = data['armEndXfo'].tr self.armIKCtrl.xfo.tr = data['armEndXfo'].tr if self.getLocation() == "R": self.armIKCtrl.rotatePoints(0, 90, 0) else: self.armIKCtrl.rotatePoints(0, -90, 0) self.armUpVCtrlSpace.xfo = data['upVXfo'] self.armUpVCtrl.xfo = data['upVXfo'] self.rightSideInputAttr.setValue(self.getLocation() is 'R') self.armBone0LenInputAttr.setMin(0.0) self.armBone0LenInputAttr.setMax(data['bicepLen'] * 3.0) self.armBone0LenInputAttr.setValue(data['bicepLen']) self.armBone1LenInputAttr.setMin(0.0) self.armBone1LenInputAttr.setMax(data['forearmLen'] * 3.0) self.armBone1LenInputAttr.setValue(data['forearmLen']) # Outputs self.handOutputTgt.xfo = data['handXfo'] # Eval Constraints self.armIKCtrlSpaceInputConstraint.evaluate() self.armUpVCtrlSpaceInputConstraint.evaluate() self.armRootInputConstraint.evaluate() self.armRootInputConstraint.evaluate() self.handConstraint.evaluate() self.handCtrlSpaceConstraint.evaluate() # Eval Operators self.spliceOp.evaluate() self.outputsToDeformersKLOp.evaluate()
class HeadComponentRig(HeadComponent): """Head Component Rig""" 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 loadData(self, data=None): """Load a saved guide representation from persisted data. Arguments: data -- object, The JSON data object. Return: True if successful. """ super(HeadComponentRig, self).loadData(data) headXfo = data.get('headXfo') headCrvData = data.get('headCrvData') eyeLeftXfo = data.get('eyeLeftXfo') eyeLeftCrvData = data.get('eyeLeftCrvData') eyeRightXfo = data.get('eyeRightXfo') eyeRightCrvData = data.get('eyeRightCrvData') jawXfo = data.get('jawXfo') jawCrvData = data.get('jawCrvData') self.headCtrlSpace.xfo = headXfo self.headCtrl.xfo = headXfo self.headCtrl.setCurveData(headCrvData) # self.eyeLeftCtrlSpace.xfo = eyeLeftXfo # self.eyeLeftCtrl.xfo = eyeLeftXfo self.eyeLeftCtrl.setCurveData(eyeLeftCrvData) # self.eyeRightCtrlSpace.xfo = eyeRightXfo # self.eyeRightCtrl.xfo = eyeRightXfo self.eyeRightCtrl.setCurveData(eyeRightCrvData) # LookAt eyeLeftRelXfo = headXfo.inverse() * eyeLeftXfo eyeRightRelXfo = headXfo.inverse() * eyeRightXfo eyeMidRelPos = eyeLeftRelXfo.tr.linearInterpolate(eyeRightRelXfo.tr, 0.5) eyeMidRelPos = eyeMidRelPos + Vec3(0.0, 0.0, 8.0) eyeLen = eyeLeftRelXfo.tr.distanceTo(eyeRightRelXfo.tr) self.eyeLeftBase.xfo = eyeLeftXfo self.eyeRightBase.xfo = eyeRightXfo self.eyeLeftUpV.xfo = eyeLeftXfo * Xfo(Vec3(0, 1, 0)) self.eyeRightUpV.xfo = eyeRightXfo * Xfo(Vec3(0, 1, 0)) self.eyeLeftAtV.xfo.tr = eyeLeftXfo.transformVector(Vec3(8.0, 0.0, 0.0)) self.eyeRightAtV.xfo.tr = eyeRightXfo.transformVector(Vec3(8.0, 0.0, 0.0)) lookAtXfo = headXfo.clone() lookAtXfo.tr = headXfo.transformVector(eyeMidRelPos) self.lookAtCtrl.scalePoints(Vec3(eyeLen * 1.6, eyeLen * 0.65, 1.0)) self.lookAtCtrl.xfo = lookAtXfo self.lookAtCtrlSpace.xfo = lookAtXfo self.jawCtrlSpace.xfo = jawXfo self.jawCtrl.xfo = jawXfo self.jawCtrl.setCurveData(jawCrvData) # ============ # Set IO Xfos # ============ self.neckRefInputTgt.xfo = headXfo self.worldRefInputTgt.xfo = headXfo self.headOutputTgt.xfo = headXfo self.jawOutputTgt.xfo = jawXfo self.eyeLOutputTgt.xfo = eyeLeftXfo self.eyeROutputTgt.xfo = eyeRightXfo # Eval Constraints self.headInputConstraint.evaluate() self.headOutputConstraint.evaluate() self.jawOutputConstraint.evaluate() self.eyeLOutputConstraint.evaluate() self.eyeROutputConstraint.evaluate() # Eval Operators self.eyeLeftDirKLOp.evaluate() self.eyeRightDirKLOp.evaluate() self.outputsToDeformersKLOp.evaluate() # Have to set the eye control xfos to match the evaluated xfos from self.eyeLeftCtrl.xfo = self.eyeLeftCtrlSpace.xfo self.eyeRightCtrl.xfo = self.eyeRightCtrlSpace.xfo
class HeadComponentRig(HeadComponent): """Head Component Rig""" def __init__(self, name='head', parent=None): Profiler.getInstance().push("Construct Head Rig Component:" + name) super(HeadComponentRig, self).__init__(name, parent) # ========= # Controls # ========= # Head self.headCtrlSpace = CtrlSpace('head', parent=self.ctrlCmpGrp) self.headCtrl = Control('head', parent=self.headCtrlSpace, shape="circle") self.headCtrl.rotatePoints(0, 0, 90) self.headCtrl.scalePoints(Vec3(3, 3, 3)) self.headCtrl.translatePoints(Vec3(0, 1, 0.25)) # Eye Left self.eyeLeftCtrlSpace = CtrlSpace('eyeLeft', parent=self.headCtrl) self.eyeLeftCtrl = Control('eyeLeft', parent=self.eyeLeftCtrlSpace, shape="sphere") self.eyeLeftCtrl.scalePoints(Vec3(0.5, 0.5, 0.5)) self.eyeLeftCtrl.setColor("blueMedium") # Eye Right self.eyeRightCtrlSpace = CtrlSpace('eyeRight', parent=self.headCtrl) self.eyeRightCtrl = Control('eyeRight', parent=self.eyeRightCtrlSpace, shape="sphere") self.eyeRightCtrl.scalePoints(Vec3(0.5, 0.5, 0.5)) self.eyeRightCtrl.setColor("blueMedium") # Jaw self.jawCtrlSpace = CtrlSpace('jawCtrlSpace', parent=self.headCtrl) self.jawCtrl = Control('jaw', parent=self.jawCtrlSpace, shape="cube") 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') defCmpGrp = ComponentGroup(self.getName(), self, parent=deformersLayer) headDef = Joint('head', parent=defCmpGrp) headDef.setComponent(self) jawDef = Joint('jaw', parent=defCmpGrp) jawDef.setComponent(self) eyeLeftDef = Joint('eyeLeft', parent=defCmpGrp) eyeLeftDef.setComponent(self) eyeRightDef = Joint('eyeRight', parent=defCmpGrp) eyeRightDef.setComponent(self) # ============== # Constrain I/O # ============== # Constraint inputs headInputConstraint = PoseConstraint('_'.join([ self.headCtrlSpace.getName(), 'To', self.headBaseInputTgt.getName() ])) headInputConstraint.setMaintainOffset(True) headInputConstraint.addConstrainer(self.headBaseInputTgt) self.headCtrlSpace.addConstraint(headInputConstraint) # # Constraint outputs headOutputConstraint = PoseConstraint('_'.join( [self.headOutputTgt.getName(), 'To', self.headCtrl.getName()])) headOutputConstraint.addConstrainer(self.headCtrl) self.headOutputTgt.addConstraint(headOutputConstraint) jawOutputConstraint = PoseConstraint('_'.join( [self.jawOutputTgt.getName(), 'To', self.jawCtrl.getName()])) jawOutputConstraint.addConstrainer(self.jawCtrl) self.jawOutputTgt.addConstraint(jawOutputConstraint) eyeLOutputConstraint = PoseConstraint('_'.join( [self.eyeLOutputTgt.getName(), 'To', self.eyeLeftCtrl.getName()])) eyeLOutputConstraint.addConstrainer(self.eyeLeftCtrl) self.eyeLOutputTgt.addConstraint(eyeLOutputConstraint) eyeROutputConstraint = PoseConstraint('_'.join( [self.eyeROutputTgt.getName(), 'To', self.eyeRightCtrl.getName()])) eyeROutputConstraint.addConstrainer(self.eyeRightCtrl) self.eyeROutputTgt.addConstraint(eyeROutputConstraint) # ================== # Add Component I/O # ================== # Add Xfo I/O's # self.addInput(self.headBaseInputTgt) # self.addOutput(self.headOutputTgt) # self.addOutput(self.jawOutputTgt) # self.addOutput(self.eyeLOutputTgt) # self.addOutput(self.eyeROutputTgt) # Add Attribute I/O's # self.addInput(self.drawDebugInputAttr) # =============== # Add Splice Ops # =============== # Add Deformer Splice Op # spliceOp = SpliceOperator('headDeformerSpliceOp', 'HeadConstraintSolver', 'KrakenHeadConstraintSolver') # self.addOperator(spliceOp) # # Add Att Inputs # spliceOp.setInput('drawDebug', self.drawDebugInputAttr) # spliceOp.setInput('rigScale', self.rigScaleInputAttr) # # Add Xfo Inputstrl) # spliceOp.setInput('headConstrainer', self.headOutputTgt) # spliceOp.setInput('jawConstrainer', self.jawOutputTgt) # spliceOp.setInput('eyeLeftConstrainer', self.eyeLOutputTgt) # spliceOp.setInput('eyeRightConstrainer', self.eyeROutputTgt) # # Add Xfo Outputs # spliceOp.setOutput('headDeformer', headDef) # spliceOp.setOutput('jawDeformer', jawDef) # spliceOp.setOutput('eyeLeftDeformer', eyeLeftDef) # spliceOp.setOutput('eyeRightDeformer', eyeRightDef) 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(HeadComponentRig, self).loadData(data) self.headCtrlSpace.xfo.tr = data['headPosition'] self.headCtrl.xfo.tr = data['headPosition'] self.eyeLeftCtrlSpace.xfo.tr = data['eyeLeftPosition'] self.eyeLeftCtrl.xfo.tr = data['eyeLeftPosition'] self.eyeRightCtrlSpace.xfo.tr = data['eyeRightPosition'] self.eyeRightCtrl.xfo.tr = data['eyeRightPosition'] self.jawCtrlSpace.xfo.tr = data['jawPosition'] self.jawCtrl.xfo.tr = data['jawPosition'] # ============ # Set IO Xfos # ============ self.headBaseInputTgt.xfo.tr = data['headPosition'] self.headOutputTgt.xfo.tr = data['headPosition'] self.jawOutputTgt.xfo.tr = data['jawPosition'] self.eyeLOutputTgt.xfo.tr = data['eyeLeftPosition'] self.eyeROutputTgt.xfo.tr = data['eyeRightPosition']
class FabriceHeadGuide(FabriceHead): """Fabrice Head Component Guide""" def __init__(self, name='head', parent=None): Profiler.getInstance().push("Construct Head Guide Component:" + name) super(FabriceHeadGuide, self).__init__(name, parent) # ========= # Controls # ========= guideSettingsAttrGrp = AttributeGroup("GuideSettings", parent=self) self.headCtrl = Control('head', parent=self.ctrlCmpGrp, shape="circle") self.headCtrl.rotatePoints(90.0, 0.0, 0.0) self.headCtrl.scalePoints(Vec3(3.5, 3.5, 3.5)) self.jawCtrl = Control('jaw', parent=self.ctrlCmpGrp, shape="cube") self.jawCtrl.alignOnZAxis() self.jawCtrl.scalePoints(Vec3(2.0, 0.5, 2.0)) self.jawCtrl.alignOnYAxis(negative=True) self.jawCtrl.setColor('orange') data = { "name": name, "location": "M", "headXfo": Xfo(Vec3(0.0, 1.67, 1.75)), "headCtrlCrvData": self.headCtrl.getCurveData(), "jawPosition": Vec3(0.0, 1.2787, 2.0078), "jawCtrlCrvData": self.jawCtrl.getCurveData(), } self.loadData(data) Profiler.getInstance().pop() # ============= # Data Methods # ============= def saveData(self): """Save the data for the component to be persisted. Return: The JSON data object """ data = super(FabriceHeadGuide, self).saveData() data['headXfo'] = self.headCtrl.xfo data['headCtrlCrvData'] = self.headCtrl.getCurveData() data['jawPosition'] = self.jawCtrl.xfo.tr data['jawCtrlCrvData'] = self.jawCtrl.getCurveData() return data def loadData(self, data): """Load a saved guide representation from persisted data. Arguments: data -- object, The JSON data object. Return: True if successful. """ super(FabriceHeadGuide, self).loadData( data ) self.headCtrl.xfo = data['headXfo'] self.headCtrl.setCurveData(data['headCtrlCrvData']) self.jawCtrl.xfo.tr = data['jawPosition'] self.jawCtrl.setCurveData(data['jawCtrlCrvData']) return True def getRigBuildData(self): """Returns the Guide data used by the Rig Component to define the layout of the final rig.. Return: The JSON rig data object. """ data = super(FabriceHeadGuide, self).getRigBuildData() data['headXfo'] = self.headCtrl.xfo data['headCtrlCrvData'] = self.headCtrl.getCurveData() data['jawPosition'] = self.jawCtrl.xfo.tr data['jawCtrlCrvData'] = self.jawCtrl.getCurveData() return data # ============== # Class Methods # ============== @classmethod def getComponentType(cls): """Enables introspection of the class prior to construction to determine if it is a guide component. Return: The true if this component is a guide component. """ return 'Guide' @classmethod def getRigComponentClass(cls): """Returns the corresponding rig component class for this guide component class Return: The rig component class. """ return FabriceHeadRig
class InsectLegComponentRig(InsectLegComponent): """Insect Leg Rig""" def __init__(self, name='InsectLeg', parent=None): Profiler.getInstance().push("Construct InsectLeg Rig Component:" + name) super(InsectLegComponentRig, self).__init__(name, parent) # ========= # Controls # ========= # Chain Base self.chainBase = Locator('ChainBase', parent=self.ctrlCmpGrp) self.chainBase.setShapeVisibility(False) # FK self.fkCtrlSpaces = [] self.fkCtrls = [] self.setNumControls(4) # IK Control self.legIKCtrlSpace = CtrlSpace('IK', parent=self.ctrlCmpGrp) self.legIKCtrl = Control('IK', parent=self.legIKCtrlSpace, shape="pin") 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)) # Add Component Params to IK control legSettingsAttrGrp = AttributeGroup("DisplayInfo_LegSettings", parent=self.legIKCtrl) legdrawDebugInputAttr = BoolAttribute('drawDebug', value=False, parent=legSettingsAttrGrp) legUseInitPoseInputAttr = BoolAttribute('useInitPose', value=True, parent=legSettingsAttrGrp) self.rootIndexInputAttr = IntegerAttribute('rootIndex', value=0, parent=legSettingsAttrGrp) legFkikInputAttr = ScalarAttribute('fkik', value=1.0, minValue=0.0, maxValue=1.0, parent=legSettingsAttrGrp) # Connect IO to controls self.drawDebugInputAttr.connect(legdrawDebugInputAttr) # UpV self.legUpVCtrlSpace = CtrlSpace('UpV', parent=self.ctrlCmpGrp) self.legUpVCtrl = Control('UpV', parent=self.legUpVCtrlSpace, shape="triangle") self.legUpVCtrl.alignOnZAxis() self.legUpVCtrl.rotatePoints(0, 90, 0) # ========== # Deformers # ========== deformersLayer = self.getOrCreateLayer('deformers') self.defCmpGrp = ComponentGroup(self.getName(), self, parent=deformersLayer) self.deformerJoints = [] self.boneOutputsTgt = [] self.setNumDeformers(4) # ===================== # Create Component I/O # ===================== # Set IO Targets self.boneOutputs.setTarget(self.boneOutputsTgt) # ============== # Constrain I/O # ============== # Constraint inputs legRootInputConstraint = PoseConstraint('_'.join([self.fkCtrlSpaces[0].getName(), 'To', self.rootInputTgt.getName()])) legRootInputConstraint.setMaintainOffset(True) legRootInputConstraint.addConstrainer(self.rootInputTgt) self.fkCtrlSpaces[0].addConstraint(legRootInputConstraint) chainBaseInputConstraint = PoseConstraint('_'.join([self.chainBase.getName(), 'To', self.rootInputTgt.getName()])) chainBaseInputConstraint.setMaintainOffset(True) chainBaseInputConstraint.addConstrainer(self.rootInputTgt) self.chainBase.addConstraint(chainBaseInputConstraint) # =============== # Add Splice Ops # =============== # Add Splice Op self.nBoneSolverSpliceOp = SpliceOperator('legSpliceOp', 'NBoneIKSolver', 'Kraken') self.addOperator(self.nBoneSolverSpliceOp) # # Add Att Inputs self.nBoneSolverSpliceOp.setInput('drawDebug', self.drawDebugInputAttr) self.nBoneSolverSpliceOp.setInput('rigScale', self.rigScaleInputAttr) self.nBoneSolverSpliceOp.setInput('useInitPose', legUseInitPoseInputAttr) self.nBoneSolverSpliceOp.setInput('ikblend', legFkikInputAttr) self.nBoneSolverSpliceOp.setInput('rootIndex', self.rootIndexInputAttr) self.nBoneSolverSpliceOp.setInput('tipBoneLen', self.tipBoneLenInputAttr) # Add Xfo Inputs self.nBoneSolverSpliceOp.setInput('chainBase', self.chainBase) self.nBoneSolverSpliceOp.setInput('ikgoal', self.legIKCtrl) self.nBoneSolverSpliceOp.setInput('upVector', self.legUpVCtrl) self.nBoneSolverSpliceOp.setInput('fkcontrols', self.fkCtrls) # Add Xfo Outputs self.nBoneSolverSpliceOp.setOutput('pose', self.boneOutputsTgt) self.nBoneSolverSpliceOp.setOutput('legEnd', self.legEndPosOutputTgt) # Add Deformer Splice Op self.outputsToDeformersSpliceOp = SpliceOperator('insectLegDeformerSpliceOp', 'MultiPoseConstraintSolver', 'Kraken') self.addOperator(self.outputsToDeformersSpliceOp) # Add Att Inputs self.outputsToDeformersSpliceOp.setInput('drawDebug', self.drawDebugInputAttr) self.outputsToDeformersSpliceOp.setInput('rigScale', self.rigScaleInputAttr) # Add Xfo Inputs self.outputsToDeformersSpliceOp.setInput('constrainers', self.boneOutputsTgt) # Add Xfo Outputs self.outputsToDeformersSpliceOp.setOutput('constrainees', self.deformerJoints) Profiler.getInstance().pop() def setNumControls(self, numControls): # Add new control spaces and controls for i in xrange(len(self.fkCtrlSpaces), numControls): if i==0: parent = self.ctrlCmpGrp else: parent = self.fkCtrls[i - 1] boneName = 'bone' + str(i + 1).zfill(2) + 'FK' fkCtrlSpace = CtrlSpace(boneName, parent=parent) fkCtrl = Control(boneName, parent=fkCtrlSpace, shape="cube") fkCtrl.alignOnXAxis() fkCtrl.lockScale(x=True, y=True, z=True) fkCtrl.lockTranslation(x=True, y=True, z=True) self.fkCtrlSpaces.append(fkCtrlSpace) self.fkCtrls.append(fkCtrl) def setNumDeformers(self, numDeformers): # Add new deformers and outputs for i in xrange(len(self.boneOutputsTgt), numDeformers): name = 'bone' + str(i + 1).zfill(2) legOutput = ComponentOutput(name, parent=self.outputHrcGrp) self.boneOutputsTgt.append(legOutput) for i in xrange(len(self.deformerJoints), numDeformers): name = 'bone' + str(i + 1).zfill(2) boneDef = Joint(name, parent=self.defCmpGrp) boneDef.setComponent(self) self.deformerJoints.append(boneDef) return True def calculateUpVXfo(self, boneXfos, endXfo): """Calculates the transform for the UpV control. Args: boneXfos (list): Bone transforms. endXfo (Xfo): Transform for the end of the chain. Returns: Xfo: Up Vector transform. """ # Calculate FW toFirst = boneXfos[1].tr.subtract(boneXfos[0].tr).unit() toTip = endXfo.tr.subtract(boneXfos[0].tr).unit() fw = toTip.cross(toFirst).unit() chainNormal = fw.cross(toTip).unit() chainZAxis = toTip.cross(chainNormal).unit() chainXfo = Xfo() chainXfo.setFromVectors(toTip.unit(), chainNormal, chainZAxis, boneXfos[0].tr) rootToTip = endXfo.tr.subtract(boneXfos[0].tr).length() upVXfo = Xfo() upVXfo.tr = chainXfo.transformVector(Vec3(rootToTip / 2.0, rootToTip / 2.0, 0.0)) return upVXfo 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(InsectLegComponentRig, self).loadData( data ) boneXfos = data['boneXfos'] boneLengths = data['boneLengths'] numJoints = data['numJoints'] endXfo = data['endXfo'] # Add extra controls and outputs self.setNumControls(numJoints) self.setNumDeformers(numJoints) # Scale controls based on bone lengths for i, each in enumerate(self.fkCtrlSpaces): self.fkCtrlSpaces[i].xfo = boneXfos[i] self.fkCtrls[i].xfo = boneXfos[i] self.fkCtrls[i].scalePoints(Vec3(boneLengths[i], 1.75, 1.75)) self.chainBase.xfo = boneXfos[0] self.legIKCtrlSpace.xfo = endXfo self.legIKCtrl.xfo = endXfo upVXfo = self.calculateUpVXfo(boneXfos, endXfo) self.legUpVCtrlSpace.xfo = upVXfo self.legUpVCtrl.xfo = upVXfo # Set max on the rootIndex attribute self.rootIndexInputAttr.setMax(len(boneXfos)) # ============ # Set IO Xfos # ============ self.rootInputTgt.xfo = boneXfos[0] for i in xrange(len(boneLengths)): self.boneOutputsTgt[i].xfo = boneXfos[i] self.legEndXfoOutputTgt.xfo = endXfo self.legEndPosOutputTgt.xfo = endXfo # ============= # Set IO Attrs # ============= tipBoneLen = boneLengths[len(boneLengths) - 1] self.tipBoneLenInputAttr.setMax(tipBoneLen * 2.0) self.tipBoneLenInputAttr.setValue(tipBoneLen) # ==================== # Evaluate Splice Ops # ==================== # evaluate the nbone op so that all the output transforms are updated. self.nBoneSolverSpliceOp.evaluate() self.outputsToDeformersSpliceOp.evaluate()
class HeadComponentRig(HeadComponent): """Head Component Rig""" def __init__(self, name='head', parent=None): Profiler.getInstance().push("Construct Head Rig Component:" + name) super(HeadComponentRig, self).__init__(name, parent) # ========= # Controls # ========= # Head self.headCtrlSpace = CtrlSpace('head', parent=self.ctrlCmpGrp) self.headCtrl = Control('head', parent=self.headCtrlSpace, shape="circle") self.headCtrl.rotatePoints(0, 0, 90) self.headCtrl.scalePoints(Vec3(3, 3, 3)) self.headCtrl.translatePoints(Vec3(0, 1, 0.25)) # Eye Left self.eyeLeftCtrlSpace = CtrlSpace('eyeLeft', parent=self.headCtrl) self.eyeLeftCtrl = Control('eyeLeft', parent=self.eyeLeftCtrlSpace, shape="sphere") self.eyeLeftCtrl.scalePoints(Vec3(0.5, 0.5, 0.5)) self.eyeLeftCtrl.setColor("blueMedium") # Eye Right self.eyeRightCtrlSpace = CtrlSpace('eyeRight', parent=self.headCtrl) self.eyeRightCtrl = Control('eyeRight', parent=self.eyeRightCtrlSpace, shape="sphere") self.eyeRightCtrl.scalePoints(Vec3(0.5, 0.5, 0.5)) self.eyeRightCtrl.setColor("blueMedium") # Jaw self.jawCtrlSpace = CtrlSpace('jawCtrlSpace', parent=self.headCtrl) self.jawCtrl = Control('jaw', parent=self.jawCtrlSpace, shape="cube") 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') defCmpGrp = ComponentGroup(self.getName(), self, parent=deformersLayer) headDef = Joint('head', parent=defCmpGrp) headDef.setComponent(self) jawDef = Joint('jaw', parent=defCmpGrp) jawDef.setComponent(self) eyeLeftDef = Joint('eyeLeft', parent=defCmpGrp) eyeLeftDef.setComponent(self) eyeRightDef = Joint('eyeRight', parent=defCmpGrp) eyeRightDef.setComponent(self) # ============== # Constrain I/O # ============== # Constraint inputs headInputConstraint = PoseConstraint('_'.join([self.headCtrlSpace.getName(), 'To', self.headBaseInputTgt.getName()])) headInputConstraint.setMaintainOffset(True) headInputConstraint.addConstrainer(self.headBaseInputTgt) self.headCtrlSpace.addConstraint(headInputConstraint) # # Constraint outputs headOutputConstraint = PoseConstraint('_'.join([self.headOutputTgt.getName(), 'To', self.headCtrl.getName()])) headOutputConstraint.addConstrainer(self.headCtrl) self.headOutputTgt.addConstraint(headOutputConstraint) jawOutputConstraint = PoseConstraint('_'.join([self.jawOutputTgt.getName(), 'To', self.jawCtrl.getName()])) jawOutputConstraint.addConstrainer(self.jawCtrl) self.jawOutputTgt.addConstraint(jawOutputConstraint) eyeLOutputConstraint = PoseConstraint('_'.join([self.eyeLOutputTgt.getName(), 'To', self.eyeLeftCtrl.getName()])) eyeLOutputConstraint.addConstrainer(self.eyeLeftCtrl) self.eyeLOutputTgt.addConstraint(eyeLOutputConstraint) eyeROutputConstraint = PoseConstraint('_'.join([self.eyeROutputTgt.getName(), 'To', self.eyeRightCtrl.getName()])) eyeROutputConstraint.addConstrainer(self.eyeRightCtrl) self.eyeROutputTgt.addConstraint(eyeROutputConstraint) # ================== # Add Component I/O # ================== # Add Xfo I/O's # self.addInput(self.headBaseInputTgt) # self.addOutput(self.headOutputTgt) # self.addOutput(self.jawOutputTgt) # self.addOutput(self.eyeLOutputTgt) # self.addOutput(self.eyeROutputTgt) # Add Attribute I/O's # self.addInput(self.drawDebugInputAttr) # =============== # Add Splice Ops # =============== # Add Deformer Splice Op # spliceOp = SpliceOperator('headDeformerSpliceOp', 'HeadConstraintSolver', 'KrakenHeadConstraintSolver') # self.addOperator(spliceOp) # # Add Att Inputs # spliceOp.setInput('drawDebug', self.drawDebugInputAttr) # spliceOp.setInput('rigScale', self.rigScaleInputAttr) # # Add Xfo Inputstrl) # spliceOp.setInput('headConstrainer', self.headOutputTgt) # spliceOp.setInput('jawConstrainer', self.jawOutputTgt) # spliceOp.setInput('eyeLeftConstrainer', self.eyeLOutputTgt) # spliceOp.setInput('eyeRightConstrainer', self.eyeROutputTgt) # # Add Xfo Outputs # spliceOp.setOutput('headDeformer', headDef) # spliceOp.setOutput('jawDeformer', jawDef) # spliceOp.setOutput('eyeLeftDeformer', eyeLeftDef) # spliceOp.setOutput('eyeRightDeformer', eyeRightDef) 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(HeadComponentRig, self).loadData( data ) self.headCtrlSpace.xfo.tr = data['headPosition'] self.headCtrl.xfo.tr = data['headPosition'] self.eyeLeftCtrlSpace.xfo.tr = data['eyeLeftPosition'] self.eyeLeftCtrl.xfo.tr = data['eyeLeftPosition'] self.eyeRightCtrlSpace.xfo.tr = data['eyeRightPosition'] self.eyeRightCtrl.xfo.tr = data['eyeRightPosition'] self.jawCtrlSpace.xfo.tr = data['jawPosition'] self.jawCtrl.xfo.tr = data['jawPosition'] # ============ # Set IO Xfos # ============ self.headBaseInputTgt.xfo.tr = data['headPosition'] self.headOutputTgt.xfo.tr = data['headPosition'] self.jawOutputTgt.xfo.tr = data['jawPosition'] self.eyeLOutputTgt.xfo.tr = data['eyeLeftPosition'] self.eyeROutputTgt.xfo.tr = data['eyeRightPosition']
class StretchyLimbComponentRig(StretchyLimbComponent): """StretchyLimb Component""" def __init__(self, name='limb', parent=None): Profiler.getInstance().push("Construct StretchyLimb Rig Component:" + name) super(StretchyLimbComponentRig, self).__init__(name, parent) # ========= # Controls # ========= # Upper (FK) self.upperFKCtrlSpace = CtrlSpace('upperFK', parent=self.ctrlCmpGrp) self.upperFKCtrl = Control('upperFK', parent=self.upperFKCtrlSpace, shape="cube") self.upperFKCtrl.alignOnXAxis() # Lower (FK) self.lowerFKCtrlSpace = CtrlSpace('lowerFK', parent=self.upperFKCtrl) self.lowerFKCtrl = Control('lowerFK', parent=self.lowerFKCtrlSpace, shape="cube") self.lowerFKCtrl.alignOnXAxis() # End (IK) self.limbIKCtrlSpace = CtrlSpace('IK', parent=self.ctrlCmpGrp) self.limbIKCtrl = Control('IK', parent=self.limbIKCtrlSpace, shape="pin") # Add Component Params to IK control # TODO: Move these separate control limbSettingsAttrGrp = AttributeGroup("DisplayInfo_StretchyLimbSettings", parent=self.limbIKCtrl) limbDrawDebugInputAttr = BoolAttribute('drawDebug', value=False, parent=limbSettingsAttrGrp) self.limbBone0LenInputAttr = ScalarAttribute('bone0Len', value=1.0, parent=limbSettingsAttrGrp) self.limbBone1LenInputAttr = ScalarAttribute('bone1Len', value=1.0, parent=limbSettingsAttrGrp) limbIKBlendInputAttr = ScalarAttribute('ikblend', value=1.0, minValue=0.0, maxValue=1.0, parent=limbSettingsAttrGrp) limbSoftIKInputAttr = BoolAttribute('softIK', value=True, parent=limbSettingsAttrGrp) limbSoftRatioInputAttr = ScalarAttribute('softRatio', value=0.0, minValue=0.0, maxValue=1.0, parent=limbSettingsAttrGrp) limbStretchInputAttr = BoolAttribute('stretch', value=True, parent=limbSettingsAttrGrp) limbStretchBlendInputAttr = ScalarAttribute('stretchBlend', value=0.0, minValue=0.0, maxValue=1.0, parent=limbSettingsAttrGrp) limbSlideInputAttr = ScalarAttribute('slide', value=0.0, minValue=-1.0, maxValue=1.0, parent=limbSettingsAttrGrp) limbPinInputAttr = ScalarAttribute('pin', value=0.0, minValue=0.0, maxValue=1.0, parent=limbSettingsAttrGrp) self.rightSideInputAttr = BoolAttribute('rightSide', value=False, parent=limbSettingsAttrGrp) self.drawDebugInputAttr.connect(limbDrawDebugInputAttr) # UpV (IK Pole Vector) self.limbUpVCtrlSpace = CtrlSpace('UpV', parent=self.ctrlCmpGrp) self.limbUpVCtrl = Control('UpV', parent=self.limbUpVCtrlSpace, shape="triangle") self.limbUpVCtrl.alignOnZAxis() # ========== # Deformers # ========== deformersLayer = self.getOrCreateLayer('deformers') self.defCmpGrp = ComponentGroup(self.getName(), self, parent=deformersLayer) self.addItem('defCmpGrp', self.defCmpGrp) upperDef = Joint('upper', parent=self.defCmpGrp) upperDef.setComponent(self) lowerDef = Joint('lower', parent=self.defCmpGrp) lowerDef.setComponent(self) endDef = Joint('end', parent=self.defCmpGrp) endDef.setComponent(self) # ============== # Constrain I/O # ============== # Constraint inputs self.limbIKCtrlSpaceInputConstraint = PoseConstraint('_'.join([self.limbIKCtrlSpace.getName(), 'To', self.globalSRTInputTgt.getName()])) self.limbIKCtrlSpaceInputConstraint.setMaintainOffset(True) self.limbIKCtrlSpaceInputConstraint.addConstrainer(self.globalSRTInputTgt) self.limbIKCtrlSpace.addConstraint(self.limbIKCtrlSpaceInputConstraint) self.limbUpVCtrlSpaceInputConstraint = PoseConstraint('_'.join([self.limbUpVCtrlSpace.getName(), 'To', self.globalSRTInputTgt.getName()])) self.limbUpVCtrlSpaceInputConstraint.setMaintainOffset(True) self.limbUpVCtrlSpaceInputConstraint.addConstrainer(self.globalSRTInputTgt) self.limbUpVCtrlSpace.addConstraint(self.limbUpVCtrlSpaceInputConstraint) self.limbRootInputConstraint = PoseConstraint('_'.join([self.limbIKCtrl.getName(), 'To', self.limbParentInputTgt.getName()])) self.limbRootInputConstraint.setMaintainOffset(True) self.limbRootInputConstraint.addConstrainer(self.limbParentInputTgt) self.upperFKCtrlSpace.addConstraint(self.limbRootInputConstraint) # =============== # Add Splice Ops # =============== # Add StretchyLimb Splice Op self.limbIKKLOp = KLOperator('limbKLOp', 'TwoBoneStretchyIKSolver', 'Kraken') self.addOperator(self.limbIKKLOp) # Add Att Inputs self.limbIKKLOp.setInput('drawDebug', self.drawDebugInputAttr) self.limbIKKLOp.setInput('rigScale', self.rigScaleInputAttr) self.limbIKKLOp.setInput('bone0Len', self.limbBone0LenInputAttr) self.limbIKKLOp.setInput('bone1Len', self.limbBone1LenInputAttr) self.limbIKKLOp.setInput('ikblend', limbIKBlendInputAttr) self.limbIKKLOp.setInput('softIK', limbSoftIKInputAttr) self.limbIKKLOp.setInput('softRatio', limbSoftRatioInputAttr) self.limbIKKLOp.setInput('stretch', limbStretchInputAttr) self.limbIKKLOp.setInput('stretchBlend', limbStretchBlendInputAttr) self.limbIKKLOp.setInput('slide', limbSlideInputAttr) self.limbIKKLOp.setInput('pin', limbPinInputAttr) self.limbIKKLOp.setInput('rightSide', self.rightSideInputAttr) # Add Xfo Inputs self.limbIKKLOp.setInput('root', self.limbParentInputTgt) self.limbIKKLOp.setInput('bone0FK', self.upperFKCtrl) self.limbIKKLOp.setInput('bone1FK', self.lowerFKCtrl) self.limbIKKLOp.setInput('ikHandle', self.limbIKCtrl) self.limbIKKLOp.setInput('upV', self.limbUpVCtrl) # Add Xfo Outputs self.limbIKKLOp.setOutput('bone0Out', self.limbUpperOutputTgt) self.limbIKKLOp.setOutput('bone1Out', self.limbLowerOutputTgt) self.limbIKKLOp.setOutput('bone2Out', self.limbEndOutputTgt) # ===================== # Connect the deformers # ===================== # Add StretchyLimb Deformer Splice Op self.outputsToDeformersKLOp = KLOperator('limbDeformerKLOp', '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.limbUpperOutputTgt, self.limbLowerOutputTgt, self.limbEndOutputTgt]) # Add Xfo Outputs self.outputsToDeformersKLOp.setOutput('constrainees', [upperDef, lowerDef, endDef]) 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(StretchyLimbComponentRig, self).loadData(data) upperXfo = data.get('upperXfo') upperLen = data.get('upperLen') lowerXfo = data.get('lowerXfo') lowerLen = data.get('lowerLen') endXfo = data.get('endXfo') upVXfo = data.get('upVXfo') self.upperFKCtrlSpace.xfo = upperXfo self.upperFKCtrl.xfo = upperXfo self.upperFKCtrl.scalePoints(Vec3(upperLen, 1.75, 1.75)) self.limbUpperOutputTgt.xfo = upperXfo self.limbLowerOutputTgt.xfo = lowerXfo self.lowerFKCtrlSpace.xfo = lowerXfo self.lowerFKCtrl.xfo = lowerXfo self.lowerFKCtrl.scalePoints(Vec3(lowerLen, 1.5, 1.5)) self.limbIKCtrlSpace.xfo.tr = endXfo.tr self.limbIKCtrl.xfo.tr = endXfo.tr if self.getLocation() == "R": self.limbIKCtrl.rotatePoints(0, 90, 0) self.limbIKCtrl.translatePoints(Vec3(-1.0, 0.0, 0.0)) else: self.limbIKCtrl.rotatePoints(0, -90, 0) self.limbIKCtrl.translatePoints(Vec3(1.0, 0.0, 0.0)) self.limbUpVCtrlSpace.xfo = upVXfo self.limbUpVCtrl.xfo = upVXfo self.limbBone0LenInputAttr.setMin(0.0) self.limbBone0LenInputAttr.setMax(upperLen * 3.0) self.limbBone0LenInputAttr.setValue(upperLen) self.limbBone1LenInputAttr.setMin(0.0) self.limbBone1LenInputAttr.setMax(lowerLen * 3.0) self.limbBone1LenInputAttr.setValue(lowerLen) self.limbParentInputTgt.xfo = upperXfo # Set Attrs self.rightSideInputAttr.setValue(self.getLocation() is 'R') # Eval Constraints self.limbIKCtrlSpaceInputConstraint.evaluate() self.limbUpVCtrlSpaceInputConstraint.evaluate() self.limbRootInputConstraint.evaluate() # Eval Operators self.limbIKKLOp.evaluate() self.outputsToDeformersKLOp.evaluate()