Example #1
0
    def __init__(self, name='Clavicle', parent=None):

        Profiler.getInstance().push("Construct Clavicle Rig Component:" + name)
        super(FabriceClavicleRig, self).__init__(name, parent)


        # =========
        # Controls
        # =========
        # Clavicle
        self.clavicleCtrlSpace = CtrlSpace('clavicle', parent=self.ctrlCmpGrp)
        self.clavicleCtrl = Control('clavicle', parent=self.clavicleCtrlSpace, shape="cube")
        self.clavicleCtrl.alignOnXAxis()


        # ==========
        # Deformers
        # ==========
        deformersLayer = self.getOrCreateLayer('deformers')
        defCmpGrp = ComponentGroup(self.getName(), self, parent=deformersLayer)
        self.ctrlCmpGrp.setComponent(self)

        self.clavicleDef = Joint('clavicle', parent=defCmpGrp)
        self.clavicleDef.setComponent(self)


        # ==============
        # Constrain I/O
        # ==============
        # Constraint inputs
        clavicleInputConstraint = PoseConstraint('_'.join([self.clavicleCtrl.getName(), 'To', self.spineEndInputTgt.getName()]))
        clavicleInputConstraint.setMaintainOffset(True)
        clavicleInputConstraint.addConstrainer(self.spineEndInputTgt)
        self.clavicleCtrlSpace.addConstraint(clavicleInputConstraint)

        # Constraint outputs
        clavicleConstraint = PoseConstraint('_'.join([self.clavicleOutputTgt.getName(), 'To', self.clavicleCtrl.getName()]))
        clavicleConstraint.addConstrainer(self.clavicleCtrl)
        self.clavicleOutputTgt.addConstraint(clavicleConstraint)


        # ===============
        # Add Splice Ops
        # ===============
        # Add Deformer Splice Op
        spliceOp = SpliceOperator('clavicleDeformerSpliceOp', 'PoseConstraintSolver', 'Kraken')
        self.addOperator(spliceOp)

        # Add Att Inputs
        spliceOp.setInput('drawDebug', self.drawDebugInputAttr)
        spliceOp.setInput('rigScale', self.rigScaleInputAttr)

        # Add Xfo Inputs
        spliceOp.setInput('constrainer', self.clavicleOutputTgt)

        # Add Xfo Outputs
        spliceOp.setOutput('constrainee', self.clavicleDef)

        Profiler.getInstance().pop()
Example #2
0
class SpineComponentRig(SpineComponent):
    """Spine Component"""
    def __init__(self, name="spine", parent=None):

        Profiler.getInstance().push("Construct Spine Rig Component:" + name)
        super(SpineComponentRig, self).__init__(name, parent)

        # =========
        # Controls
        # =========
        # COG
        self.cogCtrlSpace = CtrlSpace('cog', parent=self.ctrlCmpGrp)
        self.cogCtrl = Control('cog', parent=self.cogCtrlSpace, shape="circle")
        self.cogCtrl.scalePoints(Vec3(6.0, 6.0, 6.0))
        self.cogCtrl.setColor("orange")

        # Spine01
        self.spine01CtrlSpace = CtrlSpace('spine01', parent=self.cogCtrl)
        self.spine01Ctrl = Control('spine01',
                                   parent=self.spine01CtrlSpace,
                                   shape="circle")
        self.spine01Ctrl.scalePoints(Vec3(4.0, 4.0, 4.0))

        # Spine02
        self.spine02CtrlSpace = CtrlSpace('spine02', parent=self.spine01Ctrl)
        self.spine02Ctrl = Control('spine02',
                                   parent=self.spine02CtrlSpace,
                                   shape="circle")
        self.spine02Ctrl.scalePoints(Vec3(4.5, 4.5, 4.5))

        # Spine03
        self.spine03CtrlSpace = CtrlSpace('spine03', parent=self.spine02Ctrl)
        self.spine03Ctrl = Control('spine03',
                                   parent=self.spine03CtrlSpace,
                                   shape="circle")
        self.spine03Ctrl.scalePoints(Vec3(4.5, 4.5, 4.5))
        self.spine03Ctrl.setColor("blue")

        # Spine04
        self.spine04CtrlSpace = CtrlSpace('spine04', parent=self.cogCtrl)
        self.spine04Ctrl = Control('spine04',
                                   parent=self.spine04CtrlSpace,
                                   shape="circle")
        self.spine04Ctrl.scalePoints(Vec3(6.0, 6.0, 6.0))

        # Pelvis
        self.pelvisCtrlSpace = CtrlSpace('pelvis', parent=self.cogCtrl)
        self.pelvisCtrl = Control('pelvis',
                                  parent=self.pelvisCtrlSpace,
                                  shape="cube")
        self.pelvisCtrl.alignOnYAxis(negative=True)
        self.pelvisCtrl.scalePoints(Vec3(2.0, 1.5, 1.5))

        # ==========
        # Deformers
        # ==========
        deformersLayer = self.getOrCreateLayer('deformers')
        self.defCmpGrp = ComponentGroup(self.getName(),
                                        self,
                                        parent=deformersLayer)
        self.deformerJoints = []
        self.spineOutputs = []
        self.setNumDeformers(1)

        pelvisDef = Joint('pelvis', parent=self.defCmpGrp)
        pelvisDef.setComponent(self)

        # =====================
        # Create Component I/O
        # =====================
        # Setup component Xfo I/O's
        self.spineVertebraeOutput.setTarget(self.spineOutputs)

        # ==============
        # Constrain I/O
        # ==============
        # Constraint inputs
        self.spineSrtInputConstraint = PoseConstraint('_'.join([
            self.cogCtrlSpace.getName(), 'To',
            self.spineMainSrtInputTgt.getName()
        ]))
        self.spineSrtInputConstraint.addConstrainer(self.spineMainSrtInputTgt)
        self.spineSrtInputConstraint.setMaintainOffset(True)
        self.cogCtrlSpace.addConstraint(self.spineSrtInputConstraint)

        # Constraint outputs
        self.spineCogOutputConstraint = PoseConstraint('_'.join(
            [self.spineCogOutputTgt.getName(), 'To',
             self.cogCtrl.getName()]))
        self.spineCogOutputConstraint.addConstrainer(self.cogCtrl)
        self.spineCogOutputTgt.addConstraint(self.spineCogOutputConstraint)

        self.spineBaseOutputConstraint = PoseConstraint('_'.join(
            [self.spineBaseOutputTgt.getName(), 'To', 'spineBase']))
        self.spineBaseOutputConstraint.addConstrainer(self.spineOutputs[0])
        self.spineBaseOutputTgt.addConstraint(self.spineBaseOutputConstraint)

        self.pelvisOutputConstraint = PoseConstraint('_'.join(
            [self.pelvisOutputTgt.getName(), 'To',
             self.pelvisCtrl.getName()]))
        self.pelvisOutputConstraint.addConstrainer(self.pelvisCtrl)
        self.pelvisOutputTgt.addConstraint(self.pelvisOutputConstraint)

        self.spineEndOutputConstraint = PoseConstraint('_'.join(
            [self.spineEndOutputTgt.getName(), 'To', 'spineEnd']))
        self.spineEndOutputConstraint.addConstrainer(self.spineOutputs[0])
        self.spineEndOutputTgt.addConstraint(self.spineEndOutputConstraint)

        # ===============
        # Add Splice Ops
        # ===============
        # Add Spine Splice Op
        self.bezierSpineSpliceOp = SpliceOperator('spineSpliceOp',
                                                  'BezierSpineSolver',
                                                  'Kraken')
        self.addOperator(self.bezierSpineSpliceOp)

        # Add Att Inputs
        self.bezierSpineSpliceOp.setInput('drawDebug', self.drawDebugInputAttr)
        self.bezierSpineSpliceOp.setInput('rigScale', self.rigScaleInputAttr)
        self.bezierSpineSpliceOp.setInput('length', self.lengthInputAttr)

        # Add Xfo Inputs
        self.bezierSpineSpliceOp.setInput('base', self.spine01Ctrl)
        self.bezierSpineSpliceOp.setInput('baseHandle', self.spine02Ctrl)
        self.bezierSpineSpliceOp.setInput('tipHandle', self.spine03Ctrl)
        self.bezierSpineSpliceOp.setInput('tip', self.spine04Ctrl)

        # Add Xfo Outputs
        self.bezierSpineSpliceOp.setOutput('outputs', self.spineOutputs)

        # Add Deformer Splice Op
        self.deformersToOutputsSpliceOp = SpliceOperator(
            'spineDeformerSpliceOp', 'MultiPoseConstraintSolver', 'Kraken')
        self.addOperator(self.deformersToOutputsSpliceOp)

        # Add Att Inputs
        self.deformersToOutputsSpliceOp.setInput('drawDebug',
                                                 self.drawDebugInputAttr)
        self.deformersToOutputsSpliceOp.setInput('rigScale',
                                                 self.rigScaleInputAttr)

        # Add Xfo Outputs
        self.deformersToOutputsSpliceOp.setInput('constrainers',
                                                 self.spineOutputs)

        # Add Xfo Outputs
        self.deformersToOutputsSpliceOp.setOutput('constrainees',
                                                  self.deformerJoints)

        # Add Pelvis Splice Op
        self.pelvisDefSpliceOp = SpliceOperator('pelvisDeformerSpliceOp',
                                                'PoseConstraintSolver',
                                                'Kraken')
        self.addOperator(self.pelvisDefSpliceOp)

        # Add Att Inputs
        self.pelvisDefSpliceOp.setInput('drawDebug', self.drawDebugInputAttr)
        self.pelvisDefSpliceOp.setInput('rigScale', self.rigScaleInputAttr)

        # Add Xfo Inputs
        self.pelvisDefSpliceOp.setInput('constrainer', self.pelvisOutputTgt)

        # Add Xfo Outputs
        self.pelvisDefSpliceOp.setOutput('constrainee', pelvisDef)

        Profiler.getInstance().pop()

    def setNumDeformers(self, numDeformers):

        # Add new deformers and outputs
        for i in xrange(len(self.spineOutputs), numDeformers):
            name = 'spine' + str(i + 1).zfill(2)
            spineOutput = ComponentOutput(name, parent=self.outputHrcGrp)
            self.spineOutputs.append(spineOutput)

        for i in xrange(len(self.deformerJoints), numDeformers):
            name = 'spine' + str(i + 1).zfill(2)
            spineDef = Joint(name, parent=self.defCmpGrp)
            spineDef.setComponent(self)
            self.deformerJoints.append(spineDef)

        return True

    def loadData(self, data=None):
        """Load a saved guide representation from persisted data.

        Arguments:
        data -- object, The JSON data object.

        Return:
        True if successful.

        """

        super(SpineComponentRig, self).loadData(data)

        cogPosition = data['cogPosition']
        spine01Position = data['spine01Position']
        spine02Position = data['spine02Position']
        spine03Position = data['spine03Position']
        spine04Position = data['spine04Position']
        numDeformers = data['numDeformers']

        self.cogCtrlSpace.xfo.tr = cogPosition
        self.cogCtrl.xfo.tr = cogPosition

        self.pelvisCtrlSpace.xfo.tr = cogPosition
        self.pelvisCtrl.xfo.tr = cogPosition

        self.spine01CtrlSpace.xfo.tr = spine01Position
        self.spine01Ctrl.xfo.tr = spine01Position

        self.spine02CtrlSpace.xfo.tr = spine02Position
        self.spine02Ctrl.xfo.tr = spine02Position

        self.spine03CtrlSpace.xfo.tr = spine03Position
        self.spine03Ctrl.xfo.tr = spine03Position

        self.spine04CtrlSpace.xfo.tr = spine04Position
        self.spine04Ctrl.xfo.tr = spine04Position

        length = spine01Position.distanceTo(
            spine02Position) + spine02Position.distanceTo(
                spine03Position) + spine03Position.distanceTo(spine04Position)
        self.lengthInputAttr.setMax(length * 3.0)
        self.lengthInputAttr.setValue(length)

        # Update number of deformers and outputs
        self.setNumDeformers(numDeformers)

        # Updating constraint to use the updated last output.
        self.spineEndOutputConstraint.setConstrainer(self.spineOutputs[-1],
                                                     index=0)

        # ============
        # Set IO Xfos
        # ============

        # ====================
        # Evaluate Splice Ops
        # ====================
        # evaluate the spine op so that all the output transforms are updated.
        self.bezierSpineSpliceOp.evaluate()

        # evaluate the constraint op so that all the joint transforms are updated.
        self.deformersToOutputsSpliceOp.evaluate()
        self.pelvisDefSpliceOp.evaluate()

        # evaluate the constraints to ensure the outputs are now in the correct location.
        self.spineCogOutputConstraint.evaluate()
        self.spineBaseOutputConstraint.evaluate()
        self.pelvisOutputConstraint.evaluate()
        self.spineEndOutputConstraint.evaluate()
Example #3
0
class FabriceHeadRig(FabriceHead):
    """Fabrice Head Component Rig"""
    def __init__(self, name='h  ead', parent=None):

        Profiler.getInstance().push("Construct Head Rig Component:" + name)
        super(FabriceHeadRig, self).__init__(name, parent)

        # =========
        # Controls
        # =========
        # Head Aim
        self.headAimCtrlSpace = CtrlSpace('headAim', parent=self.ctrlCmpGrp)
        self.headAimCtrl = Control('headAim',
                                   parent=self.headAimCtrlSpace,
                                   shape="sphere")
        self.headAimCtrl.scalePoints(Vec3(0.35, 0.35, 0.35))
        self.headAimCtrl.lockScale(x=True, y=True, z=True)

        self.headAimUpV = Locator('headAimUpV', parent=self.headAimCtrl)
        self.headAimUpV.setShapeVisibility(False)

        # Head
        self.headAim = Locator('headAim', parent=self.ctrlCmpGrp)
        self.headAim.setShapeVisibility(False)

        self.headCtrlSpace = CtrlSpace('head', parent=self.ctrlCmpGrp)
        self.headCtrl = Control('head',
                                parent=self.headCtrlSpace,
                                shape="circle")
        self.headCtrl.lockTranslation(x=True, y=True, z=True)
        self.headCtrl.lockScale(x=True, y=True, z=True)

        # Jaw
        self.jawCtrlSpace = CtrlSpace('jawCtrlSpace', parent=self.headCtrl)
        self.jawCtrl = Control('jaw', parent=self.jawCtrlSpace, shape="cube")
        self.jawCtrl.lockTranslation(x=True, y=True, z=True)
        self.jawCtrl.lockScale(x=True, y=True, z=True)
        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)

        # ==============
        # Constrain I/O
        # ==============
        self.headToAimConstraint = PoseConstraint('_'.join(
            [self.headCtrlSpace.getName(), 'To',
             self.headAim.getName()]))
        self.headToAimConstraint.setMaintainOffset(True)
        self.headToAimConstraint.addConstrainer(self.headAim)
        self.headCtrlSpace.addConstraint(self.headToAimConstraint)

        # Constraint inputs
        self.headAimInputConstraint = PoseConstraint('_'.join([
            self.headAimCtrlSpace.getName(), 'To',
            self.headBaseInputTgt.getName()
        ]))
        self.headAimInputConstraint.setMaintainOffset(True)
        self.headAimInputConstraint.addConstrainer(self.headBaseInputTgt)
        self.headAimCtrlSpace.addConstraint(self.headAimInputConstraint)

        # # 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)

        # ===============
        # Add Splice Ops
        # ===============

        # Add Aim Splice Op
        # =================
        self.headAimSpliceOp = SpliceOperator('headAimSpliceOp',
                                              'DirectionConstraintSolver',
                                              'Kraken')
        self.addOperator(self.headAimSpliceOp)

        # Add Att Inputs
        self.headAimSpliceOp.setInput('drawDebug', self.drawDebugInputAttr)
        self.headAimSpliceOp.setInput('rigScale', self.rigScaleInputAttr)

        # Add Xfo Inputs
        self.headAimSpliceOp.setInput('position', self.headBaseInputTgt)
        self.headAimSpliceOp.setInput('upVector', self.headAimUpV)
        self.headAimSpliceOp.setInput('atVector', self.headAimCtrl)

        # Add Xfo Outputs
        self.headAimSpliceOp.setOutput('constrainee', self.headAim)

        # Add Deformer Splice Op
        # ======================
        self.deformersToOutputsSpliceOp = SpliceOperator(
            'headDeformerSpliceOp',
            'MultiPoseConstraintSolver',
            'Kraken',
            alwaysEval=True)
        self.addOperator(self.deformersToOutputsSpliceOp)

        # Add Att Inputs
        self.deformersToOutputsSpliceOp.setInput('drawDebug',
                                                 self.drawDebugInputAttr)
        self.deformersToOutputsSpliceOp.setInput('rigScale',
                                                 self.rigScaleInputAttr)

        # Add Xfo Outputs
        self.deformersToOutputsSpliceOp.setInput(
            'constrainers', [self.headOutputTgt, self.jawOutputTgt])

        # Add Xfo Outputs
        self.deformersToOutputsSpliceOp.setOutput('constrainees',
                                                  [headDef, jawDef])

        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(FabriceHeadRig, self).loadData(data)

        headXfo = data['headXfo']
        headCtrlCrvData = data['headCtrlCrvData']
        jawPosition = data['jawPosition']
        jawCtrlCrvData = data['jawCtrlCrvData']

        self.headAimCtrlSpace.xfo.ori = headXfo.ori
        self.headAimCtrlSpace.xfo.tr = headXfo.tr.add(Vec3(0, 0, 4))
        self.headAimCtrl.xfo = self.headAimCtrlSpace.xfo

        self.headAimUpV.xfo.ori = self.headAimCtrl.xfo.ori
        self.headAimUpV.xfo.tr = self.headAimCtrl.xfo.tr.add(Vec3(0, 3, 0))

        self.headAim.xfo = headXfo
        self.headCtrlSpace.xfo = headXfo
        self.headCtrl.xfo = headXfo
        self.headCtrl.setCurveData(headCtrlCrvData)

        self.jawCtrlSpace.xfo.tr = jawPosition
        self.jawCtrl.xfo.tr = jawPosition
        self.jawCtrl.setCurveData(jawCtrlCrvData)

        # ============
        # Set IO Xfos
        # ============
        self.headBaseInputTgt.xfo = headXfo
        self.headOutputTgt.xfo = headXfo
        self.jawOutputTgt.xfo.tr = jawPosition

        # ====================
        # Evaluate Splice Ops
        # ====================
        # evaluate the constraint op so that all the joint transforms are updated.
        self.headAimSpliceOp.evaluate()
        self.deformersToOutputsSpliceOp.evaluate()

        # evaluate the constraints to ensure the outputs are now in the correct location.
        self.headToAimConstraint.evaluate()
        self.headAimInputConstraint.evaluate()
        self.headOutputConstraint.evaluate()
        self.jawOutputConstraint.evaluate()
