def __init__(self, name, parent=None, location='M'): super(ArmComponent, self).__init__(name, parent, location) # ========= # Controls # ========= # Setup component attributes defaultAttrGroup = self.getAttributeGroupByIndex(0) defaultAttrGroup.addAttribute(BoolAttribute("toggleDebugging", True)) # Default values if self.getLocation() == "R": ctrlColor = "red" bicepPosition = Vec3(-2.27, 15.295, -0.753) forearmPosition = Vec3(-5.039, 13.56, -0.859) wristPosition = Vec3(-7.1886, 12.2819, 0.4906) else: ctrlColor = "greenBright" bicepPosition = Vec3(2.27, 15.295, -0.753) forearmPosition = Vec3(5.039, 13.56, -0.859) wristPosition = Vec3(7.1886, 12.2819, 0.4906) # Calculate Bicep Xfo rootToWrist = wristPosition.subtract(bicepPosition).unit() rootToElbow = forearmPosition.subtract(bicepPosition).unit() bone1Normal = rootToWrist.cross(rootToElbow).unit() bone1ZAxis = rootToElbow.cross(bone1Normal).unit() bicepXfo = Xfo() bicepXfo.setFromVectors(rootToElbow, bone1Normal, bone1ZAxis, bicepPosition) # Calculate Forearm Xfo elbowToWrist = wristPosition.subtract(forearmPosition).unit() elbowToRoot = bicepPosition.subtract(forearmPosition).unit() bone2Normal = elbowToRoot.cross(elbowToWrist).unit() bone2ZAxis = elbowToWrist.cross(bone2Normal).unit() forearmXfo = Xfo() forearmXfo.setFromVectors(elbowToWrist, bone2Normal, bone2ZAxis, forearmPosition) # Bicep bicepFKCtrl = CubeControl('bicepFK') bicepFKCtrl.alignOnXAxis() bicepLen = bicepPosition.subtract(forearmPosition).length() bicepFKCtrl.scalePoints(Vec3(bicepLen, 1.75, 1.75)) bicepFKCtrl.setColor(ctrlColor) bicepFKCtrl.xfo.copy(bicepXfo) bicepFKCtrlSrtBuffer = SrtBuffer('bicepFK') self.addChild(bicepFKCtrlSrtBuffer) bicepFKCtrlSrtBuffer.xfo.copy(bicepFKCtrl.xfo) bicepFKCtrlSrtBuffer.addChild(bicepFKCtrl) # Forearm forearmFKCtrl = CubeControl('forearmFK') forearmFKCtrl.alignOnXAxis() forearmLen = forearmPosition.subtract(wristPosition).length() forearmFKCtrl.scalePoints(Vec3(forearmLen, 1.5, 1.5)) forearmFKCtrl.setColor(ctrlColor) forearmFKCtrl.xfo.copy(forearmXfo) forearmFKCtrlSrtBuffer = SrtBuffer('forearmFK') bicepFKCtrl.addChild(forearmFKCtrlSrtBuffer) forearmFKCtrlSrtBuffer.xfo.copy(forearmFKCtrl.xfo) forearmFKCtrlSrtBuffer.addChild(forearmFKCtrl) # Arm IK armIKCtrlSrtBuffer = SrtBuffer('IK', parent=self) armIKCtrlSrtBuffer.xfo.tr.copy(wristPosition) armIKCtrl = PinControl('IK', parent=armIKCtrlSrtBuffer) armIKCtrl.xfo.copy(armIKCtrlSrtBuffer.xfo) armIKCtrl.setColor(ctrlColor) if self.getLocation() == "R": armIKCtrl.rotatePoints(0, 90, 0) else: armIKCtrl.rotatePoints(0, -90, 0) # Add Component Params to IK control armDebugInputAttr = BoolAttribute('debug', True) armBone1LenInputAttr = FloatAttribute('bone1Len', bicepLen, 0.0, 100.0) armBone2LenInputAttr = FloatAttribute('bone2Len', forearmLen, 0.0, 100.0) armFkikInputAttr = FloatAttribute('fkik', 0.0, 0.0, 1.0) armSoftIKInputAttr = BoolAttribute('softIK', True) armSoftDistInputAttr = FloatAttribute('softDist', 0.0, 0.0, 1.0) armStretchInputAttr = BoolAttribute('stretch', True) armStretchBlendInputAttr = FloatAttribute('stretchBlend', 0.0, 0.0, 1.0) armSettingsAttrGrp = AttributeGroup("DisplayInfo_ArmSettings") armIKCtrl.addAttributeGroup(armSettingsAttrGrp) armSettingsAttrGrp.addAttribute(armDebugInputAttr) armSettingsAttrGrp.addAttribute(armBone1LenInputAttr) armSettingsAttrGrp.addAttribute(armBone2LenInputAttr) armSettingsAttrGrp.addAttribute(armFkikInputAttr) armSettingsAttrGrp.addAttribute(armSoftIKInputAttr) armSettingsAttrGrp.addAttribute(armSoftDistInputAttr) armSettingsAttrGrp.addAttribute(armStretchInputAttr) armSettingsAttrGrp.addAttribute(armStretchBlendInputAttr) # UpV upVXfo = xfoFromDirAndUpV(bicepPosition, wristPosition, forearmPosition) upVXfo.tr.copy(forearmPosition) upVOffset = Vec3(0, 0, 5) upVOffset = upVXfo.transformVector(upVOffset) armUpVCtrl = TriangleControl('UpV') armUpVCtrl.xfo.tr.copy(upVOffset) armUpVCtrl.alignOnZAxis() armUpVCtrl.rotatePoints(180, 0, 0) armUpVCtrl.setColor(ctrlColor) armUpVCtrlSrtBuffer = SrtBuffer('UpV') self.addChild(armUpVCtrlSrtBuffer) armUpVCtrlSrtBuffer.xfo.tr.copy(upVOffset) armUpVCtrlSrtBuffer.addChild(armUpVCtrl) # ========== # Deformers # ========== container = self.getParent().getParent() deformersLayer = container.getChildByName('deformers') bicepDef = Joint('bicep') bicepDef.setComponent(self) forearmDef = Joint('forearm') forearmDef.setComponent(self) wristDef = Joint('wrist') wristDef.setComponent(self) deformersLayer.addChild(bicepDef) deformersLayer.addChild(forearmDef) deformersLayer.addChild(wristDef) # ===================== # Create Component I/O # ===================== # Setup component Xfo I/O's clavicleEndInput = Locator('clavicleEnd') clavicleEndInput.xfo.copy(bicepXfo) bicepOutput = Locator('bicep') bicepOutput.xfo.copy(bicepXfo) forearmOutput = Locator('forearm') forearmOutput.xfo.copy(forearmXfo) armEndXfo = Xfo() armEndXfo.rot = forearmXfo.rot.clone() armEndXfo.tr.copy(wristPosition) armEndXfoOutput = Locator('armEndXfo') armEndXfoOutput.xfo.copy(armEndXfo) armEndPosOutput = Locator('armEndPos') armEndPosOutput.xfo.copy(armEndXfo) # Setup componnent Attribute I/O's debugInputAttr = BoolAttribute('debug', True) bone1LenInputAttr = FloatAttribute('bone1Len', bicepLen, 0.0, 100.0) bone2LenInputAttr = FloatAttribute('bone2Len', forearmLen, 0.0, 100.0) fkikInputAttr = FloatAttribute('fkik', 0.0, 0.0, 1.0) softIKInputAttr = BoolAttribute('softIK', True) softDistInputAttr = FloatAttribute('softDist', 0.5, 0.0, 1.0) stretchInputAttr = BoolAttribute('stretch', True) stretchBlendInputAttr = FloatAttribute('stretchBlend', 0.0, 0.0, 1.0) rightSideInputAttr = BoolAttribute('rightSide', location is 'R') # Connect attrs to control attrs debugInputAttr.connect(armDebugInputAttr) bone1LenInputAttr.connect(armBone1LenInputAttr) bone2LenInputAttr.connect(armBone2LenInputAttr) fkikInputAttr.connect(armFkikInputAttr) softIKInputAttr.connect(armSoftIKInputAttr) softDistInputAttr.connect(armSoftDistInputAttr) stretchInputAttr.connect(armStretchInputAttr) stretchBlendInputAttr.connect(armStretchBlendInputAttr) # ============== # Constrain I/O # ============== # Constraint inputs armRootInputConstraint = PoseConstraint('_'.join([armIKCtrl.getName(), 'To', clavicleEndInput.getName()])) armRootInputConstraint.setMaintainOffset(True) armRootInputConstraint.addConstrainer(clavicleEndInput) bicepFKCtrlSrtBuffer.addConstraint(armRootInputConstraint) # Constraint outputs # ================== # Add Component I/O # ================== # Add Xfo I/O's self.addInput(clavicleEndInput) self.addOutput(bicepOutput) self.addOutput(forearmOutput) self.addOutput(armEndXfoOutput) self.addOutput(armEndPosOutput) # Add Attribute I/O's self.addInput(debugInputAttr) self.addInput(bone1LenInputAttr) self.addInput(bone2LenInputAttr) self.addInput(fkikInputAttr) self.addInput(softIKInputAttr) self.addInput(softDistInputAttr) self.addInput(stretchInputAttr) self.addInput(stretchBlendInputAttr) self.addInput(rightSideInputAttr)
class FabriceHeadRig(FabriceHead): """Fabrice Head Component Rig""" def __init__(self, name='head', parent=None): Profiler.getInstance().push("Construct Head Rig Component:" + name) super(FabriceHeadRig, self).__init__(name, parent) # ========= # Controls # ========= # Head Aim self.headAimCtrlSpace = CtrlSpace('headAim', parent=self.ctrlCmpGrp) self.headAimCtrl = Control('headAim', parent=self.headAimCtrlSpace, shape="sphere") self.headAimCtrl.scalePoints(Vec3(0.35, 0.35, 0.35)) self.headAimCtrl.lockScale(x=True, y=True, z=True) self.headAimUpV = Locator('headAimUpV', parent=self.headAimCtrl) self.headAimUpV.setShapeVisibility(False) # Head self.headAim = Locator('headAim', parent=self.ctrlCmpGrp) self.headAim.setShapeVisibility(False) self.headCtrlSpace = CtrlSpace('head', parent=self.ctrlCmpGrp) self.headCtrl = Control('head', parent=self.headCtrlSpace, shape="circle") self.headCtrl.lockTranslation(x=True, y=True, z=True) self.headCtrl.lockScale(x=True, y=True, z=True) # Jaw self.jawCtrlSpace = CtrlSpace('jawCtrlSpace', parent=self.headCtrl) self.jawCtrl = Control('jaw', parent=self.jawCtrlSpace, shape="cube") self.jawCtrl.lockTranslation(x=True, y=True, z=True) self.jawCtrl.lockScale(x=True, y=True, z=True) self.jawCtrl.setColor("orange") # ========== # Deformers # ========== deformersLayer = self.getOrCreateLayer('deformers') defCmpGrp = ComponentGroup(self.getName(), self, parent=deformersLayer) self.addItem('defCmpGrp', self.defCmpGrp) headDef = Joint('head', parent=defCmpGrp) headDef.setComponent(self) jawDef = Joint('jaw', parent=defCmpGrp) jawDef.setComponent(self) # ============== # Constrain I/O # ============== self.headToAimConstraint = PoseConstraint('_'.join( [self.headCtrlSpace.getName(), 'To', self.headAim.getName()])) self.headToAimConstraint.setMaintainOffset(True) self.headToAimConstraint.addConstrainer(self.headAim) self.headCtrlSpace.addConstraint(self.headToAimConstraint) # Constraint inputs self.headAimInputConstraint = PoseConstraint('_'.join([ self.headAimCtrlSpace.getName(), 'To', self.headBaseInputTgt.getName() ])) self.headAimInputConstraint.setMaintainOffset(True) self.headAimInputConstraint.addConstrainer(self.headBaseInputTgt) self.headAimCtrlSpace.addConstraint(self.headAimInputConstraint) # # Constraint outputs self.headOutputConstraint = PoseConstraint('_'.join( [self.headOutputTgt.getName(), 'To', self.headCtrl.getName()])) self.headOutputConstraint.addConstrainer(self.headCtrl) self.headOutputTgt.addConstraint(self.headOutputConstraint) self.jawOutputConstraint = PoseConstraint('_'.join( [self.jawOutputTgt.getName(), 'To', self.jawCtrl.getName()])) self.jawOutputConstraint.addConstrainer(self.jawCtrl) self.jawOutputTgt.addConstraint(self.jawOutputConstraint) # ============== # Add Operators # ============== # Add Aim Canvas Op # ================= self.headAimCanvasOp = CanvasOperator( 'headAimCanvasOp', 'Kraken.Solvers.DirectionConstraintSolver') self.addOperator(self.headAimCanvasOp) # Add Att Inputs self.headAimCanvasOp.setInput('drawDebug', self.drawDebugInputAttr) self.headAimCanvasOp.setInput('rigScale', self.rigScaleInputAttr) # Add Xfo Inputs self.headAimCanvasOp.setInput('position', self.headBaseInputTgt) self.headAimCanvasOp.setInput('upVector', self.headAimUpV) self.headAimCanvasOp.setInput('atVector', self.headAimCtrl) # Add Xfo Outputs self.headAimCanvasOp.setOutput('constrainee', self.headAim) # Add Deformer KL Op # ================== self.deformersToOutputsKLOp = KLOperator('headDeformerKLOp', 'MultiPoseConstraintSolver', 'Kraken') self.addOperator(self.deformersToOutputsKLOp) # Add Att Inputs self.deformersToOutputsKLOp.setInput('drawDebug', self.drawDebugInputAttr) self.deformersToOutputsKLOp.setInput('rigScale', self.rigScaleInputAttr) # Add Xfo Outputs self.deformersToOutputsKLOp.setInput( 'constrainers', [self.headOutputTgt, self.jawOutputTgt]) # Add Xfo Outputs self.deformersToOutputsKLOp.setOutput('constrainees', [headDef, jawDef]) Profiler.getInstance().pop() def loadData(self, data=None): """Load a saved guide representation from persisted data. Arguments: data -- object, The JSON data object. Return: True if successful. """ super(FabriceHeadRig, self).loadData(data) headXfo = data['headXfo'] headCtrlCrvData = data['headCtrlCrvData'] jawPosition = data['jawPosition'] jawCtrlCrvData = data['jawCtrlCrvData'] self.headAimCtrlSpace.xfo.ori = headXfo.ori self.headAimCtrlSpace.xfo.tr = headXfo.tr.add(Vec3(0, 0, 4)) self.headAimCtrl.xfo = self.headAimCtrlSpace.xfo self.headAimUpV.xfo.ori = self.headAimCtrl.xfo.ori self.headAimUpV.xfo.tr = self.headAimCtrl.xfo.tr.add(Vec3(0, 3, 0)) self.headAim.xfo = headXfo self.headCtrlSpace.xfo = headXfo self.headCtrl.xfo = headXfo self.headCtrl.setCurveData(headCtrlCrvData) self.jawCtrlSpace.xfo.tr = jawPosition self.jawCtrl.xfo.tr = jawPosition self.jawCtrl.setCurveData(jawCtrlCrvData) # ============ # Set IO Xfos # ============ self.headBaseInputTgt.xfo = headXfo self.headOutputTgt.xfo = headXfo self.jawOutputTgt.xfo.tr = jawPosition # ==================== # Evaluate Splice Ops # ==================== # evaluate the constraint op so that all the joint transforms are updated. self.headAimCanvasOp.evaluate() self.deformersToOutputsKLOp.evaluate() # evaluate the constraints to ensure the outputs are now in the correct location. self.headToAimConstraint.evaluate() self.headAimInputConstraint.evaluate() self.headOutputConstraint.evaluate() self.jawOutputConstraint.evaluate()
class InsectLegComponentRig(InsectLegComponent): """Insect Leg Rig""" 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() def setNumControls(self, numControls): # Add new control spaces and controls 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' fkCtrlSpace = CtrlSpace(boneName, parent=parent) fkCtrl = Control(boneName, parent=fkCtrlSpace, shape="cube") fkCtrl.alignOnXAxis() fkCtrl.lockScale(x=True, y=True, z=True) fkCtrl.lockTranslation(x=True, y=True, z=True) self.fkCtrlSpaces.append(fkCtrlSpace) self.fkCtrls.append(fkCtrl) def setNumDeformers(self, numDeformers): # Add new deformers and outputs 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) for i in xrange(len(self.deformerJoints), numDeformers): name = 'bone' + str(i + 1).zfill(2) boneDef = Joint(name, parent=self.defCmpGrp) boneDef.setComponent(self) self.deformerJoints.append(boneDef) return True def calculateUpVXfo(self, boneXfos, endXfo): """Calculates the transform for the UpV control. Args: boneXfos (list): Bone transforms. endXfo (Xfo): Transform for the end of the chain. Returns: Xfo: Up Vector transform. """ # Calculate FW toFirst = boneXfos[1].tr.subtract(boneXfos[0].tr).unit() toTip = endXfo.tr.subtract(boneXfos[0].tr).unit() fw = toTip.cross(toFirst).unit() chainNormal = fw.cross(toTip).unit() chainZAxis = toTip.cross(chainNormal).unit() chainXfo = Xfo() chainXfo.setFromVectors(toTip.unit(), chainNormal, chainZAxis, boneXfos[0].tr) rootToTip = endXfo.tr.subtract(boneXfos[0].tr).length() upVXfo = Xfo() upVXfo.tr = chainXfo.transformVector( Vec3(rootToTip / 2.0, rootToTip / 2.0, 0.0)) return upVXfo 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(InsectLegComponentRig, self).loadData(data) boneXfos = data['boneXfos'] boneLengths = data['boneLengths'] numJoints = data['numJoints'] endXfo = data['endXfo'] # Add extra controls and outputs self.setNumControls(numJoints) self.setNumDeformers(numJoints) # Scale controls based on bone lengths for i, each in enumerate(self.fkCtrlSpaces): self.fkCtrlSpaces[i].xfo = boneXfos[i] self.fkCtrls[i].xfo = boneXfos[i] self.fkCtrls[i].scalePoints(Vec3(boneLengths[i], 1.75, 1.75)) self.chainBase.xfo = boneXfos[0] self.legIKCtrlSpace.xfo = endXfo self.legIKCtrl.xfo = endXfo upVXfo = self.calculateUpVXfo(boneXfos, endXfo) self.legUpVCtrlSpace.xfo = upVXfo self.legUpVCtrl.xfo = upVXfo # Set max on the rootIndex attribute self.rootIndexInputAttr.setMax(len(boneXfos)) # ============ # Set IO Xfos # ============ self.rootInputTgt.xfo = boneXfos[0] for i in xrange(len(boneLengths)): self.boneOutputsTgt[i].xfo = boneXfos[i] self.legEndXfoOutputTgt.xfo = endXfo self.legEndPosOutputTgt.xfo = endXfo # ============= # Set IO Attrs # ============= tipBoneLen = boneLengths[len(boneLengths) - 1] self.tipBoneLenInputAttr.setMax(tipBoneLen * 2.0) self.tipBoneLenInputAttr.setValue(tipBoneLen) # ==================== # Evaluate Splice Ops # ==================== # evaluate the nbone op so that all the output transforms are updated. self.nBoneSolverKLOp.evaluate() self.outputsToDeformersKLOp.evaluate()
class mjEyelidComponentRig(mjEyelidComponent): """Eyelid Component Rig""" 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() def setNumUpDeformers(self, numUpDeformers): # Add Up Deformers and Outputs for i in xrange(len(self.eyelidUpOutputs), numUpDeformers): name = 'Lid_Up_' + str(i + 1).zfill(2) lidUpOutputs = ComponentOutput(name, parent=self.outputHrcGrp) self.eyelidUpOutputs.append(lidUpOutputs) for i in xrange(len(self.eyelidUpDef), numUpDeformers): name = 'Lid_Up_' + str(i + 1).zfill(2) lidUpDef = Joint(name, parent=self.defCmpGrp) lidUpDef.setComponent(self) self.eyelidUpDef.append(lidUpDef) return True def setNumLowDeformers(self, numLowDeformers): # Add Low Deformers and Outputs for i in xrange(len(self.eyelidLowOutputs), numLowDeformers): name = 'Lid_Low_' + str(i + 1).zfill(2) lidLowOutputs = ComponentOutput(name, parent=self.outputHrcGrp) self.eyelidLowOutputs.append(lidLowOutputs) for i in xrange(len(self.eyelidLowDef), numLowDeformers): name = 'Lid_Low_' + str(i + 1).zfill(2) lidLowDef = Joint(name, parent=self.defCmpGrp) lidLowDef.setComponent(self) self.eyelidLowDef.append(lidLowDef) return True def loadData(self, data=None): super(mjEyelidComponentRig, self).loadData(data) # Set CtrlSpace Xfos self.eyelidCtrlSpace.xfo = data['eyeballXfo'] self.eyeballLocator.xfo = data['eyeballXfo'] self.eyelidUpVLocator.xfo = data['eyelidUpVXfo'] self.lidMedialLocator.xfo = data['lidMedialXfo'] self.lidLateralLocator.xfo = data['lidLateralXfo'] self.lidUpCtrlSpace.xfo = data['lidUpXfo'] self.lidUpCtrl.xfo = data['lidUpXfo'] self.lipUpMedialLocator.xfo = data['lidUpMedialXfo'] self.lipUpLateralLocator.xfo = data['lidUpLateralXfo'] self.lidLowCtrlSpace.xfo = data['lidLowXfo'] self.lidLowCtrl.xfo = data['lidLowXfo'] self.lidLowMedialLocator.xfo = data['lidLowMedialXfo'] self.lidLowLateralLocator.xfo = data['lidLowLateralXfo'] # Update number of deformers and outputs self.setNumUpDeformers(data['numUpDeformers']) self.setNumLowDeformers(data['numLowDeformers']) # Set Attributes self.upMedialFactorInputAttr.setValue(data['lidUpMedialBlink']) self.upLateralFactorInputAttr.setValue(data['lidUpLateralBlink']) self.numUpDeformersInputAttr.setValue(data['numUpDeformers']) self.lowMedialFactorInputAttr.setValue(data['lidLowMedialBlink']) self.lowLateralFactorInputAttr.setValue(data['lidLowLateralBlink']) self.numLowDeformersInputAttr.setValue(data['numLowDeformers']) self.lidUp_MedialBlinkInputAttr.setValue(data['lidUpMedialBlink']) self.lidUp_LateralBlinkInputAttr.setValue(data['lidUpLateralBlink']) self.lidLow_MedialBlinkInputAttr.setValue(data['lidLowMedialBlink']) self.lidLow_LateralBlinkInputAttr.setValue(data['lidLowLateralBlink']) # Set I/O Xfos self.headInputTgt.xfo = data['eyeballXfo'] self.eyeballInputTgt.xfo = data['eyeballXfo'] self.eyelidUpOutputTgt = self.eyelidUpDef self.eyelidLowOutputTgt = self.eyelidLowDef # Evaluate Constraints self.headInputConstraint.evaluate() self.eyeballInputConstraint.evaluate() # Evaluate Operators self.lidUpCanvasOp.evaluate() self.lidLowCanvasOp.evaluate() self.outputsToDeformersKLOp.evaluate()
def __init__(self, name, parent=None, location='M'): super(FootComponent, self).__init__(name, parent, location) # ========= # Controls # ========= # Setup component attributes defaultAttrGroup = self.getAttributeGroupByIndex(0) defaultAttrGroup.addAttribute(BoolAttribute("toggleDebugging", True)) # Default values if location == 'R': ctrlColor = "red" footPosition = Vec3(-7.1886, 12.2819, 0.4906) footUpV = Vec3(-1.7454, 0.1922, -1.7397) footEndPosition = Vec3(-2.0939, 0.4288, 0.0944) else: ctrlColor = "greenBright" footPosition = Vec3(7.1886, 12.2819, 0.4906) footUpV = Vec3(1.7454, 0.1922, -1.7397) footEndPosition = Vec3(2.0939, 0.4288, 0.0944) # Calculate Clavicle Xfo rootToEnd = footEndPosition.subtract(footPosition).unit() rootToUpV = footUpV.subtract(footPosition).unit() bone1ZAxis = rootToEnd.cross(rootToUpV).unit() bone1Normal = rootToEnd.cross(bone1ZAxis).unit() footXfo = Xfo() if location == "R": footQuat = Quat(Vec3(0.5695, -0.6377, 0.4190), 0.3053) footPos = Vec3(-1.841, 1.1516, -1.237) else: footQuat = Quat(Vec3(0.6377, -0.5695, 0.3053), 0.4190) footPos = Vec3(1.841, 1.1516, -1.237) footXfo.rot = footQuat.clone() footXfo.tr.copy(footPos) # Add Controls footCtrlSrtBuffer = SrtBuffer('foot', parent=self) footCtrlSrtBuffer.xfo.copy(footXfo) footCtrl = CubeControl('foot', parent=footCtrlSrtBuffer) footCtrl.alignOnXAxis() footCtrl.scalePoints(Vec3(2.5, 1.5, 0.75)) footCtrl.xfo.copy(footCtrlSrtBuffer.xfo) footCtrl.setColor(ctrlColor) # Rig Ref objects footRefSrt = Locator('footRef', parent=self) footRefSrt.xfo.copy(footCtrlSrtBuffer.xfo) # Add Component Params to IK control footDebugInputAttr = BoolAttribute('debug', True) footLinkToWorldInputAttr = FloatAttribute('linkToWorld', 1.0, 0.0, 1.0) footSettingsAttrGrp = AttributeGroup("DisplayInfo_HandSettings") footCtrl.addAttributeGroup(footSettingsAttrGrp) footSettingsAttrGrp.addAttribute(footDebugInputAttr) footSettingsAttrGrp.addAttribute(footLinkToWorldInputAttr) # ========== # Deformers # ========== container = self.getParent().getParent() deformersLayer = container.getChildByName('deformers') footDef = Joint('foot') footDef.setComponent(self) deformersLayer.addChild(footDef) # ===================== # Create Component I/O # ===================== # Setup Component Xfo I/O's legEndXfoInput = Locator('legEndXfo') legEndXfoInput.xfo.copy(footCtrlSrtBuffer.xfo) legEndPosInput = Locator('legEndPos') legEndPosInput.xfo.copy(footCtrlSrtBuffer.xfo) footEndOutput = Locator('handEnd') footEndOutput.xfo.copy(footCtrlSrtBuffer.xfo) footOutput = Locator('hand') footOutput.xfo.copy(footCtrlSrtBuffer.xfo) # Setup componnent Attribute I/O's debugInputAttr = BoolAttribute('debug', True) rightSideInputAttr = BoolAttribute('rightSide', location is 'R') linkToWorldInputAttr = FloatAttribute('linkToWorld', 0.0, 0.0, 1.0) # Connect attrs to control attrs debugInputAttr.connect(footDebugInputAttr) linkToWorldInputAttr.connect(footLinkToWorldInputAttr) # ============== # Constrain I/O # ============== # Constraint inputs # Constraint outputs handConstraint = PoseConstraint('_'.join([footOutput.getName(), 'To', footCtrl.getName()])) handConstraint.addConstrainer(footCtrl) footOutput.addConstraint(handConstraint) handEndConstraint = PoseConstraint('_'.join([footEndOutput.getName(), 'To', footCtrl.getName()])) handEndConstraint.addConstrainer(footCtrl) footEndOutput.addConstraint(handEndConstraint) # ================== # Add Component I/O # ================== # Add Xfo I/O's self.addInput(legEndXfoInput) self.addInput(legEndPosInput) self.addOutput(footOutput) self.addOutput(footEndOutput) # Add Attribute I/O's self.addInput(debugInputAttr) self.addInput(rightSideInputAttr) self.addInput(linkToWorldInputAttr)
class TentacleComponentRig(TentacleComponent): """Insect Leg Rig""" 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() def setNumControls(self, numControls): # Add new control spaces and controls 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' fkCtrlSpace = CtrlSpace(boneName, parent=parent) fkCtrl = Control(boneName, parent=fkCtrlSpace, shape="cube") fkCtrl.alignOnXAxis() fkCtrl.lockScale(x=True, y=True, z=True) fkCtrl.lockTranslation(x=True, y=True, z=True) self.fkCtrlSpaces.append(fkCtrlSpace) self.fkCtrls.append(fkCtrl) def setNumDeformers(self, numDeformers): # Add new deformers and outputs for i in xrange(len(self.boneOutputsTgt), numDeformers): name = 'bone' + str(i + 1).zfill(2) tentacleOutput = ComponentOutput(name, parent=self.outputHrcGrp) self.boneOutputsTgt.append(tentacleOutput) for i in xrange(len(self.deformerJoints), numDeformers): name = 'bone' + str(i + 1).zfill(2) boneDef = Joint(name, parent=self.defCmpGrp) boneDef.setComponent(self) self.deformerJoints.append(boneDef) return True 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(TentacleComponentRig, self).loadData(data) boneXfos = data['boneXfos'] boneLengths = data['boneLengths'] numJoints = data['numJoints'] endXfo = data['endXfo'] # Add extra controls and outputs self.setNumControls(numJoints) self.setNumDeformers(numJoints) # Scale controls based on bone lengths for i, each in enumerate(self.fkCtrlSpaces): self.fkCtrlSpaces[i].xfo = boneXfos[i] self.fkCtrls[i].xfo = boneXfos[i] self.fkCtrls[i].scalePoints( Vec3( Vec3(boneLengths[i], boneLengths[i] * 0.45, boneLengths[i] * 0.45))) self.chainBase.xfo = boneXfos[0] self.tentacleIKCtrlSpace.xfo = endXfo self.tentacleIKCtrl.xfo = endXfo # ============ # Set IO Xfos # ============ self.rootInputTgt.xfo = boneXfos[0] for i in xrange(len(boneLengths)): self.boneOutputsTgt[i].xfo = boneXfos[i] self.tentacleEndXfoOutputTgt.xfo = endXfo # ============= # Set IO Attrs # ============= tipBoneLen = boneLengths[len(boneLengths) - 1] self.tipBoneLenInputAttr.setMax(tipBoneLen * 2.0) self.tipBoneLenInputAttr.setValue(tipBoneLen) # ==================== # Evaluate Splice Ops # ==================== # evaluate the nbone op so that all the output transforms are updated. self.tentacleSolverKLOp.evaluate() self.outputsToDeformersKLOp.evaluate()
class FabriceHeadRig(FabriceHead): """Fabrice Head Component Rig""" def __init__(self, name='head', parent=None): Profiler.getInstance().push("Construct Head Rig Component:" + name) super(FabriceHeadRig, self).__init__(name, parent) # ========= # Controls # ========= # Head Aim self.headAimCtrlSpace = CtrlSpace('headAim', parent=self.ctrlCmpGrp) self.headAimCtrl = Control('headAim', parent=self.headAimCtrlSpace, shape="sphere") self.headAimCtrl.scalePoints(Vec3(0.35, 0.35, 0.35)) self.headAimCtrl.lockScale(x=True, y=True, z=True) self.headAimUpV = Locator('headAimUpV', parent=self.headAimCtrl) self.headAimUpV.setShapeVisibility(False) # Head self.headAim = Locator('headAim', parent=self.ctrlCmpGrp) self.headAim.setShapeVisibility(False) self.headCtrlSpace = CtrlSpace('head', parent=self.ctrlCmpGrp) self.headCtrl = Control('head', parent=self.headCtrlSpace, shape="circle") self.headCtrl.lockTranslation(x=True, y=True, z=True) self.headCtrl.lockScale(x=True, y=True, z=True) # Jaw self.jawCtrlSpace = CtrlSpace('jawCtrlSpace', parent=self.headCtrl) self.jawCtrl = Control('jaw', parent=self.jawCtrlSpace, shape="cube") self.jawCtrl.lockTranslation(x=True, y=True, z=True) self.jawCtrl.lockScale(x=True, y=True, z=True) self.jawCtrl.setColor("orange") # ========== # Deformers # ========== deformersLayer = self.getOrCreateLayer('deformers') defCmpGrp = ComponentGroup(self.getName(), self, parent=deformersLayer) self.addItem('defCmpGrp', self.defCmpGrp) headDef = Joint('head', parent=defCmpGrp) headDef.setComponent(self) jawDef = Joint('jaw', parent=defCmpGrp) jawDef.setComponent(self) # ============== # Constrain I/O # ============== self.headToAimConstraint = PoseConstraint('_'.join([self.headCtrlSpace.getName(), 'To', self.headAim.getName()])) self.headToAimConstraint.setMaintainOffset(True) self.headToAimConstraint.addConstrainer(self.headAim) self.headCtrlSpace.addConstraint(self.headToAimConstraint) # Constraint inputs self.headAimInputConstraint = PoseConstraint('_'.join([self.headAimCtrlSpace.getName(), 'To', self.headBaseInputTgt.getName()])) self.headAimInputConstraint.setMaintainOffset(True) self.headAimInputConstraint.addConstrainer(self.headBaseInputTgt) self.headAimCtrlSpace.addConstraint(self.headAimInputConstraint) # # Constraint outputs self.headOutputConstraint = PoseConstraint('_'.join([self.headOutputTgt.getName(), 'To', self.headCtrl.getName()])) self.headOutputConstraint.addConstrainer(self.headCtrl) self.headOutputTgt.addConstraint(self.headOutputConstraint) self.jawOutputConstraint = PoseConstraint('_'.join([self.jawOutputTgt.getName(), 'To', self.jawCtrl.getName()])) self.jawOutputConstraint.addConstrainer(self.jawCtrl) self.jawOutputTgt.addConstraint(self.jawOutputConstraint) # ============== # Add Operators # ============== # Add Aim Canvas Op # ================= self.headAimCanvasOp = CanvasOperator('headAimCanvasOp', 'Kraken.Solvers.DirectionConstraintSolver') self.addOperator(self.headAimCanvasOp) # Add Att Inputs self.headAimCanvasOp.setInput('drawDebug', self.drawDebugInputAttr) self.headAimCanvasOp.setInput('rigScale', self.rigScaleInputAttr) # Add Xfo Inputs self.headAimCanvasOp.setInput('position', self.headBaseInputTgt) self.headAimCanvasOp.setInput('upVector', self.headAimUpV) self.headAimCanvasOp.setInput('atVector', self.headAimCtrl) # Add Xfo Outputs self.headAimCanvasOp.setOutput('constrainee', self.headAim) # Add Deformer KL Op # ================== self.deformersToOutputsKLOp = KLOperator('headDeformerKLOp', 'MultiPoseConstraintSolver', 'Kraken') self.addOperator(self.deformersToOutputsKLOp) # Add Att Inputs self.deformersToOutputsKLOp.setInput('drawDebug', self.drawDebugInputAttr) self.deformersToOutputsKLOp.setInput('rigScale', self.rigScaleInputAttr) # Add Xfo Outputs self.deformersToOutputsKLOp.setInput('constrainers', [self.headOutputTgt, self.jawOutputTgt]) # Add Xfo Outputs self.deformersToOutputsKLOp.setOutput('constrainees', [headDef, jawDef]) Profiler.getInstance().pop() def loadData(self, data=None): """Load a saved guide representation from persisted data. Arguments: data -- object, The JSON data object. Return: True if successful. """ super(FabriceHeadRig, self).loadData( data ) headXfo = data['headXfo'] headCtrlCrvData = data['headCtrlCrvData'] jawPosition = data['jawPosition'] jawCtrlCrvData = data['jawCtrlCrvData'] self.headAimCtrlSpace.xfo.ori = headXfo.ori self.headAimCtrlSpace.xfo.tr = headXfo.tr.add(Vec3(0, 0, 4)) self.headAimCtrl.xfo = self.headAimCtrlSpace.xfo self.headAimUpV.xfo.ori = self.headAimCtrl.xfo.ori self.headAimUpV.xfo.tr = self.headAimCtrl.xfo.tr.add(Vec3(0, 3, 0)) self.headAim.xfo = headXfo self.headCtrlSpace.xfo = headXfo self.headCtrl.xfo = headXfo self.headCtrl.setCurveData(headCtrlCrvData) self.jawCtrlSpace.xfo.tr = jawPosition self.jawCtrl.xfo.tr = jawPosition self.jawCtrl.setCurveData(jawCtrlCrvData) # ============ # Set IO Xfos # ============ self.headBaseInputTgt.xfo = headXfo self.headOutputTgt.xfo = headXfo self.jawOutputTgt.xfo.tr = jawPosition # ==================== # Evaluate Splice Ops # ==================== # evaluate the constraint op so that all the joint transforms are updated. self.headAimCanvasOp.evaluate() self.deformersToOutputsKLOp.evaluate() # evaluate the constraints to ensure the outputs are now in the correct location. self.headToAimConstraint.evaluate() self.headAimInputConstraint.evaluate() self.headOutputConstraint.evaluate() self.jawOutputConstraint.evaluate()
def __init__(self, name, parent=None, location='M'): super(NeckComponent, self).__init__(name, parent, location) # Setup component attributes defaultAttrGroup = self.getAttributeGroupByIndex(0) defaultAttrGroup.addAttribute(BoolAttribute("toggleDebugging", True)) # Default values neckPosition = Vec3(0.0, 16.5572, -0.6915) neckUpV = Vec3() neckUpV.copy(neckPosition) neckUpV = neckUpV.add(Vec3(0.0, 0.0, -1.0)).unit() neckEndPosition = Vec3(0.0, 17.4756, -0.421) # Calculate Clavicle Xfo rootToEnd = neckEndPosition.subtract(neckPosition).unit() rootToUpV = neckUpV.subtract(neckPosition).unit() bone1ZAxis = rootToUpV.cross(rootToEnd).unit() bone1Normal = bone1ZAxis.cross(rootToEnd).unit() neckXfo = Xfo() neckXfo.setFromVectors(rootToEnd, bone1Normal, bone1ZAxis, neckPosition) # Add Guide Controls neckCtrlSrtBuffer = SrtBuffer('neck', parent=self) neckCtrlSrtBuffer.xfo.copy(neckXfo) neckCtrl = PinControl('neck', parent=neckCtrlSrtBuffer) neckCtrl.scalePoints(Vec3(1.25, 1.25, 1.25)) neckCtrl.translatePoints(Vec3(0, 0, -0.5)) neckCtrl.rotatePoints(90, 0, 90) neckCtrl.xfo.copy(neckXfo) neckCtrl.setColor("orange") # ========== # Deformers # ========== container = self.getParent().getParent() deformersLayer = container.getChildByName('deformers') neckDef = Joint('neck', parent=deformersLayer) neckDef.setComponent(self) # ===================== # Create Component I/O # ===================== # Setup Component Xfo I/O's neckEndInput = Locator('neckBase') neckEndInput.xfo.copy(neckXfo) neckEndOutput = Locator('neckEnd') neckEndOutput.xfo.copy(neckXfo) neckOutput = Locator('neck') neckOutput.xfo.copy(neckXfo) # Setup componnent Attribute I/O's debugInputAttr = BoolAttribute('debug', True) rightSideInputAttr = BoolAttribute('rightSide', location is 'R') # ============== # Constrain I/O # ============== # Constraint inputs clavicleInputConstraint = PoseConstraint('_'.join([neckCtrl.getName(), 'To', neckEndInput.getName()])) clavicleInputConstraint.setMaintainOffset(True) clavicleInputConstraint.addConstrainer(neckEndInput) neckCtrlSrtBuffer.addConstraint(clavicleInputConstraint) # Constraint outputs neckEndConstraint = PoseConstraint('_'.join([neckEndOutput.getName(), 'To', neckCtrl.getName()])) neckEndConstraint.addConstrainer(neckCtrl) neckEndOutput.addConstraint(neckEndConstraint) # ================== # Add Component I/O # ================== # Add Xfo I/O's self.addInput(neckEndInput) self.addOutput(neckEndOutput) self.addOutput(neckOutput) # Add Attribute I/O's self.addInput(debugInputAttr) self.addInput(rightSideInputAttr)
class InsectLegComponentRig(InsectLegComponent): """Insect Leg Rig""" 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.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 Splice Ops # =============== # Add Splice Op self.nBoneSolverSpliceOp = SpliceOperator('legSpliceOp', 'NBoneIKSolver', 'Kraken') self.addOperator(self.nBoneSolverSpliceOp) # # Add Att Inputs self.nBoneSolverSpliceOp.setInput('drawDebug', self.drawDebugInputAttr) self.nBoneSolverSpliceOp.setInput('rigScale', self.rigScaleInputAttr) self.nBoneSolverSpliceOp.setInput('useInitPose', legUseInitPoseInputAttr) self.nBoneSolverSpliceOp.setInput('ikblend', legFkikInputAttr) self.nBoneSolverSpliceOp.setInput('rootIndex', self.rootIndexInputAttr) self.nBoneSolverSpliceOp.setInput('tipBoneLen', self.tipBoneLenInputAttr) # Add Xfo Inputs self.nBoneSolverSpliceOp.setInput('chainBase', self.chainBase) self.nBoneSolverSpliceOp.setInput('ikgoal', self.legIKCtrl) self.nBoneSolverSpliceOp.setInput('upVector', self.legUpVCtrl) self.nBoneSolverSpliceOp.setInput('fkcontrols', self.fkCtrls) # Add Xfo Outputs self.nBoneSolverSpliceOp.setOutput('pose', self.boneOutputsTgt) self.nBoneSolverSpliceOp.setOutput('legEnd', self.legEndPosOutputTgt) # Add Deformer Splice Op self.outputsToDeformersSpliceOp = SpliceOperator('insectLegDeformerSpliceOp', '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.boneOutputsTgt) # Add Xfo Outputs self.outputsToDeformersSpliceOp.setOutput('constrainees', self.deformerJoints) Profiler.getInstance().pop() def setNumControls(self, numControls): # Add new control spaces and controls 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' fkCtrlSpace = CtrlSpace(boneName, parent=parent) fkCtrl = Control(boneName, parent=fkCtrlSpace, shape="cube") fkCtrl.alignOnXAxis() fkCtrl.lockScale(x=True, y=True, z=True) fkCtrl.lockTranslation(x=True, y=True, z=True) self.fkCtrlSpaces.append(fkCtrlSpace) self.fkCtrls.append(fkCtrl) def setNumDeformers(self, numDeformers): # Add new deformers and outputs 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) for i in xrange(len(self.deformerJoints), numDeformers): name = 'bone' + str(i + 1).zfill(2) boneDef = Joint(name, parent=self.defCmpGrp) boneDef.setComponent(self) self.deformerJoints.append(boneDef) return True def calculateUpVXfo(self, boneXfos, endXfo): """Calculates the transform for the UpV control. Args: boneXfos (list): Bone transforms. endXfo (Xfo): Transform for the end of the chain. Returns: Xfo: Up Vector transform. """ # Calculate FW toFirst = boneXfos[1].tr.subtract(boneXfos[0].tr).unit() toTip = endXfo.tr.subtract(boneXfos[0].tr).unit() fw = toTip.cross(toFirst).unit() chainNormal = fw.cross(toTip).unit() chainZAxis = toTip.cross(chainNormal).unit() chainXfo = Xfo() chainXfo.setFromVectors(toTip.unit(), chainNormal, chainZAxis, boneXfos[0].tr) rootToTip = endXfo.tr.subtract(boneXfos[0].tr).length() upVXfo = Xfo() upVXfo.tr = chainXfo.transformVector(Vec3(rootToTip / 2.0, rootToTip / 2.0, 0.0)) return upVXfo 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(InsectLegComponentRig, self).loadData( data ) boneXfos = data['boneXfos'] boneLengths = data['boneLengths'] numJoints = data['numJoints'] endXfo = data['endXfo'] # Add extra controls and outputs self.setNumControls(numJoints) self.setNumDeformers(numJoints) # Scale controls based on bone lengths for i, each in enumerate(self.fkCtrlSpaces): self.fkCtrlSpaces[i].xfo = boneXfos[i] self.fkCtrls[i].xfo = boneXfos[i] self.fkCtrls[i].scalePoints(Vec3(boneLengths[i], 1.75, 1.75)) self.chainBase.xfo = boneXfos[0] self.legIKCtrlSpace.xfo = endXfo self.legIKCtrl.xfo = endXfo upVXfo = self.calculateUpVXfo(boneXfos, endXfo) self.legUpVCtrlSpace.xfo = upVXfo self.legUpVCtrl.xfo = upVXfo # Set max on the rootIndex attribute self.rootIndexInputAttr.setMax(len(boneXfos)) # ============ # Set IO Xfos # ============ self.rootInputTgt.xfo = boneXfos[0] for i in xrange(len(boneLengths)): self.boneOutputsTgt[i].xfo = boneXfos[i] self.legEndXfoOutputTgt.xfo = endXfo self.legEndPosOutputTgt.xfo = endXfo # ============= # Set IO Attrs # ============= tipBoneLen = boneLengths[len(boneLengths) - 1] self.tipBoneLenInputAttr.setMax(tipBoneLen * 2.0) self.tipBoneLenInputAttr.setValue(tipBoneLen) # ==================== # Evaluate Splice Ops # ==================== # evaluate the nbone op so that all the output transforms are updated. self.nBoneSolverSpliceOp.evaluate() self.outputsToDeformersSpliceOp.evaluate()
class TentacleComponentRig(TentacleComponent): """Insect Leg Rig""" 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.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 Splice Ops # =============== # Add Splice Op self.tentacleSolverKLOp = KLOperator('tentacleKLOp', '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 Splice Op self.outputsToDeformersKLOp = KLOperator('TentacleDeformerKLOp', '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() def setNumControls(self, numControls): # Add new control spaces and controls 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' fkCtrlSpace = CtrlSpace(boneName, parent=parent) fkCtrl = Control(boneName, parent=fkCtrlSpace, shape="cube") fkCtrl.alignOnXAxis() fkCtrl.lockScale(x=True, y=True, z=True) fkCtrl.lockTranslation(x=True, y=True, z=True) self.fkCtrlSpaces.append(fkCtrlSpace) self.fkCtrls.append(fkCtrl) def setNumDeformers(self, numDeformers): # Add new deformers and outputs for i in xrange(len(self.boneOutputsTgt), numDeformers): name = 'bone' + str(i + 1).zfill(2) tentacleOutput = ComponentOutput(name, parent=self.outputHrcGrp) self.boneOutputsTgt.append(tentacleOutput) for i in xrange(len(self.deformerJoints), numDeformers): name = 'bone' + str(i + 1).zfill(2) boneDef = Joint(name, parent=self.defCmpGrp) boneDef.setComponent(self) self.deformerJoints.append(boneDef) return True 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(TentacleComponentRig, self).loadData( data ) boneXfos = data['boneXfos'] boneLengths = data['boneLengths'] numJoints = data['numJoints'] endXfo = data['endXfo'] # Add extra controls and outputs self.setNumControls(numJoints) self.setNumDeformers(numJoints) # Scale controls based on bone lengths for i, each in enumerate(self.fkCtrlSpaces): self.fkCtrlSpaces[i].xfo = boneXfos[i] self.fkCtrls[i].xfo = boneXfos[i] self.fkCtrls[i].scalePoints(Vec3(Vec3(boneLengths[i], boneLengths[i] * 0.45, boneLengths[i] * 0.45))) self.chainBase.xfo = boneXfos[0] self.tentacleIKCtrlSpace.xfo = endXfo self.tentacleIKCtrl.xfo = endXfo # ============ # Set IO Xfos # ============ self.rootInputTgt.xfo = boneXfos[0] for i in xrange(len(boneLengths)): self.boneOutputsTgt[i].xfo = boneXfos[i] self.tentacleEndXfoOutputTgt.xfo = endXfo # ============= # Set IO Attrs # ============= tipBoneLen = boneLengths[len(boneLengths) - 1] self.tipBoneLenInputAttr.setMax(tipBoneLen * 2.0) self.tipBoneLenInputAttr.setValue(tipBoneLen) # ==================== # Evaluate Splice Ops # ==================== # evaluate the nbone op so that all the output transforms are updated. self.tentacleSolverKLOp.evaluate() self.outputsToDeformersKLOp.evaluate()
def __init__(self, name, parent=None, location='M'): super(ClavicleComponent, self).__init__(name, parent, location) # ========= # Controls # ========= # Setup component attributes defaultAttrGroup = self.getAttributeGroupByIndex(0) defaultAttrGroup.addAttribute(BoolAttribute("toggleDebugging", True)) # Default values if location == 'R': ctrlColor = "red" claviclePosition = Vec3(-0.1322, 15.403, -0.5723) clavicleUpV = Vec3() clavicleUpV.copy(claviclePosition) clavicleUpV = clavicleUpV.add(Vec3(0.0, 1.0, 0.0)).unit() clavicleEndPosition = Vec3(-2.27, 15.295, -0.753) else: ctrlColor = "greenBright" claviclePosition = Vec3(0.1322, 15.403, -0.5723) clavicleUpV = Vec3() clavicleUpV.copy(claviclePosition) clavicleUpV = clavicleUpV.add(Vec3(0.0, 1.0, 0.0)).unit() clavicleEndPosition = Vec3(2.27, 15.295, -0.753) # Calculate Clavicle Xfo rootToEnd = clavicleEndPosition.subtract(claviclePosition).unit() rootToUpV = clavicleUpV.subtract(claviclePosition).unit() bone1ZAxis = rootToUpV.cross(rootToEnd).unit() bone1Normal = bone1ZAxis.cross(rootToEnd).unit() clavicleXfo = Xfo() clavicleXfo.setFromVectors(rootToEnd, bone1Normal, bone1ZAxis, claviclePosition) # Add Controls clavicleCtrl = CubeControl('clavicle', parent=self) clavicleCtrl.alignOnXAxis() clavicleLen = claviclePosition.subtract(clavicleEndPosition).length() clavicleCtrl.scalePoints(Vec3(clavicleLen, 0.75, 0.75)) if location == "R": clavicleCtrl.translatePoints(Vec3(0.0, 0.0, -1.0)) else: clavicleCtrl.translatePoints(Vec3(0.0, 0.0, 1.0)) clavicleCtrl.xfo.copy(clavicleXfo) clavicleCtrl.setColor(ctrlColor) clavicleCtrlSrtBuffer = SrtBuffer('clavicle', parent=self) clavicleCtrlSrtBuffer.xfo.copy(clavicleCtrl.xfo) clavicleCtrlSrtBuffer.addChild(clavicleCtrl) # ========== # Deformers # ========== container = self.getParent().getParent() deformersLayer = container.getChildByName('deformers') clavicleDef = Joint('clavicle') clavicleDef.setComponent(self) deformersLayer.addChild(clavicleDef) # ===================== # Create Component I/O # ===================== # Setup Component Xfo I/O's spineEndInput = Locator('spineEnd') spineEndInput.xfo.copy(clavicleXfo) clavicleEndOutput = Locator('clavicleEnd') clavicleEndOutput.xfo.copy(clavicleXfo) clavicleOutput = Locator('clavicle') clavicleOutput.xfo.copy(clavicleXfo) # Setup componnent Attribute I/O's debugInputAttr = BoolAttribute('debug', True) rightSideInputAttr = BoolAttribute('rightSide', location is 'R') armFollowBodyOutputAttr = FloatAttribute('followBody', 0.0, 0.0, 1.0) # ============== # Constrain I/O # ============== # Constraint inputs clavicleInputConstraint = PoseConstraint('_'.join([clavicleCtrl.getName(), 'To', spineEndInput.getName()])) clavicleInputConstraint.setMaintainOffset(True) clavicleInputConstraint.addConstrainer(spineEndInput) clavicleCtrlSrtBuffer.addConstraint(clavicleInputConstraint) # Constraint outputs clavicleConstraint = PoseConstraint('_'.join([clavicleOutput.getName(), 'To', clavicleCtrl.getName()])) clavicleConstraint.addConstrainer(clavicleCtrl) clavicleOutput.addConstraint(clavicleConstraint) clavicleEndConstraint = PoseConstraint('_'.join([clavicleEndOutput.getName(), 'To', clavicleCtrl.getName()])) clavicleEndConstraint.addConstrainer(clavicleCtrl) clavicleEndOutput.addConstraint(clavicleEndConstraint) # ================== # Add Component I/O # ================== # Add Xfo I/O's self.addInput(spineEndInput) self.addOutput(clavicleEndOutput) self.addOutput(clavicleOutput) # Add Attribute I/O's self.addInput(debugInputAttr) self.addInput(rightSideInputAttr) self.addOutput(armFollowBodyOutputAttr)
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()
def __init__(self, name, parent=None, location='M'): super(HandComponent, self).__init__(name, parent, location) # ========= # Controls # ========= # Setup component attributes defaultAttrGroup = self.getAttributeGroupByIndex(0) defaultAttrGroup.addAttribute(BoolAttribute("toggleDebugging", True)) # Default values if location == 'R': ctrlColor = "red" handPosition = Vec3(-7.1886, 12.2819, 0.4906) handUpV = Vec3(-7.7463, 13.1746, 0.4477) handEndPosition = Vec3(-7.945, 11.8321, 0.9655) else: ctrlColor = "greenBright" handPosition = Vec3(7.1886, 12.2819, 0.4906) handUpV = Vec3(7.7463, 13.1746, 0.4477) handEndPosition = Vec3(7.945, 11.8321, 0.9655) # Calculate Clavicle Xfo rootToEnd = handEndPosition.subtract(handPosition).unit() rootToUpV = handUpV.subtract(handPosition).unit() bone1ZAxis = rootToEnd.cross(rootToUpV).unit() bone1Normal = rootToEnd.cross(bone1ZAxis).unit() handXfo = Xfo() if location == "R": handQuat = Quat(Vec3(-0.2301, -0.0865, -0.9331), 0.2623) handPos = Vec3(-7.1886, 12.2819, 0.4906) else: handQuat = Quat(Vec3(-0.0865, -0.2301, -0.2623), 0.9331) handPos = Vec3(7.1886, 12.2819, 0.4906) handXfo.rot = handQuat.clone() handXfo.tr.copy(handPos) # Add Controls handCtrlSrtBuffer = SrtBuffer('hand', parent=self) handCtrlSrtBuffer.xfo.copy(handXfo) handCtrl = CubeControl('hand', parent=handCtrlSrtBuffer) handCtrl.alignOnXAxis() handCtrl.scalePoints(Vec3(2.0, 0.75, 1.25)) handCtrl.xfo.copy(handCtrlSrtBuffer.xfo) handCtrl.setColor(ctrlColor) # Rig Ref objects handRefSrt = Locator('handRef', parent=self) handRefSrt.xfo.copy(handCtrlSrtBuffer.xfo) # Add Component Params to IK control handDebugInputAttr = BoolAttribute('debug', True) handLinkToWorldInputAttr = FloatAttribute('linkToWorld', 0.0, 0.0, 1.0) handSettingsAttrGrp = AttributeGroup("DisplayInfo_HandSettings") handCtrl.addAttributeGroup(handSettingsAttrGrp) handSettingsAttrGrp.addAttribute(handDebugInputAttr) handSettingsAttrGrp.addAttribute(handLinkToWorldInputAttr) # ========== # Deformers # ========== container = self.getParent().getParent() deformersLayer = container.getChildByName('deformers') handDef = Joint('hand') handDef.setComponent(self) deformersLayer.addChild(handDef) # ===================== # Create Component I/O # ===================== # Setup Component Xfo I/O's armEndXfoInput = Locator('armEndXfo') armEndXfoInput.xfo.copy(handCtrlSrtBuffer.xfo) armEndPosInput = Locator('armEndPos') armEndPosInput.xfo.copy(handCtrlSrtBuffer.xfo) handEndOutput = Locator('handEnd') handEndOutput.xfo.copy(handCtrlSrtBuffer.xfo) handOutput = Locator('hand') handOutput.xfo.copy(handCtrlSrtBuffer.xfo) # Setup componnent Attribute I/O's debugInputAttr = BoolAttribute('debug', True) rightSideInputAttr = BoolAttribute('rightSide', location is 'R') linkToWorldInputAttr = FloatAttribute('linkToWorld', 0.0, 0.0, 1.0) # Connect attrs to control attrs debugInputAttr.connect(handDebugInputAttr) linkToWorldInputAttr.connect(handLinkToWorldInputAttr) # ============== # Constrain I/O # ============== # Constraint inputs # Constraint outputs handConstraint = PoseConstraint('_'.join([handOutput.getName(), 'To', handCtrl.getName()])) handConstraint.addConstrainer(handCtrl) handOutput.addConstraint(handConstraint) handEndConstraint = PoseConstraint('_'.join([handEndOutput.getName(), 'To', handCtrl.getName()])) handEndConstraint.addConstrainer(handCtrl) handEndOutput.addConstraint(handEndConstraint) # ================== # Add Component I/O # ================== # Add Xfo I/O's self.addInput(armEndXfoInput) self.addInput(armEndPosInput) self.addOutput(handOutput) self.addOutput(handEndOutput) # Add Attribute I/O's self.addInput(debugInputAttr) self.addInput(rightSideInputAttr) self.addInput(linkToWorldInputAttr)
def __init__(self, name, parent=None, location='M'): super(SpineComponent, self).__init__(name, parent, location) # ========= # Controls # ========= # Setup component attributes defaultAttrGroup = self.getAttributeGroupByIndex(0) defaultAttrGroup.addAttribute(BoolAttribute("toggleDebugging", True)) # Default values cogPosition = Vec3(0.0, 11.1351, -0.1382) spine01Position = Vec3(0.0, 11.1351, -0.1382) spine02Position = Vec3(0.0, 11.8013, -0.1995) spine03Position = Vec3(0.0, 12.4496, -0.3649) spine04Position = Vec3(0.0, 13.1051, -0.4821) # COG cogCtrlSrtBuffer = SrtBuffer('cog', parent=self) cogCtrlSrtBuffer.xfo.tr.copy(cogPosition) cogCtrl = CircleControl('cog', parent=cogCtrlSrtBuffer) cogCtrl.scalePoints(Vec3(6.0, 6.0, 6.0)) cogCtrl.xfo.tr.copy(cogPosition) cogCtrl.setColor("orange") # Spine01 spine01CtrlSrtBuffer = SrtBuffer('spine01', parent=cogCtrl) spine01CtrlSrtBuffer.xfo.tr.copy(spine01Position) spine01Ctrl = CircleControl('spine01', parent=spine01CtrlSrtBuffer) spine01Ctrl.scalePoints(Vec3(4.0, 4.0, 4.0)) spine01Ctrl.xfo.tr.copy(spine01Position) spine01Ctrl.setColor("yellow") # Spine02 spine02CtrlSrtBuffer = SrtBuffer('spine02', parent=spine01Ctrl) spine02CtrlSrtBuffer.xfo.tr.copy(spine02Position) spine02Ctrl = CircleControl('spine02', parent=spine02CtrlSrtBuffer) spine02Ctrl.scalePoints(Vec3(4.5, 4.5, 4.5)) spine02Ctrl.xfo.tr.copy(spine02Position) spine02Ctrl.setColor("blue") # Spine03 spine03CtrlSrtBuffer = SrtBuffer('spine03', parent=spine02Ctrl) spine03CtrlSrtBuffer.xfo.tr.copy(spine03Position) spine03Ctrl = CircleControl('spine03', parent=spine03CtrlSrtBuffer) spine03Ctrl.scalePoints(Vec3(4.5, 4.5, 4.5)) spine03Ctrl.xfo.tr.copy(spine03Position) spine03Ctrl.setColor("blue") # Spine04 spine04CtrlSrtBuffer = SrtBuffer('spine04', parent=cogCtrl) spine04CtrlSrtBuffer.xfo.tr.copy(spine04Position) spine04Ctrl = CircleControl('spine04', parent=spine04CtrlSrtBuffer) spine04Ctrl.scalePoints(Vec3(6.0, 6.0, 6.0)) spine04Ctrl.xfo.tr.copy(spine04Position) spine04Ctrl.setColor("yellow") # ========== # Deformers # ========== container = self.getParent().getParent() deformersLayer = container.getChildByName('deformers') spine01Def = Joint('spine01') spine01Def.setComponent(self) spine02Def = Joint('spine02') spine02Def.setComponent(self) spine03Def = Joint('spine03') spine03Def.setComponent(self) spine04Def = Joint('spine04') spine04Def.setComponent(self) deformersLayer.addChild(spine01Def) deformersLayer.addChild(spine02Def) deformersLayer.addChild(spine03Def) deformersLayer.addChild(spine04Def) # ===================== # Create Component I/O # ===================== # Setup component Xfo I/O's spine01Output = Locator('spine01') spine01Output.xfo.tr.copy(spine01Ctrl.xfo.tr) spine02Output = Locator('spine02') spine02Output.xfo.tr.copy(spine01Ctrl.xfo.tr) spine03Output = Locator('spine03') spine03Output.xfo.tr.copy(spine01Ctrl.xfo.tr) spine04Output = Locator('spine04') spine04Output.xfo.tr.copy(spine01Ctrl.xfo.tr) spineBaseOutput = Locator('spineBase') spineBaseOutput.xfo.tr.copy(spine01Ctrl.xfo.tr) spineEndOutput = Locator('spineEnd') spineEndOutput.xfo.tr.copy(spine03Ctrl.xfo.tr) # Setup componnent Attribute I/O's debugInputAttr = BoolAttribute('debug', True) # ============== # Constrain I/O # ============== # Constraint inputs # Constraint outputs spineBaseOutputConstraint = PoseConstraint('_'.join([spineBaseOutput.getName(), 'To', 'spineBase'])) spineBaseOutputConstraint.addConstrainer(spine01Ctrl) spineBaseOutput.addConstraint(spineBaseOutputConstraint) spineEndOutputConstraint = PoseConstraint('_'.join([spineEndOutput.getName(), 'To', 'spineEnd'])) spineEndOutputConstraint.addConstrainer(spine04Ctrl) spineEndOutput.addConstraint(spineEndOutputConstraint) # ================== # Add Component I/O # ================== # Add Xfo I/O's self.addOutput(spine01Output) self.addOutput(spine02Output) self.addOutput(spine03Output) self.addOutput(spine04Output) self.addOutput(spineBaseOutput) self.addOutput(spineEndOutput) # Add Attribute I/O's self.addInput(debugInputAttr)
def __init__(self, name, parent=None, location='M'): super(HeadComponent, self).__init__(name, parent, location) # Setup component attributes defaultAttrGroup = self.getAttributeGroupByIndex(0) defaultAttrGroup.addAttribute(BoolAttribute("toggleDebugging", True)) # Default values headPosition = Vec3(0.0, 17.4756, -0.421) headEndPosition = Vec3(0.0, 19.5, -0.421) eyeLeftPosition = Vec3(0.3497, 18.0878, 0.6088) eyeRightPosition = Vec3(-0.3497, 18.0878, 0.6088) jawPosition = Vec3(0.0, 17.613, -0.2731) # Head headCtrl = CircleControl('head') headCtrl.rotatePoints(0, 0, 90) headCtrl.scalePoints(Vec3(3, 3, 3)) headCtrl.translatePoints(Vec3(0, 1, 0.25)) headCtrl.xfo.tr.copy(headPosition) headCtrl.setColor("yellow") headCtrlSrtBuffer = SrtBuffer('head') self.addChild(headCtrlSrtBuffer) headCtrlSrtBuffer.xfo.copy(headCtrl.xfo) headCtrlSrtBuffer.addChild(headCtrl) # Eye Left eyeLeftCtrl = SphereControl('eyeLeft') eyeLeftCtrl.scalePoints(Vec3(0.75, 0.75, 0.75)) eyeLeftCtrl.xfo.tr.copy(eyeLeftPosition) eyeLeftCtrl.setColor("blueMedium") eyeLeftCtrlSrtBuffer = SrtBuffer('eyeLeft') headCtrl.addChild(eyeLeftCtrlSrtBuffer) eyeLeftCtrlSrtBuffer.xfo.copy(eyeLeftCtrl.xfo) eyeLeftCtrlSrtBuffer.addChild(eyeLeftCtrl) # Eye Right eyeRightCtrl = SphereControl('eyeRight') eyeRightCtrl.scalePoints(Vec3(0.5, 0.5, 0.5)) eyeRightCtrl.xfo.tr.copy(eyeRightPosition) eyeRightCtrl.setColor("blueMedium") eyeRightCtrlSrtBuffer = SrtBuffer('eyeRight') headCtrl.addChild(eyeRightCtrlSrtBuffer) eyeRightCtrlSrtBuffer.xfo.copy(eyeRightCtrl.xfo) eyeRightCtrlSrtBuffer.addChild(eyeRightCtrl) # Jaw jawCtrl = CubeControl('jaw') jawCtrl.alignOnYAxis(negative=True) jawCtrl.alignOnZAxis() jawCtrl.scalePoints(Vec3(1.45, 0.65, 1.25)) jawCtrl.translatePoints(Vec3(0, -0.25, 0)) jawCtrl.xfo.tr.copy(jawPosition) jawCtrl.setColor("orange") jawCtrlSrtBuffer = SrtBuffer('jawSrtBuffer') headCtrl.addChild(jawCtrlSrtBuffer) jawCtrlSrtBuffer.xfo.copy(jawCtrl.xfo) jawCtrlSrtBuffer.addChild(jawCtrl) # ========== # Deformers # ========== container = self.getParent().getParent() deformersLayer = container.getChildByName('deformers') headDef = Joint('head') headDef.setComponent(self) jawDef = Joint('jaw') jawDef.setComponent(self) eyeLeftDef = Joint('eyeLeft') eyeLeftDef.setComponent(self) eyeRightDef = Joint('eyeRight') eyeRightDef.setComponent(self) deformersLayer.addChild(headDef) deformersLayer.addChild(jawDef) deformersLayer.addChild(eyeLeftDef) deformersLayer.addChild(eyeRightDef) # ===================== # Create Component I/O # ===================== # Setup component Xfo I/O's headBaseInput = Locator('headBase') headBaseInput.xfo.copy(headCtrl.xfo) headOutput = Locator('head') headOutput.xfo.copy(headCtrl.xfo) jawOutput = Locator('jaw') jawOutput.xfo.copy(jawCtrl.xfo) eyeLOutput = Locator('eyeL') eyeLOutput.xfo.copy(eyeLeftCtrl.xfo) eyeROutput = Locator('eyeR') eyeROutput.xfo.copy(eyeRightCtrl.xfo) # Setup componnent Attribute I/O's debugInputAttr = BoolAttribute('debug', True) rightSideInputAttr = BoolAttribute('rightSide', location is 'R') # ============== # Constrain I/O # ============== # Constraint inputs headInputConstraint = PoseConstraint('_'.join([headCtrlSrtBuffer.getName(), 'To', headBaseInput.getName()])) headInputConstraint.setMaintainOffset(True) headInputConstraint.addConstrainer(headBaseInput) headCtrlSrtBuffer.addConstraint(headInputConstraint) # Constraint outputs headOutputConstraint = PoseConstraint('_'.join([headOutput.getName(), 'To', headCtrl.getName()])) headOutputConstraint.setMaintainOffset(True) headOutputConstraint.addConstrainer(headCtrl) headOutput.addConstraint(headOutputConstraint) jawOutputConstraint = PoseConstraint('_'.join([jawOutput.getName(), 'To', jawCtrl.getName()])) jawOutputConstraint.setMaintainOffset(True) jawOutputConstraint.addConstrainer(jawCtrl) jawOutput.addConstraint(jawOutputConstraint) eyeLOutputConstraint = PoseConstraint('_'.join([eyeLOutput.getName(), 'To', eyeLeftCtrl.getName()])) eyeLOutputConstraint.setMaintainOffset(True) eyeLOutputConstraint.addConstrainer(eyeLeftCtrl) eyeLOutput.addConstraint(eyeLOutputConstraint) eyeROutputConstraint = PoseConstraint('_'.join([eyeROutput.getName(), 'To', eyeRightCtrl.getName()])) eyeROutputConstraint.setMaintainOffset(True) eyeROutputConstraint.addConstrainer(eyeRightCtrl) eyeROutput.addConstraint(eyeROutputConstraint) # ================== # Add Component I/O # ================== # Add Xfo I/O's self.addInput(headBaseInput) self.addOutput(headOutput) self.addOutput(jawOutput) self.addOutput(eyeLOutput) self.addOutput(eyeROutput) # Add Attribute I/O's self.addInput(debugInputAttr) self.addInput(rightSideInputAttr)