Esempio n. 1
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
Esempio n. 2
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
Esempio n. 3
0
class NeckComponentGuide(NeckComponent):
    """Neck Component Guide"""
    def __init__(self, name='neck', parent=None, *args, **kwargs):

        Profiler.getInstance().push('Construct Neck Component:' + name)
        super(NeckComponentGuide, self).__init__(name, parent, *args, **kwargs)

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

        # Guide Controls
        self.neckCtrl = Control('neck', parent=self.ctrlCmpGrp, shape='sphere')
        self.neckCtrl.scalePoints(Vec3(0.5, 0.5, 0.5))
        self.neckMidCtrl = Control('neckMid',
                                   parent=self.ctrlCmpGrp,
                                   shape='sphere')
        self.neckMidCtrl.scalePoints(Vec3(0.5, 0.5, 0.5))
        self.neckEndCtrl = Control('neckEnd',
                                   parent=self.ctrlCmpGrp,
                                   shape='sphere')
        self.neckEndCtrl.scalePoints(Vec3(0.5, 0.5, 0.5))

        self.neckCtrlShape = Control('neck',
                                     parent=self.ctrlCmpGrp,
                                     shape='pin')
        self.neckCtrlShape.rotatePoints(90.0, 0.0, 0.0)
        self.neckCtrlShape.rotatePoints(0.0, 90.0, 0.0)
        self.neckCtrlShape.setColor('orange')
        self.neckMidCtrlShape = Control('neckMid',
                                        parent=self.ctrlCmpGrp,
                                        shape='pin')
        self.neckMidCtrlShape.rotatePoints(90.0, 0.0, 0.0)
        self.neckMidCtrlShape.rotatePoints(0.0, 90.0, 0.0)
        self.neckMidCtrlShape.setColor('orange')

        # Guide Operator
        self.neckGuideKLOp = KLOperator(name + 'GuideKLOp', 'NeckGuideSolver',
                                        'Kraken')
        self.addOperator(self.neckGuideKLOp)

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

        # Add Source Inputs
        self.neckGuideKLOp.setInput(
            'sources', [self.neckCtrl, self.neckMidCtrl, self.neckEndCtrl])

        # Add Target Outputs
        self.neckGuideKLOp.setOutput(
            'targets', [self.neckCtrlShape, self.neckMidCtrlShape])

        # Calculate default values
        neckVec = Vec3(0.0, 16.00, -0.75)
        neckMidVec = Vec3(0.0, 16.50, -0.50)
        neckEndVec = Vec3(0.0, 17.00, -0.25)
        upVector = Vec3(0.0, 0.0, -1.0)

        neckOri = Quat()
        neckOri.setFromDirectionAndUpvector(
            (neckMidVec - neckVec).unit(),
            ((neckVec + upVector) - neckVec).unit())

        neckMidOri = Quat()
        neckMidOri.setFromDirectionAndUpvector(
            (neckEndVec - neckMidVec).unit(),
            ((neckMidVec + upVector) - neckMidVec).unit())

        self.default_data = {
            "name": name,
            "location": "M",
            "neckXfo": Xfo(tr=neckVec, ori=neckOri),
            "neckMidXfo": Xfo(tr=neckMidVec, ori=neckMidOri),
            "neckEndXfo": Xfo(tr=neckEndVec, ori=neckMidOri),
            "neckCrvData": self.neckCtrlShape.getCurveData(),
            "neckMidCrvData": self.neckMidCtrlShape.getCurveData()
        }

        self.loadData(self.default_data)

        Profiler.getInstance().pop()

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

        Return:
        The JSON data object

        """

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

        data['neckXfo'] = self.neckCtrl.xfo
        data['neckMidXfo'] = self.neckMidCtrl.xfo
        data['neckEndXfo'] = self.neckEndCtrl.xfo

        data['neckCrvData'] = self.neckCtrlShape.getCurveData()
        data['neckMidCrvData'] = self.neckMidCtrlShape.getCurveData()

        return data

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

        Arguments:
            data (object): The JSON data object.

        Returns:
            bool: True if successful.

        """

        super(NeckComponentGuide, self).loadData(data)

        self.neckCtrl.xfo = data.get('neckXfo')
        self.neckMidCtrl.xfo = data.get('neckMidXfo')
        self.neckEndCtrl.xfo = data.get('neckEndXfo')

        self.neckCtrlShape.setCurveData(data.get('neckCrvData'))
        self.neckMidCtrlShape.setCurveData(data.get('neckMidCrvData'))

        # Evaluate guide operators
        self.neckGuideKLOp.evaluate()

        return True

    def getRigBuildData(self):
        """Returns the Guide data used by the Rig Component to define the layout
        of the final rig.

        Return:
        The JSON rig data object.

        """

        data = super(NeckComponentGuide, self).getRigBuildData()

        neckEndXfo = Xfo(tr=self.neckEndCtrl.xfo.tr,
                         ori=self.neckMidCtrlShape.xfo.ori)

        data['neckXfo'] = self.neckCtrlShape.xfo
        data['neckCrvData'] = self.neckCtrlShape.getCurveData()
        data['neckMidXfo'] = self.neckMidCtrlShape.xfo
        data['neckMidCrvData'] = self.neckMidCtrlShape.getCurveData()
        data['neckEndXfo'] = neckEndXfo

        return data

    # ==============
    # Class Methods
    # ==============
    @classmethod
    def getComponentType(cls):
        """Enables introspection of the class prior to construction to determine
        if it is a guide component.

        Returns:
            bool: Whether the component is a guide component.

        """

        return 'Guide'

    @classmethod
    def getRigComponentClass(cls):
        """Returns the corresponding rig component class for this guide
        component class.

        Returns:
            class: The rig component class.

        """

        return NeckComponentRig