Example #4
0
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()
Example #5
0
class FabriceTailGuide(FabriceTail):
    """Fabrice Tail Component Guide"""

    def __init__(self, name='tail', parent=None):

        Profiler.getInstance().push("Construct Fabrice Tail Guide Component:" + name)
        super(FabriceTailGuide, self).__init__(name, parent)

        # =========
        # Controls
        # ========
        guideSettingsAttrGrp = AttributeGroup("GuideSettings", parent=self)
        self.numDeformersAttr = IntegerAttribute('numDeformers', value=1, minValue=0, maxValue=20, parent=guideSettingsAttrGrp)
        self.numDeformersAttr.setValueChangeCallback(self.updateNumDeformers)


        # Guide Controls
        self.tailBaseCtrl = Control('tailBase', parent=self.ctrlCmpGrp, shape='sphere')
        self.tailBaseCtrl.scalePoints(Vec3(1.2, 1.2, 1.2))
        self.tailBaseCtrl.lockScale(x=True, y=True, z=True)
        self.tailBaseCtrl.setColor("turqoise")

        self.tailBaseHandleCtrl = Control('tailBaseHandle', parent=self.ctrlCmpGrp, shape='pin')
        self.tailBaseHandleCtrl.rotatePoints(90, 0, 0)
        self.tailBaseHandleCtrl.translatePoints(Vec3(0, 1.0, 0))
        self.tailBaseHandleCtrl.lockScale(x=True, y=True, z=True)
        self.tailBaseHandleCtrl.setColor("turqoise")

        self.tailEndHandleCtrl = Control('tailEndHandle', parent=self.ctrlCmpGrp, shape='pin')
        self.tailEndHandleCtrl.rotatePoints(90, 0, 0)
        self.tailEndHandleCtrl.translatePoints(Vec3(0, 1.0, 0))
        self.tailEndHandleCtrl.lockScale(x=True, y=True, z=True)
        self.tailEndHandleCtrl.setColor("turqoise")

        self.tailEndCtrl = Control('tailEnd', parent=self.ctrlCmpGrp, shape='pin')
        self.tailEndCtrl.rotatePoints(90, 0, 0)
        self.tailEndCtrl.translatePoints(Vec3(0, 1.0, 0))
        self.tailEndCtrl.lockScale(x=True, y=True, z=True)
        self.tailEndCtrl.setColor("turqoise")

        # ===============
        # Add Splice Ops
        # ===============
        # Add Tail Splice Op
        self.bezierSpineSpliceOp = SpliceOperator('spineGuideSpliceOp', 'BezierSpineSolver', 'Kraken', alwaysEval=True)
        self.bezierSpineSpliceOp.setOutput('outputs', self.tailVertebraeOutput.getTarget())

        self.addOperator(self.bezierSpineSpliceOp)

        # Add Att Inputs
        self.bezierSpineSpliceOp.setInput('drawDebug', self.drawDebugInputAttr)
        self.bezierSpineSpliceOp.setInput('rigScale', self.rigScaleInputAttr)
        self.bezierSpineSpliceOp.setInput('length', self.lengthInputAttr)

        # Add Xfo Inputs
        self.bezierSpineSpliceOp.setInput('base', self.tailBaseCtrl)
        self.bezierSpineSpliceOp.setInput('baseHandle', self.tailBaseHandleCtrl)
        self.bezierSpineSpliceOp.setInput('tipHandle', self.tailEndHandleCtrl)
        self.bezierSpineSpliceOp.setInput('tip', self.tailEndCtrl)

        self.loadData({
            'name': name,
            'location': 'M',
            'tailBasePos': Vec3(0.0, 0.65, -3.1),
            'tailBaseHandlePos': Vec3(0.0, 0.157, -4.7),
            'tailBaseHandleCtrlCrvData': self.tailBaseHandleCtrl.getCurveData(),
            'tailEndHandlePos': Vec3(0.0, 0.0625, -6.165),
            'tailEndHandleCtrlCrvData': self.tailEndHandleCtrl.getCurveData(),
            'tailEndPos': Vec3(0.0, -0.22, -7.42),
            'tailEndCtrlCrvData': self.tailEndCtrl.getCurveData(),
            'numDeformers': 6
        })

        Profiler.getInstance().pop()


    # ==========
    # Callbacks
    # ==========
    def updateNumDeformers(self, count):
        """Generate the guide controls for the variable outputes array.

        Arguments:
        count -- object, The number of joints inthe chain.

        Return:
        True if successful.

        """

        if count == 0:
            raise IndexError("'count' must be > 0")


        vertebraeOutputs = self.tailVertebraeOutput.getTarget()
        if count > len(vertebraeOutputs):
            for i in xrange(len(vertebraeOutputs), count):
                debugCtrl = Control('spine' + str(i+1).zfill(2), parent=self.outputHrcGrp, shape="vertebra")
                debugCtrl.rotatePoints(0, -90, 0)
                debugCtrl.scalePoints(Vec3(0.5, 0.5, 0.5))
                debugCtrl.setColor('turqoise')
                vertebraeOutputs.append(debugCtrl)

        elif count < len(vertebraeOutputs):
            numExtraCtrls = len(vertebraeOutputs) - count
            for i in xrange(numExtraCtrls):
                extraCtrl = vertebraeOutputs.pop()
                self.outputHrcGrp.removeChild(extraCtrl)

        return True

    # =============
    # Data Methods
    # =============
    def saveData(self):
        """Save the data for the component to be persisted.

        Return:
        The JSON data object

        """

        data = super(FabriceTailGuide, self).saveData()

        data['tailBasePos'] = self.tailBaseCtrl.xfo.tr

        data['tailBaseHandlePos'] = self.tailBaseHandleCtrl.xfo.tr
        data['tailBaseHandleCtrlCrvData'] = self.tailBaseHandleCtrl.getCurveData()

        data['tailEndHandlePos'] = self.tailEndHandleCtrl.xfo.tr
        data['tailEndHandleCtrlCrvData'] = self.tailEndHandleCtrl.getCurveData()

        data['tailEndPos'] = self.tailEndCtrl.xfo.tr
        data['tailEndCtrlCrvData'] = self.tailEndCtrl.getCurveData()

        data['numDeformers'] = self.numDeformersAttr.getValue()

        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(FabriceTailGuide, self).loadData( data )

        self.tailBaseCtrl.xfo.tr = data["tailBasePos"]

        self.tailBaseHandleCtrl.xfo.tr = data["tailBaseHandlePos"]
        self.tailBaseHandleCtrl.setCurveData(data['tailBaseHandleCtrlCrvData'])

        self.tailEndHandleCtrl.xfo.tr = data["tailEndHandlePos"]
        self.tailEndHandleCtrl.setCurveData(data['tailEndHandleCtrlCrvData'])

        self.tailEndCtrl.xfo.tr = data["tailEndPos"]
        self.tailEndCtrl.setCurveData(data['tailEndCtrlCrvData'])

        self.numDeformersAttr.setValue(data["numDeformers"])

        length = data["tailBasePos"].distanceTo(data["tailBaseHandlePos"]) + data["tailBaseHandlePos"].distanceTo(data["tailEndHandlePos"]) + data["tailEndHandlePos"].distanceTo(data["tailEndPos"])
        self.lengthInputAttr.setMax(length * 3.0)
        self.lengthInputAttr.setValue(length)

        self.bezierSpineSpliceOp.evaluate()

        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(FabriceTailGuide, self).getRigBuildData()

        data['tailBasePos'] = self.tailBaseCtrl.xfo.tr

        data['tailBaseHandlePos'] = self.tailBaseHandleCtrl.xfo.tr
        data['tailBaseHandleCtrlCrvData'] = self.tailBaseHandleCtrl.getCurveData()

        data['tailEndHandlePos'] = self.tailEndHandleCtrl.xfo.tr
        data['tailEndHandleCtrlCrvData'] = self.tailEndHandleCtrl.getCurveData()

        data['tailEndPos'] = self.tailEndCtrl.xfo.tr
        data['tailEndCtrlCrvData'] = self.tailEndCtrl.getCurveData()

        data['numDeformers'] = self.numDeformersAttr.getValue()

        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 FabriceTailRig
Example #6
0
class FabriceTailRig(FabriceTail):
    """Fabrice Tail Component"""

    def __init__(self, name="fabriceTail", parent=None):

        Profiler.getInstance().push("Construct Tail Rig Component:" + name)
        super(FabriceTailRig, self).__init__(name, parent)


        # =========
        # Controls
        # =========

        # Tail Base
        # self.tailBaseCtrlSpace = CtrlSpace('tailBase', parent=self.ctrlCmpGrp)
        # self.tailBaseCtrl = Control('tailBase', parent=self.tailBaseCtrlSpace, shape="circle")
        # self.tailBaseCtrl.rotatePoints(90, 0, 0)
        # self.tailBaseCtrl.scalePoints(Vec3(2.0, 2.0, 2.0))
        # self.tailBaseCtrl.setColor("greenBlue")

        # Tail Base Handle
        self.tailBaseHandleCtrlSpace = CtrlSpace('tailBaseHandle', parent=self.ctrlCmpGrp)
        self.tailBaseHandleCtrl = Control('tailBaseHandle', parent=self.tailBaseHandleCtrlSpace, shape="pin")
        self.tailBaseHandleCtrl.lockScale(x=True, y=True, z=True)
        self.tailBaseHandleCtrl.setColor("turqoise")

        # Tail End Handle
        self.tailEndHandleCtrlSpace = CtrlSpace('tailEndHandle', parent=self.ctrlCmpGrp)
        self.tailEndHandleCtrl = Control('tailEndHandle', parent=self.tailEndHandleCtrlSpace, shape="pin")
        self.tailEndHandleCtrl.lockScale(x=True, y=True, z=True)
        self.tailEndHandleCtrl.setColor("turqoise")

        # Tail End
        self.tailEndCtrlSpace = CtrlSpace('tailEnd', parent=self.tailEndHandleCtrl)
        self.tailEndCtrl = Control('tailEnd', parent=self.tailEndCtrlSpace, shape="pin")
        self.tailEndCtrl.lockScale(x=True, y=True, z=True)
        self.tailEndCtrl.setColor("greenBlue")


        # ==========
        # Deformers
        # ==========
        deformersLayer = self.getOrCreateLayer('deformers')
        self.defCmpGrp = ComponentGroup(self.getName(), self, parent=deformersLayer)
        self.deformerJoints = []
        self.tailOutputs = []
        self.setNumDeformers(1)


        # =====================
        # Create Component I/O
        # =====================
        # Setup component Xfo I/O's
        self.tailVertebraeOutput.setTarget(self.tailOutputs)


        # ==============
        # Constrain I/O
        # ==============
        # Constraint inputs
        self.tailBaseHandleInputConstraint = PoseConstraint('_'.join([self.tailBaseHandleCtrlSpace.getName(), 'To', self.spineEndCtrlInputTgt.getName()]))
        self.tailBaseHandleInputConstraint.addConstrainer(self.spineEndCtrlInputTgt)
        self.tailBaseHandleInputConstraint.setMaintainOffset(True)
        self.tailBaseHandleCtrlSpace.addConstraint(self.tailBaseHandleInputConstraint)

        self.tailEndHandleInputConstraint = PoseConstraint('_'.join([self.tailEndHandleCtrlSpace.getName(), 'To', self.cogInputTgt.getName()]))
        self.tailEndHandleInputConstraint.addConstrainer(self.cogInputTgt)
        self.tailEndHandleInputConstraint.setMaintainOffset(True)
        self.tailEndHandleCtrlSpace.addConstraint(self.tailEndHandleInputConstraint)

        # Constraint outputs
        self.tailBaseOutputConstraint = PoseConstraint('_'.join([self.tailBaseOutputTgt.getName(), 'To', 'spineBase']))
        self.tailBaseOutputConstraint.addConstrainer(self.tailOutputs[0])
        self.tailBaseOutputTgt.addConstraint(self.tailBaseOutputConstraint)

        self.tailEndOutputConstraint = PoseConstraint('_'.join([self.tailEndOutputTgt.getName(), 'To', 'spineEnd']))
        self.tailEndOutputConstraint.addConstrainer(self.tailOutputs[0])
        self.tailEndOutputTgt.addConstraint(self.tailEndOutputConstraint)


        # ===============
        # Add Splice Ops
        # ===============
        # Add Tail Splice Op
        self.bezierTailSpliceOp = SpliceOperator('tailSpliceOp', 'BezierSpineSolver', 'Kraken')
        self.addOperator(self.bezierTailSpliceOp)

        # Add Att Inputs
        self.bezierTailSpliceOp.setInput('drawDebug', self.drawDebugInputAttr)
        self.bezierTailSpliceOp.setInput('rigScale', self.rigScaleInputAttr)
        self.bezierTailSpliceOp.setInput('length', self.lengthInputAttr)

        # Add Xfo Inputs
        self.bezierTailSpliceOp.setInput('base', self.spineEndInputTgt)
        self.bezierTailSpliceOp.setInput('baseHandle', self.tailBaseHandleCtrl)
        self.bezierTailSpliceOp.setInput('tipHandle', self.tailEndHandleCtrl)
        self.bezierTailSpliceOp.setInput('tip', self.tailEndCtrl)

        # Add Xfo Outputs
        self.bezierTailSpliceOp.setOutput('outputs', self.tailOutputs)

        # Add Deformer Splice Op
        self.deformersToOutputsSpliceOp = SpliceOperator('tailDeformerSpliceOp', 'MultiPoseConstraintSolver', 'Kraken', alwaysEval=True)
        self.addOperator(self.deformersToOutputsSpliceOp)

        # Add Att Inputs
        self.deformersToOutputsSpliceOp.setInput('drawDebug', self.drawDebugInputAttr)
        self.deformersToOutputsSpliceOp.setInput('rigScale', self.rigScaleInputAttr)

        # Add Xfo Outputs
        self.deformersToOutputsSpliceOp.setInput('constrainers', self.tailOutputs)

        # Add Xfo Outputs
        self.deformersToOutputsSpliceOp.setOutput('constrainees', self.deformerJoints)

        Profiler.getInstance().pop()


    def setNumDeformers(self, numDeformers):

        # Add new deformers and outputs
        for i in xrange(len(self.tailOutputs), numDeformers):
            name = 'tail' + str(i + 1).zfill(2)
            tailOutput = ComponentOutput(name, parent=self.outputHrcGrp)
            self.tailOutputs.append(tailOutput)

        for i in xrange(len(self.deformerJoints), numDeformers):
            name = 'tail' + str(i + 1).zfill(2)
            tailDef = Joint(name, parent=self.defCmpGrp)
            tailDef.setComponent(self)
            self.deformerJoints.append(tailDef)

        return True


    def loadData(self, data=None):
        """Load a saved guide representation from persisted data.

        Arguments:
        data -- object, The JSON data object.

        Return:
        True if successful.

        """

        super(FabriceTailRig, self).loadData( data )

        tailBasePos = data['tailBasePos']

        tailBaseHandlePos = data['tailBaseHandlePos']
        tailBaseHandleCtrlCrvData = data['tailBaseHandleCtrlCrvData']

        tailEndHandlePos = data['tailEndHandlePos']
        tailEndHandleCtrlCrvData = data['tailEndHandleCtrlCrvData']

        tailEndPos = data['tailEndPos']
        tailEndCtrlCrvData = data['tailEndCtrlCrvData']

        numDeformers = data['numDeformers']

        # Set Xfos
        self.spineEndInputTgt.xfo.tr = tailBasePos
        self.spineEndCtrlInputTgt.xfo.tr = tailBasePos

        self.tailBaseHandleCtrlSpace.xfo.tr = tailBaseHandlePos
        self.tailBaseHandleCtrl.xfo.tr = tailBaseHandlePos
        self.tailBaseHandleCtrl.setCurveData(tailBaseHandleCtrlCrvData)

        self.tailEndHandleCtrlSpace.xfo.tr = tailEndHandlePos
        self.tailEndHandleCtrl.xfo.tr = tailEndHandlePos
        self.tailEndHandleCtrl.setCurveData(tailEndHandleCtrlCrvData)

        self.tailEndCtrlSpace.xfo.tr = tailEndPos
        self.tailEndCtrl.xfo.tr = tailEndPos
        self.tailEndCtrl.setCurveData(tailEndCtrlCrvData)

        length = tailBasePos.distanceTo(tailBaseHandlePos) + tailBaseHandlePos.distanceTo(tailEndHandlePos) + tailEndHandlePos.distanceTo(tailEndPos)
        self.lengthInputAttr.setMax(length * 3.0)
        self.lengthInputAttr.setValue(length)

        # Update number of deformers and outputs
        self.setNumDeformers(numDeformers)

        # Updating constraint to use the updated last output.
        self.tailEndOutputConstraint.setConstrainer(self.tailOutputs[-1], index=0)

        # ============
        # Set IO Xfos
        # ============

        # ====================
        # Evaluate Splice Ops
        # ====================
        # evaluate the spine op so that all the output transforms are updated.
        self.bezierTailSpliceOp.evaluate()

        # evaluate the constraint op so that all the joint transforms are updated.
        self.deformersToOutputsSpliceOp.evaluate()

        # evaluate the constraints to ensure the outputs are now in the correct location.
        self.tailBaseHandleInputConstraint.evaluate()
        self.tailBaseOutputConstraint.evaluate()
        self.tailEndOutputConstraint.evaluate()
