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