コード例 #1
0
ファイル: fkChain_component.py プロジェクト: sonictk/Kraken
    def loadData(self, data=None):
        """Load a saved guide representation from persisted data.

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

        Return:
        True if successful.

        """

        super(FKChainComponentRig, self).loadData(data)

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

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

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

        # ==========================
        # Create Output Constraints
        # ==========================
        # This needs to be done here since the 'numJoints' attribute resizes the
        # number of controls and outputs

        self.chainEndXfoOutputConstraint = PoseConstraint('_'.join([
            self.chainEndXfoOutputTgt.getName(), 'To',
            self.boneOutputsTgt[-1].getName()
        ]))
        self.chainEndXfoOutputConstraint.setMaintainOffset(True)
        self.chainEndXfoOutputConstraint.addConstrainer(
            self.boneOutputsTgt[-1])
        self.chainEndXfoOutputTgt.addConstraint(
            self.chainEndXfoOutputConstraint)

        self.chainEndPosOutputConstraint = PositionConstraint('_'.join([
            self.chainEndPosOutputTgt.getName(), 'To',
            self.boneOutputsTgt[-1].getName()
        ]))
        self.chainEndPosOutputConstraint.setMaintainOffset(True)
        self.chainEndPosOutputConstraint.addConstrainer(
            self.boneOutputsTgt[-1])
        self.chainEndPosOutputTgt.addConstraint(
            self.chainEndPosOutputConstraint)

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

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

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

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

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

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

        # evaluate the constraints to ensure the outputs are now in the correct location.
        self.rootInputConstraint.evaluate()
        self.chainEndXfoOutputConstraint.evaluate()
コード例 #2
0
ファイル: fabrice_spine.py プロジェクト: hoorayfor3d/Kraken
    def __init__(self, name="spine", parent=None):

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


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

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

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

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

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


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

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


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

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

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

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

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

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

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

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

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


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

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

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

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

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

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

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

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

        Profiler.getInstance().pop()
