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()
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()
class FKChainComponentRig(FKChainComponent): """FK Chain 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 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 # ============== # 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 Canvas Ops # =============== # Add Output Canvas Op self.outputsToControlsKLOp = KLOperator('outputConstraint', '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 Canvas Op self.deformersToOutputsKLOp = KLOperator('defConstraint', '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) defOutput = ComponentOutput(name, parent=self.outputHrcGrp) self.boneOutputsTgt.append(defOutput) 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 Canvas 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() self.chainEndPosOutputConstraint.evaluate()