Esempio n. 4
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()
Esempio n. 5
0
class HeadComponentGuide(HeadComponent):
    """Head Component Guide"""
    def __init__(self, name='head', parent=None, *args, **kwargs):

        Profiler.getInstance().push("Construct Head Guide Component:" + name)
        super(HeadComponentGuide, self).__init__(name, parent, *args, **kwargs)

        # =========
        # Controls
        # =========
        guideSettingsAttrGrp = AttributeGroup("GuideSettings", parent=self)

        sphereCtrl = Control('sphere', shape='sphere')
        sphereCtrl.scalePoints(Vec3(0.375, 0.375, 0.375))

        self.headCtrl = Control('head', parent=self.ctrlCmpGrp, shape='square')
        self.headCtrl.rotatePoints(90, 0, 0)
        self.headCtrl.translatePoints(Vec3(0.0, 0.5, 0.0))
        self.headCtrl.scalePoints(Vec3(1.8, 2.0, 2.0))

        self.eyeLeftCtrl = Control('eyeLeft',
                                   parent=self.headCtrl,
                                   shape='arrow_thin')
        self.eyeLeftCtrl.translatePoints(Vec3(0, 0, 0.5))
        self.eyeLeftCtrl.rotatePoints(0, 90, 0)
        self.eyeLeftCtrl.appendCurveData(sphereCtrl.getCurveData())

        self.eyeRightCtrl = Control('eyeRight',
                                    parent=self.headCtrl,
                                    shape='arrow_thin')
        self.eyeRightCtrl.translatePoints(Vec3(0, 0, 0.5))
        self.eyeRightCtrl.rotatePoints(0, 90, 0)
        self.eyeRightCtrl.appendCurveData(sphereCtrl.getCurveData())

        self.jawCtrl = Control('jaw', parent=self.headCtrl, shape='square')
        self.jawCtrl.rotatePoints(90, 0, 0)
        self.jawCtrl.rotatePoints(0, 90, 0)
        self.jawCtrl.translatePoints(Vec3(0.0, -0.5, 0.5))
        self.jawCtrl.scalePoints(Vec3(1.0, 0.8, 1.5))
        self.jawCtrl.setColor('orange')

        eyeXAlignOri = Quat()
        eyeXAlignOri.setFromAxisAndAngle(Vec3(0, 1, 0), Math_degToRad(-90))

        self.default_data = {
            "name": name,
            "location": "M",
            "headXfo": Xfo(Vec3(0.0, 17.5, -0.5)),
            "headCrvData": self.headCtrl.getCurveData(),
            "eyeLeftXfo": Xfo(tr=Vec3(0.375, 18.5, 0.5), ori=eyeXAlignOri),
            "eyeLeftCrvData": self.eyeLeftCtrl.getCurveData(),
            "eyeRightXfo": Xfo(tr=Vec3(-0.375, 18.5, 0.5), ori=eyeXAlignOri),
            "eyeRightCrvData": self.eyeRightCtrl.getCurveData(),
            "jawXfo": Xfo(Vec3(0.0, 17.875, -0.275)),
            "jawCrvData": self.jawCtrl.getCurveData()
        }

        self.loadData(self.default_data)

        Profiler.getInstance().pop()

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

        Return:
        The JSON data object

        """

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

        data['headXfo'] = self.headCtrl.xfo
        data['headCrvData'] = self.headCtrl.getCurveData()
        data['eyeLeftXfo'] = self.eyeLeftCtrl.xfo
        data['eyeLeftCrvData'] = self.eyeLeftCtrl.getCurveData()
        data['eyeRightXfo'] = self.eyeRightCtrl.xfo
        data['eyeRightCrvData'] = self.eyeRightCtrl.getCurveData()
        data['jawXfo'] = self.jawCtrl.xfo
        data['jawCrvData'] = self.jawCtrl.getCurveData()

        return data

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

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

        Return:
        True if successful.

        """

        super(HeadComponentGuide, self).loadData(data)

        self.headCtrl.xfo = data.get('headXfo', self.default_data['headXfo'])
        self.headCtrl.setCurveData(
            data.get('headCrvData', self.default_data['headCrvData']))
        self.eyeLeftCtrl.xfo = data.get('eyeLeftXfo',
                                        self.default_data['eyeLeftXfo'])
        self.eyeLeftCtrl.setCurveData(
            data.get('eyeLeftCrvData', self.default_data['eyeLeftCrvData']))
        self.eyeRightCtrl.xfo = data.get('eyeRightXfo',
                                         self.default_data['eyeRightXfo'])
        self.eyeRightCtrl.setCurveData(
            data.get('eyeRightCrvData', self.default_data['eyeRightCrvData']))
        self.jawCtrl.xfo = data.get('jawXfo', self.default_data['jawXfo'])
        self.jawCtrl.setCurveData(
            data.get('jawCrvData', self.default_data['jawCrvData']))

        return True

    def getRigBuildData(self):
        """Returns the Guide data used by the Rig Component to define the layout of the final rig..

        Return:
        The JSON rig data object.

        """

        data = super(HeadComponentGuide, self).getRigBuildData()

        data['headXfo'] = self.headCtrl.xfo
        data['headCrvData'] = self.headCtrl.getCurveData()

        data['eyeLeftXfo'] = self.eyeLeftCtrl.xfo
        data['eyeLeftCrvData'] = self.eyeLeftCtrl.getCurveData()

        data['eyeRightXfo'] = self.eyeRightCtrl.xfo
        data['eyeRightCrvData'] = self.eyeRightCtrl.getCurveData()

        data['jawXfo'] = self.jawCtrl.xfo
        data['jawCrvData'] = self.jawCtrl.getCurveData()

        return data

    # ==============
    # Class Methods
    # ==============
    @classmethod
    def getComponentType(cls):
        """Enables introspection of the class prior to construction to determine if it is a guide component.

        Return:
        The true if this component is a guide component.

        """

        return 'Guide'

    @classmethod
    def getRigComponentClass(cls):
        """Returns the corresponding rig component class for this guide component class

        Return:
        The rig component class.

        """

        return HeadComponentRig