Example #7
0
class MainSrtComponentRig(MainSrtComponent):
    """MainSrt Component Rig"""
    def __init__(self, name='mainSrt', parent=None):

        Profiler.getInstance().push("Construct MainSrt Rig Component:" + name)
        super(MainSrtComponentRig, self).__init__(name, parent)

        # =========
        # Controls
        # =========
        # Add Controls
        self.mainSRTCtrlSpace = CtrlSpace('SRT', parent=self.ctrlCmpGrp)
        self.mainSRTCtrl = Control('SRT',
                                   shape='circle',
                                   parent=self.mainSRTCtrlSpace)
        self.mainSRTCtrl.lockScale(x=True, y=True, z=True)

        self.offsetCtrlSpace = CtrlSpace('Offset', parent=self.mainSRTCtrl)
        self.offsetCtrl = Control('Offset',
                                  shape='circle',
                                  parent=self.offsetCtrlSpace)
        self.offsetCtrl.setColor("orange")
        self.offsetCtrl.lockScale(x=True, y=True, z=True)

        # Add Component Params to IK control
        mainSrtSettingsAttrGrp = AttributeGroup('DisplayInfo_MainSrtSettings',
                                                parent=self.mainSRTCtrl)
        self.rigScaleAttr = ScalarAttribute('rigScale',
                                            value=1.0,
                                            parent=mainSrtSettingsAttrGrp,
                                            minValue=0.1,
                                            maxValue=100.0)

        self.rigScaleOutputAttr.connect(self.rigScaleAttr)

        # ==========
        # Deformers
        # ==========

        # ==============
        # Constrain I/O
        # ==============
        # Constraint inputs

        # Constraint outputs
        srtConstraint = PoseConstraint('_'.join(
            [self.srtOutputTgt.getName(), 'To',
             self.mainSRTCtrl.getName()]))
        srtConstraint.addConstrainer(self.mainSRTCtrl)
        self.srtOutputTgt.addConstraint(srtConstraint)

        offsetConstraint = PoseConstraint('_'.join(
            [self.offsetOutputTgt.getName(), 'To',
             self.mainSRTCtrl.getName()]))
        offsetConstraint.addConstrainer(self.offsetCtrl)
        self.offsetOutputTgt.addConstraint(offsetConstraint)

        # ===============
        # Add Splice Ops
        # ===============
        #Add Rig Scale Splice Op
        self.rigScaleSpliceOp = SpliceOperator('rigScaleSpliceOp',
                                               'RigScaleSolver', 'Kraken')
        self.addOperator(self.rigScaleSpliceOp)

        # Add Att Inputs
        self.rigScaleSpliceOp.setInput('drawDebug', self.drawDebugInputAttr)
        self.rigScaleSpliceOp.setInput('rigScale', self.rigScaleOutputAttr)

        # Add Xfo Inputs

        # Add Xfo Outputs
        self.rigScaleSpliceOp.setOutput('target', self.mainSRTCtrlSpace)

        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(MainSrtComponentRig, self).loadData(data)

        # ================
        # Resize Controls
        # ================
        self.mainSRTCtrl.scalePoints(
            Vec3(data["mainSrtSize"], 1.0, data["mainSrtSize"]))
        self.offsetCtrl.scalePoints(
            Vec3(data["mainSrtSize"] - 0.5, 1.0, data["mainSrtSize"] - 0.5))

        # =======================
        # Set Control Transforms
        # =======================
        self.mainSRTCtrlSpace.xfo = data["mainSrtXfo"]
        self.mainSRTCtrl.xfo = data["mainSrtXfo"]
        self.offsetCtrlSpace.xfo = data["mainSrtXfo"]
        self.offsetCtrl.xfo = data["mainSrtXfo"]

        # ============
        # Set IO Xfos
        # ============
        self.srtOutputTgt = data["mainSrtXfo"]
        self.offsetOutputTgt = data["mainSrtXfo"]
Example #8
0
    def __init__(self, name="spine", parent=None):

        Profiler.getInstance().push("Construct Spine Rig Component:" + name)
        super(FabriceSpineRig, self).__init__(name, parent)

        # =========
        # Controls
        # =========
        # COG
        self.cogCtrlSpace = CtrlSpace('cog', parent=self.ctrlCmpGrp)
        self.cogCtrl = Control('cog', parent=self.cogCtrlSpace, shape="circle")
        self.cogCtrl.rotatePoints(90, 0, 0)
        self.cogCtrl.scalePoints(Vec3(3.0, 3.0, 3.0))
        self.cogCtrl.translatePoints(Vec3(0.0, 0.0, 0.2))
        self.cogCtrl.lockScale(x=True, y=True, z=True)
        self.cogCtrl.setColor("orange")

        # Spine Base
        self.spineBaseCtrlSpace = CtrlSpace('spineBase', parent=self.cogCtrl)
        self.spineBaseCtrl = Control('spineBase',
                                     parent=self.spineBaseCtrlSpace,
                                     shape="pin")
        self.spineBaseCtrl.rotatePoints(90, 0, 0)
        self.spineBaseCtrl.translatePoints(Vec3(0, 1.0, 0))
        self.spineBaseCtrl.lockScale(x=True, y=True, z=True)

        # Spine Base Handle
        self.spineBaseHandleCtrlSpace = CtrlSpace('spineBaseHandle',
                                                  parent=self.spineBaseCtrl)
        self.spineBaseHandleCtrl = Control(
            'spineBaseHandle',
            parent=self.spineBaseHandleCtrlSpace,
            shape="pin")
        self.spineBaseHandleCtrl.rotatePoints(90, 0, 0)
        self.spineBaseHandleCtrl.translatePoints(Vec3(0, 1.0, 0))
        self.spineBaseHandleCtrl.lockScale(x=True, y=True, z=True)
        self.spineBaseHandleCtrl.setColor("orange")

        # Spine End
        self.spineEndCtrlSpace = CtrlSpace('spineEnd', parent=self.cogCtrl)
        self.spineEndCtrl = Control('spineEnd',
                                    parent=self.spineEndCtrlSpace,
                                    shape="pin")
        self.spineEndCtrl.rotatePoints(90, 0, 0)
        self.spineEndCtrl.lockScale(x=True, y=True, z=True)
        self.spineEndCtrl.translatePoints(Vec3(0, 1.0, 0))

        # Spine End Handle
        self.spineEndHandleCtrlSpace = CtrlSpace('spineEndHandle',
                                                 parent=self.spineEndCtrl)
        self.spineEndHandleCtrl = Control('spineEndHandle',
                                          parent=self.spineEndHandleCtrlSpace,
                                          shape="pin")
        self.spineEndHandleCtrl.rotatePoints(90, 0, 0)
        self.spineEndHandleCtrl.translatePoints(Vec3(0, 1.0, 0))
        self.spineEndHandleCtrl.lockScale(x=True, y=True, z=True)
        self.spineEndHandleCtrl.setColor("orange")

        # ==========
        # Deformers
        # ==========
        deformersLayer = self.getOrCreateLayer('deformers')
        self.defCmpGrp = ComponentGroup(self.getName(),
                                        self,
                                        parent=deformersLayer)
        self.chestDef = Joint('chest', parent=self.defCmpGrp)
        self.chestDef.setComponent(self)

        self.deformerJoints = []
        self.spineOutputs = []
        self.setNumDeformers(1)

        # =====================
        # Create Component I/O
        # =====================
        # Setup component Xfo I/O's
        self.spineVertebraeOutput.setTarget(self.spineOutputs)

        # =====================
        # Constraint Deformers
        # =====================
        self.chestDefConstraint = PoseConstraint('_'.join(
            [self.chestDef.getName(), 'To',
             self.spineBaseOutputTgt.getName()]))
        self.chestDefConstraint.addConstrainer(self.spineBaseOutputTgt)
        self.chestDef.addConstraint(self.chestDefConstraint)

        # ==============
        # Constrain I/O
        # ==============

        # Constraint inputs
        self.spineSrtInputConstraint = PoseConstraint('_'.join([
            self.cogCtrlSpace.getName(), 'To',
            self.spineMainSrtInputTgt.getName()
        ]))
        self.spineSrtInputConstraint.addConstrainer(self.spineMainSrtInputTgt)
        self.spineSrtInputConstraint.setMaintainOffset(True)
        self.cogCtrlSpace.addConstraint(self.spineSrtInputConstraint)

        # Constraint outputs
        self.spineCogOutputConstraint = PoseConstraint('_'.join(
            [self.spineCogOutputTgt.getName(), 'To',
             self.cogCtrl.getName()]))
        self.spineCogOutputConstraint.addConstrainer(self.cogCtrl)
        self.spineCogOutputTgt.addConstraint(self.spineCogOutputConstraint)

        # Spine Base
        self.spineBaseOutputPosConstraint = PositionConstraint('_'.join([
            self.spineBaseOutputTgt.getName(), 'PosTo',
            self.spineOutputs[0].getName()
        ]))
        self.spineBaseOutputPosConstraint.addConstrainer(self.spineOutputs[0])
        self.spineBaseOutputTgt.addConstraint(
            self.spineBaseOutputPosConstraint)

        self.spineBaseOutputOriConstraint = OrientationConstraint('_'.join([
            self.spineBaseOutputTgt.getName(), 'PosTo',
            self.cogCtrl.getName()
        ]))
        self.spineBaseOutputOriConstraint.addConstrainer(self.cogCtrl)
        self.spineBaseOutputTgt.addConstraint(
            self.spineBaseOutputOriConstraint)

        # Spine End
        self.spineEndOutputConstraint = PoseConstraint('_'.join(
            [self.spineEndOutputTgt.getName(), 'To', 'spineEnd']))
        self.spineEndOutputConstraint.addConstrainer(self.spineOutputs[0])
        self.spineEndOutputTgt.addConstraint(self.spineEndOutputConstraint)

        self.spineEndCtrlOutputConstraint = PoseConstraint('_'.join([
            self.spineEndCtrlOutputTgt.getName(), 'To',
            self.spineEndCtrl.getName()
        ]))
        self.spineEndCtrlOutputConstraint.addConstrainer(self.spineEndCtrl)
        self.spineEndCtrlOutputTgt.addConstraint(
            self.spineEndCtrlOutputConstraint)

        # ===============
        # Add Splice Ops
        # ===============
        # Add Spine Splice Op
        self.bezierSpineSpliceOp = SpliceOperator('spineSpliceOp',
                                                  'BezierSpineSolver',
                                                  'Kraken')
        self.addOperator(self.bezierSpineSpliceOp)

        # Add Att Inputs
        self.bezierSpineSpliceOp.setInput('drawDebug', self.drawDebugInputAttr)
        self.bezierSpineSpliceOp.setInput('rigScale', self.rigScaleInputAttr)
        self.bezierSpineSpliceOp.setInput('length', self.lengthInputAttr)

        # Add Xfo Inputs
        self.bezierSpineSpliceOp.setInput('base', self.spineBaseCtrl)
        self.bezierSpineSpliceOp.setInput('baseHandle',
                                          self.spineBaseHandleCtrl)
        self.bezierSpineSpliceOp.setInput('tipHandle', self.spineEndHandleCtrl)
        self.bezierSpineSpliceOp.setInput('tip', self.spineEndCtrl)

        # Add Xfo Outputs
        self.bezierSpineSpliceOp.setOutput('outputs', self.spineOutputs)

        # Add Deformer Splice Op
        self.deformersToOutputsSpliceOp = SpliceOperator(
            'spineDeformerSpliceOp',
            'MultiPoseConstraintSolver',
            'Kraken',
            alwaysEval=True)
        self.addOperator(self.deformersToOutputsSpliceOp)

        # Add Att Inputs
        self.deformersToOutputsSpliceOp.setInput('drawDebug',
                                                 self.drawDebugInputAttr)
        self.deformersToOutputsSpliceOp.setInput('rigScale',
                                                 self.rigScaleInputAttr)

        # Add Xfo Outputs
        self.deformersToOutputsSpliceOp.setInput('constrainers',
                                                 self.spineOutputs)

        # Add Xfo Outputs
        self.deformersToOutputsSpliceOp.setOutput('constrainees',
                                                  self.deformerJoints)

        Profiler.getInstance().pop()
Example #9
0
    def __init__(self, name="neck", parent=None):

        Profiler.getInstance().push("Construct Neck Rig Component:" + name)
        super(NeckComponentRig, self).__init__(name, parent)


        # =========
        # Controls
        # =========
        # Neck
        self.neckCtrlSpace = CtrlSpace('neck', parent=self.ctrlCmpGrp)
        self.neckCtrl = Control('neck', parent=self.neckCtrlSpace, shape="pin")
        self.neckCtrl.scalePoints(Vec3(1.25, 1.25, 1.25))
        self.neckCtrl.translatePoints(Vec3(0, 0, -0.5))
        self.neckCtrl.rotatePoints(90, 0, 90)
        self.neckCtrl.setColor("orange")


        # ==========
        # Deformers
        # ==========
        deformersLayer = self.getOrCreateLayer('deformers')
        defCmpGrp = ComponentGroup(self.getName(), self, parent=deformersLayer)

        neckDef = Joint('neck', parent=defCmpGrp)
        neckDef.setComponent(self)


        # ==============
        # Constrain I/O
        # ==============
        # Constraint inputs
        clavicleInputConstraint = PoseConstraint('_'.join([self.neckCtrlSpace.getName(), 'To', self.neckBaseInputTgt.getName()]))
        clavicleInputConstraint.setMaintainOffset(True)
        clavicleInputConstraint.addConstrainer(self.neckBaseInputTgt)
        self.neckCtrlSpace.addConstraint(clavicleInputConstraint)

        # Constraint outputs
        neckOutputConstraint = PoseConstraint('_'.join([self.neckOutputTgt.getName(), 'To', self.neckCtrl.getName()]))
        neckOutputConstraint.addConstrainer(self.neckCtrl)
        self.neckOutputTgt.addConstraint(neckOutputConstraint)

        neckEndConstraint = PoseConstraint('_'.join([self.neckEndOutputTgt.getName(), 'To', self.neckCtrl.getName()]))
        neckEndConstraint.addConstrainer(self.neckCtrl)
        self.neckEndOutputTgt.addConstraint(neckEndConstraint)


        # ===============
        # Add Splice Ops
        # ===============
        #Add Deformer Splice Op
        spliceOp = SpliceOperator('neckDeformerSpliceOp', 'PoseConstraintSolver', 'Kraken')
        self.addOperator(spliceOp)

        # Add Att Inputs
        spliceOp.setInput('drawDebug', self.drawDebugInputAttr)
        spliceOp.setInput('rigScale', self.rigScaleInputAttr)

        # Add Xfo Inputstrl)
        spliceOp.setInput('constrainer', self.neckEndOutputTgt)

        # Add Xfo Outputs
        spliceOp.setOutput('constrainee', neckDef)

        Profiler.getInstance().pop()
Example #10
0
    def __init__(self, name='h  ead', parent=None):

        Profiler.getInstance().push("Construct Head Rig Component:" + name)
        super(FabriceHeadRig, self).__init__(name, parent)


        # =========
        # Controls
        # =========
        # Head Aim
        self.headAimCtrlSpace = CtrlSpace('headAim', parent=self.ctrlCmpGrp)
        self.headAimCtrl = Control('headAim', parent=self.headAimCtrlSpace, shape="sphere")
        self.headAimCtrl.scalePoints(Vec3(0.35, 0.35, 0.35))
        self.headAimCtrl.lockScale(x=True, y=True, z=True)

        self.headAimUpV = Locator('headAimUpV', parent=self.headAimCtrl)
        self.headAimUpV.setShapeVisibility(False)

        # Head
        self.headAim = Locator('headAim', parent=self.ctrlCmpGrp)
        self.headAim.setShapeVisibility(False)

        self.headCtrlSpace = CtrlSpace('head', parent=self.ctrlCmpGrp)
        self.headCtrl = Control('head', parent=self.headCtrlSpace, shape="circle")
        self.headCtrl.lockTranslation(x=True, y=True, z=True)
        self.headCtrl.lockScale(x=True, y=True, z=True)

        # Jaw
        self.jawCtrlSpace = CtrlSpace('jawCtrlSpace', parent=self.headCtrl)
        self.jawCtrl = Control('jaw', parent=self.jawCtrlSpace, shape="cube")
        self.jawCtrl.lockTranslation(x=True, y=True, z=True)
        self.jawCtrl.lockScale(x=True, y=True, z=True)
        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)


        # ==============
        # Constrain I/O
        # ==============
        self.headToAimConstraint = PoseConstraint('_'.join([self.headCtrlSpace.getName(), 'To', self.headAim.getName()]))
        self.headToAimConstraint.setMaintainOffset(True)
        self.headToAimConstraint.addConstrainer(self.headAim)
        self.headCtrlSpace.addConstraint(self.headToAimConstraint)

        # Constraint inputs
        self.headAimInputConstraint = PoseConstraint('_'.join([self.headAimCtrlSpace.getName(), 'To', self.headBaseInputTgt.getName()]))
        self.headAimInputConstraint.setMaintainOffset(True)
        self.headAimInputConstraint.addConstrainer(self.headBaseInputTgt)
        self.headAimCtrlSpace.addConstraint(self.headAimInputConstraint)

        # # 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)

        # ===============
        # Add Splice Ops
        # ===============

        # Add Aim Splice Op
        # =================
        self.headAimSpliceOp = SpliceOperator('headAimSpliceOp', 'DirectionConstraintSolver', 'Kraken')
        self.addOperator(self.headAimSpliceOp)

        # Add Att Inputs
        self.headAimSpliceOp.setInput('drawDebug', self.drawDebugInputAttr)
        self.headAimSpliceOp.setInput('rigScale', self.rigScaleInputAttr)

        # Add Xfo Inputs
        self.headAimSpliceOp.setInput('position', self.headBaseInputTgt)
        self.headAimSpliceOp.setInput('upVector', self.headAimUpV)
        self.headAimSpliceOp.setInput('atVector', self.headAimCtrl)

        # Add Xfo Outputs
        self.headAimSpliceOp.setOutput('constrainee', self.headAim)

        # Add Deformer Splice Op
        # ======================
        self.deformersToOutputsSpliceOp = SpliceOperator('headDeformerSpliceOp', 'MultiPoseConstraintSolver', 'Kraken', alwaysEval=True)
        self.addOperator(self.deformersToOutputsSpliceOp)

        # Add Att Inputs
        self.deformersToOutputsSpliceOp.setInput('drawDebug', self.drawDebugInputAttr)
        self.deformersToOutputsSpliceOp.setInput('rigScale', self.rigScaleInputAttr)

        # Add Xfo Outputs
        self.deformersToOutputsSpliceOp.setInput('constrainers', [self.headOutputTgt, self.jawOutputTgt])

        # Add Xfo Outputs
        self.deformersToOutputsSpliceOp.setOutput('constrainees', [headDef, jawDef])

        Profiler.getInstance().pop()
