예제 #1
0
    def __init__(self, name='mainSrt', parent=None):

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

        # =========
        # Attributes
        # =========
        # Add Component Params to IK control
        guideSettingsAttrGrp = AttributeGroup("GuideSettings", parent=self)

        self.mainSrtSizeInputAttr = ScalarAttribute('mainSrtSize', value=5.0, minValue=1.0, maxValue=50.0, parent=guideSettingsAttrGrp)

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

        # Guide Controls
        self.mainSrtCtrl = Control('mainSrt', parent=self.ctrlCmpGrp, shape="circle")

        data = {
                "location": 'M',
                "mainSrtSize": self.mainSrtSizeInputAttr.getValue(),
                "mainSrtXfo": Xfo(tr=Vec3(0.0, 0.0, 0.0))
               }

        self.loadData(data)

        Profiler.getInstance().pop()
예제 #2
0
    def __init__(self, name='twist', parent=None):

        Profiler.getInstance().push('Construct Spine Guide Component:' + name)
        super(TwistComponentGuide, self).__init__(name, parent)

        # =========
        # Controls
        # ========
        guideSettingsAttrGrp = AttributeGroup('GuideSettings', parent=self)
        self.numDeformersAttr = IntegerAttribute('numDeformers',
                                                 value=1,
                                                 minValue=0,
                                                 maxValue=20,
                                                 parent=guideSettingsAttrGrp)
        self.blendBiasAttr = ScalarAttribute('blendBias',
                                             value=0.0,
                                             minValue=0,
                                             maxValue=1.0,
                                             parent=guideSettingsAttrGrp)

        # Guide Controls
        triangleCtrl = Control('triangle', shape='triangle')
        triangleCtrl.rotatePoints(90, 0, 0)
        triangleCtrl.scalePoints(Vec3(0.25, 0.25, 0.25))
        triangleCtrl.scalePoints(Vec3(1.0, 0.5, 1.0))
        triangleCtrl.translatePoints(Vec3(0.0, 1.25, 0.0))
        triangleCtrl.rotatePoints(0, 90, 0)

        self.originCtrl = Control('origin',
                                  parent=self.ctrlCmpGrp,
                                  shape='circle')
        self.originCtrl.rotatePoints(90, 0, 0)
        self.originCtrl.rotatePoints(0, 90, 0)
        self.originCtrl.appendCurveData(triangleCtrl.getCurveData())
        self.insertCtrl = Control('insert',
                                  parent=self.ctrlCmpGrp,
                                  shape='circle')
        self.insertCtrl.rotatePoints(90, 0, 0)
        self.insertCtrl.rotatePoints(0, 90, 0)
        self.insertCtrl.appendCurveData(triangleCtrl.getCurveData())

        self.default_data = {
            'name': name,
            'location': 'M',
            'blendBias': 0.5,
            'originXfo': Xfo(Vec3(0.0, 0.0, 0.0)),
            'insertXfo': Xfo(Vec3(5.0, 0.0, 0.0)),
            'numDeformers': 5
        }

        self.loadData(self.default_data)

        Profiler.getInstance().pop()
예제 #3
0
    def createOutput(self, name, dataType, **kwargs):
        """Creates an output object and also a connected target object that matches
        the data type that is passed.

        Args:
            name (str): Name of the output to create.
            dataType (str): Data type of the output.

        Returns:
            Object: The connected target object for the output.

        """

        componentOutputPort = self.addOutput(name, dataType)

        if dataType.endswith('[]'):
            newOutputTgt = []
        else:
            # Create object
            if dataType.startswith('Xfo'):
                newOutputTgt = ComponentOutput(name)

            elif dataType.startswith('Boolean'):
                newOutputTgt = BoolAttribute(name)

            elif dataType.startswith('Float'):
                newOutputTgt = ScalarAttribute(name)

            elif dataType.startswith('Integer'):
                newOutputTgt = IntegerAttribute(name)

            elif dataType.startswith('String'):
                newOutputTgt = StringAttribute(name)

        # Handle keyword arguments
        for k, v in kwargs.iteritems():
            if k == 'value':
                newOutputTgt.setValue(v)
            elif k == 'minValue':
                newOutputTgt.setMin(v)
            elif k == 'maxValue':
                newOutputTgt.setMax(v)
            elif k == 'parent':
                if isinstance(newOutputTgt, list):
                    raise Exception(
                        "Array outputs cannot be assigned to a parent. Each element in the array must be parented individually: "
                        + name + ".")

                if dataType.startswith('Xfo'):
                    v.addChild(newOutputTgt)
                else:
                    v.addAttribute(newOutputTgt)
            else:
                logger.warning(
                    "Keyword '%s' is not supported with createOutput method!" %
                    k)

        componentOutputPort.setTarget(newOutputTgt)

        return componentOutputPort
예제 #4
0
    def __init__(self, name="mainSrt", parent=None, data=None):

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

        # =========
        # Attributes
        # =========
        # Add Component Params to IK control
        guideSettingsAttrGrp = AttributeGroup("GuideSettings", parent=self)

        self.mainSrtSizeInputAttr = ScalarAttribute(
            "mainSrtSize", value=5.0, minValue=1.0, maxValue=50.0, parent=guideSettingsAttrGrp
        )

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

        # Guide Controls
        self.mainSrtCtrl = Control("mainSrt", parent=self.ctrlCmpGrp, shape="circle")

        if data is None:
            data = {
                "location": "M",
                "mainSrtSize": self.mainSrtSizeInputAttr.getValue(),
                "mainSrtXfo": Xfo(tr=Vec3(0.0, 0.0, 0.0)),
            }

        self.loadData(data)

        Profiler.getInstance().pop()
예제 #5
0
    def createInput(self, name, dataType, **kwargs):
        """Creates an input object and also a connected target object that matches
        the data type that is passed.

        Args:
            name (str): Name of the input to create.
            dataType (str): Data type of the input.

        Returns:
            Object: The connected target object for the input.

        """

        componentInputPort = self.addInput(name, dataType)

        # Create object
        if dataType.startswith('Xfo'):
            newInputTgt = ComponentInput(name)

        elif dataType.startswith('Boolean'):
            newInputTgt = BoolAttribute(name)

        elif dataType.startswith('Float'):
            newInputTgt = ScalarAttribute(name)

        elif dataType.startswith('Integer'):
            newInputTgt = IntegerAttribute(name)

        elif dataType.startswith('String'):
            newInputTgt = StringAttribute(name)

        # Handle keyword arguments
        for k, v in kwargs.iteritems():
            if k == 'value':
                newInputTgt.setValue(v)
            elif k == 'minValue':
                newInputTgt.setMin(v)
                newInputTgt.setUIMin(v)
            elif k == 'maxValue':
                newInputTgt.setMax(v)
                newInputTgt.setUIMax(v)
            elif k == 'parent':
                if dataType.startswith('Xfo'):
                    v.addChild(newInputTgt)
                else:
                    v.addAttribute(newInputTgt)
            else:
                logger.warning(
                    "Keyword '%s' is not supported with createInput method!" %
                    k)

        componentInputPort.setTarget(newInputTgt)

        return componentInputPort
예제 #6
0
    def __init__(self, name='SimpleControl', parent=None):

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

        # =========
        # Attributes
        # =========
        # Add Component Params to IK control
        guideSettingsAttrGrp = AttributeGroup("GuideSettings", parent=self)

        self.ctrlSizeInputAttr = ScalarAttribute('ctrlSize',
                                                 value=5.0,
                                                 minValue=1.0,
                                                 maxValue=50.0,
                                                 parent=guideSettingsAttrGrp)
        self.ctrlSizeInputAttr.setValueChangeCallback(self.resizeMainCtrl)

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

        # Guide Controls
        self.mainCtrl = Control('main', parent=self.ctrlCmpGrp, shape='square')
        self.mainCtrl.rotatePoints(90, 0, 0)

        data = {
            "location": 'M',
            "ctrlSize": self.ctrlSizeInputAttr.getValue(),
            "ctrlXfo": Xfo(tr=Vec3(0.0, 0.0, 0.0))
        }

        self.loadData(data)

        Profiler.getInstance().pop()
예제 #7
0
    def __init__(self, name='twist', parent=None):

        Profiler.getInstance().push('Construct Spine Guide Component:' + name)
        super(TwistComponentGuide, self).__init__(name, parent)

        # =========
        # Controls
        # ========
        guideSettingsAttrGrp = AttributeGroup('GuideSettings', parent=self)
        self.numDeformersAttr = IntegerAttribute('numDeformers', value=1, minValue=0, maxValue=20, parent=guideSettingsAttrGrp)
        self.blendBiasAttr = ScalarAttribute('blendBias', value=0.0, minValue=0, maxValue=1.0, parent=guideSettingsAttrGrp)

        # Guide Controls
        triangleCtrl = Control('triangle', shape='triangle')
        triangleCtrl.rotatePoints(90, 0, 0)
        triangleCtrl.scalePoints(Vec3(0.25, 0.25, 0.25))
        triangleCtrl.scalePoints(Vec3(1.0, 0.5, 1.0))
        triangleCtrl.translatePoints(Vec3(0.0, 1.25, 0.0))
        triangleCtrl.rotatePoints(0, 90, 0)

        self.originCtrl = Control('origin', parent=self.ctrlCmpGrp, shape='circle')
        self.originCtrl.rotatePoints(90, 0, 0)
        self.originCtrl.rotatePoints(0, 90, 0)
        self.originCtrl.appendCurveData(triangleCtrl.getCurveData())
        self.insertCtrl = Control('insert', parent=self.ctrlCmpGrp, shape='circle')
        self.insertCtrl.rotatePoints(90, 0, 0)
        self.insertCtrl.rotatePoints(0, 90, 0)
        self.insertCtrl.appendCurveData(triangleCtrl.getCurveData())

        self.default_data = {
            'name': name,
            'location': 'M',
            'blendBias': 0.5,
            'originXfo': Xfo(Vec3(0.0, 0.0, 0.0)),
            'insertXfo': Xfo(Vec3(5.0, 0.0, 0.0)),
            'numDeformers': 5
        }

        self.loadData(self.default_data)

        Profiler.getInstance().pop()