Esempio n. 6
0
class HeadComponentRig(HeadComponent):
    """Head Component Rig"""
    def __init__(self, name='head', parent=None):

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        Profiler.getInstance().pop()

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

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

        Return:
        True if successful.

        """

        super(HeadComponentRig, self).loadData(data)

        headXfo = data.get('headXfo')
        headCrvData = data.get('headCrvData')
        eyeLeftXfo = data.get('eyeLeftXfo')
        eyeLeftCrvData = data.get('eyeLeftCrvData')
        eyeRightXfo = data.get('eyeRightXfo')
        eyeRightCrvData = data.get('eyeRightCrvData')
        jawXfo = data.get('jawXfo')
        jawCrvData = data.get('jawCrvData')

        self.headCtrlSpace.xfo = headXfo
        self.headCtrl.xfo = headXfo
        self.headCtrl.setCurveData(headCrvData)

        # self.eyeLeftCtrlSpace.xfo = eyeLeftXfo
        # self.eyeLeftCtrl.xfo = eyeLeftXfo
        self.eyeLeftCtrl.setCurveData(eyeLeftCrvData)

        # self.eyeRightCtrlSpace.xfo = eyeRightXfo
        # self.eyeRightCtrl.xfo = eyeRightXfo
        self.eyeRightCtrl.setCurveData(eyeRightCrvData)

        # LookAt
        eyeLeftRelXfo = headXfo.inverse() * eyeLeftXfo
        eyeRightRelXfo = headXfo.inverse() * eyeRightXfo
        eyeMidRelPos = eyeLeftRelXfo.tr.linearInterpolate(
            eyeRightRelXfo.tr, 0.5)
        eyeMidRelPos = eyeMidRelPos + Vec3(0.0, 0.0, 8.0)
        eyeLen = eyeLeftRelXfo.tr.distanceTo(eyeRightRelXfo.tr)

        self.eyeLeftBase.xfo = eyeLeftXfo
        self.eyeRightBase.xfo = eyeRightXfo

        self.eyeLeftUpV.xfo = eyeLeftXfo * Xfo(Vec3(0, 1, 0))
        self.eyeRightUpV.xfo = eyeRightXfo * Xfo(Vec3(0, 1, 0))

        self.eyeLeftAtV.xfo.tr = eyeLeftXfo.transformVector(Vec3(
            8.0, 0.0, 0.0))
        self.eyeRightAtV.xfo.tr = eyeRightXfo.transformVector(
            Vec3(8.0, 0.0, 0.0))

        lookAtXfo = headXfo.clone()
        lookAtXfo.tr = headXfo.transformVector(eyeMidRelPos)

        self.lookAtCtrl.scalePoints(Vec3(eyeLen * 1.6, eyeLen * 0.65, 1.0))
        self.lookAtCtrl.xfo = lookAtXfo
        self.lookAtCtrlSpace.xfo = lookAtXfo

        self.jawCtrlSpace.xfo = jawXfo
        self.jawCtrl.xfo = jawXfo
        self.jawCtrl.setCurveData(jawCrvData)

        # ============
        # Set IO Xfos
        # ============
        self.neckRefInputTgt.xfo = headXfo
        self.worldRefInputTgt.xfo = headXfo
        self.headOutputTgt.xfo = headXfo
        self.jawOutputTgt.xfo = jawXfo
        self.eyeLOutputTgt.xfo = eyeLeftXfo
        self.eyeROutputTgt.xfo = eyeRightXfo

        # Eval Constraints
        self.headInputConstraint.evaluate()
        self.headOutputConstraint.evaluate()
        self.jawOutputConstraint.evaluate()
        self.eyeLOutputConstraint.evaluate()
        self.eyeROutputConstraint.evaluate()

        # Eval Operators
        self.eyeLeftDirKLOp.evaluate()
        self.eyeRightDirKLOp.evaluate()
        self.outputsToDeformersKLOp.evaluate()

        # Have to set the eye control xfos to match the evaluated xfos from
        self.eyeLeftCtrl.xfo = self.eyeLeftCtrlSpace.xfo
        self.eyeRightCtrl.xfo = self.eyeRightCtrlSpace.xfo
Esempio n. 7
0
class FabriceTailGuide(FabriceTail):
    """Fabrice Tail Component Guide"""

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

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

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


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

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

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

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

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

        self.addOperator(self.bezierSpineSpliceOp)

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

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

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

        Profiler.getInstance().pop()


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

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

        Return:
        True if successful.

        """

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


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

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

        return True

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

        Return:
        The JSON data object

        """

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

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

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

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

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

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

        return data


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

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

        Return:
        True if successful.

        """

        super(FabriceTailGuide, self).loadData( data )

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

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

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

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

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

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

        self.bezierSpineSpliceOp.evaluate()

        return True


    def getRigBuildData(self):
        """Returns the Guide data used by the Rig Component to define the layout of the final rig.

        Return:
        The JSON rig data object.

        """

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

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

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

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

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

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

        return data


    # ==============
    # Class Methods
    # ==============
    @classmethod
    def getComponentType(cls):
        """Enables introspection of the class prior to construction to determine if it is a guide component.

        Return:
        The true if this component is a guide component.

        """

        return 'Guide'

    @classmethod
    def getRigComponentClass(cls):
        """Returns the corresponding rig component class for this guide component class

        Return:
        The rig component class.

        """

        return FabriceTailRig
