def createObjects(self): # SIZE size = self.translations("Root").distance(self.translations("Eff")) # TRANSFORMATION # Normal normal = self.directions("Root", "z") direction = self.translations("Eff") - self.translations("Root") rootTfm = Transformation.lookAt(self.translations("Root"), direction, normal, self.nsign() + "yz", self.negate()) dynTfm = Transformation.lookAt(self.translations("Root"), direction, normal, "xz", self.negate()) posTfm = dynTfm.copy(translation=self.translations("Eff")) upvPos = Vector3([0, 0, 10]) * dynTfm.asMatrix() # OBJECTS # Controller self.dynBfr = self.addBfr(None, "Part1", dynTfm) self.dynCtl = self.addCtl(self.dynBfr, "Part1", dynTfm, "sphere", size=size, po=(self.factor(), 0, 0), so=(1, 1, 0), color=self.colorFk()) attributes.setKeyables(self.dynCtl) # self.setInversedParameters(self.dynCtl, middle=["posz", "rotx", "roty"]) self.posBfr = self.addBfr(self.dynBfr, "Part2", posTfm) self.posCtl = self.addCtl(self.posBfr, "Part2", posTfm, "sphere", size=size * 1.5, so=[0, 1, 1], color=self.colorIk()) attributes.setKeyables(self.posCtl) # self.setInversedParameters(self.posCtl, middle=["posz", "rotx", "roty"]) # Dynamic ---------------------------- self.harmonic = self.addRig(self.posCtl, "Harmonic", posTfm, "diamond", size=1)
def createObjects(self): # Transformation tfm = Transformation.lookAt(self.translations("Root"), self.directions("Root", "x"), self.directions("Root", "z"), "xz", self.negate()) # Controller self.bfr = self.addBfr(None, "Average", tfm,) if self.settings("addControllers"): self.ctl = self.addCtl(self.bfr, "Average", self.guide().controllers("gde_Root"), tfm, color=self.colorFk())
def createObjects(self): self.bfr = [] self.ctl = [] parent = None color = self.colorIk() if self.settings( "useIkColor") else self.colorFk() axis = self.sign() + "yz" self.jntparent = [] self.splitParent = [] # for i, tfm in enumerate(self.transforms("Part"), start=1): for i, (t, dy, dz) in enumerate(izip(self.translations("Part"), self.directions("Part", "y"), self.directions("Part", "z")), start=1): tfm = Transformation.lookAt(t, dy, dz, axis, negativeSide=self.negate()) part = "Part{}".format(i) bfr = self.addBfr(None, part, tfm=tfm) self.bfr.append(bfr) if self.settings("addControllers"): ctl = self.addCtl(bfr, part, tfm=tfm, icon="cube", color=color) self.ctl.append(ctl) attributes.setRotOrder(ctl, self.settings("defaultRotationOrder")) keyables = [ attr for attr in constants.ATTRS_TRS if self.settings(attr) ] attributes.setKeyables(ctl, keyables) jntparent = ctl else: jntparent = bfr if self.settings("dynamic"): harmonic = self.addRig(jntparent, "Harmonic{}".format(i), tfm=tfm) jntparent = harmonic self.jntparent.append(jntparent) if self.settings("splitRotation"): splitParent = self.addRig(jntparent, "Split{}".format(i), tfm=tfm) self.splitParent.append(splitParent)
def createObjects(self): self.setSettings(count=self.count("Part")) # TRANSFORMATIONS zipper = izip(self.translations("Part"), self.translations("Eff"), self.directions("Part", "z")) boneTfm = [ Transformation.lookAt(posA, posB - posA, drt, "xz", self.negate()) for posA, posB, drt in zipper ] # OBJECTS # Root root = self.addRig(None, "Root", boneTfm[0]) buildController = [] if self.settings("startController"): buildController.append(1) if self.settings("interController"): buildController.extend(xrange(2, self.count("Part"))) buildController.append(self.count("Part")) self.bones = [] self.drivers = [] for i, tfm in enumerate(boneTfm, start=1): bfr = self.addBfr(root, "Part{}".format(i), tfm) drv = self.addRig(bfr, "Part{}".format(i), tfm) if i in buildController: bone = self.addCtl(drv, "Part{}".format(i), tfm, "pyramid", po=(0, 2.5, 0), color=self.colorFk()) self.bones.append(bone) else: self.bones.append(drv) self.drivers.append(drv)
def createObjects(self): # TRANSFORMATION tfm = Transformation.lookAt(self.translations("Root"), self.directions("Root", "y"), self.directions("Root", "z"), "y" + self.sign() + "z", False) # GET SETTINGS camera = self.markers("Root").name() shape = cmds.listRelatives(camera, shapes=True)[0] options = {} for attr in [ "focalLength", "cameraScale", "nearClipPlane", "farClipPlane", "horizontalFilmAperture", "verticalFilmAperture", "lensSqueezeRatio", "filmFit", "filmFitOffset", "horizontalFilmOffset", "verticalFilmOffset" ]: options[attr] = cmds.getAttr(shape + "." + attr) # OBJECTS bfr = self.addBfr(None, "Camera", tfm) camera = self.addCamera(bfr, "Camera", tfm=tfm, **options)
def createObjects(self): # Normal normal = self.directions("Root", "y") distance = self.translations("Root").distance(self.translations("Eff")) # Transformations direction = self.translations("Eff") - self.translations("Root") startTfm = Transformation.lookAt(self.translations("Root"), direction, normal, "xy", self.negate()) endTfm = startTfm.copy(translation=self.translations("Eff")) # Controllers startBfr = self.addBfr(None, "Start", startTfm) if self.settings("addControllers"): ctl = self.addCtl(startBfr, "Start", startTfm, "sphere", size=.5, color=self.colorIk()) attributes.setKeyables(ctl) self.startParent = ctl else: self.startParent = startBfr endBfr = self.addBfr(None, "End", endTfm) if self.settings("addControllers"): self.endCtl = self.addCtl(endBfr, "End", endTfm, "sphere", size=.5, color=self.colorIk()) attributes.setKeyables(self.endCtl) self.endParent = self.endCtl else: self.endParent = endBfr # Stretch self.startRig = self.addRig(self.startParent, "StretchStart", startTfm, "cube", size=1, po=(distance*.25,0,0), so=(distance*.5, 1, 1)) self.endRig = self.addRig(self.endParent, "StretchEnd", endTfm, "cube", size=1, po=(distance*-.25,0,0), so=(distance*.5, 1, 1)) self.interDiv = [self.addRig(self.startParent, "Div%s"%i, startTfm, "cube", self.size()) for i in xrange(1, self.settings("interDeformers")+1)]
def createObjects(self): # TRANSFORMATIONS normal = Vector3.planeNormal(self.translations("Root"), self.translations("Part")[-1], self.translations("Heel")) if self.negate(): normal *= -1 rootTfm = Transformation.lookAt(self.translations("Root"), constants.AXIS_Y, normal, "y-x", self.negate()) direction = self.translations("Part")[-1] - self.translations("Heel") heelTfm = Transformation.lookAt(self.translations("Heel"), direction, normal, "xz", self.negate()) if self.count("Part") > 1: B = self.translations("Heel") - self.translations("Part")[-1] C = self.translations("Part")[0] - self.translations("Part")[-1] a = 1 - ((math.cos(B.angle(C)) * C.length()) / B.length()) else: a = .5 swivel_pos = self.translations("Heel").lerp( self.translations("Part")[-1], a) swivelTfm = heelTfm.copy(translation=swivel_pos) direction = self.translations("Part")[0] - self.translations("Root") fkrefTfm = Transformation.lookAt(self.translations("Root"), direction, normal, "xz", self.negate()) fkTfm = TransformationArray.chain(self.translations("Part"), normal, axis="xz", negativeSide=self.negate(), endTransform=False) fkTfm = fkTfm.appended( heelTfm.copy(translation=self.translations("Part")[-1])) # CONTROLLERS # Root self._root = self.addRig(None, "Root", rootTfm) # Heel self.heelBfr = self.addBfr(self._root, "Heel", heelTfm) self.heelRol = self.addRig(self.heelBfr, "HeelRoll", tfm=heelTfm) self.heelCtl = self.addCtl(self.heelRol, "Heel", heelTfm, "sphere", so=[1, 1, 0], color=self.colorIk()) attributes.setKeyables(self.heelCtl, constants.ATTRS_TR) # self.setInversedParameters(self.heelCtl, middle=["posz", "rotx", "roty"]) # Swivel self.swivelBfr = self.addBfr(self.heelCtl, "Swivel", swivelTfm) self.swivelCtl = self.addCtl(self.swivelBfr, "Swivel", swivelTfm, "sphere", so=[3, 0, 3], color=self.colorIk()) attributes.setKeyables(self.swivelCtl, constants.ATTRS_TR) # self.setInversedParameters(self.swivelCtl, middle=["posz", "rotx", "roty"]) # Roll self.rollCtl = self.addCtl(self._root, "Roll", rootTfm, "sphere", color=self.colorIk(), so=[0, 2, 2]) # self.addToSubControllers(self.rollCtl) attributes.setKeyables(self.rollCtl, ["rotx", "rotz"]) # self.setInversedParameters(self.rollCtl, middle=["rotz"]) # Backward Controllers parent = self.swivelCtl self.bkBfr = [] self.bkRol = [] self.bkCtl = [] for i, tfm in enumerate(reversed(fkTfm)): index = i + 1 bkBfr = self.addBfr(parent, "Bk%s" % index, tfm=tfm) bkRol = self.addRig(bkBfr, "Bk%sRoll" % index, tfm=tfm) bkCtl = self.addCtl(bkRol, "Bk%s" % index, tfm, "sphere", color=self.colorIk(), so=[1, 1, 0]) attributes.setKeyables(bkCtl, constants.ATTRS_R) # self.setInversedParameters(bkCtl, middle=["rotx", "roty"]) self.bkBfr.append(bkBfr) self.bkRol.append(bkRol) self.bkCtl.append(bkCtl) parent = bkCtl # Forward Controllers self.fkRef = self.addRig(self.bkCtl[-1], "FkRef", fkrefTfm) self.fkBfr = [] self.fkCtl = [] parent = self.fkRef for i, (tfm, bkCtl) in enumerate(izip(fkTfm, self.bkCtl[:-1]), start=1): fkBfr = self.addBfr(parent, "Fk%s" % i, tfm=tfm) fkCtl = self.addCtl(fkBfr, "Fk%s" % i, tfm, "sphere", color=self.colorFk(), so=[0, 2, 4]) attributes.setKeyables( fkCtl, [t + s for t, s in product(["scl", "rot", "pos"], "xyz")]) # self.setInversedParameters(fkCtl, middle=["posz", "rotx", "roty"]) parent = fkCtl self.fkBfr.append(fkBfr) self.fkCtl.append(fkCtl)
def createObjects(self): # Search for optional Upv marker to determine normal if "Upv" in self.translations(): upv_pos = self.translations("Upv") normal = self.translations("Upv") - self.translations("Root") else: normal = self.directions("Root", "z") upv_pos = None # Transformation direction = self.translations("Eff") - self.translations("Root") dirTfm = Transformation.lookAt(self.translations("Root"), direction, normal, "xz", self.negate()) ctlTfm = Transformation.lookAt(self.translations("Ctrl"), self.directions("Ctrl", "x"), self.directions("Ctrl", "z"), "xz", self.negate()) trgTfm = Transformation.lookAt(self.translations("Eff"), self.directions("Eff", "x"), self.directions("Eff", "z"), "xz", self.negate()) rigTfm = ctlTfm.copy(translation=self.translations("Root")) if self.settings("extraOffsetController") and self.settings( "keepRotationOffset"): offTfm = Transformation.lookAt(self.translations("Root"), self.directions("Root", "x"), self.directions("Root", "z"), "zy", self.negate()) offctlTfm = offTfm.copy(translation=self.translations("Ctrl")) else: offTfm = rigTfm offctlTfm = ctlTfm if not upv_pos: upv_pos = Vector3([0, 0, 10]) * dirTfm.asMatrix() upvTfm = dirTfm.copy(translation=upv_pos) # Direction self.dirRig = self.addRig(None, "Direction", dirTfm) # Up Vector upvBfr = self.addBfr(None, "Upv", upvTfm) if self.settings("addUpVController"): self.parentUpv = self.addCtl(upvBfr, "Upv", upvTfm, "diamond", size=.5, color=self.colorIk()) # self.addToSubControllers(self.parentUpv) else: self.parentUpv = upvBfr # Target self.targetBfr = self.addBfr(None, "Target", trgTfm) if self.settings("addTargetController"): # Target self.targetCtl = self.addCtl(self.targetBfr, "Target", trgTfm, "cube", size=1, color=self.colorIk()) # self.addToSubControllers(self.targetCtl) attributes.setKeyables(self.targetCtl, constants.ATTRS_T) # self.setInversedsettings(self.targetCtl, middle=["posy"]) if self.settings("addLocalController"): # Local Controller localBfr = self.addBfr(self.dirRig, "LocalNP", rigTfm) self.localRig = self.addRig(localBfr, "Local", rigTfm, "cube") # self.setNeutralPose(self.localRig) localBfr = self.addBfr(None, "Local", ctlTfm) self.localCtl = self.addCtl(localBfr, "Local", ctlTfm, "sphere", size=1, color=self.colorFk()) # self.setInversedsettings(self.localCtl, middle=["posx", "roty", "rotz"]) # Extra Offset Controller if self.settings("extraOffsetController"): self.offsetRig = self.addRig(self.localRig, "Offset", offTfm, "cube", size=.5) self.offsetCtl = self.addCtl(self.localCtl, "Offset", offctlTfm, "sphere", size=.5, color=self.colorIk())
def createObjects(self): # TRANSFORMATIONS positions = Vector3Array([ self.translations("Root"), self.translations("Knee"), self.translations("Ankle"), self.translations("Toe") ]) normal = Vector3.planeNormal(*positions[:3]) oriNormal = normal.copy() if self.negate(): normal *= -1 d = [(positions[i], positions[i + 1]) for i in range(3)] 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[:3]) # root rootTfm = Transformation.fromParts( translation=self.translations("Root")) # fk fkTfm = TransformationArray.chain(positions, normal, axis="xz", negativeSide=self.negate(), endTransform=False) lookAtEff = self.translations("Eff") - self.translations("Toe") fk3Tfm = Transformation.lookAt(self.translations("Toe"), lookAtEff, constants.AXIS_Y, "y-x", self.negate()) fkTfm = fkTfm.appended(fk3Tfm) for tfm, dist in izip(fkTfm, self.lengths): tfm.scale = Vector3( [dist * self.factor(), self.factor(), self.factor()]) bfrTfm = [ tfm.copy(rotation=fkTfm[max(i - 1, 0)].rotation) for i, tfm in enumerate(fkTfm) ] bfrTfm[0] = Transformation.lookAt(self.translations("Root"), constants.AXIS_NY, constants.AXIS_X, "x" + self.nsign() + "z", self.negate()) scale = bfrTfm[0].scale scale.x *= self.lengths[0] bfrTfm[0].scale = scale # ik ikbfrPos = Vector3([ self.translations("Root").x, self.translations("Toe").y, self.translations("Root").z ]) ikbfrTfm = Transformation.fromParts(translation=ikbfrPos) ikTfm = Transformation.lookAt(self.translations("Toe"), lookAtEff, constants.AXIS_Y, "zy", False) upvbfrTfm = Transformation.fromParts( translation=umath.upVector(self.translations("Root"), ikbfrPos, constants.AXIS_NX, ratio, False)) upvTfm = Transformation.fromParts( translation=umath.upVector(self.translations( "Root"), self.translations("Ankle"), oriNormal, ratio)) rollNormal = Vector3.planeNormal(self.translations("Root"), upvTfm.translation, self.translations("Toe")) if self.negate(): rollNormal *= -1 direction = self.translations("Root") - self.translations("Toe") rollbfrTfm = Transformation.lookAt(self.translations("Toe"), direction, rollNormal, "y-x", self.negate()) direction = self.translations("Ankle") - self.translations("Toe") rollTfm = Transformation.lookAt(self.translations("Toe"), direction, normal, "y-x", self.negate()) # extras scale = Vector3([self.factor(), self.factor(), self.factor()]) twisterTfm = {} interTfm = {} for i, (p, pos) in enumerate(izip(self.twp, positions[1:4])): twisterTfm[p] = [ fkTfm[i].copy(scale=scale), fkTfm[i].copy(translation=pos, scale=scale) ] interPos = twisterTfm[p][0].translation.lerp( twisterTfm[p][1].translation, .5) interTfm[p] = twisterTfm[p][0].copy(translation=interPos) ctrATfm = twisterTfm["Mid"][0] ctrBTfm = twisterTfm["Lwr"][0] # CONTROLLERS # Root self.rootBfr = self.addBfr(None, "Root", rootTfm) self.rootCtl = self.addCtl(self.rootBfr, "Root", rootTfm, "sphere", size=4, color=self.colorIk()) # self.addToSubControllers(self.rootCtl) attributes.setKeyables(self.rootCtl, constants.ATTRS_T) # self.setInversedParameters(self.rootCtl, middle=["posx"], side=["posx"]) # 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", size=8, so=[0, 1, 1], color=self.colorFk()) if self.settings("lockKneeRotation") and i == 2: keyables = [ "posx", "posy", "posz", "rotz", "sclx", "scly", "sclz" ] else: keyables = constants.ATTRS_TRS if i == 1: attributes.setRotOrder(ctl, "XZY") attributes.setKeyables(ctl, keyables) # self.setInversedParameters(ctl, middle=["posz", "roty", "rotx"]) 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.rollBfr = self.addBfr(self.rootBfr, "Roll", rollbfrTfm) self.rollCtl = self.addCtl(self.rollBfr, "Roll", rollTfm, "jaw", size=1, ro=(-90, 0, 0), color=self.colorIk()) #self.rollCtl = self.addCtl(self.rollBfr, "Roll", rollTfm, "jaw", size=2, po=(4,6,0), color=self.colorIk()) # self.setNeutralPose(self.rollCtl) attributes.setKeyables(self.rollCtl, ["rotx", "roty", "rotz", "rotorder", "scly"]) self.ikRef = self.addRig(self.rollCtl, "IkRef", fkTfm[-2]) self.ikBfr = self.addBfr(None, "Ik", ikbfrTfm) self.ikCtl = self.addCtl(self.ikBfr, "Ik", ikTfm, "cube", size=6, color=self.colorIk()) attributes.setKeyables(self.ikCtl, constants.ATTRS_TRS) # self.setInversedParameters(self.ikCtl, middle=["posx", "rotz", "roty"], side=["posx", "rotz", "roty"]) attributes.setRotOrder(self.ikCtl, "XZY") self.ikoffCtl = self.addCtl(self.ikCtl, "IkOffset", ikTfm, "null", size=4, color=self.colorIk()) # self.addToSubControllers(self.ikoffCtl) attributes.setKeyables(self.ikoffCtl, constants.ATTRS_TRS) # self.setInversedParameters(self.ikoffCtl, middle=["posx", "rotz", "roty"], side=["posx", "rotz", "roty"]) attributes.setRotOrder(self.ikoffCtl, "XZY") self.upvBfr = self.addBfr(None, "Upv", upvbfrTfm) self.upvCtl = self.addCtl(self.upvBfr, "Upv", upvTfm, "diamond", size=2, color=self.colorIk()) attributes.setKeyables(self.upvCtl, constants.ATTRS_T) # self.setInversedParameters(self.upvCtl, middle=["posx"], side=["posx"]) self.ctrABfr = self.addBfr(self.bones[0], "CenterA", ctrATfm) self.ctrACtl = self.addCtl(self.ctrABfr, "CenterA", ctrATfm, "sphere", size=5, color=self.colorIk()) # self.addToSubControllers(self.ctrACtl) attributes.setKeyables(self.ctrACtl, constants.ATTRS_TRS) # self.setInversedParameters(self.ctrACtl, middle=["posz", "roty", "rotx"]) self.ctrBBfr = self.addBfr(self.bones[1], "CenterB", ctrBTfm) self.ctrBCtl = self.addCtl(self.ctrBBfr, "CenterB", ctrBTfm, "sphere", size=5, color=self.colorIk()) # self.addToSubControllers(self.ctrBCtl) attributes.setKeyables(self.ctrBCtl, constants.ATTRS_TRS) # self.setInversedParameters(self.ctrBCtl, middle=["posz", "roty", "rotx"]) self.upvCrv = create.cnsCurve( self.getObjectName(config.USE_RIG, "UpvCrv"), [self.upvCtl, self.ctrACtl]) cmds.setAttr(self.upvCrv + ".template", True) self.footRef = self.addRig(self.ikoffCtl, "FootRef", ikTfm) # Twisters self.twisters = defaultdict(list) for p in self.twp: for s, tfm, factor in izip(["Start", "End"], twisterTfm[p], [1, -1]): twister = self.addRig(self.rootBfr, "Tw" + p + s, tfm, "sphere", po=[factor, 0, 0], so=[2, 1, 1]) # self.setNeutralPose(twister) self.twisters[p].append(twister) # Inter self.inters = {} for p in self.twp: self.inters[p] = self.addRig(self.rootBfr, "Inter" + p, interTfm[p], "pyramid")
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): # SIZE size = self.translations("Root").distance(self.translations("Eff")) fkSize = size * .8 ikSize = size * .75 hipSize = size * 1.25 # TRANSFORMATION normal = self.directions("Root", "z") positions = [] transforms = [] for i in range(self.ctl_count): lookat = self.translations("Eff") - self.translations("Root") t = Transformation.lookAt(self.translations("Root"), lookat, normal, self.settings("axis").lower(), self.negate()) t.translation = self.translations("Root").lerp( self.translations("Eff"), i / (self.ctl_count - 1.0)) positions.append(t.translation) transforms.append(t) # OBJECTS self.root = self.addRig(None, "Root") # Curves points = [positions[i] for i in [0, 2, 2, 4]] self.crvA = create.curve(self.getObjectName(config.USE_RIG, "CrvA"), points, closed=False, degree=3, parent=self.root) points = [positions[0].lerp(positions[-1], i / 6.0) for i in xrange(7)] self.crvB = create.bezier(self.getObjectName(config.USE_RIG, "CrvB"), self.root, points) # Controllers self.fkCtl = [] self.hookRig = [] fk_parent = self.root self.ikBfr = [] self.ikCtl = [] self.hookRig = [] for i, tfm in enumerate(transforms, start=1): # Fk Controllers fkCtl = self.addCtl(fk_parent, "Fk%s" % i, tfm, "sphere", size=fkSize, so=(1, 0, 1), color=self.colorFk()) # self.setInversedsettings(fkCtl, ["posx", "rotz", "roty"]) attributes.setRotOrder(fkCtl, "XYZ") fk_parent = fkCtl self.fkCtl.append(fkCtl) # Ik Controllers ikBfr = self.addBfr(self.root, "Ik%s" % i, tfm) self.ikBfr.append(ikBfr) # First ik ctl is a box if i in [1, 5]: ikCtl = self.addCtl(ikBfr, "Ik%s" % i, tfm, "cube", size=hipSize, so=(1, .25, 1), color=self.colorIk()) else: ikCtl = self.addCtl(ikBfr, "Ik%s" % i, tfm, "sphere", size=ikSize, so=(1, 0, 1), color=self.colorIk()) # if i in [2,4]: # self.addToSubControllers(ikCtl) # self.setInversedsettings(ikCtl, ["posx", "rotz", "roty"]) attributes.setRotOrder(ikCtl, "YZX") self.ikCtl.append(ikCtl) # Hooks if i == 1: hookRig = None else: hookRig = self.addRig(self.root, "Hook%s" % i, tfm, "cube", size=2) self.hookRig.append(hookRig) # Tangent parents self.aTan0 = self.addRig(self.ikCtl[0], "ATan0", transforms[2], "pyramid", size=.5) self.aTan1 = self.addRig(self.ikCtl[-1], "ATan1", transforms[2], "pyramid", size=.5) self.bTan0 = self.addRig(self.ikCtl[0], "BTan0", transforms[1], "pyramid", size=.5) self.bTan1 = self.addRig(self.ikCtl[2], "BTan1", transforms[1], "pyramid", size=.5) self.bTan2 = self.addRig(self.ikCtl[2], "BTan2", transforms[2], "pyramid", size=.5) self.bTan3 = self.addRig(self.ikCtl[2], "BTan3", transforms[3], "pyramid", size=.5) self.bTan4 = self.addRig(self.ikCtl[4], "BTan4", transforms[3], "pyramid", size=.5) if self.settings("breathing"): breathBfr = self.addBfr(self.hookRig[4], "Breathing", transforms[-1]) self.breathCtl = self.addCtl(breathBfr, "Breathing", transforms[-1], "lung", size=ikSize / 2.0, po=(0, 0, ikSize), color=self.colorIk()) # self.addToSubControllers(self.breathCtl) # self.setInversedsettings(self.breathCtl, ["posx", "rotz", "roty"]) attributes.setRotOrder(self.breathCtl, "YZX")
def createObjects(self): north = self.settings("north") south = self.settings("south") east = self.settings("east") west = self.settings("west") # TRANSFORMATION tfm = Transformation.lookAt(self.translations("Root"), self.directions("Root", "y"), self.directions("Root", "z"), axis="y" + self.sign() + "z", negativeSide=False) tfm.scale *= .5 if north != south and False in [ east, west ] or east != west and False in [north, south]: tfm.scale *= 2 # Label if not north and not south: dirn = .20 dirs = -.20 else: dirn = int(north) dirs = -int(south) if not east and not west: dire = .20 dirw = -.20 else: dire = int(east) dirw = -int(west) if self.settings("labelPosition") == "North": labelTfm = Transformation.fromParts( translation=Vector3([(dire + dirw) * .5, dirn + .1, 0])) align = "center" elif self.settings("labelPosition") == "South": labelTfm = Transformation.fromParts( translation=Vector3([(dire + dirw) * .5, dirs - .5, 0])) align = "center" elif self.settings("labelPosition") == "East": labelTfm = Transformation.fromParts( translation=Vector3([dire + .1, -.15, 0])) align = "left" elif self.settings("labelPosition") == "West": labelTfm = Transformation.fromParts( translation=Vector3([dirw - .1, -.15, 0])) align = "right" labelTfm *= tfm # CREATE OBJECTS # Frame scly = 1 * (north + south) if (north or south) else 0 sclx = 1 * (east + west) if (east or west) else 0 offy = .5 * (north - south) offx = .5 * (east - west) frame = self.addRig(None, "Frame", tfm, "cube", size=1, po=(offx, offy, 0), so=(sclx, scly, 0)) # Controller self.ctl = self.addCtl(frame, "1", tfm, "cube", size=1, so=(.5, .5, 0), color=self.colorFk()) attributes.setKeyables( self.ctl, ["posx", "posy"] ) # Faceware doesn't like if the posx is not keyable, so we make it keyable all the time... # Label labelText = self.settings("label") if ( self.settings("customLabel") and self.settings("label") != "") else self.settings("name") label = create.text(self.getObjectName(config.USE_RIG, "Label"), frame, labelTfm, labelText, size=.2, align=align) # RECONNECT for source, destination in self._connections: cmds.connectAttr(source, destination)
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)