예제 #8
0
class FootComponentRig(FootComponent):
    """Foot Component"""

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

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


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

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

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

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

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

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

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

        self.drawDebugInputAttr.connect(self.footDebugInputAttr)

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

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

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

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

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


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

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

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


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

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

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


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

        self.addOperator(self.footPivotCanvasOp)

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

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

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


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

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

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

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


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

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

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

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

        Profiler.getInstance().pop()


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

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

        Return:
        True if successful.

        """

        super(FootComponentRig, self).loadData( data )

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

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

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

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

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

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

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

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

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

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

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

        # Eval Constraints
        self.ikTargetOutputConstraint.evaluate()
        self.ankleFKInputConstraint.evaluate()
예제 #9
0
    def addFinger(self, name):

        digitSizeAttributes = []
        fingerGuideCtrls = []

        firstDigitCtrl = Control(name + "01", parent=self.handCtrl, shape='sphere')
        firstDigitCtrl.scalePoints(Vec3(0.125, 0.125, 0.125))

        firstDigitShapeCtrl = Control(name + "Shp01", parent=self.guideCtrlHrcGrp, shape='square')
        firstDigitShapeCtrl.setColor('yellow')
        firstDigitShapeCtrl.scalePoints(Vec3(0.175, 0.175, 0.175))
        firstDigitShapeCtrl.translatePoints(Vec3(0.0, 0.125, 0.0))
        fingerGuideCtrls.append(firstDigitShapeCtrl)
        firstDigitCtrl.shapeCtrl = firstDigitShapeCtrl

        firstDigitVisAttr = firstDigitShapeCtrl.getVisibilityAttr()
        firstDigitVisAttr.connect(self.ctrlShapeToggle)

        triangleCtrl = Control('tempCtrl', parent=None, shape='triangle')
        triangleCtrl.rotatePoints(90.0, 0.0, 0.0)
        triangleCtrl.scalePoints(Vec3(0.025, 0.025, 0.025))
        triangleCtrl.translatePoints(Vec3(0.0, 0.0875, 0.0))

        firstDigitCtrl.appendCurveData(triangleCtrl.getCurveData())
        firstDigitCtrl.lockScale(True, True, True)

        digitSettingsAttrGrp = AttributeGroup("DigitSettings", parent=firstDigitCtrl)
        digitSizeAttr = ScalarAttribute('size', value=0.25, parent=digitSettingsAttrGrp)
        digitSizeAttributes.append(digitSizeAttr)

        # Set Finger
        self.fingers[name] = []
        self.fingers[name].append(firstDigitCtrl)

        parent = firstDigitCtrl
        numJoints = self.numJointsAttr.getValue()
        if name == "thumb":
            numJoints = 3
        for i in xrange(2, numJoints + 2):
            digitCtrl = Control(name + str(i).zfill(2), parent=parent, shape='sphere')

            if i != numJoints + 1:
                digitCtrl.scalePoints(Vec3(0.125, 0.125, 0.125))
                digitCtrl.appendCurveData(triangleCtrl.getCurveData())

                digitShapeCtrl = Control(name + 'Shp' + str(i).zfill(2), parent=self.guideCtrlHrcGrp, shape='circle')
                digitShapeCtrl.setColor('yellow')
                digitShapeCtrl.scalePoints(Vec3(0.175, 0.175, 0.175))
                digitShapeCtrl.getVisibilityAttr().connect(self.ctrlShapeToggle)

                digitCtrl.shapeCtrl = digitShapeCtrl

                if i == 2:
                    digitShapeCtrl.translatePoints(Vec3(0.0, 0.125, 0.0))
                else:
                    digitShapeCtrl.rotatePoints(0.0, 0.0, 90.0)

                fingerGuideCtrls.append(digitShapeCtrl)

                # Add size attr to all but last guide control
                digitSettingsAttrGrp = AttributeGroup("DigitSettings", parent=digitCtrl)
                digitSizeAttr = ScalarAttribute('size', value=0.25, parent=digitSettingsAttrGrp)
                digitSizeAttributes.append(digitSizeAttr)
            else:
                digitCtrl.scalePoints(Vec3(0.0875, 0.0875, 0.0875))

            digitCtrl.lockScale(True, True, True)

            self.fingers[name].append(digitCtrl)

            parent = digitCtrl

        # ===========================
        # Create Canvas Operators
        # ===========================
        # Add Finger Guide Canvas Op
        fingerGuideCanvasOp = CanvasOperator(name + 'FingerGuide', 'Kraken.Solvers.Biped.BipedFingerGuideSolver')
        self.addOperator(fingerGuideCanvasOp)

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

        # Add Xfo Inputs
        fingerGuideCanvasOp.setInput('controls', self.fingers[name])
        fingerGuideCanvasOp.setInput('planeSizes', digitSizeAttributes)

        # Add Xfo Outputs
        fingerGuideCanvasOp.setOutput('result', fingerGuideCtrls)
        fingerGuideCanvasOp.setOutput('forceEval', firstDigitCtrl.getVisibilityAttr())

        return firstDigitCtrl
예제 #10
0
    def __init__(self, name='mainSrt', parent=None):

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

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

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

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

        self.rigScaleOutputAttr.connect(self.rigScaleAttr)

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

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

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

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

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

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

        # Add Xfo Inputs

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

        Profiler.getInstance().pop()
예제 #11
0
class SimpleControlComponentGuide(SimpleControlComponent):
    """Simple Control Component Guide"""
    def __init__(self, name='SimpleControl', parent=None):

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

        # =========
        # Attributes
        # =========
        # Add Component Params to IK control
        guideSettingsAttrGrp = AttributeGroup("GuideSettings", parent=self)

        self.ctrlSizeInputAttr = ScalarAttribute('ctrlSize',
                                                 value=5.0,
                                                 minValue=1.0,
                                                 maxValue=50.0,
                                                 parent=guideSettingsAttrGrp)
        self.ctrlSizeInputAttr.setValueChangeCallback(self.resizeMainCtrl)

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

        # Guide Controls
        self.mainCtrl = Control('main', parent=self.ctrlCmpGrp, shape='square')
        self.mainCtrl.rotatePoints(90, 0, 0)

        data = {
            "location": 'M',
            "ctrlSize": self.ctrlSizeInputAttr.getValue(),
            "ctrlXfo": Xfo(tr=Vec3(0.0, 0.0, 0.0))
        }

        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(SimpleControlComponentGuide, self).saveData()

        data["ctrlSize"] = self.ctrlSizeInputAttr.getValue()
        data["ctrlXfo"] = self.mainCtrl.xfo

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

        self.ctrlSizeInputAttr.setValue(data["ctrlSize"])
        self.mainCtrl.xfo = data["ctrlXfo"]

        scaleValue = data["ctrlSize"]
        self.mainCtrl.setShape('square')
        self.mainCtrl.rotatePoints(90, 0, 0)
        self.mainCtrl.scalePoints(Vec3(scaleValue, scaleValue, scaleValue))

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

        data["ctrlSize"] = self.ctrlSizeInputAttr.getValue()
        data["ctrlXfo"] = self.mainCtrl.xfo

        return data

    # ==========
    # Callbacks
    # ==========
    def resizeMainCtrl(self, newSize):
        self.mainCtrl.setShape('square')
        self.mainCtrl.rotatePoints(90, 0, 0)
        self.mainCtrl.scalePoints(Vec3(newSize, newSize, newSize))

    # ==============
    # 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 SimpleControlComponentRig
예제 #12
0
    def __init__(self, name='arm', parent=None, *args, **kwargs):
        Profiler.getInstance().push("Construct Arm Guide Component:" + name)
        super(ArmComponentGuide, self).__init__(name, parent, *args, **kwargs)

        # ===========
        # Attributes
        # ===========
        # Add Component Params to IK control
        guideSettingsAttrGrp = AttributeGroup("GuideSettings", parent=self)

        self.bicepFKCtrlSizeInputAttr = ScalarAttribute(
            'bicepFKCtrlSize',
            value=1.75,
            minValue=0.0,
            maxValue=10.0,
            parent=guideSettingsAttrGrp)
        self.forearmFKCtrlSizeInputAttr = ScalarAttribute(
            'forearmFKCtrlSize',
            value=1.5,
            minValue=0.0,
            maxValue=10.0,
            parent=guideSettingsAttrGrp)

        # =========
        # Controls
        # =========
        # Guide Controls
        self.bicepCtrl = Control('bicep',
                                 parent=self.ctrlCmpGrp,
                                 shape="sphere")
        self.bicepCtrl.setColor('blue')
        self.forearmCtrl = Control('forearm',
                                   parent=self.ctrlCmpGrp,
                                   shape="sphere")
        self.forearmCtrl.setColor('blue')
        self.wristCtrl = Control('wrist',
                                 parent=self.ctrlCmpGrp,
                                 shape="sphere")
        self.wristCtrl.setColor('blue')

        armGuideSettingsAttrGrp = AttributeGroup("DisplayInfo_ArmSettings",
                                                 parent=self.bicepCtrl)
        self.armGuideDebugAttr = BoolAttribute('drawDebug',
                                               value=True,
                                               parent=armGuideSettingsAttrGrp)

        self.guideOpHost = Transform('guideOpHost', self.ctrlCmpGrp)

        # Guide Operator
        self.armGuideKLOp = KLOperator('guide', 'TwoBoneIKGuideSolver',
                                       'Kraken')
        self.addOperator(self.armGuideKLOp)

        # Add Att Inputs
        self.armGuideKLOp.setInput('drawDebug', self.armGuideDebugAttr)
        self.armGuideKLOp.setInput('rigScale', self.rigScaleInputAttr)

        # Add Source Inputs
        self.armGuideKLOp.setInput('root', self.bicepCtrl)
        self.armGuideKLOp.setInput('mid', self.forearmCtrl)
        self.armGuideKLOp.setInput('end', self.wristCtrl)

        # Add Target Outputs
        self.armGuideKLOp.setOutput('guideOpHost', self.guideOpHost)

        self.default_data = {
            "name": name,
            "location": "L",
            "bicepXfo": Xfo(Vec3(2.275, 15.3, -0.75)),
            "forearmXfo": Xfo(Vec3(5.0, 13.5, -0.75)),
            "wristXfo": Xfo(Vec3(7.2, 12.25, 0.5)),
            "bicepFKCtrlSize": self.bicepFKCtrlSizeInputAttr.getValue(),
            "forearmFKCtrlSize": self.forearmFKCtrlSizeInputAttr.getValue()
        }

        self.loadData(self.default_data)

        Profiler.getInstance().pop()
예제 #13
0
    def __init__(self, name='Tentacle', parent=None):

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

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

        # Chain Base
        self.chainBase = Locator('ChainBase', parent=self.ctrlCmpGrp)
        self.chainBase.setShapeVisibility(False)

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

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

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

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

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

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

        # =====================
        # Create Component I/O
        # =====================

        # Set IO Targets
        self.boneOutputs.setTarget(self.boneOutputsTgt)

        # ==============
        # Constrain I/O
        # ==============
        # Constraint inputs
        tentacleRootInputConstraint = PoseConstraint('_'.join([
            self.fkCtrlSpaces[0].getName(), 'To',
            self.rootInputTgt.getName()
        ]))
        tentacleRootInputConstraint.setMaintainOffset(True)
        tentacleRootInputConstraint.addConstrainer(self.rootInputTgt)
        self.fkCtrlSpaces[0].addConstraint(tentacleRootInputConstraint)

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

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

        # ===============
        # Add Canvas Ops
        # ===============
        # Add Canvas Op
        self.tentacleSolverKLOp = KLOperator('tentacle', 'TentacleSolver',
                                             'Kraken')
        self.addOperator(self.tentacleSolverKLOp)

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

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

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

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

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

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

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

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

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

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

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

        Profiler.getInstance().pop()
예제 #14
0
    def __init__(self, name='arm', parent=None):

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

        # =========
        # Controls
        # =========
        # Bicep
        self.bicepFKCtrlSpace = CtrlSpace('bicepFK', parent=self.ctrlCmpGrp)

        self.bicepFKCtrl = Control('bicepFK',
                                   parent=self.bicepFKCtrlSpace,
                                   shape="cube")
        self.bicepFKCtrl.alignOnXAxis()

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

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

        self.handCtrlSpace = CtrlSpace('hand', parent=self.ctrlCmpGrp)
        self.handCtrl = Control('hand',
                                parent=self.handCtrlSpace,
                                shape="circle")
        self.handCtrl.rotatePoints(0, 0, 90)
        self.handCtrl.scalePoints(Vec3(1.0, 0.75, 0.75))

        # Arm IK
        self.armIKCtrlSpace = CtrlSpace('IK', parent=self.ctrlCmpGrp)
        self.armIKCtrl = Control('IK', parent=self.armIKCtrlSpace, shape="pin")

        # Add Params to IK control
        armSettingsAttrGrp = AttributeGroup("DisplayInfo_ArmSettings",
                                            parent=self.armIKCtrl)
        armDebugInputAttr = BoolAttribute('drawDebug',
                                          value=False,
                                          parent=armSettingsAttrGrp)
        self.armBone0LenInputAttr = ScalarAttribute('bone1Len',
                                                    value=0.0,
                                                    parent=armSettingsAttrGrp)
        self.armBone1LenInputAttr = ScalarAttribute('bone2Len',
                                                    value=0.0,
                                                    parent=armSettingsAttrGrp)
        armIKBlendInputAttr = ScalarAttribute('fkik',
                                              value=0.0,
                                              minValue=0.0,
                                              maxValue=1.0,
                                              parent=armSettingsAttrGrp)
        armSoftIKInputAttr = BoolAttribute('softIK',
                                           value=True,
                                           parent=armSettingsAttrGrp)
        armSoftDistInputAttr = ScalarAttribute('softDist',
                                               value=0.0,
                                               minValue=0.0,
                                               parent=armSettingsAttrGrp)
        armStretchInputAttr = BoolAttribute('stretch',
                                            value=True,
                                            parent=armSettingsAttrGrp)
        armStretchBlendInputAttr = ScalarAttribute('stretchBlend',
                                                   value=0.0,
                                                   minValue=0.0,
                                                   maxValue=1.0,
                                                   parent=armSettingsAttrGrp)

        # Hand Params
        handSettingsAttrGrp = AttributeGroup("DisplayInfo_HandSettings",
                                             parent=self.handCtrl)
        handLinkToWorldInputAttr = ScalarAttribute('linkToWorld',
                                                   0.0,
                                                   maxValue=1.0,
                                                   parent=handSettingsAttrGrp)

        self.drawDebugInputAttr.connect(armDebugInputAttr)

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

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

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

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

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

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

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

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

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

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

        self.handCtrlSpaceConstraint = PoseConstraint('_'.join([
            self.handCtrlSpace.getName(), 'To',
            self.armEndXfoOutputTgt.getName()
        ]))
        self.handCtrlSpaceConstraint.setMaintainOffset(True)
        self.handCtrlSpaceConstraint.addConstrainer(self.armEndXfoOutputTgt)
        self.handCtrlSpace.addConstraint(self.handCtrlSpaceConstraint)

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

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

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

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

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

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

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

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

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

        Profiler.getInstance().pop()
예제 #15
0
    def __init__(self, name='arm', parent=None):
        Profiler.getInstance().push("Construct Arm Guide Component:" + name)
        super(ArmComponentGuide, self).__init__(name, parent)

        # ===========
        # Attributes
        # ===========
        # Add Component Params to IK control
        guideSettingsAttrGrp = AttributeGroup("GuideSettings", parent=self)

        self.bicepFKCtrlSizeInputAttr = ScalarAttribute(
            'bicepFKCtrlSize',
            value=1.75,
            minValue=0.0,
            maxValue=10.0,
            parent=guideSettingsAttrGrp)
        self.forearmFKCtrlSizeInputAttr = ScalarAttribute(
            'forearmFKCtrlSize',
            value=1.5,
            minValue=0.0,
            maxValue=10.0,
            parent=guideSettingsAttrGrp)

        # =========
        # Controls
        # =========
        # Guide Controls
        self.bicepCtrl = Control('bicepFK',
                                 parent=self.ctrlCmpGrp,
                                 shape="sphere")
        self.bicepCtrl.setColor('blue')
        self.forearmCtrl = Control('forearmFK',
                                   parent=self.ctrlCmpGrp,
                                   shape="sphere")
        self.forearmCtrl.setColor('blue')
        self.wristCtrl = Control('wristFK',
                                 parent=self.ctrlCmpGrp,
                                 shape="sphere")
        self.wristCtrl.setColor('blue')
        self.handCtrl = Control('hand', parent=self.ctrlCmpGrp, shape="cube")
        self.handCtrl.setColor('blue')

        data = {
            "name":
            name,
            "location":
            "L",
            "bicepXfo":
            Xfo(Vec3(2.27, 15.295, -0.753)),
            "forearmXfo":
            Xfo(Vec3(5.039, 13.56, -0.859)),
            "wristXfo":
            Xfo(Vec3(7.1886, 12.2819, 0.4906)),
            "handXfo":
            Xfo(tr=Vec3(7.1886, 12.2819, 0.4906),
                ori=Quat(Vec3(-0.0865, -0.2301, -0.2623), 0.9331)),
            "bicepFKCtrlSize":
            1.75,
            "forearmFKCtrlSize":
            1.5
        }

        self.loadData(data)

        Profiler.getInstance().pop()
예제 #16
0
    def __init__(self, name='FKChain', parent=None):

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

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

        # Add Component Params to FK control
        chainSettingsAttrGrp = AttributeGroup("DisplayInfo_ChainSettings",
                                              parent=self.fkCtrls[0])
        chainDrawDebugInputAttr = BoolAttribute('drawDebug',
                                                value=False,
                                                parent=chainSettingsAttrGrp)
        self.simulateInputAttr = BoolAttribute('simulate',
                                               value=False,
                                               parent=chainSettingsAttrGrp)
        self.resetframeInputAttr = ScalarAttribute('resetframe',
                                                   value=1,
                                                   parent=chainSettingsAttrGrp)
        self.frameInputAttr = ScalarAttribute('frame',
                                              value=0,
                                              parent=chainSettingsAttrGrp)
        self.simBlendStartInputAttr = ScalarAttribute(
            'simBlendStart',
            value=0.7,
            minValue=0.0,
            maxValue=1.0,
            parent=chainSettingsAttrGrp)
        self.simBlendEndInputAttr = ScalarAttribute(
            'simBlendEnd',
            value=1.0,
            minValue=0.0,
            maxValue=1.0,
            parent=chainSettingsAttrGrp)
        self.dampeningInputAttr = ScalarAttribute('dampening',
                                                  value=0.3,
                                                  minValue=0.0,
                                                  maxValue=1.0,
                                                  parent=chainSettingsAttrGrp)
        self.gravityInputAttr = ScalarAttribute('gravity',
                                                value=-9.8,
                                                parent=chainSettingsAttrGrp)
        self.massStartInputAttr = ScalarAttribute('massStart',
                                                  value=0.35,
                                                  minValue=0.0,
                                                  maxValue=10.0,
                                                  parent=chainSettingsAttrGrp)
        self.massEndInputAttr = ScalarAttribute('massEnd',
                                                value=1.0,
                                                minValue=0.0,
                                                maxValue=10.0,
                                                parent=chainSettingsAttrGrp)

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

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

        # =====================
        # Create Component I/O
        # =====================

        # Set IO Targets
        self.boneOutputs.setTarget(self.boneOutputsTgt)

        # ==============
        # Constrain I/O
        # ==============
        # Constraint inputs
        self.rootInputConstraint = PoseConstraint('_'.join([
            self.fkCtrlSpaces[0].getName(), 'To',
            self.rootInputTgt.getName()
        ]))
        self.rootInputConstraint.setMaintainOffset(True)
        self.rootInputConstraint.addConstrainer(self.rootInputTgt)
        self.fkCtrlSpaces[0].addConstraint(self.rootInputConstraint)

        # ===============
        # Add Splice Ops
        # ===============
        # Add Output Splice Op
        self.dynamicChainKLOp = KLOperator('dynamicChainKLOp',
                                           'DynamicChainSolver', 'Kraken')
        self.addOperator(self.dynamicChainKLOp)

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

        self.dynamicChainKLOp.setInput('simulate', self.simulateInputAttr)
        self.dynamicChainKLOp.setInput('resetframe', self.resetframeInputAttr)
        self.dynamicChainKLOp.setInput('frame', self.frameInputAttr)
        self.dynamicChainKLOp.setInput('simBlendStart',
                                       self.simBlendStartInputAttr)
        self.dynamicChainKLOp.setInput('simBlendEnd',
                                       self.simBlendEndInputAttr)
        self.dynamicChainKLOp.setInput('dampening', self.dampeningInputAttr)
        self.dynamicChainKLOp.setInput('gravity', self.gravityInputAttr)
        self.dynamicChainKLOp.setInput('massStart', self.massStartInputAttr)
        self.dynamicChainKLOp.setInput('massEnd', self.massEndInputAttr)

        # Add Xfo Inputs
        self.dynamicChainKLOp.setInput('fkPose', self.fkCtrls)

        # Add Xfo Outputs
        self.dynamicChainKLOp.setOutput('animPose', self.boneOutputsTgt)

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

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

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

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

        Profiler.getInstance().pop()
예제 #17
0
class ArmComponentRig(ArmComponent):
    """Arm Component Rig"""
    def __init__(self, name='arm', parent=None):

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

        # =========
        # Controls
        # =========
        # Bicep
        self.bicepFKCtrlSpace = CtrlSpace('bicepFK', parent=self.ctrlCmpGrp)

        self.bicepFKCtrl = Control('bicepFK',
                                   parent=self.bicepFKCtrlSpace,
                                   shape="cube")
        self.bicepFKCtrl.alignOnXAxis()

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

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

        self.handCtrlSpace = CtrlSpace('hand', parent=self.ctrlCmpGrp)
        self.handCtrl = Control('hand',
                                parent=self.handCtrlSpace,
                                shape="circle")
        self.handCtrl.rotatePoints(0, 0, 90)
        self.handCtrl.scalePoints(Vec3(1.0, 0.75, 0.75))

        # Arm IK
        self.armIKCtrlSpace = CtrlSpace('IK', parent=self.ctrlCmpGrp)
        self.armIKCtrl = Control('IK', parent=self.armIKCtrlSpace, shape="pin")

        # Add Params to IK control
        armSettingsAttrGrp = AttributeGroup("DisplayInfo_ArmSettings",
                                            parent=self.armIKCtrl)
        armDebugInputAttr = BoolAttribute('drawDebug',
                                          value=False,
                                          parent=armSettingsAttrGrp)
        self.armBone0LenInputAttr = ScalarAttribute('bone1Len',
                                                    value=0.0,
                                                    parent=armSettingsAttrGrp)
        self.armBone1LenInputAttr = ScalarAttribute('bone2Len',
                                                    value=0.0,
                                                    parent=armSettingsAttrGrp)
        armIKBlendInputAttr = ScalarAttribute('fkik',
                                              value=0.0,
                                              minValue=0.0,
                                              maxValue=1.0,
                                              parent=armSettingsAttrGrp)
        armSoftIKInputAttr = BoolAttribute('softIK',
                                           value=True,
                                           parent=armSettingsAttrGrp)
        armSoftDistInputAttr = ScalarAttribute('softDist',
                                               value=0.0,
                                               minValue=0.0,
                                               parent=armSettingsAttrGrp)
        armStretchInputAttr = BoolAttribute('stretch',
                                            value=True,
                                            parent=armSettingsAttrGrp)
        armStretchBlendInputAttr = ScalarAttribute('stretchBlend',
                                                   value=0.0,
                                                   minValue=0.0,
                                                   maxValue=1.0,
                                                   parent=armSettingsAttrGrp)

        # Hand Params
        handSettingsAttrGrp = AttributeGroup("DisplayInfo_HandSettings",
                                             parent=self.handCtrl)
        handLinkToWorldInputAttr = ScalarAttribute('linkToWorld',
                                                   0.0,
                                                   maxValue=1.0,
                                                   parent=handSettingsAttrGrp)

        self.drawDebugInputAttr.connect(armDebugInputAttr)

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

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

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

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

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

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

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

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

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

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

        self.handCtrlSpaceConstraint = PoseConstraint('_'.join([
            self.handCtrlSpace.getName(), 'To',
            self.armEndXfoOutputTgt.getName()
        ]))
        self.handCtrlSpaceConstraint.setMaintainOffset(True)
        self.handCtrlSpaceConstraint.addConstrainer(self.armEndXfoOutputTgt)
        self.handCtrlSpace.addConstraint(self.handCtrlSpaceConstraint)

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

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

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

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

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

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

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

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

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

        Profiler.getInstance().pop()

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

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

        Return:
        True if successful.

        """

        super(ArmComponentRig, self).loadData(data)

        self.clavicleEndInputTgt.xfo.tr = data['bicepXfo'].tr

        self.bicepFKCtrlSpace.xfo = data['bicepXfo']
        self.bicepFKCtrl.xfo = data['bicepXfo']
        self.bicepFKCtrl.scalePoints(
            Vec3(data['bicepLen'], data['bicepFKCtrlSize'],
                 data['bicepFKCtrlSize']))

        self.bicepOutputTgt.xfo = data['bicepXfo']
        self.forearmOutputTgt.xfo = data['forearmXfo']

        self.forearmFKCtrlSpace.xfo = data['forearmXfo']
        self.forearmFKCtrl.xfo = data['forearmXfo']
        self.forearmFKCtrl.scalePoints(
            Vec3(data['forearmLen'], data['forearmFKCtrlSize'],
                 data['forearmFKCtrlSize']))

        self.handCtrlSpace.xfo = data['handXfo']
        self.handCtrl.xfo = data['handXfo']

        self.armIKCtrlSpace.xfo.tr = data['armEndXfo'].tr
        self.armIKCtrl.xfo.tr = data['armEndXfo'].tr

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

        self.armUpVCtrlSpace.xfo = data['upVXfo']
        self.armUpVCtrl.xfo = data['upVXfo']

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

        # Outputs
        self.handOutputTgt.xfo = data['handXfo']

        # Eval Constraints
        self.armIKCtrlSpaceInputConstraint.evaluate()
        self.armUpVCtrlSpaceInputConstraint.evaluate()
        self.armRootInputConstraint.evaluate()
        self.armRootInputConstraint.evaluate()
        self.handConstraint.evaluate()
        self.handCtrlSpaceConstraint.evaluate()

        # Eval Operators
        self.spliceOp.evaluate()
        self.outputsToDeformersKLOp.evaluate()