Esempio n. 8
0
class NeckComponentGuide(NeckComponent):
    """Neck Component Guide"""

    def __init__(self, name='neck', parent=None, *args, **kwargs):

        Profiler.getInstance().push('Construct Neck Component:' + name)
        super(NeckComponentGuide, self).__init__(name, parent, *args, **kwargs)

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

        # Guide Controls
        self.neckCtrl = Control('neck', parent=self.ctrlCmpGrp, shape='sphere')
        self.neckCtrl.scalePoints(Vec3(0.5, 0.5, 0.5))
        self.neckMidCtrl = Control('neckMid', parent=self.ctrlCmpGrp, shape='sphere')
        self.neckMidCtrl.scalePoints(Vec3(0.5, 0.5, 0.5))
        self.neckEndCtrl = Control('neckEnd', parent=self.ctrlCmpGrp, shape='sphere')
        self.neckEndCtrl.scalePoints(Vec3(0.5, 0.5, 0.5))

        self.neckCtrlShape = Control('neck', parent=self.ctrlCmpGrp, shape='pin')
        self.neckCtrlShape.rotatePoints(90.0, 0.0, 0.0)
        self.neckCtrlShape.rotatePoints(0.0, 90.0, 0.0)
        self.neckCtrlShape.setColor('orange')
        self.neckMidCtrlShape = Control('neckMid', parent=self.ctrlCmpGrp, shape='pin')
        self.neckMidCtrlShape.rotatePoints(90.0, 0.0, 0.0)
        self.neckMidCtrlShape.rotatePoints(0.0, 90.0, 0.0)
        self.neckMidCtrlShape.setColor('orange')

        # Guide Operator
        self.neckGuideKLOp = KLOperator(name + 'GuideKLOp', 'NeckGuideSolver', 'Kraken')
        self.addOperator(self.neckGuideKLOp)

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

        # Add Source Inputs
        self.neckGuideKLOp.setInput('sources', [self.neckCtrl, self.neckMidCtrl, self.neckEndCtrl])

        # Add Target Outputs
        self.neckGuideKLOp.setOutput('targets', [self.neckCtrlShape, self.neckMidCtrlShape])


        # Calculate default values
        neckVec = Vec3(0.0, 16.00, -0.75)
        neckMidVec = Vec3(0.0, 16.50, -0.50)
        neckEndVec = Vec3(0.0, 17.00, -0.25)
        upVector = Vec3(0.0, 0.0, -1.0)

        neckOri = Quat()
        neckOri.setFromDirectionAndUpvector((neckMidVec - neckVec).unit(),
                                            ((neckVec + upVector) - neckVec).unit())

        neckMidOri = Quat()
        neckMidOri.setFromDirectionAndUpvector((neckEndVec - neckMidVec).unit(),
                                               ((neckMidVec + upVector) - neckMidVec).unit())

        self.default_data = {
            "name": name,
            "location": "M",
            "neckXfo": Xfo(tr=neckVec, ori=neckOri),
            "neckMidXfo": Xfo(tr=neckMidVec, ori=neckMidOri),
            "neckEndXfo": Xfo(tr=neckEndVec, ori=neckMidOri),
            "neckCrvData": self.neckCtrlShape.getCurveData(),
            "neckMidCrvData": self.neckMidCtrlShape.getCurveData()
        }

        self.loadData(self.default_data)

        Profiler.getInstance().pop()


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

        Return:
        The JSON data object

        """

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

        data['neckXfo'] = self.neckCtrl.xfo
        data['neckMidXfo'] = self.neckMidCtrl.xfo
        data['neckEndXfo'] = self.neckEndCtrl.xfo

        data['neckCrvData'] = self.neckCtrlShape.getCurveData()
        data['neckMidCrvData'] = self.neckMidCtrlShape.getCurveData()

        return data


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

        Arguments:
            data (object): The JSON data object.

        Returns:
            bool: True if successful.

        """

        super(NeckComponentGuide, self).loadData(data)

        self.neckCtrl.xfo = data.get('neckXfo')
        self.neckMidCtrl.xfo = data.get('neckMidXfo')
        self.neckEndCtrl.xfo = data.get('neckEndXfo')

        self.neckCtrlShape.setCurveData(data.get('neckCrvData'))
        self.neckMidCtrlShape.setCurveData(data.get('neckMidCrvData'))

        # Evaluate guide operators
        self.neckGuideKLOp.evaluate()

        return True


    def getRigBuildData(self):
        """Returns the Guide data used by the Rig Component to define the layout
        of the final rig.

        Return:
        The JSON rig data object.

        """

        data = super(NeckComponentGuide, self).getRigBuildData()

        neckEndXfo = Xfo(tr=self.neckEndCtrl.xfo.tr,
                         ori=self.neckMidCtrlShape.xfo.ori)

        data['neckXfo'] = self.neckCtrlShape.xfo
        data['neckCrvData'] = self.neckCtrlShape.getCurveData()
        data['neckMidXfo'] = self.neckMidCtrlShape.xfo
        data['neckMidCrvData'] = self.neckMidCtrlShape.getCurveData()
        data['neckEndXfo'] = neckEndXfo

        return data


    # ==============
    # Class Methods
    # ==============
    @classmethod
    def getComponentType(cls):
        """Enables introspection of the class prior to construction to determine
        if it is a guide component.

        Returns:
            bool: Whether the component is a guide component.

        """

        return 'Guide'


    @classmethod
    def getRigComponentClass(cls):
        """Returns the corresponding rig component class for this guide
        component class.

        Returns:
            class: The rig component class.

        """

        return NeckComponentRig
