def createObjects(self): # SIZE size = self.translations("Root").distance(self.translations("Knee")) fkSize = size * .25 ikSize = size * .25 upvSize = size * .1 rootSize = size * .15 # TRANSFORMATIONS positions = Vector3Array([ self.translations("Root"), self.translations("Knee"), self.translations("Ankle") ]) normal = Vector3.planeNormal(*positions) oriNormal = normal.copy() if self.negate(): normal *= -1 isInversed = constants.AXIS_X.dot(oriNormal) >= 0 d = [(positions[i], positions[i + 1]) for i in range(2)] self.lengths = [Vector3.distance(a, b) for a, b in d] self.lengths.append(1) ratio = self.lengths[0] / sum(self.lengths[:2]) self.setSettings(lengths=self.lengths[:2]) # root rootTfm = Transformation.fromParts( translation=self.translations("Root")) # fk fkTfm = TransformationArray.chain(positions, normal, axis="xz", negativeSide=self.negate(), endTransform=False) axis = "-y-x" if isInversed else "y-x" if self.settings("ankleUpVector") == "World Y": upaxis = constants.AXIS_Y else: upaxis = -1 * self.directions("Ankle", "z") direction = self.translations("Eff") - self.translations("Ankle") fk2Tfm = Transformation.lookAt(self.translations("Ankle"), direction, upaxis, axis, self.negate()) fkTfm = fkTfm.appended(fk2Tfm) bfrTfm = [ tfm.copy(rotation=fkTfm[max(i - 1, 0)].rotation) for i, tfm in enumerate(fkTfm) ] xaxis = constants.AXIS_NX if isInversed else constants.AXIS_X bfrTfm[0] = Transformation.lookAt(self.translations("Root"), constants.AXIS_NY, xaxis, "x" + self.nsign() + "z", self.negate()) # ik ikbfr_pos = Vector3([ self.translations("Root").x, self.translations("Ankle").y, self.translations("Root").z ]) ikbfrTfm = Transformation.fromParts(translation=ikbfr_pos) ikTfm = Transformation.lookAt(self.translations("Ankle"), direction, upaxis, "zy", False) upvbfrTfm = Transformation.fromParts( translation=umath.upVector(self.translations("Root"), ikbfr_pos, constants.AXIS_NX, ratio, False)) upvTfm = Transformation.fromParts( translation=umath.upVector(self.translations( "Root"), self.translations("Ankle"), oriNormal, ratio)) # extras scale = Vector3([1, 1, 1]) twisterTfm = {} interTfm = {} for i, (p, pos) in enumerate(izip(self.twp, positions[1:3])): twisterTfm[p] = [ fkTfm[i].copy(scale=scale), fkTfm[i].copy(translation=pos, scale=scale) ] inter_pos = twisterTfm[p][0].translation.lerp( twisterTfm[p][1].translation, .5) interTfm[p] = twisterTfm[p][0].copy(translation=inter_pos) ctrTfm = twisterTfm["Lwr"][0] # CONTROLLERS # Root self.rootBfr = self.addBfr(None, "Root", rootTfm) self.rootCtl = self.addCtl(self.rootBfr, "Root", rootTfm, "sphere", color=self.colorIk(), size=rootSize) # self.addToSubControllers(self.rootCtl) attributes.setKeyables(self.rootCtl, constants.ATTRS_T) # Fk Ref # Used as a reference for the upr start twist # We cannot use the fk1Bfr cause this one get constrained when fk ref changes self.fkRef = self.addRig(self.rootBfr, "FkRef", bfrTfm[0]) # FK Controlers and Bones fkParent = self.fkRef boneParent = self.fkRef self.fkBfr = [] self.fkCtl = [] self.bones = [] self.stretches = [] for i, (tfm, btfm) in enumerate(izip(fkTfm, bfrTfm), start=1): bfr = self.addBfr(fkParent, "Fk%s" % i, btfm) ctl = self.addCtl(bfr, "Fk%s" % i, tfm, "sphere", color=self.colorFk(), size=fkSize, so=(0, 1, 1)) if self.settings("lockKneeRotation") and i == 2: keyableParams = [ "posx", "posy", "posz", "rotz", "sclx", "scly", "sclz" ] else: keyableParams = constants.ATTRS_TRS attributes.setKeyables(ctl, keyableParams) fkParent = ctl self.fkBfr.append(bfr) self.fkCtl.append(ctl) bone = self.addRig(boneParent, "Bone{}".format(i), tfm=tfm, icon="bone", so=(self.factor(), 1, 1)) boneParent = bone self.bones.append(bone) # IK Controllers self.ikBfr = self.addBfr(None, "Ik", ikbfrTfm) self.ikCtl = self.addCtl(self.ikBfr, "Ik", ikTfm, "cube", color=self.colorIk(), size=ikSize) attributes.setKeyables(self.ikCtl, constants.ATTRS_TRS) attributes.setRotOrder(self.ikCtl, "XZY") self.ikoffCtl = self.addCtl(self.ikCtl, "IkOffset", ikTfm, "cube", color=self.colorIk(), size=ikSize) # self.addToSubControllers(self.ikoffCtl) attributes.setKeyables(self.ikoffCtl, constants.ATTRS_TRS) self.ikRef = self.addRig(self.ikoffCtl, "IkRef", fkTfm[-1]) attributes.setRotOrder(self.ikoffCtl, "XZY") self.upvBfr = self.addBfr(None, "Upv", upvbfrTfm) self.upvCtl = self.addCtl(self.upvBfr, "Upv", upvTfm, "diamond", color=self.colorIk(), size=upvSize) attributes.setKeyables(self.upvCtl, constants.ATTRS_T) self.ctrBfr = self.addBfr(self.bones[0], "Center", ctrTfm) self.ctrCtl = self.addCtl(self.ctrBfr, "Center", ctrTfm, "sphere", size=rootSize, color=self.colorIk()) # self.addToSubControllers(self.ctrCtl) attributes.setKeyables(self.ctrCtl, constants.ATTRS_TRS) self.upvCrv = create.cnsCurve( self.getObjectName(config.USE_RIG, "UpvCrv"), [self.upvCtl, self.ctrCtl]) # Twisters self.twisters = defaultdict(list) for p in self.twp: for s, tfm, factor in izip(["Start", "End"], twisterTfm[p], [1, -1]): twisterBfr = self.addBfr(self.rootBfr, "Tw" + p + s, tfm) twister = self.addRig(twisterBfr, "Tw" + p + s, tfm, "pyramid") self.twisters[p].append(twister) # Inter self.inters = {} for p in self.twp: self.inters[p] = self.addRig(self.rootBfr, "Inter" + p, interTfm[p], "cube")
def createObjects(self): # Settings self.isFk = "FK" in self.settings("kinematic") self.isIk = "IK" in self.settings("kinematic") self.isFkIk = self.isFk and self.isIk self.isNotIk = self.isFk and not self.isIk self.isNotFk = not self.isFk and self.isIk # TRANSFORMATIONS positions = Vector3Array([self.translations("Root"), self.translations("Head"), self.translations("Eff")]) normal = Vector3.planeNormal(*positions) if self.negate(): normal *= -1 self.neckLength = self.translations("Root").distance(self.translations("Head")) headLength = self.translations("Head").distance(self.translations("Eff")) direction = self.translations("Eff") - self.translations("Head") ikTfm = Transformation.lookAt(self.translations("Head"), direction, normal, "yx", self.negate()) if self.settings("orientToWorld"): headTfm = Transformation.fromParts(translation=self.translations("Head")) else: headTfm = ikTfm crvPos = Vector3Array([self.translations("Root").lerp(self.translations("Head"), i/3.0) for i in xrange(4)]) refPos = Vector3Array([self.translations("Root").lerp(self.translations("Head"), i/2.0) for i in xrange(3)]) direction = self.translations("Head") - self.translations("Root") rootTfm = Transformation.lookAt(self.translations("Root"), direction, normal, "yx", self.negate()) midTfm = rootTfm.copy(translation=refPos[1]) endTfm = rootTfm.copy(translation=refPos[2]) tan0Tfm = rootTfm.copy(translation=crvPos[1]) tan1Tfm = ikTfm.copy(translation=crvPos[-2]) bonePos = refPos.appended(self.translations("Eff")) boneTfm = TransformationArray.chain(bonePos, normal, axis="yx", negativeSide=self.negate(), endTransform=False) # CONTROLLERS # Root self.rootRig = self.addRig(None, "Root", rootTfm) self.tan0 = self.addRig(self.rootRig, "Tan0", tan0Tfm) # Ik self.ikBfr = self.addBfr(self.rootRig, "Ik", headTfm) self.ikOri = self.addBfr(self.ikBfr, "IkOri", headTfm) # Maya requires an extra object for the ori cns self.ikCtl = self.addCtl(self.ikOri, "Ik", ikTfm, "cube", size=1, po=(0,headLength*.5,0), so=(8, headLength, 8),color=self.colorIk()) # self.setInversedsettings(self.ikCtl, middle=["posx", "roty", "rotz"]) attributes.setRotOrder(self.ikCtl, "XZY") self.tan1 = self.addRig(self.ikCtl, "Tan1", tan1Tfm) if self.settings("gimbalControllers"): self.ikOffCtl = self.addCtl(self.ikCtl, "IkOff", ikTfm, "cube", size=.9, po=(0,headLength*.5,0), so=(8, headLength, 8),color=self.colorIk()) # self.setInversedsettings(self.ikOffCtl, middle=["posx", "roty", "rotz"]) attributes.setKeyables(self.ikOffCtl, constants.ATTRS_R) attributes.setRotOrder(self.ikOffCtl, "XZY") self.lastIkCtl = self.ikOffCtl # self.addToSubControllers(self.ikOffCtl) else: self.lastIkCtl = self.ikCtl # Curve self.crv = create.curve(self.getObjectName(config.USE_RIG,"Crv"), crvPos, closed=False, degree=3, parent=self.rootRig) # References self.baseBfr = self.addBfr(self.rootRig, "Base", rootTfm) self.baseCtl = self.addCtl(self.baseBfr, "Base", rootTfm, "sphere", size=4, so=(1,0,1), color=self.colorIk()) # self.setInversedsettings(self.baseCtl, middle=["posx", "roty", "rotz"]) attributes.setRotOrder(self.baseCtl, "XZY") self.midBfr = self.addBfr(self.crv, "Mid", midTfm) self.midCtl = self.addCtl(self.midBfr, "Mid", midTfm, "sphere", size=4, so=(1,0,1), color=self.colorIk()) attributes.setKeyables(self.midCtl, constants.ATTRS_TS) # self.setInversedsettings(self.midCtl, middle=["posx"]) self.headBfr = self.addBfr(self.crv, "Head", endTfm) if self.settings("extraHeadController"): self.headCtl = self.addCtl(self.headBfr, "Head", rootTfm, "sphere", so=(1,0,1), color=self.colorIk()) # self.addToSubControllers(self.headCtl) # self.setInversedsettings(self.headCtl, middle=["posx", "roty", "rotz"]) attributes.setRotOrder(self.headCtl, "XZY") self.headRef = self.headCtl else: self.headRef = self.headBfr # Fk if self.isFk: self.fkCtl = [] parent = self.rootRig for i, tfm in enumerate(boneTfm, start=1): if self.settings("orientToWorld") and i == len(boneTfm): bfr = self.addBfr(parent, "Fk%s"%i, headTfm) else: bfr = self.addBfr(parent, "Fk%s"%i, tfm) ctl = self.addCtl(bfr, "Fk%s"%i, tfm, "cube", size=8, so=(1,.1,1), color=self.colorFk()) attributes.setRotOrder(ctl, "XZY") parent = ctl self.fkCtl.append(ctl) if self.settings("gimbalControllers"): self.fkOffCtl = self.addCtl(self.fkCtl[-1], "fkOffCtl", boneTfm[-1], "cube", size=7.5, so=(1,.1,1), color=self.colorFk()) attributes.setKeyables(self.fkOffCtl, constants.ATTRS_R) attributes.setRotOrder(self.fkOffCtl, "XZY") # Hooks self.ikParents = [self.baseCtl, self.midCtl, self.headRef] self.hooks = [] for i, (tfm, parent) in enumerate(izip(boneTfm, self.ikParents), start=1): hk = self.addRig(parent, "Hook%s"%i, tfm) self.hooks.append(hk)