예제 #18
0
    def __init__(self, name='limb', parent=None):

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

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

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

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

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

        self.drawDebugInputAttr.connect(limbDrawDebugInputAttr)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        Profiler.getInstance().pop()
예제 #19
0
class StretchyLimbComponentRig(StretchyLimbComponent):
    """StretchyLimb Component"""

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

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

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

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

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

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

        self.drawDebugInputAttr.connect(limbDrawDebugInputAttr)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        Profiler.getInstance().pop()

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

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

        Return:
        True if successful.

        """

        super(StretchyLimbComponentRig, self).loadData(data)

        upperXfo = data.get('upperXfo')
        upperLen = data.get('upperLen')
        lowerXfo = data.get('lowerXfo')
        lowerLen = data.get('lowerLen')
        endXfo = data.get('endXfo')
        upVXfo = data.get('upVXfo')

        self.upperFKCtrlSpace.xfo = upperXfo
        self.upperFKCtrl.xfo = upperXfo
        self.upperFKCtrl.scalePoints(Vec3(upperLen, 1.75, 1.75))

        self.limbUpperOutputTgt.xfo = upperXfo
        self.limbLowerOutputTgt.xfo = lowerXfo

        self.lowerFKCtrlSpace.xfo = lowerXfo
        self.lowerFKCtrl.xfo = lowerXfo
        self.lowerFKCtrl.scalePoints(Vec3(lowerLen, 1.5, 1.5))

        self.limbIKCtrlSpace.xfo.tr = endXfo.tr
        self.limbIKCtrl.xfo.tr = endXfo.tr

        if self.getLocation() == "R":
            self.limbIKCtrl.rotatePoints(0, 90, 0)
            self.limbIKCtrl.translatePoints(Vec3(-1.0, 0.0, 0.0))
        else:
            self.limbIKCtrl.rotatePoints(0, -90, 0)
            self.limbIKCtrl.translatePoints(Vec3(1.0, 0.0, 0.0))

        self.limbUpVCtrlSpace.xfo = upVXfo
        self.limbUpVCtrl.xfo = upVXfo

        self.limbBone0LenInputAttr.setMin(0.0)
        self.limbBone0LenInputAttr.setMax(upperLen * 3.0)
        self.limbBone0LenInputAttr.setValue(upperLen)
        self.limbBone1LenInputAttr.setMin(0.0)
        self.limbBone1LenInputAttr.setMax(lowerLen * 3.0)
        self.limbBone1LenInputAttr.setValue(lowerLen)

        self.limbParentInputTgt.xfo = upperXfo

        # Set Attrs
        self.rightSideInputAttr.setValue(self.getLocation() is 'R')

        # Eval Constraints
        self.limbIKCtrlSpaceInputConstraint.evaluate()
        self.limbUpVCtrlSpaceInputConstraint.evaluate()
        self.limbRootInputConstraint.evaluate()

        # Eval Operators
        self.limbIKKLOp.evaluate()
        self.outputsToDeformersKLOp.evaluate()
예제 #20
0
    def __init__(self, name="foot", parent=None):

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


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

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

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

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

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

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

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

        self.drawDebugInputAttr.connect(self.footDebugInputAttr)

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

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

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

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

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


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

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

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


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

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

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


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

        self.addOperator(self.footPivotCanvasOp)

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

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

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


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

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

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

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


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

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

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

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

        Profiler.getInstance().pop()
예제 #21
0
    def __init__(self, name='arm', parent=None):

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

        # =========
        # Controls
        # =========
        # Bicep
        self.bicepFKCtrlSpace = CtrlSpace('bicepFK', parent=self.ctrlCmpGrp)

        self.bicepFKCtrl = Control('bicepFK',
                                   parent=self.bicepFKCtrlSpace,
                                   shape="cube")
        self.bicepFKCtrl.alignOnXAxis()
        self.bicepFKCtrl.lockScale(True, True, True)
        self.bicepFKCtrl.lockTranslation(True, True, True)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        # Constraint outputs

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

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

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

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

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

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

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

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

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

        Profiler.getInstance().pop()
예제 #22
0
    def __init__(self, name='FKCollision', parent=None):

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

        # =========
        # Controls
        # =========
        # Ground
        self.groundCtrl = Control('ground',
                                  parent=self.ctrlCmpGrp,
                                  shape='square')
        self.groundCtrl.insertCtrlSpace()

        groundSettingsAttrGrp = AttributeGroup("DisplayInfo_ChainSettings",
                                               parent=self.groundCtrl)
        self.groundOffsetYInputAttr = ScalarAttribute(
            'ground_offsetY',
            0.0,
            minValue=0.0,
            maxValue=10.0,
            parent=groundSettingsAttrGrp)

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

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

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

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

        # =====================
        # Create Component I/O
        # =====================

        # Set IO Targets
        self.boneOutputs.setTarget(self.boneOutputsTgt)

        # ==============
        # Constrain I/O
        # ==============
        # Constrain inputs
        self.rootInputConstraint = PoseConstraint('_'.join([
            self.fkCtrlSpaces[0].getName(), 'To',
            self.rootInputTgt.getName()
        ]))
        self.rootInputConstraint.setMaintainOffset(True)
        self.rootInputConstraint.addConstrainer(self.rootInputTgt)
        self.fkCtrlSpaces[0].addConstraint(self.rootInputConstraint)

        # ===============
        # Add Canvas Ops
        # ===============
        # Add Output Canvas Op
        self.collisionCanvasOp = CanvasOperator(
            'collisionCanvasOp', 'Kraken.Solvers.CollideChainSolver')
        self.addOperator(self.collisionCanvasOp)

        # Add Att Inputs
        self.collisionCanvasOp.setInput('drawDebug', self.drawDebugInputAttr)
        self.collisionCanvasOp.setInput('rigScale', self.rigScaleInputAttr)
        self.collisionCanvasOp.setInput('ground_offsetY',
                                        self.groundOffsetYInputAttr)

        # Add Xfo Inputs
        self.collisionCanvasOp.setInput('ground', self.groundCtrl)
        self.collisionCanvasOp.setInput('joints', self.transforms)

        # Add Xfo Outputs
        self.collisionCanvasOp.setOutput('outputs', self.boneOutputsTgt)

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

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

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

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

        Profiler.getInstance().pop()
예제 #23
0
class ArmComponentGuide(ArmComponent):
    """Arm Component Guide"""
    def __init__(self, name='arm', parent=None, *args, **kwargs):
        Profiler.getInstance().push("Construct Arm Guide Component:" + name)
        super(ArmComponentGuide, self).__init__(name, parent, *args, **kwargs)

        # ===========
        # Attributes
        # ===========
        # Add Component Params to IK control
        guideSettingsAttrGrp = AttributeGroup("GuideSettings", parent=self)

        self.bicepFKCtrlSizeInputAttr = ScalarAttribute(
            'bicepFKCtrlSize',
            value=1.75,
            minValue=0.0,
            maxValue=10.0,
            parent=guideSettingsAttrGrp)
        self.forearmFKCtrlSizeInputAttr = ScalarAttribute(
            'forearmFKCtrlSize',
            value=1.5,
            minValue=0.0,
            maxValue=10.0,
            parent=guideSettingsAttrGrp)

        # =========
        # Controls
        # =========
        # Guide Controls
        self.bicepCtrl = Control('bicep',
                                 parent=self.ctrlCmpGrp,
                                 shape="sphere")
        self.bicepCtrl.setColor('blue')
        self.forearmCtrl = Control('forearm',
                                   parent=self.ctrlCmpGrp,
                                   shape="sphere")
        self.forearmCtrl.setColor('blue')
        self.wristCtrl = Control('wrist',
                                 parent=self.ctrlCmpGrp,
                                 shape="sphere")
        self.wristCtrl.setColor('blue')

        armGuideSettingsAttrGrp = AttributeGroup("DisplayInfo_ArmSettings",
                                                 parent=self.bicepCtrl)
        self.armGuideDebugAttr = BoolAttribute('drawDebug',
                                               value=True,
                                               parent=armGuideSettingsAttrGrp)

        self.guideOpHost = Transform('guideOpHost', self.ctrlCmpGrp)

        # Guide Operator
        self.armGuideKLOp = KLOperator('guide', 'TwoBoneIKGuideSolver',
                                       'Kraken')
        self.addOperator(self.armGuideKLOp)

        # Add Att Inputs
        self.armGuideKLOp.setInput('drawDebug', self.armGuideDebugAttr)
        self.armGuideKLOp.setInput('rigScale', self.rigScaleInputAttr)

        # Add Source Inputs
        self.armGuideKLOp.setInput('root', self.bicepCtrl)
        self.armGuideKLOp.setInput('mid', self.forearmCtrl)
        self.armGuideKLOp.setInput('end', self.wristCtrl)

        # Add Target Outputs
        self.armGuideKLOp.setOutput('guideOpHost', self.guideOpHost)

        self.default_data = {
            "name": name,
            "location": "L",
            "bicepXfo": Xfo(Vec3(2.275, 15.3, -0.75)),
            "forearmXfo": Xfo(Vec3(5.0, 13.5, -0.75)),
            "wristXfo": Xfo(Vec3(7.2, 12.25, 0.5)),
            "bicepFKCtrlSize": self.bicepFKCtrlSizeInputAttr.getValue(),
            "forearmFKCtrlSize": self.forearmFKCtrlSizeInputAttr.getValue()
        }

        self.loadData(self.default_data)

        Profiler.getInstance().pop()

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


        Return:
        The JSON data object

        """

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

        data['bicepXfo'] = self.bicepCtrl.xfo
        data['forearmXfo'] = self.forearmCtrl.xfo
        data['wristXfo'] = self.wristCtrl.xfo

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

        self.bicepCtrl.xfo = data['bicepXfo']
        self.forearmCtrl.xfo = data['forearmXfo']
        self.wristCtrl.xfo = data['wristXfo']

        guideOpName = ''.join([
            self.getName().split('GuideKLOp')[0],
            self.getLocation(), 'GuideKLOp'
        ])
        self.armGuideKLOp.setName(guideOpName)

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

        # values
        bicepPosition = self.bicepCtrl.xfo.tr
        forearmPosition = self.forearmCtrl.xfo.tr
        wristPosition = self.wristCtrl.xfo.tr

        # Calculate Bicep Xfo
        rootToWrist = wristPosition.subtract(bicepPosition).unit()
        rootToElbow = forearmPosition.subtract(bicepPosition).unit()

        bone1Normal = rootToWrist.cross(rootToElbow).unit()
        bone1ZAxis = rootToElbow.cross(bone1Normal).unit()

        bicepXfo = Xfo()
        bicepXfo.setFromVectors(rootToElbow, bone1Normal, bone1ZAxis,
                                bicepPosition)

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

        # Calculate Wrist Xfo
        wristXfo = Xfo()
        wristXfo.tr = self.wristCtrl.xfo.tr
        wristXfo.ori = forearmXfo.ori

        upVXfo = xfoFromDirAndUpV(bicepPosition, wristPosition,
                                  forearmPosition)
        upVXfo.tr = forearmPosition
        upVXfo.tr = upVXfo.transformVector(Vec3(0, 0, 5))

        # Lengths
        bicepLen = bicepPosition.subtract(forearmPosition).length()
        forearmLen = forearmPosition.subtract(wristPosition).length()

        data['bicepXfo'] = bicepXfo
        data['forearmXfo'] = forearmXfo
        data['wristXfo'] = wristXfo
        data['upVXfo'] = upVXfo
        data['bicepLen'] = bicepLen
        data['forearmLen'] = forearmLen

        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 ArmComponentRig