コード例 #3
0
ファイル: fkChain_component.py プロジェクト: sonictk/Kraken
class FKChainComponentRig(FKChainComponent):
    """FK Chain Leg Rig"""
    def __init__(self, name='FKChain', parent=None):

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

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

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

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

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

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

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

        # ==============
        # Constrain I/O
        # ==============
        # Constraint inputs
        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.outputsToControlsKLOp = KLOperator('fkChainOutputKLOp',
                                                'MultiPoseConstraintSolver',
                                                'Kraken')
        self.addOperator(self.outputsToControlsKLOp)

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

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

        # Add Xfo Outputs
        self.outputsToControlsKLOp.setOutput('constrainees',
                                             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()

    def setNumControls(self, numControls):

        # Add more controls
        if numControls > len(self.fkCtrlSpaces):
            for i in xrange(len(self.fkCtrlSpaces), numControls):
                if i == 0:
                    parent = self.ctrlCmpGrp
                else:
                    parent = self.fkCtrls[i - 1]

                boneName = 'bone' + str(i + 1).zfill(2) + 'FK'
                boneFKCtrlSpace = CtrlSpace(boneName, parent=parent)

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

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

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

    def setNumDeformers(self, numDeformers):

        # Add more deformers and outputs
        if numDeformers > len(self.boneOutputsTgt):
            for i in xrange(len(self.boneOutputsTgt), numDeformers):
                name = 'bone' + str(i + 1).zfill(2)

                legOutput = ComponentOutput(name, parent=self.outputHrcGrp)
                self.boneOutputsTgt.append(legOutput)

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

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

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

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

        return True

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

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

        Return:
        True if successful.

        """

        super(FKChainComponentRig, self).loadData(data)

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

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

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

        # ==========================
        # Create Output Constraints
        # ==========================
        # This needs to be done here since the 'numJoints' attribute resizes the
        # number of controls and outputs

        self.chainEndXfoOutputConstraint = PoseConstraint('_'.join([
            self.chainEndXfoOutputTgt.getName(), 'To',
            self.boneOutputsTgt[-1].getName()
        ]))
        self.chainEndXfoOutputConstraint.setMaintainOffset(True)
        self.chainEndXfoOutputConstraint.addConstrainer(
            self.boneOutputsTgt[-1])
        self.chainEndXfoOutputTgt.addConstraint(
            self.chainEndXfoOutputConstraint)

        self.chainEndPosOutputConstraint = PositionConstraint('_'.join([
            self.chainEndPosOutputTgt.getName(), 'To',
            self.boneOutputsTgt[-1].getName()
        ]))
        self.chainEndPosOutputConstraint.setMaintainOffset(True)
        self.chainEndPosOutputConstraint.addConstrainer(
            self.boneOutputsTgt[-1])
        self.chainEndPosOutputTgt.addConstraint(
            self.chainEndPosOutputConstraint)

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

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

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

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

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

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

        # evaluate the constraints to ensure the outputs are now in the correct location.
        self.rootInputConstraint.evaluate()
        self.chainEndXfoOutputConstraint.evaluate()
コード例 #4
0
ファイル: fabrice_spine.py プロジェクト: hoorayfor3d/Kraken
class FabriceSpineRig(FabriceSpine):
    """Fabrice Spine Component"""

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

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


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

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

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

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

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


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

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


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

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

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

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

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

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

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

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

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


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

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

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

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

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

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

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

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

        Profiler.getInstance().pop()


    def setNumDeformers(self, numDeformers):

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

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

        return True


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

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

        Return:
        True if successful.

        """

        super(FabriceSpineRig, self).loadData( data )

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

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

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

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

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

        numDeformers = data['numDeformers']

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

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

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

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

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

        length = spineBasePos.distanceTo(spineBaseHandlePos) + spineBaseHandlePos.distanceTo(spineEndHandlePos) + spineEndHandlePos.distanceTo(spineEndPos)
        self.lengthInputAttr.setMax(length * 3.0)
        self.lengthInputAttr.setValue(length)

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

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

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

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

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

        # evaluate the constraints to ensure the outputs are now in the correct location.
        self.spineSrtInputConstraint.evaluate()
        self.spineCogOutputConstraint.evaluate()
        self.spineBaseOutputPosConstraint.evaluate()
        self.spineBaseOutputOriConstraint.evaluate()
        self.spineEndOutputConstraint.evaluate()
        self.spineEndCtrlOutputConstraint.evaluate()
コード例 #5
0
    def __init__(self, name="spine", parent=None):

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        Profiler.getInstance().pop()
コード例 #6
0
class FabriceSpineRig(FabriceSpine):
    """Fabrice Spine Component"""
    def __init__(self, name="spine", parent=None):

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        Profiler.getInstance().pop()

    def setNumDeformers(self, numDeformers):

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

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

        return True

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

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

        Return:
        True if successful.

        """

        super(FabriceSpineRig, self).loadData(data)

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

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

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

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

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

        numDeformers = data['numDeformers']

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

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

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

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

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

        length = spineBasePos.distanceTo(
            spineBaseHandlePos) + spineBaseHandlePos.distanceTo(
                spineEndHandlePos) + spineEndHandlePos.distanceTo(spineEndPos)
        self.lengthInputAttr.setMax(length * 3.0)
        self.lengthInputAttr.setValue(length)

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

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

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

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

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

        # evaluate the constraints to ensure the outputs are now in the correct location.
        self.spineSrtInputConstraint.evaluate()
        self.spineCogOutputConstraint.evaluate()
        self.spineBaseOutputPosConstraint.evaluate()
        self.spineBaseOutputOriConstraint.evaluate()
        self.spineEndOutputConstraint.evaluate()
        self.spineEndCtrlOutputConstraint.evaluate()
コード例 #7
0
ファイル: kraken_loader.py プロジェクト: sonictk/Kraken
    def construct(self, jsonData):
        """Returns a constructed scene item based on the provided json data.

        Args:
            jsondata (dict): the JSON data to use to decode into a Math value.

        Returns:
            object: The constructed scene item.

        """

        if '__typeHierarchy__' not in jsonData or 'name' not in jsonData:
            raise Exception("Invalid JSON data for constructing scene item:" +
                            str(jsonData))

        # =========
        # Controls
        # =========
        if "Control" in jsonData['__typeHierarchy__']:
            item = Control(jsonData['name'])

        # ===========
        # Attributes
        # ===========
        elif "AttributeGroup" in jsonData['__typeHierarchy__']:
            item = AttributeGroup(jsonData['name'])

        elif "BoolAttribute" in jsonData['__typeHierarchy__']:
            item = BoolAttribute(jsonData['name'])

        elif "ScalarAttribute" in jsonData['__typeHierarchy__']:
            item = ScalarAttribute(jsonData['name'])

        elif "IntegerAttribute" in jsonData['__typeHierarchy__']:
            item = IntegerAttribute(jsonData['name'])

        elif "StringAttribute" in jsonData['__typeHierarchy__']:
            item = StringAttribute(jsonData['name'])

        elif "ComponentInput" in jsonData['__typeHierarchy__']:
            item = ComponentInput(jsonData['name'])

        elif "ComponentOutput" in jsonData['__typeHierarchy__']:
            item = ComponentOutput(jsonData['name'])

        # ============
        # Constraints
        # ============
        elif "OrientationConstraint" in jsonData['__typeHierarchy__']:
            item = OrientationConstraint(jsonData['name'])

        elif "PoseConstraint" in jsonData['__typeHierarchy__']:
            item = PoseConstraint(jsonData['name'])

        elif "PositionConstraint" in jsonData['__typeHierarchy__']:
            item = PositionConstraint(jsonData['name'])

        elif "ScaleConstraint" in jsonData['__typeHierarchy__']:
            item = ScaleConstraint(jsonData['name'])

        elif "BaseConstraint" in jsonData['__typeHierarchy__']:
            item = BaseConstraint(jsonData['name'])

        # ==========
        # Operators
        # ==========
        elif "KLOperator" in jsonData['__typeHierarchy__']:
            item = KLOperator(jsonData['name'])

        # ============
        # Scene Items
        # ============
        elif "Group" in jsonData['__typeHierarchy__']:
            item = Group(jsonData['name'])

        elif "Null" in jsonData['__typeHierarchy__']:
            item = Null(jsonData['name'])

        elif "Chain" in jsonData['__typeHierarchy__']:
            item = Chain(jsonData['name'])

        elif "Joint" in jsonData['__typeHierarchy__']:
            item = Joint(jsonData['name'])

        elif "Container" in jsonData['__typeHierarchy__']:
            item = Container(jsonData['name'])

        elif "Curve" in jsonData['__typeHierarchy__']:
            item = Curve(jsonData['name'])

        elif "HierarchyGroup" in jsonData['__typeHierarchy__']:
            item = HierarchyGroup(jsonData['name'])

        elif "Joint" in jsonData['__typeHierarchy__']:
            item = Joint(jsonData['name'])

        elif "Layer" in jsonData['__typeHierarchy__']:
            item = Layer(jsonData['name'])

        elif "Locator" in jsonData['__typeHierarchy__']:
            item = Locator(jsonData['name'])

        elif "SceneItem" in jsonData['__typeHierarchy__']:
            item = SceneItem(jsonData['name'])

        else:
            raise Exception("KrakenLoader does not support the given type:" +
                            jsonData['__typeHierarchy__'])

        # Before registering or decoding, set the parent so that the full name contains the entire path.
        if len(self.parentItems) > 0:
            item.setParent(self.parentItems[-1])

        self.registerItem(item)
        # Store the item as the parent item before decoding the object
        # which in turn decodes the children items.
        self.parentItems.append(item)

        item.jsonDecode(self, jsonData)

        # Pop the parent item stack, which reverts the current parent item
        # to the previous value.
        self.parentItems.pop()

        return item
コード例 #8
0
    def constrainTo(self,
                    constrainers,
                    constraintType="Pose",
                    maintainOffset=False,
                    name=None):
        """Adds an constraint to this object.

        Args:
            constrainers (Object or Object list): Constraint object to add to
                this object or objects.
            constraintType (str): String name of the constraint type.
            maintainOffset (bool): Sets the constraint to maintain offset when
                creating the constraint.
            name (str): Name of the constraint. If set to None, a name is
                automatically generated.

        Returns:
            string: Constraint object

        """

        if name is None:
            constraintName = ""
            if hasattr(constrainers, '__iter__'):
                constraintName = '_'.join([
                    self.getName(), 'To', constrainers[0].getName(),
                    constraintType + 'Constraint'
                ])
            else:
                constraintName = '_'.join([
                    self.getName(), 'To',
                    constrainers.getName(), constraintType + 'Constraint'
                ])
        else:
            constraintName = name

        constraint = None
        if constraintType == "Orientation":
            constraint = OrientationConstraint(constraintName)
        elif constraintType == "Pose":
            constraint = PoseConstraint(constraintName)
        elif constraintType == "Position":
            constraint = PositionConstraint(constraintName)
        elif constraintType == "Scale":
            constraint = ScaleConstraint(constraintName)
        else:
            raise ValueError(
                "'" + constraintType +
                "' is not a valid constraint type. Valid types are Orientation, Pose, Position, or Scale"
            )

        # Accept a single object or a list of objects
        if hasattr(constrainers, '__iter__'):
            pass
        else:
            constrainers = [constrainers]

        for constrainer in constrainers:
            constraint.addConstrainer(constrainer)

        constraint.setMaintainOffset(maintainOffset)

        self.addConstraint(constraint)

        return constraint