def rotatePoints(self, xRot, yRot, zRot): """Rotates the points by the input values. Arguments: xRot -- Float, euler x rotate value. yRot -- Float, euler y rotate value. zRot -- Float, euler z rotate value. Return: True if successful. """ curveData = list(self.getCurveData()) quatRot = Quat() quatRot.setFromEuler( Euler(Math_degToRad(xRot), Math_degToRad(yRot), Math_degToRad(zRot))) newPoints = [] for eachSubCurve in curveData: for eachPoint in eachSubCurve["points"]: pointVec = Vec3(eachPoint[0], eachPoint[1], eachPoint[2]) rotVec = quatRot.rotateVector(pointVec) eachPoint[0] = rotVec.x eachPoint[1] = rotVec.y eachPoint[2] = rotVec.z self.setCurveData(curveData) return True
def __init__(self, name='head', parent=None, *args, **kwargs): Profiler.getInstance().push("Construct Head Guide Component:" + name) super(HeadComponentGuide, self).__init__(name, parent, *args, **kwargs) # ========= # Controls # ========= guideSettingsAttrGrp = AttributeGroup("GuideSettings", parent=self) sphereCtrl = Control('sphere', shape='sphere') sphereCtrl.scalePoints(Vec3(0.375, 0.375, 0.375)) self.headCtrl = Control('head', parent=self.ctrlCmpGrp, shape='square') self.headCtrl.rotatePoints(90, 0, 0) self.headCtrl.translatePoints(Vec3(0.0, 0.5, 0.0)) self.headCtrl.scalePoints(Vec3(1.8, 2.0, 2.0)) self.eyeLeftCtrl = Control('eyeLeft', parent=self.headCtrl, shape='arrow_thin') self.eyeLeftCtrl.translatePoints(Vec3(0, 0, 0.5)) self.eyeLeftCtrl.rotatePoints(0, 90, 0) self.eyeLeftCtrl.appendCurveData(sphereCtrl.getCurveData()) self.eyeRightCtrl = Control('eyeRight', parent=self.headCtrl, shape='arrow_thin') self.eyeRightCtrl.translatePoints(Vec3(0, 0, 0.5)) self.eyeRightCtrl.rotatePoints(0, 90, 0) self.eyeRightCtrl.appendCurveData(sphereCtrl.getCurveData()) self.jawCtrl = Control('jaw', parent=self.headCtrl, shape='square') self.jawCtrl.rotatePoints(90, 0, 0) self.jawCtrl.rotatePoints(0, 90, 0) self.jawCtrl.translatePoints(Vec3(0.0, -0.5, 0.5)) self.jawCtrl.scalePoints(Vec3(1.0, 0.8, 1.5)) self.jawCtrl.setColor('orange') eyeXAlignOri = Quat() eyeXAlignOri.setFromAxisAndAngle(Vec3(0, 1, 0), Math_degToRad(-90)) self.default_data = { "name": name, "location": "M", "headXfo": Xfo(Vec3(0.0, 17.5, -0.5)), "headCrvData": self.headCtrl.getCurveData(), "eyeLeftXfo": Xfo(tr=Vec3(0.375, 18.5, 0.5), ori=eyeXAlignOri), "eyeLeftCrvData": self.eyeLeftCtrl.getCurveData(), "eyeRightXfo": Xfo(tr=Vec3(-0.375, 18.5, 0.5), ori=eyeXAlignOri), "eyeRightCrvData": self.eyeRightCtrl.getCurveData(), "jawXfo": Xfo(Vec3(0.0, 17.875, -0.275)), "jawCrvData": self.jawCtrl.getCurveData() } self.loadData(self.default_data) Profiler.getInstance().pop()
def syncXfo(self, kObject): """Syncs the xfo from the DCC object to the Kraken object. Args: kObject (object): Object to sync the xfo for. Returns: Boolean: True if successful. """ if kObject.isOfAnyType(('Rig', 'Container', 'Layer', 'HierarchyGroup', 'ComponentInput', 'ComponentOutput')): logger.debug("SyncXfo: Skipping '" + kObject.getName() + "'!") return False hrcMap = self.getHierarchyMap() if kObject not in hrcMap.keys(): logger.warning("SyncXfo: 3D Object '" + kObject.getName() + "' was not found in the mapping!") return False dccItem = hrcMap[kObject]['dccItem'] if dccItem is None: logger.warning("SyncXfo: No DCC Item for :" + kObject.getPath()) return False dccPos = dccItem.GetWorldPosition() dccQuat = dccItem.GetWorldRotation() dccScl = dccItem.GetWorldScale() pos = Vec3(x=dccPos.X, y=dccPos.Y, z=dccPos.Z) quat = Quat(v=Vec3(dccQuat.X, dccQuat.Y, dccQuat.Z), w=dccQuat.W) # If flag is set, pass the DCC Scale values. if kObject.testFlag('SYNC_SCALE') is True: scl = Vec3(x=dccScl.X, y=dccScl.Y, z=dccScl.Z) else: scl = Vec3(1.0, 1.0, 1.0) newXfo = Xfo(tr=pos, ori=quat, sc=scl) rotateUpXfo = Xfo() rotateUpXfo.ori = Quat().setFromAxisAndAngle(Vec3(1, 0, 0), Math_degToRad(-90)) newXfo = rotateUpXfo * newXfo kObject.xfo = newXfo return True
def getRigBuildData(self): """Returns the Guide data used by the Rig Component to define the layout of the final rig.. Return: The JSON rig data object. """ data = super(FKCollisionComponentGuide, self).getRigBuildData() numJoints = self.numJoints.getValue() # Calculate Xfos boneXfos = [] boneLengths = [] for i in xrange(numJoints): boneVec = self.jointCtrls[i + 1].xfo.tr.subtract( self.jointCtrls[i].xfo.tr) boneLengths.append(boneVec.length()) xfo = Xfo() q = Quat() q.setFromDirectionAndUpvector( boneVec.unit(), self.jointCtrls[i].xfo.ori.getYaxis()) qDir = Quat().setFromAxisAndAngle(Vec3(0, 1, 0), Math_degToRad(-90)) xfo.ori = q * qDir xfo.tr = self.jointCtrls[i].xfo.tr boneXfos.append(xfo) data['jointXfos'] = [x.xfo for x in self.jointCtrls] data['boneXfos'] = boneXfos data['endXfo'] = self.jointCtrls[-1].xfo data['boneLengths'] = boneLengths return data
def __init__(self, name): Profiler.getInstance().push("Construct BipedGuideRig:" + name) super(BipedGuideRig, self).__init__(name) # =========== # Components # =========== mainSrtComponentGuide = MainSrtComponentGuide('mainSrt', parent=self) spineComponentGuide = SpineComponentGuide('spine', parent=self) neckComponentGuide = NeckComponentGuide('neck', parent=self) headComponentGuide = HeadComponentGuide('head', parent=self) clavicleLeftComponentGuide = ClavicleComponentGuide('clavicle', parent=self) clavicleRightComponentGuide = ClavicleComponentGuide('clavicle', parent=self) clavicleRightComponentGuide.loadData({ "name": 'clavicle', "location": 'R', "clavicleXfo": Xfo(Vec3(-0.15, 15.5, -0.5)), "clavicleUpVXfo": Xfo(Vec3(-0.15, 16.5, -0.5)), "clavicleEndXfo": Xfo(Vec3(-2.25, 15.5, -0.75)) }) armLeftComponentGuide = ArmComponentGuide('arm', parent=self) armRightComponentGuide = ArmComponentGuide('arm', parent=self) armRightComponentGuide.loadData({ "name": 'arm', "location": 'R', "bicepXfo": Xfo(Vec3(-2.275, 15.3, -0.75)), "forearmXfo": Xfo(Vec3(-5.0, 13.5, -0.75)), "wristXfo": Xfo(Vec3(-7.2, 12.25, 0.5)), "bicepFKCtrlSize": 1.75, "forearmFKCtrlSize": 1.5 }) handLeftComponentGuide = HandComponentGuide('hand', parent=self) handRightComponentGuide = HandComponentGuide('hand', parent=self) handRightOri = Quat() handRightOri.setFromAxisAndAngle(Vec3(0, 1, 0), Math_degToRad(180)) handRightComponentGuide.loadData({ "name": 'hand', "location": 'R', "handXfo": Xfo(tr=Vec3(-7.1886, 12.2819, 0.4906), ori=handRightOri), "digitNames": "thumb,index,middle,ring,pinky", "numJoints": 4, "fingersGuideXfos": { "pinky": [ Xfo(sc=Vec3(y=1.0, x=1.0, z=1.0), tr=Vec3(x=-7.439000129699707, y=12.281900405883789, z=0.0), ori=handRightOri), Xfo(sc=Vec3(y=1.0, x=1.0, z=1.0), tr=Vec3(x=-7.814000129699707, y=12.281900405883789, z=0.0), ori=handRightOri), Xfo(sc=Vec3(y=1.0, x=1.0, z=1.0), tr=Vec3(x=-8.064000129699707, y=12.281900405883789, z=0.0), ori=handRightOri), Xfo(sc=Vec3(y=1.0, x=1.0, z=1.0), tr=Vec3(x=-8.314000129699707, y=12.281900405883789, z=0.0), ori=handRightOri), Xfo(sc=Vec3(y=1.0, x=1.0, z=1.0), tr=Vec3(x=-8.564000129699707, y=12.281900405883789, z=0.0), ori=handRightOri) ], "index": [ Xfo(sc=Vec3(y=1.0, x=1.0, z=1.0), tr=Vec3(x=-7.439000129699707, y=12.281900405883789, z=0.75), ori=handRightOri), Xfo(sc=Vec3(y=1.0, x=1.0, z=1.0), tr=Vec3(x=-7.814000129699707, y=12.281900405883789, z=0.75), ori=handRightOri), Xfo(sc=Vec3(y=1.0, x=1.0, z=1.0), tr=Vec3(x=-8.064000129699707, y=12.281900405883789, z=0.75), ori=handRightOri), Xfo(sc=Vec3(y=1.0, x=1.0, z=1.0), tr=Vec3(x=-8.314000129699707, y=12.281900405883789, z=0.75), ori=handRightOri), Xfo(sc=Vec3(y=1.0, x=1.0, z=1.0), tr=Vec3(x=-8.564000129699707, y=12.281900405883789, z=0.75), ori=handRightOri) ], "ring": [ Xfo(sc=Vec3(y=1.0, x=1.0, z=1.0), tr=Vec3(x=-7.439000129699707, y=12.281900405883789, z=0.25), ori=handRightOri), Xfo(sc=Vec3(y=1.0, x=1.0, z=1.0), tr=Vec3(x=-7.814000129699707, y=12.281900405883789, z=0.25), ori=handRightOri), Xfo(sc=Vec3(y=1.0, x=1.0, z=1.0), tr=Vec3(x=-8.064000129699707, y=12.281900405883789, z=0.25), ori=handRightOri), Xfo(sc=Vec3(y=1.0, x=1.0, z=1.0), tr=Vec3(x=-8.314000129699707, y=12.281900405883789, z=0.25), ori=handRightOri), Xfo(sc=Vec3(y=1.0, x=1.0, z=1.0), tr=Vec3(x=-8.564000129699707, y=12.281900405883789, z=0.25), ori=handRightOri) ], "thumb": [ Xfo(sc=Vec3(y=1.0, x=1.0, z=1.0), tr=Vec3(x=-7.439000129699707, y=12.281900405883789, z=1.0), ori=handRightOri), Xfo(sc=Vec3(y=1.0, x=1.0, z=1.0), tr=Vec3(x=-7.814000129699707, y=12.281900405883789, z=1.0), ori=handRightOri), Xfo(sc=Vec3(y=1.0, x=1.0, z=1.0), tr=Vec3(x=-8.064000129699707, y=12.281900405883789, z=1.0), ori=handRightOri), Xfo(sc=Vec3(y=1.0, x=1.0, z=1.0), tr=Vec3(x=-8.314000129699707, y=12.281900405883789, z=1.0), ori=handRightOri) ], "middle": [ Xfo(sc=Vec3(y=1.0, x=1.0, z=1.0), tr=Vec3(x=-7.439000129699707, y=12.281900405883789, z=0.5), ori=handRightOri), Xfo(sc=Vec3(y=1.0, x=1.0, z=1.0), tr=Vec3(x=-7.814000129699707, y=12.281900405883789, z=0.5), ori=handRightOri), Xfo(sc=Vec3(y=1.0, x=1.0, z=1.0), tr=Vec3(x=-8.064000129699707, y=12.281900405883789, z=0.5), ori=handRightOri), Xfo(sc=Vec3(y=1.0, x=1.0, z=1.0), tr=Vec3(x=-8.314000129699707, y=12.281900405883789, z=0.5), ori=handRightOri), Xfo(sc=Vec3(y=1.0, x=1.0, z=1.0), tr=Vec3(x=-8.564000129699707, y=12.281900405883789, z=0.5), ori=handRightOri) ] } }) legLeftComponentGuide = LegComponentGuide('leg', parent=self) legRightComponentGuide = LegComponentGuide('leg', parent=self) legRightComponentGuide.loadData({ "name": 'leg', "location": 'R', "createIKHandle": False, "femurXfo": Xfo(Vec3(-1.0, 9.75, -0.5)), "kneeXfo": Xfo(Vec3(-1.5, 5.5, -0.5)), "ankleXfo": Xfo(Vec3(-1.75, 1.15, -1.25)) }) footLeftComponentGuide = FootComponentGuide('foot', parent=self) footRightComponentGuide = FootComponentGuide('foot', parent=self) footRightComponentGuide.loadData({ "name": 'foot', "location": 'R', 'ankleXfo': Xfo(Vec3(-1.75, 1.15, -1.25)), 'toeXfo': Xfo(Vec3(-1.75, 0.4, 0.25)), 'toeTipXfo': Xfo(Vec3(-1.75, 0.4, 1.5)), 'backPivotXfo': Xfo(Vec3(-1.75, 0.0, -2.5)), 'frontPivotXfo': Xfo(Vec3(-1.75, 0.0, 2.0)), 'outerPivotXfo': Xfo(Vec3(-2.5, 0.0, -1.25)), 'innerPivotXfo': Xfo(Vec3(-1.0, 0.0, -1.25)) }) # ============ # Connections # ============ # ======= # Outputs # ======= mainSrtRigScaleOutput = mainSrtComponentGuide.getOutputByName('rigScale') mainSrtOffsetOutput = mainSrtComponentGuide.getOutputByName('offset') spineEndOutput = spineComponentGuide.getOutputByName('spineEnd') neckEndOutput = neckComponentGuide.getOutputByName('neckEnd') clavicleLeftEndOutput = clavicleLeftComponentGuide.getOutputByName('clavicleEnd') clavicleRightEndOutput = clavicleRightComponentGuide.getOutputByName('clavicleEnd') spinePelvisOutput = spineComponentGuide.getOutputByName('pelvis') # Arm Left armLeftWristOutput = armLeftComponentGuide.getOutputByName('wrist') # Arm Right armRightWristOutput = armRightComponentGuide.getOutputByName('wrist') # Leg Left legLeftIkHandleOutput = legLeftComponentGuide.getOutputByName('ikHandle') legLeftLegEndOutput = legLeftComponentGuide.getOutputByName('legEnd') legLeftLegEndFKOutput = legLeftComponentGuide.getOutputByName('legEndFK') # Leg Right legRightIkHandleOutput = legRightComponentGuide.getOutputByName('ikHandle') legRightLegEndOutput = legRightComponentGuide.getOutputByName('legEnd') legRightLegEndFKOutput = legRightComponentGuide.getOutputByName('legEndFK') # Foot Left footLeftIkTargetOutput = footLeftComponentGuide.getOutputByName('ikTarget') # Foot Right footRightIkTargetOutput = footRightComponentGuide.getOutputByName('ikTarget') # ========================= # Inputs & Set Connections # ========================= # Spine spineGlobalSrtInput = spineComponentGuide.getInputByName('globalSRT') spineGlobalSrtInput.setConnection(mainSrtOffsetOutput) spineRigScaleInput = spineComponentGuide.getInputByName('rigScale') spineRigScaleInput.setConnection(mainSrtRigScaleOutput) # Neck neckGlobalSrtInput = neckComponentGuide.getInputByName('globalSRT') neckGlobalSrtInput.setConnection(mainSrtOffsetOutput) neckSpineEndInput = neckComponentGuide.getInputByName('neckBase') neckSpineEndInput.setConnection(spineEndOutput) # Head headGlobalSrtInput = headComponentGuide.getInputByName('globalSRT') headGlobalSrtInput.setConnection(mainSrtOffsetOutput) headBaseInput = headComponentGuide.getInputByName('neckRef') headBaseInput.setConnection(neckEndOutput) headBaseInput = headComponentGuide.getInputByName('worldRef') headBaseInput.setConnection(mainSrtOffsetOutput) # Clavicle Left clavicleLeftGlobalSrtInput = clavicleLeftComponentGuide.getInputByName('globalSRT') clavicleLeftGlobalSrtInput.setConnection(mainSrtOffsetOutput) clavicleLeftSpineEndInput = clavicleLeftComponentGuide.getInputByName('spineEnd') clavicleLeftSpineEndInput.setConnection(spineEndOutput) # Clavicle Right clavicleRightGlobalSrtInput = clavicleRightComponentGuide.getInputByName('globalSRT') clavicleRightGlobalSrtInput.setConnection(mainSrtOffsetOutput) clavicleRightSpineEndInput = clavicleRightComponentGuide.getInputByName('spineEnd') clavicleRightSpineEndInput.setConnection(spineEndOutput) # Arm Left armLeftGlobalSrtInput = armLeftComponentGuide.getInputByName('globalSRT') armLeftGlobalSrtInput.setConnection(mainSrtOffsetOutput) armLeftRigScaleInput = armLeftComponentGuide.getInputByName('rigScale') armLeftRigScaleInput.setConnection(mainSrtRigScaleOutput) armLeftClavicleEndInput = armLeftComponentGuide.getInputByName('root') armLeftClavicleEndInput.setConnection(clavicleLeftEndOutput) # Arm Right armRightGlobalSrtInput = armRightComponentGuide.getInputByName('globalSRT') armRightGlobalSrtInput.setConnection(mainSrtOffsetOutput) armRightRigScaleInput = armRightComponentGuide.getInputByName('rigScale') armRightRigScaleInput.setConnection(mainSrtRigScaleOutput) armRightClavicleEndInput = armRightComponentGuide.getInputByName('root') armRightClavicleEndInput.setConnection(clavicleRightEndOutput) # Hand Left handLeftGlobalSrtInput = handLeftComponentGuide.getInputByName('globalSRT') handLeftGlobalSrtInput.setConnection(mainSrtOffsetOutput) handLeftArmEndInput = handLeftComponentGuide.getInputByName('armEnd') handLeftArmEndInput.setConnection(armLeftWristOutput) # Hand Right handRightGlobalSrtInput = handRightComponentGuide.getInputByName('globalSRT') handRightGlobalSrtInput.setConnection(mainSrtOffsetOutput) handRightArmEndInput = handRightComponentGuide.getInputByName('armEnd') handRightArmEndInput.setConnection(armRightWristOutput) # Leg Left legLeftGlobalSrtInput = legLeftComponentGuide.getInputByName('globalSRT') legLeftGlobalSrtInput.setConnection(mainSrtOffsetOutput) legLeftRigScaleInput = legLeftComponentGuide.getInputByName('rigScale') legLeftRigScaleInput.setConnection(mainSrtRigScaleOutput) legLeftPelvisInput = legLeftComponentGuide.getInputByName('pelvisInput') legLeftPelvisInput.setConnection(spinePelvisOutput) legLeftPelvisInput = legLeftComponentGuide.getInputByName('ikTarget') legLeftPelvisInput.setConnection(footLeftIkTargetOutput) # Leg Right legRightGlobalSrtInput = legRightComponentGuide.getInputByName('globalSRT') legRightGlobalSrtInput.setConnection(mainSrtOffsetOutput) legRightRigScaleInput = legRightComponentGuide.getInputByName('rigScale') legRightRigScaleInput.setConnection(mainSrtRigScaleOutput) legRightPelvisInput = legRightComponentGuide.getInputByName('pelvisInput') legRightPelvisInput.setConnection(spinePelvisOutput) legRightPelvisInput = legRightComponentGuide.getInputByName('ikTarget') legRightPelvisInput.setConnection(footRightIkTargetOutput) # Foot Left footLeftGlobalSrtInput = footLeftComponentGuide.getInputByName('globalSRT') footLeftGlobalSrtInput.setConnection(mainSrtOffsetOutput) footLeftIkHandleInput = footLeftComponentGuide.getInputByName('ikHandle') footLeftIkHandleInput.setConnection(legLeftIkHandleOutput) footLeftLegEndInput = footLeftComponentGuide.getInputByName('legEnd') footLeftLegEndInput.setConnection(legLeftLegEndOutput) footLeftLegEndFKInput = footLeftComponentGuide.getInputByName('legEndFK') footLeftLegEndFKInput.setConnection(legLeftLegEndFKOutput) # Foot Right footRightGlobalSrtInput = footRightComponentGuide.getInputByName('globalSRT') footRightGlobalSrtInput.setConnection(mainSrtOffsetOutput) footRightIkHandleInput = footRightComponentGuide.getInputByName('ikHandle') footRightIkHandleInput.setConnection(legRightIkHandleOutput) footRightLegEndInput = footRightComponentGuide.getInputByName('legEnd') footRightLegEndInput.setConnection(legRightLegEndOutput) footRightLegEndFKInput = footRightComponentGuide.getInputByName('legEndFK') footRightLegEndFKInput.setConnection(legRightLegEndFKOutput) Profiler.getInstance().pop()
parentLoc = Locator('parent') locator1 = Locator("locator", parent=parentLoc) locator1.xfo.tr.x = 3 locator1.xfo.tr.y = -1 locator1.xfo.tr.z = 1 locator2 = Locator("locator2", parent=parentLoc) locator2.xfo.sc.x = 1 locator2.xfo.sc.y = 2 locator2.xfo.sc.z = 3 locator2.xfo.tr.x = 2 locator2.xfo.tr.y = 5 locator2.xfo.tr.z = 3 locator2.xfo.ori.setFromEulerAngles(Vec3(Math_degToRad(45.0), Math_degToRad(0.0), Math_degToRad(0.0))) constraint = locator2.constrainTo(locator1, 'Pose', True, 'PoseConstraint') builder = plugins.getBuilder() config = builder.getConfig() config.setExplicitNaming(True) builder.build(parentLoc)
parentLoc = Locator('parent') locator1 = Locator("locator", parent=parentLoc) locator1.xfo.tr.x = 3 locator1.xfo.tr.y = -1 locator1.xfo.tr.z = 1 locator2 = Locator("locator2", parent=parentLoc) locator2.xfo.sc.x = 1 locator2.xfo.sc.y = 2 locator2.xfo.sc.z = 1 locator2.xfo.tr.x = 2 locator2.xfo.tr.y = 5 locator2.xfo.tr.z = 3 locator2.xfo.ori.setFromEulerAngles( Vec3(Math_degToRad(45.0), Math_degToRad(0.0), Math_degToRad(0.0))) constraint = locator2.constrainTo(locator1, 'Scale', True, 'ScaleConstraint') builder = plugins.getBuilder() config = builder.getConfig() config.setExplicitNaming(True) builder.build(parentLoc)