예제 #24
0
    def __init__(self, name="spine", parent=None):

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


        # =========
        # Controls
        # =========
        self.originTransform = Transform('origin', parent=self.ctrlCmpGrp)
        self.originUpVTransform = Transform('originUpV', parent=self.ctrlCmpGrp)
        self.insertTransform = Transform('insert', parent=self.ctrlCmpGrp)
        self.insertUpVTransform = Transform('insertUpV', parent=self.ctrlCmpGrp)

        # Add Params to origin transform
        twistSettings = AttributeGroup("DisplayInfo_TwistSettings", parent=self.originTransform)
        self.blendBiasInputAttr = ScalarAttribute('blendBias', value=0.0, minValue=0.0, maxValue=1.0, parent=twistSettings)

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

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


        # ============
        # Constraints
        # ============
        # Constrain inputs

        # Origin and Insert
        constraintName = '_'.join([self.originTransform.getName(),
                                   'To',
                                   self.originInputTgt.getName()])

        self.originInputConstraint = self.originTransform.constrainTo(
            self.originInputTgt,
            constraintType='Position',
            maintainOffset=True,
            name=constraintName)

        constraintName = '_'.join([self.insertTransform.getName(),
                                   'To',
                                   self.insertInputTgt.getName()])

        self.insertInputConstraint = self.insertTransform.constrainTo(
            self.insertInputTgt,
            constraintType='Position',
            maintainOffset=True,
            name=constraintName)

        # Up Vectors
        constraintName = '_'.join([self.originUpVTransform.getName(),
                                   'To',
                                   self.originInputTgt.getName()])

        self.originUpVInputConstraint = self.originUpVTransform.constrainTo(
            self.originInputTgt,
            constraintType='Pose',
            maintainOffset=True,
            name=constraintName)

        constraintName = '_'.join([self.insertUpVTransform.getName(),
                                   'To',
                                   self.insertInputTgt.getName()])

        self.insertUpVInputConstraint = self.insertUpVTransform.constrainTo(
            self.insertInputTgt,
            constraintType='Pose',
            maintainOffset=True,
            name=constraintName)

        # Constrain outputs


        # ===============
        # Add Splice Ops
        # ===============
        # Add Spine Splice Op
        self.twistKLOp = KLOperator('TwistOp', 'TwistSolver', 'Kraken')
        self.addOperator(self.twistKLOp)

        # Add Att Inputs
        self.twistKLOp.setInput('drawDebug', self.drawDebugInputAttr)
        self.twistKLOp.setInput('rigScale', self.rigScaleInputAttr)
        self.twistKLOp.setInput('blendBias', self.blendBiasInputAttr)

        # Add Xfo Inputs
        self.twistKLOp.setInput('origin', self.originTransform)
        self.twistKLOp.setInput('originUpV', self.originUpVTransform)
        self.twistKLOp.setInput('insert', self.insertTransform)
        self.twistKLOp.setInput('insertUpV', self.insertUpVTransform)

        # Add Xfo Outputs
        self.twistKLOp.setOutput('pose', self.twistOutputs)

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

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

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

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

        Profiler.getInstance().pop()
예제 #25
0
    def __init__(self, name='MultiSpring', parent=None):

        Profiler.getInstance().push("Construct Multi Spring Rig Component:" +
                                    name)
        super(MultiSpringComponentRig, self).__init__(name, parent)

        # =========
        # Controls
        # =========
        # Spring Ctrls
        self.mainSpringCtrl = Control('springSettings',
                                      parent=self.ctrlCmpGrp,
                                      shape='pin')

        self.springCtrlSpaces = []
        self.springCtrls = []
        self.setNumControls(1)

        # Add Component Params to FK control
        springSettingsAttrGrp = AttributeGroup("DisplayInfo_SpringSettings",
                                               parent=self.mainSpringCtrl)
        self.springDrawDebugInputAttr = BoolAttribute(
            'drawDebug', value=False, parent=springSettingsAttrGrp)
        self.springtargetOffsetXInputAttr = ScalarAttribute(
            'targetOffset_X',
            value=3.0,
            minValue=0.0,
            maxValue=10.0,
            parent=springSettingsAttrGrp)
        self.springtargetOffsetYInputAttr = ScalarAttribute(
            'targetOffset_Y',
            value=0.0,
            minValue=0.0,
            maxValue=10.0,
            parent=springSettingsAttrGrp)
        self.springtargetOffsetZInputAttr = ScalarAttribute(
            'targetOffset_Z',
            value=0.0,
            minValue=0.0,
            maxValue=10.0,
            parent=springSettingsAttrGrp)
        self.springFrameInputAttr = IntegerAttribute(
            'frame', value=1, parent=springSettingsAttrGrp)
        self.springResetFrameInputAttr = IntegerAttribute(
            'reset_frame', value=1, parent=springSettingsAttrGrp)
        self.springMassInputAttr = ScalarAttribute(
            'mass',
            value=0.5,
            minValue=0.0,
            maxValue=20.0,
            parent=springSettingsAttrGrp)
        self.springSpringStrengthInputAttr = ScalarAttribute(
            'springStrength',
            value=6.0,
            minValue=0.0,
            maxValue=20.0,
            parent=springSettingsAttrGrp)
        self.springDampingInputAttr = ScalarAttribute(
            'damping',
            value=0.125,
            minValue=0.0,
            maxValue=5.0,
            parent=springSettingsAttrGrp)

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

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

        # =====================
        # Create Component I/O
        # =====================

        # Set IO Targets
        self.boneOutputs.setTarget(self.boneOutputsTgt)

        # ==============
        # Constrain I/O
        # ==============
        # Constraint inputs
        self.rootInputConstraint = PoseConstraint('_'.join([
            self.springCtrlSpaces[0].getName(), 'To',
            self.rootInputTgt.getName()
        ]))
        self.rootInputConstraint.setMaintainOffset(True)
        self.rootInputConstraint.addConstrainer(self.rootInputTgt)
        self.springCtrlSpaces[0].addConstraint(self.rootInputConstraint)

        # ===============
        # Add Splice Ops
        # ===============
        # Add Solver Canvas Op
        self.springOp = CanvasOperator('springSolverOp',
                                       'Kraken.Solvers.SpringOffsetSolver')
        self.addOperator(self.springOp)

        # Add Att Inputs
        self.springOp.setInput('drawDebug', self.drawDebugInputAttr)
        self.springOp.setInput('rigScale', self.rigScaleInputAttr)
        self.springOp.setInput('targetOffset_X',
                               self.springtargetOffsetXInputAttr)
        self.springOp.setInput('targetOffset_Y',
                               self.springtargetOffsetYInputAttr)
        self.springOp.setInput('targetOffset_Z',
                               self.springtargetOffsetZInputAttr)
        self.springOp.setInput('frame', self.springFrameInputAttr)
        self.springOp.setInput('reset_frame', self.springResetFrameInputAttr)
        self.springOp.setInput('mass', self.springMassInputAttr)
        self.springOp.setInput('spring_strength',
                               self.springSpringStrengthInputAttr)
        self.springOp.setInput('damping', self.springDampingInputAttr)

        # Add Xfo Inputs
        self.springOp.setInput('inputs', self.springCtrls)

        # Add Xfo Outputs
        self.springOp.setOutput('outputs', self.boneOutputsTgt)

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

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

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

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

        Profiler.getInstance().pop()
예제 #26
0
class StretchyLimbComponentRig(StretchyLimbComponent):
    """StretchyLimb Component"""
    def __init__(self, name='limb', parent=None):

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

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

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

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

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

        self.drawDebugInputAttr.connect(limbDrawDebugInputAttr)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        Profiler.getInstance().pop()

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

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

        Return:
        True if successful.

        """

        super(StretchyLimbComponentRig, self).loadData(data)

        upperXfo = data.get('upperXfo')
        upperLen = data.get('upperLen')
        lowerXfo = data.get('lowerXfo')
        lowerLen = data.get('lowerLen')
        endXfo = data.get('endXfo')
        upVXfo = data.get('upVXfo')

        self.upperFKCtrlSpace.xfo = upperXfo
        self.upperFKCtrl.xfo = upperXfo
        self.upperFKCtrl.scalePoints(Vec3(upperLen, 1.75, 1.75))

        self.limbUpperOutputTgt.xfo = upperXfo
        self.limbLowerOutputTgt.xfo = lowerXfo

        self.lowerFKCtrlSpace.xfo = lowerXfo
        self.lowerFKCtrl.xfo = lowerXfo
        self.lowerFKCtrl.scalePoints(Vec3(lowerLen, 1.5, 1.5))

        self.limbIKCtrlSpace.xfo.tr = endXfo.tr
        self.limbIKCtrl.xfo.tr = endXfo.tr

        if self.getLocation() == "R":
            self.limbIKCtrl.rotatePoints(0, 90, 0)
            self.limbIKCtrl.translatePoints(Vec3(-1.0, 0.0, 0.0))
        else:
            self.limbIKCtrl.rotatePoints(0, -90, 0)
            self.limbIKCtrl.translatePoints(Vec3(1.0, 0.0, 0.0))

        self.limbUpVCtrlSpace.xfo = upVXfo
        self.limbUpVCtrl.xfo = upVXfo

        self.limbBone0LenInputAttr.setMin(0.0)
        self.limbBone0LenInputAttr.setMax(upperLen * 3.0)
        self.limbBone0LenInputAttr.setValue(upperLen)
        self.limbBone1LenInputAttr.setMin(0.0)
        self.limbBone1LenInputAttr.setMax(lowerLen * 3.0)
        self.limbBone1LenInputAttr.setValue(lowerLen)

        self.limbParentInputTgt.xfo = upperXfo

        # Set Attrs
        self.rightSideInputAttr.setValue(self.getLocation() is 'R')

        # Eval Constraints
        self.limbIKCtrlSpaceInputConstraint.evaluate()
        self.limbUpVCtrlSpaceInputConstraint.evaluate()
        self.limbRootInputConstraint.evaluate()

        # Eval Operators
        self.limbIKKLOp.evaluate()
        self.outputsToDeformersKLOp.evaluate()
예제 #27
0
    def __init__(self, name='InsectLeg', parent=None):

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

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

        # Chain Base
        self.chainBase = Locator('ChainBase', parent=self.ctrlCmpGrp)
        self.chainBase.setShapeVisibility(False)

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

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

        if self.getLocation() == 'R':
            self.legIKCtrl.rotatePoints(0, 90, 0)
            self.legIKCtrl.translatePoints(Vec3(-1.0, 0.0, 0.0))
        else:
            self.legIKCtrl.rotatePoints(0, -90, 0)
            self.legIKCtrl.translatePoints(Vec3(1.0, 0.0, 0.0))

        # Add Component Params to IK control
        legSettingsAttrGrp = AttributeGroup("DisplayInfo_LegSettings",
                                            parent=self.legIKCtrl)
        legdrawDebugInputAttr = BoolAttribute('drawDebug',
                                              value=False,
                                              parent=legSettingsAttrGrp)
        legUseInitPoseInputAttr = BoolAttribute('useInitPose',
                                                value=True,
                                                parent=legSettingsAttrGrp)
        self.rootIndexInputAttr = IntegerAttribute('rootIndex',
                                                   value=0,
                                                   parent=legSettingsAttrGrp)
        legFkikInputAttr = ScalarAttribute('fkik',
                                           value=1.0,
                                           minValue=0.0,
                                           maxValue=1.0,
                                           parent=legSettingsAttrGrp)

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

        # UpV
        self.legUpVCtrlSpace = CtrlSpace('UpV', parent=self.ctrlCmpGrp)
        self.legUpVCtrl = Control('UpV',
                                  parent=self.legUpVCtrlSpace,
                                  shape="triangle")
        self.legUpVCtrl.alignOnZAxis()
        self.legUpVCtrl.rotatePoints(0, 90, 0)

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

        # =====================
        # Create Component I/O
        # =====================

        # Set IO Targets
        self.boneOutputs.setTarget(self.boneOutputsTgt)

        # ==============
        # Constrain I/O
        # ==============
        # Constraint inputs
        legRootInputConstraint = PoseConstraint('_'.join([
            self.fkCtrlSpaces[0].getName(), 'To',
            self.rootInputTgt.getName()
        ]))
        legRootInputConstraint.setMaintainOffset(True)
        legRootInputConstraint.addConstrainer(self.rootInputTgt)
        self.fkCtrlSpaces[0].addConstraint(legRootInputConstraint)

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

        # ===============
        # Add Canvas Ops
        # ===============
        # Add Canvas Op
        self.nBoneSolverKLOp = KLOperator('leg', 'NBoneIKSolver', 'Kraken')
        self.addOperator(self.nBoneSolverKLOp)

        # # Add Att Inputs
        self.nBoneSolverKLOp.setInput('drawDebug', self.drawDebugInputAttr)
        self.nBoneSolverKLOp.setInput('rigScale', self.rigScaleInputAttr)
        self.nBoneSolverKLOp.setInput('useInitPose', legUseInitPoseInputAttr)
        self.nBoneSolverKLOp.setInput('ikblend', legFkikInputAttr)
        self.nBoneSolverKLOp.setInput('rootIndex', self.rootIndexInputAttr)
        self.nBoneSolverKLOp.setInput('tipBoneLen', self.tipBoneLenInputAttr)

        # Add Xfo Inputs
        self.nBoneSolverKLOp.setInput('chainBase', self.chainBase)
        self.nBoneSolverKLOp.setInput('ikgoal', self.legIKCtrl)
        self.nBoneSolverKLOp.setInput('upVector', self.legUpVCtrl)

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

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

        self.nBoneSolverKLOp.setOutput('legEnd', self.legEndPosOutputTgt)

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

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

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

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

        Profiler.getInstance().pop()
예제 #28
0
class LegComponentRig(LegComponent):
    """Leg Component"""

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

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


        # =========
        # Controls
        # =========
        # Femur
        self.femurFKCtrlSpace = CtrlSpace('femurFK', parent=self.ctrlCmpGrp)
        self.femurFKCtrl = Control('femurFK', parent=self.femurFKCtrlSpace, shape="cube")
        self.femurFKCtrl.alignOnXAxis()
        self.femurFKCtrl.lockTranslation(True, True, True)
        self.femurFKCtrl.lockScale(True, True, True)

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

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

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

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

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

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

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


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

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

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

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

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

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

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

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

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

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


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

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

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

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

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


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

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

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

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

        Profiler.getInstance().pop()

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

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

        Return:
        True if successful.

        """

        super(LegComponentRig, self).loadData( data )

        createIKHandle = data.get('createIKHandle')
        femurXfo = data.get('femurXfo')
        kneeXfo = data.get('kneeXfo')
        handleXfo = data.get('handleXfo')
        upVXfo = data.get('upVXfo')
        femurLen = data.get('femurLen')
        shinLen = data.get('shinLen')

        self.femurFKCtrlSpace.xfo = femurXfo
        self.femurFKCtrl.xfo = femurXfo
        self.femurFKCtrl.scalePoints(Vec3(femurLen, 1.75, 1.75))

        self.femurOutputTgt.xfo = femurXfo
        self.shinOutputTgt.xfo = kneeXfo

        self.shinFKCtrlSpace.xfo = kneeXfo
        self.shinFKCtrl.xfo = kneeXfo
        self.shinFKCtrl.scalePoints(Vec3(shinLen, 1.5, 1.5))

        self.legEndFKOutputTgt.xfo.tr = handleXfo.tr
        self.legEndFKOutputTgt.xfo.ori = kneeXfo.ori

        self.ikHandleOutputTgt.xfo = handleXfo

        self.ikRootPosition.xfo = femurXfo

        self.legIKCtrlSpace.xfo = handleXfo
        self.legIKCtrl.xfo = handleXfo

        if self.getLocation() == 'R':
            self.legIKCtrl.rotatePoints(0, 90, 0)
            self.legIKCtrl.translatePoints(Vec3(-1.0, 0.0, 0.0))
        else:
            self.legIKCtrl.rotatePoints(0, -90, 0)
            self.legIKCtrl.translatePoints(Vec3(1.0, 0.0, 0.0))

        self.legUpVCtrlSpace.xfo.tr = upVXfo.tr
        self.legUpVCtrl.xfo.tr = upVXfo.tr

        self.legRightSideInputAttr.setValue(self.getLocation() is 'R')
        self.legBone0LenInputAttr.setMin(0.0)
        self.legBone0LenInputAttr.setMax(femurLen * 3.0)
        self.legBone0LenInputAttr.setValue(femurLen)
        self.legBone1LenInputAttr.setMin(0.0)
        self.legBone1LenInputAttr.setMax(shinLen * 3.0)
        self.legBone1LenInputAttr.setValue(shinLen)

        self.legPelvisInputTgt.xfo = femurXfo
        self.legIKTargetInputTgt.xfo = handleXfo

        # TODO: We need the Rig class to be modified to handle the ability to
        # query if the ports are connected during loadData. Currently just a
        # place holder until that happens.

        # If IK Target input is not connected, switch to legIKCtrl
        # ikTargetInput = self.getInputByName('ikTarget')
        # if not ikTargetInput.isConnected():
            # self.legIKKLOp.setInput('ikHandle', self.legIKCtrl)

        # Eval Input Constraints
        self.ikRootPosInputConstraint.evaluate()
        self.legIKCtrlSpaceInputConstraint.evaluate()
        self.legUpVCtrlSpaceInputConstraint.evaluate()
        self.legRootInputConstraint.evaluate()

        # Eval Operators
        self.legIKKLOp.evaluate()
        self.outputsToDeformersKLOp.evaluate()

        # Eval Output Constraints
        self.legEndFKOutputConstraint.evaluate()
        self.ikHandleOutputConstraint.evaluate()