Example #11
0
class FabriceHeadRig(FabriceHead):
    """Fabrice Head Component Rig"""

    def __init__(self, name='h  ead', parent=None):

        Profiler.getInstance().push("Construct Head Rig Component:" + name)
        super(FabriceHeadRig, self).__init__(name, parent)


        # =========
        # Controls
        # =========
        # Head Aim
        self.headAimCtrlSpace = CtrlSpace('headAim', parent=self.ctrlCmpGrp)
        self.headAimCtrl = Control('headAim', parent=self.headAimCtrlSpace, shape="sphere")
        self.headAimCtrl.scalePoints(Vec3(0.35, 0.35, 0.35))
        self.headAimCtrl.lockScale(x=True, y=True, z=True)

        self.headAimUpV = Locator('headAimUpV', parent=self.headAimCtrl)
        self.headAimUpV.setShapeVisibility(False)

        # Head
        self.headAim = Locator('headAim', parent=self.ctrlCmpGrp)
        self.headAim.setShapeVisibility(False)

        self.headCtrlSpace = CtrlSpace('head', parent=self.ctrlCmpGrp)
        self.headCtrl = Control('head', parent=self.headCtrlSpace, shape="circle")
        self.headCtrl.lockTranslation(x=True, y=True, z=True)
        self.headCtrl.lockScale(x=True, y=True, z=True)

        # Jaw
        self.jawCtrlSpace = CtrlSpace('jawCtrlSpace', parent=self.headCtrl)
        self.jawCtrl = Control('jaw', parent=self.jawCtrlSpace, shape="cube")
        self.jawCtrl.lockTranslation(x=True, y=True, z=True)
        self.jawCtrl.lockScale(x=True, y=True, z=True)
        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)


        # ==============
        # Constrain I/O
        # ==============
        self.headToAimConstraint = PoseConstraint('_'.join([self.headCtrlSpace.getName(), 'To', self.headAim.getName()]))
        self.headToAimConstraint.setMaintainOffset(True)
        self.headToAimConstraint.addConstrainer(self.headAim)
        self.headCtrlSpace.addConstraint(self.headToAimConstraint)

        # Constraint inputs
        self.headAimInputConstraint = PoseConstraint('_'.join([self.headAimCtrlSpace.getName(), 'To', self.headBaseInputTgt.getName()]))
        self.headAimInputConstraint.setMaintainOffset(True)
        self.headAimInputConstraint.addConstrainer(self.headBaseInputTgt)
        self.headAimCtrlSpace.addConstraint(self.headAimInputConstraint)

        # # 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)

        # ===============
        # Add Splice Ops
        # ===============

        # Add Aim Splice Op
        # =================
        self.headAimSpliceOp = SpliceOperator('headAimSpliceOp', 'DirectionConstraintSolver', 'Kraken')
        self.addOperator(self.headAimSpliceOp)

        # Add Att Inputs
        self.headAimSpliceOp.setInput('drawDebug', self.drawDebugInputAttr)
        self.headAimSpliceOp.setInput('rigScale', self.rigScaleInputAttr)

        # Add Xfo Inputs
        self.headAimSpliceOp.setInput('position', self.headBaseInputTgt)
        self.headAimSpliceOp.setInput('upVector', self.headAimUpV)
        self.headAimSpliceOp.setInput('atVector', self.headAimCtrl)

        # Add Xfo Outputs
        self.headAimSpliceOp.setOutput('constrainee', self.headAim)

        # Add Deformer Splice Op
        # ======================
        self.deformersToOutputsSpliceOp = SpliceOperator('headDeformerSpliceOp', 'MultiPoseConstraintSolver', 'Kraken', alwaysEval=True)
        self.addOperator(self.deformersToOutputsSpliceOp)

        # Add Att Inputs
        self.deformersToOutputsSpliceOp.setInput('drawDebug', self.drawDebugInputAttr)
        self.deformersToOutputsSpliceOp.setInput('rigScale', self.rigScaleInputAttr)

        # Add Xfo Outputs
        self.deformersToOutputsSpliceOp.setInput('constrainers', [self.headOutputTgt, self.jawOutputTgt])

        # Add Xfo Outputs
        self.deformersToOutputsSpliceOp.setOutput('constrainees', [headDef, jawDef])

        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(FabriceHeadRig, self).loadData( data )

        headXfo = data['headXfo']
        headCtrlCrvData = data['headCtrlCrvData']
        jawPosition = data['jawPosition']
        jawCtrlCrvData = data['jawCtrlCrvData']

        self.headAimCtrlSpace.xfo.ori = headXfo.ori
        self.headAimCtrlSpace.xfo.tr = headXfo.tr.add(Vec3(0, 0, 4))
        self.headAimCtrl.xfo = self.headAimCtrlSpace.xfo

        self.headAimUpV.xfo.ori = self.headAimCtrl.xfo.ori
        self.headAimUpV.xfo.tr = self.headAimCtrl.xfo.tr.add(Vec3(0, 3, 0))

        self.headAim.xfo = headXfo
        self.headCtrlSpace.xfo = headXfo
        self.headCtrl.xfo = headXfo
        self.headCtrl.setCurveData(headCtrlCrvData)

        self.jawCtrlSpace.xfo.tr = jawPosition
        self.jawCtrl.xfo.tr = jawPosition
        self.jawCtrl.setCurveData(jawCtrlCrvData)

        # ============
        # Set IO Xfos
        # ============
        self.headBaseInputTgt.xfo = headXfo
        self.headOutputTgt.xfo = headXfo
        self.jawOutputTgt.xfo.tr = jawPosition

        # ====================
        # Evaluate Splice Ops
        # ====================
        # evaluate the constraint op so that all the joint transforms are updated.
        self.headAimSpliceOp.evaluate()
        self.deformersToOutputsSpliceOp.evaluate()

        # evaluate the constraints to ensure the outputs are now in the correct location.
        self.headToAimConstraint.evaluate()
        self.headAimInputConstraint.evaluate()
        self.headOutputConstraint.evaluate()
        self.jawOutputConstraint.evaluate()
Example #12
0
    def __init__(self, name="spine", parent=None):

        Profiler.getInstance().push("Construct Spine Rig Component:" + name)
        super(SpineComponentRig, self).__init__(name, parent)


        # =========
        # Controls
        # =========
        # COG
        self.cogCtrlSpace = CtrlSpace('cog', parent=self.ctrlCmpGrp)
        self.cogCtrl = Control('cog', parent=self.cogCtrlSpace, shape="circle")
        self.cogCtrl.scalePoints(Vec3(6.0, 6.0, 6.0))
        self.cogCtrl.setColor("orange")

        # Spine01
        self.spine01CtrlSpace = CtrlSpace('spine01', parent=self.cogCtrl)
        self.spine01Ctrl = Control('spine01', parent=self.spine01CtrlSpace, shape="circle")
        self.spine01Ctrl.scalePoints(Vec3(4.0, 4.0, 4.0))

        # Spine02
        self.spine02CtrlSpace = CtrlSpace('spine02', parent=self.spine01Ctrl)
        self.spine02Ctrl = Control('spine02', parent=self.spine02CtrlSpace, shape="circle")
        self.spine02Ctrl.scalePoints(Vec3(4.5, 4.5, 4.5))


        # Spine03
        self.spine03CtrlSpace = CtrlSpace('spine03', parent=self.spine02Ctrl)
        self.spine03Ctrl = Control('spine03', parent=self.spine03CtrlSpace, shape="circle")
        self.spine03Ctrl.scalePoints(Vec3(4.5, 4.5, 4.5))
        self.spine03Ctrl.setColor("blue")

        # Spine04
        self.spine04CtrlSpace = CtrlSpace('spine04', parent=self.cogCtrl)
        self.spine04Ctrl = Control('spine04', parent=self.spine04CtrlSpace, shape="circle")
        self.spine04Ctrl.scalePoints(Vec3(6.0, 6.0, 6.0))

        # Pelvis
        self.pelvisCtrlSpace = CtrlSpace('pelvis', parent=self.cogCtrl)
        self.pelvisCtrl = Control('pelvis', parent=self.pelvisCtrlSpace, shape="cube")
        self.pelvisCtrl.alignOnYAxis(negative=True)
        self.pelvisCtrl.scalePoints(Vec3(2.0, 1.5, 1.5))


        # ==========
        # Deformers
        # ==========
        deformersLayer = self.getOrCreateLayer('deformers')
        self.defCmpGrp = ComponentGroup(self.getName(), self, parent=deformersLayer)
        self.deformerJoints = []
        self.spineOutputs = []
        self.setNumDeformers(1)

        pelvisDef = Joint('pelvis', parent=self.defCmpGrp)
        pelvisDef.setComponent(self)

        # =====================
        # Create Component I/O
        # =====================
        # Setup component Xfo I/O's
        self.spineVertebraeOutput.setTarget(self.spineOutputs)


        # ==============
        # Constrain I/O
        # ==============
        # Constraint inputs
        self.spineSrtInputConstraint = PoseConstraint('_'.join([self.cogCtrlSpace.getName(), 'To', self.spineMainSrtInputTgt.getName()]))
        self.spineSrtInputConstraint.addConstrainer(self.spineMainSrtInputTgt)
        self.spineSrtInputConstraint.setMaintainOffset(True)
        self.cogCtrlSpace.addConstraint(self.spineSrtInputConstraint)

        # Constraint outputs
        self.spineCogOutputConstraint = PoseConstraint('_'.join([self.spineCogOutputTgt.getName(), 'To', self.cogCtrl.getName()]))
        self.spineCogOutputConstraint.addConstrainer(self.cogCtrl)
        self.spineCogOutputTgt.addConstraint(self.spineCogOutputConstraint)

        self.spineBaseOutputConstraint = PoseConstraint('_'.join([self.spineBaseOutputTgt.getName(), 'To', 'spineBase']))
        self.spineBaseOutputConstraint.addConstrainer(self.spineOutputs[0])
        self.spineBaseOutputTgt.addConstraint(self.spineBaseOutputConstraint)

        self.pelvisOutputConstraint = PoseConstraint('_'.join([self.pelvisOutputTgt.getName(), 'To', self.pelvisCtrl.getName()]))
        self.pelvisOutputConstraint.addConstrainer(self.pelvisCtrl)
        self.pelvisOutputTgt.addConstraint(self.pelvisOutputConstraint)

        self.spineEndOutputConstraint = PoseConstraint('_'.join([self.spineEndOutputTgt.getName(), 'To', 'spineEnd']))
        self.spineEndOutputConstraint.addConstrainer(self.spineOutputs[0])
        self.spineEndOutputTgt.addConstraint(self.spineEndOutputConstraint)


        # ===============
        # Add Splice Ops
        # ===============
        # Add Spine Splice Op
        self.bezierSpineSpliceOp = SpliceOperator('spineSpliceOp', 'BezierSpineSolver', 'Kraken')
        self.addOperator(self.bezierSpineSpliceOp)

        # Add Att Inputs
        self.bezierSpineSpliceOp.setInput('drawDebug', self.drawDebugInputAttr)
        self.bezierSpineSpliceOp.setInput('rigScale', self.rigScaleInputAttr)
        self.bezierSpineSpliceOp.setInput('length', self.lengthInputAttr)

        # Add Xfo Inputs
        self.bezierSpineSpliceOp.setInput('base', self.spine01Ctrl)
        self.bezierSpineSpliceOp.setInput('baseHandle', self.spine02Ctrl)
        self.bezierSpineSpliceOp.setInput('tipHandle', self.spine03Ctrl)
        self.bezierSpineSpliceOp.setInput('tip', self.spine04Ctrl)

        # Add Xfo Outputs
        self.bezierSpineSpliceOp.setOutput('outputs', self.spineOutputs)

        # Add Deformer Splice Op
        self.deformersToOutputsSpliceOp = SpliceOperator('spineDeformerSpliceOp', 'MultiPoseConstraintSolver', 'Kraken')
        self.addOperator(self.deformersToOutputsSpliceOp)

        # Add Att Inputs
        self.deformersToOutputsSpliceOp.setInput('drawDebug', self.drawDebugInputAttr)
        self.deformersToOutputsSpliceOp.setInput('rigScale', self.rigScaleInputAttr)

        # Add Xfo Outputs
        self.deformersToOutputsSpliceOp.setInput('constrainers', self.spineOutputs)

        # Add Xfo Outputs
        self.deformersToOutputsSpliceOp.setOutput('constrainees', self.deformerJoints)

        # Add Pelvis Splice Op
        self.pelvisDefSpliceOp = SpliceOperator('pelvisDeformerSpliceOp', 'PoseConstraintSolver', 'Kraken')
        self.addOperator(self.pelvisDefSpliceOp)

        # Add Att Inputs
        self.pelvisDefSpliceOp.setInput('drawDebug', self.drawDebugInputAttr)
        self.pelvisDefSpliceOp.setInput('rigScale', self.rigScaleInputAttr)

        # Add Xfo Inputs
        self.pelvisDefSpliceOp.setInput('constrainer', self.pelvisOutputTgt)

        # Add Xfo Outputs
        self.pelvisDefSpliceOp.setOutput('constrainee', pelvisDef)


        Profiler.getInstance().pop()
Example #13
0
class SpineComponentRig(SpineComponent):
    """Spine Component"""

    def __init__(self, name="spine", parent=None):

        Profiler.getInstance().push("Construct Spine Rig Component:" + name)
        super(SpineComponentRig, self).__init__(name, parent)


        # =========
        # Controls
        # =========
        # COG
        self.cogCtrlSpace = CtrlSpace('cog', parent=self.ctrlCmpGrp)
        self.cogCtrl = Control('cog', parent=self.cogCtrlSpace, shape="circle")
        self.cogCtrl.scalePoints(Vec3(6.0, 6.0, 6.0))
        self.cogCtrl.setColor("orange")

        # Spine01
        self.spine01CtrlSpace = CtrlSpace('spine01', parent=self.cogCtrl)
        self.spine01Ctrl = Control('spine01', parent=self.spine01CtrlSpace, shape="circle")
        self.spine01Ctrl.scalePoints(Vec3(4.0, 4.0, 4.0))

        # Spine02
        self.spine02CtrlSpace = CtrlSpace('spine02', parent=self.spine01Ctrl)
        self.spine02Ctrl = Control('spine02', parent=self.spine02CtrlSpace, shape="circle")
        self.spine02Ctrl.scalePoints(Vec3(4.5, 4.5, 4.5))


        # Spine03
        self.spine03CtrlSpace = CtrlSpace('spine03', parent=self.spine02Ctrl)
        self.spine03Ctrl = Control('spine03', parent=self.spine03CtrlSpace, shape="circle")
        self.spine03Ctrl.scalePoints(Vec3(4.5, 4.5, 4.5))
        self.spine03Ctrl.setColor("blue")

        # Spine04
        self.spine04CtrlSpace = CtrlSpace('spine04', parent=self.cogCtrl)
        self.spine04Ctrl = Control('spine04', parent=self.spine04CtrlSpace, shape="circle")
        self.spine04Ctrl.scalePoints(Vec3(6.0, 6.0, 6.0))

        # Pelvis
        self.pelvisCtrlSpace = CtrlSpace('pelvis', parent=self.cogCtrl)
        self.pelvisCtrl = Control('pelvis', parent=self.pelvisCtrlSpace, shape="cube")
        self.pelvisCtrl.alignOnYAxis(negative=True)
        self.pelvisCtrl.scalePoints(Vec3(2.0, 1.5, 1.5))


        # ==========
        # Deformers
        # ==========
        deformersLayer = self.getOrCreateLayer('deformers')
        self.defCmpGrp = ComponentGroup(self.getName(), self, parent=deformersLayer)
        self.deformerJoints = []
        self.spineOutputs = []
        self.setNumDeformers(1)

        pelvisDef = Joint('pelvis', parent=self.defCmpGrp)
        pelvisDef.setComponent(self)

        # =====================
        # Create Component I/O
        # =====================
        # Setup component Xfo I/O's
        self.spineVertebraeOutput.setTarget(self.spineOutputs)


        # ==============
        # Constrain I/O
        # ==============
        # Constraint inputs
        self.spineSrtInputConstraint = PoseConstraint('_'.join([self.cogCtrlSpace.getName(), 'To', self.spineMainSrtInputTgt.getName()]))
        self.spineSrtInputConstraint.addConstrainer(self.spineMainSrtInputTgt)
        self.spineSrtInputConstraint.setMaintainOffset(True)
        self.cogCtrlSpace.addConstraint(self.spineSrtInputConstraint)

        # Constraint outputs
        self.spineCogOutputConstraint = PoseConstraint('_'.join([self.spineCogOutputTgt.getName(), 'To', self.cogCtrl.getName()]))
        self.spineCogOutputConstraint.addConstrainer(self.cogCtrl)
        self.spineCogOutputTgt.addConstraint(self.spineCogOutputConstraint)

        self.spineBaseOutputConstraint = PoseConstraint('_'.join([self.spineBaseOutputTgt.getName(), 'To', 'spineBase']))
        self.spineBaseOutputConstraint.addConstrainer(self.spineOutputs[0])
        self.spineBaseOutputTgt.addConstraint(self.spineBaseOutputConstraint)

        self.pelvisOutputConstraint = PoseConstraint('_'.join([self.pelvisOutputTgt.getName(), 'To', self.pelvisCtrl.getName()]))
        self.pelvisOutputConstraint.addConstrainer(self.pelvisCtrl)
        self.pelvisOutputTgt.addConstraint(self.pelvisOutputConstraint)

        self.spineEndOutputConstraint = PoseConstraint('_'.join([self.spineEndOutputTgt.getName(), 'To', 'spineEnd']))
        self.spineEndOutputConstraint.addConstrainer(self.spineOutputs[0])
        self.spineEndOutputTgt.addConstraint(self.spineEndOutputConstraint)


        # ===============
        # Add Splice Ops
        # ===============
        # Add Spine Splice Op
        self.bezierSpineSpliceOp = SpliceOperator('spineSpliceOp', 'BezierSpineSolver', 'Kraken')
        self.addOperator(self.bezierSpineSpliceOp)

        # Add Att Inputs
        self.bezierSpineSpliceOp.setInput('drawDebug', self.drawDebugInputAttr)
        self.bezierSpineSpliceOp.setInput('rigScale', self.rigScaleInputAttr)
        self.bezierSpineSpliceOp.setInput('length', self.lengthInputAttr)

        # Add Xfo Inputs
        self.bezierSpineSpliceOp.setInput('base', self.spine01Ctrl)
        self.bezierSpineSpliceOp.setInput('baseHandle', self.spine02Ctrl)
        self.bezierSpineSpliceOp.setInput('tipHandle', self.spine03Ctrl)
        self.bezierSpineSpliceOp.setInput('tip', self.spine04Ctrl)

        # Add Xfo Outputs
        self.bezierSpineSpliceOp.setOutput('outputs', self.spineOutputs)

        # Add Deformer Splice Op
        self.deformersToOutputsSpliceOp = SpliceOperator('spineDeformerSpliceOp', 'MultiPoseConstraintSolver', 'Kraken')
        self.addOperator(self.deformersToOutputsSpliceOp)

        # Add Att Inputs
        self.deformersToOutputsSpliceOp.setInput('drawDebug', self.drawDebugInputAttr)
        self.deformersToOutputsSpliceOp.setInput('rigScale', self.rigScaleInputAttr)

        # Add Xfo Outputs
        self.deformersToOutputsSpliceOp.setInput('constrainers', self.spineOutputs)

        # Add Xfo Outputs
        self.deformersToOutputsSpliceOp.setOutput('constrainees', self.deformerJoints)

        # Add Pelvis Splice Op
        self.pelvisDefSpliceOp = SpliceOperator('pelvisDeformerSpliceOp', 'PoseConstraintSolver', 'Kraken')
        self.addOperator(self.pelvisDefSpliceOp)

        # Add Att Inputs
        self.pelvisDefSpliceOp.setInput('drawDebug', self.drawDebugInputAttr)
        self.pelvisDefSpliceOp.setInput('rigScale', self.rigScaleInputAttr)

        # Add Xfo Inputs
        self.pelvisDefSpliceOp.setInput('constrainer', self.pelvisOutputTgt)

        # Add Xfo Outputs
        self.pelvisDefSpliceOp.setOutput('constrainee', pelvisDef)


        Profiler.getInstance().pop()


    def setNumDeformers(self, numDeformers):

        # Add new deformers and outputs
        for i in xrange(len(self.spineOutputs), numDeformers):
            name = 'spine' + str(i + 1).zfill(2)
            spineOutput = ComponentOutput(name, parent=self.outputHrcGrp)
            self.spineOutputs.append(spineOutput)

        for i in xrange(len(self.deformerJoints), numDeformers):
            name = 'spine' + str(i + 1).zfill(2)
            spineDef = Joint(name, parent=self.defCmpGrp)
            spineDef.setComponent(self)
            self.deformerJoints.append(spineDef)

        return True


    def loadData(self, data=None):
        """Load a saved guide representation from persisted data.

        Arguments:
        data -- object, The JSON data object.

        Return:
        True if successful.

        """

        super(SpineComponentRig, self).loadData( data )

        cogPosition = data['cogPosition']
        spine01Position = data['spine01Position']
        spine02Position = data['spine02Position']
        spine03Position = data['spine03Position']
        spine04Position = data['spine04Position']
        numDeformers = data['numDeformers']

        self.cogCtrlSpace.xfo.tr = cogPosition
        self.cogCtrl.xfo.tr = cogPosition

        self.pelvisCtrlSpace.xfo.tr = cogPosition
        self.pelvisCtrl.xfo.tr = cogPosition

        self.spine01CtrlSpace.xfo.tr = spine01Position
        self.spine01Ctrl.xfo.tr = spine01Position

        self.spine02CtrlSpace.xfo.tr = spine02Position
        self.spine02Ctrl.xfo.tr = spine02Position

        self.spine03CtrlSpace.xfo.tr = spine03Position
        self.spine03Ctrl.xfo.tr = spine03Position

        self.spine04CtrlSpace.xfo.tr = spine04Position
        self.spine04Ctrl.xfo.tr = spine04Position

        length = spine01Position.distanceTo(spine02Position) + spine02Position.distanceTo(spine03Position) + spine03Position.distanceTo(spine04Position)
        self.lengthInputAttr.setMax(length * 3.0)
        self.lengthInputAttr.setValue(length)

        # Update number of deformers and outputs
        self.setNumDeformers(numDeformers)

        # Updating constraint to use the updated last output.
        self.spineEndOutputConstraint.setConstrainer(self.spineOutputs[-1], index=0)

        # ============
        # Set IO Xfos
        # ============

        # ====================
        # Evaluate Splice Ops
        # ====================
        # evaluate the spine op so that all the output transforms are updated.
        self.bezierSpineSpliceOp.evaluate()

        # evaluate the constraint op so that all the joint transforms are updated.
        self.deformersToOutputsSpliceOp.evaluate()
        self.pelvisDefSpliceOp.evaluate()

        # evaluate the constraints to ensure the outputs are now in the correct location.
        self.spineCogOutputConstraint.evaluate()
        self.spineBaseOutputConstraint.evaluate()
        self.pelvisOutputConstraint.evaluate()
        self.spineEndOutputConstraint.evaluate()
