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 addMarkerCamera(self, part, parent=None, matrix=None): parent = self.model() if parent is None else parent name = self.getMarkerName(part) if matrix is None: position = self.markerPositions[part] matrix = Transformation.fromParts(translation=position) return SystemMarker.createCamera(name, self, parent, matrix)
def exampleA(mirror=False, showWindow=False): '''Built a basic and a chain system. Set the basic to be dynamic and connect the chain to it. Args: mirror (bool): True to duplicate the systems on the right side showWindow (bool): True to popup Brigks Main Window ''' # Building Matrix for guide positions basicMatrices = dict( Part1=Transformation.fromParts(translation=Vector3([2, 2, 0])), Part2=Transformation.fromParts(translation=Vector3([4, 2, 0])), ) chainMatrices = dict( Part1=Transformation.fromParts(translation=Vector3([2, 3, 0])), Part2=Transformation.fromParts(translation=Vector3([4, 4, 0])), Part3=Transformation.fromParts(translation=Vector3([6, 3, 0])), ) # Create Guide, add a layer and a couple Systems guide = Guide() guide.setSettings(hideRig=False) guide.setSettings(hideJoints=False) layer = guide.addLayer("MyFirstLayer") basic = layer.addSystem("basic", "L", "Basic", basicMatrices) chain = layer.addSystem("chain", "L", "Chain", chainMatrices) # System Settings basic.setSettings(dynamic=True, dynamicAnimatable=True, strap=True) # Connections chain.addConnection("Root", "slotParent", key=basic.key(), slot="Part1") if mirror: for system in layer.systems().values(): system.duplicate(mirror=True) # Save edit guide.commit() # Build all rig guide.build() if showWindow: showWindow() return guide
def _convertTransformToMatrix(translation, rotation, scaling): rotation = rotation[1:] + rotation[:1] translation = Vector3(translation) rotation = Quaternion(rotation) scaling = Vector3(scaling) transform = Transformation.fromParts(translation, rotation, scaling) return transform.asMatrix().flattened()
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 addMarker(self, part, parent=None, matrix=None): '''Create a single SystemMarker Args: part (str): Unique part of the system object parent (str): Marker to be parented under matrix (Matrix): The matrix of the markers Returns: SystemMarker ''' parent = self.model() if parent is None else parent name = self.getMarkerName(part) if matrix is None and part in self.markerPositions: position = self.markerPositions[part] matrix = Transformation.fromParts(translation=position) return SystemMarker.create(name, self, parent, matrix)
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): self.axis = self.settings("axis").lower() # TRANSFORMATIONS positions = self.translations("Part") # Normal if self.count("Part") > 2: normal = Vector3.planeNormal(*positions[:3]) if normal.length() < 1E-6: normal = self.directions("Part1", "z") else: normal = self.directions("Part1", "z") ctlTfm = TransformationArray.chain(positions, normal, axis=self.axis+"z", negativeSide=self.negate(), endTransform=True) divTfm = Transformation() if self.negate(): divTfm.scaling = Vector3([-1,-1,-1]) length = self.translations("Part1").distance(self.translations("Part2")) / 5.0 # CONTROLLERS self._centers = [] # Left this dictionary in here, just in case we wanna revert back shdScl = [length,length,length] shdScl["xyz".index(self.axis)] = 0 se_keyableParameters = list(constants.ATTRS_TR) int_keyableParameters = list(constants.ATTRS_T) if self.settings("scaleWithControllers"): se_keyableParameters += ["scl"+s for s in "xyz" if s != self.axis] if self.settings("scaleWithInterControllers"): int_keyableParameters += ["scl"+s for s in "xyz" if s != self.axis] # Start Controller bfr = self.addBfr(None, "Start", ctlTfm[0]) if self.settings("startController"): ctl = self.addCtl(bfr, "Start", ctlTfm[0], "sphere", so=shdScl, color=self.colorFk()) attributes.setKeyables(ctl, se_keyableParameters) self._centers.append(ctl) else: self._centers.append(bfr) # Inter Controller for i, tfm in enumerate(ctlTfm[1:-1], start=1): bfr = self.addBfr(None, "Part%s"%i, tfm) if self.settings("interControllers"): ctl = self.addCtl(bfr, "Part%s"%i, tfm, "cube", size=2, so=shdScl, color=self.colorFk()) attributes.setKeyables(ctl, int_keyableParameters) self._centers.append(ctl) else: self._centers.append(bfr) # End Controller bfr = self.addBfr(None, "End", ctlTfm[-1]) if self.settings("endController"): ctl = self.addCtl(bfr, "End", ctlTfm[-1], "sphere", so=shdScl, color=self.colorFk()) attributes.setKeyables(ctl, se_keyableParameters) self._centers.append(ctl) else: self._centers.append(bfr) # CURVE # tangent = self.settings("tangentDistance") if self.settings("tangent") else None self.crv = create.cnsCurve(self.getObjectName(config.USE_RIG, "Crv"), self._centers, closed=False, degree=3) self.length = cmds.arclen(self.crv) # DIVISIONS parent = self._centers[0] self.start_iter = 0 if self.settings("startDeformer") and not self.settings("tangent") else 1 if self.settings("tangent"): self.interDiv = [self.addRig(parent, "Div%s"%i, divTfm, "cube", size=2) for i in xrange(1, self.settings("interDeformers")+1)] if self.settings("untwistDeformers"): self.unTwistDiv = [self.addRig(parent, "Untwist%s"%i, divTfm, "cube", size=1) for i in xrange(1, self.settings("interDeformers")+1)] self.unTwistStart = self.addRig(self._centers[0], "UntwistStart", ctlTfm[0], "cube", size=1) self.unTwistEnd = self.addRig(self._centers[-1], "UntwistEnd", ctlTfm[-1], "cube", size=1) else: div_count = self.settings("interDeformers") + self.settings("startDeformer") + self.settings("endDeformer") self.interDiv = [self.addRig(parent, "Div%s"%i, divTfm, "cube", size=2) for i in xrange(self.start_iter, div_count+self.start_iter)] if self.settings("untwistDeformers"): self.unTwistDiv = [self.addRig(parent, "Untwist%s"%i, divTfm, "cube", size=1) for i in xrange(self.start_iter, div_count+self.start_iter)]
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): # 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)
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): # 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 chain(name, parent, positions, normal=None, axis="xz", negate=False, size=1, color=None): ''' Creates an Ik chain of joints Args: name (str): Name of the newly created Node parent (str): parent of the node. None if no parent positions (list of triplet): position of the node normal (triplet of float): axis (str): size (int): size off the text. Default is 40 which is close to 1 maya unit high. color (list of float): Color of the curve. Returns: (str, str, str): joints, effector, handle ''' if normal is None: if len(positions) >= 3: normal = Vector3.planeNormal(positions, normalize=True) else: normal = Vector(0, 0, -1) # Transform.setMirrorMethod(Transform.inversedRotation) transforms = TransformationArray.chain(positions, normal, axis, negate, endTransform=True) d = [(positions[i], positions[i + 1]) for i in range(len(positions) - 1)] lengths = [Vector3.distance(a, b) for a, b in d] + [1] joints = [] jointParent = parent for i, tfm in enumerate(transforms, start=1): jnt = joint(name + "%02d" % i, jointParent, tfm, color, useJointOrient=True) jointParent = jnt joints.append(jnt) handle, effector = cmds.ikHandle(startJoint=joints[0], endEffector=joints[-1]) if negate: upv = Vector3([0, -1, 0]) * transforms[0].asMatrix() tfm = Transformation.fromParts(translation=transforms[0].translation) upv = upv * tfm.asMatrix().inverse() cmds.setAttr(handle + ".poleVectorX", upv.x) cmds.setAttr(handle + ".poleVectorY", upv.y) cmds.setAttr(handle + ".poleVectorZ", upv.z) effector = cmds.rename(effector, name + "Eff") handle = cmds.rename(handle, name + "Hdl") if parent: handle = cmds.parent(handle, parent, absolute=True)[0] cmds.delete(joints.pop(-1)) return joints, effector, handle
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 # TRANSFORMATION # Positions positions = self.translations("Part") # Normal if self.count("Part") > 2: normal = Vector3.planeNormal(*positions[:3]) if normal.length() < 1E-6: normal = self.directions("Part1", "z") if self.negate(): normal *= -1 else: normal = self.directions("Part1", "z") boneTfm = TransformationArray.chain(positions, normal, axis="xz", negativeSide=self.negate(), endTransform=False) d = [(positions[i], positions[i + 1]) for i in range(self.count("Part") - 1)] boneLen = [Vector3.distance(a, b) for a, b in d] self.setSettings(count=len(boneLen), lengths=boneLen) if self.settings("setNeutralPose"): bfrTfm = boneTfm else: bfrTfm = [ tfm.copy(rotation=boneTfm[max(i - 1, 0)].rotation) for i, tfm in enumerate(boneTfm) ] if self.isIk: ikTfm = boneTfm[-1].copy(translation=positions[-1]) # Up Vector if self.count("Part") > 2: upvTfm = Transformation.fromParts( translation=umath.upVector(positions[0], positions[2], normal, ratio=1, negate=self.negate())) else: upvTfm = Transformation.fromParts( translation=umath.upVector(positions[0], positions[1], normal, ratio=1, negate=self.negate())) if self.settings("dynamic"): tgtTfm = boneTfm[1:] tgtTfm = tgtTfm.appended( boneTfm[-1].copy(translation=positions[-1])) # OBJECTS # Root self._root = self.addRig(None, "Root", tfm=boneTfm[0]) # FK Controllers ----------------------------------------- if self.isFk: self.fkBfr = [] self.fkCtl = [] self.fkDir = [] parent = self._root for i, (tfm, btfm, dist) in enumerate(izip(boneTfm, bfrTfm, boneLen), start=1): fkBfr = self.addBfr(parent, "Fk{}".format(i), tfm=btfm) fkCtl = self.addCtl(fkBfr, "Fk{}".format(i), tfm, "sphere", so=[0, 1, 1], color=self.colorFk()) # self.setInversedsettings(fkCtl, middle=["posz", "rotx", "roty"]) attributes.setRotOrder(fkCtl, self.settings("defaultRotationOrder")) parent = fkCtl self.fkBfr.append(fkBfr) self.fkCtl.append(fkCtl) bone = self.addRig(fkCtl, "Dir{}".format(i), tfm, "pyramid", size=1, ro=[0, 0, -90], so=[.5, self.factor() * dist, .5]) self.fkDir.append(bone) # Add the end reference for ikfk matching tfm = boneTfm[-1].copy(translation=positions[-1]) self._tip = self.addRig(self.fkCtl[-1], "Tip", tfm) # IK Controllers -------------------------------------- if self.isIk: # Ik Controller self.ikBfr = self.addBfr(self._root, "Ik", tfm=ikTfm) self.ikCtl = self.addCtl(self.ikBfr, "Ik", ikTfm, "cube", size=2, color=self.colorIk()) attributes.setKeyables(self.ikCtl, constants.ATTRS_TR) # UpVector Controller self.upvBfr = self.addBfr(self._root, "UpV", upvTfm) self.upvCtl = self.addCtl(self.upvBfr, "UpV", upvTfm, "diamond", color=self.colorIk()) attributes.setKeyables(self.upvCtl, constants.ATTRS_T) # Ik Chain self.ikBones, self.effector, self.handle = create.chain( self.getObjectName(config.USE_RIG, "Ik"), self._root, positions, normal, negate=self.negate()) self.upvCrv = create.cnsCurve( [self.ikChn.root(), self.upvCtl, self.ikChn.effector()], "UpvCrv") cmds.setAttr(self.upvCrv + ".template", True) # Bones ------------------------------- if self.isFkIk: # or (self.isFk and self.settings("dynamic")): self.bones = [] parent = self._root for i, (tfm, dist) in enumerate(izip(boneTfm, boneLen), start=1): bone = self.addRig(parent, "Bone{}".format(i), tfm, "cube", size=1, po=[self.factor() * dist * .5, 0, 0], so=[dist, .5, .5]) self.bones.append(bone) parent = bone elif self.isFk: self.bones = self.fkCtl else: self.bones = self.ikChn.bones() # Dynamic ---------------------------- if self.settings("dynamic"): self.dfmHost = [] self.dynCns = [] self.target = [] self.harmonic = [] self.dynBone = [] parent = self._root for i, (bone, tfmA, tfmB) in enumerate(izip(self.bones, boneTfm, tgtTfm), start=1): dynCns = self.addRig(parent, "DynCns{}".format(i), tfmA, "cube", size=1) self.dynCns.append(dynCns) target = self.addRig(dynCns, "Target{}".format(i), tfmB, "null", size=1) self.target.append(target) harmonic = self.addRig(target, "Harmonic{}".format(i), tfmB, "diamond", size=1) self.harmonic.append(harmonic) dynBone = self.addRig(parent, "Dynamic{}".format(i), tfmA, "pyramid", size=1, ro=[0, 0, -90], so=[1, self.factor(), 1]) self.dynBone.append(dynBone) parent = dynBone self.dfmHost.append(dynBone) else: self.dfmHost = self.bones # Strap ---------------------------- if self.settings("strap"): endTfm = boneTfm[-1].copy(translation=positions[-1]) self.end = self.addRig(self.dfmHost[-1], "End", endTfm)
def createTransform(t=None, r=None, s=None): return Transformation.fromParts(translation=t, rotation=r, scale=s)