예제 #29
0
    def __init__(self, name='SimpleControl', parent=None):

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

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

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

        self.rigScaleOutputAttr.connect(self.rigScaleAttr)

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

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

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

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

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

        Profiler.getInstance().pop()
예제 #30
0
class LegComponentRig(LegComponent):
    """Leg Component"""

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

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


        # =========
        # Controls
        # =========
        # Femur
        self.femurFKCtrlSpace = CtrlSpace('femurFK', parent=self.ctrlCmpGrp)
        self.femurFKCtrl = Control('femurFK', parent=self.femurFKCtrlSpace, shape="cube")
        self.femurFKCtrl.alignOnXAxis()

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

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

        # FK Foot
        self.footCtrlSpace = CtrlSpace('foot', parent=self.ctrlCmpGrp)
        self.footCtrl = Control('foot', parent=self.footCtrlSpace, shape="cube")
        self.footCtrl.alignOnXAxis()

        # FK Toe
        self.toeCtrlSpace = CtrlSpace('toe', parent=self.footCtrl)
        self.toeCtrl = Control('toe', parent=self.toeCtrlSpace, shape="cube")
        self.toeCtrl.alignOnXAxis()

        # Rig Ref objects
        self.footRefSrt = Locator('footRef', parent=self.ctrlCmpGrp)

        # Add Component Params to IK control
        footSettingsAttrGrp = AttributeGroup("DisplayInfo_FootSettings", parent=self.footCtrl)
        footLinkToWorldInputAttr = ScalarAttribute('linkToWorld', 1.0, maxValue=1.0, parent=footSettingsAttrGrp)

        # Add Component Params to IK control
        legSettingsAttrGrp = AttributeGroup("DisplayInfo_LegSettings", parent=self.legIKCtrl)
        legDrawDebugInputAttr = BoolAttribute('drawDebug', value=False, parent=legSettingsAttrGrp)
        self.legBone0LenInputAttr = ScalarAttribute('bone0Len', value=1.0, parent=legSettingsAttrGrp)
        self.legBone1LenInputAttr = ScalarAttribute('bone1Len', value=1.0, parent=legSettingsAttrGrp)
        legIKBlendInputAttr = ScalarAttribute('ikblend', value=1.0, minValue=0.0, maxValue=1.0, parent=legSettingsAttrGrp)
        legSoftIKInputAttr = BoolAttribute('softIK', value=True, parent=legSettingsAttrGrp)
        legSoftDistInputAttr = ScalarAttribute('softDist', value=0.0, minValue=0.0, parent=legSettingsAttrGrp)
        legStretchInputAttr = BoolAttribute('stretch', value=True, parent=legSettingsAttrGrp)
        legStretchBlendInputAttr = ScalarAttribute('stretchBlend', value=0.0, minValue=0.0, maxValue=1.0, parent=legSettingsAttrGrp)

        self.drawDebugInputAttr.connect(legDrawDebugInputAttr)

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


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

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

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

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

        self.footDef = Joint('foot', parent=self.defCmpGrp)
        self.footDef.setComponent(self)

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


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

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

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

        # Constraint outputs
        self.footOutputConstraint = PoseConstraint('_'.join([self.footOutputTgt.getName(), 'To', self.footCtrl.getName()]))
        self.footOutputConstraint.addConstrainer(self.footCtrl)
        self.footOutputTgt.addConstraint(self.footOutputConstraint)

        self.toeOutputConstraint = PoseConstraint('_'.join([self.toeOutputTgt.getName(), 'To', self.toeCtrl.getName()]))
        self.toeOutputConstraint.addConstrainer(self.toeCtrl)
        self.toeOutputTgt.addConstraint(self.toeOutputConstraint)


        # ===============
        # Add Splice Ops
        # ===============
        # Add Leg Splice Op
        self.legIKSpliceOp = SpliceOperator('legSpliceOp', 'TwoBoneIKSolver', 'Kraken')
        self.addOperator(self.legIKSpliceOp)

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

        self.legIKSpliceOp.setInput('bone0Len', self.legBone0LenInputAttr)
        self.legIKSpliceOp.setInput('bone1Len', self.legBone1LenInputAttr)
        self.legIKSpliceOp.setInput('ikblend', legIKBlendInputAttr)
        self.legIKSpliceOp.setInput('softIK', legSoftIKInputAttr)
        self.legIKSpliceOp.setInput('softDist', legSoftDistInputAttr)
        self.legIKSpliceOp.setInput('stretch', legStretchInputAttr)
        self.legIKSpliceOp.setInput('stretchBlend', legStretchBlendInputAttr)
        self.legIKSpliceOp.setInput('rightSide', self.rightSideInputAttr)

        # Add Xfo Inputs
        self.legIKSpliceOp.setInput('root', self.legPelvisInputTgt)
        self.legIKSpliceOp.setInput('bone0FK', self.femurFKCtrl)
        self.legIKSpliceOp.setInput('bone1FK', self.shinFKCtrl)
        self.legIKSpliceOp.setInput('ikHandle', self.legIKCtrl)
        self.legIKSpliceOp.setInput('upV', self.legUpVCtrl)

        # Add Xfo Outputs
        self.legIKSpliceOp.setOutput('bone0Out', self.femurOutputTgt)
        self.legIKSpliceOp.setOutput('bone1Out', self.shinOutputTgt)
        self.legIKSpliceOp.setOutput('bone2Out', self.legEndXfoOutputTgt)


        # Add Leg Deformer Splice Op
        self.outputsToDeformersSpliceOp = SpliceOperator('legDeformerSpliceOp', 'MultiPoseConstraintSolver', 'Kraken')
        self.addOperator(self.outputsToDeformersSpliceOp)

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

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

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

        # Add Foot Deformer Splice Op
        self.footDefSpliceOp = SpliceOperator('footDeformerSpliceOp', 'PoseConstraintSolver', 'Kraken')
        self.addOperator(self.footDefSpliceOp)

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

        # Add Xfo Inputs)
        self.footDefSpliceOp.setInput('constrainer', self.footOutputTgt)

        # Add Xfo Outputs
        self.footDefSpliceOp.setOutput('constrainee', self.footDef)

        # Add Toe Deformer Splice Op
        self.toeDefSpliceOp = SpliceOperator('toeDeformerSpliceOp', 'PoseConstraintSolver', 'Kraken')
        self.addOperator(self.toeDefSpliceOp)

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

        # Add Xfo Inputs
        self.toeDefSpliceOp.setInput('constrainer', self.toeOutputTgt)

        # Add Xfo Outputs
        self.toeDefSpliceOp.setOutput('constrainee', self.toeDef)

        Profiler.getInstance().pop()

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

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

        Return:
        True if successful.

        """

        super(LegComponentRig, self).loadData( data )

        self.femurFKCtrlSpace.xfo = data['femurXfo']
        self.femurFKCtrl.xfo = data['femurXfo']
        self.femurFKCtrl.scalePoints(Vec3(data['femurLen'], 1.75, 1.75))

        self.femurOutputTgt.xfo = data['femurXfo']
        self.shinOutputTgt.xfo = data['kneeXfo']

        self.shinFKCtrlSpace.xfo = data['kneeXfo']
        self.shinFKCtrl.xfo = data['kneeXfo']
        self.shinFKCtrl.scalePoints(Vec3(data['shinLen'], 1.5, 1.5))

        self.footCtrlSpace.xfo.tr = data['ankleXfo'].tr
        self.footCtrl.xfo.tr = data['ankleXfo'].tr

        self.toeCtrlSpace.xfo = data['toeXfo']
        self.toeCtrl.xfo = data['toeXfo']

        self.legIKCtrlSpace.xfo.tr = data['ankleXfo'].tr
        self.legIKCtrl.xfo.tr = data['ankleXfo'].tr

        if self.getLocation() == "R":
            self.legIKCtrl.rotatePoints(0, 90, 0)
            self.legIKCtrl.translatePoints(Vec3(-1.0, 0.0, 0.0))
        else:
            self.legIKCtrl.rotatePoints(0, -90, 0)
            self.legIKCtrl.translatePoints(Vec3(1.0, 0.0, 0.0))

        self.legUpVCtrlSpace.xfo = data['upVXfo']
        self.legUpVCtrl.xfo = data['upVXfo']

        self.rightSideInputAttr.setValue(self.getLocation() is 'R')
        self.legBone0LenInputAttr.setMin(0.0)
        self.legBone0LenInputAttr.setMax(data['femurLen'] * 3.0)
        self.legBone0LenInputAttr.setValue(data['femurLen'])
        self.legBone1LenInputAttr.setMin(0.0)
        self.legBone1LenInputAttr.setMax(data['shinLen'] * 3.0)
        self.legBone1LenInputAttr.setValue(data['shinLen'])

        self.legPelvisInputTgt.xfo = data['femurXfo']

        # Eval Constraints
        self.legIKCtrlSpaceInputConstraint.evaluate()
        self.legUpVCtrlSpaceInputConstraint.evaluate()
        self.legRootInputConstraint.evaluate()
        self.footOutputConstraint.evaluate()
        self.toeOutputConstraint.evaluate()

        # Eval Operators
        self.legIKSpliceOp.evaluate()
        self.outputsToDeformersSpliceOp.evaluate()
        self.footDefSpliceOp.evaluate()
예제 #31
0
class ArmComponentRig(ArmComponent):
    """Arm Component Rig"""

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

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

        # =========
        # Controls
        # =========
        # Bicep
        self.bicepFKCtrlSpace = CtrlSpace("bicepFK", parent=self.ctrlCmpGrp)

        self.bicepFKCtrl = Control("bicepFK", parent=self.bicepFKCtrlSpace, shape="cube")
        self.bicepFKCtrl.alignOnXAxis()

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

        self.forearmFKCtrl = Control("forearmFK", parent=self.forearmFKCtrlSpace, shape="cube")
        self.forearmFKCtrl.alignOnXAxis()

        self.handCtrlSpace = CtrlSpace("hand", parent=self.ctrlCmpGrp)
        self.handCtrl = Control("hand", parent=self.handCtrlSpace, shape="circle")
        self.handCtrl.rotatePoints(0, 0, 90)
        self.handCtrl.scalePoints(Vec3(1.0, 0.75, 0.75))

        # Arm IK
        self.armIKCtrlSpace = CtrlSpace("IK", parent=self.ctrlCmpGrp)
        self.armIKCtrl = Control("IK", parent=self.armIKCtrlSpace, shape="pin")

        # Add Params to IK control
        armSettingsAttrGrp = AttributeGroup("DisplayInfo_ArmSettings", parent=self.armIKCtrl)
        armDebugInputAttr = BoolAttribute("drawDebug", value=False, parent=armSettingsAttrGrp)
        self.armBone0LenInputAttr = ScalarAttribute("bone1Len", value=0.0, parent=armSettingsAttrGrp)
        self.armBone1LenInputAttr = ScalarAttribute("bone2Len", value=0.0, parent=armSettingsAttrGrp)
        armIKBlendInputAttr = ScalarAttribute("fkik", value=0.0, minValue=0.0, maxValue=1.0, parent=armSettingsAttrGrp)
        armSoftIKInputAttr = BoolAttribute("softIK", value=True, parent=armSettingsAttrGrp)
        armSoftDistInputAttr = ScalarAttribute("softDist", value=0.0, minValue=0.0, parent=armSettingsAttrGrp)
        armStretchInputAttr = BoolAttribute("stretch", value=True, parent=armSettingsAttrGrp)
        armStretchBlendInputAttr = ScalarAttribute(
            "stretchBlend", value=0.0, minValue=0.0, maxValue=1.0, parent=armSettingsAttrGrp
        )

        # Hand Params
        handSettingsAttrGrp = AttributeGroup("DisplayInfo_HandSettings", parent=self.handCtrl)
        handLinkToWorldInputAttr = ScalarAttribute("linkToWorld", 0.0, maxValue=1.0, parent=handSettingsAttrGrp)

        self.drawDebugInputAttr.connect(armDebugInputAttr)

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

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

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

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

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

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

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

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

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

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

        self.handCtrlSpaceConstraint = PoseConstraint(
            "_".join([self.handCtrlSpace.getName(), "To", self.armEndXfoOutputTgt.getName()])
        )
        self.handCtrlSpaceConstraint.setMaintainOffset(True)
        self.handCtrlSpaceConstraint.addConstrainer(self.armEndXfoOutputTgt)
        self.handCtrlSpace.addConstraint(self.handCtrlSpaceConstraint)

        # ===============
        # Add Splice Ops
        # ===============
        # Add Splice Op
        self.spliceOp = SpliceOperator("armSpliceOp", "TwoBoneIKSolver", "Kraken")
        self.addOperator(self.spliceOp)

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

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

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

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

        # Add Deformer Splice Op
        self.outputsToDeformersSpliceOp = SpliceOperator("armDeformerSpliceOp", "MultiPoseConstraintSolver", "Kraken")
        self.addOperator(self.outputsToDeformersSpliceOp)

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

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

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

        Profiler.getInstance().pop()

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

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

        Return:
        True if successful.

        """

        super(ArmComponentRig, self).loadData(data)

        self.clavicleEndInputTgt.xfo.tr = data["bicepXfo"].tr

        self.bicepFKCtrlSpace.xfo = data["bicepXfo"]
        self.bicepFKCtrl.xfo = data["bicepXfo"]
        self.bicepFKCtrl.scalePoints(Vec3(data["bicepLen"], data["bicepFKCtrlSize"], data["bicepFKCtrlSize"]))

        self.bicepOutputTgt.xfo = data["bicepXfo"]
        self.forearmOutputTgt.xfo = data["forearmXfo"]

        self.forearmFKCtrlSpace.xfo = data["forearmXfo"]
        self.forearmFKCtrl.xfo = data["forearmXfo"]
        self.forearmFKCtrl.scalePoints(Vec3(data["forearmLen"], data["forearmFKCtrlSize"], data["forearmFKCtrlSize"]))

        self.handCtrlSpace.xfo = data["handXfo"]
        self.handCtrl.xfo = data["handXfo"]

        self.armIKCtrlSpace.xfo.tr = data["armEndXfo"].tr
        self.armIKCtrl.xfo.tr = data["armEndXfo"].tr

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

        self.armUpVCtrlSpace.xfo = data["upVXfo"]
        self.armUpVCtrl.xfo = data["upVXfo"]

        self.rightSideInputAttr.setValue(self.getLocation() is "R")
        self.armBone0LenInputAttr.setMin(0.0)
        self.armBone0LenInputAttr.setMax(data["bicepLen"] * 3.0)
        self.armBone0LenInputAttr.setValue(data["bicepLen"])
        self.armBone1LenInputAttr.setMin(0.0)
        self.armBone1LenInputAttr.setMax(data["forearmLen"] * 3.0)
        self.armBone1LenInputAttr.setValue(data["forearmLen"])

        # Outputs
        self.handOutputTgt.xfo = data["handXfo"]

        # Eval Constraints
        self.armIKCtrlSpaceInputConstraint.evaluate()
        self.armUpVCtrlSpaceInputConstraint.evaluate()
        self.armRootInputConstraint.evaluate()
        self.armRootInputConstraint.evaluate()
        self.handConstraint.evaluate()
        self.handCtrlSpaceConstraint.evaluate()

        # Eval Operators
        self.spliceOp.evaluate()
        self.outputsToDeformersSpliceOp.evaluate()