Esempio n. 9
0
class FabriceTailRig(FabriceTail):
    """Fabrice Tail Component"""

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

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


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

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

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

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

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


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


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


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

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

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

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


        # ===============
        # Add Splice Ops
        # ===============
        # Add Tail Splice Op
        self.bezierTailKLOp = KLOperator('tailKLOp', 'BezierSpineSolver', 'Kraken')
        self.addOperator(self.bezierTailKLOp)

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

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

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

        # Add Deformer Splice Op
        self.deformersToOutputsKLOp = KLOperator('tailDeformerKLOp', '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.tailOutputs)

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

        Profiler.getInstance().pop()


    def setNumDeformers(self, numDeformers):

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

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

        return True


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

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

        Return:
        True if successful.

        """

        super(FabriceTailRig, self).loadData( data )

        tailBasePos = data['tailBasePos']

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

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

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

        numDeformers = data['numDeformers']

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

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

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

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

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

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

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

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

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

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

        # evaluate the constraints to ensure the outputs are now in the correct location.
        self.tailBaseHandleInputConstraint.evaluate()
        self.tailBaseOutputConstraint.evaluate()
        self.tailEndOutputConstraint.evaluate()
Esempio n. 10
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']
Esempio n. 11
0
class HeadComponentGuide(HeadComponent):
    """Head Component Guide"""

    def __init__(self, name='head', parent=None, *args, **kwargs):

        Profiler.getInstance().push("Construct Head Guide Component:" + name)
        super(HeadComponentGuide, self).__init__(name, parent, *args, **kwargs)


        # =========
        # Controls
        # =========
        guideSettingsAttrGrp = AttributeGroup("GuideSettings", parent=self)


        sphereCtrl = Control('sphere', shape='sphere')
        sphereCtrl.scalePoints(Vec3(0.375, 0.375, 0.375))

        self.headCtrl = Control('head', parent=self.ctrlCmpGrp, shape='square')
        self.headCtrl.rotatePoints(90, 0, 0)
        self.headCtrl.translatePoints(Vec3(0.0, 0.5, 0.0))
        self.headCtrl.scalePoints(Vec3(1.8, 2.0, 2.0))

        self.eyeLeftCtrl = Control('eyeLeft', parent=self.headCtrl, shape='arrow_thin')
        self.eyeLeftCtrl.translatePoints(Vec3(0, 0, 0.5))
        self.eyeLeftCtrl.rotatePoints(0, 90, 0)
        self.eyeLeftCtrl.appendCurveData(sphereCtrl.getCurveData())

        self.eyeRightCtrl = Control('eyeRight', parent=self.headCtrl, shape='arrow_thin')
        self.eyeRightCtrl.translatePoints(Vec3(0, 0, 0.5))
        self.eyeRightCtrl.rotatePoints(0, 90, 0)
        self.eyeRightCtrl.appendCurveData(sphereCtrl.getCurveData())

        self.jawCtrl = Control('jaw', parent=self.headCtrl, shape='square')
        self.jawCtrl.rotatePoints(90, 0, 0)
        self.jawCtrl.rotatePoints(0, 90, 0)
        self.jawCtrl.translatePoints(Vec3(0.0, -0.5, 0.5))
        self.jawCtrl.scalePoints(Vec3(1.0, 0.8, 1.5))
        self.jawCtrl.setColor('orange')

        eyeXAlignOri = Quat()
        eyeXAlignOri.setFromAxisAndAngle(Vec3(0, 1, 0), Math_degToRad(-90))

        self.default_data = {
            "name": name,
            "location": "M",
            "headXfo": Xfo(Vec3(0.0, 17.5, -0.5)),
            "headCrvData": self.headCtrl.getCurveData(),
            "eyeLeftXfo": Xfo(tr=Vec3(0.375, 18.5, 0.5), ori=eyeXAlignOri),
            "eyeLeftCrvData": self.eyeLeftCtrl.getCurveData(),
            "eyeRightXfo": Xfo(tr=Vec3(-0.375, 18.5, 0.5), ori=eyeXAlignOri),
            "eyeRightCrvData": self.eyeRightCtrl.getCurveData(),
            "jawXfo": Xfo(Vec3(0.0, 17.875, -0.275)),
            "jawCrvData": self.jawCtrl.getCurveData()
        }

        self.loadData(self.default_data)

        Profiler.getInstance().pop()


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

        Return:
        The JSON data object

        """

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

        data['headXfo'] = self.headCtrl.xfo
        data['headCrvData'] = self.headCtrl.getCurveData()
        data['eyeLeftXfo'] = self.eyeLeftCtrl.xfo
        data['eyeLeftCrvData'] = self.eyeLeftCtrl.getCurveData()
        data['eyeRightXfo'] = self.eyeRightCtrl.xfo
        data['eyeRightCrvData'] = self.eyeRightCtrl.getCurveData()
        data['jawXfo'] = self.jawCtrl.xfo
        data['jawCrvData'] = self.jawCtrl.getCurveData()

        return data


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

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

        Return:
        True if successful.

        """

        super(HeadComponentGuide, self).loadData(data)

        self.headCtrl.xfo = data.get('headXfo', self.default_data['headXfo'])
        self.headCtrl.setCurveData(data.get('headCrvData', self.default_data['headCrvData']))
        self.eyeLeftCtrl.xfo = data.get('eyeLeftXfo', self.default_data['eyeLeftXfo'])
        self.eyeLeftCtrl.setCurveData(data.get('eyeLeftCrvData', self.default_data['eyeLeftCrvData']))
        self.eyeRightCtrl.xfo = data.get('eyeRightXfo', self.default_data['eyeRightXfo'])
        self.eyeRightCtrl.setCurveData(data.get('eyeRightCrvData', self.default_data['eyeRightCrvData']))
        self.jawCtrl.xfo = data.get('jawXfo', self.default_data['jawXfo'])
        self.jawCtrl.setCurveData(data.get('jawCrvData', self.default_data['jawCrvData']))

        return True


    def getRigBuildData(self):
        """Returns the Guide data used by the Rig Component to define the layout of the final rig..

        Return:
        The JSON rig data object.

        """

        data = super(HeadComponentGuide, self).getRigBuildData()

        data['headXfo'] = self.headCtrl.xfo
        data['headCrvData'] = self.headCtrl.getCurveData()

        data['eyeLeftXfo'] = self.eyeLeftCtrl.xfo
        data['eyeLeftCrvData'] = self.eyeLeftCtrl.getCurveData()

        data['eyeRightXfo'] = self.eyeRightCtrl.xfo
        data['eyeRightCrvData'] = self.eyeRightCtrl.getCurveData()

        data['jawXfo'] = self.jawCtrl.xfo
        data['jawCrvData'] = self.jawCtrl.getCurveData()


        return data


    # ==============
    # Class Methods
    # ==============
    @classmethod
    def getComponentType(cls):
        """Enables introspection of the class prior to construction to determine if it is a guide component.

        Return:
        The true if this component is a guide component.

        """

        return 'Guide'

    @classmethod
    def getRigComponentClass(cls):
        """Returns the corresponding rig component class for this guide component class

        Return:
        The rig component class.

        """

        return HeadComponentRig
Esempio n. 12
0
class HeadComponentRig(HeadComponent):
    """Head Component Rig"""

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

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


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

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

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

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

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

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


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

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

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

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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


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

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

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

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

        Profiler.getInstance().pop()


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

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

        Return:
        True if successful.

        """

        super(HeadComponentRig, self).loadData(data)

        headXfo = data.get('headXfo')
        headCrvData = data.get('headCrvData')
        eyeLeftXfo = data.get('eyeLeftXfo')
        eyeLeftCrvData = data.get('eyeLeftCrvData')
        eyeRightXfo = data.get('eyeRightXfo')
        eyeRightCrvData = data.get('eyeRightCrvData')
        jawXfo = data.get('jawXfo')
        jawCrvData = data.get('jawCrvData')

        self.headCtrlSpace.xfo = headXfo
        self.headCtrl.xfo = headXfo
        self.headCtrl.setCurveData(headCrvData)

        # self.eyeLeftCtrlSpace.xfo = eyeLeftXfo
        # self.eyeLeftCtrl.xfo = eyeLeftXfo
        self.eyeLeftCtrl.setCurveData(eyeLeftCrvData)

        # self.eyeRightCtrlSpace.xfo = eyeRightXfo
        # self.eyeRightCtrl.xfo = eyeRightXfo
        self.eyeRightCtrl.setCurveData(eyeRightCrvData)

        # LookAt
        eyeLeftRelXfo = headXfo.inverse() * eyeLeftXfo
        eyeRightRelXfo = headXfo.inverse() * eyeRightXfo
        eyeMidRelPos = eyeLeftRelXfo.tr.linearInterpolate(eyeRightRelXfo.tr, 0.5)
        eyeMidRelPos = eyeMidRelPos + Vec3(0.0, 0.0, 8.0)
        eyeLen = eyeLeftRelXfo.tr.distanceTo(eyeRightRelXfo.tr)

        self.eyeLeftBase.xfo = eyeLeftXfo
        self.eyeRightBase.xfo = eyeRightXfo

        self.eyeLeftUpV.xfo = eyeLeftXfo * Xfo(Vec3(0, 1, 0))
        self.eyeRightUpV.xfo = eyeRightXfo * Xfo(Vec3(0, 1, 0))

        self.eyeLeftAtV.xfo.tr = eyeLeftXfo.transformVector(Vec3(8.0, 0.0, 0.0))
        self.eyeRightAtV.xfo.tr = eyeRightXfo.transformVector(Vec3(8.0, 0.0, 0.0))

        lookAtXfo = headXfo.clone()
        lookAtXfo.tr = headXfo.transformVector(eyeMidRelPos)

        self.lookAtCtrl.scalePoints(Vec3(eyeLen * 1.6, eyeLen * 0.65, 1.0))
        self.lookAtCtrl.xfo = lookAtXfo
        self.lookAtCtrlSpace.xfo = lookAtXfo

        self.jawCtrlSpace.xfo = jawXfo
        self.jawCtrl.xfo = jawXfo
        self.jawCtrl.setCurveData(jawCrvData)

        # ============
        # Set IO Xfos
        # ============
        self.neckRefInputTgt.xfo = headXfo
        self.worldRefInputTgt.xfo = headXfo
        self.headOutputTgt.xfo = headXfo
        self.jawOutputTgt.xfo = jawXfo
        self.eyeLOutputTgt.xfo = eyeLeftXfo
        self.eyeROutputTgt.xfo = eyeRightXfo

        # Eval Constraints
        self.headInputConstraint.evaluate()
        self.headOutputConstraint.evaluate()
        self.jawOutputConstraint.evaluate()
        self.eyeLOutputConstraint.evaluate()
        self.eyeROutputConstraint.evaluate()

        # Eval Operators
        self.eyeLeftDirKLOp.evaluate()
        self.eyeRightDirKLOp.evaluate()
        self.outputsToDeformersKLOp.evaluate()

        # Have to set the eye control xfos to match the evaluated xfos from
        self.eyeLeftCtrl.xfo = self.eyeLeftCtrlSpace.xfo
        self.eyeRightCtrl.xfo = self.eyeRightCtrlSpace.xfo
Esempio n. 13
0
class FabriceHeadGuide(FabriceHead):
    """Fabrice Head Component Guide"""

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

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


        # =========
        # Controls
        # =========
        guideSettingsAttrGrp = AttributeGroup("GuideSettings", parent=self)

        self.headCtrl = Control('head', parent=self.ctrlCmpGrp, shape="circle")
        self.headCtrl.rotatePoints(90.0, 0.0, 0.0)
        self.headCtrl.scalePoints(Vec3(3.5, 3.5, 3.5))

        self.jawCtrl = Control('jaw', parent=self.ctrlCmpGrp, shape="cube")
        self.jawCtrl.alignOnZAxis()
        self.jawCtrl.scalePoints(Vec3(2.0, 0.5, 2.0))
        self.jawCtrl.alignOnYAxis(negative=True)
        self.jawCtrl.setColor('orange')

        data = {
                "name": name,
                "location": "M",
                "headXfo": Xfo(Vec3(0.0, 1.67, 1.75)),
                "headCtrlCrvData": self.headCtrl.getCurveData(),
                "jawPosition": Vec3(0.0, 1.2787, 2.0078),
                "jawCtrlCrvData": self.jawCtrl.getCurveData(),
               }

        self.loadData(data)

        Profiler.getInstance().pop()


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

        Return:
        The JSON data object

        """

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

        data['headXfo'] = self.headCtrl.xfo
        data['headCtrlCrvData'] = self.headCtrl.getCurveData()
        data['jawPosition'] = self.jawCtrl.xfo.tr
        data['jawCtrlCrvData'] = self.jawCtrl.getCurveData()

        return data


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

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

        Return:
        True if successful.

        """

        super(FabriceHeadGuide, self).loadData( data )

        self.headCtrl.xfo = data['headXfo']
        self.headCtrl.setCurveData(data['headCtrlCrvData'])
        self.jawCtrl.xfo.tr = data['jawPosition']
        self.jawCtrl.setCurveData(data['jawCtrlCrvData'])

        return True


    def getRigBuildData(self):
        """Returns the Guide data used by the Rig Component to define the layout of the final rig..

        Return:
        The JSON rig data object.

        """

        data = super(FabriceHeadGuide, self).getRigBuildData()

        data['headXfo'] = self.headCtrl.xfo
        data['headCtrlCrvData'] = self.headCtrl.getCurveData()
        data['jawPosition'] = self.jawCtrl.xfo.tr
        data['jawCtrlCrvData'] = self.jawCtrl.getCurveData()

        return data


    # ==============
    # Class Methods
    # ==============
    @classmethod
    def getComponentType(cls):
        """Enables introspection of the class prior to construction to determine if it is a guide component.

        Return:
        The true if this component is a guide component.

        """

        return 'Guide'

    @classmethod
    def getRigComponentClass(cls):
        """Returns the corresponding rig component class for this guide component class

        Return:
        The rig component class.

        """

        return FabriceHeadRig
Esempio n. 14
0
class FabriceHeadRig(FabriceHead):
    """Fabrice Head Component Rig"""

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


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

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

        Return:
        True if successful.

        """

        super(FabriceHeadRig, self).loadData( data )

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

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

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

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

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

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

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

        # evaluate the constraints to ensure the outputs are now in the correct location.
        self.headToAimConstraint.evaluate()
        self.headAimInputConstraint.evaluate()
        self.headOutputConstraint.evaluate()
        self.jawOutputConstraint.evaluate()
Esempio n. 15
0
class FabriceHeadRig(FabriceHead):
    """Fabrice Head Component Rig"""
    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()

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

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

        Return:
        True if successful.

        """

        super(FabriceHeadRig, self).loadData(data)

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

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

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

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

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

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

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

        # evaluate the constraints to ensure the outputs are now in the correct location.
        self.headToAimConstraint.evaluate()
        self.headAimInputConstraint.evaluate()
        self.headOutputConstraint.evaluate()
        self.jawOutputConstraint.evaluate()
Esempio n. 16
0
class FabriceClavicleGuide(FabriceClavicle):
    """Clavicle Component Guide"""

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

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


        # =========
        # Controls
        # =========
        # Guide Controls
        guideSettingsAttrGrp = AttributeGroup("GuideSettings", parent=self)

        self.clavicleCtrl = Control('clavicle', parent=self.ctrlCmpGrp, shape="cube")
        self.clavicleCtrl.alignOnXAxis()
        self.clavicleCtrl.scalePoints(Vec3(1.0, 0.25, 0.25))

        data = {
                "name": name,
                "location": "L",
                "clavicleXfo": Xfo(Vec3(0.1322, 15.403, -0.5723)),
                'clavicleCtrlCrvData': self.clavicleCtrl.getCurveData()
               }

        self.loadData(data)

        Profiler.getInstance().pop()


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

        Return:
        The JSON data object

        """

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

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

        return data


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

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

        Return:
        True if successful.

        """

        super(FabriceClavicleGuide, self).loadData( data )

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

        return True


    def getRigBuildData(self):
        """Returns the Guide data used by the Rig Component to define the layout of the final rig..

        Return:
        The JSON rig data object.

        """

        data = super(FabriceClavicleGuide, self).getRigBuildData()


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

        return data


    # ==============
    # Class Methods
    # ==============
    @classmethod
    def getComponentType(cls):
        """Enables introspection of the class prior to construction to determine if it is a guide component.

        Return:
        The true if this component is a guide component.

        """

        return 'Guide'

    @classmethod
    def getRigComponentClass(cls):
        """Returns the corresponding rig component class for this guide component class

        Return:
        The rig component class.

        """

        return FabriceClavicleRig
Esempio n. 17
0
class FabriceHeadGuide(FabriceHead):
    """Fabrice Head Component Guide"""
    def __init__(self, name='head', parent=None):

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

        # =========
        # Controls
        # =========
        guideSettingsAttrGrp = AttributeGroup("GuideSettings", parent=self)

        self.headCtrl = Control('head', parent=self.ctrlCmpGrp, shape="circle")
        self.headCtrl.rotatePoints(90.0, 0.0, 0.0)
        self.headCtrl.scalePoints(Vec3(3.5, 3.5, 3.5))

        self.jawCtrl = Control('jaw', parent=self.ctrlCmpGrp, shape="cube")
        self.jawCtrl.alignOnZAxis()
        self.jawCtrl.scalePoints(Vec3(2.0, 0.5, 2.0))
        self.jawCtrl.alignOnYAxis(negative=True)
        self.jawCtrl.setColor('orange')

        data = {
            "name": name,
            "location": "M",
            "headXfo": Xfo(Vec3(0.0, 1.67, 1.75)),
            "headCtrlCrvData": self.headCtrl.getCurveData(),
            "jawPosition": Vec3(0.0, 1.2787, 2.0078),
            "jawCtrlCrvData": self.jawCtrl.getCurveData(),
        }

        self.loadData(data)

        Profiler.getInstance().pop()

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

        Return:
        The JSON data object

        """

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

        data['headXfo'] = self.headCtrl.xfo
        data['headCtrlCrvData'] = self.headCtrl.getCurveData()
        data['jawPosition'] = self.jawCtrl.xfo.tr
        data['jawCtrlCrvData'] = self.jawCtrl.getCurveData()

        return data

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

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

        Return:
        True if successful.

        """

        super(FabriceHeadGuide, self).loadData(data)

        self.headCtrl.xfo = data['headXfo']
        self.headCtrl.setCurveData(data['headCtrlCrvData'])
        self.jawCtrl.xfo.tr = data['jawPosition']
        self.jawCtrl.setCurveData(data['jawCtrlCrvData'])

        return True

    def getRigBuildData(self):
        """Returns the Guide data used by the Rig Component to define the layout of the final rig..

        Return:
        The JSON rig data object.

        """

        data = super(FabriceHeadGuide, self).getRigBuildData()

        data['headXfo'] = self.headCtrl.xfo
        data['headCtrlCrvData'] = self.headCtrl.getCurveData()
        data['jawPosition'] = self.jawCtrl.xfo.tr
        data['jawCtrlCrvData'] = self.jawCtrl.getCurveData()

        return data

    # ==============
    # Class Methods
    # ==============
    @classmethod
    def getComponentType(cls):
        """Enables introspection of the class prior to construction to determine if it is a guide component.

        Return:
        The true if this component is a guide component.

        """

        return 'Guide'

    @classmethod
    def getRigComponentClass(cls):
        """Returns the corresponding rig component class for this guide component class

        Return:
        The rig component class.

        """

        return FabriceHeadRig
Esempio n. 18
0
class FabriceTailRig(FabriceTail):
    """Fabrice Tail Component"""

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

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


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

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

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

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

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


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


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


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

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

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

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


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

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

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

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

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

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

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

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

        Profiler.getInstance().pop()


    def setNumDeformers(self, numDeformers):

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

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

        return True


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

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

        Return:
        True if successful.

        """

        super(FabriceTailRig, self).loadData( data )

        tailBasePos = data['tailBasePos']

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

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

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

        numDeformers = data['numDeformers']

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

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

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

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

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

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

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

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

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

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

        # evaluate the constraints to ensure the outputs are now in the correct location.
        self.tailBaseHandleInputConstraint.evaluate()
        self.tailBaseOutputConstraint.evaluate()
        self.tailEndOutputConstraint.evaluate()
Esempio n. 19
0
class FabriceTailGuide(FabriceTail):
    """Fabrice Tail Component Guide"""

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

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

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


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

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

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

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

        # ===============
        # Add Splice Ops
        # ===============
        # Add Tail Splice Op
        self.bezierSpineKLOp = KLOperator('spineGuideKLOp', 'BezierSpineSolver', 'Kraken')
        self.bezierSpineKLOp.setOutput('outputs', self.tailVertebraeOutput.getTarget())

        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.tailBaseCtrl)
        self.bezierSpineKLOp.setInput('baseHandle', self.tailBaseHandleCtrl)
        self.bezierSpineKLOp.setInput('tipHandle', self.tailEndHandleCtrl)
        self.bezierSpineKLOp.setInput('tip', self.tailEndCtrl)

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

        Profiler.getInstance().pop()


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

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

        Return:
        True if successful.

        """

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


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

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

        return True

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

        Return:
        The JSON data object

        """

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

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

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

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

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

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

        return data


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

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

        Return:
        True if successful.

        """

        super(FabriceTailGuide, self).loadData( data )

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

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

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

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

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

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

        self.bezierSpineKLOp.evaluate()

        return True


    def getRigBuildData(self):
        """Returns the Guide data used by the Rig Component to define the layout of the final rig.

        Return:
        The JSON rig data object.

        """

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

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

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

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

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

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

        return data


    # ==============
    # Class Methods
    # ==============
    @classmethod
    def getComponentType(cls):
        """Enables introspection of the class prior to construction to determine if it is a guide component.

        Return:
        The true if this component is a guide component.

        """

        return 'Guide'

    @classmethod
    def getRigComponentClass(cls):
        """Returns the corresponding rig component class for this guide component class

        Return:
        The rig component class.

        """

        return FabriceTailRig
Esempio n. 20
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()