Example #14
0
    def __init__(self, name='Tentacle', parent=None):

        Profiler.getInstance().push("Construct Tentacle Rig Component:" + name)
        super(TentacleComponentRig, 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(2)

        # IK Control
        self.tentacleIKCtrlSpace = CtrlSpace('IK', parent=self.ctrlCmpGrp)
        self.tentacleIKCtrl = Control('IK', parent=self.tentacleIKCtrlSpace, shape="sphere")
        self.tentacleIKCtrl.scalePoints(Vec3(0.25, 0.25, 0.25))
        self.tentacleIKCtrl.lockScale(x=True, y=True, z=True)
        self.tentacleIKCtrl.lockRotation(x=True, y=True, z=True)

        # Add Component Params to IK control
        tentacleSettingsAttrGrp = AttributeGroup("DisplayInfo_LegSettings", parent=self.tentacleIKCtrl)
        tentacledrawDebugInputAttr = BoolAttribute('drawDebug', value=False, parent=tentacleSettingsAttrGrp)
        fkikInputAttr = ScalarAttribute('fkik', value=0.0, minValue=0.0, maxValue=1.0, parent=tentacleSettingsAttrGrp)
        waveLength_YInputAttr = ScalarAttribute('waveLength_Y', value=1.0, minValue=0.0, maxValue=5.0, parent=tentacleSettingsAttrGrp)
        waveAmplitude_YInputAttr = ScalarAttribute('waveAmplitude_Y', value=0.0, minValue=-3.0, maxValue=3.0, parent=tentacleSettingsAttrGrp)
        waveFrequency_YInputAttr = ScalarAttribute('waveFrequency_Y', value=2.0, minValue=0.0, maxValue=10.0, parent=tentacleSettingsAttrGrp)
        waveLength_ZInputAttr = ScalarAttribute('waveLength_Z', value=2.329, minValue=0.0, maxValue=5.0, parent=tentacleSettingsAttrGrp)
        waveAmplitude_ZInputAttr = ScalarAttribute('waveAmplitude_Z', value=0.0, minValue=-3.0, maxValue=3.0, parent=tentacleSettingsAttrGrp)
        waveFrequency_ZInputAttr = ScalarAttribute('waveFrequency_Z', value=3.354, minValue=0.0, maxValue=10.0, parent=tentacleSettingsAttrGrp)
        tipBiasInputAttr = ScalarAttribute('tipBias', value=1.0, minValue=0.0, maxValue=1.0, parent=tentacleSettingsAttrGrp)

        springStrengthInputAttr = ScalarAttribute('springStrength', value=0.3, minValue=0.0, maxValue=1.0, parent=tentacleSettingsAttrGrp)
        dampeningInputAttr = ScalarAttribute('dampening', value=0.03, minValue=0.0, maxValue=1.0, parent=tentacleSettingsAttrGrp)
        simulationWeightInputAttr = ScalarAttribute('simulationWeight', value=1.0, minValue=0.0, maxValue=1.0, parent=tentacleSettingsAttrGrp)
        softLimitBoundsInputAttr = ScalarAttribute('softLimitBounds', value=5.0, minValue=0.0, maxValue=10.0, parent=tentacleSettingsAttrGrp)

        # Connect IO to controls
        self.drawDebugInputAttr.connect(tentacledrawDebugInputAttr)

        # ==========
        # 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
        tentacleRootInputConstraint = PoseConstraint('_'.join([self.fkCtrlSpaces[0].getName(), 'To', self.rootInputTgt.getName()]))
        tentacleRootInputConstraint.setMaintainOffset(True)
        tentacleRootInputConstraint.addConstrainer(self.rootInputTgt)
        self.fkCtrlSpaces[0].addConstraint(tentacleRootInputConstraint)

        tentacleRootInputConstraint = PoseConstraint('_'.join([self.tentacleIKCtrlSpace.getName(), 'To', self.rootInputTgt.getName()]))
        tentacleRootInputConstraint.setMaintainOffset(True)
        tentacleRootInputConstraint.addConstrainer(self.rootInputTgt)
        self.tentacleIKCtrlSpace.addConstraint(tentacleRootInputConstraint)


        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.tentacleSolverSpliceOp = SpliceOperator('tentacleSpliceOp', 'TentacleSolver', 'Kraken')
        self.addOperator(self.tentacleSolverSpliceOp)

        # # Add Att Inputs
        self.tentacleSolverSpliceOp.setInput('drawDebug', self.drawDebugInputAttr)
        self.tentacleSolverSpliceOp.setInput('rigScale', self.rigScaleInputAttr)
        self.tentacleSolverSpliceOp.setInput('ikblend', fkikInputAttr)
        self.tentacleSolverSpliceOp.setInput('waveLength_Y', waveLength_YInputAttr)
        self.tentacleSolverSpliceOp.setInput('waveAmplitude_Y', waveAmplitude_YInputAttr)
        self.tentacleSolverSpliceOp.setInput('waveFrequency_Y', waveFrequency_YInputAttr)
        self.tentacleSolverSpliceOp.setInput('waveLength_Z', waveLength_ZInputAttr)
        self.tentacleSolverSpliceOp.setInput('waveAmplitude_Z', waveAmplitude_ZInputAttr)
        self.tentacleSolverSpliceOp.setInput('waveFrequency_Z', waveFrequency_ZInputAttr)
        self.tentacleSolverSpliceOp.setInput('tipBias', tipBiasInputAttr)

        self.tentacleSolverSpliceOp.setInput('springStrength', springStrengthInputAttr)
        self.tentacleSolverSpliceOp.setInput('dampening', dampeningInputAttr)
        self.tentacleSolverSpliceOp.setInput('simulationWeight', simulationWeightInputAttr)
        self.tentacleSolverSpliceOp.setInput('softLimitBounds', softLimitBoundsInputAttr)

        self.tentacleSolverSpliceOp.setInput('tipBoneLen', self.tipBoneLenInputAttr)

        # Add Xfo Inputs
        self.tentacleSolverSpliceOp.setInput('chainBase', self.chainBase)
        self.tentacleSolverSpliceOp.setInput('ikgoal', self.tentacleIKCtrl)

        self.tentacleSolverSpliceOp.setInput('fkcontrols', self.fkCtrls)

        # Add Xfo Outputs
        self.tentacleSolverSpliceOp.setOutput('pose', self.boneOutputsTgt)

        self.tentacleSolverSpliceOp.setOutput('tentacleEnd', self.tentacleEndXfoOutputTgt)


        # Add Deformer Splice Op
        self.outputsToDeformersSpliceOp = SpliceOperator('TentacleDeformerSpliceOp', 'MultiPoseConstraintSolver', 'Kraken', alwaysEval=True)
        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()
Example #15
0
class TentacleComponentRig(TentacleComponent):
    """Insect Leg Rig"""

    def __init__(self, name='Tentacle', parent=None):

        Profiler.getInstance().push("Construct Tentacle Rig Component:" + name)
        super(TentacleComponentRig, 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(2)

        # IK Control
        self.tentacleIKCtrlSpace = CtrlSpace('IK', parent=self.ctrlCmpGrp)
        self.tentacleIKCtrl = Control('IK', parent=self.tentacleIKCtrlSpace, shape="sphere")
        self.tentacleIKCtrl.scalePoints(Vec3(0.25, 0.25, 0.25))
        self.tentacleIKCtrl.lockScale(x=True, y=True, z=True)
        self.tentacleIKCtrl.lockRotation(x=True, y=True, z=True)

        # Add Component Params to IK control
        tentacleSettingsAttrGrp = AttributeGroup("DisplayInfo_LegSettings", parent=self.tentacleIKCtrl)
        tentacledrawDebugInputAttr = BoolAttribute('drawDebug', value=False, parent=tentacleSettingsAttrGrp)
        fkikInputAttr = ScalarAttribute('fkik', value=0.0, minValue=0.0, maxValue=1.0, parent=tentacleSettingsAttrGrp)
        waveLength_YInputAttr = ScalarAttribute('waveLength_Y', value=1.0, minValue=0.0, maxValue=5.0, parent=tentacleSettingsAttrGrp)
        waveAmplitude_YInputAttr = ScalarAttribute('waveAmplitude_Y', value=0.0, minValue=-3.0, maxValue=3.0, parent=tentacleSettingsAttrGrp)
        waveFrequency_YInputAttr = ScalarAttribute('waveFrequency_Y', value=2.0, minValue=0.0, maxValue=10.0, parent=tentacleSettingsAttrGrp)
        waveLength_ZInputAttr = ScalarAttribute('waveLength_Z', value=2.329, minValue=0.0, maxValue=5.0, parent=tentacleSettingsAttrGrp)
        waveAmplitude_ZInputAttr = ScalarAttribute('waveAmplitude_Z', value=0.0, minValue=-3.0, maxValue=3.0, parent=tentacleSettingsAttrGrp)
        waveFrequency_ZInputAttr = ScalarAttribute('waveFrequency_Z', value=3.354, minValue=0.0, maxValue=10.0, parent=tentacleSettingsAttrGrp)
        tipBiasInputAttr = ScalarAttribute('tipBias', value=1.0, minValue=0.0, maxValue=1.0, parent=tentacleSettingsAttrGrp)

        springStrengthInputAttr = ScalarAttribute('springStrength', value=0.3, minValue=0.0, maxValue=1.0, parent=tentacleSettingsAttrGrp)
        dampeningInputAttr = ScalarAttribute('dampening', value=0.03, minValue=0.0, maxValue=1.0, parent=tentacleSettingsAttrGrp)
        simulationWeightInputAttr = ScalarAttribute('simulationWeight', value=1.0, minValue=0.0, maxValue=1.0, parent=tentacleSettingsAttrGrp)
        softLimitBoundsInputAttr = ScalarAttribute('softLimitBounds', value=5.0, minValue=0.0, maxValue=10.0, parent=tentacleSettingsAttrGrp)

        # Connect IO to controls
        self.drawDebugInputAttr.connect(tentacledrawDebugInputAttr)

        # ==========
        # 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
        tentacleRootInputConstraint = PoseConstraint('_'.join([self.fkCtrlSpaces[0].getName(), 'To', self.rootInputTgt.getName()]))
        tentacleRootInputConstraint.setMaintainOffset(True)
        tentacleRootInputConstraint.addConstrainer(self.rootInputTgt)
        self.fkCtrlSpaces[0].addConstraint(tentacleRootInputConstraint)

        tentacleRootInputConstraint = PoseConstraint('_'.join([self.tentacleIKCtrlSpace.getName(), 'To', self.rootInputTgt.getName()]))
        tentacleRootInputConstraint.setMaintainOffset(True)
        tentacleRootInputConstraint.addConstrainer(self.rootInputTgt)
        self.tentacleIKCtrlSpace.addConstraint(tentacleRootInputConstraint)


        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.tentacleSolverSpliceOp = SpliceOperator('tentacleSpliceOp', 'TentacleSolver', 'Kraken')
        self.addOperator(self.tentacleSolverSpliceOp)

        # # Add Att Inputs
        self.tentacleSolverSpliceOp.setInput('drawDebug', self.drawDebugInputAttr)
        self.tentacleSolverSpliceOp.setInput('rigScale', self.rigScaleInputAttr)
        self.tentacleSolverSpliceOp.setInput('ikblend', fkikInputAttr)
        self.tentacleSolverSpliceOp.setInput('waveLength_Y', waveLength_YInputAttr)
        self.tentacleSolverSpliceOp.setInput('waveAmplitude_Y', waveAmplitude_YInputAttr)
        self.tentacleSolverSpliceOp.setInput('waveFrequency_Y', waveFrequency_YInputAttr)
        self.tentacleSolverSpliceOp.setInput('waveLength_Z', waveLength_ZInputAttr)
        self.tentacleSolverSpliceOp.setInput('waveAmplitude_Z', waveAmplitude_ZInputAttr)
        self.tentacleSolverSpliceOp.setInput('waveFrequency_Z', waveFrequency_ZInputAttr)
        self.tentacleSolverSpliceOp.setInput('tipBias', tipBiasInputAttr)

        self.tentacleSolverSpliceOp.setInput('springStrength', springStrengthInputAttr)
        self.tentacleSolverSpliceOp.setInput('dampening', dampeningInputAttr)
        self.tentacleSolverSpliceOp.setInput('simulationWeight', simulationWeightInputAttr)
        self.tentacleSolverSpliceOp.setInput('softLimitBounds', softLimitBoundsInputAttr)

        self.tentacleSolverSpliceOp.setInput('tipBoneLen', self.tipBoneLenInputAttr)

        # Add Xfo Inputs
        self.tentacleSolverSpliceOp.setInput('chainBase', self.chainBase)
        self.tentacleSolverSpliceOp.setInput('ikgoal', self.tentacleIKCtrl)

        self.tentacleSolverSpliceOp.setInput('fkcontrols', self.fkCtrls)

        # Add Xfo Outputs
        self.tentacleSolverSpliceOp.setOutput('pose', self.boneOutputsTgt)

        self.tentacleSolverSpliceOp.setOutput('tentacleEnd', self.tentacleEndXfoOutputTgt)


        # Add Deformer Splice Op
        self.outputsToDeformersSpliceOp = SpliceOperator('TentacleDeformerSpliceOp', 'MultiPoseConstraintSolver', 'Kraken', alwaysEval=True)
        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)
            tentacleOutput = ComponentOutput(name, parent=self.outputHrcGrp)
            self.boneOutputsTgt.append(tentacleOutput)

        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 loadData(self, data=None):
        """Load a saved guide representation from persisted data.

        Arguments:
        data -- object, The JSON data object.

        Return:
        True if successful.

        """

        super(TentacleComponentRig, 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(Vec3(boneLengths[i], boneLengths[i] * 0.45, boneLengths[i] * 0.45)))

        self.chainBase.xfo = boneXfos[0]

        self.tentacleIKCtrlSpace.xfo = endXfo
        self.tentacleIKCtrl.xfo = endXfo

        # ============
        # Set IO Xfos
        # ============
        self.rootInputTgt.xfo = boneXfos[0]

        for i in xrange(len(boneLengths)):
            self.boneOutputsTgt[i].xfo = boneXfos[i]

        self.tentacleEndXfoOutputTgt.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.tentacleSolverSpliceOp.evaluate()
        self.outputsToDeformersSpliceOp.evaluate()
Example #16
0
class FKChainComponentRig(FKChainComponent):
    """FK Chain Leg Rig"""
    def __init__(self, name='FKChain', parent=None):

        Profiler.getInstance().push("Construct FK Chain Rig Component:" + name)
        super(FKChainComponentRig, self).__init__(name, parent)

        # =========
        # Controls
        # =========
        # FK
        self.fkCtrlSpaces = []
        self.fkCtrls = []
        self.setNumControls(4)

        # Add Component Params to IK control
        legSettingsAttrGrp = AttributeGroup("DisplayInfo_ChainSettings",
                                            parent=self.fkCtrls[0])
        legdrawDebugInputAttr = BoolAttribute('drawDebug',
                                              value=False,
                                              parent=legSettingsAttrGrp)

        # Connect IO to controls
        self.drawDebugInputAttr.connect(legdrawDebugInputAttr)

        # ==========
        # 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
        rootInputConstraint = PoseConstraint('_'.join([
            self.fkCtrlSpaces[0].getName(), 'To',
            self.rootInputTgt.getName()
        ]))
        rootInputConstraint.setMaintainOffset(True)
        rootInputConstraint.addConstrainer(self.rootInputTgt)
        self.fkCtrlSpaces[0].addConstraint(rootInputConstraint)

        # ===============
        # Add Splice Ops
        # ===============
        # Add Output Splice Op
        self.outputsToControlsSpliceOp = SpliceOperator(
            'fkChainOutputSpliceOp', 'MultiPoseConstraintSolver', 'Kraken')
        self.addOperator(self.outputsToControlsSpliceOp)

        # Add Att Inputs
        self.outputsToControlsSpliceOp.setInput('drawDebug',
                                                self.drawDebugInputAttr)
        self.outputsToControlsSpliceOp.setInput('rigScale',
                                                self.rigScaleInputAttr)

        # Add Xfo Inputs
        self.outputsToControlsSpliceOp.setInput('constrainers', self.fkCtrls)

        # Add Xfo Outputs
        self.outputsToControlsSpliceOp.setOutput('constrainees',
                                                 self.boneOutputsTgt)

        # Add Deformer Splice Op
        self.deformersToOutputsSpliceOp = SpliceOperator(
            'fkChainDeformerSpliceOp', 'MultiPoseConstraintSolver', 'Kraken')
        self.addOperator(self.deformersToOutputsSpliceOp)

        # Add Att Inputs
        self.deformersToOutputsSpliceOp.setInput('drawDebug',
                                                 self.drawDebugInputAttr)
        self.deformersToOutputsSpliceOp.setInput('rigScale',
                                                 self.rigScaleInputAttr)

        # Add Xfo Inputs
        self.deformersToOutputsSpliceOp.setInput('constrainers',
                                                 self.boneOutputsTgt)

        # Add Xfo Outputs
        self.deformersToOutputsSpliceOp.setOutput('constrainees',
                                                  self.deformerJoints)

        Profiler.getInstance().pop()

    def setNumControls(self, numControls):

        # Add more controls
        if numControls > len(self.fkCtrlSpaces):
            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'
                boneFKCtrlSpace = CtrlSpace(boneName, parent=parent)

                boneFKCtrl = Control(boneName,
                                     parent=boneFKCtrlSpace,
                                     shape="cube")
                boneFKCtrl.alignOnXAxis()
                boneFKCtrl.lockScale(x=True, y=True, z=True)
                boneFKCtrl.lockTranslation(x=True, y=True, z=True)

                self.fkCtrlSpaces.append(boneFKCtrlSpace)
                self.fkCtrls.append(boneFKCtrl)

        # Remove extra ctrls
        elif numControls < len(self.fkCtrlSpaces):
            numExtraCtrls = len(self.fkCtrls) - numControls
            for i in xrange(numExtraCtrls):
                extraCtrlSpace = self.fkCtrlSpaces.pop()
                extraCtrl = self.fkCtrls.pop()
                extraCtrlSpace.getParent().removeChild(extraCtrlSpace)
                extraCtrl.getParent().removeChild(extraCtrl)

    def setNumDeformers(self, numDeformers):

        # Add more deformers and outputs
        if numDeformers > len(self.boneOutputsTgt):
            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)

                boneDef = Joint(name, parent=self.defCmpGrp)
                boneDef.setComponent(self)
                self.deformerJoints.append(boneDef)

        # Remove extra deformers and outputs
        elif numDeformers < len(self.boneOutputsTgt):
            numExtraOutputs = len(self.boneOutputsTgt) - numDeformers
            numExtraDefs = len(self.deformerJoints) - numDeformers

            for i in xrange(numExtraOutputs):
                extraOutput = self.boneOutputsTgt.pop()
                extraDef = self.deformerJoints.pop()

                extraOutput.getParent().removeChild(extraOutput)
                extraDef.getParent().removeChild(extraDef)

        return True

    def loadData(self, data=None):
        """Load a saved guide representation from persisted data.

        Arguments:
        data -- object, The JSON data object.

        Return:
        True if successful.

        """

        super(FKChainComponentRig, self).loadData(data)

        boneXfos = data['boneXfos']
        boneLengths = data['boneLengths']
        numJoints = data['numJoints']

        # Add extra controls and outputs
        self.setNumControls(numJoints)
        self.setNumDeformers(numJoints)

        for i in xrange(numJoints):
            self.fkCtrlSpaces[i].xfo = boneXfos[i]
            self.fkCtrls[i].xfo = boneXfos[i]
            self.fkCtrls[i].scalePoints(
                Vec3(boneLengths[i], boneLengths[i] * 0.45,
                     boneLengths[i] * 0.45))

        # ============
        # Set IO Xfos
        # ============
        self.rootInputTgt.xfo = boneXfos[0]

        for i in xrange(numJoints):
            self.boneOutputsTgt[i].xfo = boneXfos[i]

        self.chainEndXfoOutputTgt.xfo = data['endXfo']
        self.chainEndPosOutputTgt.xfo = data['endXfo']

        # =============
        # Set IO Attrs
        # =============

        # ====================
        # Evaluate Splice Ops
        # ====================
        # Eval Outputs to Controls Op to evaulate with new outputs and controls
        self.outputsToControlsSpliceOp.evaluate()

        # evaluate the output splice op to evaluate with new outputs and deformers
        self.deformersToOutputsSpliceOp.evaluate()