예제 #32
0
class MainSrtComponentGuide(MainSrtComponent):
    """MainSrt Component Guide"""

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

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

        # =========
        # Attributes
        # =========
        # Add Component Params to IK control
        guideSettingsAttrGrp = AttributeGroup("GuideSettings", parent=self)

        self.mainSrtSizeInputAttr = ScalarAttribute(
            "mainSrtSize", value=5.0, minValue=1.0, maxValue=50.0, parent=guideSettingsAttrGrp
        )

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

        # Guide Controls
        self.mainSrtCtrl = Control("mainSrt", parent=self.ctrlCmpGrp, shape="circle")

        if data is None:
            data = {
                "location": "M",
                "mainSrtSize": self.mainSrtSizeInputAttr.getValue(),
                "mainSrtXfo": Xfo(tr=Vec3(0.0, 0.0, 0.0)),
            }

        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(MainSrtComponentGuide, self).saveData()

        data["mainSrtSize"] = self.mainSrtSizeInputAttr.getValue()
        data["mainSrtXfo"] = self.mainSrtCtrl.xfo

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

        self.mainSrtSizeInputAttr.setValue(data["mainSrtSize"])
        self.mainSrtCtrl.xfo = data["mainSrtXfo"]

        self.mainSrtCtrl.scalePoints(Vec3(data["mainSrtSize"], 1.0, data["mainSrtSize"]))

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

        data["mainSrtSize"] = self.mainSrtSizeInputAttr.getValue()
        data["mainSrtXfo"] = self.mainSrtCtrl.xfo

        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 MainSrtComponentRig
예제 #33
0
    def __init__(self, name='limb', parent=None):

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

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

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

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

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

        self.drawDebugInputAttr.connect(limbDrawDebugInputAttr)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        Profiler.getInstance().pop()
예제 #34
0
    def __init__(self, name="arm", parent=None):

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

        # =========
        # Controls
        # =========
        # Bicep
        self.bicepFKCtrlSpace = CtrlSpace("bicepFK", parent=self.ctrlCmpGrp)

        self.bicepFKCtrl = Control("bicepFK", parent=self.bicepFKCtrlSpace, shape="cube")
        self.bicepFKCtrl.alignOnXAxis()

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

        self.forearmFKCtrl = Control("forearmFK", parent=self.forearmFKCtrlSpace, shape="cube")
        self.forearmFKCtrl.alignOnXAxis()

        self.handCtrlSpace = CtrlSpace("hand", parent=self.ctrlCmpGrp)
        self.handCtrl = Control("hand", parent=self.handCtrlSpace, shape="circle")
        self.handCtrl.rotatePoints(0, 0, 90)
        self.handCtrl.scalePoints(Vec3(1.0, 0.75, 0.75))

        # Arm IK
        self.armIKCtrlSpace = CtrlSpace("IK", parent=self.ctrlCmpGrp)
        self.armIKCtrl = Control("IK", parent=self.armIKCtrlSpace, shape="pin")

        # Add Params to IK control
        armSettingsAttrGrp = AttributeGroup("DisplayInfo_ArmSettings", parent=self.armIKCtrl)
        armDebugInputAttr = BoolAttribute("drawDebug", value=False, parent=armSettingsAttrGrp)
        self.armBone0LenInputAttr = ScalarAttribute("bone1Len", value=0.0, parent=armSettingsAttrGrp)
        self.armBone1LenInputAttr = ScalarAttribute("bone2Len", value=0.0, parent=armSettingsAttrGrp)
        armIKBlendInputAttr = ScalarAttribute("fkik", value=0.0, minValue=0.0, maxValue=1.0, parent=armSettingsAttrGrp)
        armSoftIKInputAttr = BoolAttribute("softIK", value=True, parent=armSettingsAttrGrp)
        armSoftDistInputAttr = ScalarAttribute("softDist", value=0.0, minValue=0.0, parent=armSettingsAttrGrp)
        armStretchInputAttr = BoolAttribute("stretch", value=True, parent=armSettingsAttrGrp)
        armStretchBlendInputAttr = ScalarAttribute(
            "stretchBlend", value=0.0, minValue=0.0, maxValue=1.0, parent=armSettingsAttrGrp
        )

        # Hand Params
        handSettingsAttrGrp = AttributeGroup("DisplayInfo_HandSettings", parent=self.handCtrl)
        handLinkToWorldInputAttr = ScalarAttribute("linkToWorld", 0.0, maxValue=1.0, parent=handSettingsAttrGrp)

        self.drawDebugInputAttr.connect(armDebugInputAttr)

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

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

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

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

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

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

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

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

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

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

        self.handCtrlSpaceConstraint = PoseConstraint(
            "_".join([self.handCtrlSpace.getName(), "To", self.armEndXfoOutputTgt.getName()])
        )
        self.handCtrlSpaceConstraint.setMaintainOffset(True)
        self.handCtrlSpaceConstraint.addConstrainer(self.armEndXfoOutputTgt)
        self.handCtrlSpace.addConstraint(self.handCtrlSpaceConstraint)

        # ===============
        # Add Splice Ops
        # ===============
        # Add Splice Op
        self.spliceOp = SpliceOperator("armSpliceOp", "TwoBoneIKSolver", "Kraken")
        self.addOperator(self.spliceOp)

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

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

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

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

        # Add Deformer Splice Op
        self.outputsToDeformersSpliceOp = SpliceOperator("armDeformerSpliceOp", "MultiPoseConstraintSolver", "Kraken")
        self.addOperator(self.outputsToDeformersSpliceOp)

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

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

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

        Profiler.getInstance().pop()
예제 #35
0
    def __init__(self, name='leg', parent=None):

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


        # =========
        # Controls
        # =========
        # Femur
        self.femurFKCtrlSpace = CtrlSpace('femurFK', parent=self.ctrlCmpGrp)
        self.femurFKCtrl = Control('femurFK', parent=self.femurFKCtrlSpace, shape="cube")
        self.femurFKCtrl.alignOnXAxis()
        self.femurFKCtrl.lockTranslation(True, True, True)
        self.femurFKCtrl.lockScale(True, True, True)

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

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

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

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

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

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

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


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

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

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

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

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

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

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

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

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

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


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

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

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

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

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


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

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

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

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

        Profiler.getInstance().pop()
예제 #36
0
class mjEyelidComponentGuide(mjEyelidComponent):
    """Eyelid Component Guide"""
    def __init__(self, name='mjEyelid', parent=None):

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

        # =========
        # Attributes // Create Attributes Controls.
        # =========
        guideUpSettingsAttrGrp = AttributeGroup("Eyelid Up", parent=self)
        guideLowSettingsAttrGrp = AttributeGroup("Eyelid Low", parent=self)

        self.numUpDeformersAttr = IntegerAttribute(
            'Num Deformers',
            value=10,
            minValue=1,
            maxValue=50,
            parent=guideUpSettingsAttrGrp)
        self.upMedialFactorAttr = ScalarAttribute(
            'Medial Blink Factor',
            value=0.25,
            minValue=0,
            maxValue=1,
            parent=guideUpSettingsAttrGrp)
        self.upLateralFactorAttr = ScalarAttribute(
            'Lateral Blink Factor',
            value=0.65,
            minValue=0,
            maxValue=1,
            parent=guideUpSettingsAttrGrp)

        self.numLowDeformersAttr = IntegerAttribute(
            'Num Deformers',
            value=10,
            minValue=1,
            maxValue=50,
            parent=guideLowSettingsAttrGrp)
        self.lowMedialFactorAttr = ScalarAttribute(
            'Medial Blink Factor',
            value=0.25,
            minValue=0,
            maxValue=1,
            parent=guideLowSettingsAttrGrp)
        self.lowLateralFactorAttr = ScalarAttribute(
            'Lateral Blink Factor',
            value=0.65,
            minValue=0,
            maxValue=1,
            parent=guideLowSettingsAttrGrp)

        self.numUpDeformersAttr.setValueChangeCallback(
            self.updateNumUpDeformers)
        self.numLowDeformersAttr.setValueChangeCallback(
            self.updateNumLowDeformers)

        # =========
        # Controls // Create the Guide Controls, Name them, give them a shape, a color and scale it.
        # =========
        self.eyeballCtrl = Control('eyeball',
                                   parent=self.ctrlCmpGrp,
                                   shape="sphere")
        self.eyeballCtrl.scalePoints(Vec3(0.35, 0.35, 0.35))
        self.eyeballCtrl.setColor("red")

        self.lidMedialCtrl = Control('lidMedial',
                                     parent=self.eyeballCtrl,
                                     shape="sphere")
        self.lidMedialCtrl.scalePoints(Vec3(0.025, 0.025, 0.025))
        self.lidMedialCtrl.setColor("peach")

        self.lidLateralCtrl = Control('lidLateral',
                                      parent=self.eyeballCtrl,
                                      shape="sphere")
        self.lidLateralCtrl.scalePoints(Vec3(0.025, 0.025, 0.025))
        self.lidLateralCtrl.setColor("peach")

        self.lidUpCtrl = Control('lidUp',
                                 parent=self.eyeballCtrl,
                                 shape="sphere")
        self.lidUpCtrl.scalePoints(Vec3(0.025, 0.025, 0.025))
        self.lidUpCtrl.setColor("peach")

        self.lidUpMedialCtrl = Control('lidUpMedial',
                                       parent=self.eyeballCtrl,
                                       shape="sphere")
        self.lidUpMedialCtrl.scalePoints(Vec3(0.025, 0.025, 0.025))
        self.lidUpMedialCtrl.setColor("peach")

        self.lidUpLateralCtrl = Control('lidUpLateral',
                                        parent=self.eyeballCtrl,
                                        shape="sphere")
        self.lidUpLateralCtrl.scalePoints(Vec3(0.025, 0.025, 0.025))
        self.lidUpLateralCtrl.setColor("peach")

        self.lidLowCtrl = Control('lidLow',
                                  parent=self.eyeballCtrl,
                                  shape="sphere")
        self.lidLowCtrl.scalePoints(Vec3(0.025, 0.025, 0.025))
        self.lidLowCtrl.setColor("peach")

        self.lidLowMedialCtrl = Control('lidLowMedial',
                                        parent=self.eyeballCtrl,
                                        shape="sphere")
        self.lidLowMedialCtrl.scalePoints(Vec3(0.025, 0.025, 0.025))
        self.lidLowMedialCtrl.setColor("peach")

        self.lidLowLateralCtrl = Control('lidLowLateral',
                                         parent=self.eyeballCtrl,
                                         shape="sphere")
        self.lidLowLateralCtrl.scalePoints(Vec3(0.025, 0.025, 0.025))
        self.lidLowLateralCtrl.setColor("peach")

        # ===============
        # Add Debug Splice Ops
        # ===============
        # Add Lid Up Canvas Op
        self.debugLidUpCanvasOp = CanvasOperator(
            'Debug_Canvas_Eyelid_Up_Op', 'MJCG.Solvers.mjEyelidDebugSolver')
        self.addOperator(self.debugLidUpCanvasOp)

        # Add Attributes Inputs
        self.debugLidUpCanvasOp.setInput('drawDebug', self.drawDebugInputAttr)
        self.debugLidUpCanvasOp.setInput('rigScale', self.rigScaleInputAttr)
        self.debugLidUpCanvasOp.setInput('Deformer_Count',
                                         self.numUpDeformersInputAttr)

        # Add Xfo Inputs
        self.debugLidUpCanvasOp.setInput('Eye_Center', self.eyeballCtrl)
        self.debugLidUpCanvasOp.setInput('Lid_Medial', self.lidMedialCtrl)
        self.debugLidUpCanvasOp.setInput('Lid_MedialCen', self.lidUpMedialCtrl)
        self.debugLidUpCanvasOp.setInput('Lid_Center_Ref', self.lidUpCtrl)
        self.debugLidUpCanvasOp.setInput('Lid_Center_Ctrl', self.lidUpCtrl)
        self.debugLidUpCanvasOp.setInput('Lid_LateralCen',
                                         self.lidUpLateralCtrl)
        self.debugLidUpCanvasOp.setInput('Lid_Lateral', self.lidLateralCtrl)

        # Add Xfo Outputs
        self.debugLidUpCanvasOp.setOutput('result',
                                          self.eyelidUpOutput.getTarget())

        # Add Lid Low Canvas Op
        self.debugLidLowCanvasOp = CanvasOperator(
            'Debug_Canvas_Eyelid_Low_Op', 'MJCG.Solvers.mjEyelidDebugSolver')
        self.addOperator(self.debugLidLowCanvasOp)

        # Add Attributes Inputs
        self.debugLidLowCanvasOp.setInput('drawDebug', self.drawDebugInputAttr)
        self.debugLidLowCanvasOp.setInput('rigScale', self.rigScaleInputAttr)
        self.debugLidLowCanvasOp.setInput('Deformer_Count',
                                          self.numLowDeformersInputAttr)

        # Add Xfo Inputs
        self.debugLidLowCanvasOp.setInput('Eye_Center', self.eyeballCtrl)
        self.debugLidLowCanvasOp.setInput('Lid_Medial', self.lidMedialCtrl)
        self.debugLidLowCanvasOp.setInput('Lid_MedialCen',
                                          self.lidLowMedialCtrl)
        self.debugLidLowCanvasOp.setInput('Lid_Center_Ref', self.lidLowCtrl)
        self.debugLidLowCanvasOp.setInput('Lid_Center_Ctrl', self.lidLowCtrl)
        self.debugLidLowCanvasOp.setInput('Lid_LateralCen',
                                          self.lidLowLateralCtrl)
        self.debugLidLowCanvasOp.setInput('Lid_Lateral', self.lidLateralCtrl)

        # Add Xfo Outputs
        self.debugLidLowCanvasOp.setOutput('result',
                                           self.eyelidLowOutput.getTarget())

        # =========
        # Position Data // Get the Guide Controls Position data, else set them at their initial position.
        # =========
        self.default_data = {
            "name": name,
            "location": "L",
            "eyeballXfo": Xfo(Vec3(0.322, 15.500, 0.390)),
            "lidMedialXfo": Xfo(Vec3(0.168, 15.445, 0.520)),
            "lidLateralXfo": Xfo(Vec3(0.465, 15.47, 0.465)),
            "lidUpXfo": Xfo(Vec3(0.322, 15.585, 0.605)),
            "lidUpMedialXfo": Xfo(Vec3(0.203, 15.515, 0.525)),
            "lidUpLateralXfo": Xfo(Vec3(0.432, 15.55, 0.538)),
            "lidLowXfo": Xfo(Vec3(0.322, 15.434, 0.6)),
            "lidLowMedialXfo": Xfo(Vec3(0.24, 15.45, 0.513)),
            "lidLowLateralXfo": Xfo(Vec3(0.413, 15.44, 0.525)),
            "lidUpMedialBlink": self.upMedialFactorAttr.getValue(),
            "lidUpLateralBlink": self.upLateralFactorAttr.getValue(),
            "lidLowMedialBlink": self.lowMedialFactorAttr.getValue(),
            "lidLowLateralBlink": self.lowLateralFactorAttr.getValue(),
            "numUpDeformers": self.numUpDeformersAttr.getValue(),
            "numLowDeformers": self.numLowDeformersAttr.getValue(),
        }

        self.loadData(self.default_data)

        Profiler.getInstance().pop()

