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 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
Exemple #3
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 = KLOperator('clavicleDeformerKLOp', '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()
Exemple #4
0
    def __init__(self, name='Hand', parent=None):

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

        # =========
        # Controls
        # =========
        # Hand
        self.handCtrlSpace = CtrlSpace('hand', parent=self.ctrlCmpGrp)
        self.handCtrl = Control('hand',
                                parent=self.handCtrlSpace,
                                shape="square")
        self.handCtrl.rotatePoints(0, 0, 90.0)
        self.handCtrl.lockScale(True, True, True)
        self.handCtrl.lockTranslation(True, True, True)

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

        self.handDef = Joint('hand', parent=self.defCmpGrp)
        self.handDef.setComponent(self)

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

        # Constraint outputs
        self.handOutputConstraint = PoseConstraint('_'.join(
            [self.handOutputTgt.getName(), 'To',
             self.handCtrl.getName()]))
        self.handOutputConstraint.addConstrainer(self.handCtrl)
        self.handOutputTgt.addConstraint(self.handOutputConstraint)

        # Constraint deformers
        self.handDefConstraint = PoseConstraint('_'.join(
            [self.handDef.getName(), 'To',
             self.handCtrl.getName()]))
        self.handDefConstraint.addConstrainer(self.handCtrl)
        self.handDef.addConstraint(self.handDefConstraint)

        Profiler.getInstance().pop()
Exemple #5
0
    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 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
Exemple #7
0
    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
Exemple #8
0
    def setNumLowDeformers(self, numLowDeformers):

        # Add Low Deformers and Outputs
        for i in xrange(len(self.eyelidLowOutputs), numLowDeformers):
            name = 'Lid_Low_' + str(i + 1).zfill(2)
            lidLowOutputs = ComponentOutput(name, parent=self.outputHrcGrp)
            self.eyelidLowOutputs.append(lidLowOutputs)

        for i in xrange(len(self.eyelidLowDef), numLowDeformers):
            name = 'Lid_Low_' + str(i + 1).zfill(2)
            lidLowDef = Joint(name, parent=self.defCmpGrp)
            lidLowDef.setComponent(self)
            self.eyelidLowDef.append(lidLowDef)

        return True
Exemple #9
0
    def addFinger(self, name, data):

        fingerCtrls = []
        fingerJoints = []

        parentCtrl = self.handCtrl
        for i, joint in enumerate(data):
            if i == 0:
                jointName = name + 'Meta'
            else:
                jointName = name + str(i).zfill(2)

            jointXfo = joint.get('xfo', Xfo())
            jointCrvData = joint.get('curveData')

            # Create Controls
            newJointCtrlSpace = CtrlSpace(jointName, parent=parentCtrl)
            newJointCtrl = Control(jointName,
                                   parent=newJointCtrlSpace,
                                   shape='square')
            newJointCtrl.lockScale(True, True, True)
            newJointCtrl.lockTranslation(True, True, True)

            if jointCrvData is not None:
                newJointCtrl.setCurveData(jointCrvData)

            fingerCtrls.append(newJointCtrl)

            # Create Deformers
            jointDef = Joint(jointName, parent=self.defCmpGrp)
            fingerJoints.append(jointDef)

            # Create Constraints

            # Set Xfos
            newJointCtrlSpace.xfo = jointXfo
            newJointCtrl.xfo = jointXfo

            parentCtrl = newJointCtrl

        # =================
        # Create Operators
        # =================
        # Add Deformer KL Op
        deformersToCtrlsKLOp = KLOperator(name + 'DeformerKLOp',
                                          'MultiPoseConstraintSolver',
                                          'Kraken')
        self.addOperator(deformersToCtrlsKLOp)

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

        # Add Xfo Inputs
        deformersToCtrlsKLOp.setInput('constrainers', fingerCtrls)

        # Add Xfo Outputs
        deformersToCtrlsKLOp.setOutput('constrainees', fingerJoints)

        return deformersToCtrlsKLOp
Exemple #10
0
    def __init__(self, name='Hand', parent=None):

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


        # =========
        # Controls
        # =========
        # Hand
        self.handCtrlSpace = CtrlSpace('hand', parent=self.ctrlCmpGrp)
        self.handCtrl = Control('hand', parent=self.handCtrlSpace, shape="square")
        self.handCtrl.rotatePoints(0, 0, 90.0)
        self.handCtrl.lockScale(True, True, True)
        self.handCtrl.lockTranslation(True, True, True)


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

        self.handDef = Joint('hand', parent=self.defCmpGrp)
        self.handDef.setComponent(self)


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

        # Constraint outputs
        self.handOutputConstraint = PoseConstraint('_'.join([self.handOutputTgt.getName(), 'To', self.handCtrl.getName()]))
        self.handOutputConstraint.addConstrainer(self.handCtrl)
        self.handOutputTgt.addConstraint(self.handOutputConstraint)

        # Constraint deformers
        self.handDefConstraint = PoseConstraint('_'.join([self.handDef.getName(), 'To', self.handCtrl.getName()]))
        self.handDefConstraint.addConstrainer(self.handCtrl)
        self.handDef.addConstraint(self.handDefConstraint)

        Profiler.getInstance().pop()
Exemple #11
0
    def __init__(self, name='mjEyelid', parent=None):
        Profiler.getInstance().push("Construct Eyelid Rig Component:" + name)
        super(mjEyelidComponentRig, self).__init__(name, parent)

        # =========
        # Controls // Get the Guide Xfos data and create the final controllers, offset them if needed.
        # =========

        # Inputs
        self.eyelidCtrlSpace = CtrlSpace('eyelid', parent=self.ctrlCmpGrp)

        self.eyeballLocator = Locator('eyeball', parent=self.ctrlCmpGrp)
        self.eyeballLocator.setShapeVisibility(False)

        self.eyelidUpVLocator = Locator('eyelid_Upv',
                                        parent=self.eyelidCtrlSpace)
        self.eyelidUpVLocator.setShapeVisibility(False)

        # Lid Sides
        self.lidMedialLocator = Locator('lid_Medial',
                                        parent=self.eyelidCtrlSpace)
        self.lidMedialLocator.setShapeVisibility(False)

        self.lidLateralLocator = Locator('lid_Lateral',
                                         parent=self.eyelidCtrlSpace)
        self.lidLateralLocator.setShapeVisibility(False)

        # Lid Upper
        self.lidUpCtrlSpace = CtrlSpace('lid_Up', parent=self.eyelidCtrlSpace)
        self.lidUpCtrl = Control('lid_Up',
                                 parent=self.lidUpCtrlSpace,
                                 shape="cube")
        self.lidUpCtrl.scalePoints(Vec3(0.05, 0.05, 0.05))
        self.lidUpCtrl.lockTranslation(x=True, y=False, z=True)
        self.lidUpCtrl.setColor("yellow")

        self.lipUpMedialLocator = Locator('lid_Up_Medial',
                                          parent=self.eyelidCtrlSpace)
        self.lipUpMedialLocator.setShapeVisibility(False)
        self.lipUpLateralLocator = Locator('lid_Up_Lateral',
                                           parent=self.eyelidCtrlSpace)
        self.lipUpLateralLocator.setShapeVisibility(False)

        # Lid Lower
        self.lidLowCtrlSpace = CtrlSpace('lid_Low',
                                         parent=self.eyelidCtrlSpace)
        self.lidLowCtrl = Control('lid_Low',
                                  parent=self.lidLowCtrlSpace,
                                  shape="cube")
        self.lidLowCtrl.scalePoints(Vec3(0.05, 0.05, 0.05))
        self.lidLowCtrl.lockTranslation(x=True, y=False, z=True)
        self.lidLowCtrl.setColor("yellow")

        self.lidLowMedialLocator = Locator('lid_Low_Medial',
                                           parent=self.eyelidCtrlSpace)
        self.lidLowMedialLocator.setShapeVisibility(False)
        self.lidLowLateralLocator = Locator('lid_Low_Lateral',
                                            parent=self.eyelidCtrlSpace)
        self.lidLowLateralLocator.setShapeVisibility(False)

        # Lid Attributes
        lidUp_AttrGrp = AttributeGroup("Eyelid_Settings",
                                       parent=self.lidUpCtrl)
        lidLow_AttrGrp = AttributeGroup("Eyelid_Settings",
                                        parent=self.lidLowCtrl)

        self.lidUp_OffsetInputAttr = BoolAttribute('Eyeball_Offset',
                                                   value=True,
                                                   parent=lidUp_AttrGrp)
        self.lidUp_FollowFactorInputAttr = ScalarAttribute(
            'Eyeball_Follow_Factor', value=1.0, parent=lidUp_AttrGrp)
        self.lidUp_DebugInputAttr = BoolAttribute('DrawDebug',
                                                  value=False,
                                                  parent=lidUp_AttrGrp)
        self.lidUp_MedialBlinkInputAttr = ScalarAttribute(
            'Medial_Blink_Factor', value=0.25, parent=lidUp_AttrGrp)
        self.lidUp_LateralBlinkInputAttr = ScalarAttribute(
            'Lateral_Blink_Factor', value=0.65, parent=lidUp_AttrGrp)
        self.lidUp_DefCountInputAttr = IntegerAttribute('numDeformers',
                                                        value=10,
                                                        parent=lidUp_AttrGrp)

        self.lidLow_OffsetInputAttr = BoolAttribute('Eyeball_Offset',
                                                    value=True,
                                                    parent=lidLow_AttrGrp)
        self.lidLow_FollowFactorInputAttr = ScalarAttribute(
            'Eyeball_Follow_Factor', value=0.8, parent=lidLow_AttrGrp)
        self.lidLow_DebugInputAttr = BoolAttribute('DrawDebug',
                                                   value=False,
                                                   parent=lidLow_AttrGrp)
        self.lidLow_MedialBlinkInputAttr = ScalarAttribute(
            'Medial_Blink_Factor', value=0.25, parent=lidLow_AttrGrp)
        self.lidLow_LateralBlinkInputAttr = ScalarAttribute(
            'Lateral_Blink_Factor', value=0.65, parent=lidLow_AttrGrp)
        self.lidLow_DefCountInputAttr = IntegerAttribute('numDeformers',
                                                         value=10,
                                                         parent=lidLow_AttrGrp)

        self.lidUp_DebugInputAttr.connect(self.drawDebugInputAttr)
        self.lidLow_DebugInputAttr.connect(self.drawDebugInputAttr)
        self.lidUp_DefCountInputAttr.connect(self.numUpDeformersInputAttr)
        self.lidLow_DefCountInputAttr.connect(self.numLowDeformersInputAttr)

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

        # Lid Sides
        lidMedialDef = Joint('lid_Medial', parent=self.defCmpGrp)
        lidMedialDef.setComponent(self)

        lidLateralDef = Joint('lid_Lateral', parent=self.defCmpGrp)
        lidLateralDef.setComponent(self)

        # Lid Up
        self.eyelidUpDef = []
        self.eyelidUpOutputs = []
        self.setNumUpDeformers(1)

        # Lid Low
        self.eyelidLowDef = []
        self.eyelidLowOutputs = []
        self.setNumLowDeformers(1)

        # =====================
        # Create Component I/O
        # =====================
        # Setup component Xfo I/O's
        self.eyelidUpOutput.setTarget(self.eyelidUpOutputs)
        self.eyelidLowOutput.setTarget(self.eyelidLowOutputs)

        # ==============
        # Constrain I/O
        # ==============
        # Constraint inputs
        self.headInputConstraint = PoseConstraint('_'.join([
            self.eyelidCtrlSpace.getName(), 'To',
            self.headInputTgt.getName()
        ]))
        self.headInputConstraint.addConstrainer(self.headInputTgt)
        self.eyelidCtrlSpace.addConstraint(self.headInputConstraint)

        self.eyeballInputConstraint = PoseConstraint('_'.join([
            self.eyeballLocator.getName(), 'To',
            self.eyeballInputTgt.getName()
        ]))
        self.eyeballInputConstraint.setMaintainOffset(True)
        self.eyeballInputConstraint.addConstrainer(self.eyeballInputTgt)
        self.eyeballLocator.addConstraint(self.eyeballInputConstraint)

        # ===============
        # Add Splice Ops
        # ===============
        # Add MultiPoseConstraint Joints Splice Op
        self.outputsToDeformersKLOp = KLOperator('Canvas_Eyelid_Side_Op',
                                                 'MultiPoseConstraintSolver',
                                                 'Kraken')
        self.addOperator(self.outputsToDeformersKLOp)
        # Add Att Inputs
        self.outputsToDeformersKLOp.setInput('drawDebug',
                                             self.drawDebugInputAttr)
        self.outputsToDeformersKLOp.setInput('rigScale',
                                             self.rigScaleInputAttr)
        # Add Xfo Inputs
        self.outputsToDeformersKLOp.setInput('constrainers', [
            self.lidMedialLocator,
            self.lidLateralLocator,
        ])
        # Add Xfo Outputs
        self.outputsToDeformersKLOp.setOutput('constrainees', [
            lidMedialDef,
            lidLateralDef,
        ])

        # Add Lid Up Canvas Op
        self.lidUpCanvasOp = CanvasOperator(
            'Canvas_Eyelid_Up_Op', 'MJCG.Solvers.mjEyelidConstraintSolver')
        self.addOperator(self.lidUpCanvasOp)

        # Add Attributes Inputs
        self.lidUpCanvasOp.setInput('drawDebug', self.lidUp_DebugInputAttr)
        self.lidUpCanvasOp.setInput('rigScale', self.rigScaleInputAttr)
        self.lidUpCanvasOp.setInput('Eyeball_Offset',
                                    self.lidUp_OffsetInputAttr)
        self.lidUpCanvasOp.setInput('Eyeball_Follow_Factor',
                                    self.lidUp_FollowFactorInputAttr)
        self.lidUpCanvasOp.setInput('Medial_Blink_Factor',
                                    self.lidUp_MedialBlinkInputAttr)
        self.lidUpCanvasOp.setInput('Lateral_Blink_Factor',
                                    self.lidUp_LateralBlinkInputAttr)
        self.lidUpCanvasOp.setInput('Deformer_Count',
                                    self.lidUp_DefCountInputAttr)

        # Add Xfo Inputs
        self.lidUpCanvasOp.setInput('Eye_Center', self.eyeballLocator)
        self.lidUpCanvasOp.setInput('Lid_Global', self.eyelidCtrlSpace)
        self.lidUpCanvasOp.setInput('Lid_UpV', self.eyelidUpVLocator)
        self.lidUpCanvasOp.setInput('Lid_Medial', self.lidMedialLocator)
        self.lidUpCanvasOp.setInput('Lid_MedialCen', self.lipUpMedialLocator)
        self.lidUpCanvasOp.setInput('Lid_Center_Ref', self.lidUpCtrlSpace)
        self.lidUpCanvasOp.setInput('Lid_Center_Ctrl', self.lidUpCtrl)
        self.lidUpCanvasOp.setInput('Lid_LateralCen', self.lipUpLateralLocator)
        self.lidUpCanvasOp.setInput('Lid_Lateral', self.lidLateralLocator)
        #Add Xfo Outputs
        self.lidUpCanvasOp.setOutput('result', self.eyelidUpDef)

        # Add Lid Low Canvas Op
        self.lidLowCanvasOp = CanvasOperator(
            'Canvas_Eyelid_Low_Op', 'MJCG.Solvers.mjEyelidConstraintSolver')
        self.addOperator(self.lidLowCanvasOp)

        # Add Attributes Inputs
        self.lidLowCanvasOp.setInput('drawDebug', self.lidLow_DebugInputAttr)
        self.lidLowCanvasOp.setInput('rigScale', self.rigScaleInputAttr)
        self.lidLowCanvasOp.setInput('Eyeball_Offset',
                                     self.lidLow_OffsetInputAttr)
        self.lidLowCanvasOp.setInput('Eyeball_Follow_Factor',
                                     self.lidLow_FollowFactorInputAttr)
        self.lidLowCanvasOp.setInput('Medial_Blink_Factor',
                                     self.lidLow_MedialBlinkInputAttr)
        self.lidLowCanvasOp.setInput('Lateral_Blink_Factor',
                                     self.lidLow_LateralBlinkInputAttr)
        self.lidLowCanvasOp.setInput('Deformer_Count',
                                     self.lidLow_DefCountInputAttr)

        # Add Xfo Inputs
        self.lidLowCanvasOp.setInput('Eye_Center', self.eyeballLocator)
        self.lidLowCanvasOp.setInput('Lid_Global', self.eyelidCtrlSpace)
        self.lidLowCanvasOp.setInput('Lid_UpV', self.eyelidUpVLocator)
        self.lidLowCanvasOp.setInput('Lid_Medial', self.lidMedialLocator)
        self.lidLowCanvasOp.setInput('Lid_MedialCen', self.lidLowMedialLocator)
        self.lidLowCanvasOp.setInput('Lid_Center_Ref', self.lidLowCtrlSpace)
        self.lidLowCanvasOp.setInput('Lid_Center_Ctrl', self.lidLowCtrl)
        self.lidLowCanvasOp.setInput('Lid_LateralCen',
                                     self.lidLowLateralLocator)
        self.lidLowCanvasOp.setInput('Lid_Lateral', self.lidLateralLocator)

        #Add Xfo Outputs
        self.lidLowCanvasOp.setOutput('result', self.eyelidLowDef)

        Profiler.getInstance().pop()
Exemple #12
0
class HandComponentRig(HandComponent):
    """Hand Component"""

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

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


        # =========
        # Controls
        # =========
        # Hand
        self.handCtrlSpace = CtrlSpace('hand', parent=self.ctrlCmpGrp)
        self.handCtrl = Control('hand', parent=self.handCtrlSpace, shape="square")
        self.handCtrl.rotatePoints(0, 0, 90.0)
        self.handCtrl.lockScale(True, True, True)
        self.handCtrl.lockTranslation(True, True, True)


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

        self.handDef = Joint('hand', parent=self.defCmpGrp)
        self.handDef.setComponent(self)


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

        # Constraint outputs
        self.handOutputConstraint = PoseConstraint('_'.join([self.handOutputTgt.getName(), 'To', self.handCtrl.getName()]))
        self.handOutputConstraint.addConstrainer(self.handCtrl)
        self.handOutputTgt.addConstraint(self.handOutputConstraint)

        # Constraint deformers
        self.handDefConstraint = PoseConstraint('_'.join([self.handDef.getName(), 'To', self.handCtrl.getName()]))
        self.handDefConstraint.addConstrainer(self.handCtrl)
        self.handDef.addConstraint(self.handDefConstraint)

        Profiler.getInstance().pop()


    def addFinger(self, name, data):

        fingerCtrls = []
        fingerJoints = []

        parentCtrl = self.handCtrl
        for i, joint in enumerate(data):
            if i == 0:
                jointName = name + 'Meta'
            else:
                jointName = name + str(i).zfill(2)

            jointXfo = joint.get('xfo', Xfo())
            jointCrvData = joint.get('curveData')

            # Create Controls
            newJointCtrlSpace = CtrlSpace(jointName, parent=parentCtrl)
            newJointCtrl = Control(jointName, parent=newJointCtrlSpace, shape='square')
            newJointCtrl.lockScale(True, True, True)
            newJointCtrl.lockTranslation(True, True, True)

            if jointCrvData is not None:
                newJointCtrl.setCurveData(jointCrvData)

            fingerCtrls.append(newJointCtrl)

            # Create Deformers
            jointDef = Joint(jointName, parent=self.defCmpGrp)
            fingerJoints.append(jointDef)

            # Create Constraints

            # Set Xfos
            newJointCtrlSpace.xfo = jointXfo
            newJointCtrl.xfo = jointXfo

            parentCtrl = newJointCtrl


        # =================
        # Create Operators
        # =================
        # Add Deformer KL Op
        deformersToCtrlsKLOp = KLOperator(name + 'DefConstraint', 'MultiPoseConstraintSolver', 'Kraken')
        self.addOperator(deformersToCtrlsKLOp)

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

        # Add Xfo Inputs
        deformersToCtrlsKLOp.setInput('constrainers', fingerCtrls)

        # Add Xfo Outputs
        deformersToCtrlsKLOp.setOutput('constrainees', fingerJoints)

        return deformersToCtrlsKLOp


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

        # Data
        fingerData = data.get('fingerData')
        handXfo = data.get('handXfo', Xfo())

        self.handCtrlSpace.xfo = handXfo
        self.handCtrl.xfo = handXfo

        fingerOps = []
        for finger in fingerData.keys():
            fingerOp = self.addFinger(finger, fingerData[finger])
            fingerOps.append(fingerOp)

        # ============
        # Set IO Xfos
        # ============
        self.armEndInputTgt.xfo = handXfo
        self.handOutputTgt.xfo = handXfo

        # Eval Constraints
        self.armEndInputConstraint.evaluate()
        self.handOutputConstraint.evaluate()
        self.handDefConstraint.evaluate()

        # Eval Operators
        for op in fingerOps:
            op.evaluate()
Exemple #13
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()
    def __init__(self, name='limb', parent=None):

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

        # =========
        # Controls
        # =========
        # Upper (FK)
        self.upperFKCtrlSpace = CtrlSpace('upperFK', parent=self.ctrlCmpGrp)
        self.upperFKCtrl = Control('upperFK',
                                   parent=self.upperFKCtrlSpace,
                                   shape="cube")
        self.upperFKCtrl.alignOnXAxis()

        # Lower (FK)
        self.lowerFKCtrlSpace = CtrlSpace('lowerFK', parent=self.upperFKCtrl)
        self.lowerFKCtrl = Control('lowerFK',
                                   parent=self.lowerFKCtrlSpace,
                                   shape="cube")
        self.lowerFKCtrl.alignOnXAxis()

        # End (IK)
        self.limbIKCtrlSpace = CtrlSpace('IK', parent=self.ctrlCmpGrp)
        self.limbIKCtrl = Control('IK',
                                  parent=self.limbIKCtrlSpace,
                                  shape="pin")

        # Add Component Params to IK control
        # TODO: Move these separate control
        limbSettingsAttrGrp = AttributeGroup(
            "DisplayInfo_StretchyLimbSettings", parent=self.limbIKCtrl)
        limbDrawDebugInputAttr = BoolAttribute('drawDebug',
                                               value=False,
                                               parent=limbSettingsAttrGrp)
        self.limbBone0LenInputAttr = ScalarAttribute(
            'bone0Len', value=1.0, parent=limbSettingsAttrGrp)
        self.limbBone1LenInputAttr = ScalarAttribute(
            'bone1Len', value=1.0, parent=limbSettingsAttrGrp)
        limbIKBlendInputAttr = ScalarAttribute('ikblend',
                                               value=1.0,
                                               minValue=0.0,
                                               maxValue=1.0,
                                               parent=limbSettingsAttrGrp)
        limbSoftIKInputAttr = BoolAttribute('softIK',
                                            value=True,
                                            parent=limbSettingsAttrGrp)
        limbSoftRatioInputAttr = ScalarAttribute('softRatio',
                                                 value=0.0,
                                                 minValue=0.0,
                                                 maxValue=1.0,
                                                 parent=limbSettingsAttrGrp)
        limbStretchInputAttr = BoolAttribute('stretch',
                                             value=True,
                                             parent=limbSettingsAttrGrp)
        limbStretchBlendInputAttr = ScalarAttribute('stretchBlend',
                                                    value=0.0,
                                                    minValue=0.0,
                                                    maxValue=1.0,
                                                    parent=limbSettingsAttrGrp)
        limbSlideInputAttr = ScalarAttribute('slide',
                                             value=0.0,
                                             minValue=-1.0,
                                             maxValue=1.0,
                                             parent=limbSettingsAttrGrp)
        limbPinInputAttr = ScalarAttribute('pin',
                                           value=0.0,
                                           minValue=0.0,
                                           maxValue=1.0,
                                           parent=limbSettingsAttrGrp)
        self.rightSideInputAttr = BoolAttribute('rightSide',
                                                value=False,
                                                parent=limbSettingsAttrGrp)

        self.drawDebugInputAttr.connect(limbDrawDebugInputAttr)

        # UpV (IK Pole Vector)
        self.limbUpVCtrlSpace = CtrlSpace('UpV', parent=self.ctrlCmpGrp)
        self.limbUpVCtrl = Control('UpV',
                                   parent=self.limbUpVCtrlSpace,
                                   shape="triangle")
        self.limbUpVCtrl.alignOnZAxis()

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

        upperDef = Joint('upper', parent=self.defCmpGrp)
        upperDef.setComponent(self)

        lowerDef = Joint('lower', parent=self.defCmpGrp)
        lowerDef.setComponent(self)

        endDef = Joint('end', parent=self.defCmpGrp)
        endDef.setComponent(self)

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

        self.limbUpVCtrlSpaceInputConstraint = PoseConstraint('_'.join([
            self.limbUpVCtrlSpace.getName(), 'To',
            self.globalSRTInputTgt.getName()
        ]))
        self.limbUpVCtrlSpaceInputConstraint.setMaintainOffset(True)
        self.limbUpVCtrlSpaceInputConstraint.addConstrainer(
            self.globalSRTInputTgt)
        self.limbUpVCtrlSpace.addConstraint(
            self.limbUpVCtrlSpaceInputConstraint)

        self.limbRootInputConstraint = PoseConstraint('_'.join([
            self.limbIKCtrl.getName(), 'To',
            self.limbParentInputTgt.getName()
        ]))
        self.limbRootInputConstraint.setMaintainOffset(True)
        self.limbRootInputConstraint.addConstrainer(self.limbParentInputTgt)
        self.upperFKCtrlSpace.addConstraint(self.limbRootInputConstraint)

        # ===============
        # Add Splice Ops
        # ===============
        # Add StretchyLimb Splice Op
        self.limbIKKLOp = KLOperator('limbKLOp', 'TwoBoneStretchyIKSolver',
                                     'Kraken')
        self.addOperator(self.limbIKKLOp)

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

        self.limbIKKLOp.setInput('bone0Len', self.limbBone0LenInputAttr)
        self.limbIKKLOp.setInput('bone1Len', self.limbBone1LenInputAttr)
        self.limbIKKLOp.setInput('ikblend', limbIKBlendInputAttr)
        self.limbIKKLOp.setInput('softIK', limbSoftIKInputAttr)
        self.limbIKKLOp.setInput('softRatio', limbSoftRatioInputAttr)
        self.limbIKKLOp.setInput('stretch', limbStretchInputAttr)
        self.limbIKKLOp.setInput('stretchBlend', limbStretchBlendInputAttr)
        self.limbIKKLOp.setInput('slide', limbSlideInputAttr)
        self.limbIKKLOp.setInput('pin', limbPinInputAttr)
        self.limbIKKLOp.setInput('rightSide', self.rightSideInputAttr)

        # Add Xfo Inputs
        self.limbIKKLOp.setInput('root', self.limbParentInputTgt)
        self.limbIKKLOp.setInput('bone0FK', self.upperFKCtrl)
        self.limbIKKLOp.setInput('bone1FK', self.lowerFKCtrl)
        self.limbIKKLOp.setInput('ikHandle', self.limbIKCtrl)
        self.limbIKKLOp.setInput('upV', self.limbUpVCtrl)

        # Add Xfo Outputs
        self.limbIKKLOp.setOutput('bone0Out', self.limbUpperOutputTgt)
        self.limbIKKLOp.setOutput('bone1Out', self.limbLowerOutputTgt)
        self.limbIKKLOp.setOutput('bone2Out', self.limbEndOutputTgt)

        # =====================
        # Connect the deformers
        # =====================

        # Add StretchyLimb Deformer Splice Op
        self.outputsToDeformersKLOp = KLOperator('limbDeformerKLOp',
                                                 'MultiPoseConstraintSolver',
                                                 'Kraken')
        self.addOperator(self.outputsToDeformersKLOp)

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

        # Add Xfo Inputs
        self.outputsToDeformersKLOp.setInput('constrainers', [
            self.limbUpperOutputTgt, self.limbLowerOutputTgt,
            self.limbEndOutputTgt
        ])

        # Add Xfo Outputs
        self.outputsToDeformersKLOp.setOutput('constrainees',
                                              [upperDef, lowerDef, endDef])

        Profiler.getInstance().pop()
class SimpleControlComponentRig(SimpleControlComponent):
    """Simple Control Component Rig"""
    def __init__(self, name='SimpleControl', parent=None):

        Profiler.getInstance().push("Construct Simple Control Rig Component:" +
                                    name)
        super(SimpleControlComponentRig, self).__init__(name, parent)

        # =========
        # Controls
        # =========
        # Add Controls
        self.mainCtrl = Control('main', shape='square', parent=self.ctrlCmpGrp)
        self.mainCtrlSpace = self.mainCtrl.insertCtrlSpace()
        self.mainCtrl.lockScale(x=True, y=True, z=True)

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

        self.rigScaleOutputAttr.connect(self.rigScaleAttr)

        # ==========
        # Deformers
        # ==========
        deformersLayer = self.getOrCreateLayer('deformers')
        self.defCmpGrp = ComponentGroup(self.getName(),
                                        self,
                                        parent=deformersLayer)
        self.addItem('defCmpGrp', self.defCmpGrp)
        self.mainDef = Joint('main', parent=self.defCmpGrp)
        self.mainDef.setComponent(self)

        # ==============
        # Constrain I/O
        # ==============
        # Constrain inputs
        self.mainInputConstraint = PoseConstraint('_'.join(
            [self.mainCtrlSpace.getName(), 'To',
             self.mainInputTgt.getName()]))
        self.mainInputConstraint.setMaintainOffset(True)
        self.mainInputConstraint.addConstrainer(self.mainInputTgt)
        self.mainCtrlSpace.addConstraint(self.mainInputConstraint)

        # Constrain outputs
        self.mainOutputConstraint = PoseConstraint('_'.join(
            [self.outputTgt.getName(), 'To',
             self.mainCtrl.getName()]))
        self.mainOutputConstraint.addConstrainer(self.mainCtrl)
        self.outputTgt.addConstraint(self.mainOutputConstraint)

        # Constrain deformers
        self.mainDefConstraint = PoseConstraint('_'.join(
            [self.mainDef.getName(), 'To',
             self.mainCtrl.getName()]))
        self.mainDefConstraint.addConstrainer(self.mainCtrl)
        self.mainDef.addConstraint(self.mainDefConstraint)

        # ===============
        # Add Canvas Ops
        # ===============

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

        ctrlSize = data.get('ctrlSize', 1.0)
        ctrlXfo = data.get('ctrlXfo', Xfo())

        # ================
        # Resize Controls
        # ================
        self.mainCtrl.setShape('square')
        self.mainCtrl.rotatePoints(90, 0, 0)
        self.mainCtrl.scalePoints(Vec3(ctrlSize, ctrlSize, ctrlSize))

        # =======================
        # Set Control Transforms
        # =======================
        self.mainCtrlSpace.xfo = ctrlXfo
        self.mainCtrl.xfo = ctrlXfo

        # ============
        # Set IO Xfos
        # ============
        self.mainInputTgt.xfo = ctrlXfo
        self.mainDef.xfo = ctrlXfo
        self.outputTgt.xfo = ctrlXfo

        # ====================
        # Evaluate Constraints
        # ====================
        self.mainInputConstraint.evaluate()
        self.mainOutputConstraint.evaluate()
        self.mainDefConstraint.evaluate()
Exemple #16
0
class FabriceSpineRig(FabriceSpine):
    """Fabrice Spine Component"""

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


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

        # Get Data
        cogPos = data['cogPos']
        cogCtrlCrvData = data['cogCtrlCrvData']

        spineBasePos = data['spineBasePos']
        spineBaseCtrlCrvData = data['spineBaseCtrlCrvData']

        spineBaseHandlePos = data['spineBaseHandlePos']
        spineBaseHandleCtrlCrvData = data['spineBaseHandleCtrlCrvData']

        spineEndHandlePos = data['spineEndHandlePos']
        spineEndHandleCtrlCrvData = data['spineEndHandleCtrlCrvData']

        spineEndPos = data['spineEndPos']
        spineEndCtrlCrvData = data['spineEndCtrlCrvData']

        numDeformers = data['numDeformers']

        # Set Xfos
        self.cogCtrlSpace.xfo.tr = cogPos
        self.cogCtrl.xfo.tr = cogPos
        self.cogCtrl.setCurveData(cogCtrlCrvData)

        self.spineBaseCtrlSpace.xfo.tr = spineBasePos
        self.spineBaseCtrl.xfo.tr = spineBasePos
        self.spineBaseCtrl.setCurveData(spineBaseCtrlCrvData)

        self.spineBaseHandleCtrlSpace.xfo.tr = spineBaseHandlePos
        self.spineBaseHandleCtrl.xfo.tr = spineBaseHandlePos
        self.spineBaseHandleCtrl.setCurveData(spineBaseHandleCtrlCrvData)

        self.spineEndHandleCtrlSpace.xfo.tr = spineEndHandlePos
        self.spineEndHandleCtrl.xfo.tr = spineEndHandlePos
        self.spineEndHandleCtrl.setCurveData(spineEndHandleCtrlCrvData)

        self.spineEndCtrlSpace.xfo.tr = spineEndPos
        self.spineEndCtrl.xfo.tr = spineEndPos
        self.spineEndCtrl.setCurveData(spineEndCtrlCrvData)

        length = spineBasePos.distanceTo(spineBaseHandlePos) + spineBaseHandlePos.distanceTo(spineEndHandlePos) + spineEndHandlePos.distanceTo(spineEndPos)
        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()

        # evaluate the constraints to ensure the outputs are now in the correct location.
        self.spineSrtInputConstraint.evaluate()
        self.spineCogOutputConstraint.evaluate()
        self.spineBaseOutputPosConstraint.evaluate()
        self.spineBaseOutputOriConstraint.evaluate()
        self.spineEndOutputConstraint.evaluate()
        self.spineEndCtrlOutputConstraint.evaluate()
Exemple #17
0
    def __init__(self, name='head', parent=None):

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


        # =========
        # Controls
        # =========
        # Head
        self.headCtrlSpace = CtrlSpace('head', parent=self.ctrlCmpGrp)
        self.headCtrl = Control('head', parent=self.headCtrlSpace, shape="circle")
        self.headCtrl.rotatePoints(0, 0, 90)
        self.headCtrl.scalePoints(Vec3(3, 3, 3))
        self.headCtrl.translatePoints(Vec3(0, 1, 0.25))

        # Eye Left
        self.eyeLeftCtrlSpace = CtrlSpace('eyeLeft', parent=self.headCtrl)
        self.eyeLeftCtrl = Control('eyeLeft', parent=self.eyeLeftCtrlSpace, shape="sphere")
        self.eyeLeftCtrl.scalePoints(Vec3(0.5, 0.5, 0.5))
        self.eyeLeftCtrl.setColor("blueMedium")

        # Eye Right
        self.eyeRightCtrlSpace = CtrlSpace('eyeRight', parent=self.headCtrl)
        self.eyeRightCtrl = Control('eyeRight', parent=self.eyeRightCtrlSpace, shape="sphere")
        self.eyeRightCtrl.scalePoints(Vec3(0.5, 0.5, 0.5))
        self.eyeRightCtrl.setColor("blueMedium")

        # Jaw
        self.jawCtrlSpace = CtrlSpace('jawCtrlSpace', parent=self.headCtrl)
        self.jawCtrl = Control('jaw', parent=self.jawCtrlSpace, shape="cube")
        self.jawCtrl.alignOnYAxis(negative=True)
        self.jawCtrl.alignOnZAxis()
        self.jawCtrl.scalePoints(Vec3(1.45, 0.65, 1.25))
        self.jawCtrl.translatePoints(Vec3(0, -0.25, 0))
        self.jawCtrl.setColor("orange")


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

        headDef = Joint('head', parent=defCmpGrp)
        headDef.setComponent(self)

        jawDef = Joint('jaw', parent=defCmpGrp)
        jawDef.setComponent(self)

        eyeLeftDef = Joint('eyeLeft', parent=defCmpGrp)
        eyeLeftDef.setComponent(self)

        eyeRightDef = Joint('eyeRight', parent=defCmpGrp)
        eyeRightDef.setComponent(self)


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

        # # Constraint outputs
        headOutputConstraint = PoseConstraint('_'.join([self.headOutputTgt.getName(), 'To', self.headCtrl.getName()]))
        headOutputConstraint.addConstrainer(self.headCtrl)
        self.headOutputTgt.addConstraint(headOutputConstraint)

        jawOutputConstraint = PoseConstraint('_'.join([self.jawOutputTgt.getName(), 'To', self.jawCtrl.getName()]))
        jawOutputConstraint.addConstrainer(self.jawCtrl)
        self.jawOutputTgt.addConstraint(jawOutputConstraint)

        eyeLOutputConstraint = PoseConstraint('_'.join([self.eyeLOutputTgt.getName(), 'To', self.eyeLeftCtrl.getName()]))
        eyeLOutputConstraint.addConstrainer(self.eyeLeftCtrl)
        self.eyeLOutputTgt.addConstraint(eyeLOutputConstraint)

        eyeROutputConstraint = PoseConstraint('_'.join([self.eyeROutputTgt.getName(), 'To', self.eyeRightCtrl.getName()]))
        eyeROutputConstraint.addConstrainer(self.eyeRightCtrl)
        self.eyeROutputTgt.addConstraint(eyeROutputConstraint)


        # ==================
        # Add Component I/O
        # ==================
        # Add Xfo I/O's
        # self.addInput(self.headBaseInputTgt)

        # self.addOutput(self.headOutputTgt)
        # self.addOutput(self.jawOutputTgt)
        # self.addOutput(self.eyeLOutputTgt)
        # self.addOutput(self.eyeROutputTgt)

        # Add Attribute I/O's
        # self.addInput(self.drawDebugInputAttr)


        # ===============
        # Add Splice Ops
        # ===============
        # Add Deformer Splice Op
        # spliceOp = SpliceOperator('headDeformerSpliceOp', 'HeadConstraintSolver', 'KrakenHeadConstraintSolver')
        # self.addOperator(spliceOp)

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

        # # Add Xfo Inputstrl)
        # spliceOp.setInput('headConstrainer', self.headOutputTgt)
        # spliceOp.setInput('jawConstrainer', self.jawOutputTgt)
        # spliceOp.setInput('eyeLeftConstrainer', self.eyeLOutputTgt)
        # spliceOp.setInput('eyeRightConstrainer', self.eyeROutputTgt)

        # # Add Xfo Outputs
        # spliceOp.setOutput('headDeformer', headDef)
        # spliceOp.setOutput('jawDeformer', jawDef)
        # spliceOp.setOutput('eyeLeftDeformer', eyeLeftDef)
        # spliceOp.setOutput('eyeRightDeformer', eyeRightDef)

        Profiler.getInstance().pop()
Exemple #18
0
    def __init__(self, name, parent=None, location='M'):
        super(HandComponent, self).__init__(name, parent, location)

        # =========
        # Controls
        # =========
        # Setup component attributes
        defaultAttrGroup = self.getAttributeGroupByIndex(0)
        defaultAttrGroup.addAttribute(BoolAttribute("toggleDebugging", True))

        # Default values
        if location == 'R':
            ctrlColor = "red"
            handPosition = Vec3(-7.1886, 12.2819, 0.4906)
            handUpV = Vec3(-7.7463, 13.1746, 0.4477)
            handEndPosition = Vec3(-7.945, 11.8321, 0.9655)
        else:
            ctrlColor = "greenBright"
            handPosition = Vec3(7.1886, 12.2819, 0.4906)
            handUpV = Vec3(7.7463, 13.1746, 0.4477)
            handEndPosition = Vec3(7.945, 11.8321, 0.9655)

        # Calculate Clavicle Xfo
        rootToEnd = handEndPosition.subtract(handPosition).unit()
        rootToUpV = handUpV.subtract(handPosition).unit()
        bone1ZAxis = rootToEnd.cross(rootToUpV).unit()
        bone1Normal = rootToEnd.cross(bone1ZAxis).unit()
        handXfo = Xfo()

        if location == "R":
            handQuat = Quat(Vec3(-0.2301, -0.0865, -0.9331), 0.2623)
            handPos = Vec3(-7.1886, 12.2819, 0.4906)
        else:
            handQuat = Quat(Vec3(-0.0865, -0.2301, -0.2623), 0.9331)
            handPos = Vec3(7.1886, 12.2819, 0.4906)

        handXfo.rot = handQuat.clone()
        handXfo.tr.copy(handPos)

        # Add Controls
        handCtrlSrtBuffer = SrtBuffer('hand', parent=self)
        handCtrlSrtBuffer.xfo.copy(handXfo)

        handCtrl = CubeControl('hand', parent=handCtrlSrtBuffer)
        handCtrl.alignOnXAxis()
        handCtrl.scalePoints(Vec3(2.0, 0.75, 1.25))
        handCtrl.xfo.copy(handCtrlSrtBuffer.xfo)
        handCtrl.setColor(ctrlColor)

        # Rig Ref objects
        handRefSrt = Locator('handRef', parent=self)
        handRefSrt.xfo.copy(handCtrlSrtBuffer.xfo)


        # Add Component Params to IK control
        handDebugInputAttr = BoolAttribute('debug', True)
        handLinkToWorldInputAttr = FloatAttribute('linkToWorld', 0.0, 0.0, 1.0)

        handSettingsAttrGrp = AttributeGroup("DisplayInfo_HandSettings")
        handCtrl.addAttributeGroup(handSettingsAttrGrp)
        handSettingsAttrGrp.addAttribute(handDebugInputAttr)
        handSettingsAttrGrp.addAttribute(handLinkToWorldInputAttr)


        # ==========
        # Deformers
        # ==========
        container = self.getParent().getParent()
        deformersLayer = container.getChildByName('deformers')

        handDef = Joint('hand')
        handDef.setComponent(self)

        deformersLayer.addChild(handDef)


        # =====================
        # Create Component I/O
        # =====================
        # Setup Component Xfo I/O's
        armEndXfoInput = Locator('armEndXfo')
        armEndXfoInput.xfo.copy(handCtrlSrtBuffer.xfo)
        armEndPosInput = Locator('armEndPos')
        armEndPosInput.xfo.copy(handCtrlSrtBuffer.xfo)

        handEndOutput = Locator('handEnd')
        handEndOutput.xfo.copy(handCtrlSrtBuffer.xfo)
        handOutput = Locator('hand')
        handOutput.xfo.copy(handCtrlSrtBuffer.xfo)

        # Setup componnent Attribute I/O's
        debugInputAttr = BoolAttribute('debug', True)
        rightSideInputAttr = BoolAttribute('rightSide', location is 'R')
        linkToWorldInputAttr = FloatAttribute('linkToWorld', 0.0, 0.0, 1.0)

        # Connect attrs to control attrs
        debugInputAttr.connect(handDebugInputAttr)
        linkToWorldInputAttr.connect(handLinkToWorldInputAttr)


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

        # Constraint outputs
        handConstraint = PoseConstraint('_'.join([handOutput.getName(), 'To', handCtrl.getName()]))
        handConstraint.addConstrainer(handCtrl)
        handOutput.addConstraint(handConstraint)

        handEndConstraint = PoseConstraint('_'.join([handEndOutput.getName(), 'To', handCtrl.getName()]))
        handEndConstraint.addConstrainer(handCtrl)
        handEndOutput.addConstraint(handEndConstraint)


        # ==================
        # Add Component I/O
        # ==================
        # Add Xfo I/O's
        self.addInput(armEndXfoInput)
        self.addInput(armEndPosInput)
        self.addOutput(handOutput)
        self.addOutput(handEndOutput)

        # Add Attribute I/O's
        self.addInput(debugInputAttr)
        self.addInput(rightSideInputAttr)
        self.addInput(linkToWorldInputAttr)
Exemple #19
0
class FootComponentRig(FootComponent):
    """Foot Component"""

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

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


        # =========
        # Controls
        # =========
        self.ankleLenInputAttr = ScalarAttribute('ankleLen', 1.0, maxValue=1.0, parent=self.cmpInputAttrGrp)
        self.toeLenInputAttr = ScalarAttribute('toeLen', 1.0, maxValue=1.0, parent=self.cmpInputAttrGrp)
        self.rightSideInputAttr = BoolAttribute('rightSide', False, parent=self.cmpInputAttrGrp)

        self.footAll = Locator('footAll', parent=self.ctrlCmpGrp)
        self.footAll.setShapeVisibility(False)

        self.ankleIKCtrlSpace = CtrlSpace('ankleIK', parent=self.footAll)
        self.ankleIKCtrl = Control('ankleIK', parent=self.ankleIKCtrlSpace, shape="square")
        self.ankleIKCtrl.alignOnXAxis(negative=True)
        self.ankleIKCtrl.lockTranslation(True, True, True)
        self.ankleIKCtrl.lockScale(True, True, True)

        self.toeIKCtrlSpace = CtrlSpace('toeIK', parent=self.footAll)
        self.toeIKCtrl = Control('toeIK', parent=self.toeIKCtrlSpace, shape="square")
        self.toeIKCtrl.alignOnXAxis()
        self.toeIKCtrl.lockTranslation(True, True, True)
        self.toeIKCtrl.lockScale(True, True, True)

        self.ankleFKCtrlSpace = CtrlSpace('ankleFK', parent=self.ctrlCmpGrp)
        self.ankleFKCtrl = Control('ankleFK', parent=self.ankleFKCtrlSpace, shape="cube")
        self.ankleFKCtrl.alignOnXAxis()
        self.ankleFKCtrl.lockTranslation(True, True, True)
        self.ankleFKCtrl.lockScale(True, True, True)

        self.toeFKCtrlSpace = CtrlSpace('toeFK', parent=self.ankleFKCtrl)
        self.toeFKCtrl = Control('toeFK', parent=self.toeFKCtrlSpace, shape="cube")
        self.toeFKCtrl.alignOnXAxis()
        self.toeFKCtrl.lockTranslation(True, True, True)
        self.toeFKCtrl.lockScale(True, True, True)

        self.footSettingsAttrGrp = AttributeGroup("DisplayInfo_FootSettings", parent=self.ankleIKCtrl)
        self.footDebugInputAttr = BoolAttribute('drawDebug', value=False, parent=self.footSettingsAttrGrp)
        self.footRockInputAttr = ScalarAttribute('footRock', value=0.0, minValue=-1.0, maxValue=1.0, parent=self.footSettingsAttrGrp)
        self.footBankInputAttr = ScalarAttribute('footBank', value=0.0, minValue=-1.0, maxValue=1.0, parent=self.footSettingsAttrGrp)

        self.drawDebugInputAttr.connect(self.footDebugInputAttr)

        self.pivotAll = Locator('pivotAll', parent=self.ctrlCmpGrp)
        self.pivotAll.setShapeVisibility(False)

        self.backPivotCtrl = Control('backPivot', parent=self.pivotAll, shape="axesHalfTarget")
        self.backPivotCtrl.scalePoints(Vec3(0.5, 0.5, 0.5))
        self.backPivotCtrl.lockScale(True, True, True)
        self.backPivotCtrlSpace = self.backPivotCtrl.insertCtrlSpace()

        self.frontPivotCtrl = Control('frontPivot', parent=self.pivotAll, shape="axesHalfTarget")
        self.frontPivotCtrl.rotatePoints(0.0, 180.0, 0.0)
        self.frontPivotCtrl.lockScale(True, True, True)
        self.frontPivotCtrlSpace = self.frontPivotCtrl.insertCtrlSpace()
        self.frontPivotCtrl.scalePoints(Vec3(0.5, 0.5, 0.5))

        self.outerPivotCtrl = Control('outerPivot', parent=self.pivotAll, shape="axesHalfTarget")
        self.outerPivotCtrl.rotatePoints(0.0, -90.0, 0.0)
        self.outerPivotCtrl.lockScale(True, True, True)
        self.outerPivotCtrlSpace = self.outerPivotCtrl.insertCtrlSpace()
        self.outerPivotCtrl.scalePoints(Vec3(0.5, 0.5, 0.5))

        self.innerPivotCtrl = Control('innerPivot', parent=self.pivotAll, shape="axesHalfTarget")
        self.innerPivotCtrl.rotatePoints(0.0, 90.0, 0.0)
        self.innerPivotCtrl.lockScale(True, True, True)
        self.innerPivotCtrlSpace = self.innerPivotCtrl.insertCtrlSpace()
        self.innerPivotCtrl.scalePoints(Vec3(0.5, 0.5, 0.5))


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

        self.ankleDef = Joint('ankle', parent=self.defCmpGrp)
        self.ankleDef.setComponent(self)

        self.toeDef = Joint('toe', parent=self.defCmpGrp)
        self.toeDef.setComponent(self)


        # ==============
        # Constrain I/O
        # ==============
        # Constraint to inputs
        self.pivotAllInputConstraint = PoseConstraint('_'.join([self.pivotAll.getName(), 'To', self.ikHandleInputTgt.getName()]))
        self.pivotAllInputConstraint.setMaintainOffset(True)
        self.pivotAllInputConstraint.addConstrainer(self.ikHandleInputTgt)
        self.pivotAll.addConstraint(self.pivotAllInputConstraint)

        self.ankleFKInputConstraint = PoseConstraint('_'.join([self.ankleFKCtrlSpace.getName(), 'To', self.legEndFKInputTgt.getName()]))
        self.ankleFKInputConstraint.setMaintainOffset(True)
        self.ankleFKInputConstraint.addConstrainer(self.legEndFKInputTgt)
        self.ankleFKCtrlSpace.addConstraint(self.ankleFKInputConstraint)

        # Constraint outputs
        self.ikTargetOutputConstraint = PoseConstraint('_'.join([self.ikTargetOutputTgt.getName(), 'To', self.ankleIKCtrl.getName()]))
        self.ikTargetOutputConstraint.setMaintainOffset(True)
        self.ikTargetOutputConstraint.addConstrainer(self.ankleIKCtrl)
        self.ikTargetOutputTgt.addConstraint(self.ikTargetOutputConstraint)


        # =========================
        # Add Foot Pivot Canvas Op
        # =========================
        # self.footPivotCanvasOp = CanvasOperator('footPivotCanvasOp', 'Kraken.Solvers.Biped.BipedFootPivotSolver')
        self.footPivotCanvasOp = KLOperator('footPivotKLOp', 'BipedFootPivotSolver', 'Kraken')

        self.addOperator(self.footPivotCanvasOp)

        # Add Att Inputs
        self.footPivotCanvasOp.setInput('drawDebug', self.drawDebugInputAttr)
        self.footPivotCanvasOp.setInput('rigScale', self.rigScaleInputAttr)
        self.footPivotCanvasOp.setInput('rightSide', self.rightSideInputAttr)
        self.footPivotCanvasOp.setInput('footRock', self.footRockInputAttr)
        self.footPivotCanvasOp.setInput('footBank', self.footBankInputAttr)

        # Add Xfo Inputs
        self.footPivotCanvasOp.setInput('pivotAll', self.pivotAll)
        self.footPivotCanvasOp.setInput('backPivot', self.backPivotCtrl)
        self.footPivotCanvasOp.setInput('frontPivot', self.frontPivotCtrl)
        self.footPivotCanvasOp.setInput('outerPivot', self.outerPivotCtrl)
        self.footPivotCanvasOp.setInput('innerPivot', self.innerPivotCtrl)

        # Add Xfo Outputs
        self.footPivotCanvasOp.setOutput('result', self.footAll)


        # =========================
        # Add Foot Solver Canvas Op
        # =========================
        # self.footSolverCanvasOp = CanvasOperator('footSolverCanvasOp', 'Kraken.Solvers.Biped.BipedFootSolver')
        self.footSolverCanvasOp = KLOperator('footSolverKLOp', 'BipedFootSolver', 'Kraken')
        self.addOperator(self.footSolverCanvasOp)

        # Add Att Inputs
        self.footSolverCanvasOp.setInput('drawDebug', self.drawDebugInputAttr)
        self.footSolverCanvasOp.setInput('rigScale', self.rigScaleInputAttr)
        self.footSolverCanvasOp.setInput('ikBlend', self.ikBlendInputAttr)
        self.footSolverCanvasOp.setInput('ankleLen', self.ankleLenInputAttr)
        self.footSolverCanvasOp.setInput('toeLen', self.toeLenInputAttr)

        # Add Xfo Inputs
        self.footSolverCanvasOp.setInput('legEnd', self.legEndInputTgt)
        self.footSolverCanvasOp.setInput('ankleIK', self.ankleIKCtrl)
        self.footSolverCanvasOp.setInput('toeIK', self.toeIKCtrl)
        self.footSolverCanvasOp.setInput('ankleFK', self.ankleFKCtrl)
        self.footSolverCanvasOp.setInput('toeFK', self.toeFKCtrl)

        # Add Xfo Outputs
        self.footSolverCanvasOp.setOutput('ankle_result', self.ankleOutputTgt)
        self.footSolverCanvasOp.setOutput('toe_result', self.toeOutputTgt)


        # ===================
        # Add Deformer KL Op
        # ===================
        self.outputsToDeformersKLOp = KLOperator('foot' + self.getLocation() + 'DeformerKLOp', 'MultiPoseConstraintSolver', 'Kraken')
        self.addOperator(self.outputsToDeformersKLOp)

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

        # Add Xfo Inputs
        self.outputsToDeformersKLOp.setInput('constrainers', [self.ankleOutputTgt, self.toeOutputTgt])

        # Add Xfo Outputs
        self.outputsToDeformersKLOp.setOutput('constrainees', [self.ankleDef, self.toeDef])

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

        footXfo = data.get('footXfo')
        ankleXfo = data.get('ankleXfo')
        toeXfo = data.get('toeXfo')
        ankleFKXfo = data.get('ankleFKXfo')
        toeFKXfo = data.get('toeFKXfo')
        ankleLen = data.get('ankleLen')
        toeLen = data.get('toeLen')
        backPivotXfo = data.get('backPivotXfo')
        frontPivotXfo = data.get('frontPivotXfo')
        outerPivotXfo = data.get('outerPivotXfo')
        innerPivotXfo = data.get('innerPivotXfo')

        self.footAll.xfo = footXfo
        self.ankleIKCtrlSpace.xfo = ankleXfo
        self.ankleIKCtrl.xfo = ankleXfo
        self.toeIKCtrlSpace.xfo = toeXfo
        self.toeIKCtrl.xfo = toeXfo

        self.ankleFKCtrl.scalePoints(Vec3(ankleLen, 1.0, 1.0))
        self.toeFKCtrl.scalePoints(Vec3(toeLen, 1.0, 1.0))

        self.ankleFKCtrlSpace.xfo.tr = footXfo.tr
        self.ankleFKCtrlSpace.xfo.ori = ankleFKXfo.ori
        self.ankleFKCtrl.xfo.tr = footXfo.tr
        self.ankleFKCtrl.xfo.ori = ankleFKXfo.ori
        self.toeFKCtrlSpace.xfo = toeFKXfo
        self.toeFKCtrl.xfo = toeFKXfo

        self.pivotAll.xfo = footXfo
        self.backPivotCtrlSpace.xfo = backPivotXfo
        self.backPivotCtrl.xfo = backPivotXfo
        self.frontPivotCtrlSpace.xfo = frontPivotXfo
        self.frontPivotCtrl.xfo = frontPivotXfo
        self.outerPivotCtrlSpace.xfo = outerPivotXfo
        self.outerPivotCtrl.xfo = outerPivotXfo
        self.innerPivotCtrlSpace.xfo = innerPivotXfo
        self.innerPivotCtrl.xfo = innerPivotXfo

        if self.getLocation() == 'R':
            self.outerPivotCtrl.rotatePoints(0.0, 180.0, 0.0)
            self.innerPivotCtrl.rotatePoints(0.0, 180.0, 0.0)

        self.ankleIKCtrl.scalePoints(Vec3(ankleLen, 1.0, 1.5))
        self.toeIKCtrl.scalePoints(Vec3(toeLen, 1.0, 1.5))

        # Set Attribute Values
        self.rightSideInputAttr.setValue(self.getLocation() is 'R')
        self.ankleLenInputAttr.setValue(ankleLen)
        self.ankleLenInputAttr.setMax(ankleLen * 3.0)
        self.toeLenInputAttr.setValue(toeLen)
        self.toeLenInputAttr.setMax(toeLen * 3.0)

        # Set IO Xfos
        self.ikHandleInputTgt.xfo = footXfo
        self.legEndInputTgt.xfo.tr = footXfo.tr
        self.legEndInputTgt.xfo.ori = ankleXfo.ori
        self.legEndFKInputTgt.xfo.tr = footXfo.tr
        self.legEndFKInputTgt.xfo.ori = ankleXfo.ori

        self.ikTargetOutputTgt.xfo.tr = footXfo.tr
        self.ikTargetOutputTgt.xfo.ori = ankleXfo.ori

        # Eval Canvas Ops
        self.footPivotCanvasOp.evaluate()
        self.footSolverCanvasOp.evaluate()

        # Eval Constraints
        self.ikTargetOutputConstraint.evaluate()
        self.ankleFKInputConstraint.evaluate()
Exemple #20
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.neck01Ctrl = Control('neck01', parent=self.ctrlCmpGrp, shape="pin")
        self.neck01Ctrl.setColor("orange")
        self.neck01Ctrl.lockTranslation(True, True, True)
        self.neck01Ctrl.lockScale(True, True, True)

        self.neck01CtrlSpace = self.neck01Ctrl.insertCtrlSpace(name='neck01')

        self.neck02Ctrl = Control('neck02', parent=self.neck01Ctrl, shape="pin")
        self.neck02Ctrl.setColor("orange")
        self.neck02Ctrl.lockTranslation(True, True, True)
        self.neck02Ctrl.lockScale(True, True, True)

        self.neck02CtrlSpace = self.neck02Ctrl.insertCtrlSpace(name='neck02')


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

        self.neck01Def = Joint('neck01', parent=self.defCmpGrp)
        self.neck01Def.setComponent(self)

        self.neck02Def = Joint('neck02', parent=self.defCmpGrp)
        self.neck02Def.setComponent(self)


        # ==============
        # Constrain I/O
        # ==============
        # Constraint inputs
        neckInputConstraintName = '_'.join([self.neck01CtrlSpace.getName(),
                                            'To',
                                            self.neckBaseInputTgt.getName()])

        self.neckInputCnstr = self.neck01CtrlSpace.constrainTo(
            self.neckBaseInputTgt,
            'Pose',
            maintainOffset=True,
            name=neckInputConstraintName)


        # Constraint outputs
        neck01OutCnstrName = '_'.join([self.neck01OutputTgt.getName(),
                                       'To',
                                       self.neck01Ctrl.getName()])

        self.neck01OutCnstr = self.neck01OutputTgt.constrainTo(
            self.neck01Ctrl,
            'Pose',
            maintainOffset=False,
            name=neck01OutCnstrName)

        neck02OutCnstrName = '_'.join([self.neck02OutputTgt.getName(),
                                       'To',
                                       self.neck02Ctrl.getName()])

        self.neck02OutCnstr = self.neck02OutputTgt.constrainTo(
            self.neck02Ctrl,
            'Pose',
            maintainOffset=False,
            name=neck02OutCnstrName)

        neckEndCnstrName = '_'.join([self.neckEndOutputTgt.getName(),
                                     'To',
                                     self.neck02Ctrl.getName()])

        self.neckEndCnstr = self.neckEndOutputTgt.constrainTo(
            self.neck02Ctrl,
            'Pose',
            maintainOffset=True,
            name=neckEndCnstrName)


        # ==============
        # Add Operators
        # ==============
        # Add Deformer KL Op
        self.neckDeformerKLOp = KLOperator('neckDeformerKLOp',
                                           'MultiPoseConstraintSolver',
                                           'Kraken')

        self.addOperator(self.neckDeformerKLOp)

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

        # Add Xfo Inputstrl)
        self.neckDeformerKLOp.setInput('constrainers',
                                       [self.neck01Ctrl, self.neck02Ctrl])

        # Add Xfo Outputs
        self.neckDeformerKLOp.setOutput('constrainees',
                                        [self.neck01Def, self.neck02Def])

        Profiler.getInstance().pop()
Exemple #21
0
    def __init__(self, name="foot", parent=None):

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


        # =========
        # Controls
        # =========
        self.ankleLenInputAttr = ScalarAttribute('ankleLen', 1.0, maxValue=1.0, parent=self.cmpInputAttrGrp)
        self.toeLenInputAttr = ScalarAttribute('toeLen', 1.0, maxValue=1.0, parent=self.cmpInputAttrGrp)
        self.rightSideInputAttr = BoolAttribute('rightSide', False, parent=self.cmpInputAttrGrp)

        self.footAll = Locator('footAll', parent=self.ctrlCmpGrp)
        self.footAll.setShapeVisibility(False)

        self.ankleIKCtrlSpace = CtrlSpace('ankleIK', parent=self.footAll)
        self.ankleIKCtrl = Control('ankleIK', parent=self.ankleIKCtrlSpace, shape="square")
        self.ankleIKCtrl.alignOnXAxis(negative=True)
        self.ankleIKCtrl.lockTranslation(True, True, True)
        self.ankleIKCtrl.lockScale(True, True, True)

        self.toeIKCtrlSpace = CtrlSpace('toeIK', parent=self.footAll)
        self.toeIKCtrl = Control('toeIK', parent=self.toeIKCtrlSpace, shape="square")
        self.toeIKCtrl.alignOnXAxis()
        self.toeIKCtrl.lockTranslation(True, True, True)
        self.toeIKCtrl.lockScale(True, True, True)

        self.ankleFKCtrlSpace = CtrlSpace('ankleFK', parent=self.ctrlCmpGrp)
        self.ankleFKCtrl = Control('ankleFK', parent=self.ankleFKCtrlSpace, shape="cube")
        self.ankleFKCtrl.alignOnXAxis()
        self.ankleFKCtrl.lockTranslation(True, True, True)
        self.ankleFKCtrl.lockScale(True, True, True)

        self.toeFKCtrlSpace = CtrlSpace('toeFK', parent=self.ankleFKCtrl)
        self.toeFKCtrl = Control('toeFK', parent=self.toeFKCtrlSpace, shape="cube")
        self.toeFKCtrl.alignOnXAxis()
        self.toeFKCtrl.lockTranslation(True, True, True)
        self.toeFKCtrl.lockScale(True, True, True)

        self.footSettingsAttrGrp = AttributeGroup("DisplayInfo_FootSettings", parent=self.ankleIKCtrl)
        self.footDebugInputAttr = BoolAttribute('drawDebug', value=False, parent=self.footSettingsAttrGrp)
        self.footRockInputAttr = ScalarAttribute('footRock', value=0.0, minValue=-1.0, maxValue=1.0, parent=self.footSettingsAttrGrp)
        self.footBankInputAttr = ScalarAttribute('footBank', value=0.0, minValue=-1.0, maxValue=1.0, parent=self.footSettingsAttrGrp)

        self.drawDebugInputAttr.connect(self.footDebugInputAttr)

        self.pivotAll = Locator('pivotAll', parent=self.ctrlCmpGrp)
        self.pivotAll.setShapeVisibility(False)

        self.backPivotCtrl = Control('backPivot', parent=self.pivotAll, shape="axesHalfTarget")
        self.backPivotCtrl.scalePoints(Vec3(0.5, 0.5, 0.5))
        self.backPivotCtrl.lockScale(True, True, True)
        self.backPivotCtrlSpace = self.backPivotCtrl.insertCtrlSpace()

        self.frontPivotCtrl = Control('frontPivot', parent=self.pivotAll, shape="axesHalfTarget")
        self.frontPivotCtrl.rotatePoints(0.0, 180.0, 0.0)
        self.frontPivotCtrl.lockScale(True, True, True)
        self.frontPivotCtrlSpace = self.frontPivotCtrl.insertCtrlSpace()
        self.frontPivotCtrl.scalePoints(Vec3(0.5, 0.5, 0.5))

        self.outerPivotCtrl = Control('outerPivot', parent=self.pivotAll, shape="axesHalfTarget")
        self.outerPivotCtrl.rotatePoints(0.0, -90.0, 0.0)
        self.outerPivotCtrl.lockScale(True, True, True)
        self.outerPivotCtrlSpace = self.outerPivotCtrl.insertCtrlSpace()
        self.outerPivotCtrl.scalePoints(Vec3(0.5, 0.5, 0.5))

        self.innerPivotCtrl = Control('innerPivot', parent=self.pivotAll, shape="axesHalfTarget")
        self.innerPivotCtrl.rotatePoints(0.0, 90.0, 0.0)
        self.innerPivotCtrl.lockScale(True, True, True)
        self.innerPivotCtrlSpace = self.innerPivotCtrl.insertCtrlSpace()
        self.innerPivotCtrl.scalePoints(Vec3(0.5, 0.5, 0.5))


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

        self.ankleDef = Joint('ankle', parent=self.defCmpGrp)
        self.ankleDef.setComponent(self)

        self.toeDef = Joint('toe', parent=self.defCmpGrp)
        self.toeDef.setComponent(self)


        # ==============
        # Constrain I/O
        # ==============
        # Constraint to inputs
        self.pivotAllInputConstraint = PoseConstraint('_'.join([self.pivotAll.getName(), 'To', self.ikHandleInputTgt.getName()]))
        self.pivotAllInputConstraint.setMaintainOffset(True)
        self.pivotAllInputConstraint.addConstrainer(self.ikHandleInputTgt)
        self.pivotAll.addConstraint(self.pivotAllInputConstraint)

        self.ankleFKInputConstraint = PoseConstraint('_'.join([self.ankleFKCtrlSpace.getName(), 'To', self.legEndFKInputTgt.getName()]))
        self.ankleFKInputConstraint.setMaintainOffset(True)
        self.ankleFKInputConstraint.addConstrainer(self.legEndFKInputTgt)
        self.ankleFKCtrlSpace.addConstraint(self.ankleFKInputConstraint)

        # Constraint outputs
        self.ikTargetOutputConstraint = PoseConstraint('_'.join([self.ikTargetOutputTgt.getName(), 'To', self.ankleIKCtrl.getName()]))
        self.ikTargetOutputConstraint.setMaintainOffset(True)
        self.ikTargetOutputConstraint.addConstrainer(self.ankleIKCtrl)
        self.ikTargetOutputTgt.addConstraint(self.ikTargetOutputConstraint)


        # =========================
        # Add Foot Pivot Canvas Op
        # =========================
        # self.footPivotCanvasOp = CanvasOperator('footPivotCanvasOp', 'Kraken.Solvers.Biped.BipedFootPivotSolver')
        self.footPivotCanvasOp = KLOperator('footPivotKLOp', 'BipedFootPivotSolver', 'Kraken')

        self.addOperator(self.footPivotCanvasOp)

        # Add Att Inputs
        self.footPivotCanvasOp.setInput('drawDebug', self.drawDebugInputAttr)
        self.footPivotCanvasOp.setInput('rigScale', self.rigScaleInputAttr)
        self.footPivotCanvasOp.setInput('rightSide', self.rightSideInputAttr)
        self.footPivotCanvasOp.setInput('footRock', self.footRockInputAttr)
        self.footPivotCanvasOp.setInput('footBank', self.footBankInputAttr)

        # Add Xfo Inputs
        self.footPivotCanvasOp.setInput('pivotAll', self.pivotAll)
        self.footPivotCanvasOp.setInput('backPivot', self.backPivotCtrl)
        self.footPivotCanvasOp.setInput('frontPivot', self.frontPivotCtrl)
        self.footPivotCanvasOp.setInput('outerPivot', self.outerPivotCtrl)
        self.footPivotCanvasOp.setInput('innerPivot', self.innerPivotCtrl)

        # Add Xfo Outputs
        self.footPivotCanvasOp.setOutput('result', self.footAll)


        # =========================
        # Add Foot Solver Canvas Op
        # =========================
        # self.footSolverCanvasOp = CanvasOperator('footSolverCanvasOp', 'Kraken.Solvers.Biped.BipedFootSolver')
        self.footSolverCanvasOp = KLOperator('footSolverKLOp', 'BipedFootSolver', 'Kraken')
        self.addOperator(self.footSolverCanvasOp)

        # Add Att Inputs
        self.footSolverCanvasOp.setInput('drawDebug', self.drawDebugInputAttr)
        self.footSolverCanvasOp.setInput('rigScale', self.rigScaleInputAttr)
        self.footSolverCanvasOp.setInput('ikBlend', self.ikBlendInputAttr)
        self.footSolverCanvasOp.setInput('ankleLen', self.ankleLenInputAttr)
        self.footSolverCanvasOp.setInput('toeLen', self.toeLenInputAttr)

        # Add Xfo Inputs
        self.footSolverCanvasOp.setInput('legEnd', self.legEndInputTgt)
        self.footSolverCanvasOp.setInput('ankleIK', self.ankleIKCtrl)
        self.footSolverCanvasOp.setInput('toeIK', self.toeIKCtrl)
        self.footSolverCanvasOp.setInput('ankleFK', self.ankleFKCtrl)
        self.footSolverCanvasOp.setInput('toeFK', self.toeFKCtrl)

        # Add Xfo Outputs
        self.footSolverCanvasOp.setOutput('ankle_result', self.ankleOutputTgt)
        self.footSolverCanvasOp.setOutput('toe_result', self.toeOutputTgt)


        # ===================
        # Add Deformer KL Op
        # ===================
        self.outputsToDeformersKLOp = KLOperator('foot' + self.getLocation() + 'DeformerKLOp', 'MultiPoseConstraintSolver', 'Kraken')
        self.addOperator(self.outputsToDeformersKLOp)

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

        # Add Xfo Inputs
        self.outputsToDeformersKLOp.setInput('constrainers', [self.ankleOutputTgt, self.toeOutputTgt])

        # Add Xfo Outputs
        self.outputsToDeformersKLOp.setOutput('constrainees', [self.ankleDef, self.toeDef])

        Profiler.getInstance().pop()
Exemple #22
0
class HandComponentRig(HandComponent):
    """Hand Component"""

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

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


        # =========
        # Controls
        # =========
        # Hand
        self.handCtrlSpace = CtrlSpace('hand', parent=self.ctrlCmpGrp)
        self.handCtrl = Control('hand', parent=self.handCtrlSpace, shape="square")
        self.handCtrl.rotatePoints(0, 0, 90.0)
        self.handCtrl.lockScale(True, True, True)
        self.handCtrl.lockTranslation(True, True, True)


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

        self.handDef = Joint('hand', parent=self.defCmpGrp)
        self.handDef.setComponent(self)


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

        # Constraint outputs
        self.handOutputConstraint = PoseConstraint('_'.join([self.handOutputTgt.getName(), 'To', self.handCtrl.getName()]))
        self.handOutputConstraint.addConstrainer(self.handCtrl)
        self.handOutputTgt.addConstraint(self.handOutputConstraint)

        # Constraint deformers
        self.handDefConstraint = PoseConstraint('_'.join([self.handDef.getName(), 'To', self.handCtrl.getName()]))
        self.handDefConstraint.addConstrainer(self.handCtrl)
        self.handDef.addConstraint(self.handDefConstraint)

        Profiler.getInstance().pop()


    def addFinger(self, name, data):

        fingerCtrls = []
        fingerJoints = []

        parentCtrl = self.handCtrl
        for i, joint in enumerate(data):
            if i == 0:
                jointName = name + 'Meta'
            else:
                jointName = name + str(i).zfill(2)

            jointXfo = joint.get('xfo', Xfo())
            jointCrvData = joint.get('curveData')

            # Create Controls
            newJointCtrlSpace = CtrlSpace(jointName, parent=parentCtrl)
            newJointCtrl = Control(jointName, parent=newJointCtrlSpace, shape='square')
            newJointCtrl.lockScale(True, True, True)
            newJointCtrl.lockTranslation(True, True, True)

            if jointCrvData is not None:
                newJointCtrl.setCurveData(jointCrvData)

            fingerCtrls.append(newJointCtrl)

            # Create Deformers
            jointDef = Joint(jointName, parent=self.defCmpGrp)
            fingerJoints.append(jointDef)

            # Create Constraints

            # Set Xfos
            newJointCtrlSpace.xfo = jointXfo
            newJointCtrl.xfo = jointXfo

            parentCtrl = newJointCtrl


        # =================
        # Create Operators
        # =================
        # Add Deformer KL Op
        deformersToCtrlsKLOp = KLOperator(name + 'DeformerKLOp', 'MultiPoseConstraintSolver', 'Kraken')
        self.addOperator(deformersToCtrlsKLOp)

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

        # Add Xfo Inputs
        deformersToCtrlsKLOp.setInput('constrainers', fingerCtrls)

        # Add Xfo Outputs
        deformersToCtrlsKLOp.setOutput('constrainees', fingerJoints)

        return deformersToCtrlsKLOp


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

        # Data
        fingerData = data.get('fingerData')
        handXfo = data.get('handXfo', Xfo())

        self.handCtrlSpace.xfo = handXfo
        self.handCtrl.xfo = handXfo

        fingerOps = []
        for finger in fingerData.keys():
            fingerOp = self.addFinger(finger, fingerData[finger])
            fingerOps.append(fingerOp)

        # ============
        # Set IO Xfos
        # ============
        self.armEndInputTgt.xfo = handXfo
        self.handOutputTgt.xfo = handXfo

        # Eval Constraints
        self.armEndInputConstraint.evaluate()
        self.handOutputConstraint.evaluate()
        self.handDefConstraint.evaluate()

        # Eval Operators
        for op in fingerOps:
            op.evaluate()
Exemple #23
0
    def __init__(self, name, parent=None, location='M'):
        super(ClavicleComponent, self).__init__(name, parent, location)

        # =========
        # Controls
        # =========
        # Setup component attributes
        defaultAttrGroup = self.getAttributeGroupByIndex(0)
        defaultAttrGroup.addAttribute(BoolAttribute("toggleDebugging", True))

        # Default values
        if location == 'R':
            ctrlColor = "red"
            claviclePosition = Vec3(-0.1322, 15.403, -0.5723)
            clavicleUpV = Vec3()
            clavicleUpV.copy(claviclePosition)
            clavicleUpV = clavicleUpV.add(Vec3(0.0, 1.0, 0.0)).unit()
            clavicleEndPosition = Vec3(-2.27, 15.295, -0.753)
        else:
            ctrlColor = "greenBright"
            claviclePosition = Vec3(0.1322, 15.403, -0.5723)
            clavicleUpV = Vec3()
            clavicleUpV.copy(claviclePosition)
            clavicleUpV = clavicleUpV.add(Vec3(0.0, 1.0, 0.0)).unit()
            clavicleEndPosition = Vec3(2.27, 15.295, -0.753)

        # Calculate Clavicle Xfo
        rootToEnd = clavicleEndPosition.subtract(claviclePosition).unit()
        rootToUpV = clavicleUpV.subtract(claviclePosition).unit()
        bone1ZAxis = rootToUpV.cross(rootToEnd).unit()
        bone1Normal = bone1ZAxis.cross(rootToEnd).unit()
        clavicleXfo = Xfo()

        clavicleXfo.setFromVectors(rootToEnd, bone1Normal, bone1ZAxis, claviclePosition)

        # Add Controls
        clavicleCtrl = CubeControl('clavicle', parent=self)
        clavicleCtrl.alignOnXAxis()
        clavicleLen = claviclePosition.subtract(clavicleEndPosition).length()
        clavicleCtrl.scalePoints(Vec3(clavicleLen, 0.75, 0.75))

        if location == "R":
            clavicleCtrl.translatePoints(Vec3(0.0, 0.0, -1.0))
        else:
            clavicleCtrl.translatePoints(Vec3(0.0, 0.0, 1.0))

        clavicleCtrl.xfo.copy(clavicleXfo)
        clavicleCtrl.setColor(ctrlColor)

        clavicleCtrlSrtBuffer = SrtBuffer('clavicle', parent=self)
        clavicleCtrlSrtBuffer.xfo.copy(clavicleCtrl.xfo)
        clavicleCtrlSrtBuffer.addChild(clavicleCtrl)


        # ==========
        # Deformers
        # ==========
        container = self.getParent().getParent()
        deformersLayer = container.getChildByName('deformers')

        clavicleDef = Joint('clavicle')
        clavicleDef.setComponent(self)

        deformersLayer.addChild(clavicleDef)


        # =====================
        # Create Component I/O
        # =====================
        # Setup Component Xfo I/O's
        spineEndInput = Locator('spineEnd')
        spineEndInput.xfo.copy(clavicleXfo)

        clavicleEndOutput = Locator('clavicleEnd')
        clavicleEndOutput.xfo.copy(clavicleXfo)
        clavicleOutput = Locator('clavicle')
        clavicleOutput.xfo.copy(clavicleXfo)

        # Setup componnent Attribute I/O's
        debugInputAttr = BoolAttribute('debug', True)
        rightSideInputAttr = BoolAttribute('rightSide', location is 'R')
        armFollowBodyOutputAttr = FloatAttribute('followBody', 0.0, 0.0, 1.0)


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

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

        clavicleEndConstraint = PoseConstraint('_'.join([clavicleEndOutput.getName(), 'To', clavicleCtrl.getName()]))
        clavicleEndConstraint.addConstrainer(clavicleCtrl)
        clavicleEndOutput.addConstraint(clavicleEndConstraint)


        # ==================
        # Add Component I/O
        # ==================
        # Add Xfo I/O's
        self.addInput(spineEndInput)
        self.addOutput(clavicleEndOutput)
        self.addOutput(clavicleOutput)

        # Add Attribute I/O's
        self.addInput(debugInputAttr)
        self.addInput(rightSideInputAttr)
        self.addOutput(armFollowBodyOutputAttr)
Exemple #24
0
    def __init__(self, name, parent=None, location='M'):
        super(ArmComponent, self).__init__(name, parent, location)

        # =========
        # Controls
        # =========
        # Setup component attributes
        defaultAttrGroup = self.getAttributeGroupByIndex(0)
        defaultAttrGroup.addAttribute(BoolAttribute("toggleDebugging", True))

        # Default values
        if self.getLocation() == "R":
            ctrlColor = "red"
            bicepPosition = Vec3(-2.27, 15.295, -0.753)
            forearmPosition = Vec3(-5.039, 13.56, -0.859)
            wristPosition = Vec3(-7.1886, 12.2819, 0.4906)
        else:
            ctrlColor = "greenBright"
            bicepPosition = Vec3(2.27, 15.295, -0.753)
            forearmPosition = Vec3(5.039, 13.56, -0.859)
            wristPosition = Vec3(7.1886, 12.2819, 0.4906)

        # Calculate Bicep Xfo
        rootToWrist = wristPosition.subtract(bicepPosition).unit()
        rootToElbow = forearmPosition.subtract(bicepPosition).unit()
        bone1Normal = rootToWrist.cross(rootToElbow).unit()
        bone1ZAxis = rootToElbow.cross(bone1Normal).unit()
        bicepXfo = Xfo()
        bicepXfo.setFromVectors(rootToElbow, bone1Normal, bone1ZAxis, bicepPosition)

        # Calculate Forearm Xfo
        elbowToWrist = wristPosition.subtract(forearmPosition).unit()
        elbowToRoot = bicepPosition.subtract(forearmPosition).unit()
        bone2Normal = elbowToRoot.cross(elbowToWrist).unit()
        bone2ZAxis = elbowToWrist.cross(bone2Normal).unit()
        forearmXfo = Xfo()
        forearmXfo.setFromVectors(elbowToWrist, bone2Normal, bone2ZAxis, forearmPosition)

        # Bicep
        bicepFKCtrl = CubeControl('bicepFK')
        bicepFKCtrl.alignOnXAxis()
        bicepLen = bicepPosition.subtract(forearmPosition).length()
        bicepFKCtrl.scalePoints(Vec3(bicepLen, 1.75, 1.75))
        bicepFKCtrl.setColor(ctrlColor)
        bicepFKCtrl.xfo.copy(bicepXfo)

        bicepFKCtrlSrtBuffer = SrtBuffer('bicepFK')
        self.addChild(bicepFKCtrlSrtBuffer)
        bicepFKCtrlSrtBuffer.xfo.copy(bicepFKCtrl.xfo)
        bicepFKCtrlSrtBuffer.addChild(bicepFKCtrl)

        # Forearm
        forearmFKCtrl = CubeControl('forearmFK')
        forearmFKCtrl.alignOnXAxis()
        forearmLen = forearmPosition.subtract(wristPosition).length()
        forearmFKCtrl.scalePoints(Vec3(forearmLen, 1.5, 1.5))
        forearmFKCtrl.setColor(ctrlColor)
        forearmFKCtrl.xfo.copy(forearmXfo)

        forearmFKCtrlSrtBuffer = SrtBuffer('forearmFK')
        bicepFKCtrl.addChild(forearmFKCtrlSrtBuffer)
        forearmFKCtrlSrtBuffer.xfo.copy(forearmFKCtrl.xfo)
        forearmFKCtrlSrtBuffer.addChild(forearmFKCtrl)

        # Arm IK
        armIKCtrlSrtBuffer = SrtBuffer('IK', parent=self)
        armIKCtrlSrtBuffer.xfo.tr.copy(wristPosition)

        armIKCtrl = PinControl('IK', parent=armIKCtrlSrtBuffer)
        armIKCtrl.xfo.copy(armIKCtrlSrtBuffer.xfo)
        armIKCtrl.setColor(ctrlColor)

        if self.getLocation() == "R":
            armIKCtrl.rotatePoints(0, 90, 0)
        else:
            armIKCtrl.rotatePoints(0, -90, 0)


        # Add Component Params to IK control
        armDebugInputAttr = BoolAttribute('debug', True)
        armBone1LenInputAttr = FloatAttribute('bone1Len', bicepLen, 0.0, 100.0)
        armBone2LenInputAttr = FloatAttribute('bone2Len', forearmLen, 0.0, 100.0)
        armFkikInputAttr = FloatAttribute('fkik', 0.0, 0.0, 1.0)
        armSoftIKInputAttr = BoolAttribute('softIK', True)
        armSoftDistInputAttr = FloatAttribute('softDist', 0.0, 0.0, 1.0)
        armStretchInputAttr = BoolAttribute('stretch', True)
        armStretchBlendInputAttr = FloatAttribute('stretchBlend', 0.0, 0.0, 1.0)

        armSettingsAttrGrp = AttributeGroup("DisplayInfo_ArmSettings")
        armIKCtrl.addAttributeGroup(armSettingsAttrGrp)
        armSettingsAttrGrp.addAttribute(armDebugInputAttr)
        armSettingsAttrGrp.addAttribute(armBone1LenInputAttr)
        armSettingsAttrGrp.addAttribute(armBone2LenInputAttr)
        armSettingsAttrGrp.addAttribute(armFkikInputAttr)
        armSettingsAttrGrp.addAttribute(armSoftIKInputAttr)
        armSettingsAttrGrp.addAttribute(armSoftDistInputAttr)
        armSettingsAttrGrp.addAttribute(armStretchInputAttr)
        armSettingsAttrGrp.addAttribute(armStretchBlendInputAttr)

        # UpV
        upVXfo = xfoFromDirAndUpV(bicepPosition, wristPosition, forearmPosition)
        upVXfo.tr.copy(forearmPosition)
        upVOffset = Vec3(0, 0, 5)
        upVOffset = upVXfo.transformVector(upVOffset)

        armUpVCtrl = TriangleControl('UpV')
        armUpVCtrl.xfo.tr.copy(upVOffset)
        armUpVCtrl.alignOnZAxis()
        armUpVCtrl.rotatePoints(180, 0, 0)
        armUpVCtrl.setColor(ctrlColor)

        armUpVCtrlSrtBuffer = SrtBuffer('UpV')
        self.addChild(armUpVCtrlSrtBuffer)
        armUpVCtrlSrtBuffer.xfo.tr.copy(upVOffset)
        armUpVCtrlSrtBuffer.addChild(armUpVCtrl)


        # ==========
        # Deformers
        # ==========
        container = self.getParent().getParent()
        deformersLayer = container.getChildByName('deformers')

        bicepDef = Joint('bicep')
        bicepDef.setComponent(self)

        forearmDef = Joint('forearm')
        forearmDef.setComponent(self)

        wristDef = Joint('wrist')
        wristDef.setComponent(self)

        deformersLayer.addChild(bicepDef)
        deformersLayer.addChild(forearmDef)
        deformersLayer.addChild(wristDef)


        # =====================
        # Create Component I/O
        # =====================
        # Setup component Xfo I/O's
        clavicleEndInput = Locator('clavicleEnd')
        clavicleEndInput.xfo.copy(bicepXfo)

        bicepOutput = Locator('bicep')
        bicepOutput.xfo.copy(bicepXfo)
        forearmOutput = Locator('forearm')
        forearmOutput.xfo.copy(forearmXfo)

        armEndXfo = Xfo()
        armEndXfo.rot = forearmXfo.rot.clone()
        armEndXfo.tr.copy(wristPosition)
        armEndXfoOutput = Locator('armEndXfo')
        armEndXfoOutput.xfo.copy(armEndXfo)

        armEndPosOutput = Locator('armEndPos')
        armEndPosOutput.xfo.copy(armEndXfo)

        # Setup componnent Attribute I/O's
        debugInputAttr = BoolAttribute('debug', True)
        bone1LenInputAttr = FloatAttribute('bone1Len', bicepLen, 0.0, 100.0)
        bone2LenInputAttr = FloatAttribute('bone2Len', forearmLen, 0.0, 100.0)
        fkikInputAttr = FloatAttribute('fkik', 0.0, 0.0, 1.0)
        softIKInputAttr = BoolAttribute('softIK', True)
        softDistInputAttr = FloatAttribute('softDist', 0.5, 0.0, 1.0)
        stretchInputAttr = BoolAttribute('stretch', True)
        stretchBlendInputAttr = FloatAttribute('stretchBlend', 0.0, 0.0, 1.0)
        rightSideInputAttr = BoolAttribute('rightSide', location is 'R')

        # Connect attrs to control attrs
        debugInputAttr.connect(armDebugInputAttr)
        bone1LenInputAttr.connect(armBone1LenInputAttr)
        bone2LenInputAttr.connect(armBone2LenInputAttr)
        fkikInputAttr.connect(armFkikInputAttr)
        softIKInputAttr.connect(armSoftIKInputAttr)
        softDistInputAttr.connect(armSoftDistInputAttr)
        stretchInputAttr.connect(armStretchInputAttr)
        stretchBlendInputAttr.connect(armStretchBlendInputAttr)


        # ==============
        # Constrain I/O
        # ==============
        # Constraint inputs
        armRootInputConstraint = PoseConstraint('_'.join([armIKCtrl.getName(), 'To', clavicleEndInput.getName()]))
        armRootInputConstraint.setMaintainOffset(True)
        armRootInputConstraint.addConstrainer(clavicleEndInput)
        bicepFKCtrlSrtBuffer.addConstraint(armRootInputConstraint)

        # Constraint outputs


        # ==================
        # Add Component I/O
        # ==================
        # Add Xfo I/O's
        self.addInput(clavicleEndInput)
        self.addOutput(bicepOutput)
        self.addOutput(forearmOutput)
        self.addOutput(armEndXfoOutput)
        self.addOutput(armEndPosOutput)

        # Add Attribute I/O's
        self.addInput(debugInputAttr)
        self.addInput(bone1LenInputAttr)
        self.addInput(bone2LenInputAttr)
        self.addInput(fkikInputAttr)
        self.addInput(softIKInputAttr)
        self.addInput(softDistInputAttr)
        self.addInput(stretchInputAttr)
        self.addInput(stretchBlendInputAttr)
        self.addInput(rightSideInputAttr)
Exemple #25
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()
        self.bicepFKCtrl.lockScale(True, True, True)
        self.bicepFKCtrl.lockTranslation(True, True, True)

        # Forearm
        self.forearmFKCtrlSpace = CtrlSpace('forearmFK',
                                            parent=self.bicepFKCtrl)

        self.forearmFKCtrl = Control('forearmFK',
                                     parent=self.forearmFKCtrlSpace,
                                     shape="cube")
        self.forearmFKCtrl.alignOnXAxis()
        self.forearmFKCtrl.lockScale(True, True, True)
        self.forearmFKCtrl.lockTranslation(True, True, True)

        # Arm IK
        self.armIKCtrlSpace = CtrlSpace('IK', parent=self.ctrlCmpGrp)
        self.armIKCtrl = Control('IK',
                                 parent=self.armIKCtrlSpace,
                                 shape="jack")
        self.armIKCtrl.scalePoints(Vec3(2.0, 2.0, 2.0))
        self.armIKCtrl.lockScale(True, True, True)

        # Add Params to IK control
        armSettingsAttrGrp = AttributeGroup("DisplayInfo_ArmSettings",
                                            parent=self.armIKCtrl)
        self.armDebugInputAttr = BoolAttribute('drawDebug',
                                               value=False,
                                               parent=armSettingsAttrGrp)
        self.armBone0LenInputAttr = ScalarAttribute('bone1Len',
                                                    value=0.0,
                                                    parent=armSettingsAttrGrp)
        self.armBone1LenInputAttr = ScalarAttribute('bone2Len',
                                                    value=0.0,
                                                    parent=armSettingsAttrGrp)
        self.armIKBlendInputAttr = ScalarAttribute('fkik',
                                                   value=0.0,
                                                   minValue=0.0,
                                                   maxValue=1.0,
                                                   parent=armSettingsAttrGrp)

        # Util Objects
        self.ikRootPosition = Transform("ikPosition", parent=self.ctrlCmpGrp)

        # Connect Input Attrs
        self.drawDebugInputAttr.connect(self.armDebugInputAttr)

        # Connect Output Attrs
        self.drawDebugOutputAttr.connect(self.armDebugInputAttr)
        self.ikBlendOutputAttr.connect(self.armIKBlendInputAttr)

        # UpV
        self.armUpVCtrlSpace = CtrlSpace('UpV', parent=self.ctrlCmpGrp)
        self.armUpVCtrl = Control('UpV',
                                  parent=self.armUpVCtrlSpace,
                                  shape="triangle")
        self.armUpVCtrl.alignOnZAxis()
        self.armUpVCtrl.rotatePoints(180, 0, 0)
        self.armIKCtrl.lockScale(True, True, True)
        self.armIKCtrl.lockRotation(True, True, True)

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

        self.bicepDef = Joint('bicep', parent=self.defCmpGrp)
        self.bicepDef.setComponent(self)

        self.elbowDef = Joint('elbow', parent=self.defCmpGrp)
        self.elbowDef.setComponent(self)

        self.forearmDef = Joint('forearm', parent=self.defCmpGrp)
        self.forearmDef.setComponent(self)

        self.wristDef = Joint('wrist', parent=self.defCmpGrp)
        self.wristDef.setComponent(self)

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

        self.armUpVCtrlSpaceInputConstraint = PoseConstraint('_'.join([
            self.armUpVCtrlSpace.getName(), 'To',
            self.globalSRTInputTgt.getName()
        ]))
        self.armUpVCtrlSpaceInputConstraint.setMaintainOffset(True)
        self.armUpVCtrlSpaceInputConstraint.addConstrainer(
            self.globalSRTInputTgt)
        self.armUpVCtrlSpace.addConstraint(self.armUpVCtrlSpaceInputConstraint)

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

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

        # Constraint outputs

        # ===============
        # Add Splice Ops
        # ===============
        # Add Splice Op
        self.armSolverKLOperator = KLOperator('ikSolver', 'TwoBoneIKSolver',
                                              'Kraken')
        self.addOperator(self.armSolverKLOperator)

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

        self.armSolverKLOperator.setInput('bone0Len',
                                          self.armBone0LenInputAttr)
        self.armSolverKLOperator.setInput('bone1Len',
                                          self.armBone1LenInputAttr)
        self.armSolverKLOperator.setInput('ikblend', self.armIKBlendInputAttr)
        self.armSolverKLOperator.setInput('rightSide', self.rightSideInputAttr)

        # Add Xfo Inputs
        self.armSolverKLOperator.setInput('root', self.ikRootPosition)
        self.armSolverKLOperator.setInput('bone0FK', self.bicepFKCtrl)
        self.armSolverKLOperator.setInput('bone1FK', self.forearmFKCtrl)
        self.armSolverKLOperator.setInput('ikHandle', self.armIKCtrl)
        self.armSolverKLOperator.setInput('upV', self.armUpVCtrl)

        # Add Xfo Outputs
        self.armSolverKLOperator.setOutput('bone0Out', self.bicepOutputTgt)
        self.armSolverKLOperator.setOutput('bone1Out', self.forearmOutputTgt)
        self.armSolverKLOperator.setOutput('bone2Out', self.wristOutputTgt)
        self.armSolverKLOperator.setOutput('midJointOut', self.elbowOutputTgt)

        # Add Deformer Splice Op
        self.outputsToDeformersKLOp = KLOperator('defConstraint',
                                                 'MultiPoseConstraintSolver',
                                                 'Kraken')
        self.addOperator(self.outputsToDeformersKLOp)

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

        # Add Xfo Inputs
        self.outputsToDeformersKLOp.setInput('constrainers', [
            self.bicepOutputTgt, self.elbowOutputTgt, self.forearmOutputTgt,
            self.wristOutputTgt
        ])

        # Add Xfo Outputs
        self.outputsToDeformersKLOp.setOutput(
            'constrainees',
            [self.bicepDef, self.elbowDef, self.forearmDef, self.wristDef])

        Profiler.getInstance().pop()

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

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

        Return:
        True if successful.

        """

        super(ArmComponentRig, self).loadData(data)

        bicepXfo = data.get('bicepXfo')
        forearmXfo = data.get('forearmXfo')
        wristXfo = data.get('wristXfo')
        upVXfo = data.get('upVXfo')
        bicepLen = data.get('bicepLen')
        forearmLen = data.get('forearmLen')
        bicepFKCtrlSize = data.get('bicepFKCtrlSize')
        forearmFKCtrlSize = data.get('forearmFKCtrlSize')

        self.rootInputTgt.xfo.tr = bicepXfo.tr

        self.bicepFKCtrlSpace.xfo = bicepXfo
        self.bicepFKCtrl.xfo = bicepXfo
        self.bicepFKCtrl.scalePoints(
            Vec3(bicepLen, bicepFKCtrlSize, bicepFKCtrlSize))

        self.forearmFKCtrlSpace.xfo = forearmXfo
        self.forearmFKCtrl.xfo = forearmXfo
        self.forearmFKCtrl.scalePoints(
            Vec3(forearmLen, forearmFKCtrlSize, forearmFKCtrlSize))

        self.ikRootPosition.xfo = bicepXfo

        self.armIKCtrlSpace.xfo.tr = wristXfo.tr
        self.armIKCtrl.xfo.tr = wristXfo.tr

        if self.getLocation() == "R":
            self.armIKCtrl.rotatePoints(0, 90, 0)
        else:
            self.armIKCtrl.rotatePoints(0, -90, 0)

        self.armUpVCtrlSpace.xfo.tr = upVXfo.tr
        self.armUpVCtrl.xfo.tr = upVXfo.tr

        self.rightSideInputAttr.setValue(self.getLocation() is 'R')
        self.armBone0LenInputAttr.setMin(0.0)
        self.armBone0LenInputAttr.setMax(bicepLen * 3.0)
        self.armBone0LenInputAttr.setValue(bicepLen)
        self.armBone1LenInputAttr.setMin(0.0)
        self.armBone1LenInputAttr.setMax(forearmLen * 3.0)
        self.armBone1LenInputAttr.setValue(forearmLen)

        # Outputs
        self.bicepOutputTgt.xfo = bicepXfo
        self.forearmOutputTgt.xfo = forearmXfo
        self.wristOutputTgt.xfo = wristXfo

        # Eval Constraints
        self.ikPosInputConstraint.evaluate()
        self.armIKCtrlSpaceInputConstraint.evaluate()
        self.armUpVCtrlSpaceInputConstraint.evaluate()
        self.armRootInputConstraint.evaluate()
        self.armRootInputConstraint.evaluate()

        # Eval Operators
        self.armSolverKLOperator.evaluate()
        self.outputsToDeformersKLOp.evaluate()
Exemple #26
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.neck01Ctrl = Control('neck01',
                                  parent=self.ctrlCmpGrp,
                                  shape="pin")
        self.neck01Ctrl.setColor("orange")
        self.neck01Ctrl.lockTranslation(True, True, True)
        self.neck01Ctrl.lockScale(True, True, True)

        self.neck01CtrlSpace = self.neck01Ctrl.insertCtrlSpace(name='neck01')

        self.neck02Ctrl = Control('neck02',
                                  parent=self.neck01Ctrl,
                                  shape="pin")
        self.neck02Ctrl.setColor("orange")
        self.neck02Ctrl.lockTranslation(True, True, True)
        self.neck02Ctrl.lockScale(True, True, True)

        self.neck02CtrlSpace = self.neck02Ctrl.insertCtrlSpace(name='neck02')

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

        self.neck01Def = Joint('neck01', parent=self.defCmpGrp)
        self.neck01Def.setComponent(self)

        self.neck02Def = Joint('neck02', parent=self.defCmpGrp)
        self.neck02Def.setComponent(self)

        # ==============
        # Constrain I/O
        # ==============
        # Constraint inputs
        neckInputConstraintName = '_'.join([
            self.neck01CtrlSpace.getName(), 'To',
            self.neckBaseInputTgt.getName()
        ])

        self.neckInputCnstr = self.neck01CtrlSpace.constrainTo(
            self.neckBaseInputTgt,
            'Pose',
            maintainOffset=True,
            name=neckInputConstraintName)

        # Constraint outputs
        neck01OutCnstrName = '_'.join(
            [self.neck01OutputTgt.getName(), 'To',
             self.neck01Ctrl.getName()])

        self.neck01OutCnstr = self.neck01OutputTgt.constrainTo(
            self.neck01Ctrl,
            'Pose',
            maintainOffset=False,
            name=neck01OutCnstrName)

        neck02OutCnstrName = '_'.join(
            [self.neck02OutputTgt.getName(), 'To',
             self.neck02Ctrl.getName()])

        self.neck02OutCnstr = self.neck02OutputTgt.constrainTo(
            self.neck02Ctrl,
            'Pose',
            maintainOffset=False,
            name=neck02OutCnstrName)

        neckEndCnstrName = '_'.join(
            [self.neckEndOutputTgt.getName(), 'To',
             self.neck02Ctrl.getName()])

        self.neckEndCnstr = self.neckEndOutputTgt.constrainTo(
            self.neck02Ctrl,
            'Pose',
            maintainOffset=True,
            name=neckEndCnstrName)

        # ==============
        # Add Operators
        # ==============
        # Add Deformer KL Op
        self.neckDeformerKLOp = KLOperator('neckDeformerKLOp',
                                           'MultiPoseConstraintSolver',
                                           'Kraken')

        self.addOperator(self.neckDeformerKLOp)

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

        # Add Xfo Inputstrl)
        self.neckDeformerKLOp.setInput('constrainers',
                                       [self.neck01Ctrl, self.neck02Ctrl])

        # Add Xfo Outputs
        self.neckDeformerKLOp.setOutput('constrainees',
                                        [self.neck01Def, self.neck02Def])

        Profiler.getInstance().pop()
    def __init__(self, name='limb', parent=None):

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

        # =========
        # Controls
        # =========
        # Upper (FK)
        self.upperFKCtrlSpace = CtrlSpace('upperFK', parent=self.ctrlCmpGrp)
        self.upperFKCtrl = Control('upperFK', parent=self.upperFKCtrlSpace, shape="cube")
        self.upperFKCtrl.alignOnXAxis()

        # Lower (FK)
        self.lowerFKCtrlSpace = CtrlSpace('lowerFK', parent=self.upperFKCtrl)
        self.lowerFKCtrl = Control('lowerFK', parent=self.lowerFKCtrlSpace, shape="cube")
        self.lowerFKCtrl.alignOnXAxis()

        # End (IK)
        self.limbIKCtrlSpace = CtrlSpace('IK', parent=self.ctrlCmpGrp)
        self.limbIKCtrl = Control('IK', parent=self.limbIKCtrlSpace, shape="pin")

        # Add Component Params to IK control
        # TODO: Move these separate control
        limbSettingsAttrGrp = AttributeGroup("DisplayInfo_StretchyLimbSettings", parent=self.limbIKCtrl)
        limbDrawDebugInputAttr = BoolAttribute('drawDebug', value=False, parent=limbSettingsAttrGrp)
        self.limbBone0LenInputAttr = ScalarAttribute('bone0Len', value=1.0, parent=limbSettingsAttrGrp)
        self.limbBone1LenInputAttr = ScalarAttribute('bone1Len', value=1.0, parent=limbSettingsAttrGrp)
        limbIKBlendInputAttr = ScalarAttribute('ikblend', value=1.0, minValue=0.0, maxValue=1.0, parent=limbSettingsAttrGrp)
        limbSoftIKInputAttr = BoolAttribute('softIK', value=True, parent=limbSettingsAttrGrp)
        limbSoftRatioInputAttr = ScalarAttribute('softRatio', value=0.0, minValue=0.0, maxValue=1.0, parent=limbSettingsAttrGrp)
        limbStretchInputAttr = BoolAttribute('stretch', value=True, parent=limbSettingsAttrGrp)
        limbStretchBlendInputAttr = ScalarAttribute('stretchBlend', value=0.0, minValue=0.0, maxValue=1.0, parent=limbSettingsAttrGrp)
        limbSlideInputAttr = ScalarAttribute('slide', value=0.0, minValue=-1.0, maxValue=1.0, parent=limbSettingsAttrGrp)
        limbPinInputAttr = ScalarAttribute('pin', value=0.0, minValue=0.0, maxValue=1.0, parent=limbSettingsAttrGrp)
        self.rightSideInputAttr = BoolAttribute('rightSide', value=False, parent=limbSettingsAttrGrp)

        self.drawDebugInputAttr.connect(limbDrawDebugInputAttr)

        # UpV (IK Pole Vector)
        self.limbUpVCtrlSpace = CtrlSpace('UpV', parent=self.ctrlCmpGrp)
        self.limbUpVCtrl = Control('UpV', parent=self.limbUpVCtrlSpace, shape="triangle")
        self.limbUpVCtrl.alignOnZAxis()

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

        upperDef = Joint('upper', parent=self.defCmpGrp)
        upperDef.setComponent(self)

        lowerDef = Joint('lower', parent=self.defCmpGrp)
        lowerDef.setComponent(self)

        endDef = Joint('end', parent=self.defCmpGrp)
        endDef.setComponent(self)

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

        self.limbUpVCtrlSpaceInputConstraint = PoseConstraint('_'.join([self.limbUpVCtrlSpace.getName(), 'To', self.globalSRTInputTgt.getName()]))
        self.limbUpVCtrlSpaceInputConstraint.setMaintainOffset(True)
        self.limbUpVCtrlSpaceInputConstraint.addConstrainer(self.globalSRTInputTgt)
        self.limbUpVCtrlSpace.addConstraint(self.limbUpVCtrlSpaceInputConstraint)

        self.limbRootInputConstraint = PoseConstraint('_'.join([self.limbIKCtrl.getName(), 'To', self.limbParentInputTgt.getName()]))
        self.limbRootInputConstraint.setMaintainOffset(True)
        self.limbRootInputConstraint.addConstrainer(self.limbParentInputTgt)
        self.upperFKCtrlSpace.addConstraint(self.limbRootInputConstraint)

        # ===============
        # Add Splice Ops
        # ===============
        # Add StretchyLimb Splice Op
        self.limbIKKLOp = KLOperator('limbKLOp', 'TwoBoneStretchyIKSolver', 'Kraken')
        self.addOperator(self.limbIKKLOp)

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

        self.limbIKKLOp.setInput('bone0Len', self.limbBone0LenInputAttr)
        self.limbIKKLOp.setInput('bone1Len', self.limbBone1LenInputAttr)
        self.limbIKKLOp.setInput('ikblend', limbIKBlendInputAttr)
        self.limbIKKLOp.setInput('softIK', limbSoftIKInputAttr)
        self.limbIKKLOp.setInput('softRatio', limbSoftRatioInputAttr)
        self.limbIKKLOp.setInput('stretch', limbStretchInputAttr)
        self.limbIKKLOp.setInput('stretchBlend', limbStretchBlendInputAttr)
        self.limbIKKLOp.setInput('slide', limbSlideInputAttr)
        self.limbIKKLOp.setInput('pin', limbPinInputAttr)
        self.limbIKKLOp.setInput('rightSide', self.rightSideInputAttr)

        # Add Xfo Inputs
        self.limbIKKLOp.setInput('root', self.limbParentInputTgt)
        self.limbIKKLOp.setInput('bone0FK', self.upperFKCtrl)
        self.limbIKKLOp.setInput('bone1FK', self.lowerFKCtrl)
        self.limbIKKLOp.setInput('ikHandle', self.limbIKCtrl)
        self.limbIKKLOp.setInput('upV', self.limbUpVCtrl)

        # Add Xfo Outputs
        self.limbIKKLOp.setOutput('bone0Out', self.limbUpperOutputTgt)
        self.limbIKKLOp.setOutput('bone1Out', self.limbLowerOutputTgt)
        self.limbIKKLOp.setOutput('bone2Out', self.limbEndOutputTgt)

        # =====================
        # Connect the deformers
        # =====================

        # Add StretchyLimb Deformer Splice Op
        self.outputsToDeformersKLOp = KLOperator('limbDeformerKLOp', 'MultiPoseConstraintSolver', 'Kraken')
        self.addOperator(self.outputsToDeformersKLOp)

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

        # Add Xfo Inputs
        self.outputsToDeformersKLOp.setInput('constrainers', [self.limbUpperOutputTgt, self.limbLowerOutputTgt, self.limbEndOutputTgt])

        # Add Xfo Outputs
        self.outputsToDeformersKLOp.setOutput('constrainees', [upperDef, lowerDef, endDef])

        Profiler.getInstance().pop()
Exemple #28
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.bezierSpineKLOp = KLOperator("spineKLOp", "BezierSpineSolver", "Kraken")
        self.addOperator(self.bezierSpineKLOp)

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

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

        # Add Xfo Outputs
        self.bezierSpineKLOp.setOutput("outputs", self.spineOutputs)

        # Add Deformer Splice Op
        self.deformersToOutputsKLOp = KLOperator("spineDeformerKLOp", "MultiPoseConstraintSolver", "Kraken")
        self.addOperator(self.deformersToOutputsKLOp)

        # Add Att Inputs
        self.deformersToOutputsKLOp.setInput("drawDebug", self.drawDebugInputAttr)
        self.deformersToOutputsKLOp.setInput("rigScale", self.rigScaleInputAttr)

        # Add Xfo Outputs
        self.deformersToOutputsKLOp.setInput("constrainers", self.spineOutputs)

        # Add Xfo Outputs
        self.deformersToOutputsKLOp.setOutput("constrainees", self.deformerJoints)

        # Add Pelvis Splice Op
        self.pelvisDefKLOp = KLOperator("pelvisDeformerKLOp", "PoseConstraintSolver", "Kraken")
        self.addOperator(self.pelvisDefKLOp)

        # Add Att Inputs
        self.pelvisDefKLOp.setInput("drawDebug", self.drawDebugInputAttr)
        self.pelvisDefKLOp.setInput("rigScale", self.rigScaleInputAttr)

        # Add Xfo Inputs
        self.pelvisDefKLOp.setInput("constrainer", self.pelvisOutputTgt)

        # Add Xfo Outputs
        self.pelvisDefKLOp.setOutput("constrainee", pelvisDef)

        Profiler.getInstance().pop()
Exemple #29
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")
        self.cogCtrl.lockScale(True, True, True)

        # 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))
        self.spine01Ctrl.lockScale(True, True, True)

        # 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))
        self.spine02Ctrl.lockScale(True, True, True)
        self.spine02Ctrl.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))
        self.spine04Ctrl.lockScale(True, True, True)

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

        # Pelvis
        self.pelvisCtrlSpace = CtrlSpace('pelvis', parent=self.spine01Ctrl)
        self.pelvisCtrl = Control('pelvis', parent=self.pelvisCtrlSpace, shape="cube")
        self.pelvisCtrl.alignOnYAxis(negative=True)
        self.pelvisCtrl.scalePoints(Vec3(4.0, 0.375, 3.75))
        self.pelvisCtrl.translatePoints(Vec3(0.0, -0.5, -0.25))
        self.pelvisCtrl.lockTranslation(True, True, True)
        self.pelvisCtrl.lockScale(True, True, True)
        self.pelvisCtrl.setColor("blueLightMuted")


        # ==========
        # Deformers
        # ==========
        deformersLayer = self.getOrCreateLayer('deformers')
        self.defCmpGrp = ComponentGroup(self.getName(), self, parent=deformersLayer)
        self.addItem('defCmpGrp', self.defCmpGrp)
        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.globalSRTInputTgt.getName()]))
        self.spineSrtInputConstraint.addConstrainer(self.globalSRTInputTgt)
        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.bezierSpineKLOp = KLOperator('spineKLOp', 'BezierSpineSolver', 'Kraken')
        self.addOperator(self.bezierSpineKLOp)

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

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

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

        # Add Deformer Splice Op
        self.deformersToOutputsKLOp = KLOperator('spineDeformerKLOp', 'MultiPoseConstraintSolver', 'Kraken')
        self.addOperator(self.deformersToOutputsKLOp)

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

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

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

        # Add Pelvis Splice Op
        self.pelvisDefKLOp = KLOperator('pelvisDeformerKLOp', 'PoseConstraintSolver', 'Kraken')
        self.addOperator(self.pelvisDefKLOp)

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

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

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


        Profiler.getInstance().pop()
Exemple #30
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()
Exemple #31
0
    def __init__(self, name='head', 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)
        self.addItem('defCmpGrp', self.defCmpGrp)

        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 Operators
        # ==============

        # Add Aim Canvas Op
        # =================
        self.headAimCanvasOp = CanvasOperator('headAimCanvasOp', 'Kraken.Solvers.DirectionConstraintSolver')
        self.addOperator(self.headAimCanvasOp)

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

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

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

        # Add Deformer KL Op
        # ==================
        self.deformersToOutputsKLOp = KLOperator('headDeformerKLOp', 'MultiPoseConstraintSolver', 'Kraken')
        self.addOperator(self.deformersToOutputsKLOp)

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

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

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

        Profiler.getInstance().pop()
Exemple #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()
        self.bicepFKCtrl.lockScale(True, True, True)
        self.bicepFKCtrl.lockTranslation(True, True, True)

        # Forearm
        self.forearmFKCtrlSpace = CtrlSpace('forearmFK',
                                            parent=self.bicepFKCtrl)

        self.forearmFKCtrl = Control('forearmFK',
                                     parent=self.forearmFKCtrlSpace,
                                     shape="cube")
        self.forearmFKCtrl.alignOnXAxis()
        self.forearmFKCtrl.lockScale(True, True, True)
        self.forearmFKCtrl.lockTranslation(True, True, True)

        # Arm IK
        self.armIKCtrlSpace = CtrlSpace('IK', parent=self.ctrlCmpGrp)
        self.armIKCtrl = Control('IK',
                                 parent=self.armIKCtrlSpace,
                                 shape="jack")
        self.armIKCtrl.scalePoints(Vec3(2.0, 2.0, 2.0))
        self.armIKCtrl.lockScale(True, True, True)

        # Add Params to IK control
        armSettingsAttrGrp = AttributeGroup("DisplayInfo_ArmSettings",
                                            parent=self.armIKCtrl)
        self.armDebugInputAttr = BoolAttribute('drawDebug',
                                               value=False,
                                               parent=armSettingsAttrGrp)
        self.armBone0LenInputAttr = ScalarAttribute('bone1Len',
                                                    value=0.0,
                                                    parent=armSettingsAttrGrp)
        self.armBone1LenInputAttr = ScalarAttribute('bone2Len',
                                                    value=0.0,
                                                    parent=armSettingsAttrGrp)
        self.armIKBlendInputAttr = ScalarAttribute('fkik',
                                                   value=0.0,
                                                   minValue=0.0,
                                                   maxValue=1.0,
                                                   parent=armSettingsAttrGrp)

        # Util Objects
        self.ikRootPosition = Transform("ikPosition", parent=self.ctrlCmpGrp)

        # Connect Input Attrs
        self.drawDebugInputAttr.connect(self.armDebugInputAttr)

        # Connect Output Attrs
        self.drawDebugOutputAttr.connect(self.armDebugInputAttr)
        self.ikBlendOutputAttr.connect(self.armIKBlendInputAttr)

        # UpV
        self.armUpVCtrlSpace = CtrlSpace('UpV', parent=self.ctrlCmpGrp)
        self.armUpVCtrl = Control('UpV',
                                  parent=self.armUpVCtrlSpace,
                                  shape="triangle")
        self.armUpVCtrl.alignOnZAxis()
        self.armUpVCtrl.rotatePoints(180, 0, 0)
        self.armIKCtrl.lockScale(True, True, True)
        self.armIKCtrl.lockRotation(True, True, True)

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

        self.bicepDef = Joint('bicep', parent=self.defCmpGrp)
        self.bicepDef.setComponent(self)

        self.elbowDef = Joint('elbow', parent=self.defCmpGrp)
        self.elbowDef.setComponent(self)

        self.forearmDef = Joint('forearm', parent=self.defCmpGrp)
        self.forearmDef.setComponent(self)

        self.wristDef = Joint('wrist', parent=self.defCmpGrp)
        self.wristDef.setComponent(self)

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

        self.armUpVCtrlSpaceInputConstraint = PoseConstraint('_'.join([
            self.armUpVCtrlSpace.getName(), 'To',
            self.globalSRTInputTgt.getName()
        ]))
        self.armUpVCtrlSpaceInputConstraint.setMaintainOffset(True)
        self.armUpVCtrlSpaceInputConstraint.addConstrainer(
            self.globalSRTInputTgt)
        self.armUpVCtrlSpace.addConstraint(self.armUpVCtrlSpaceInputConstraint)

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

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

        # Constraint outputs

        # ===============
        # Add Splice Ops
        # ===============
        # Add Splice Op
        self.armSolverKLOperator = KLOperator('ikSolver', 'TwoBoneIKSolver',
                                              'Kraken')
        self.addOperator(self.armSolverKLOperator)

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

        self.armSolverKLOperator.setInput('bone0Len',
                                          self.armBone0LenInputAttr)
        self.armSolverKLOperator.setInput('bone1Len',
                                          self.armBone1LenInputAttr)
        self.armSolverKLOperator.setInput('ikblend', self.armIKBlendInputAttr)
        self.armSolverKLOperator.setInput('rightSide', self.rightSideInputAttr)

        # Add Xfo Inputs
        self.armSolverKLOperator.setInput('root', self.ikRootPosition)
        self.armSolverKLOperator.setInput('bone0FK', self.bicepFKCtrl)
        self.armSolverKLOperator.setInput('bone1FK', self.forearmFKCtrl)
        self.armSolverKLOperator.setInput('ikHandle', self.armIKCtrl)
        self.armSolverKLOperator.setInput('upV', self.armUpVCtrl)

        # Add Xfo Outputs
        self.armSolverKLOperator.setOutput('bone0Out', self.bicepOutputTgt)
        self.armSolverKLOperator.setOutput('bone1Out', self.forearmOutputTgt)
        self.armSolverKLOperator.setOutput('bone2Out', self.wristOutputTgt)
        self.armSolverKLOperator.setOutput('midJointOut', self.elbowOutputTgt)

        # Add Deformer Splice Op
        self.outputsToDeformersKLOp = KLOperator('defConstraint',
                                                 'MultiPoseConstraintSolver',
                                                 'Kraken')
        self.addOperator(self.outputsToDeformersKLOp)

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

        # Add Xfo Inputs
        self.outputsToDeformersKLOp.setInput('constrainers', [
            self.bicepOutputTgt, self.elbowOutputTgt, self.forearmOutputTgt,
            self.wristOutputTgt
        ])

        # Add Xfo Outputs
        self.outputsToDeformersKLOp.setOutput(
            'constrainees',
            [self.bicepDef, self.elbowDef, self.forearmDef, self.wristDef])

        Profiler.getInstance().pop()
Exemple #33
0
    def __init__(self, name='head', parent=None):

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

        # =========
        # Controls
        # =========
        # Head
        self.headCtrlSpace = CtrlSpace('head', parent=self.ctrlCmpGrp)
        self.headCtrl = Control('head',
                                parent=self.headCtrlSpace,
                                shape="circle")
        self.headCtrl.rotatePoints(0, 0, 90)
        self.headCtrl.scalePoints(Vec3(3, 3, 3))
        self.headCtrl.translatePoints(Vec3(0, 1, 0.25))

        # Eye Left
        self.eyeLeftCtrlSpace = CtrlSpace('eyeLeft', parent=self.headCtrl)
        self.eyeLeftCtrl = Control('eyeLeft',
                                   parent=self.eyeLeftCtrlSpace,
                                   shape="sphere")
        self.eyeLeftCtrl.scalePoints(Vec3(0.5, 0.5, 0.5))
        self.eyeLeftCtrl.setColor("blueMedium")

        # Eye Right
        self.eyeRightCtrlSpace = CtrlSpace('eyeRight', parent=self.headCtrl)
        self.eyeRightCtrl = Control('eyeRight',
                                    parent=self.eyeRightCtrlSpace,
                                    shape="sphere")
        self.eyeRightCtrl.scalePoints(Vec3(0.5, 0.5, 0.5))
        self.eyeRightCtrl.setColor("blueMedium")

        # Jaw
        self.jawCtrlSpace = CtrlSpace('jawCtrlSpace', parent=self.headCtrl)
        self.jawCtrl = Control('jaw', parent=self.jawCtrlSpace, shape="cube")
        self.jawCtrl.alignOnYAxis(negative=True)
        self.jawCtrl.alignOnZAxis()
        self.jawCtrl.scalePoints(Vec3(1.45, 0.65, 1.25))
        self.jawCtrl.translatePoints(Vec3(0, -0.25, 0))
        self.jawCtrl.setColor("orange")

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

        headDef = Joint('head', parent=defCmpGrp)
        headDef.setComponent(self)

        jawDef = Joint('jaw', parent=defCmpGrp)
        jawDef.setComponent(self)

        eyeLeftDef = Joint('eyeLeft', parent=defCmpGrp)
        eyeLeftDef.setComponent(self)

        eyeRightDef = Joint('eyeRight', parent=defCmpGrp)
        eyeRightDef.setComponent(self)

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

        # # Constraint outputs
        headOutputConstraint = PoseConstraint('_'.join(
            [self.headOutputTgt.getName(), 'To',
             self.headCtrl.getName()]))
        headOutputConstraint.addConstrainer(self.headCtrl)
        self.headOutputTgt.addConstraint(headOutputConstraint)

        jawOutputConstraint = PoseConstraint('_'.join(
            [self.jawOutputTgt.getName(), 'To',
             self.jawCtrl.getName()]))
        jawOutputConstraint.addConstrainer(self.jawCtrl)
        self.jawOutputTgt.addConstraint(jawOutputConstraint)

        eyeLOutputConstraint = PoseConstraint('_'.join(
            [self.eyeLOutputTgt.getName(), 'To',
             self.eyeLeftCtrl.getName()]))
        eyeLOutputConstraint.addConstrainer(self.eyeLeftCtrl)
        self.eyeLOutputTgt.addConstraint(eyeLOutputConstraint)

        eyeROutputConstraint = PoseConstraint('_'.join(
            [self.eyeROutputTgt.getName(), 'To',
             self.eyeRightCtrl.getName()]))
        eyeROutputConstraint.addConstrainer(self.eyeRightCtrl)
        self.eyeROutputTgt.addConstraint(eyeROutputConstraint)

        # ==================
        # Add Component I/O
        # ==================
        # Add Xfo I/O's
        # self.addInput(self.headBaseInputTgt)

        # self.addOutput(self.headOutputTgt)
        # self.addOutput(self.jawOutputTgt)
        # self.addOutput(self.eyeLOutputTgt)
        # self.addOutput(self.eyeROutputTgt)

        # Add Attribute I/O's
        # self.addInput(self.drawDebugInputAttr)

        # ===============
        # Add Splice Ops
        # ===============
        # Add Deformer Splice Op
        # spliceOp = SpliceOperator('headDeformerSpliceOp', 'HeadConstraintSolver', 'KrakenHeadConstraintSolver')
        # self.addOperator(spliceOp)

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

        # # Add Xfo Inputstrl)
        # spliceOp.setInput('headConstrainer', self.headOutputTgt)
        # spliceOp.setInput('jawConstrainer', self.jawOutputTgt)
        # spliceOp.setInput('eyeLeftConstrainer', self.eyeLOutputTgt)
        # spliceOp.setInput('eyeRightConstrainer', self.eyeROutputTgt)

        # # Add Xfo Outputs
        # spliceOp.setOutput('headDeformer', headDef)
        # spliceOp.setOutput('jawDeformer', jawDef)
        # spliceOp.setOutput('eyeLeftDeformer', eyeLeftDef)
        # spliceOp.setOutput('eyeRightDeformer', eyeRightDef)

        Profiler.getInstance().pop()
Exemple #34
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()
Exemple #35
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 = KLOperator('armKLOp', 'TwoBoneIKSolver', 'Kraken')
        self.addOperator(self.spliceOp)

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

        self.spliceOp.setInput('bone0Len', self.armBone0LenInputAttr)
        self.spliceOp.setInput('bone1Len', self.armBone1LenInputAttr)
        self.spliceOp.setInput('ikblend', armIKBlendInputAttr)
        self.spliceOp.setInput('softIK', armSoftIKInputAttr)
        self.spliceOp.setInput('softDist', armSoftDistInputAttr)
        self.spliceOp.setInput('stretch', armStretchInputAttr)
        self.spliceOp.setInput('stretchBlend', armStretchBlendInputAttr)
        self.spliceOp.setInput('rightSide', self.rightSideInputAttr)

        # Add Xfo Inputs
        self.spliceOp.setInput('root', self.clavicleEndInputTgt)
        self.spliceOp.setInput('bone0FK', self.bicepFKCtrl)
        self.spliceOp.setInput('bone1FK', self.forearmFKCtrl)
        self.spliceOp.setInput('ikHandle', self.armIKCtrl)
        self.spliceOp.setInput('upV', self.armUpVCtrl)

        # Add Xfo Outputs
        self.spliceOp.setOutput('bone0Out', self.bicepOutputTgt)
        self.spliceOp.setOutput('bone1Out', self.forearmOutputTgt)
        self.spliceOp.setOutput('bone2Out', self.armEndXfoOutputTgt)

        # Add Deformer Splice Op
        self.outputsToDeformersKLOp = KLOperator('armDeformerKLOp',
                                                 'MultiPoseConstraintSolver',
                                                 'Kraken')
        self.addOperator(self.outputsToDeformersKLOp)

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

        # Add Xfo Inputs
        self.outputsToDeformersKLOp.setInput('constrainers', [
            self.bicepOutputTgt, self.forearmOutputTgt,
            self.armEndXfoOutputTgt, self.handOutputTgt
        ])

        # Add Xfo Outputs
        self.outputsToDeformersKLOp.setOutput(
            'constrainees', [bicepDef, forearmDef, wristDef, handDef])

        Profiler.getInstance().pop()
    def __init__(self, name='SimpleControl', parent=None):

        Profiler.getInstance().push("Construct Simple Control Rig Component:" +
                                    name)
        super(SimpleControlComponentRig, self).__init__(name, parent)

        # =========
        # Controls
        # =========
        # Add Controls
        self.mainCtrl = Control('main', shape='square', parent=self.ctrlCmpGrp)
        self.mainCtrlSpace = self.mainCtrl.insertCtrlSpace()
        self.mainCtrl.lockScale(x=True, y=True, z=True)

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

        self.rigScaleOutputAttr.connect(self.rigScaleAttr)

        # ==========
        # Deformers
        # ==========
        deformersLayer = self.getOrCreateLayer('deformers')
        self.defCmpGrp = ComponentGroup(self.getName(),
                                        self,
                                        parent=deformersLayer)
        self.addItem('defCmpGrp', self.defCmpGrp)
        self.mainDef = Joint('main', parent=self.defCmpGrp)
        self.mainDef.setComponent(self)

        # ==============
        # Constrain I/O
        # ==============
        # Constrain inputs
        self.mainInputConstraint = PoseConstraint('_'.join(
            [self.mainCtrlSpace.getName(), 'To',
             self.mainInputTgt.getName()]))
        self.mainInputConstraint.setMaintainOffset(True)
        self.mainInputConstraint.addConstrainer(self.mainInputTgt)
        self.mainCtrlSpace.addConstraint(self.mainInputConstraint)

        # Constrain outputs
        self.mainOutputConstraint = PoseConstraint('_'.join(
            [self.outputTgt.getName(), 'To',
             self.mainCtrl.getName()]))
        self.mainOutputConstraint.addConstrainer(self.mainCtrl)
        self.outputTgt.addConstraint(self.mainOutputConstraint)

        # Constrain deformers
        self.mainDefConstraint = PoseConstraint('_'.join(
            [self.mainDef.getName(), 'To',
             self.mainCtrl.getName()]))
        self.mainDefConstraint.addConstrainer(self.mainCtrl)
        self.mainDef.addConstraint(self.mainDefConstraint)

        # ===============
        # Add Canvas Ops
        # ===============

        Profiler.getInstance().pop()
Exemple #37
0
    def __init__(self, name='head', parent=None):

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


        # =========
        # Controls
        # =========
        # Head
        self.headCtrl = Control('head', parent=self.ctrlCmpGrp, shape='circle')
        self.headCtrl.lockScale(x=True, y=True, z=True)
        self.headCtrl.lockTranslation(x=True, y=True, z=True)
        self.headCtrlSpace = self.headCtrl.insertCtrlSpace()
        self.headCtrl.rotatePoints(0, 0, 90)
        self.headCtrl.scalePoints(Vec3(3, 3, 3))
        self.headCtrl.translatePoints(Vec3(0, 1, 0.25))

        # Eye Left
        self.eyeLeftCtrl = Control('eyeLeft', parent=self.ctrlCmpGrp, shape='sphere')
        self.eyeLeftCtrl.lockScale(x=True, y=True, z=True)
        self.eyeLeftCtrl.lockTranslation(x=True, y=True, z=True)
        self.eyeLeftCtrlSpace = self.eyeLeftCtrl.insertCtrlSpace()
        self.eyeLeftCtrl.rotatePoints(0, 90, 0)
        self.eyeLeftCtrl.scalePoints(Vec3(0.5, 0.5, 0.5))
        self.eyeLeftCtrl.setColor('blueMedium')

        # Eye Right
        self.eyeRightCtrl = Control('eyeRight', parent=self.ctrlCmpGrp, shape='sphere')
        self.eyeRightCtrl.lockScale(x=True, y=True, z=True)
        self.eyeRightCtrl.lockTranslation(x=True, y=True, z=True)
        self.eyeRightCtrlSpace = self.eyeRightCtrl.insertCtrlSpace()
        self.eyeRightCtrl.rotatePoints(0, 90, 0)
        self.eyeRightCtrl.scalePoints(Vec3(0.5, 0.5, 0.5))
        self.eyeRightCtrl.setColor('blueMedium')

        # LookAt Control
        self.lookAtCtrl = Control('lookAt', parent=self.ctrlCmpGrp, shape='square')
        self.lookAtCtrl.lockScale(x=True, y=True, z=True)
        self.lookAtCtrl.rotatePoints(90, 0, 0)
        self.lookAtCtrlSpace = self.lookAtCtrl.insertCtrlSpace()

        self.eyeLeftBase = Transform('eyeLeftBase', parent=self.headCtrl)
        self.eyeRightBase = Transform('eyeRightBase', parent=self.headCtrl)
        self.eyeLeftUpV = Transform('eyeLeftUpV', parent=self.headCtrl)
        self.eyeRightUpV = Transform('eyeRightUpV', parent=self.headCtrl)
        self.eyeLeftAtV = Transform('eyeLeftAtV', parent=self.lookAtCtrl)
        self.eyeRightAtV = Transform('eyeRightAtV', parent=self.lookAtCtrl)

        # Jaw
        self.jawCtrl = Control('jaw', parent=self.headCtrl, shape='cube')
        self.jawCtrlSpace = self.jawCtrl.insertCtrlSpace()
        self.jawCtrl.lockScale(x=True, y=True, z=True)
        self.jawCtrl.lockTranslation(x=True, y=True, z=True)
        self.jawCtrl.alignOnYAxis(negative=True)
        self.jawCtrl.alignOnZAxis()
        self.jawCtrl.scalePoints(Vec3(1.45, 0.65, 1.25))
        self.jawCtrl.translatePoints(Vec3(0, -0.25, 0))
        self.jawCtrl.setColor('orange')


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

        headDef = Joint('head', parent=self.defCmpGrp)
        headDef.setComponent(self)

        jawDef = Joint('jaw', parent=self.defCmpGrp)
        jawDef.setComponent(self)

        eyeLeftDef = Joint('eyeLeft', parent=self.defCmpGrp)
        eyeLeftDef.setComponent(self)

        eyeRightDef = Joint('eyeRight', parent=self.defCmpGrp)
        eyeRightDef.setComponent(self)


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

        # Constraint outputs
        self.headOutputConstraint = PoseConstraint('_'.join([self.headOutputTgt.getName(), 'To', self.headCtrl.getName()]))
        self.headOutputConstraint.addConstrainer(self.headCtrl)
        self.headOutputTgt.addConstraint(self.headOutputConstraint)

        self.jawOutputConstraint = PoseConstraint('_'.join([self.jawOutputTgt.getName(), 'To', self.jawCtrl.getName()]))
        self.jawOutputConstraint.addConstrainer(self.jawCtrl)
        self.jawOutputTgt.addConstraint(self.jawOutputConstraint)

        self.eyeLOutputConstraint = PoseConstraint('_'.join([self.eyeLOutputTgt.getName(), 'To', self.eyeLeftCtrl.getName()]))
        self.eyeLOutputConstraint.addConstrainer(self.eyeLeftCtrl)
        self.eyeLOutputTgt.addConstraint(self.eyeLOutputConstraint)

        self.eyeROutputConstraint = PoseConstraint('_'.join([self.eyeROutputTgt.getName(), 'To', self.eyeRightCtrl.getName()]))
        self.eyeROutputConstraint.addConstrainer(self.eyeRightCtrl)
        self.eyeROutputTgt.addConstraint(self.eyeROutputConstraint)

        # Add Eye Left Direction KL Op
        self.eyeLeftDirKLOp = KLOperator('eyeLeftDirKLOp', 'DirectionConstraintSolver', 'Kraken')
        self.addOperator(self.eyeLeftDirKLOp)

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

        # Add Xfo Inputs
        self.eyeLeftDirKLOp.setInput('position', self.eyeLeftBase)
        self.eyeLeftDirKLOp.setInput('upVector', self.eyeLeftUpV)
        self.eyeLeftDirKLOp.setInput('atVector', self.eyeLeftAtV)

        # Add Xfo Outputs
        self.eyeLeftDirKLOp.setOutput('constrainee', self.eyeLeftCtrlSpace)

        # Add Eye Right Direction KL Op
        self.eyeRightDirKLOp = KLOperator('eyeRightDirKLOp', 'DirectionConstraintSolver', 'Kraken')
        self.addOperator(self.eyeRightDirKLOp)

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

        # Add Xfo Inputs
        self.eyeRightDirKLOp.setInput('position', self.eyeRightBase)
        self.eyeRightDirKLOp.setInput('upVector', self.eyeRightUpV)
        self.eyeRightDirKLOp.setInput('atVector', self.eyeRightAtV)

        # Add Xfo Outputs
        self.eyeRightDirKLOp.setOutput('constrainee', self.eyeRightCtrlSpace)


        # Add Deformer Joints KL Op
        self.outputsToDeformersKLOp = KLOperator('headDeformerKLOp', 'MultiPoseConstraintSolver', 'Kraken')
        self.addOperator(self.outputsToDeformersKLOp)

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

        # Add Xfo Inputs
        self.outputsToDeformersKLOp.setInput('constrainers', [self.headOutputTgt, self.jawOutputTgt, self.eyeROutputTgt, self.eyeLOutputTgt])

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

        Profiler.getInstance().pop()
Exemple #38
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()
        self.femurFKCtrl.lockTranslation(True, True, True)
        self.femurFKCtrl.lockScale(True, True, True)

        # Shin
        self.shinFKCtrlSpace = CtrlSpace('shinFK', parent=self.femurFKCtrl)
        self.shinFKCtrl = Control('shinFK', parent=self.shinFKCtrlSpace, shape="cube")
        self.shinFKCtrl.alignOnXAxis()
        self.shinFKCtrl.lockTranslation(True, True, True)
        self.shinFKCtrl.lockScale(True, True, True)

        # IK Handle
        self.legIKCtrlSpace = CtrlSpace('IK', parent=self.ctrlCmpGrp)
        self.legIKCtrl = Control('IK', parent=self.legIKCtrlSpace, shape="pin")
        self.legIKCtrl.lockScale(True, True, True)

        # Add Component Params to IK control
        legSettingsAttrGrp = AttributeGroup("DisplayInfo_LegSettings", parent=self.legIKCtrl)
        legDrawDebugInputAttr = BoolAttribute('drawDebug', value=False, parent=legSettingsAttrGrp)
        self.legRightSideInputAttr = BoolAttribute('rightSide', value=False, parent=legSettingsAttrGrp)
        self.legBone0LenInputAttr = ScalarAttribute('bone0Len', value=1.0, parent=legSettingsAttrGrp)
        self.legBone1LenInputAttr = ScalarAttribute('bone1Len', value=1.0, parent=legSettingsAttrGrp)
        legIKBlendInputAttr = ScalarAttribute('ikblend', value=1.0, minValue=0.0, maxValue=1.0, parent=legSettingsAttrGrp)

        # Util Objects
        self.ikRootPosition = Transform("ikRootPosition", parent=self.ctrlCmpGrp)

        # Connect Input Attrs
        self.drawDebugInputAttr.connect(legDrawDebugInputAttr)

        # Connect Output Attrs
        self.drawDebugOutputAttr.connect(legDrawDebugInputAttr)
        self.ikBlendOutputAttr.connect(legIKBlendInputAttr)

        # UpV
        self.legUpVCtrlSpace = CtrlSpace('UpV', parent=self.ctrlCmpGrp)
        self.legUpVCtrl = Control('UpV', parent=self.legUpVCtrlSpace, shape="triangle")
        self.legUpVCtrl.alignOnZAxis()
        self.legUpVCtrl.lockRotation(True, True, True)
        self.legUpVCtrl.lockScale(True, True, True)


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

        femurDef = Joint('femur', parent=self.defCmpGrp)
        femurDef.setComponent(self)

        kneeDef = Joint('knee', parent=self.defCmpGrp)
        kneeDef.setComponent(self)

        shinDef = Joint('shin', parent=self.defCmpGrp)
        shinDef.setComponent(self)

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

        self.legUpVCtrlSpaceInputConstraint = PoseConstraint('_'.join([self.legUpVCtrlSpace.getName(), 'To', self.globalSRTInputTgt.getName()]))
        self.legUpVCtrlSpaceInputConstraint.setMaintainOffset(True)
        self.legUpVCtrlSpaceInputConstraint.addConstrainer(self.globalSRTInputTgt)
        self.legUpVCtrlSpace.addConstraint(self.legUpVCtrlSpaceInputConstraint)

        self.legRootInputConstraint = PoseConstraint('_'.join([self.femurFKCtrlSpace.getName(), 'To', self.legPelvisInputTgt.getName()]))
        self.legRootInputConstraint.setMaintainOffset(True)
        self.legRootInputConstraint.addConstrainer(self.legPelvisInputTgt)
        self.femurFKCtrlSpace.addConstraint(self.legRootInputConstraint)

        self.ikRootPosInputConstraint = PoseConstraint('_'.join([self.ikRootPosition.getName(), 'To', self.legPelvisInputTgt.getName()]))
        self.ikRootPosInputConstraint.setMaintainOffset(True)
        self.ikRootPosInputConstraint.addConstrainer(self.legPelvisInputTgt)
        self.ikRootPosition.addConstraint(self.ikRootPosInputConstraint)

        # Constraint outputs
        self.legEndFKOutputConstraint = PoseConstraint('_'.join([self.legEndFKOutputTgt.getName(), 'To', self.shinFKCtrl.getName()]))
        self.legEndFKOutputConstraint.setMaintainOffset(True)
        self.legEndFKOutputConstraint.addConstrainer(self.shinFKCtrl)
        self.legEndFKOutputTgt.addConstraint(self.legEndFKOutputConstraint)

        self.ikHandleOutputConstraint = PoseConstraint('_'.join([self.ikHandleOutputTgt.getName(), 'To', self.legIKCtrl.getName()]))
        self.ikHandleOutputConstraint.setMaintainOffset(True)
        self.ikHandleOutputConstraint.addConstrainer(self.legIKCtrl)
        self.ikHandleOutputTgt.addConstraint(self.ikHandleOutputConstraint)


        # ===============
        # Add Splice Ops
        # ===============
        # Add Leg Splice Op
        self.legIKKLOp = KLOperator('legKLOp', 'TwoBoneIKSolver', 'Kraken')
        self.addOperator(self.legIKKLOp)

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

        self.legIKKLOp.setInput('bone0Len', self.legBone0LenInputAttr)
        self.legIKKLOp.setInput('bone1Len', self.legBone1LenInputAttr)
        self.legIKKLOp.setInput('ikblend', legIKBlendInputAttr)
        self.legIKKLOp.setInput('rightSide', self.legRightSideInputAttr)

        # Add Xfo Inputs
        self.legIKKLOp.setInput('root', self.ikRootPosition)
        self.legIKKLOp.setInput('bone0FK', self.femurFKCtrl)
        self.legIKKLOp.setInput('bone1FK', self.shinFKCtrl)
        self.legIKKLOp.setInput('ikHandle', self.legIKTargetInputTgt)
        self.legIKKLOp.setInput('upV', self.legUpVCtrl)

        # Add Xfo Outputs
        self.legIKKLOp.setOutput('bone0Out', self.femurOutputTgt)
        self.legIKKLOp.setOutput('bone1Out', self.shinOutputTgt)
        self.legIKKLOp.setOutput('bone2Out', self.legEndOutputTgt)
        self.legIKKLOp.setOutput('midJointOut', self.kneeOutputTgt)


        # Add Leg Deformer Splice Op
        self.outputsToDeformersKLOp = KLOperator('legDeformerKLOp', 'MultiPoseConstraintSolver', 'Kraken')
        self.addOperator(self.outputsToDeformersKLOp)

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

        # Add Xfo Inputs
        self.outputsToDeformersKLOp.setInput('constrainers', [self.femurOutputTgt, self.kneeOutputTgt, self.shinOutputTgt])

        # Add Xfo Outputs
        self.outputsToDeformersKLOp.setOutput('constrainees', [femurDef, kneeDef, shinDef])

        Profiler.getInstance().pop()
Exemple #39
0
    def __init__(self, name, parent=None, location='M'):
        super(NeckComponent, self).__init__(name, parent, location)

        # Setup component attributes
        defaultAttrGroup = self.getAttributeGroupByIndex(0)
        defaultAttrGroup.addAttribute(BoolAttribute("toggleDebugging", True))

        # Default values
        neckPosition = Vec3(0.0, 16.5572, -0.6915)
        neckUpV = Vec3()
        neckUpV.copy(neckPosition)
        neckUpV = neckUpV.add(Vec3(0.0, 0.0, -1.0)).unit()
        neckEndPosition = Vec3(0.0, 17.4756, -0.421)

        # Calculate Clavicle Xfo
        rootToEnd = neckEndPosition.subtract(neckPosition).unit()
        rootToUpV = neckUpV.subtract(neckPosition).unit()
        bone1ZAxis = rootToUpV.cross(rootToEnd).unit()
        bone1Normal = bone1ZAxis.cross(rootToEnd).unit()
        neckXfo = Xfo()
        neckXfo.setFromVectors(rootToEnd, bone1Normal, bone1ZAxis, neckPosition)

        # Add Guide Controls
        neckCtrlSrtBuffer = SrtBuffer('neck', parent=self)
        neckCtrlSrtBuffer.xfo.copy(neckXfo)

        neckCtrl = PinControl('neck', parent=neckCtrlSrtBuffer)
        neckCtrl.scalePoints(Vec3(1.25, 1.25, 1.25))
        neckCtrl.translatePoints(Vec3(0, 0, -0.5))
        neckCtrl.rotatePoints(90, 0, 90)
        neckCtrl.xfo.copy(neckXfo)
        neckCtrl.setColor("orange")


        # ==========
        # Deformers
        # ==========
        container = self.getParent().getParent()
        deformersLayer = container.getChildByName('deformers')

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


        # =====================
        # Create Component I/O
        # =====================
        # Setup Component Xfo I/O's
        neckEndInput = Locator('neckBase')
        neckEndInput.xfo.copy(neckXfo)
        neckEndOutput = Locator('neckEnd')
        neckEndOutput.xfo.copy(neckXfo)
        neckOutput = Locator('neck')
        neckOutput.xfo.copy(neckXfo)

        # Setup componnent Attribute I/O's
        debugInputAttr = BoolAttribute('debug', True)
        rightSideInputAttr = BoolAttribute('rightSide', location is 'R')


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

        # Constraint outputs
        neckEndConstraint = PoseConstraint('_'.join([neckEndOutput.getName(), 'To', neckCtrl.getName()]))
        neckEndConstraint.addConstrainer(neckCtrl)
        neckEndOutput.addConstraint(neckEndConstraint)


        # ==================
        # Add Component I/O
        # ==================
        # Add Xfo I/O's
        self.addInput(neckEndInput)
        self.addOutput(neckEndOutput)
        self.addOutput(neckOutput)

        # Add Attribute I/O's
        self.addInput(debugInputAttr)
        self.addInput(rightSideInputAttr)
Exemple #40
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()
Exemple #41
0
    def __init__(self, name, parent=None, location='M'):
        super(FootComponent, self).__init__(name, parent, location)

        # =========
        # Controls
        # =========
        # Setup component attributes
        defaultAttrGroup = self.getAttributeGroupByIndex(0)
        defaultAttrGroup.addAttribute(BoolAttribute("toggleDebugging", True))

        # Default values
        if location == 'R':
            ctrlColor = "red"
            footPosition = Vec3(-7.1886, 12.2819, 0.4906)
            footUpV = Vec3(-1.7454, 0.1922, -1.7397)
            footEndPosition = Vec3(-2.0939, 0.4288, 0.0944)
        else:
            ctrlColor = "greenBright"
            footPosition = Vec3(7.1886, 12.2819, 0.4906)
            footUpV = Vec3(1.7454, 0.1922, -1.7397)
            footEndPosition = Vec3(2.0939, 0.4288, 0.0944)

        # Calculate Clavicle Xfo
        rootToEnd = footEndPosition.subtract(footPosition).unit()
        rootToUpV = footUpV.subtract(footPosition).unit()
        bone1ZAxis = rootToEnd.cross(rootToUpV).unit()
        bone1Normal = rootToEnd.cross(bone1ZAxis).unit()
        footXfo = Xfo()

        if location == "R":
            footQuat = Quat(Vec3(0.5695, -0.6377, 0.4190), 0.3053)
            footPos = Vec3(-1.841, 1.1516, -1.237)
        else:
            footQuat = Quat(Vec3(0.6377, -0.5695, 0.3053), 0.4190)
            footPos = Vec3(1.841, 1.1516, -1.237)

        footXfo.rot = footQuat.clone()
        footXfo.tr.copy(footPos)

        # Add Controls
        footCtrlSrtBuffer = SrtBuffer('foot', parent=self)
        footCtrlSrtBuffer.xfo.copy(footXfo)

        footCtrl = CubeControl('foot', parent=footCtrlSrtBuffer)
        footCtrl.alignOnXAxis()
        footCtrl.scalePoints(Vec3(2.5, 1.5, 0.75))
        footCtrl.xfo.copy(footCtrlSrtBuffer.xfo)
        footCtrl.setColor(ctrlColor)

        # Rig Ref objects
        footRefSrt = Locator('footRef', parent=self)
        footRefSrt.xfo.copy(footCtrlSrtBuffer.xfo)


        # Add Component Params to IK control
        footDebugInputAttr = BoolAttribute('debug', True)
        footLinkToWorldInputAttr = FloatAttribute('linkToWorld', 1.0, 0.0, 1.0)

        footSettingsAttrGrp = AttributeGroup("DisplayInfo_HandSettings")
        footCtrl.addAttributeGroup(footSettingsAttrGrp)
        footSettingsAttrGrp.addAttribute(footDebugInputAttr)
        footSettingsAttrGrp.addAttribute(footLinkToWorldInputAttr)


        # ==========
        # Deformers
        # ==========
        container = self.getParent().getParent()
        deformersLayer = container.getChildByName('deformers')

        footDef = Joint('foot')
        footDef.setComponent(self)

        deformersLayer.addChild(footDef)


        # =====================
        # Create Component I/O
        # =====================
        # Setup Component Xfo I/O's
        legEndXfoInput = Locator('legEndXfo')
        legEndXfoInput.xfo.copy(footCtrlSrtBuffer.xfo)
        legEndPosInput = Locator('legEndPos')
        legEndPosInput.xfo.copy(footCtrlSrtBuffer.xfo)

        footEndOutput = Locator('handEnd')
        footEndOutput.xfo.copy(footCtrlSrtBuffer.xfo)
        footOutput = Locator('hand')
        footOutput.xfo.copy(footCtrlSrtBuffer.xfo)

        # Setup componnent Attribute I/O's
        debugInputAttr = BoolAttribute('debug', True)
        rightSideInputAttr = BoolAttribute('rightSide', location is 'R')
        linkToWorldInputAttr = FloatAttribute('linkToWorld', 0.0, 0.0, 1.0)

        # Connect attrs to control attrs
        debugInputAttr.connect(footDebugInputAttr)
        linkToWorldInputAttr.connect(footLinkToWorldInputAttr)


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

        # Constraint outputs
        handConstraint = PoseConstraint('_'.join([footOutput.getName(), 'To', footCtrl.getName()]))
        handConstraint.addConstrainer(footCtrl)
        footOutput.addConstraint(handConstraint)

        handEndConstraint = PoseConstraint('_'.join([footEndOutput.getName(), 'To', footCtrl.getName()]))
        handEndConstraint.addConstrainer(footCtrl)
        footEndOutput.addConstraint(handEndConstraint)


        # ==================
        # Add Component I/O
        # ==================
        # Add Xfo I/O's
        self.addInput(legEndXfoInput)
        self.addInput(legEndPosInput)
        self.addOutput(footOutput)
        self.addOutput(footEndOutput)

        # Add Attribute I/O's
        self.addInput(debugInputAttr)
        self.addInput(rightSideInputAttr)
        self.addInput(linkToWorldInputAttr)
Exemple #42
0
    def __init__(self, name='head', parent=None):

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

        # =========
        # Controls
        # =========
        # Head
        self.headCtrl = Control('head', parent=self.ctrlCmpGrp, shape='circle')
        self.headCtrl.lockScale(x=True, y=True, z=True)
        self.headCtrl.lockTranslation(x=True, y=True, z=True)
        self.headCtrlSpace = self.headCtrl.insertCtrlSpace()
        self.headCtrl.rotatePoints(0, 0, 90)
        self.headCtrl.scalePoints(Vec3(3, 3, 3))
        self.headCtrl.translatePoints(Vec3(0, 1, 0.25))

        # Eye Left
        self.eyeLeftCtrl = Control('eyeLeft',
                                   parent=self.ctrlCmpGrp,
                                   shape='sphere')
        self.eyeLeftCtrl.lockScale(x=True, y=True, z=True)
        self.eyeLeftCtrl.lockTranslation(x=True, y=True, z=True)
        self.eyeLeftCtrlSpace = self.eyeLeftCtrl.insertCtrlSpace()
        self.eyeLeftCtrl.rotatePoints(0, 90, 0)
        self.eyeLeftCtrl.scalePoints(Vec3(0.5, 0.5, 0.5))
        self.eyeLeftCtrl.setColor('blueMedium')

        # Eye Right
        self.eyeRightCtrl = Control('eyeRight',
                                    parent=self.ctrlCmpGrp,
                                    shape='sphere')
        self.eyeRightCtrl.lockScale(x=True, y=True, z=True)
        self.eyeRightCtrl.lockTranslation(x=True, y=True, z=True)
        self.eyeRightCtrlSpace = self.eyeRightCtrl.insertCtrlSpace()
        self.eyeRightCtrl.rotatePoints(0, 90, 0)
        self.eyeRightCtrl.scalePoints(Vec3(0.5, 0.5, 0.5))
        self.eyeRightCtrl.setColor('blueMedium')

        # LookAt Control
        self.lookAtCtrl = Control('lookAt',
                                  parent=self.ctrlCmpGrp,
                                  shape='square')
        self.lookAtCtrl.lockScale(x=True, y=True, z=True)
        self.lookAtCtrl.rotatePoints(90, 0, 0)
        self.lookAtCtrlSpace = self.lookAtCtrl.insertCtrlSpace()

        self.eyeLeftBase = Transform('eyeLeftBase', parent=self.headCtrl)
        self.eyeRightBase = Transform('eyeRightBase', parent=self.headCtrl)
        self.eyeLeftUpV = Transform('eyeLeftUpV', parent=self.headCtrl)
        self.eyeRightUpV = Transform('eyeRightUpV', parent=self.headCtrl)
        self.eyeLeftAtV = Transform('eyeLeftAtV', parent=self.lookAtCtrl)
        self.eyeRightAtV = Transform('eyeRightAtV', parent=self.lookAtCtrl)

        # Jaw
        self.jawCtrl = Control('jaw', parent=self.headCtrl, shape='cube')
        self.jawCtrlSpace = self.jawCtrl.insertCtrlSpace()
        self.jawCtrl.lockScale(x=True, y=True, z=True)
        self.jawCtrl.lockTranslation(x=True, y=True, z=True)
        self.jawCtrl.alignOnYAxis(negative=True)
        self.jawCtrl.alignOnZAxis()
        self.jawCtrl.scalePoints(Vec3(1.45, 0.65, 1.25))
        self.jawCtrl.translatePoints(Vec3(0, -0.25, 0))
        self.jawCtrl.setColor('orange')

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

        headDef = Joint('head', parent=self.defCmpGrp)
        headDef.setComponent(self)

        jawDef = Joint('jaw', parent=self.defCmpGrp)
        jawDef.setComponent(self)

        eyeLeftDef = Joint('eyeLeft', parent=self.defCmpGrp)
        eyeLeftDef.setComponent(self)

        eyeRightDef = Joint('eyeRight', parent=self.defCmpGrp)
        eyeRightDef.setComponent(self)

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

        # Constraint outputs
        self.headOutputConstraint = PoseConstraint('_'.join(
            [self.headOutputTgt.getName(), 'To',
             self.headCtrl.getName()]))
        self.headOutputConstraint.addConstrainer(self.headCtrl)
        self.headOutputTgt.addConstraint(self.headOutputConstraint)

        self.jawOutputConstraint = PoseConstraint('_'.join(
            [self.jawOutputTgt.getName(), 'To',
             self.jawCtrl.getName()]))
        self.jawOutputConstraint.addConstrainer(self.jawCtrl)
        self.jawOutputTgt.addConstraint(self.jawOutputConstraint)

        self.eyeLOutputConstraint = PoseConstraint('_'.join(
            [self.eyeLOutputTgt.getName(), 'To',
             self.eyeLeftCtrl.getName()]))
        self.eyeLOutputConstraint.addConstrainer(self.eyeLeftCtrl)
        self.eyeLOutputTgt.addConstraint(self.eyeLOutputConstraint)

        self.eyeROutputConstraint = PoseConstraint('_'.join(
            [self.eyeROutputTgt.getName(), 'To',
             self.eyeRightCtrl.getName()]))
        self.eyeROutputConstraint.addConstrainer(self.eyeRightCtrl)
        self.eyeROutputTgt.addConstraint(self.eyeROutputConstraint)

        # Add Eye Left Direction KL Op
        self.eyeLeftDirKLOp = KLOperator('eyeLeftDirKLOp',
                                         'DirectionConstraintSolver', 'Kraken')
        self.addOperator(self.eyeLeftDirKLOp)

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

        # Add Xfo Inputs
        self.eyeLeftDirKLOp.setInput('position', self.eyeLeftBase)
        self.eyeLeftDirKLOp.setInput('upVector', self.eyeLeftUpV)
        self.eyeLeftDirKLOp.setInput('atVector', self.eyeLeftAtV)

        # Add Xfo Outputs
        self.eyeLeftDirKLOp.setOutput('constrainee', self.eyeLeftCtrlSpace)

        # Add Eye Right Direction KL Op
        self.eyeRightDirKLOp = KLOperator('eyeRightDirKLOp',
                                          'DirectionConstraintSolver',
                                          'Kraken')
        self.addOperator(self.eyeRightDirKLOp)

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

        # Add Xfo Inputs
        self.eyeRightDirKLOp.setInput('position', self.eyeRightBase)
        self.eyeRightDirKLOp.setInput('upVector', self.eyeRightUpV)
        self.eyeRightDirKLOp.setInput('atVector', self.eyeRightAtV)

        # Add Xfo Outputs
        self.eyeRightDirKLOp.setOutput('constrainee', self.eyeRightCtrlSpace)

        # Add Deformer Joints KL Op
        self.outputsToDeformersKLOp = KLOperator('headDeformerKLOp',
                                                 'MultiPoseConstraintSolver',
                                                 'Kraken')
        self.addOperator(self.outputsToDeformersKLOp)

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

        # Add Xfo Inputs
        self.outputsToDeformersKLOp.setInput('constrainers', [
            self.headOutputTgt, self.jawOutputTgt, self.eyeROutputTgt,
            self.eyeLOutputTgt
        ])

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

        Profiler.getInstance().pop()
Exemple #43
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 = KLOperator('neckDeformerKLOp', '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()
Exemple #44
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()
Exemple #45
0
    def __init__(self, name, parent=None, location='M'):
        super(HeadComponent, self).__init__(name, parent, location)

        # Setup component attributes
        defaultAttrGroup = self.getAttributeGroupByIndex(0)
        defaultAttrGroup.addAttribute(BoolAttribute("toggleDebugging", True))

        # Default values
        headPosition = Vec3(0.0, 17.4756, -0.421)
        headEndPosition = Vec3(0.0, 19.5, -0.421)
        eyeLeftPosition = Vec3(0.3497, 18.0878, 0.6088)
        eyeRightPosition = Vec3(-0.3497, 18.0878, 0.6088)
        jawPosition = Vec3(0.0, 17.613, -0.2731)

        # Head
        headCtrl = CircleControl('head')
        headCtrl.rotatePoints(0, 0, 90)
        headCtrl.scalePoints(Vec3(3, 3, 3))
        headCtrl.translatePoints(Vec3(0, 1, 0.25))
        headCtrl.xfo.tr.copy(headPosition)
        headCtrl.setColor("yellow")

        headCtrlSrtBuffer = SrtBuffer('head')
        self.addChild(headCtrlSrtBuffer)
        headCtrlSrtBuffer.xfo.copy(headCtrl.xfo)
        headCtrlSrtBuffer.addChild(headCtrl)

        # Eye Left
        eyeLeftCtrl = SphereControl('eyeLeft')
        eyeLeftCtrl.scalePoints(Vec3(0.75, 0.75, 0.75))
        eyeLeftCtrl.xfo.tr.copy(eyeLeftPosition)
        eyeLeftCtrl.setColor("blueMedium")

        eyeLeftCtrlSrtBuffer = SrtBuffer('eyeLeft')
        headCtrl.addChild(eyeLeftCtrlSrtBuffer)
        eyeLeftCtrlSrtBuffer.xfo.copy(eyeLeftCtrl.xfo)
        eyeLeftCtrlSrtBuffer.addChild(eyeLeftCtrl)

        # Eye Right
        eyeRightCtrl = SphereControl('eyeRight')
        eyeRightCtrl.scalePoints(Vec3(0.5, 0.5, 0.5))
        eyeRightCtrl.xfo.tr.copy(eyeRightPosition)
        eyeRightCtrl.setColor("blueMedium")

        eyeRightCtrlSrtBuffer = SrtBuffer('eyeRight')
        headCtrl.addChild(eyeRightCtrlSrtBuffer)
        eyeRightCtrlSrtBuffer.xfo.copy(eyeRightCtrl.xfo)
        eyeRightCtrlSrtBuffer.addChild(eyeRightCtrl)

        # Jaw
        jawCtrl = CubeControl('jaw')
        jawCtrl.alignOnYAxis(negative=True)
        jawCtrl.alignOnZAxis()
        jawCtrl.scalePoints(Vec3(1.45, 0.65, 1.25))
        jawCtrl.translatePoints(Vec3(0, -0.25, 0))
        jawCtrl.xfo.tr.copy(jawPosition)
        jawCtrl.setColor("orange")

        jawCtrlSrtBuffer = SrtBuffer('jawSrtBuffer')
        headCtrl.addChild(jawCtrlSrtBuffer)
        jawCtrlSrtBuffer.xfo.copy(jawCtrl.xfo)
        jawCtrlSrtBuffer.addChild(jawCtrl)


        # ==========
        # Deformers
        # ==========
        container = self.getParent().getParent()
        deformersLayer = container.getChildByName('deformers')

        headDef = Joint('head')
        headDef.setComponent(self)

        jawDef = Joint('jaw')
        jawDef.setComponent(self)

        eyeLeftDef = Joint('eyeLeft')
        eyeLeftDef.setComponent(self)

        eyeRightDef = Joint('eyeRight')
        eyeRightDef.setComponent(self)

        deformersLayer.addChild(headDef)
        deformersLayer.addChild(jawDef)
        deformersLayer.addChild(eyeLeftDef)
        deformersLayer.addChild(eyeRightDef)


        # =====================
        # Create Component I/O
        # =====================
        # Setup component Xfo I/O's
        headBaseInput = Locator('headBase')
        headBaseInput.xfo.copy(headCtrl.xfo)

        headOutput = Locator('head')
        headOutput.xfo.copy(headCtrl.xfo)
        jawOutput = Locator('jaw')
        jawOutput.xfo.copy(jawCtrl.xfo)
        eyeLOutput = Locator('eyeL')
        eyeLOutput.xfo.copy(eyeLeftCtrl.xfo)
        eyeROutput = Locator('eyeR')
        eyeROutput.xfo.copy(eyeRightCtrl.xfo)

        # Setup componnent Attribute I/O's
        debugInputAttr = BoolAttribute('debug', True)
        rightSideInputAttr = BoolAttribute('rightSide', location is 'R')


        # ==============
        # Constrain I/O
        # ==============
        # Constraint inputs
        headInputConstraint = PoseConstraint('_'.join([headCtrlSrtBuffer.getName(), 'To', headBaseInput.getName()]))
        headInputConstraint.setMaintainOffset(True)
        headInputConstraint.addConstrainer(headBaseInput)
        headCtrlSrtBuffer.addConstraint(headInputConstraint)

        # Constraint outputs
        headOutputConstraint = PoseConstraint('_'.join([headOutput.getName(), 'To', headCtrl.getName()]))
        headOutputConstraint.setMaintainOffset(True)
        headOutputConstraint.addConstrainer(headCtrl)
        headOutput.addConstraint(headOutputConstraint)

        jawOutputConstraint = PoseConstraint('_'.join([jawOutput.getName(), 'To', jawCtrl.getName()]))
        jawOutputConstraint.setMaintainOffset(True)
        jawOutputConstraint.addConstrainer(jawCtrl)
        jawOutput.addConstraint(jawOutputConstraint)

        eyeLOutputConstraint = PoseConstraint('_'.join([eyeLOutput.getName(), 'To', eyeLeftCtrl.getName()]))
        eyeLOutputConstraint.setMaintainOffset(True)
        eyeLOutputConstraint.addConstrainer(eyeLeftCtrl)
        eyeLOutput.addConstraint(eyeLOutputConstraint)

        eyeROutputConstraint = PoseConstraint('_'.join([eyeROutput.getName(), 'To', eyeRightCtrl.getName()]))
        eyeROutputConstraint.setMaintainOffset(True)
        eyeROutputConstraint.addConstrainer(eyeRightCtrl)
        eyeROutput.addConstraint(eyeROutputConstraint)


        # ==================
        # Add Component I/O
        # ==================
        # Add Xfo I/O's
        self.addInput(headBaseInput)

        self.addOutput(headOutput)
        self.addOutput(jawOutput)
        self.addOutput(eyeLOutput)
        self.addOutput(eyeROutput)

        # Add Attribute I/O's
        self.addInput(debugInputAttr)
        self.addInput(rightSideInputAttr)
Exemple #46
0
class NeckComponentRig(NeckComponent):
    """Neck Component"""
    def __init__(self, name="neck", parent=None):

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

        # =========
        # Controls
        # =========
        # Neck
        self.neck01Ctrl = Control('neck01',
                                  parent=self.ctrlCmpGrp,
                                  shape="pin")
        self.neck01Ctrl.setColor("orange")
        self.neck01Ctrl.lockTranslation(True, True, True)
        self.neck01Ctrl.lockScale(True, True, True)

        self.neck01CtrlSpace = self.neck01Ctrl.insertCtrlSpace(name='neck01')

        self.neck02Ctrl = Control('neck02',
                                  parent=self.neck01Ctrl,
                                  shape="pin")
        self.neck02Ctrl.setColor("orange")
        self.neck02Ctrl.lockTranslation(True, True, True)
        self.neck02Ctrl.lockScale(True, True, True)

        self.neck02CtrlSpace = self.neck02Ctrl.insertCtrlSpace(name='neck02')

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

        self.neck01Def = Joint('neck01', parent=self.defCmpGrp)
        self.neck01Def.setComponent(self)

        self.neck02Def = Joint('neck02', parent=self.defCmpGrp)
        self.neck02Def.setComponent(self)

        # ==============
        # Constrain I/O
        # ==============
        # Constraint inputs
        neckInputConstraintName = '_'.join([
            self.neck01CtrlSpace.getName(), 'To',
            self.neckBaseInputTgt.getName()
        ])

        self.neckInputCnstr = self.neck01CtrlSpace.constrainTo(
            self.neckBaseInputTgt,
            'Pose',
            maintainOffset=True,
            name=neckInputConstraintName)

        # Constraint outputs
        neck01OutCnstrName = '_'.join(
            [self.neck01OutputTgt.getName(), 'To',
             self.neck01Ctrl.getName()])

        self.neck01OutCnstr = self.neck01OutputTgt.constrainTo(
            self.neck01Ctrl,
            'Pose',
            maintainOffset=False,
            name=neck01OutCnstrName)

        neck02OutCnstrName = '_'.join(
            [self.neck02OutputTgt.getName(), 'To',
             self.neck02Ctrl.getName()])

        self.neck02OutCnstr = self.neck02OutputTgt.constrainTo(
            self.neck02Ctrl,
            'Pose',
            maintainOffset=False,
            name=neck02OutCnstrName)

        neckEndCnstrName = '_'.join(
            [self.neckEndOutputTgt.getName(), 'To',
             self.neck02Ctrl.getName()])

        self.neckEndCnstr = self.neckEndOutputTgt.constrainTo(
            self.neck02Ctrl,
            'Pose',
            maintainOffset=True,
            name=neckEndCnstrName)

        # ==============
        # Add Operators
        # ==============
        # Add Deformer KL Op
        self.neckDeformerKLOp = KLOperator('neckDeformerKLOp',
                                           'MultiPoseConstraintSolver',
                                           'Kraken')

        self.addOperator(self.neckDeformerKLOp)

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

        # Add Xfo Inputstrl)
        self.neckDeformerKLOp.setInput('constrainers',
                                       [self.neck01Ctrl, self.neck02Ctrl])

        # Add Xfo Outputs
        self.neckDeformerKLOp.setOutput('constrainees',
                                        [self.neck01Def, self.neck02Def])

        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(NeckComponentRig, self).loadData(data)
        neckXfo = data.get('neckXfo')
        neckCrvData = data.get('neckCrvData')
        neckMidXfo = data.get('neckMidXfo')
        neckMidCrvData = data.get('neckMidCrvData')
        neckEndXfo = data.get('neckEndXfo')

        self.neck01CtrlSpace.xfo = neckXfo
        self.neck01Ctrl.xfo = neckXfo
        self.neck01Ctrl.setCurveData(neckCrvData)

        self.neck02CtrlSpace.xfo = neckMidXfo
        self.neck02Ctrl.xfo = neckMidXfo
        self.neck02Ctrl.setCurveData(neckMidCrvData)

        # ============
        # Set IO Xfos
        # ============
        self.neckBaseInputTgt.xfo = neckXfo
        self.neck01OutputTgt.xfo = neckXfo
        self.neck02OutputTgt.xfo = neckMidXfo
        self.neckEndOutputTgt.xfo = neckEndXfo

        # Evaluate Constraints
        self.neckInputCnstr.evaluate()
        self.neck01OutCnstr.evaluate()
        self.neck02OutCnstr.evaluate()
        self.neckEndCnstr.evaluate()
Exemple #47
0
class NeckComponentRig(NeckComponent):
    """Neck Component"""

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

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


        # =========
        # Controls
        # =========
        # Neck
        self.neck01Ctrl = Control('neck01', parent=self.ctrlCmpGrp, shape="pin")
        self.neck01Ctrl.setColor("orange")
        self.neck01Ctrl.lockTranslation(True, True, True)
        self.neck01Ctrl.lockScale(True, True, True)

        self.neck01CtrlSpace = self.neck01Ctrl.insertCtrlSpace(name='neck01')

        self.neck02Ctrl = Control('neck02', parent=self.neck01Ctrl, shape="pin")
        self.neck02Ctrl.setColor("orange")
        self.neck02Ctrl.lockTranslation(True, True, True)
        self.neck02Ctrl.lockScale(True, True, True)

        self.neck02CtrlSpace = self.neck02Ctrl.insertCtrlSpace(name='neck02')


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

        self.neck01Def = Joint('neck01', parent=self.defCmpGrp)
        self.neck01Def.setComponent(self)

        self.neck02Def = Joint('neck02', parent=self.defCmpGrp)
        self.neck02Def.setComponent(self)


        # ==============
        # Constrain I/O
        # ==============
        # Constraint inputs
        neckInputConstraintName = '_'.join([self.neck01CtrlSpace.getName(),
                                            'To',
                                            self.neckBaseInputTgt.getName()])

        self.neckInputCnstr = self.neck01CtrlSpace.constrainTo(
            self.neckBaseInputTgt,
            'Pose',
            maintainOffset=True,
            name=neckInputConstraintName)


        # Constraint outputs
        neck01OutCnstrName = '_'.join([self.neck01OutputTgt.getName(),
                                       'To',
                                       self.neck01Ctrl.getName()])

        self.neck01OutCnstr = self.neck01OutputTgt.constrainTo(
            self.neck01Ctrl,
            'Pose',
            maintainOffset=False,
            name=neck01OutCnstrName)

        neck02OutCnstrName = '_'.join([self.neck02OutputTgt.getName(),
                                       'To',
                                       self.neck02Ctrl.getName()])

        self.neck02OutCnstr = self.neck02OutputTgt.constrainTo(
            self.neck02Ctrl,
            'Pose',
            maintainOffset=False,
            name=neck02OutCnstrName)

        neckEndCnstrName = '_'.join([self.neckEndOutputTgt.getName(),
                                     'To',
                                     self.neck02Ctrl.getName()])

        self.neckEndCnstr = self.neckEndOutputTgt.constrainTo(
            self.neck02Ctrl,
            'Pose',
            maintainOffset=True,
            name=neckEndCnstrName)


        # ==============
        # Add Operators
        # ==============
        # Add Deformer KL Op
        self.neckDeformerKLOp = KLOperator('neckDeformerKLOp',
                                           'MultiPoseConstraintSolver',
                                           'Kraken')

        self.addOperator(self.neckDeformerKLOp)

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

        # Add Xfo Inputstrl)
        self.neckDeformerKLOp.setInput('constrainers',
                                       [self.neck01Ctrl, self.neck02Ctrl])

        # Add Xfo Outputs
        self.neckDeformerKLOp.setOutput('constrainees',
                                        [self.neck01Def, self.neck02Def])

        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(NeckComponentRig, self).loadData(data)
        neckXfo = data.get('neckXfo')
        neckCrvData = data.get('neckCrvData')
        neckMidXfo = data.get('neckMidXfo')
        neckMidCrvData = data.get('neckMidCrvData')
        neckEndXfo = data.get('neckEndXfo')

        self.neck01CtrlSpace.xfo = neckXfo
        self.neck01Ctrl.xfo = neckXfo
        self.neck01Ctrl.setCurveData(neckCrvData)

        self.neck02CtrlSpace.xfo = neckMidXfo
        self.neck02Ctrl.xfo = neckMidXfo
        self.neck02Ctrl.setCurveData(neckMidCrvData)


        # ============
        # Set IO Xfos
        # ============
        self.neckBaseInputTgt.xfo = neckXfo
        self.neck01OutputTgt.xfo = neckXfo
        self.neck02OutputTgt.xfo = neckMidXfo
        self.neckEndOutputTgt.xfo = neckEndXfo

        # Evaluate Constraints
        self.neckInputCnstr.evaluate()
        self.neck01OutCnstr.evaluate()
        self.neck02OutCnstr.evaluate()
        self.neckEndCnstr.evaluate()
Exemple #48
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()
Exemple #49
0
class ClavicleComponentRig(ClavicleComponent):
    """Clavicle Component"""

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

        Profiler.getInstance().push("Construct Clavicle Rig Component:" + name)
        super(ClavicleComponentRig, 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()
        self.clavicleCtrl.lockTranslation(True, True, True)
        self.clavicleCtrl.lockScale(True, True, True)


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

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


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

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

        self.clavicleEndConstraint = PoseConstraint('_'.join([self.clavicleEndOutputTgt.getName(), 'To', self.clavicleCtrl.getName()]))
        self.clavicleEndConstraint.setMaintainOffset(True)
        self.clavicleEndConstraint.addConstrainer(self.clavicleCtrl)
        self.clavicleEndOutputTgt.addConstraint(self.clavicleEndConstraint)


        # ===============
        # Add Canavs Ops
        # ===============
        # Add Deformer Canvas Op
        self.clavicleDefOp = KLOperator('defConstraint', 'PoseConstraintSolver', 'Kraken')
        self.addOperator(self.clavicleDefOp)

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

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

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

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

        clavicleXfo = data.get('clavicleXfo')
        clavicleLen = data.get('clavicleLen')

        clavicleLenVec = Vec3(clavicleLen, 0.75, 0.75)

        self.clavicleCtrlSpace.xfo = clavicleXfo
        self.clavicleCtrl.xfo = clavicleXfo
        self.clavicleCtrl.scalePoints(clavicleLenVec)

        if data['location'] == "R":
            self.clavicleCtrl.translatePoints(Vec3(0.0, 0.0, -1.0))
        else:
            self.clavicleCtrl.translatePoints(Vec3(0.0, 0.0, 1.0))


        # Set IO Xfos
        self.spineEndInputTgt.xfo = clavicleXfo
        self.clavicleEndOutputTgt.xfo = clavicleXfo
        self.clavicleEndOutputTgt.xfo.tr = clavicleXfo.transformVector(Vec3(clavicleLen, 0.0, 0.0))
        self.clavicleOutputTgt.xfo = clavicleXfo

        # Eval Constraints
        self.clavicleInputConstraint.evaluate()
        self.clavicleConstraint.evaluate()
        self.clavicleEndConstraint.evaluate()

        # Eval Operators
        self.clavicleDefOp.evaluate()
Exemple #50
0
    def __init__(self, name='head', 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)
        self.addItem('defCmpGrp', self.defCmpGrp)

        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 Operators
        # ==============

        # Add Aim Canvas Op
        # =================
        self.headAimCanvasOp = CanvasOperator(
            'headAimCanvasOp', 'Kraken.Solvers.DirectionConstraintSolver')
        self.addOperator(self.headAimCanvasOp)

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

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

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

        # Add Deformer KL Op
        # ==================
        self.deformersToOutputsKLOp = KLOperator('headDeformerKLOp',
                                                 'MultiPoseConstraintSolver',
                                                 'Kraken')
        self.addOperator(self.deformersToOutputsKLOp)

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

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

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

        Profiler.getInstance().pop()
Exemple #51
0
class FabriceSpineRig(FabriceSpine):
    """Fabrice Spine Component"""
    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()

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

        # Get Data
        cogPos = data['cogPos']
        cogCtrlCrvData = data['cogCtrlCrvData']

        spineBasePos = data['spineBasePos']
        spineBaseCtrlCrvData = data['spineBaseCtrlCrvData']

        spineBaseHandlePos = data['spineBaseHandlePos']
        spineBaseHandleCtrlCrvData = data['spineBaseHandleCtrlCrvData']

        spineEndHandlePos = data['spineEndHandlePos']
        spineEndHandleCtrlCrvData = data['spineEndHandleCtrlCrvData']

        spineEndPos = data['spineEndPos']
        spineEndCtrlCrvData = data['spineEndCtrlCrvData']

        numDeformers = data['numDeformers']

        # Set Xfos
        self.cogCtrlSpace.xfo.tr = cogPos
        self.cogCtrl.xfo.tr = cogPos
        self.cogCtrl.setCurveData(cogCtrlCrvData)

        self.spineBaseCtrlSpace.xfo.tr = spineBasePos
        self.spineBaseCtrl.xfo.tr = spineBasePos
        self.spineBaseCtrl.setCurveData(spineBaseCtrlCrvData)

        self.spineBaseHandleCtrlSpace.xfo.tr = spineBaseHandlePos
        self.spineBaseHandleCtrl.xfo.tr = spineBaseHandlePos
        self.spineBaseHandleCtrl.setCurveData(spineBaseHandleCtrlCrvData)

        self.spineEndHandleCtrlSpace.xfo.tr = spineEndHandlePos
        self.spineEndHandleCtrl.xfo.tr = spineEndHandlePos
        self.spineEndHandleCtrl.setCurveData(spineEndHandleCtrlCrvData)

        self.spineEndCtrlSpace.xfo.tr = spineEndPos
        self.spineEndCtrl.xfo.tr = spineEndPos
        self.spineEndCtrl.setCurveData(spineEndCtrlCrvData)

        length = spineBasePos.distanceTo(
            spineBaseHandlePos) + spineBaseHandlePos.distanceTo(
                spineEndHandlePos) + spineEndHandlePos.distanceTo(spineEndPos)
        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()

        # evaluate the constraints to ensure the outputs are now in the correct location.
        self.spineSrtInputConstraint.evaluate()
        self.spineCogOutputConstraint.evaluate()
        self.spineBaseOutputPosConstraint.evaluate()
        self.spineBaseOutputOriConstraint.evaluate()
        self.spineEndOutputConstraint.evaluate()
        self.spineEndCtrlOutputConstraint.evaluate()
Exemple #52
0
class FabriceClavicleRig(FabriceClavicle):
    """Clavicle Component"""

    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 = KLOperator('clavicleDeformerKLOp', '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()


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

        self.clavicleCtrlSpace.xfo = data['clavicleXfo']
        self.clavicleCtrl.xfo = data['clavicleXfo']
        self.clavicleCtrl.setCurveData(data['clavicleCtrlCrvData'])

        # ============
        # Set IO Xfos
        # ============
        self.spineEndInputTgt.xfo = data['clavicleXfo']
        self.clavicleOutputTgt.xfo = data['clavicleXfo']
Exemple #53
0
    def __init__(self, name, parent=None, location='M'):
        super(SpineComponent, self).__init__(name, parent, location)

        # =========
        # Controls
        # =========
        # Setup component attributes
        defaultAttrGroup = self.getAttributeGroupByIndex(0)
        defaultAttrGroup.addAttribute(BoolAttribute("toggleDebugging", True))

        # Default values
        cogPosition = Vec3(0.0, 11.1351, -0.1382)
        spine01Position = Vec3(0.0, 11.1351, -0.1382)
        spine02Position = Vec3(0.0, 11.8013, -0.1995)
        spine03Position = Vec3(0.0, 12.4496, -0.3649)
        spine04Position = Vec3(0.0, 13.1051, -0.4821)

        # COG
        cogCtrlSrtBuffer = SrtBuffer('cog', parent=self)
        cogCtrlSrtBuffer.xfo.tr.copy(cogPosition)

        cogCtrl = CircleControl('cog', parent=cogCtrlSrtBuffer)
        cogCtrl.scalePoints(Vec3(6.0, 6.0, 6.0))
        cogCtrl.xfo.tr.copy(cogPosition)
        cogCtrl.setColor("orange")

        # Spine01
        spine01CtrlSrtBuffer = SrtBuffer('spine01', parent=cogCtrl)
        spine01CtrlSrtBuffer.xfo.tr.copy(spine01Position)

        spine01Ctrl = CircleControl('spine01', parent=spine01CtrlSrtBuffer)
        spine01Ctrl.scalePoints(Vec3(4.0, 4.0, 4.0))
        spine01Ctrl.xfo.tr.copy(spine01Position)
        spine01Ctrl.setColor("yellow")

        # Spine02
        spine02CtrlSrtBuffer = SrtBuffer('spine02', parent=spine01Ctrl)
        spine02CtrlSrtBuffer.xfo.tr.copy(spine02Position)

        spine02Ctrl = CircleControl('spine02', parent=spine02CtrlSrtBuffer)
        spine02Ctrl.scalePoints(Vec3(4.5, 4.5, 4.5))
        spine02Ctrl.xfo.tr.copy(spine02Position)
        spine02Ctrl.setColor("blue")

        # Spine03
        spine03CtrlSrtBuffer = SrtBuffer('spine03', parent=spine02Ctrl)
        spine03CtrlSrtBuffer.xfo.tr.copy(spine03Position)

        spine03Ctrl = CircleControl('spine03', parent=spine03CtrlSrtBuffer)
        spine03Ctrl.scalePoints(Vec3(4.5, 4.5, 4.5))
        spine03Ctrl.xfo.tr.copy(spine03Position)
        spine03Ctrl.setColor("blue")

        # Spine04
        spine04CtrlSrtBuffer = SrtBuffer('spine04', parent=cogCtrl)
        spine04CtrlSrtBuffer.xfo.tr.copy(spine04Position)

        spine04Ctrl = CircleControl('spine04', parent=spine04CtrlSrtBuffer)
        spine04Ctrl.scalePoints(Vec3(6.0, 6.0, 6.0))
        spine04Ctrl.xfo.tr.copy(spine04Position)
        spine04Ctrl.setColor("yellow")

        # ==========
        # Deformers
        # ==========
        container = self.getParent().getParent()
        deformersLayer = container.getChildByName('deformers')

        spine01Def = Joint('spine01')
        spine01Def.setComponent(self)

        spine02Def = Joint('spine02')
        spine02Def.setComponent(self)

        spine03Def = Joint('spine03')
        spine03Def.setComponent(self)

        spine04Def = Joint('spine04')
        spine04Def.setComponent(self)

        deformersLayer.addChild(spine01Def)
        deformersLayer.addChild(spine02Def)
        deformersLayer.addChild(spine03Def)
        deformersLayer.addChild(spine04Def)


        # =====================
        # Create Component I/O
        # =====================
        # Setup component Xfo I/O's
        spine01Output = Locator('spine01')
        spine01Output.xfo.tr.copy(spine01Ctrl.xfo.tr)
        spine02Output = Locator('spine02')
        spine02Output.xfo.tr.copy(spine01Ctrl.xfo.tr)
        spine03Output = Locator('spine03')
        spine03Output.xfo.tr.copy(spine01Ctrl.xfo.tr)
        spine04Output = Locator('spine04')
        spine04Output.xfo.tr.copy(spine01Ctrl.xfo.tr)

        spineBaseOutput = Locator('spineBase')
        spineBaseOutput.xfo.tr.copy(spine01Ctrl.xfo.tr)

        spineEndOutput = Locator('spineEnd')
        spineEndOutput.xfo.tr.copy(spine03Ctrl.xfo.tr)

        # Setup componnent Attribute I/O's
        debugInputAttr = BoolAttribute('debug', True)


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

        # Constraint outputs
        spineBaseOutputConstraint = PoseConstraint('_'.join([spineBaseOutput.getName(), 'To', 'spineBase']))
        spineBaseOutputConstraint.addConstrainer(spine01Ctrl)
        spineBaseOutput.addConstraint(spineBaseOutputConstraint)

        spineEndOutputConstraint = PoseConstraint('_'.join([spineEndOutput.getName(), 'To', 'spineEnd']))
        spineEndOutputConstraint.addConstrainer(spine04Ctrl)
        spineEndOutput.addConstraint(spineEndOutputConstraint)


        # ==================
        # Add Component I/O
        # ==================
        # Add Xfo I/O's
        self.addOutput(spine01Output)
        self.addOutput(spine02Output)
        self.addOutput(spine03Output)
        self.addOutput(spine04Output)
        self.addOutput(spineBaseOutput)
        self.addOutput(spineEndOutput)

        # Add Attribute I/O's
        self.addInput(debugInputAttr)