Example #17
0
    def __init__(self, name='FKChain', parent=None):

        Profiler.getInstance().push("Construct FK Chain Rig Component:" + name)
        super(FKChainComponentRig, self).__init__(name, parent)


        # =========
        # Controls
        # =========
        # FK
        self.fkCtrlSpaces = []
        self.fkCtrls = []
        self.setNumControls(4)

        # Add Component Params to IK control
        legSettingsAttrGrp = AttributeGroup("DisplayInfo_ChainSettings", parent=self.fkCtrls[0])
        legdrawDebugInputAttr = BoolAttribute('drawDebug', value=False, parent=legSettingsAttrGrp)

        # Connect IO to controls
        self.drawDebugInputAttr.connect(legdrawDebugInputAttr)

        # ==========
        # 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
        rootInputConstraint = PoseConstraint('_'.join([self.fkCtrlSpaces[0].getName(), 'To', self.rootInputTgt.getName()]))
        rootInputConstraint.setMaintainOffset(True)
        rootInputConstraint.addConstrainer(self.rootInputTgt)
        self.fkCtrlSpaces[0].addConstraint(rootInputConstraint)


        # ===============
        # Add Splice Ops
        # ===============
        # Add Output Splice Op
        self.outputsToControlsSpliceOp = SpliceOperator('fkChainOutputSpliceOp', 'MultiPoseConstraintSolver', 'Kraken')
        self.addOperator(self.outputsToControlsSpliceOp)

        # Add Att Inputs
        self.outputsToControlsSpliceOp.setInput('drawDebug', self.drawDebugInputAttr)
        self.outputsToControlsSpliceOp.setInput('rigScale', self.rigScaleInputAttr)

        # Add Xfo Inputs
        self.outputsToControlsSpliceOp.setInput('constrainers', self.fkCtrls)

        # Add Xfo Outputs
        self.outputsToControlsSpliceOp.setOutput('constrainees', self.boneOutputsTgt)

        # Add Deformer Splice Op
        self.deformersToOutputsSpliceOp = SpliceOperator('fkChainDeformerSpliceOp', 'MultiPoseConstraintSolver', 'Kraken')
        self.addOperator(self.deformersToOutputsSpliceOp)

        # Add Att Inputs
        self.deformersToOutputsSpliceOp.setInput('drawDebug', self.drawDebugInputAttr)
        self.deformersToOutputsSpliceOp.setInput('rigScale', self.rigScaleInputAttr)

        # Add Xfo Inputs
        self.deformersToOutputsSpliceOp.setInput('constrainers', self.boneOutputsTgt)

        # Add Xfo Outputs
        self.deformersToOutputsSpliceOp.setOutput('constrainees', self.deformerJoints)

        Profiler.getInstance().pop()
Example #18
0
class MainSrtComponentRig(MainSrtComponent):
    """MainSrt Component Rig"""

    def __init__(self, name="mainSrt", parent=None):

        Profiler.getInstance().push("Construct MainSrt Rig Component:" + name)
        super(MainSrtComponentRig, self).__init__(name, parent)

        # =========
        # Controls
        # =========
        # Add Controls
        self.mainSRTCtrlSpace = CtrlSpace("SRT", parent=self.ctrlCmpGrp)
        self.mainSRTCtrl = Control("SRT", shape="circle", parent=self.mainSRTCtrlSpace)
        self.mainSRTCtrl.lockScale(x=True, y=True, z=True)

        self.offsetCtrlSpace = CtrlSpace("Offset", parent=self.mainSRTCtrl)
        self.offsetCtrl = Control("Offset", shape="circle", parent=self.offsetCtrlSpace)
        self.offsetCtrl.setColor("orange")
        self.offsetCtrl.lockScale(x=True, y=True, z=True)

        # Add Component Params to IK control
        mainSrtSettingsAttrGrp = AttributeGroup("DisplayInfo_MainSrtSettings", parent=self.mainSRTCtrl)
        self.rigScaleAttr = ScalarAttribute(
            "rigScale", value=1.0, parent=mainSrtSettingsAttrGrp, minValue=0.1, maxValue=100.0
        )

        self.rigScaleOutputAttr.connect(self.rigScaleAttr)

        # ==========
        # Deformers
        # ==========

        # ==============
        # Constrain I/O
        # ==============
        # Constraint inputs

        # Constraint outputs
        srtConstraint = PoseConstraint("_".join([self.srtOutputTgt.getName(), "To", self.mainSRTCtrl.getName()]))
        srtConstraint.addConstrainer(self.mainSRTCtrl)
        self.srtOutputTgt.addConstraint(srtConstraint)

        offsetConstraint = PoseConstraint("_".join([self.offsetOutputTgt.getName(), "To", self.mainSRTCtrl.getName()]))
        offsetConstraint.addConstrainer(self.offsetCtrl)
        self.offsetOutputTgt.addConstraint(offsetConstraint)

        # ===============
        # Add Splice Ops
        # ===============
        # Add Rig Scale Splice Op
        self.rigScaleSpliceOp = SpliceOperator("rigScaleSpliceOp", "RigScaleSolver", "Kraken")
        self.addOperator(self.rigScaleSpliceOp)

        # Add Att Inputs
        self.rigScaleSpliceOp.setInput("drawDebug", self.drawDebugInputAttr)
        self.rigScaleSpliceOp.setInput("rigScale", self.rigScaleOutputAttr)

        # Add Xfo Inputs

        # Add Xfo Outputs
        self.rigScaleSpliceOp.setOutput("target", self.mainSRTCtrlSpace)

        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(MainSrtComponentRig, self).loadData(data)

        # ================
        # Resize Controls
        # ================
        self.mainSRTCtrl.scalePoints(Vec3(data["mainSrtSize"], 1.0, data["mainSrtSize"]))
        self.offsetCtrl.scalePoints(Vec3(data["mainSrtSize"] - 0.5, 1.0, data["mainSrtSize"] - 0.5))

        # =======================
        # Set Control Transforms
        # =======================
        self.mainSRTCtrlSpace.xfo = data["mainSrtXfo"]
        self.mainSRTCtrl.xfo = data["mainSrtXfo"]
        self.offsetCtrlSpace.xfo = data["mainSrtXfo"]
        self.offsetCtrl.xfo = data["mainSrtXfo"]

        # ============
        # Set IO Xfos
        # ============
        self.srtOutputTgt = data["mainSrtXfo"]
        self.offsetOutputTgt = data["mainSrtXfo"]
Example #19
0
    def __init__(self, name="spine", parent=None):

        Profiler.getInstance().push("Construct Spine Rig Component:" + name)
        super(FabriceSpineRig, self).__init__(name, parent)


        # =========
        # Controls
        # =========
        # COG
        self.cogCtrlSpace = CtrlSpace('cog', parent=self.ctrlCmpGrp)
        self.cogCtrl = Control('cog', parent=self.cogCtrlSpace, shape="circle")
        self.cogCtrl.rotatePoints(90, 0, 0)
        self.cogCtrl.scalePoints(Vec3(3.0, 3.0, 3.0))
        self.cogCtrl.translatePoints(Vec3(0.0, 0.0, 0.2))
        self.cogCtrl.lockScale(x=True, y=True, z=True)
        self.cogCtrl.setColor("orange")

        # Spine Base
        self.spineBaseCtrlSpace = CtrlSpace('spineBase', parent=self.cogCtrl)
        self.spineBaseCtrl = Control('spineBase', parent=self.spineBaseCtrlSpace, shape="pin")
        self.spineBaseCtrl.rotatePoints(90, 0, 0)
        self.spineBaseCtrl.translatePoints(Vec3(0, 1.0, 0))
        self.spineBaseCtrl.lockScale(x=True, y=True, z=True)

        # Spine Base Handle
        self.spineBaseHandleCtrlSpace = CtrlSpace('spineBaseHandle', parent=self.spineBaseCtrl)
        self.spineBaseHandleCtrl = Control('spineBaseHandle', parent=self.spineBaseHandleCtrlSpace, shape="pin")
        self.spineBaseHandleCtrl.rotatePoints(90, 0, 0)
        self.spineBaseHandleCtrl.translatePoints(Vec3(0, 1.0, 0))
        self.spineBaseHandleCtrl.lockScale(x=True, y=True, z=True)
        self.spineBaseHandleCtrl.setColor("orange")

        # Spine End
        self.spineEndCtrlSpace = CtrlSpace('spineEnd', parent=self.cogCtrl)
        self.spineEndCtrl = Control('spineEnd', parent=self.spineEndCtrlSpace, shape="pin")
        self.spineEndCtrl.rotatePoints(90, 0, 0)
        self.spineEndCtrl.lockScale(x=True, y=True, z=True)
        self.spineEndCtrl.translatePoints(Vec3(0, 1.0, 0))

        # Spine End Handle
        self.spineEndHandleCtrlSpace = CtrlSpace('spineEndHandle', parent=self.spineEndCtrl)
        self.spineEndHandleCtrl = Control('spineEndHandle', parent=self.spineEndHandleCtrlSpace, shape="pin")
        self.spineEndHandleCtrl.rotatePoints(90, 0, 0)
        self.spineEndHandleCtrl.translatePoints(Vec3(0, 1.0, 0))
        self.spineEndHandleCtrl.lockScale(x=True, y=True, z=True)
        self.spineEndHandleCtrl.setColor("orange")


        # ==========
        # Deformers
        # ==========
        deformersLayer = self.getOrCreateLayer('deformers')
        self.defCmpGrp = ComponentGroup(self.getName(), self, parent=deformersLayer)
        self.chestDef = Joint('chest', parent=self.defCmpGrp)
        self.chestDef.setComponent(self)

        self.deformerJoints = []
        self.spineOutputs = []
        self.setNumDeformers(1)


        # =====================
        # Create Component I/O
        # =====================
        # Setup component Xfo I/O's
        self.spineVertebraeOutput.setTarget(self.spineOutputs)

        # =====================
        # Constraint Deformers
        # =====================
        self.chestDefConstraint = PoseConstraint('_'.join([self.chestDef.getName(), 'To', self.spineBaseOutputTgt.getName()]))
        self.chestDefConstraint.addConstrainer(self.spineBaseOutputTgt)
        self.chestDef.addConstraint(self.chestDefConstraint)

        # ==============
        # Constrain I/O
        # ==============

        # Constraint inputs
        self.spineSrtInputConstraint = PoseConstraint('_'.join([self.cogCtrlSpace.getName(), 'To', self.spineMainSrtInputTgt.getName()]))
        self.spineSrtInputConstraint.addConstrainer(self.spineMainSrtInputTgt)
        self.spineSrtInputConstraint.setMaintainOffset(True)
        self.cogCtrlSpace.addConstraint(self.spineSrtInputConstraint)

        # Constraint outputs
        self.spineCogOutputConstraint = PoseConstraint('_'.join([self.spineCogOutputTgt.getName(), 'To', self.cogCtrl.getName()]))
        self.spineCogOutputConstraint.addConstrainer(self.cogCtrl)
        self.spineCogOutputTgt.addConstraint(self.spineCogOutputConstraint)

        # Spine Base
        self.spineBaseOutputPosConstraint = PositionConstraint('_'.join([self.spineBaseOutputTgt.getName(), 'PosTo', self.spineOutputs[0].getName()]))
        self.spineBaseOutputPosConstraint.addConstrainer(self.spineOutputs[0])
        self.spineBaseOutputTgt.addConstraint(self.spineBaseOutputPosConstraint)

        self.spineBaseOutputOriConstraint = OrientationConstraint('_'.join([self.spineBaseOutputTgt.getName(), 'PosTo', self.cogCtrl.getName()]))
        self.spineBaseOutputOriConstraint.addConstrainer(self.cogCtrl)
        self.spineBaseOutputTgt.addConstraint(self.spineBaseOutputOriConstraint)

        # Spine End
        self.spineEndOutputConstraint = PoseConstraint('_'.join([self.spineEndOutputTgt.getName(), 'To', 'spineEnd']))
        self.spineEndOutputConstraint.addConstrainer(self.spineOutputs[0])
        self.spineEndOutputTgt.addConstraint(self.spineEndOutputConstraint)

        self.spineEndCtrlOutputConstraint = PoseConstraint('_'.join([self.spineEndCtrlOutputTgt.getName(), 'To', self.spineEndCtrl.getName()]))
        self.spineEndCtrlOutputConstraint.addConstrainer(self.spineEndCtrl)
        self.spineEndCtrlOutputTgt.addConstraint(self.spineEndCtrlOutputConstraint)


        # ===============
        # Add Splice Ops
        # ===============
        # Add Spine Splice Op
        self.bezierSpineSpliceOp = SpliceOperator('spineSpliceOp', 'BezierSpineSolver', 'Kraken')
        self.addOperator(self.bezierSpineSpliceOp)

        # Add Att Inputs
        self.bezierSpineSpliceOp.setInput('drawDebug', self.drawDebugInputAttr)
        self.bezierSpineSpliceOp.setInput('rigScale', self.rigScaleInputAttr)
        self.bezierSpineSpliceOp.setInput('length', self.lengthInputAttr)

        # Add Xfo Inputs
        self.bezierSpineSpliceOp.setInput('base', self.spineBaseCtrl)
        self.bezierSpineSpliceOp.setInput('baseHandle', self.spineBaseHandleCtrl)
        self.bezierSpineSpliceOp.setInput('tipHandle', self.spineEndHandleCtrl)
        self.bezierSpineSpliceOp.setInput('tip', self.spineEndCtrl)

        # Add Xfo Outputs
        self.bezierSpineSpliceOp.setOutput('outputs', self.spineOutputs)

        # Add Deformer Splice Op
        self.deformersToOutputsSpliceOp = SpliceOperator('spineDeformerSpliceOp', 'MultiPoseConstraintSolver', 'Kraken', alwaysEval=True)
        self.addOperator(self.deformersToOutputsSpliceOp)

        # Add Att Inputs
        self.deformersToOutputsSpliceOp.setInput('drawDebug', self.drawDebugInputAttr)
        self.deformersToOutputsSpliceOp.setInput('rigScale', self.rigScaleInputAttr)

        # Add Xfo Outputs
        self.deformersToOutputsSpliceOp.setInput('constrainers', self.spineOutputs)

        # Add Xfo Outputs
        self.deformersToOutputsSpliceOp.setOutput('constrainees', self.deformerJoints)

        Profiler.getInstance().pop()