# ==========
# Callbacks
# ==========

    def updateNumUpDeformers(self, countUp):

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

        #Lip Up
        lidUpOutputs = self.eyelidUpOutput.getTarget()
        if countUp > len(lidUpOutputs):
            for i in xrange(len(lidUpOutputs), countUp):
                debugUpCtrl = Control('Lid_Up_' + str(i + 1).zfill(2),
                                      parent=self.outputHrcGrp,
                                      shape="sphere")
                debugUpCtrl.rotatePoints(90, -90, 180)
                debugUpCtrl.scalePoints(Vec3(0.01, 0.01, 0.01))
                debugUpCtrl.setColor("yellowLight")
                lidUpOutputs.append(debugUpCtrl)

        elif countUp < len(lidUpOutputs):
            numExtraUpCtrls = len(lidUpOutputs) - countUp
            for i in xrange(numExtraUpCtrls):
                extraUpCtrl = lidUpOutputs.pop()
                self.outputHrcGrp.removeChild(extraUpCtrl)

        return True

    def updateNumLowDeformers(self, countLow):

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

        #Lip Low
        lidLowOutputs = self.eyelidLowOutput.getTarget()
        if countLow > len(lidLowOutputs):
            for i in xrange(len(lidLowOutputs), countLow):
                debugLowCtrl = Control('Lid_Low_' + str(i + 1).zfill(2),
                                       parent=self.outputHrcGrp,
                                       shape="sphere")
                debugLowCtrl.rotatePoints(90, -90, 180)
                debugLowCtrl.scalePoints(Vec3(0.01, 0.01, 0.01))
                debugLowCtrl.setColor("yellowLight")
                lidLowOutputs.append(debugLowCtrl)

        elif countLow < len(lidLowOutputs):
            numExtraLowCtrls = len(lidLowOutputs) - countLow
            for i in xrange(numExtraLowCtrls):
                extraLowCtrl = lidLowOutputs.pop()
                self.outputHrcGrp.removeChild(extraLowCtrl)

        return True

    # =============
    # Data Methods
    # =============
    def saveData(self):

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

        data['eyeballXfo'] = self.eyeballCtrl.xfo

        data['lidMedialXfo'] = self.lidMedialCtrl.xfo
        data['lidLateralXfo'] = self.lidLateralCtrl.xfo

        data['lidUpXfo'] = self.lidUpCtrl.xfo
        data['lidUpMedialXfo'] = self.lidUpMedialCtrl.xfo
        data['lidUpLateralXfo'] = self.lidUpLateralCtrl.xfo

        data['lidLowXfo'] = self.lidLowCtrl.xfo
        data['lidLowMedialXfo'] = self.lidLowMedialCtrl.xfo
        data['lidLowLateralXfo'] = self.lidLowLateralCtrl.xfo

        data['numUpDeformers'] = self.numUpDeformersAttr.getValue()
        data['numLowDeformers'] = self.numLowDeformersAttr.getValue()

        data['lidUpMedialBlink'] = self.upMedialFactorAttr.getValue()
        data['lidUpLateralBlink'] = self.upLateralFactorAttr.getValue()

        data['lidLowMedialBlink'] = self.lowMedialFactorAttr.getValue()
        data['lidLowLateralBlink'] = self.lowLateralFactorAttr.getValue()

        return data

    def loadData(self, data):

        super(mjEyelidComponentGuide, self).loadData(data)

        self.eyeballCtrl.xfo = data['eyeballXfo']

        self.lidMedialCtrl.xfo = data['lidMedialXfo']
        self.lidLateralCtrl.xfo = data['lidLateralXfo']

        self.lidUpCtrl.xfo = data['lidUpXfo']
        self.lidUpMedialCtrl.xfo = data['lidUpMedialXfo']
        self.lidUpLateralCtrl.xfo = data['lidUpLateralXfo']

        self.lidLowCtrl.xfo = data['lidLowXfo']
        self.lidLowMedialCtrl.xfo = data['lidLowMedialXfo']
        self.lidLowLateralCtrl.xfo = data['lidLowLateralXfo']

        self.numUpDeformersAttr.setValue(data["numUpDeformers"])
        self.numLowDeformersAttr.setValue(data["numLowDeformers"])

        self.numUpDeformersInputAttr.setValue(data["numUpDeformers"])
        self.numLowDeformersInputAttr.setValue(data["numLowDeformers"])

        self.upMedialFactorInputAttr.setValue(data['lidUpMedialBlink'])
        self.upLateralFactorInputAttr.setValue(data['lidUpLateralBlink'])

        self.lowMedialFactorInputAttr.setValue(data['lidLowMedialBlink'])
        self.lowLateralFactorInputAttr.setValue(data['lidLowLateralBlink'])

        self.debugLidUpCanvasOp.evaluate()
        self.debugLidLowCanvasOp.evaluate()

        return True

    def getRigBuildData(self):

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

        eyeballPosition = self.eyeballCtrl.xfo.tr
        eyeballOriXfo = Xfo()
        eyeballOriXfo.tr = eyeballPosition
        eyeballOriOffset = Quat(Vec3(0.0, 0.894, 0.0), -0.448)
        if self.getLocation() == "R":
            eyeballOriXfo.ori.subtract(eyeballOriOffset)

        data['eyeballXfo'] = eyeballOriXfo

        eyelidUpVOffset = Vec3(0.0, 0.2, 0.0)
        eyelidUpVXfo = Xfo()
        eyelidUpVXfo.tr = eyeballPosition.add(eyelidUpVOffset)

        data['eyelidUpVXfo'] = eyelidUpVXfo

        data['lidMedialXfo'] = self.lidMedialCtrl.xfo
        data['lidLateralXfo'] = self.lidLateralCtrl.xfo

        data['lidUpXfo'] = self.lidUpCtrl.xfo
        data['lidUpMedialXfo'] = self.lidUpMedialCtrl.xfo
        data['lidUpLateralXfo'] = self.lidUpLateralCtrl.xfo

        data['lidLowXfo'] = self.lidLowCtrl.xfo
        data['lidLowMedialXfo'] = self.lidLowMedialCtrl.xfo
        data['lidLowLateralXfo'] = self.lidLowLateralCtrl.xfo

        data['numUpDeformers'] = self.numUpDeformersAttr.getValue()
        data['numLowDeformers'] = self.numLowDeformersAttr.getValue()

        data['lidUpMedialBlink'] = self.upMedialFactorAttr.getValue()
        data['lidUpLateralBlink'] = self.upLateralFactorAttr.getValue()

        data['lidLowMedialBlink'] = self.lowMedialFactorAttr.getValue()
        data['lidLowLateralBlink'] = self.lowLateralFactorAttr.getValue()

        return data

    # ==============
    # Class Methods
    # ==============
    @classmethod
    def getComponentType(cls):

        return 'Guide'

    @classmethod
    def getRigComponentClass(cls):

        return mjEyelidComponentRig
예제 #37
0
    def __init__(self, name='leg', parent=None):

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


        # =========
        # Controls
        # =========
        # Femur
        self.femurFKCtrlSpace = CtrlSpace('femurFK', parent=self.ctrlCmpGrp)
        self.femurFKCtrl = Control('femurFK', parent=self.femurFKCtrlSpace, shape="cube")
        self.femurFKCtrl.alignOnXAxis()

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

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

        # FK Foot
        self.footCtrlSpace = CtrlSpace('foot', parent=self.ctrlCmpGrp)
        self.footCtrl = Control('foot', parent=self.footCtrlSpace, shape="cube")
        self.footCtrl.alignOnXAxis()

        # FK Toe
        self.toeCtrlSpace = CtrlSpace('toe', parent=self.footCtrl)
        self.toeCtrl = Control('toe', parent=self.toeCtrlSpace, shape="cube")
        self.toeCtrl.alignOnXAxis()

        # Rig Ref objects
        self.footRefSrt = Locator('footRef', parent=self.ctrlCmpGrp)

        # Add Component Params to IK control
        footSettingsAttrGrp = AttributeGroup("DisplayInfo_FootSettings", parent=self.footCtrl)
        footLinkToWorldInputAttr = ScalarAttribute('linkToWorld', 1.0, maxValue=1.0, parent=footSettingsAttrGrp)

        # Add Component Params to IK control
        legSettingsAttrGrp = AttributeGroup("DisplayInfo_LegSettings", parent=self.legIKCtrl)
        legDrawDebugInputAttr = BoolAttribute('drawDebug', value=False, parent=legSettingsAttrGrp)
        self.legBone0LenInputAttr = ScalarAttribute('bone0Len', value=1.0, parent=legSettingsAttrGrp)
        self.legBone1LenInputAttr = ScalarAttribute('bone1Len', value=1.0, parent=legSettingsAttrGrp)
        legIKBlendInputAttr = ScalarAttribute('ikblend', value=1.0, minValue=0.0, maxValue=1.0, parent=legSettingsAttrGrp)
        legSoftIKInputAttr = BoolAttribute('softIK', value=True, parent=legSettingsAttrGrp)
        legSoftDistInputAttr = ScalarAttribute('softDist', value=0.0, minValue=0.0, parent=legSettingsAttrGrp)
        legStretchInputAttr = BoolAttribute('stretch', value=True, parent=legSettingsAttrGrp)
        legStretchBlendInputAttr = ScalarAttribute('stretchBlend', value=0.0, minValue=0.0, maxValue=1.0, parent=legSettingsAttrGrp)

        self.drawDebugInputAttr.connect(legDrawDebugInputAttr)

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


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

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

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

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

        self.footDef = Joint('foot', parent=self.defCmpGrp)
        self.footDef.setComponent(self)

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


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

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

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

        # Constraint outputs
        self.footOutputConstraint = PoseConstraint('_'.join([self.footOutputTgt.getName(), 'To', self.footCtrl.getName()]))
        self.footOutputConstraint.addConstrainer(self.footCtrl)
        self.footOutputTgt.addConstraint(self.footOutputConstraint)

        self.toeOutputConstraint = PoseConstraint('_'.join([self.toeOutputTgt.getName(), 'To', self.toeCtrl.getName()]))
        self.toeOutputConstraint.addConstrainer(self.toeCtrl)
        self.toeOutputTgt.addConstraint(self.toeOutputConstraint)


        # ===============
        # Add Splice Ops
        # ===============
        # Add Leg Splice Op
        self.legIKSpliceOp = SpliceOperator('legSpliceOp', 'TwoBoneIKSolver', 'Kraken')
        self.addOperator(self.legIKSpliceOp)

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

        self.legIKSpliceOp.setInput('bone0Len', self.legBone0LenInputAttr)
        self.legIKSpliceOp.setInput('bone1Len', self.legBone1LenInputAttr)
        self.legIKSpliceOp.setInput('ikblend', legIKBlendInputAttr)
        self.legIKSpliceOp.setInput('softIK', legSoftIKInputAttr)
        self.legIKSpliceOp.setInput('softDist', legSoftDistInputAttr)
        self.legIKSpliceOp.setInput('stretch', legStretchInputAttr)
        self.legIKSpliceOp.setInput('stretchBlend', legStretchBlendInputAttr)
        self.legIKSpliceOp.setInput('rightSide', self.rightSideInputAttr)

        # Add Xfo Inputs
        self.legIKSpliceOp.setInput('root', self.legPelvisInputTgt)
        self.legIKSpliceOp.setInput('bone0FK', self.femurFKCtrl)
        self.legIKSpliceOp.setInput('bone1FK', self.shinFKCtrl)
        self.legIKSpliceOp.setInput('ikHandle', self.legIKCtrl)
        self.legIKSpliceOp.setInput('upV', self.legUpVCtrl)

        # Add Xfo Outputs
        self.legIKSpliceOp.setOutput('bone0Out', self.femurOutputTgt)
        self.legIKSpliceOp.setOutput('bone1Out', self.shinOutputTgt)
        self.legIKSpliceOp.setOutput('bone2Out', self.legEndXfoOutputTgt)


        # Add Leg Deformer Splice Op
        self.outputsToDeformersSpliceOp = SpliceOperator('legDeformerSpliceOp', 'MultiPoseConstraintSolver', 'Kraken')
        self.addOperator(self.outputsToDeformersSpliceOp)

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

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

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

        # Add Foot Deformer Splice Op
        self.footDefSpliceOp = SpliceOperator('footDeformerSpliceOp', 'PoseConstraintSolver', 'Kraken')
        self.addOperator(self.footDefSpliceOp)

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

        # Add Xfo Inputs)
        self.footDefSpliceOp.setInput('constrainer', self.footOutputTgt)

        # Add Xfo Outputs
        self.footDefSpliceOp.setOutput('constrainee', self.footDef)

        # Add Toe Deformer Splice Op
        self.toeDefSpliceOp = SpliceOperator('toeDeformerSpliceOp', 'PoseConstraintSolver', 'Kraken')
        self.addOperator(self.toeDefSpliceOp)

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

        # Add Xfo Inputs
        self.toeDefSpliceOp.setInput('constrainer', self.toeOutputTgt)

        # Add Xfo Outputs
        self.toeDefSpliceOp.setOutput('constrainee', self.toeDef)

        Profiler.getInstance().pop()
예제 #38
0
class TwistComponentRig(TwistComponent):
    """Twist Component"""

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

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


        # =========
        # Controls
        # =========
        self.originTransform = Transform('origin', parent=self.ctrlCmpGrp)
        self.originUpVTransform = Transform('originUpV', parent=self.ctrlCmpGrp)
        self.insertTransform = Transform('insert', parent=self.ctrlCmpGrp)
        self.insertUpVTransform = Transform('insertUpV', parent=self.ctrlCmpGrp)

        # Add Params to origin transform
        twistSettings = AttributeGroup("DisplayInfo_TwistSettings", parent=self.originTransform)
        self.blendBiasInputAttr = ScalarAttribute('blendBias', value=0.0, minValue=0.0, maxValue=1.0, parent=twistSettings)

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

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


        # ============
        # Constraints
        # ============
        # Constrain inputs

        # Origin and Insert
        constraintName = '_'.join([self.originTransform.getName(),
                                   'To',
                                   self.originInputTgt.getName()])

        self.originInputConstraint = self.originTransform.constrainTo(
            self.originInputTgt,
            constraintType='Position',
            maintainOffset=True,
            name=constraintName)

        constraintName = '_'.join([self.insertTransform.getName(),
                                   'To',
                                   self.insertInputTgt.getName()])

        self.insertInputConstraint = self.insertTransform.constrainTo(
            self.insertInputTgt,
            constraintType='Position',
            maintainOffset=True,
            name=constraintName)

        # Up Vectors
        constraintName = '_'.join([self.originUpVTransform.getName(),
                                   'To',
                                   self.originInputTgt.getName()])

        self.originUpVInputConstraint = self.originUpVTransform.constrainTo(
            self.originInputTgt,
            constraintType='Pose',
            maintainOffset=True,
            name=constraintName)

        constraintName = '_'.join([self.insertUpVTransform.getName(),
                                   'To',
                                   self.insertInputTgt.getName()])

        self.insertUpVInputConstraint = self.insertUpVTransform.constrainTo(
            self.insertInputTgt,
            constraintType='Pose',
            maintainOffset=True,
            name=constraintName)

        # Constrain outputs


        # ===============
        # Add Splice Ops
        # ===============
        # Add Spine Splice Op
        self.twistKLOp = KLOperator('TwistOp', 'TwistSolver', 'Kraken')
        self.addOperator(self.twistKLOp)

        # Add Att Inputs
        self.twistKLOp.setInput('drawDebug', self.drawDebugInputAttr)
        self.twistKLOp.setInput('rigScale', self.rigScaleInputAttr)
        self.twistKLOp.setInput('blendBias', self.blendBiasInputAttr)

        # Add Xfo Inputs
        self.twistKLOp.setInput('origin', self.originTransform)
        self.twistKLOp.setInput('originUpV', self.originUpVTransform)
        self.twistKLOp.setInput('insert', self.insertTransform)
        self.twistKLOp.setInput('insertUpV', self.insertUpVTransform)

        # Add Xfo Outputs
        self.twistKLOp.setOutput('pose', self.twistOutputs)

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

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

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

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

        Profiler.getInstance().pop()


    def setNumDeformers(self, numDeformers):

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

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

        return True


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

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

        Return:
        True if successful.

        """

        super(TwistComponentRig, self).loadData(data)

        blendBias = data.get('blendBias')
        originXfo = data.get('originXfo')
        insertXfo = data.get('insertXfo')
        originUpVXfo = data.get('originUpVXfo')
        insertUpVXfo = data.get('insertUpVXfo')
        numDeformers = data.get('numDeformers')

        self.blendBiasInputAttr.setValue(blendBias)

        self.originTransform.xfo = originXfo
        self.originUpVTransform.xfo = originUpVXfo
        self.insertTransform.xfo = insertXfo
        self.insertUpVTransform.xfo = insertUpVXfo

        self.originInputTgt.xfo = originXfo
        self.insertInputTgt.xfo = insertXfo

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

        # Evaluate Constraints
        self.originInputConstraint.evaluate()
        self.insertInputConstraint.evaluate()
        self.originUpVInputConstraint.evaluate()
        self.insertUpVInputConstraint.evaluate()

        # Evaluate Operators
        # self.twistKLOp.evaluate()
        self.deformersToOutputsKLOp.evaluate()
예제 #39
0
    def __init__(self, name='mjEyelid', parent=None):
        Profiler.getInstance().push("Construct Eyelid Rig Component:" + name)
        super(mjEyelidComponentRig, self).__init__(name, parent)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        Profiler.getInstance().pop()
예제 #40
0
class TwistComponentGuide(TwistComponent):
    """Twist Component Guide"""

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

        Profiler.getInstance().push('Construct Spine Guide Component:' + name)
        super(TwistComponentGuide, self).__init__(name, parent)

        # =========
        # Controls
        # ========
        guideSettingsAttrGrp = AttributeGroup('GuideSettings', parent=self)
        self.numDeformersAttr = IntegerAttribute('numDeformers', value=1, minValue=0, maxValue=20, parent=guideSettingsAttrGrp)
        self.blendBiasAttr = ScalarAttribute('blendBias', value=0.0, minValue=0, maxValue=1.0, parent=guideSettingsAttrGrp)

        # Guide Controls
        triangleCtrl = Control('triangle', shape='triangle')
        triangleCtrl.rotatePoints(90, 0, 0)
        triangleCtrl.scalePoints(Vec3(0.25, 0.25, 0.25))
        triangleCtrl.scalePoints(Vec3(1.0, 0.5, 1.0))
        triangleCtrl.translatePoints(Vec3(0.0, 1.25, 0.0))
        triangleCtrl.rotatePoints(0, 90, 0)

        self.originCtrl = Control('origin', parent=self.ctrlCmpGrp, shape='circle')
        self.originCtrl.rotatePoints(90, 0, 0)
        self.originCtrl.rotatePoints(0, 90, 0)
        self.originCtrl.appendCurveData(triangleCtrl.getCurveData())
        self.insertCtrl = Control('insert', parent=self.ctrlCmpGrp, shape='circle')
        self.insertCtrl.rotatePoints(90, 0, 0)
        self.insertCtrl.rotatePoints(0, 90, 0)
        self.insertCtrl.appendCurveData(triangleCtrl.getCurveData())

        self.default_data = {
            'name': name,
            'location': 'M',
            'blendBias': 0.5,
            'originXfo': Xfo(Vec3(0.0, 0.0, 0.0)),
            'insertXfo': Xfo(Vec3(5.0, 0.0, 0.0)),
            'numDeformers': 5
        }

        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(TwistComponentGuide, self).saveData()

        data['blendBias'] = self.blendBiasAttr.getValue()
        data['originXfo'] = self.originCtrl.xfo
        data['insertXfo'] = self.insertCtrl.xfo
        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(TwistComponentGuide, self).loadData(data)

        self.blendBiasAttr.setValue(data.get('blendBias', 0.0))
        self.originCtrl.xfo = data.get('originXfo', Xfo())
        self.insertCtrl.xfo = data.get('insertXfo', Xfo())
        self.numDeformersAttr.setValue(data.get('numDeformers', 5))

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

        data['blendBias'] = self.blendBiasAttr.getValue()

        data['originXfo'] = self.originCtrl.xfo
        data['insertXfo'] = self.insertCtrl.xfo

        originUpVXfo = Xfo(Vec3(0.0, 1.0, 0.0))
        insertUpVXfo = Xfo(Vec3(0.0, 1.0, 0.0))

        data['originUpVXfo'] = self.originCtrl.xfo * originUpVXfo
        data['insertUpVXfo'] = self.insertCtrl.xfo * insertUpVXfo

        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 TwistComponentRig
예제 #41
0
    def __init__(self, name='mjEyelid', parent=None):

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

        # =========
        # Attributes // Create Attributes Controls.
        # =========
        guideUpSettingsAttrGrp = AttributeGroup("Eyelid Up", parent=self)
        guideLowSettingsAttrGrp = AttributeGroup("Eyelid Low", parent=self)

        self.numUpDeformersAttr = IntegerAttribute(
            'Num Deformers',
            value=10,
            minValue=1,
            maxValue=50,
            parent=guideUpSettingsAttrGrp)
        self.upMedialFactorAttr = ScalarAttribute(
            'Medial Blink Factor',
            value=0.25,
            minValue=0,
            maxValue=1,
            parent=guideUpSettingsAttrGrp)
        self.upLateralFactorAttr = ScalarAttribute(
            'Lateral Blink Factor',
            value=0.65,
            minValue=0,
            maxValue=1,
            parent=guideUpSettingsAttrGrp)

        self.numLowDeformersAttr = IntegerAttribute(
            'Num Deformers',
            value=10,
            minValue=1,
            maxValue=50,
            parent=guideLowSettingsAttrGrp)
        self.lowMedialFactorAttr = ScalarAttribute(
            'Medial Blink Factor',
            value=0.25,
            minValue=0,
            maxValue=1,
            parent=guideLowSettingsAttrGrp)
        self.lowLateralFactorAttr = ScalarAttribute(
            'Lateral Blink Factor',
            value=0.65,
            minValue=0,
            maxValue=1,
            parent=guideLowSettingsAttrGrp)

        self.numUpDeformersAttr.setValueChangeCallback(
            self.updateNumUpDeformers)
        self.numLowDeformersAttr.setValueChangeCallback(
            self.updateNumLowDeformers)

        # =========
        # Controls // Create the Guide Controls, Name them, give them a shape, a color and scale it.
        # =========
        self.eyeballCtrl = Control('eyeball',
                                   parent=self.ctrlCmpGrp,
                                   shape="sphere")
        self.eyeballCtrl.scalePoints(Vec3(0.35, 0.35, 0.35))
        self.eyeballCtrl.setColor("red")

        self.lidMedialCtrl = Control('lidMedial',
                                     parent=self.eyeballCtrl,
                                     shape="sphere")
        self.lidMedialCtrl.scalePoints(Vec3(0.025, 0.025, 0.025))
        self.lidMedialCtrl.setColor("peach")

        self.lidLateralCtrl = Control('lidLateral',
                                      parent=self.eyeballCtrl,
                                      shape="sphere")
        self.lidLateralCtrl.scalePoints(Vec3(0.025, 0.025, 0.025))
        self.lidLateralCtrl.setColor("peach")

        self.lidUpCtrl = Control('lidUp',
                                 parent=self.eyeballCtrl,
                                 shape="sphere")
        self.lidUpCtrl.scalePoints(Vec3(0.025, 0.025, 0.025))
        self.lidUpCtrl.setColor("peach")

        self.lidUpMedialCtrl = Control('lidUpMedial',
                                       parent=self.eyeballCtrl,
                                       shape="sphere")
        self.lidUpMedialCtrl.scalePoints(Vec3(0.025, 0.025, 0.025))
        self.lidUpMedialCtrl.setColor("peach")

        self.lidUpLateralCtrl = Control('lidUpLateral',
                                        parent=self.eyeballCtrl,
                                        shape="sphere")
        self.lidUpLateralCtrl.scalePoints(Vec3(0.025, 0.025, 0.025))
        self.lidUpLateralCtrl.setColor("peach")

        self.lidLowCtrl = Control('lidLow',
                                  parent=self.eyeballCtrl,
                                  shape="sphere")
        self.lidLowCtrl.scalePoints(Vec3(0.025, 0.025, 0.025))
        self.lidLowCtrl.setColor("peach")

        self.lidLowMedialCtrl = Control('lidLowMedial',
                                        parent=self.eyeballCtrl,
                                        shape="sphere")
        self.lidLowMedialCtrl.scalePoints(Vec3(0.025, 0.025, 0.025))
        self.lidLowMedialCtrl.setColor("peach")

        self.lidLowLateralCtrl = Control('lidLowLateral',
                                         parent=self.eyeballCtrl,
                                         shape="sphere")
        self.lidLowLateralCtrl.scalePoints(Vec3(0.025, 0.025, 0.025))
        self.lidLowLateralCtrl.setColor("peach")

        # ===============
        # Add Debug Splice Ops
        # ===============
        # Add Lid Up Canvas Op
        self.debugLidUpCanvasOp = CanvasOperator(
            'Debug_Canvas_Eyelid_Up_Op', 'MJCG.Solvers.mjEyelidDebugSolver')
        self.addOperator(self.debugLidUpCanvasOp)

        # Add Attributes Inputs
        self.debugLidUpCanvasOp.setInput('drawDebug', self.drawDebugInputAttr)
        self.debugLidUpCanvasOp.setInput('rigScale', self.rigScaleInputAttr)
        self.debugLidUpCanvasOp.setInput('Deformer_Count',
                                         self.numUpDeformersInputAttr)

        # Add Xfo Inputs
        self.debugLidUpCanvasOp.setInput('Eye_Center', self.eyeballCtrl)
        self.debugLidUpCanvasOp.setInput('Lid_Medial', self.lidMedialCtrl)
        self.debugLidUpCanvasOp.setInput('Lid_MedialCen', self.lidUpMedialCtrl)
        self.debugLidUpCanvasOp.setInput('Lid_Center_Ref', self.lidUpCtrl)
        self.debugLidUpCanvasOp.setInput('Lid_Center_Ctrl', self.lidUpCtrl)
        self.debugLidUpCanvasOp.setInput('Lid_LateralCen',
                                         self.lidUpLateralCtrl)
        self.debugLidUpCanvasOp.setInput('Lid_Lateral', self.lidLateralCtrl)

        # Add Xfo Outputs
        self.debugLidUpCanvasOp.setOutput('result',
                                          self.eyelidUpOutput.getTarget())

        # Add Lid Low Canvas Op
        self.debugLidLowCanvasOp = CanvasOperator(
            'Debug_Canvas_Eyelid_Low_Op', 'MJCG.Solvers.mjEyelidDebugSolver')
        self.addOperator(self.debugLidLowCanvasOp)

        # Add Attributes Inputs
        self.debugLidLowCanvasOp.setInput('drawDebug', self.drawDebugInputAttr)
        self.debugLidLowCanvasOp.setInput('rigScale', self.rigScaleInputAttr)
        self.debugLidLowCanvasOp.setInput('Deformer_Count',
                                          self.numLowDeformersInputAttr)

        # Add Xfo Inputs
        self.debugLidLowCanvasOp.setInput('Eye_Center', self.eyeballCtrl)
        self.debugLidLowCanvasOp.setInput('Lid_Medial', self.lidMedialCtrl)
        self.debugLidLowCanvasOp.setInput('Lid_MedialCen',
                                          self.lidLowMedialCtrl)
        self.debugLidLowCanvasOp.setInput('Lid_Center_Ref', self.lidLowCtrl)
        self.debugLidLowCanvasOp.setInput('Lid_Center_Ctrl', self.lidLowCtrl)
        self.debugLidLowCanvasOp.setInput('Lid_LateralCen',
                                          self.lidLowLateralCtrl)
        self.debugLidLowCanvasOp.setInput('Lid_Lateral', self.lidLateralCtrl)

        # Add Xfo Outputs
        self.debugLidLowCanvasOp.setOutput('result',
                                           self.eyelidLowOutput.getTarget())

        # =========
        # Position Data // Get the Guide Controls Position data, else set them at their initial position.
        # =========
        self.default_data = {
            "name": name,
            "location": "L",
            "eyeballXfo": Xfo(Vec3(0.322, 15.500, 0.390)),
            "lidMedialXfo": Xfo(Vec3(0.168, 15.445, 0.520)),
            "lidLateralXfo": Xfo(Vec3(0.465, 15.47, 0.465)),
            "lidUpXfo": Xfo(Vec3(0.322, 15.585, 0.605)),
            "lidUpMedialXfo": Xfo(Vec3(0.203, 15.515, 0.525)),
            "lidUpLateralXfo": Xfo(Vec3(0.432, 15.55, 0.538)),
            "lidLowXfo": Xfo(Vec3(0.322, 15.434, 0.6)),
            "lidLowMedialXfo": Xfo(Vec3(0.24, 15.45, 0.513)),
            "lidLowLateralXfo": Xfo(Vec3(0.413, 15.44, 0.525)),
            "lidUpMedialBlink": self.upMedialFactorAttr.getValue(),
            "lidUpLateralBlink": self.upLateralFactorAttr.getValue(),
            "lidLowMedialBlink": self.lowMedialFactorAttr.getValue(),
            "lidLowLateralBlink": self.lowLateralFactorAttr.getValue(),
            "numUpDeformers": self.numUpDeformersAttr.getValue(),
            "numLowDeformers": self.numLowDeformersAttr.getValue(),
        }

        self.loadData(self.default_data)

        Profiler.getInstance().pop()
예제 #42
0
class ArmComponentRig(ArmComponent):
    """Arm Component Rig"""
    def __init__(self, name='arm', parent=None):

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

        # =========
        # Controls
        # =========
        # Bicep
        self.bicepFKCtrlSpace = CtrlSpace('bicepFK', parent=self.ctrlCmpGrp)

        self.bicepFKCtrl = Control('bicepFK',
                                   parent=self.bicepFKCtrlSpace,
                                   shape="cube")
        self.bicepFKCtrl.alignOnXAxis()
        self.bicepFKCtrl.lockScale(True, True, True)
        self.bicepFKCtrl.lockTranslation(True, True, True)

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        # Constraint outputs

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

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

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

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

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

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

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

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

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

        Profiler.getInstance().pop()

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

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

        Return:
        True if successful.

        """

        super(ArmComponentRig, self).loadData(data)

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

        self.rootInputTgt.xfo.tr = bicepXfo.tr

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

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

        self.ikRootPosition.xfo = bicepXfo

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

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

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

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

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

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

        # Eval Operators
        self.armSolverKLOperator.evaluate()
        self.outputsToDeformersKLOp.evaluate()