Example #20
0
    def __init__(self, name="mainSrt", parent=None):

        Profiler.getInstance().push("Construct MainSrt Rig Component:" + name)
        super(MainSrtComponentRig, self).__init__(name, parent)

        # =========
        # Controls
        # =========
        # Add Controls
        self.mainSRTCtrlSpace = CtrlSpace("SRT", parent=self.ctrlCmpGrp)
        self.mainSRTCtrl = Control("SRT", shape="circle", parent=self.mainSRTCtrlSpace)
        self.mainSRTCtrl.lockScale(x=True, y=True, z=True)

        self.offsetCtrlSpace = CtrlSpace("Offset", parent=self.mainSRTCtrl)
        self.offsetCtrl = Control("Offset", shape="circle", parent=self.offsetCtrlSpace)
        self.offsetCtrl.setColor("orange")
        self.offsetCtrl.lockScale(x=True, y=True, z=True)

        # Add Component Params to IK control
        mainSrtSettingsAttrGrp = AttributeGroup("DisplayInfo_MainSrtSettings", parent=self.mainSRTCtrl)
        self.rigScaleAttr = ScalarAttribute(
            "rigScale", value=1.0, parent=mainSrtSettingsAttrGrp, minValue=0.1, maxValue=100.0
        )

        self.rigScaleOutputAttr.connect(self.rigScaleAttr)

        # ==========
        # Deformers
        # ==========

        # ==============
        # Constrain I/O
        # ==============
        # Constraint inputs

        # Constraint outputs
        srtConstraint = PoseConstraint("_".join([self.srtOutputTgt.getName(), "To", self.mainSRTCtrl.getName()]))
        srtConstraint.addConstrainer(self.mainSRTCtrl)
        self.srtOutputTgt.addConstraint(srtConstraint)

        offsetConstraint = PoseConstraint("_".join([self.offsetOutputTgt.getName(), "To", self.mainSRTCtrl.getName()]))
        offsetConstraint.addConstrainer(self.offsetCtrl)
        self.offsetOutputTgt.addConstraint(offsetConstraint)

        # ===============
        # Add Splice Ops
        # ===============
        # Add Rig Scale Splice Op
        self.rigScaleSpliceOp = SpliceOperator("rigScaleSpliceOp", "RigScaleSolver", "Kraken")
        self.addOperator(self.rigScaleSpliceOp)

        # Add Att Inputs
        self.rigScaleSpliceOp.setInput("drawDebug", self.drawDebugInputAttr)
        self.rigScaleSpliceOp.setInput("rigScale", self.rigScaleOutputAttr)

        # Add Xfo Inputs

        # Add Xfo Outputs
        self.rigScaleSpliceOp.setOutput("target", self.mainSRTCtrlSpace)

        Profiler.getInstance().pop()
Example #21
0
    def __init__(self, name='mainSrt', parent=None):

        Profiler.getInstance().push("Construct MainSrt Rig Component:" + name)
        super(MainSrtComponentRig, self).__init__(name, parent)

        # =========
        # Controls
        # =========
        # Add Controls
        self.mainSRTCtrlSpace = CtrlSpace('SRT', parent=self.ctrlCmpGrp)
        self.mainSRTCtrl = Control('SRT',
                                   shape='circle',
                                   parent=self.mainSRTCtrlSpace)
        self.mainSRTCtrl.lockScale(x=True, y=True, z=True)

        self.offsetCtrlSpace = CtrlSpace('Offset', parent=self.mainSRTCtrl)
        self.offsetCtrl = Control('Offset',
                                  shape='circle',
                                  parent=self.offsetCtrlSpace)
        self.offsetCtrl.setColor("orange")
        self.offsetCtrl.lockScale(x=True, y=True, z=True)

        # Add Component Params to IK control
        mainSrtSettingsAttrGrp = AttributeGroup('DisplayInfo_MainSrtSettings',
                                                parent=self.mainSRTCtrl)
        self.rigScaleAttr = ScalarAttribute('rigScale',
                                            value=1.0,
                                            parent=mainSrtSettingsAttrGrp,
                                            minValue=0.1,
                                            maxValue=100.0)

        self.rigScaleOutputAttr.connect(self.rigScaleAttr)

        # ==========
        # Deformers
        # ==========

        # ==============
        # Constrain I/O
        # ==============
        # Constraint inputs

        # Constraint outputs
        srtConstraint = PoseConstraint('_'.join(
            [self.srtOutputTgt.getName(), 'To',
             self.mainSRTCtrl.getName()]))
        srtConstraint.addConstrainer(self.mainSRTCtrl)
        self.srtOutputTgt.addConstraint(srtConstraint)

        offsetConstraint = PoseConstraint('_'.join(
            [self.offsetOutputTgt.getName(), 'To',
             self.mainSRTCtrl.getName()]))
        offsetConstraint.addConstrainer(self.offsetCtrl)
        self.offsetOutputTgt.addConstraint(offsetConstraint)

        # ===============
        # Add Splice Ops
        # ===============
        #Add Rig Scale Splice Op
        self.rigScaleSpliceOp = SpliceOperator('rigScaleSpliceOp',
                                               'RigScaleSolver', 'Kraken')
        self.addOperator(self.rigScaleSpliceOp)

        # Add Att Inputs
        self.rigScaleSpliceOp.setInput('drawDebug', self.drawDebugInputAttr)
        self.rigScaleSpliceOp.setInput('rigScale', self.rigScaleOutputAttr)

        # Add Xfo Inputs

        # Add Xfo Outputs
        self.rigScaleSpliceOp.setOutput('target', self.mainSRTCtrlSpace)

        Profiler.getInstance().pop()
Example #22
0
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()
Example #23
0
    def __init__(self, name="fabriceTail", parent=None):

        Profiler.getInstance().push("Construct Tail Rig Component:" + name)
        super(FabriceTailRig, self).__init__(name, parent)


        # =========
        # Controls
        # =========

        # Tail Base
        # self.tailBaseCtrlSpace = CtrlSpace('tailBase', parent=self.ctrlCmpGrp)
        # self.tailBaseCtrl = Control('tailBase', parent=self.tailBaseCtrlSpace, shape="circle")
        # self.tailBaseCtrl.rotatePoints(90, 0, 0)
        # self.tailBaseCtrl.scalePoints(Vec3(2.0, 2.0, 2.0))
        # self.tailBaseCtrl.setColor("greenBlue")

        # Tail Base Handle
        self.tailBaseHandleCtrlSpace = CtrlSpace('tailBaseHandle', parent=self.ctrlCmpGrp)
        self.tailBaseHandleCtrl = Control('tailBaseHandle', parent=self.tailBaseHandleCtrlSpace, shape="pin")
        self.tailBaseHandleCtrl.lockScale(x=True, y=True, z=True)
        self.tailBaseHandleCtrl.setColor("turqoise")

        # Tail End Handle
        self.tailEndHandleCtrlSpace = CtrlSpace('tailEndHandle', parent=self.ctrlCmpGrp)
        self.tailEndHandleCtrl = Control('tailEndHandle', parent=self.tailEndHandleCtrlSpace, shape="pin")
        self.tailEndHandleCtrl.lockScale(x=True, y=True, z=True)
        self.tailEndHandleCtrl.setColor("turqoise")

        # Tail End
        self.tailEndCtrlSpace = CtrlSpace('tailEnd', parent=self.tailEndHandleCtrl)
        self.tailEndCtrl = Control('tailEnd', parent=self.tailEndCtrlSpace, shape="pin")
        self.tailEndCtrl.lockScale(x=True, y=True, z=True)
        self.tailEndCtrl.setColor("greenBlue")


        # ==========
        # Deformers
        # ==========
        deformersLayer = self.getOrCreateLayer('deformers')
        self.defCmpGrp = ComponentGroup(self.getName(), self, parent=deformersLayer)
        self.deformerJoints = []
        self.tailOutputs = []
        self.setNumDeformers(1)


        # =====================
        # Create Component I/O
        # =====================
        # Setup component Xfo I/O's
        self.tailVertebraeOutput.setTarget(self.tailOutputs)


        # ==============
        # Constrain I/O
        # ==============
        # Constraint inputs
        self.tailBaseHandleInputConstraint = PoseConstraint('_'.join([self.tailBaseHandleCtrlSpace.getName(), 'To', self.spineEndCtrlInputTgt.getName()]))
        self.tailBaseHandleInputConstraint.addConstrainer(self.spineEndCtrlInputTgt)
        self.tailBaseHandleInputConstraint.setMaintainOffset(True)
        self.tailBaseHandleCtrlSpace.addConstraint(self.tailBaseHandleInputConstraint)

        self.tailEndHandleInputConstraint = PoseConstraint('_'.join([self.tailEndHandleCtrlSpace.getName(), 'To', self.cogInputTgt.getName()]))
        self.tailEndHandleInputConstraint.addConstrainer(self.cogInputTgt)
        self.tailEndHandleInputConstraint.setMaintainOffset(True)
        self.tailEndHandleCtrlSpace.addConstraint(self.tailEndHandleInputConstraint)

        # Constraint outputs
        self.tailBaseOutputConstraint = PoseConstraint('_'.join([self.tailBaseOutputTgt.getName(), 'To', 'spineBase']))
        self.tailBaseOutputConstraint.addConstrainer(self.tailOutputs[0])
        self.tailBaseOutputTgt.addConstraint(self.tailBaseOutputConstraint)

        self.tailEndOutputConstraint = PoseConstraint('_'.join([self.tailEndOutputTgt.getName(), 'To', 'spineEnd']))
        self.tailEndOutputConstraint.addConstrainer(self.tailOutputs[0])
        self.tailEndOutputTgt.addConstraint(self.tailEndOutputConstraint)


        # ===============
        # Add Splice Ops
        # ===============
        # Add Tail Splice Op
        self.bezierTailSpliceOp = SpliceOperator('tailSpliceOp', 'BezierSpineSolver', 'Kraken')
        self.addOperator(self.bezierTailSpliceOp)

        # Add Att Inputs
        self.bezierTailSpliceOp.setInput('drawDebug', self.drawDebugInputAttr)
        self.bezierTailSpliceOp.setInput('rigScale', self.rigScaleInputAttr)
        self.bezierTailSpliceOp.setInput('length', self.lengthInputAttr)

        # Add Xfo Inputs
        self.bezierTailSpliceOp.setInput('base', self.spineEndInputTgt)
        self.bezierTailSpliceOp.setInput('baseHandle', self.tailBaseHandleCtrl)
        self.bezierTailSpliceOp.setInput('tipHandle', self.tailEndHandleCtrl)
        self.bezierTailSpliceOp.setInput('tip', self.tailEndCtrl)

        # Add Xfo Outputs
        self.bezierTailSpliceOp.setOutput('outputs', self.tailOutputs)

        # Add Deformer Splice Op
        self.deformersToOutputsSpliceOp = SpliceOperator('tailDeformerSpliceOp', 'MultiPoseConstraintSolver', 'Kraken', alwaysEval=True)
        self.addOperator(self.deformersToOutputsSpliceOp)

        # Add Att Inputs
        self.deformersToOutputsSpliceOp.setInput('drawDebug', self.drawDebugInputAttr)
        self.deformersToOutputsSpliceOp.setInput('rigScale', self.rigScaleInputAttr)

        # Add Xfo Outputs
        self.deformersToOutputsSpliceOp.setInput('constrainers', self.tailOutputs)

        # Add Xfo Outputs
        self.deformersToOutputsSpliceOp.setOutput('constrainees', self.deformerJoints)

        Profiler.getInstance().pop()
Example #24
0
    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()
Example #25
0
    def __init__(self, name='tail', parent=None):

        Profiler.getInstance().push("Construct Fabrice Tail Guide Component:" + name)
        super(FabriceTailGuide, self).__init__(name, parent)

        # =========
        # Controls
        # ========
        guideSettingsAttrGrp = AttributeGroup("GuideSettings", parent=self)
        self.numDeformersAttr = IntegerAttribute('numDeformers', value=1, minValue=0, maxValue=20, parent=guideSettingsAttrGrp)
        self.numDeformersAttr.setValueChangeCallback(self.updateNumDeformers)


        # Guide Controls
        self.tailBaseCtrl = Control('tailBase', parent=self.ctrlCmpGrp, shape='sphere')
        self.tailBaseCtrl.scalePoints(Vec3(1.2, 1.2, 1.2))
        self.tailBaseCtrl.lockScale(x=True, y=True, z=True)
        self.tailBaseCtrl.setColor("turqoise")

        self.tailBaseHandleCtrl = Control('tailBaseHandle', parent=self.ctrlCmpGrp, shape='pin')
        self.tailBaseHandleCtrl.rotatePoints(90, 0, 0)
        self.tailBaseHandleCtrl.translatePoints(Vec3(0, 1.0, 0))
        self.tailBaseHandleCtrl.lockScale(x=True, y=True, z=True)
        self.tailBaseHandleCtrl.setColor("turqoise")

        self.tailEndHandleCtrl = Control('tailEndHandle', parent=self.ctrlCmpGrp, shape='pin')
        self.tailEndHandleCtrl.rotatePoints(90, 0, 0)
        self.tailEndHandleCtrl.translatePoints(Vec3(0, 1.0, 0))
        self.tailEndHandleCtrl.lockScale(x=True, y=True, z=True)
        self.tailEndHandleCtrl.setColor("turqoise")

        self.tailEndCtrl = Control('tailEnd', parent=self.ctrlCmpGrp, shape='pin')
        self.tailEndCtrl.rotatePoints(90, 0, 0)
        self.tailEndCtrl.translatePoints(Vec3(0, 1.0, 0))
        self.tailEndCtrl.lockScale(x=True, y=True, z=True)
        self.tailEndCtrl.setColor("turqoise")

        # ===============
        # Add Splice Ops
        # ===============
        # Add Tail Splice Op
        self.bezierSpineSpliceOp = SpliceOperator('spineGuideSpliceOp', 'BezierSpineSolver', 'Kraken', alwaysEval=True)
        self.bezierSpineSpliceOp.setOutput('outputs', self.tailVertebraeOutput.getTarget())

        self.addOperator(self.bezierSpineSpliceOp)

        # Add Att Inputs
        self.bezierSpineSpliceOp.setInput('drawDebug', self.drawDebugInputAttr)
        self.bezierSpineSpliceOp.setInput('rigScale', self.rigScaleInputAttr)
        self.bezierSpineSpliceOp.setInput('length', self.lengthInputAttr)

        # Add Xfo Inputs
        self.bezierSpineSpliceOp.setInput('base', self.tailBaseCtrl)
        self.bezierSpineSpliceOp.setInput('baseHandle', self.tailBaseHandleCtrl)
        self.bezierSpineSpliceOp.setInput('tipHandle', self.tailEndHandleCtrl)
        self.bezierSpineSpliceOp.setInput('tip', self.tailEndCtrl)

        self.loadData({
            'name': name,
            'location': 'M',
            'tailBasePos': Vec3(0.0, 0.65, -3.1),
            'tailBaseHandlePos': Vec3(0.0, 0.157, -4.7),
            'tailBaseHandleCtrlCrvData': self.tailBaseHandleCtrl.getCurveData(),
            'tailEndHandlePos': Vec3(0.0, 0.0625, -6.165),
            'tailEndHandleCtrlCrvData': self.tailEndHandleCtrl.getCurveData(),
            'tailEndPos': Vec3(0.0, -0.22, -7.42),
            'tailEndCtrlCrvData': self.tailEndCtrl.getCurveData(),
            'numDeformers': 6
        })

        Profiler.getInstance().pop()
Example #26
0
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()
Example #27
0
    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()
Example #28
0
    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()
Example #29
0
    def __init__(self, name='h  ead', parent=None):

        Profiler.getInstance().push("Construct Head Rig Component:" + name)
        super(FabriceHeadRig, self).__init__(name, parent)

        # =========
        # Controls
        # =========
        # Head Aim
        self.headAimCtrlSpace = CtrlSpace('headAim', parent=self.ctrlCmpGrp)
        self.headAimCtrl = Control('headAim',
                                   parent=self.headAimCtrlSpace,
                                   shape="sphere")
        self.headAimCtrl.scalePoints(Vec3(0.35, 0.35, 0.35))
        self.headAimCtrl.lockScale(x=True, y=True, z=True)

        self.headAimUpV = Locator('headAimUpV', parent=self.headAimCtrl)
        self.headAimUpV.setShapeVisibility(False)

        # Head
        self.headAim = Locator('headAim', parent=self.ctrlCmpGrp)
        self.headAim.setShapeVisibility(False)

        self.headCtrlSpace = CtrlSpace('head', parent=self.ctrlCmpGrp)
        self.headCtrl = Control('head',
                                parent=self.headCtrlSpace,
                                shape="circle")
        self.headCtrl.lockTranslation(x=True, y=True, z=True)
        self.headCtrl.lockScale(x=True, y=True, z=True)

        # Jaw
        self.jawCtrlSpace = CtrlSpace('jawCtrlSpace', parent=self.headCtrl)
        self.jawCtrl = Control('jaw', parent=self.jawCtrlSpace, shape="cube")
        self.jawCtrl.lockTranslation(x=True, y=True, z=True)
        self.jawCtrl.lockScale(x=True, y=True, z=True)
        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)

        # ==============
        # Constrain I/O
        # ==============
        self.headToAimConstraint = PoseConstraint('_'.join(
            [self.headCtrlSpace.getName(), 'To',
             self.headAim.getName()]))
        self.headToAimConstraint.setMaintainOffset(True)
        self.headToAimConstraint.addConstrainer(self.headAim)
        self.headCtrlSpace.addConstraint(self.headToAimConstraint)

        # Constraint inputs
        self.headAimInputConstraint = PoseConstraint('_'.join([
            self.headAimCtrlSpace.getName(), 'To',
            self.headBaseInputTgt.getName()
        ]))
        self.headAimInputConstraint.setMaintainOffset(True)
        self.headAimInputConstraint.addConstrainer(self.headBaseInputTgt)
        self.headAimCtrlSpace.addConstraint(self.headAimInputConstraint)

        # # 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)

        # ===============
        # Add Splice Ops
        # ===============

        # Add Aim Splice Op
        # =================
        self.headAimSpliceOp = SpliceOperator('headAimSpliceOp',
                                              'DirectionConstraintSolver',
                                              'Kraken')
        self.addOperator(self.headAimSpliceOp)

        # Add Att Inputs
        self.headAimSpliceOp.setInput('drawDebug', self.drawDebugInputAttr)
        self.headAimSpliceOp.setInput('rigScale', self.rigScaleInputAttr)

        # Add Xfo Inputs
        self.headAimSpliceOp.setInput('position', self.headBaseInputTgt)
        self.headAimSpliceOp.setInput('upVector', self.headAimUpV)
        self.headAimSpliceOp.setInput('atVector', self.headAimCtrl)

        # Add Xfo Outputs
        self.headAimSpliceOp.setOutput('constrainee', self.headAim)

        # Add Deformer Splice Op
        # ======================
        self.deformersToOutputsSpliceOp = SpliceOperator(
            'headDeformerSpliceOp',
            'MultiPoseConstraintSolver',
            'Kraken',
            alwaysEval=True)
        self.addOperator(self.deformersToOutputsSpliceOp)

        # Add Att Inputs
        self.deformersToOutputsSpliceOp.setInput('drawDebug',
                                                 self.drawDebugInputAttr)
        self.deformersToOutputsSpliceOp.setInput('rigScale',
                                                 self.rigScaleInputAttr)

        # Add Xfo Outputs
        self.deformersToOutputsSpliceOp.setInput(
            'constrainers', [self.headOutputTgt, self.jawOutputTgt])

        # Add Xfo Outputs
        self.deformersToOutputsSpliceOp.setOutput('constrainees',
                                                  [headDef, jawDef])

        Profiler.getInstance().pop()
Example #30
0
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()
Example #31
0
    def __init__(self, name="spine", parent=None):

        Profiler.getInstance().push("Construct Spine Rig Component:" + name)
        super(SpineComponentRig, self).__init__(name, parent)

        # =========
        # Controls
        # =========
        # COG
        self.cogCtrlSpace = CtrlSpace('cog', parent=self.ctrlCmpGrp)
        self.cogCtrl = Control('cog', parent=self.cogCtrlSpace, shape="circle")
        self.cogCtrl.scalePoints(Vec3(6.0, 6.0, 6.0))
        self.cogCtrl.setColor("orange")

        # Spine01
        self.spine01CtrlSpace = CtrlSpace('spine01', parent=self.cogCtrl)
        self.spine01Ctrl = Control('spine01',
                                   parent=self.spine01CtrlSpace,
                                   shape="circle")
        self.spine01Ctrl.scalePoints(Vec3(4.0, 4.0, 4.0))

        # Spine02
        self.spine02CtrlSpace = CtrlSpace('spine02', parent=self.spine01Ctrl)
        self.spine02Ctrl = Control('spine02',
                                   parent=self.spine02CtrlSpace,
                                   shape="circle")
        self.spine02Ctrl.scalePoints(Vec3(4.5, 4.5, 4.5))

        # Spine03
        self.spine03CtrlSpace = CtrlSpace('spine03', parent=self.spine02Ctrl)
        self.spine03Ctrl = Control('spine03',
                                   parent=self.spine03CtrlSpace,
                                   shape="circle")
        self.spine03Ctrl.scalePoints(Vec3(4.5, 4.5, 4.5))
        self.spine03Ctrl.setColor("blue")

        # Spine04
        self.spine04CtrlSpace = CtrlSpace('spine04', parent=self.cogCtrl)
        self.spine04Ctrl = Control('spine04',
                                   parent=self.spine04CtrlSpace,
                                   shape="circle")
        self.spine04Ctrl.scalePoints(Vec3(6.0, 6.0, 6.0))

        # Pelvis
        self.pelvisCtrlSpace = CtrlSpace('pelvis', parent=self.cogCtrl)
        self.pelvisCtrl = Control('pelvis',
                                  parent=self.pelvisCtrlSpace,
                                  shape="cube")
        self.pelvisCtrl.alignOnYAxis(negative=True)
        self.pelvisCtrl.scalePoints(Vec3(2.0, 1.5, 1.5))

        # ==========
        # Deformers
        # ==========
        deformersLayer = self.getOrCreateLayer('deformers')
        self.defCmpGrp = ComponentGroup(self.getName(),
                                        self,
                                        parent=deformersLayer)
        self.deformerJoints = []
        self.spineOutputs = []
        self.setNumDeformers(1)

        pelvisDef = Joint('pelvis', parent=self.defCmpGrp)
        pelvisDef.setComponent(self)

        # =====================
        # Create Component I/O
        # =====================
        # Setup component Xfo I/O's
        self.spineVertebraeOutput.setTarget(self.spineOutputs)

        # ==============
        # Constrain I/O
        # ==============
        # Constraint inputs
        self.spineSrtInputConstraint = PoseConstraint('_'.join([
            self.cogCtrlSpace.getName(), 'To',
            self.spineMainSrtInputTgt.getName()
        ]))
        self.spineSrtInputConstraint.addConstrainer(self.spineMainSrtInputTgt)
        self.spineSrtInputConstraint.setMaintainOffset(True)
        self.cogCtrlSpace.addConstraint(self.spineSrtInputConstraint)

        # Constraint outputs
        self.spineCogOutputConstraint = PoseConstraint('_'.join(
            [self.spineCogOutputTgt.getName(), 'To',
             self.cogCtrl.getName()]))
        self.spineCogOutputConstraint.addConstrainer(self.cogCtrl)
        self.spineCogOutputTgt.addConstraint(self.spineCogOutputConstraint)

        self.spineBaseOutputConstraint = PoseConstraint('_'.join(
            [self.spineBaseOutputTgt.getName(), 'To', 'spineBase']))
        self.spineBaseOutputConstraint.addConstrainer(self.spineOutputs[0])
        self.spineBaseOutputTgt.addConstraint(self.spineBaseOutputConstraint)

        self.pelvisOutputConstraint = PoseConstraint('_'.join(
            [self.pelvisOutputTgt.getName(), 'To',
             self.pelvisCtrl.getName()]))
        self.pelvisOutputConstraint.addConstrainer(self.pelvisCtrl)
        self.pelvisOutputTgt.addConstraint(self.pelvisOutputConstraint)

        self.spineEndOutputConstraint = PoseConstraint('_'.join(
            [self.spineEndOutputTgt.getName(), 'To', 'spineEnd']))
        self.spineEndOutputConstraint.addConstrainer(self.spineOutputs[0])
        self.spineEndOutputTgt.addConstraint(self.spineEndOutputConstraint)

        # ===============
        # Add Splice Ops
        # ===============
        # Add Spine Splice Op
        self.bezierSpineSpliceOp = SpliceOperator('spineSpliceOp',
                                                  'BezierSpineSolver',
                                                  'Kraken')
        self.addOperator(self.bezierSpineSpliceOp)

        # Add Att Inputs
        self.bezierSpineSpliceOp.setInput('drawDebug', self.drawDebugInputAttr)
        self.bezierSpineSpliceOp.setInput('rigScale', self.rigScaleInputAttr)
        self.bezierSpineSpliceOp.setInput('length', self.lengthInputAttr)

        # Add Xfo Inputs
        self.bezierSpineSpliceOp.setInput('base', self.spine01Ctrl)
        self.bezierSpineSpliceOp.setInput('baseHandle', self.spine02Ctrl)
        self.bezierSpineSpliceOp.setInput('tipHandle', self.spine03Ctrl)
        self.bezierSpineSpliceOp.setInput('tip', self.spine04Ctrl)

        # Add Xfo Outputs
        self.bezierSpineSpliceOp.setOutput('outputs', self.spineOutputs)

        # Add Deformer Splice Op
        self.deformersToOutputsSpliceOp = SpliceOperator(
            'spineDeformerSpliceOp', 'MultiPoseConstraintSolver', 'Kraken')
        self.addOperator(self.deformersToOutputsSpliceOp)

        # Add Att Inputs
        self.deformersToOutputsSpliceOp.setInput('drawDebug',
                                                 self.drawDebugInputAttr)
        self.deformersToOutputsSpliceOp.setInput('rigScale',
                                                 self.rigScaleInputAttr)

        # Add Xfo Outputs
        self.deformersToOutputsSpliceOp.setInput('constrainers',
                                                 self.spineOutputs)

        # Add Xfo Outputs
        self.deformersToOutputsSpliceOp.setOutput('constrainees',
                                                  self.deformerJoints)

        # Add Pelvis Splice Op
        self.pelvisDefSpliceOp = SpliceOperator('pelvisDeformerSpliceOp',
                                                'PoseConstraintSolver',
                                                'Kraken')
        self.addOperator(self.pelvisDefSpliceOp)

        # Add Att Inputs
        self.pelvisDefSpliceOp.setInput('drawDebug', self.drawDebugInputAttr)
        self.pelvisDefSpliceOp.setInput('rigScale', self.rigScaleInputAttr)

        # Add Xfo Inputs
        self.pelvisDefSpliceOp.setInput('constrainer', self.pelvisOutputTgt)

        # Add Xfo Outputs
        self.pelvisDefSpliceOp.setOutput('constrainee', pelvisDef)

        Profiler.getInstance().pop()
Example #32
0
    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()
Example #33
0
    def __init__(self, name='FKChain', parent=None):

        Profiler.getInstance().push("Construct FK Chain Rig Component:" + name)
        super(FKChainComponentRig, self).__init__(name, parent)

        # =========
        # Controls
        # =========
        # FK
        self.fkCtrlSpaces = []
        self.fkCtrls = []
        self.setNumControls(4)

        # Add Component Params to IK control
        legSettingsAttrGrp = AttributeGroup("DisplayInfo_ChainSettings",
                                            parent=self.fkCtrls[0])
        legdrawDebugInputAttr = BoolAttribute('drawDebug',
                                              value=False,
                                              parent=legSettingsAttrGrp)

        # Connect IO to controls
        self.drawDebugInputAttr.connect(legdrawDebugInputAttr)

        # ==========
        # 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
        rootInputConstraint = PoseConstraint('_'.join([
            self.fkCtrlSpaces[0].getName(), 'To',
            self.rootInputTgt.getName()
        ]))
        rootInputConstraint.setMaintainOffset(True)
        rootInputConstraint.addConstrainer(self.rootInputTgt)
        self.fkCtrlSpaces[0].addConstraint(rootInputConstraint)

        # ===============
        # Add Splice Ops
        # ===============
        # Add Output Splice Op
        self.outputsToControlsSpliceOp = SpliceOperator(
            'fkChainOutputSpliceOp', 'MultiPoseConstraintSolver', 'Kraken')
        self.addOperator(self.outputsToControlsSpliceOp)

        # Add Att Inputs
        self.outputsToControlsSpliceOp.setInput('drawDebug',
                                                self.drawDebugInputAttr)
        self.outputsToControlsSpliceOp.setInput('rigScale',
                                                self.rigScaleInputAttr)

        # Add Xfo Inputs
        self.outputsToControlsSpliceOp.setInput('constrainers', self.fkCtrls)

        # Add Xfo Outputs
        self.outputsToControlsSpliceOp.setOutput('constrainees',
                                                 self.boneOutputsTgt)

        # Add Deformer Splice Op
        self.deformersToOutputsSpliceOp = SpliceOperator(
            'fkChainDeformerSpliceOp', 'MultiPoseConstraintSolver', 'Kraken')
        self.addOperator(self.deformersToOutputsSpliceOp)

        # Add Att Inputs
        self.deformersToOutputsSpliceOp.setInput('drawDebug',
                                                 self.drawDebugInputAttr)
        self.deformersToOutputsSpliceOp.setInput('rigScale',
                                                 self.rigScaleInputAttr)

        # Add Xfo Inputs
        self.deformersToOutputsSpliceOp.setInput('constrainers',
                                                 self.boneOutputsTgt)

        # Add Xfo Outputs
        self.deformersToOutputsSpliceOp.setOutput('constrainees',
                                                  self.deformerJoints)

        Profiler.getInstance().pop()
Example #34
0
class FKChainComponentRig(FKChainComponent):
    """FK Chain Leg Rig"""

    def __init__(self, name='FKChain', parent=None):

        Profiler.getInstance().push("Construct FK Chain Rig Component:" + name)
        super(FKChainComponentRig, self).__init__(name, parent)


        # =========
        # Controls
        # =========
        # FK
        self.fkCtrlSpaces = []
        self.fkCtrls = []
        self.setNumControls(4)

        # Add Component Params to IK control
        legSettingsAttrGrp = AttributeGroup("DisplayInfo_ChainSettings", parent=self.fkCtrls[0])
        legdrawDebugInputAttr = BoolAttribute('drawDebug', value=False, parent=legSettingsAttrGrp)

        # Connect IO to controls
        self.drawDebugInputAttr.connect(legdrawDebugInputAttr)

        # ==========
        # 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
        rootInputConstraint = PoseConstraint('_'.join([self.fkCtrlSpaces[0].getName(), 'To', self.rootInputTgt.getName()]))
        rootInputConstraint.setMaintainOffset(True)
        rootInputConstraint.addConstrainer(self.rootInputTgt)
        self.fkCtrlSpaces[0].addConstraint(rootInputConstraint)


        # ===============
        # Add Splice Ops
        # ===============
        # Add Output Splice Op
        self.outputsToControlsSpliceOp = SpliceOperator('fkChainOutputSpliceOp', 'MultiPoseConstraintSolver', 'Kraken')
        self.addOperator(self.outputsToControlsSpliceOp)

        # Add Att Inputs
        self.outputsToControlsSpliceOp.setInput('drawDebug', self.drawDebugInputAttr)
        self.outputsToControlsSpliceOp.setInput('rigScale', self.rigScaleInputAttr)

        # Add Xfo Inputs
        self.outputsToControlsSpliceOp.setInput('constrainers', self.fkCtrls)

        # Add Xfo Outputs
        self.outputsToControlsSpliceOp.setOutput('constrainees', self.boneOutputsTgt)

        # Add Deformer Splice Op
        self.deformersToOutputsSpliceOp = SpliceOperator('fkChainDeformerSpliceOp', 'MultiPoseConstraintSolver', 'Kraken')
        self.addOperator(self.deformersToOutputsSpliceOp)

        # Add Att Inputs
        self.deformersToOutputsSpliceOp.setInput('drawDebug', self.drawDebugInputAttr)
        self.deformersToOutputsSpliceOp.setInput('rigScale', self.rigScaleInputAttr)

        # Add Xfo Inputs
        self.deformersToOutputsSpliceOp.setInput('constrainers', self.boneOutputsTgt)

        # Add Xfo Outputs
        self.deformersToOutputsSpliceOp.setOutput('constrainees', self.deformerJoints)

        Profiler.getInstance().pop()


    def setNumControls(self, numControls):

        # Add more controls
        if numControls > len(self.fkCtrlSpaces):
            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'
                boneFKCtrlSpace = CtrlSpace(boneName, parent=parent)

                boneFKCtrl = Control(boneName, parent=boneFKCtrlSpace, shape="cube")
                boneFKCtrl.alignOnXAxis()
                boneFKCtrl.lockScale(x=True, y=True, z=True)
                boneFKCtrl.lockTranslation(x=True, y=True, z=True)

                self.fkCtrlSpaces.append(boneFKCtrlSpace)
                self.fkCtrls.append(boneFKCtrl)

        # Remove extra ctrls
        elif numControls < len(self.fkCtrlSpaces):
            numExtraCtrls = len(self.fkCtrls) - numControls
            for i in xrange(numExtraCtrls):
                extraCtrlSpace = self.fkCtrlSpaces.pop()
                extraCtrl = self.fkCtrls.pop()
                extraCtrlSpace.getParent().removeChild(extraCtrlSpace)
                extraCtrl.getParent().removeChild(extraCtrl)


    def setNumDeformers(self, numDeformers):

        # Add more deformers and outputs
        if numDeformers > len(self.boneOutputsTgt):
            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)

                boneDef = Joint(name, parent=self.defCmpGrp)
                boneDef.setComponent(self)
                self.deformerJoints.append(boneDef)

        # Remove extra deformers and outputs
        elif numDeformers < len(self.boneOutputsTgt):
            numExtraOutputs = len(self.boneOutputsTgt) - numDeformers
            numExtraDefs = len(self.deformerJoints) - numDeformers

            for i in xrange(numExtraOutputs):
                extraOutput = self.boneOutputsTgt.pop()
                extraDef = self.deformerJoints.pop()

                extraOutput.getParent().removeChild(extraOutput)
                extraDef.getParent().removeChild(extraDef)

        return True


    def loadData(self, data=None):
        """Load a saved guide representation from persisted data.

        Arguments:
        data -- object, The JSON data object.

        Return:
        True if successful.

        """

        super(FKChainComponentRig, self).loadData( data )

        boneXfos = data['boneXfos']
        boneLengths = data['boneLengths']
        numJoints = data['numJoints']

        # Add extra controls and outputs
        self.setNumControls(numJoints)
        self.setNumDeformers(numJoints)

        for i in xrange(numJoints):
            self.fkCtrlSpaces[i].xfo = boneXfos[i]
            self.fkCtrls[i].xfo = boneXfos[i]
            self.fkCtrls[i].scalePoints(Vec3(boneLengths[i], boneLengths[i] * 0.45, boneLengths[i] * 0.45))

        # ============
        # Set IO Xfos
        # ============
        self.rootInputTgt.xfo = boneXfos[0]

        for i in xrange(numJoints):
            self.boneOutputsTgt[i].xfo = boneXfos[i]

        self.chainEndXfoOutputTgt.xfo = data['endXfo']
        self.chainEndPosOutputTgt.xfo = data['endXfo']

        # =============
        # Set IO Attrs
        # =============

        # ====================
        # Evaluate Splice Ops
        # ====================
        # Eval Outputs to Controls Op to evaulate with new outputs and controls
        self.outputsToControlsSpliceOp.evaluate()

        # evaluate the output splice op to evaluate with new outputs and deformers
        self.deformersToOutputsSpliceOp.evaluate()