def initialHierarchy(self): mgear.log("Initial Hierarchy") # -------------------------------------------------- # Model self.model = pri.addTransformFromPos(None, self.options["rig_name"]) att.lockAttribute(self.model) # -------------------------------------------------- # Global Ctl self.global_ctl = self.addCtl(self.model, "global_C0_ctl", dt.Matrix(), self.options["C_color_fk"], "crossarrow", w=10) # -------------------------------------------------- # INFOS self.isRig_att = att.addAttribute(self.model, "is_rig", "bool", True) self.rigName_att = att.addAttribute(self.model, "rig_name", "string", self.options["rig_name"]) self.user_att = att.addAttribute(self.model, "user", "string", getpass.getuser()) self.isWip_att = att.addAttribute(self.model, "wip", "bool", self.options["mode"] != 0) self.date_att = att.addAttribute(self.model, "date", "string", str(datetime.datetime.now())) self.mayaVersion_att = att.addAttribute( self.model, "maya_version", "string", str(mel.eval("getApplicationVersionAsFloat"))) self.gearVersion_att = att.addAttribute(self.model, "gear_version", "string", mgear.getVersion()) self.synoptic_att = att.addAttribute(self.model, "synoptic", "string", str(self.options["synoptic"])) self.comments_att = att.addAttribute(self.model, "comments", "string", str(self.options["comments"])) self.ctlVis_att = att.addAttribute(self.model, "ctl_vis", "bool", True) self.shdVis_att = att.addAttribute(self.model, "shd_vis", "bool", False) self.qsA_att = att.addAttribute(self.model, "quickselA", "string", "") self.qsB_att = att.addAttribute(self.model, "quickselB", "string", "") self.qsC_att = att.addAttribute(self.model, "quickselC", "string", "") self.qsD_att = att.addAttribute(self.model, "quickselD", "string", "") self.qsE_att = att.addAttribute(self.model, "quickselE", "string", "") self.qsF_att = att.addAttribute(self.model, "quickselF", "string", "") # -------------------------------------------------- # UI SETUP AND ANIM self.oglLevel_att = att.addAttribute(self.model, "ogl_level", "long", 0, None, None, 0, 3) # -------------------------------------------------- # Basic set of null if self.options["shadow_rig"]: self.shd_org = pri.addTransformFromPos(self.model, "shd_org") connectAttr(self.shdVis_att, self.shd_org.attr("visibility"))
def initialHierarchy(self): """ Build the initial hierarchy of the rig. Create the rig model, the main properties, and a couple of base organisation nulls. Get the global size of the rig. """ mgear.log("Initial Hierarchy") # -------------------------------------------------- # Model self.model = pri.addTransformFromPos(None, self.options["rig_name"]) att.lockAttribute(self.model) # -------------------------------------------------- # Global Ctl self.global_ctl = self.addCtl(self.model, "global_C0_ctl", dt.Matrix(), self.options["C_color_fk"], "crossarrow", w=10) att.setRotOrder(self.global_ctl, "ZXY") # -------------------------------------------------- # Setup in world Space self.setupWS = pri.addTransformFromPos(self.model, "setup") att.lockAttribute(self.setupWS) # -------------------------------------------------- # INFOS self.isRig_att = att.addAttribute(self.model, "is_rig", "bool", True) self.rigName_att = att.addAttribute(self.model, "rig_name", "string", self.options["rig_name"]) self.user_att = att.addAttribute(self.model, "user", "string", getpass.getuser()) self.isWip_att = att.addAttribute(self.model, "wip", "bool", self.options["mode"] != 0) self.date_att = att.addAttribute(self.model, "date", "string", str(datetime.datetime.now())) self.mayaVersion_att = att.addAttribute(self.model, "maya_version", "string", str(pm.mel.eval("getApplicationVersionAsFloat"))) self.gearVersion_att = att.addAttribute(self.model, "gear_version", "string", mgear.getVersion()) self.synoptic_att = att.addAttribute(self.model, "synoptic", "string", str(self.options["synoptic"])) self.comments_att = att.addAttribute(self.model, "comments", "string", str(self.options["comments"])) self.ctlVis_att = att.addAttribute(self.model, "ctl_vis", "bool", True) self.jntVis_att = att.addAttribute(self.model, "jnt_vis", "bool", True) self.qsA_att = att.addAttribute(self.model, "quickselA", "string", "") self.qsB_att = att.addAttribute(self.model, "quickselB", "string", "") self.qsC_att = att.addAttribute(self.model, "quickselC", "string", "") self.qsD_att = att.addAttribute(self.model, "quickselD", "string", "") self.qsE_att = att.addAttribute(self.model, "quickselE", "string", "") self.qsF_att = att.addAttribute(self.model, "quickselF", "string", "") self.rigGroups = self.model.addAttr( "rigGroups", at='message', m=1 ) self.rigPoses = self.model.addAttr( "rigPoses", at='message', m=1 ) # -------------------------------------------------- # Basic set of null if self.options["joint_rig"]: self.jnt_org = pri.addTransformFromPos(self.model, "jnt_org") pm.connectAttr(self.jntVis_att, self.jnt_org.attr("visibility"))
def initialHierarchy(self): """ Create the inital structure for the rig. """ # Root self.root = primitive.addTransformFromPos(self.model, self.getName("root"), self.guide.pos["root"]) self.addToGroup(self.root, names=["componentsRoots"]) # infos attribute.addAttribute(self.root, "componentType", "string", self.guide.compType) attribute.addAttribute(self.root, "componentName", "string", self.guide.compName) attribute.addAttribute(self.root, "componentVersion", "string", str(self.guide.version)[1:-1]) attribute.addAttribute(self.root, "componentAuthor", "string", self.guide.author) attribute.addAttribute(self.root, "componentURL", "string", self.guide.url) attribute.addAttribute(self.root, "componentEmail", "string", self.guide.email) # joint -------------------------------- if self.options["joint_rig"]: self.component_jnt_org = primitive.addTransform( self.rig.jnt_org, self.getName("jnt_org")) # The initial assigment of the active jnt and the parent relative # jnt is the same, later will be updated base in the user options self.active_jnt = self.component_jnt_org self.parent_relative_jnt = self.component_jnt_org return
def initialHierarchy(self): mgear.log("Initial Hierarchy") # -------------------------------------------------- # Model self.model = pri.addTransformFromPos(None, self.options["rig_name"]) att.lockAttribute(self.model) # -------------------------------------------------- # Global Ctl self.global_ctl = self.addCtl(self.model, "global_C0_ctl", dt.Matrix(), self.options["C_color_fk"], "crossarrow", w=10) # -------------------------------------------------- # INFOS self.isRig_att = att.addAttribute(self.model, "is_rig", "bool", True) self.rigName_att = att.addAttribute(self.model, "rig_name", "string", self.options["rig_name"]) self.user_att = att.addAttribute(self.model, "user", "string", getpass.getuser()) self.isWip_att = att.addAttribute(self.model, "wip", "bool", self.options["mode"] != 0) self.date_att = att.addAttribute(self.model, "date", "string", str(datetime.datetime.now())) self.mayaVersion_att = att.addAttribute(self.model, "maya_version", "string", str(mel.eval("getApplicationVersionAsFloat"))) self.gearVersion_att = att.addAttribute(self.model, "gear_version", "string", mgear.getVersion()) self.synoptic_att = att.addAttribute(self.model, "synoptic", "string", str(self.options["synoptic"])) self.comments_att = att.addAttribute(self.model, "comments", "string", str(self.options["comments"])) self.ctlVis_att = att.addAttribute(self.model, "ctl_vis", "bool", True) self.shdVis_att = att.addAttribute(self.model, "shd_vis", "bool", False) self.qsA_att = att.addAttribute(self.model, "quickselA", "string", "") self.qsB_att = att.addAttribute(self.model, "quickselB", "string", "") self.qsC_att = att.addAttribute(self.model, "quickselC", "string", "") self.qsD_att = att.addAttribute(self.model, "quickselD", "string", "") self.qsE_att = att.addAttribute(self.model, "quickselE", "string", "") self.qsF_att = att.addAttribute(self.model, "quickselF", "string", "") # -------------------------------------------------- # UI SETUP AND ANIM self.oglLevel_att = att.addAttribute(self.model, "ogl_level", "long", 0, None, None, 0, 3) # -------------------------------------------------- # Basic set of null if self.options["shadow_rig"]: self.shd_org = pri.addTransformFromPos(self.model, "shd_org") connectAttr(self.shdVis_att, self.shd_org.attr("visibility"))
def initialHierarchy(self): # Root self.root = pri.addTransformFromPos(self.model, self.getName("root"), self.guide.pos["root"]) # Shd -------------------------------- if self.options["shadow_rig"]: self.shd_org = pri.addTransform(self.rig.shd_org, self.getName("shd_org")) return
def addObjects(self): self.normal = self.guide.blades["blade"].z self.binormal = self.guide.blades["blade"].x self.isFk = self.settings["mode"] != 1 self.isIk = self.settings["mode"] != 0 self.isFkIk = self.settings["mode"] == 2 # FK controlers ------------------------------------ if self.isFk: self.fk_npo = [] self.fk_ctl = [] parent = self.root for i, t in enumerate(tra.getChainTransform(self.guide.apos, self.normal, self.negate)): dist = vec.getDistance(self.guide.apos[i], self.guide.apos[i+1]) fk_npo = pri.addTransform(parent, self.getName("fk%s_npo"%i), t) fk_ctl = self.addCtl(fk_npo, "fk%s_ctl"%i, t, self.color_fk, "cube", w=dist, h=self.size*.1, d=self.size*.1, po=dt.Vector(dist*.5*self.n_factor,0,0)) parent = fk_ctl self.fk_npo.append(fk_npo) self.fk_ctl.append(fk_ctl) # IK controlers ------------------------------------ if self.isIk: normal = vec.getTransposedVector(self.normal, [self.guide.apos[0], self.guide.apos[1]], [self.guide.apos[-2], self.guide.apos[-1]]) t = tra.getTransformLookingAt(self.guide.apos[-2], self.guide.apos[-1], normal, "xy", self.negate) t = tra.setMatrixPosition(t, self.guide.apos[-1]) self.ik_cns = pri.addTransform(self.root, self.getName("ik_cns"), t) self.ikcns_ctl = self.addCtl(self.ik_cns, "ikcns_ctl", t, self.color_ik, "null", w=self.size) self.ik_ctl = self.addCtl(self.ikcns_ctl, "ik_ctl", t, self.color_ik, "cube", w=self.size*.3, h=self.size*.3, d=self.size*.3) v = self.guide.apos[-1] - self.guide.apos[0] v = v ^ self.normal v.normalize() v *= self.size v += self.guide.apos[1] self.upv_cns = pri.addTransformFromPos(self.root, self.getName("upv_cns"), v) self.upv_ctl = self.addCtl(self.upv_cns, "upv_ctl", tra.getTransform(self.upv_cns), self.color_ik, "diamond", w=self.size*.1) # Chain self.chain = pri.add2DChain(self.root, self.getName("chain"), self.guide.apos, self.normal, self.negate) self.ikh = pri.addIkHandle(self.root, self.getName("ikh"), self.chain) # Chain of deformers ------------------------------- self.loc = [] parent = self.root for i, t in enumerate(tra.getChainTransform(self.guide.apos, self.normal, self.negate)): loc = pri.addTransform(parent, self.getName("%s_loc"%i), t) self.addShadow(loc, i) self.loc.append(loc) parent = loc
def initialHierarchy(self): """ Create the inital structure for the rig. """ # Root self.root = pri.addTransformFromPos(self.model, self.getName("root"), self.guide.pos["root"]) # joint -------------------------------- if self.options["joint_rig"]: self.component_jnt_org = pri.addTransform(self.rig.jnt_org, self.getName("jnt_org")) # The initial assigment of the active jnt and the parent relative jnt is the same, later will be updated base in the user options self.active_jnt = self.component_jnt_org self.parent_relative_jnt = self.component_jnt_org return
def addObjects(self): """Add all the objects needed to create the component.""" self.WIP = self.options["mode"] self.normal = self.getNormalFromPos(self.guide.apos) self.length0 = vector.getDistance(self.guide.apos[0], self.guide.apos[1]) self.length1 = vector.getDistance(self.guide.apos[1], self.guide.apos[2]) self.length2 = vector.getDistance(self.guide.apos[2], self.guide.apos[3]) # 1 bone chain for upv ref self.legChainUpvRef = primitive.add2DChain( self.root, self.getName("legUpvRef%s_jnt"), [self.guide.apos[0], self.guide.apos[2]], self.normal, False, self.WIP) self.legChainUpvRef[1].setAttr( "jointOrientZ", self.legChainUpvRef[1].getAttr("jointOrientZ") * -1) # extra neutral pose t = transform.getTransformFromPos(self.guide.apos[0]) self.root_npo = primitive.addTransform(self.root, self.getName("root_npo"), t) self.root_ctl = self.addCtl(self.root_npo, "root_ctl", t, self.color_fk, "circle", w=self.length0 / 6, tp=self.parentCtlTag) # FK Controlers ----------------------------------- t = transform.getTransformLookingAt(self.guide.apos[0], self.guide.apos[1], self.normal, "xz", self.negate) self.fk0_npo = primitive.addTransform(self.root_ctl, self.getName("fk0_npo"), t) po_vec = datatypes.Vector(.5 * self.length0 * self.n_factor, 0, 0) self.fk0_ctl = self.addCtl(self.fk0_npo, "fk0_ctl", t, self.color_fk, "cube", w=self.length0, h=self.size * .1, d=self.size * .1, po=po_vec, tp=self.root_ctl) attribute.setKeyableAttributes( self.fk0_ctl, ["tx", "ty", "tz", "ro", "rx", "ry", "rz", "sx"]) t = transform.getTransformLookingAt(self.guide.apos[1], self.guide.apos[2], self.normal, "xz", self.negate) self.fk1_npo = primitive.addTransform(self.fk0_ctl, self.getName("fk1_npo"), t) po_vec = datatypes.Vector(.5 * self.length1 * self.n_factor, 0, 0) self.fk1_ctl = self.addCtl(self.fk1_npo, "fk1_ctl", t, self.color_fk, "cube", w=self.length1, h=self.size * .1, d=self.size * .1, po=po_vec, tp=self.fk0_ctl) attribute.setKeyableAttributes( self.fk1_ctl, ["tx", "ty", "tz", "ro", "rx", "ry", "rz", "sx"]) t = transform.getTransformLookingAt(self.guide.apos[2], self.guide.apos[3], self.normal, "xz", self.negate) self.fk2_npo = primitive.addTransform(self.fk1_ctl, self.getName("fk2_npo"), t) po_vec = datatypes.Vector(.5 * self.length2 * self.n_factor, 0, 0) self.fk2_ctl = self.addCtl(self.fk2_npo, "fk2_ctl", t, self.color_fk, "cube", w=self.length2, h=self.size * .1, d=self.size * .1, po=po_vec, tp=self.fk1_ctl) attribute.setKeyableAttributes(self.fk2_ctl) self.fk_ctl = [self.fk0_ctl, self.fk1_ctl, self.fk2_ctl] for x in self.fk_ctl: attribute.setInvertMirror(x, ["tx", "ty", "tz"]) # IK Controlers ----------------------------------- self.ik_cns = primitive.addTransformFromPos(self.root_ctl, self.getName("ik_cns"), self.guide.pos["ankle"]) self.ikcns_ctl = self.addCtl(self.ik_cns, "ikcns_ctl", transform.getTransformFromPos( self.guide.pos["ankle"]), self.color_ik, "null", w=self.size * .12, tp=self.root_ctl) attribute.setInvertMirror(self.ikcns_ctl, ["tx"]) m = transform.getTransformLookingAt(self.guide.pos["ankle"], self.guide.pos["eff"], self.x_axis, "zx", False) self.ik_ctl = self.addCtl(self.ikcns_ctl, "ik_ctl", transform.getTransformFromPos( self.guide.pos["ankle"]), self.color_ik, "cube", w=self.size * .12, h=self.size * .12, d=self.size * .12, tp=self.ikcns_ctl) attribute.setKeyableAttributes(self.ik_ctl) attribute.setRotOrder(self.ik_ctl, "XZY") attribute.setInvertMirror(self.ik_ctl, ["tx", "ry", "rz"]) # upv v = self.guide.apos[2] - self.guide.apos[0] v = self.normal ^ v v.normalize() v *= self.size * .5 v += self.guide.apos[1] self.upv_cns = primitive.addTransformFromPos(self.ik_ctl, self.getName("upv_cns"), v) self.upv_ctl = self.addCtl(self.upv_cns, "upv_ctl", transform.getTransform(self.upv_cns), self.color_ik, "diamond", w=self.size * .12, tp=self.root_ctl) if self.settings["mirrorMid"]: if self.negate: self.upv_cns.rz.set(180) self.upv_cns.sy.set(-1) else: attribute.setInvertMirror(self.upv_ctl, ["tx"]) attribute.setKeyableAttributes(self.upv_ctl, self.t_params) # References -------------------------------------- self.ik_ref = primitive.addTransform( self.ik_ctl, self.getName("ik_ref"), transform.getTransform(self.ik_ctl)) self.fk_ref = primitive.addTransform( self.fk_ctl[2], self.getName("fk_ref"), transform.getTransform(self.ik_ctl)) # Chain -------------------------------------------- # The outputs of the ikfk2bone solver self.bone0 = primitive.addLocator( self.root_ctl, self.getName("0_bone"), transform.getTransform(self.fk_ctl[0])) self.bone0_shp = self.bone0.getShape() self.bone0_shp.setAttr("localPositionX", self.n_factor * .5) self.bone0_shp.setAttr("localScale", .5, 0, 0) self.bone0.setAttr("sx", self.length0) self.bone0.setAttr("visibility", False) self.bone1 = primitive.addLocator( self.root_ctl, self.getName("1_bone"), transform.getTransform(self.fk_ctl[1])) self.bone1_shp = self.bone1.getShape() self.bone1_shp.setAttr("localPositionX", self.n_factor * .5) self.bone1_shp.setAttr("localScale", .5, 0, 0) self.bone1.setAttr("sx", self.length1) self.bone1.setAttr("visibility", False) self.ctrn_loc = primitive.addTransformFromPos(self.root_ctl, self.getName("ctrn_loc"), self.guide.apos[1]) self.eff_loc = primitive.addTransformFromPos(self.root_ctl, self.getName("eff_loc"), self.guide.apos[2]) # tws_ref t = transform.getRotationFromAxis(datatypes.Vector(0, -1, 0), self.normal, "xz", self.negate) t = transform.setMatrixPosition(t, self.guide.pos["ankle"]) self.tws_ref = primitive.addTransform(self.eff_loc, self.getName("tws_ref"), t) # Mid Controler ------------------------------------ t = transform.getTransform(self.ctrn_loc) self.mid_cns = primitive.addTransform(self.ctrn_loc, self.getName("mid_cns"), t) self.mid_ctl = self.addCtl(self.mid_cns, "mid_ctl", t, self.color_ik, "sphere", w=self.size * .2, tp=self.root_ctl) if self.settings["mirrorMid"]: if self.negate: self.mid_cns.rz.set(180) self.mid_cns.sz.set(-1) else: attribute.setInvertMirror(self.mid_ctl, ["tx", "ty", "tz"]) # Twist references --------------------------------- x = datatypes.Vector(0, -1, 0) x = x * transform.getTransform(self.eff_loc) z = datatypes.Vector(self.normal.x, self.normal.y, self.normal.z) z = z * transform.getTransform(self.eff_loc) m = transform.getRotationFromAxis(x, z, "xz", self.negate) m = transform.setMatrixPosition(m, transform.getTranslation(self.ik_ctl)) self.rollRef = primitive.add2DChain(self.root, self.getName("rollChain"), self.guide.apos[:2], self.normal, self.negate, self.WIP) self.tws0_loc = primitive.addTransform( self.rollRef[0], self.getName("tws0_loc"), transform.getTransform(self.fk_ctl[0])) self.tws0_rot = primitive.addTransform( self.tws0_loc, self.getName("tws0_rot"), transform.getTransform(self.fk_ctl[0])) self.tws1_loc = primitive.addTransform( self.ctrn_loc, self.getName("tws1_loc"), transform.getTransform(self.ctrn_loc)) self.tws1_rot = primitive.addTransform( self.tws1_loc, self.getName("tws1_rot"), transform.getTransform(self.ctrn_loc)) self.tws2_loc = primitive.addTransform( self.root_ctl, self.getName("tws2_loc"), transform.getTransform(self.tws_ref)) self.tws2_rot = primitive.addTransform( self.tws2_loc, self.getName("tws2_rot"), transform.getTransform(self.tws_ref)) self.tws2_rot.setAttr("sx", .001) # Divisions ---------------------------------------- # We have at least one division at the start, the end and one for # the elbow. + 2 for knee angle control self.divisions = self.settings["div0"] + self.settings["div1"] + 3 + 2 self.div_cns = [] for i in range(self.divisions): div_cns = primitive.addTransform(self.root_ctl, self.getName("div%s_loc" % i)) self.div_cns.append(div_cns) self.jnt_pos.append([div_cns, i]) # End reference ------------------------------------ # To help the deformation on the ankle self.end_ref = primitive.addTransform(self.tws2_rot, self.getName("end_ref"), m) self.jnt_pos.append([self.end_ref, 'end']) # match IK FK references self.match_fk0_off = primitive.addTransform( self.root, self.getName("matchFk0_npo"), transform.getTransform(self.fk_ctl[1])) self.match_fk0 = primitive.addTransform( self.match_fk0_off, self.getName("fk0_mth"), transform.getTransform(self.fk_ctl[0])) self.match_fk1_off = primitive.addTransform( self.root, self.getName("matchFk1_npo"), transform.getTransform(self.fk_ctl[2])) self.match_fk1 = primitive.addTransform( self.match_fk1_off, self.getName("fk1_mth"), transform.getTransform(self.fk_ctl[1])) self.match_fk2 = primitive.addTransform( self.ik_ctl, self.getName("fk2_mth"), transform.getTransform(self.fk_ctl[2])) self.match_ik = primitive.addTransform( self.fk2_ctl, self.getName("ik_mth"), transform.getTransform(self.ik_ctl)) self.match_ikUpv = primitive.addTransform( self.fk0_ctl, self.getName("upv_mth"), transform.getTransform(self.upv_ctl))
def addObjects(self): """Add all the objects needed to create the component.""" self.normal = self.getNormalFromPos(self.guide.apos) self.binormal = self.getBiNormalFromPos(self.guide.apos) self.length0 = vector.getDistance(self.guide.apos[0], self.guide.apos[1]) self.length1 = vector.getDistance(self.guide.apos[1], self.guide.apos[2]) self.length2 = vector.getDistance(self.guide.apos[2], self.guide.apos[3]) # FK Controlers ----------------------------------- # *ms* set npo @ Tpose, to make the fk rotation work # best with rot order"yzx" self.fk_cns = primitive.addTransformFromPos(self.root, self.getName("fk_cns"), self.guide.apos[0]) vec_offset = ((self.guide.apos[1] - self.guide.apos[0]) * [1, 0, 0]) tpv = self.guide.apos[0] + vec_offset t = transform.getTransformLookingAt(self.guide.apos[0], tpv, self.normal, "xz", self.negate) # *ms* add FK isolation self.fk0_npo = primitive.addTransform(self.fk_cns, self.getName("fk0_npo"), t) t = transform.getTransformLookingAt(self.guide.apos[0], self.guide.apos[1], self.normal, "xz", self.negate) po_off = datatypes.Vector(.35 * self.length0 * self.n_factor, 0, 0) self.fk0_ctl = self.addCtl(self.fk0_npo, "fk0_ctl", t, self.color_fk, "cube", w=self.length0 * .7, h=self.size * .1, d=self.size * .1, po=po_off, tp=self.parentCtlTag) attribute.setKeyableAttributes(self.fk0_ctl) # *ms* add fk roll control Simage style po_off = datatypes.Vector(.85 * self.length0 * self.n_factor, 0, 0) self.fk0_roll_ctl = self.addCtl(self.fk0_ctl, "fk0_roll_ctl", t, self.color_fk, "cube", w=self.length0 * .3, h=self.size * .1, d=self.size * 0.1, po=po_off, tp=self.fk0_ctl) attribute.setRotOrder(self.fk0_roll_ctl, "YZX") attribute.setKeyableAttributes(self.fk0_roll_ctl, ["rx"]) self.fk0_mtx = primitive.addTransform(self.root, self.getName("fk0_mtx"), t) t = transform.setMatrixPosition(t, self.guide.apos[1]) self.fk1_ref = primitive.addTransform(self.fk0_roll_ctl, self.getName("fk1_ref"), t) self.fk1_loc = primitive.addTransform(self.root, self.getName("fk1_loc"), t) t = transform.getTransformLookingAt(self.guide.apos[1], self.guide.apos[2], self.normal, "xz", self.negate) self.fk1_npo = primitive.addTransform(self.fk1_loc, self.getName("fk1_npo"), t) po_off = datatypes.Vector(.35 * self.length1 * self.n_factor, 0, 0) self.fk1_ctl = self.addCtl(self.fk1_npo, "fk1_ctl", t, self.color_fk, "cube", w=self.length1 * .7, h=self.size * .1, d=self.size * .1, po=po_off, tp=self.fk0_roll_ctl) attribute.setKeyableAttributes(self.fk1_ctl) self.fk1_mtx = primitive.addTransform(self.fk1_ctl, self.getName("fk1_mtx"), t) po_off = datatypes.Vector(.85 * self.length1 * self.n_factor, 0, 0) self.fk1_roll_ctl = self.addCtl(self.fk1_ctl, "fk1_roll_ctl", t, self.color_fk, "cube", w=self.length1 * .3, h=self.size * .1, d=self.size * .1, po=po_off, tp=self.fk1_ctl) attribute.setRotOrder(self.fk1_roll_ctl, "XYZ") attribute.setKeyableAttributes(self.fk1_roll_ctl, ["rx"]) t = transform.getTransformLookingAt(self.guide.apos[2], self.guide.apos[3], self.normal, "xz", self.negate) # *ms* buffer object to feed into ikfk solver for hand seperation self.fk2_mtx = primitive.addTransform(self.fk1_roll_ctl, self.getName("fk2_mtx"), t) # fk2_loc is need to take the effector position + bone1 rotation t1 = transform.getTransformLookingAt(self.guide.apos[2], self.guide.apos[1], self.normal, "-xz", self.negate) self.fk2_loc = primitive.addTransform(self.root, self.getName("fk2_loc"), t1) self.fk2_npo = primitive.addTransform(self.fk2_loc, self.getName("fk2_npo"), t) po_off = datatypes.Vector(.5 * self.length2 * self.n_factor, 0, 0) self.fk2_ctl = self.addCtl(self.fk2_npo, "fk2_ctl", t, self.color_fk, "cube", w=self.length2, h=self.size * .1, d=self.size * .1, po=po_off, tp=self.fk1_roll_ctl) attribute.setKeyableAttributes(self.fk2_ctl) self.fk_ctl = [self.fk0_roll_ctl, self.fk1_mtx, self.fk2_ctl] self.fk_ctls = [ self.fk0_ctl, self.fk0_roll_ctl, self.fk1_ctl, self.fk1_roll_ctl, self.fk2_ctl ] for x in self.fk_ctls: attribute.setInvertMirror(x, ["tx", "ty", "tz"]) # IK Controlers ----------------------------------- self.ik_cns = primitive.addTransformFromPos(self.root, self.getName("ik_cns"), self.guide.pos["wrist"]) self.ikcns_ctl = self.addCtl(self.ik_cns, "ikcns_ctl", transform.getTransformFromPos( self.guide.pos["wrist"]), self.color_ik, "null", w=self.size * .12, tp=self.parentCtlTag) attribute.setInvertMirror(self.ikcns_ctl, ["tx", "ty", "tz"]) if self.negate: m = transform.getTransformLookingAt(self.guide.pos["wrist"], self.guide.pos["eff"], self.normal, "x-y", True) else: m = transform.getTransformLookingAt(self.guide.pos["wrist"], self.guide.pos["eff"], self.normal, "xy", False) self.ik_ctl = self.addCtl(self.ikcns_ctl, "ik_ctl", m, self.color_ik, "cube", w=self.size * .12, h=self.size * .12, d=self.size * .12, tp=self.ikcns_ctl) attribute.setKeyableAttributes(self.ik_ctl) attribute.setInvertMirror(self.ik_ctl, ["tx", "ry", "rz"]) # upv v = self.guide.apos[2] - self.guide.apos[0] v = self.normal ^ v v.normalize() v *= self.size * .5 v += self.guide.apos[1] # *ms* auto up vector ------------------------------ self.upv_cns = primitive.addTransformFromPos(self.root, self.getName("upv_cns"), self.guide.apos[0]) self.upv_auv = primitive.addTransformFromPos(self.root, self.getName("upv_auv"), self.guide.apos[0]) self.upv_mtx = primitive.addTransformFromPos(self.upv_cns, self.getName("upv_mtx"), self.guide.apos[0]) self.upv_npo = primitive.addTransformFromPos(self.upv_mtx, self.getName("upv_npo"), v) self.upv_ctl = self.addCtl(self.upv_npo, "upv_ctl", transform.getTransform(self.upv_npo), self.color_ik, "diamond", w=self.size * .12, tp=self.parentCtlTag) attribute.setKeyableAttributes(self.upv_ctl, self.t_params) attribute.setInvertMirror(self.upv_ctl, ["tx"]) # References -------------------------------------- # Calculate again the transfor for the IK ref. This way align with FK trnIK_ref = transform.getTransformLookingAt(self.guide.pos["wrist"], self.guide.pos["eff"], self.normal, "xz", self.negate) self.ik_ref = primitive.addTransform(self.ik_ctl, self.getName("ik_ref"), trnIK_ref) self.fk_ref = primitive.addTransform(self.fk_ctl[2], self.getName("fk_ref"), trnIK_ref) # Chain -------------------------------------------- # take outputs of the ikfk2bone solver self.bone0 = primitive.addLocator( self.root, self.getName("0_bone"), transform.getTransform(self.fk_ctl[0])) self.bone0_shp = self.bone0.getShape() self.bone0_shp.setAttr("localPositionX", self.n_factor * .5) self.bone0_shp.setAttr("localScale", .5, 0, 0) self.bone0.setAttr("sx", self.length0) self.bone0.setAttr("visibility", False) self.bone1 = primitive.addLocator( self.root, self.getName("1_bone"), transform.getTransform(self.fk_ctl[1])) self.bone1_shp = self.bone1.getShape() self.bone1_shp.setAttr("localPositionX", self.n_factor * .5) self.bone1_shp.setAttr("localScale", .5, 0, 0) self.bone1.setAttr("sx", self.length1) self.bone1.setAttr("visibility", False) self.ctrn_loc = primitive.addTransformFromPos(self.root, self.getName("ctrn_loc"), self.guide.apos[1]) # eff npo --- take the effector output of gear ik solver self.eff_npo = primitive.addTransformFromPos(self.root, self.getName("eff_npo"), self.guide.apos[2]) # eff loc --- take the fk ik blend result self.eff_loc = primitive.addTransformFromPos(self.eff_npo, self.getName("eff_loc"), self.guide.apos[2]) # Mid Controler ------------------------------------ self.mid_ctl = self.addCtl(self.ctrn_loc, "mid_ctl", transform.getTransform(self.ctrn_loc), self.color_ik, "sphere", w=self.size * .2, tp=self.parentCtlTag) attribute.setInvertMirror(self.mid_ctl, ["tx", "ty", "tz"]) # *ms* add elbow thickness # Roll join ref self.tws0_npo = primitive.addTransform( self.root, self.getName("tws0_npo"), transform.getTransform(self.fk_ctl[0])) self.tws0_loc = primitive.addTransform( self.tws0_npo, self.getName("tws0_loc"), transform.getTransform(self.fk_ctl[0])) self.tws0_rot = primitive.addTransform( self.tws0_loc, self.getName("tws0_rot"), transform.getTransform(self.fk_ctl[0])) self.tws1_npo = primitive.addTransform( self.ctrn_loc, self.getName("tws1_npo"), transform.getTransform(self.ctrn_loc)) self.tws1_loc = primitive.addTransform( self.tws1_npo, self.getName("tws1_loc"), transform.getTransform(self.ctrn_loc)) self.tws1_rot = primitive.addTransform( self.tws1_loc, self.getName("tws1_rot"), transform.getTransform(self.ctrn_loc)) self.tws2_loc = primitive.addTransform( self.tws1_npo, self.getName("tws2_loc"), transform.getTransform(self.ctrn_loc)) self.tws2_rot = primitive.addTransform( self.tws2_loc, self.getName("tws2_rot"), transform.getTransform(self.ctrn_loc)) self.tws3_npo = primitive.addTransform( self.root, self.getName("tws3_npo"), transform.getTransform(self.fk_ctl[2])) self.tws3_loc = primitive.addTransform( self.tws3_npo, self.getName("tws3_loc"), transform.getTransform(self.fk_ctl[2])) self.tws3_rot = primitive.addTransform( self.tws3_loc, self.getName("tws3_rot"), transform.getTransform(self.fk_ctl[2])) # Divisions ---------------------------------------- # We have at least one division at the start, the end and one for the # elbow. + 2 for elbow angle control # separate up and dn limb self.divisions = self.settings["div0"] + self.settings["div1"] + 3 + 2 self.divisions0 = self.settings["div0"] + 2 self.divisions1 = self.settings["div1"] + 2 self.div_cns = [] self.div_cnsUp = [] self.div_cnsDn = [] self.div_ctls = [] self.div_org = primitive.addTransform( self.root, self.getName("div_org"), transform.getTransform(self.root)) self.previousTag = self.parentCtlTag for i in range(self.divisions0): div_cns = primitive.addTransform(self.div_org, self.getName("div%s_loc" % i)) if self.negate: div_ctl = self.addCtl( div_cns, self.getName("div%s_ctl" % i), transform.getTransform(div_cns), self.color_fk, "square", d=self.size * .05, w=self.size * .1, po=datatypes.Vector(0, self.size * -0.05, 0), ro=datatypes.Vector(0, 0, datatypes.radians(90)), tp=self.previousTag) else: div_ctl = self.addCtl( div_cns, self.getName("div%s_ctl" % i), transform.getTransform(div_cns), self.color_fk, "square", d=self.size * .05, w=self.size * .1, po=datatypes.Vector(0, self.size * 0.05, 0), ro=datatypes.Vector(0, 0, datatypes.radians(90)), tp=self.previousTag) attribute.setKeyableAttributes(div_ctl) self.previousTag = div_ctl self.div_cns.append(div_cns) self.div_cnsUp.append(div_cns) self.jnt_pos.append([div_ctl, i]) self.div_ctls.append(div_ctl) # mid division d = self.divisions0 self.div_mid = primitive.addTransform( self.div_org, self.getName("div%s_loc" % d), transform.getTransform(self.mid_ctl)) if self.negate: self.div_mid_ctl = self.addCtl( self.div_mid, self.getName("div%s_ctl" % d), transform.getTransform(self.div_mid), self.color_fk, "square", d=self.size * .05, w=self.size * .1, po=datatypes.Vector(0, self.size * -0.05, 0), ro=datatypes.Vector(0, 0, datatypes.radians(90)), tp=self.previousTag) else: self.div_mid_ctl = self.addCtl( self.div_mid, self.getName("div%s_ctl" % d), transform.getTransform(self.div_mid), self.color_fk, "square", d=self.size * .05, w=self.size * .1, po=datatypes.Vector(0, self.size * 0.05, 0), ro=datatypes.Vector(0, 0, datatypes.radians(90)), tp=self.previousTag) attribute.setKeyableAttributes(self.div_mid_ctl) self.previousTag = div_ctl self.div_cns.append(self.div_mid) self.jnt_pos.append([self.div_mid_ctl, self.divisions0]) self.div_ctls.append(self.div_mid_ctl) # down division for i in range(self.divisions1): dd = i + self.divisions1 + 1 div_cns = primitive.addTransform(self.div_org, self.getName("div%s_loc" % dd)) if self.negate: div_ctl = self.addCtl( div_cns, self.getName("div%s_ctl" % dd), transform.getTransform(div_cns), self.color_fk, "square", d=self.size * .05, w=self.size * .1, po=datatypes.Vector(0, self.size * -0.05, 0), ro=datatypes.Vector(0, 0, datatypes.radians(90)), tp=self.previousTag) else: div_ctl = self.addCtl( div_cns, self.getName("div%s_ctl" % dd), transform.getTransform(div_cns), self.color_fk, "square", d=self.size * .05, w=self.size * .1, po=datatypes.Vector(0, self.size * 0.05, 0), ro=datatypes.Vector(0, 0, datatypes.radians(90)), tp=self.previousTag) attribute.setKeyableAttributes(div_ctl) self.previousTag = div_ctl self.div_cns.append(div_cns) self.div_cnsDn.append(div_cns) self.jnt_pos.append([div_ctl, i + self.divisions0 + 1]) self.div_ctls.append(div_ctl) # End reference ------------------------------------ # To help the deformation on the wrist self.jnt_pos.append([self.eff_loc, 'end']) # match IK FK references self.match_fk0 = primitive.addTransform( self.root, self.getName("fk0_mth"), transform.getTransform(self.fk_ctl[0])) self.match_fk1 = primitive.addTransform( self.root, self.getName("fk1_mth"), transform.getTransform(self.fk_ctl[1])) self.match_fk2 = primitive.addTransform( self.ik_ctl, self.getName("fk2_mth"), transform.getTransform(self.fk_ctl[2])) self.match_ik = primitive.addTransform( self.fk2_ctl, self.getName("ik_mth"), transform.getTransform(self.ik_ctl)) self.match_ikUpv = primitive.addTransform( self.fk0_roll_ctl, self.getName("upv_mth"), transform.getTransform(self.upv_ctl))
def addObjects(self): """Add all the objects needed to create the component.""" self.WIP = self.options["mode"] self.normal = self.getNormalFromPos(self.guide.apos) self.length0 = vector.getDistance(self.guide.apos[0], self.guide.apos[1]) self.length1 = vector.getDistance(self.guide.apos[1], self.guide.apos[2]) self.length2 = vector.getDistance(self.guide.apos[2], self.guide.apos[3]) # 1 bone chain for upv ref self.legChainUpvRef = primitive.add2DChain( self.root, self.getName("legUpvRef%s_jnt"), [self.guide.apos[0], self.guide.apos[2]], self.normal, False, self.WIP) self.legChainUpvRef[1].setAttr( "jointOrientZ", self.legChainUpvRef[1].getAttr("jointOrientZ") * -1) # extra neutral pose t = transform.getTransformFromPos(self.guide.apos[0]) self.root_npo = primitive.addTransform(self.root, self.getName("root_npo"), t) self.root_ctl = self.addCtl(self.root_npo, "root_ctl", t, self.color_fk, "circle", w=self.length0 / 6, tp=self.parentCtlTag) # FK Controlers ----------------------------------- t = transform.getTransformLookingAt(self.guide.apos[0], self.guide.apos[1], self.normal, "xz", self.negate) self.fk0_npo = primitive.addTransform(self.root_ctl, self.getName("fk0_npo"), t) self.fk0_ctl = self.addCtl(self.fk0_npo, "fk0_ctl", t, self.color_fk, "cube", w=self.length0, h=self.size * .1, d=self.size * .1, po=datatypes.Vector( .5 * self.length0 * self.n_factor, 0, 0), tp=self.root_ctl) attribute.setKeyableAttributes( self.fk0_ctl, ["tx", "ty", "tz", "ro", "rx", "ry", "rz", "sx"]) t = transform.getTransformLookingAt(self.guide.apos[1], self.guide.apos[2], self.normal, "xz", self.negate) self.fk1_npo = primitive.addTransform(self.fk0_ctl, self.getName("fk1_npo"), t) self.fk1_ctl = self.addCtl(self.fk1_npo, "fk1_ctl", t, self.color_fk, "cube", w=self.length1, h=self.size * .1, d=self.size * .1, po=datatypes.Vector( .5 * self.length1 * self.n_factor, 0, 0), tp=self.fk0_ctl) attribute.setKeyableAttributes( self.fk1_ctl, ["tx", "ty", "tz", "ro", "rx", "ry", "rz", "sx"]) t = transform.getTransformLookingAt(self.guide.apos[2], self.guide.apos[3], self.normal, "xz", self.negate) self.fk2_npo = primitive.addTransform(self.fk1_ctl, self.getName("fk2_npo"), t) self.fk2_ctl = self.addCtl(self.fk2_npo, "fk2_ctl", t, self.color_fk, "cube", w=self.length2, h=self.size * .1, d=self.size * .1, po=datatypes.Vector( .5 * self.length2 * self.n_factor, 0, 0), tp=self.fk1_ctl) attribute.setKeyableAttributes(self.fk2_ctl) self.fk_ctl = [self.fk0_ctl, self.fk1_ctl, self.fk2_ctl] for x in self.fk_ctl: attribute.setInvertMirror(x, ["tx", "ty", "tz"]) # IK Controlers ----------------------------------- self.ik_cns = primitive.addTransformFromPos(self.root_ctl, self.getName("ik_cns"), self.guide.pos["ankle"]) self.ikcns_ctl = self.addCtl(self.ik_cns, "ikcns_ctl", transform.getTransformFromPos( self.guide.pos["ankle"]), self.color_ik, "null", w=self.size * .12, tp=self.root_ctl) attribute.setInvertMirror(self.ikcns_ctl, ["tx"]) m = transform.getTransformLookingAt(self.guide.pos["ankle"], self.guide.pos["eff"], self.x_axis, "zx", False) self.ik_ctl = self.addCtl(self.ikcns_ctl, "ik_ctl", transform.getTransformFromPos( self.guide.pos["ankle"]), self.color_ik, "cube", w=self.size * .12, h=self.size * .12, d=self.size * .12, tp=self.ikcns_ctl) attribute.setKeyableAttributes(self.ik_ctl) attribute.setRotOrder(self.ik_ctl, "XZY") attribute.setInvertMirror(self.ik_ctl, ["tx", "ry", "rz"]) # upv v = self.guide.apos[2] - self.guide.apos[0] v = self.normal ^ v v.normalize() v *= self.size * .5 v += self.guide.apos[1] self.upv_cns = primitive.addTransformFromPos(self.ik_ctl, self.getName("upv_cns"), v) self.upv_ctl = self.addCtl(self.upv_cns, "upv_ctl", transform.getTransform(self.upv_cns), self.color_ik, "diamond", w=self.size * .12, tp=self.root_ctl) if self.settings["mirrorMid"]: if self.negate: self.upv_cns.rz.set(180) self.upv_cns.sy.set(-1) else: attribute.setInvertMirror(self.upv_ctl, ["tx"]) attribute.setKeyableAttributes(self.upv_ctl, self.t_params) # References -------------------------------------- self.ik_ref = primitive.addTransform( self.ik_ctl, self.getName("ik_ref"), transform.getTransform(self.ik_ctl)) self.fk_ref = primitive.addTransform( self.fk_ctl[2], self.getName("fk_ref"), transform.getTransform(self.ik_ctl)) # Chain -------------------------------------------- # The outputs of the ikfk2bone solver self.bone0 = primitive.addLocator( self.root_ctl, self.getName("0_bone"), transform.getTransform(self.fk_ctl[0])) self.bone0_shp = self.bone0.getShape() self.bone0_shp.setAttr("localPositionX", self.n_factor * .5) self.bone0_shp.setAttr("localScale", .5, 0, 0) self.bone0.setAttr("sx", self.length0) self.bone0.setAttr("visibility", False) self.bone1 = primitive.addLocator( self.root_ctl, self.getName("1_bone"), transform.getTransform(self.fk_ctl[1])) self.bone1_shp = self.bone1.getShape() self.bone1_shp.setAttr("localPositionX", self.n_factor * .5) self.bone1_shp.setAttr("localScale", .5, 0, 0) self.bone1.setAttr("sx", self.length1) self.bone1.setAttr("visibility", False) tA = transform.getTransformLookingAt(self.guide.apos[0], self.guide.apos[1], self.normal, "xz", self.negate) tA = transform.setMatrixPosition(tA, self.guide.apos[1]) tB = transform.getTransformLookingAt(self.guide.apos[1], self.guide.apos[2], self.normal, "xz", self.negate) t = transform.getInterpolateTransformMatrix(tA, tB) self.ctrn_loc = primitive.addTransform(self.root, self.getName("ctrn_loc"), t) self.eff_loc = primitive.addTransformFromPos(self.root_ctl, self.getName("eff_loc"), self.guide.apos[2]) # tws_ref t = transform.getRotationFromAxis(datatypes.Vector(0, -1, 0), self.normal, "xz", self.negate) t = transform.setMatrixPosition(t, self.guide.pos["ankle"]) self.tws_ref = primitive.addTransform(self.eff_loc, self.getName("tws_ref"), t) # Mid Controler ------------------------------------ t = transform.getTransform(self.ctrn_loc) self.mid_cns = primitive.addTransform(self.ctrn_loc, self.getName("mid_cns"), t) self.mid_ctl = self.addCtl(self.mid_cns, "mid_ctl", t, self.color_ik, "sphere", w=self.size * .2, tp=self.root_ctl) if self.settings["mirrorMid"]: if self.negate: self.mid_cns.rz.set(180) self.mid_cns.sz.set(-1) else: attribute.setInvertMirror(self.mid_ctl, ["tx", "ty", "tz"]) attribute.setKeyableAttributes(self.mid_ctl, self.t_params) # Twist references --------------------------------- x = datatypes.Vector(0, -1, 0) x = x * transform.getTransform(self.eff_loc) z = datatypes.Vector(self.normal.x, self.normal.y, self.normal.z) z = z * transform.getTransform(self.eff_loc) m = transform.getRotationFromAxis(x, z, "xz", self.negate) m = transform.setMatrixPosition(m, transform.getTranslation(self.ik_ctl)) self.tws0_loc = primitive.addTransform( self.root_ctl, self.getName("tws0_loc"), transform.getTransform(self.fk_ctl[0])) self.tws0_rot = primitive.addTransform( self.tws0_loc, self.getName("tws0_rot"), transform.getTransform(self.fk_ctl[0])) self.tws1_loc = primitive.addTransform( self.ctrn_loc, self.getName("tws1_loc"), transform.getTransform(self.ctrn_loc)) self.tws1_rot = primitive.addTransform( self.tws1_loc, self.getName("tws1_rot"), transform.getTransform(self.ctrn_loc)) self.tws1A_npo = primitive.addTransform(self.mid_ctl, self.getName("tws1A_npo"), tA) self.tws1A_loc = primitive.addTransform(self.tws1A_npo, self.getName("tws1A_loc"), tA) self.tws1B_npo = primitive.addTransform(self.mid_ctl, self.getName("tws1B_npo"), tB) self.tws1B_loc = primitive.addTransform(self.tws1B_npo, self.getName("tws1B_loc"), tB) self.tws2_npo = primitive.addTransform( self.root, self.getName("tws2_npo"), transform.getTransform(self.fk_ctl[2])) self.tws2_loc = primitive.addTransform( self.tws2_npo, self.getName("tws2_loc"), transform.getTransform(self.fk_ctl[2])) self.tws2_rot = primitive.addTransform( self.tws2_npo, self.getName("tws2_rot"), transform.getTransform(self.fk_ctl[2])) # Roll twist chain --------------------------------- # Arm self.uplegChainPos = [] ii = 1.0 / (self.settings["div0"] + 1) i = 0.0 for p in range(self.settings["div0"] + 2): self.uplegChainPos.append( vector.linearlyInterpolate(self.guide.pos["root"], self.guide.pos["knee"], blend=i)) i = i + ii self.uplegTwistChain = primitive.add2DChain( self.root, self.getName("uplegTwist%s_jnt"), self.uplegChainPos, self.normal, False, self.WIP) # Forearm self.lowlegChainPos = [] ii = 1.0 / (self.settings["div1"] + 1) i = 0.0 for p in range(self.settings["div1"] + 2): self.lowlegChainPos.append( vector.linearlyInterpolate(self.guide.pos["knee"], self.guide.pos["ankle"], blend=i)) i = i + ii self.lowlegTwistChain = primitive.add2DChain( self.root, self.getName("lowlegTwist%s_jnt"), self.lowlegChainPos, self.normal, False, self.WIP) pm.parent(self.lowlegTwistChain[0], self.mid_ctl) # Hand Aux chain and nonroll self.auxChainPos = [] ii = .5 i = 0.0 for p in range(3): self.auxChainPos.append( vector.linearlyInterpolate(self.guide.pos["ankle"], self.guide.pos["eff"], blend=i)) i = i + ii t = self.root.getMatrix(worldSpace=True) self.aux_npo = primitive.addTransform(self.root, self.getName("aux_npo"), t) self.auxTwistChain = primitive.add2DChain( self.aux_npo, self.getName("auxTwist%s_jnt"), self.lowlegChainPos[:3], self.normal, False, self.WIP) # Non Roll join ref --------------------------------- self.uplegRollRef = primitive.add2DChain( self.root, self.getName("uplegRollRef%s_jnt"), self.uplegChainPos[:2], self.normal, False, self.WIP) self.lowlegRollRef = primitive.add2DChain( self.aux_npo, self.getName("lowlegRollRef%s_jnt"), self.lowlegChainPos[:2], self.normal, False, self.WIP) # Divisions ---------------------------------------- # We have at least one division at the start, the end and one for the # elbow. + 2 for knee angle control self.divisions = self.settings["div0"] + self.settings["div1"] + 4 self.div_cns = [] for i in range(self.divisions): div_cns = primitive.addTransform(self.root_ctl, self.getName("div%s_loc" % i)) self.div_cns.append(div_cns) self.jnt_pos.append([div_cns, i]) # End reference ------------------------------------ # To help the deformation on the ankle self.end_ref = primitive.addTransform(self.eff_loc, self.getName("end_ref"), m) for a in "xyz": self.end_ref.attr("s%s" % a).set(1.0) if self.negate: self.end_ref.attr("ry").set(-180.0) self.jnt_pos.append([self.end_ref, 'end']) # Tangent controls t = transform.getInterpolateTransformMatrix(self.fk_ctl[0], self.tws1A_npo, .5) self.uplegTangentA_loc = primitive.addTransform( self.root_ctl, self.getName("uplegTangentA_loc"), self.fk_ctl[0].getMatrix(worldSpace=True)) self.uplegTangentA_npo = primitive.addTransform( self.uplegTangentA_loc, self.getName("uplegTangentA_npo"), t) self.uplegTangentA_ctl = self.addCtl(self.uplegTangentA_npo, "uplegTangentA_ctl", t, self.color_ik, "circle", w=self.size * .2, ro=datatypes.Vector( 0, 0, 1.570796), tp=self.mid_ctl) if self.negate: self.uplegTangentA_npo.rz.set(180) self.uplegTangentA_npo.sz.set(-1) attribute.setKeyableAttributes(self.uplegTangentA_ctl, self.t_params) t = transform.getInterpolateTransformMatrix(self.fk_ctl[0], self.tws1A_npo, .9) self.uplegTangentB_npo = primitive.addTransform( self.tws1A_loc, self.getName("uplegTangentB_npo"), t) self.uplegTangentB_ctl = self.addCtl(self.uplegTangentB_npo, "uplegTangentB_ctl", t, self.color_ik, "circle", w=self.size * .1, ro=datatypes.Vector( 0, 0, 1.570796), tp=self.mid_ctl) if self.negate: self.uplegTangentB_npo.rz.set(180) self.uplegTangentB_npo.sz.set(-1) attribute.setKeyableAttributes(self.uplegTangentB_ctl, self.t_params) tC = self.tws1B_npo.getMatrix(worldSpace=True) tC = transform.setMatrixPosition(tC, self.guide.apos[2]) t = transform.getInterpolateTransformMatrix(self.tws1B_npo, tC, .1) self.lowlegTangentA_npo = primitive.addTransform( self.tws1B_loc, self.getName("lowlegTangentA_npo"), t) self.lowlegTangentA_ctl = self.addCtl(self.lowlegTangentA_npo, "lowlegTangentA_ctl", t, self.color_ik, "circle", w=self.size * .1, ro=datatypes.Vector( 0, 0, 1.570796), tp=self.mid_ctl) if self.negate: self.lowlegTangentA_npo.rz.set(180) self.lowlegTangentA_npo.sz.set(-1) attribute.setKeyableAttributes(self.lowlegTangentA_ctl, self.t_params) t = transform.getInterpolateTransformMatrix(self.tws1B_npo, tC, .5) self.lowlegTangentB_loc = primitive.addTransform( self.root, self.getName("lowlegTangentB_loc"), tC) self.lowlegTangentB_npo = primitive.addTransform( self.lowlegTangentB_loc, self.getName("lowlegTangentB_npo"), t) self.lowlegTangentB_ctl = self.addCtl(self.lowlegTangentB_npo, "lowlegTangentB_ctl", t, self.color_ik, "circle", w=self.size * .2, ro=datatypes.Vector( 0, 0, 1.570796), tp=self.mid_ctl) if self.negate: self.lowlegTangentB_npo.rz.set(180) self.lowlegTangentB_npo.sz.set(-1) attribute.setKeyableAttributes(self.lowlegTangentB_ctl, self.t_params) t = self.mid_ctl.getMatrix(worldSpace=True) self.kneeTangent_npo = primitive.addTransform( self.mid_ctl, self.getName("kneeTangent_npo"), t) self.kneeTangent_ctl = self.addCtl(self.kneeTangent_npo, "kneeTangent_ctl", t, self.color_fk, "circle", w=self.size * .25, ro=datatypes.Vector(0, 0, 1.570796), tp=self.mid_ctl) if self.negate: self.kneeTangent_npo.rz.set(180) self.kneeTangent_npo.sz.set(-1) attribute.setKeyableAttributes(self.kneeTangent_ctl, self.t_params) # match IK FK references self.match_fk0_off = primitive.addTransform( self.root, self.getName("matchFk0_npo"), transform.getTransform(self.fk_ctl[1])) self.match_fk0 = primitive.addTransform( self.match_fk0_off, self.getName("fk0_mth"), transform.getTransform(self.fk_ctl[0])) self.match_fk1_off = primitive.addTransform( self.root, self.getName("matchFk1_npo"), transform.getTransform(self.fk_ctl[2])) self.match_fk1 = primitive.addTransform( self.match_fk1_off, self.getName("fk1_mth"), transform.getTransform(self.fk_ctl[1])) self.match_fk2 = primitive.addTransform( self.ik_ctl, self.getName("fk2_mth"), transform.getTransform(self.fk_ctl[2])) self.match_ik = primitive.addTransform( self.fk2_ctl, self.getName("ik_mth"), transform.getTransform(self.ik_ctl)) self.match_ikUpv = primitive.addTransform( self.fk0_ctl, self.getName("upv_mth"), transform.getTransform(self.upv_ctl)) # add visual reference self.line_ref = icon.connection_display_curve( self.getName("visalRef"), [self.upv_ctl, self.mid_ctl])
def addObjects(self): self.div_count = len(self.guide.apos) - 5 plane = [self.guide.apos[0], self.guide.apos[-4], self.guide.apos[-3]] self.normal = self.getNormalFromPos(plane) self.binormal = self.getBiNormalFromPos(plane) # Heel --------------------------------------------- # bank pivot t = tra.getTransformLookingAt(self.guide.pos["heel"], self.guide.apos[-4], self.normal, "xz", self.negate) t = tra.setMatrixPosition(t, self.guide.pos["inpivot"]) self.in_piv = pri.addTransform(self.root, self.getName("in_piv"), t) t = tra.setMatrixPosition(t, self.guide.pos["outpivot"]) self.out_piv = pri.addTransform(self.in_piv, self.getName("out_piv"), t) # heel t = tra.getTransformLookingAt(self.guide.pos["heel"], self.guide.apos[-4], self.normal, "xz", self.negate) self.heel_loc = pri.addTransform(self.out_piv, self.getName("heel_loc"), t) att.setRotOrder(self.heel_loc, "YZX") self.heel_ctl = self.addCtl(self.heel_loc, "heel_ctl", t, self.color_ik, "sphere", w=self.size*.1) att.setKeyableAttributes(self.heel_ctl, self.r_params) # Tip ---------------------------------------------- v = dt.Vector(self.guide.apos[-5].x,self.guide.apos[-1].y,self.guide.apos[-5].z) t = tra.setMatrixPosition(t, v) self.tip_ctl = self.addCtl(self.heel_ctl, "tip_ctl", t, self.color_ik, "circle", w=self.size) att.setKeyableAttributes(self.tip_ctl, self.r_params) # Roll --------------------------------------------- if self.settings["roll"] == 0: t = tra.getRotationFromAxis(self.y_axis, self.normal, "yz", self.negate) t = tra.setMatrixPosition(t, self.guide.pos["root"]) self.roll_np = pri.addTransform(self.root, self.getName("roll_np"), t) self.roll_ctl = self.addCtl(self.roll_np, "roll_ctl", t, self.color_ik, "cylinder", w=self.size*.5, h=self.size*.5, ro=dt.Vector(3.1415*.5,0,0)) att.setKeyableAttributes(self.roll_ctl, ["rx", "rz"]) # Backward Controlers ------------------------------ bk_pos = self.guide.apos[1:-3] bk_pos.reverse() parent = self.tip_ctl self.bk_ctl = [] self.bk_loc = [] for i, pos in enumerate(bk_pos): if i == 0: t = tra.getTransform(self.heel_ctl) t = tra.setMatrixPosition(t, pos) else: dir = bk_pos[i-1] t = tra.getTransformLookingAt(pos, dir, self.normal, "xz", self.negate) bk_loc = pri.addTransform(parent, self.getName("bk%s_loc"%i), t) bk_ctl = self.addCtl(bk_loc, "bk%s_ctl"%i, t, self.color_ik, "sphere", w=self.size*.15) att.setKeyableAttributes(bk_ctl, self.r_params) self.bk_loc.append(bk_loc) self.bk_ctl.append(bk_ctl) parent = bk_ctl # FK Reference ------------------------------------ self.fk_ref = pri.addTransformFromPos(self.bk_ctl[-1], self.getName("fk_ref"), self.guide.apos[0]) self.fk_npo = pri.addTransform(self.fk_ref, self.getName("fk0_npo"), tra.getTransform(self.bk_ctl[-1])) # Forward Controlers ------------------------------ self.fk_ctl = [] self.fk_loc = [] parent = self.fk_npo for i, bk_ctl in enumerate(reversed(self.bk_ctl[1:])): t = tra.getTransform(bk_ctl) dist = vec.getDistance(self.guide.apos[i+1], self.guide.apos[i+2]) # fk_npo = pri.addTransform(parent, self.getName("fk%s_npo"%i), t) fk_loc = pri.addTransform(parent, self.getName("fk%s_loc"%i), t) fk_ctl = self.addCtl(fk_loc, "fk%s_ctl"%i, t, self.color_fk, "cube", w=dist, h=self.size*.5, d=self.size*.5, po=dt.Vector(dist*.5*self.n_factor,0,0)) att.setKeyableAttributes(fk_ctl) self.addShadow(fk_ctl, i) parent = fk_ctl self.fk_ctl.append(fk_ctl) self.fk_loc.append(fk_loc)
def addObjects(self): """Add all the objects needed to create the component.""" self.div_count = len(self.guide.apos) - 5 plane = [self.guide.apos[0], self.guide.apos[-4], self.guide.apos[-3]] self.normal = self.getNormalFromPos(plane) self.binormal = self.getBiNormalFromPos(plane) # Heel --------------------------------------------- # bank pivot t = transform.getTransformLookingAt(self.guide.pos["heel"], self.guide.apos[-4], self.normal, "xz", self.negate) t = transform.setMatrixPosition(t, self.guide.pos["inpivot"]) self.in_npo = primitive.addTransform( self.root, self.getName("in_npo"), t) self.in_piv = primitive.addTransform( self.in_npo, self.getName("in_piv"), t) t = transform.setMatrixPosition(t, self.guide.pos["outpivot"]) self.out_piv = primitive.addTransform( self.in_piv, self.getName("out_piv"), t) # heel t = transform.getTransformLookingAt(self.guide.pos["heel"], self.guide.apos[-4], self.normal, "xz", self.negate) self.heel_loc = primitive.addTransform( self.out_piv, self.getName("heel_loc"), t) attribute.setRotOrder(self.heel_loc, "YZX") self.heel_ctl = self.addCtl(self.heel_loc, "heel_ctl", t, self.color_ik, "sphere", w=self.size * .1, tp=self.parentCtlTag) attribute.setKeyableAttributes(self.heel_ctl, self.r_params) # Tip ---------------------------------------------- v = datatypes.Vector(self.guide.apos[-5].x, self.guide.apos[-1].y, self.guide.apos[-5].z) t = transform.setMatrixPosition(t, v) self.tip_ctl = self.addCtl(self.heel_ctl, "tip_ctl", t, self.color_ik, "circle", w=self.size, tp=self.heel_ctl) attribute.setKeyableAttributes(self.tip_ctl, self.r_params) # Roll --------------------------------------------- if self.settings["useRollCtl"]: t = transform.getTransformLookingAt(self.guide.pos["heel"], self.guide.apos[-4], self.normal, "xz", self.negate) t = transform.setMatrixPosition(t, self.guide.pos["root"]) self.roll_np = primitive.addTransform( self.root, self.getName("roll_npo"), t) self.roll_ctl = self.addCtl(self.roll_np, "roll_ctl", t, self.color_ik, "cylinder", w=self.size * .5, h=self.size * .5, ro=datatypes.Vector(3.1415 * .5, 0, 0), tp=self.tip_ctl) attribute.setKeyableAttributes(self.roll_ctl, ["rx", "rz"]) # Backward Controlers ------------------------------ bk_pos = self.guide.apos[1:-3] bk_pos.reverse() parent = self.tip_ctl self.bk_ctl = [] self.bk_loc = [] self.previousTag = self.tip_ctl for i, pos in enumerate(bk_pos): if i == 0: t = transform.getTransform(self.heel_ctl) t = transform.setMatrixPosition(t, pos) else: dir = bk_pos[i - 1] t = transform.getTransformLookingAt( pos, dir, self.normal, "xz", self.negate) bk_loc = primitive.addTransform( parent, self.getName("bk%s_loc" % i), t) bk_ctl = self.addCtl(bk_loc, "bk%s_ctl" % i, t, self.color_ik, "sphere", w=self.size * .15, tp=self.previousTag) attribute.setKeyableAttributes(bk_ctl, self.r_params) self.previousTag = bk_ctl self.bk_loc.append(bk_loc) self.bk_ctl.append(bk_ctl) parent = bk_ctl # FK Reference ------------------------------------ self.fk_ref = primitive.addTransformFromPos(self.bk_ctl[-1], self.getName("fk_ref"), self.guide.apos[0]) self.fk_npo = primitive.addTransform( self.fk_ref, self.getName("fk0_npo"), transform.getTransform(self.bk_ctl[-1])) # Forward Controlers ------------------------------ self.fk_ctl = [] self.fk_loc = [] parent = self.fk_npo self.previousTag = self.tip_ctl for i, bk_ctl in enumerate(reversed(self.bk_ctl[1:])): t = transform.getTransform(bk_ctl) dist = vector.getDistance(self.guide.apos[i + 1], self.guide.apos[i + 2]) fk_loc = primitive.addTransform( parent, self.getName("fk%s_loc" % i), t) po_vec = datatypes.Vector(dist * .5 * self.n_factor, 0, 0) fk_ctl = self.addCtl(fk_loc, "fk%s_ctl" % i, t, self.color_fk, "cube", w=dist, h=self.size * .5, d=self.size * .5, po=po_vec, tp=self.previousTag) self.previousTag = fk_ctl attribute.setKeyableAttributes(fk_ctl) self.jnt_pos.append([fk_ctl, i]) parent = fk_ctl self.fk_ctl.append(fk_ctl) self.fk_loc.append(fk_loc)
def eyeRig(eyeMesh, edgeLoop, blinkH, namePrefix, offset, rigidLoops, falloffLoops, headJnt, doSkin, parent=None, ctlName="ctl", sideRange=False, customCorner=False, intCorner=None, extCorner=None, ctlGrp=None, defGrp=None): """Create eyelid and eye rig Args: eyeMesh (TYPE): Description edgeLoop (TYPE): Description blinkH (TYPE): Description namePrefix (TYPE): Description offset (TYPE): Description rigidLoops (TYPE): Description falloffLoops (TYPE): Description headJnt (TYPE): Description doSkin (TYPE): Description parent (None, optional): Description ctlName (str, optional): Description sideRange (bool, optional): Description customCorner (bool, optional): Description intCorner (None, optional): Description extCorner (None, optional): Description ctlGrp (None, optional): Description defGrp (None, optional): Description Returns: TYPE: Description """ # Checkers if edgeLoop: edgeLoopList = [pm.PyNode(e) for e in edgeLoop.split(",")] else: pm.displayWarning("Please set the edge loop first") return if eyeMesh: try: eyeMesh = pm.PyNode(eyeMesh) except pm.MayaNodeError: pm.displayWarning("The object %s can not be found in the " "scene" % (eyeMesh)) return else: pm.displayWarning("Please set the eye mesh first") if doSkin: if not headJnt: pm.displayWarning("Please set the Head Jnt or unCheck " "Compute Topological Autoskin") return # Initial Data bboxCenter = meshNavigation.bboxCenter(eyeMesh) extr_v = meshNavigation.getExtremeVertexFromLoop(edgeLoopList, sideRange) upPos = extr_v[0] lowPos = extr_v[1] inPos = extr_v[2] outPos = extr_v[3] edgeList = extr_v[4] vertexList = extr_v[5] # Detect the side L or R from the x value if inPos.getPosition(space='world')[0] < 0.0: side = "R" inPos = extr_v[3] outPos = extr_v[2] normalPos = outPos npw = normalPos.getPosition(space='world') normalVec = npw - bboxCenter else: side = "L" normalPos = outPos npw = normalPos.getPosition(space='world') normalVec = bboxCenter - npw # Manual Vertex corners if customCorner: if intCorner: try: if side == "R": inPos = pm.PyNode(extCorner) else: inPos = pm.PyNode(intCorner) except pm.MayaNodeError: pm.displayWarning("%s can not be found" % intCorner) return else: pm.displayWarning("Please set the internal eyelid corner") return if extCorner: try: normalPos = pm.PyNode(extCorner) npw = normalPos.getPosition(space='world') if side == "R": outPos = pm.PyNode(intCorner) normalVec = npw - bboxCenter else: outPos = pm.PyNode(extCorner) normalVec = bboxCenter - npw except pm.MayaNodeError: pm.displayWarning("%s can not be found" % extCorner) return else: pm.displayWarning("Please set the external eyelid corner") return # Check if we have prefix: if namePrefix: namePrefix = string.removeInvalidCharacter(namePrefix) else: pm.displayWarning("Prefix is needed") return def setName(name, ind=None): namesList = [namePrefix, side, name] if ind is not None: namesList[1] = side + str(ind) name = "_".join(namesList) return name if pm.ls(setName("root")): pm.displayWarning("The object %s already exist in the scene. Please " "choose another name prefix" % setName("root")) return # Eye root eye_root = primitive.addTransform(None, setName("root")) eyeCrv_root = primitive.addTransform(eye_root, setName("crvs")) # Eyelid Main crvs try: upEyelid = meshNavigation.edgeRangeInLoopFromMid( edgeList, upPos, inPos, outPos) upCrv = curve.createCurveFromOrderedEdges( upEyelid, inPos, setName("upperEyelid"), parent=eyeCrv_root) upCrv_ctl = curve.createCurveFromOrderedEdges( upEyelid, inPos, setName("upCrv_%s" % ctlName), parent=eyeCrv_root) pm.rebuildCurve(upCrv_ctl, s=2, rt=0, rpo=True, ch=False) lowEyelid = meshNavigation.edgeRangeInLoopFromMid( edgeList, lowPos, inPos, outPos) lowCrv = curve.createCurveFromOrderedEdges( lowEyelid, inPos, setName("lowerEyelid"), parent=eyeCrv_root) lowCrv_ctl = curve.createCurveFromOrderedEdges( lowEyelid, inPos, setName("lowCrv_%s" % ctlName), parent=eyeCrv_root) pm.rebuildCurve(lowCrv_ctl, s=2, rt=0, rpo=True, ch=False) except UnboundLocalError: if customCorner: pm.displayWarning("This error is maybe caused because the custom " "Corner vertex is not part of the edge loop") pm.displayError(traceback.format_exc()) return upBlink = curve.createCurveFromCurve( upCrv, setName("upblink_crv"), nbPoints=30, parent=eyeCrv_root) lowBlink = curve.createCurveFromCurve( lowCrv, setName("lowBlink_crv"), nbPoints=30, parent=eyeCrv_root) upTarget = curve.createCurveFromCurve( upCrv, setName("upblink_target"), nbPoints=30, parent=eyeCrv_root) lowTarget = curve.createCurveFromCurve( lowCrv, setName("lowBlink_target"), nbPoints=30, parent=eyeCrv_root) midTarget = curve.createCurveFromCurve( lowCrv, setName("midBlink_target"), nbPoints=30, parent=eyeCrv_root) rigCrvs = [upCrv, lowCrv, upCrv_ctl, lowCrv_ctl, upBlink, lowBlink, upTarget, lowTarget, midTarget] for crv in rigCrvs: crv.attr("visibility").set(False) # localBBOX localBBox = eyeMesh.getBoundingBox(invisible=True, space='world') wRadius = abs((localBBox[0][0] - localBBox[1][0])) dRadius = abs((localBBox[0][1] - localBBox[1][1]) / 1.7) # Groups if not ctlGrp: ctlGrp = "rig_controllers_grp" try: ctlSet = pm.PyNode(ctlGrp) except pm.MayaNodeError: pm.sets(n=ctlGrp, em=True) ctlSet = pm.PyNode(ctlGrp) if not defGrp: defGrp = "rig_deformers_grp" try: defset = pm.PyNode(defGrp) except pm.MayaNodeError: pm.sets(n=defGrp, em=True) defset = pm.PyNode(defGrp) # Calculate center looking at averagePosition = ((upPos.getPosition(space='world') + lowPos.getPosition(space='world') + inPos.getPosition(space='world') + outPos.getPosition(space='world')) / 4) if side == "R": negate = False offset = offset over_offset = dRadius else: negate = False over_offset = dRadius if side == "R" and sideRange or side == "R" and customCorner: axis = "z-x" # axis = "zx" else: axis = "z-x" t = transform.getTransformLookingAt( bboxCenter, averagePosition, normalVec, axis=axis, negate=negate) over_npo = primitive.addTransform( eye_root, setName("center_lookatRoot"), t) over_ctl = icon.create(over_npo, setName("over_%s" % ctlName), t, icon="square", w=wRadius, d=dRadius, ro=datatypes.Vector(1.57079633, 0, 0), po=datatypes.Vector(0, 0, over_offset), color=4) node.add_controller_tag(over_ctl) attribute.add_mirror_config_channels(over_ctl) attribute.setKeyableAttributes( over_ctl, params=["tx", "ty", "tz", "ro", "rx", "ry", "rz", "sx", "sy", "sz"]) if side == "R": over_npo.attr("rx").set(over_npo.attr("rx").get() * -1) over_npo.attr("ry").set(over_npo.attr("ry").get() + 180) over_npo.attr("sz").set(-1) if len(ctlName.split("_")) == 2 and ctlName.split("_")[-1] == "ghost": pass else: pm.sets(ctlSet, add=over_ctl) center_lookat = primitive.addTransform( over_ctl, setName("center_lookat"), t) # Tracking # Eye aim control t_arrow = transform.getTransformLookingAt(bboxCenter, averagePosition, upPos.getPosition(space='world'), axis="zy", negate=False) radius = abs((localBBox[0][0] - localBBox[1][0]) / 1.7) arrow_npo = primitive.addTransform(eye_root, setName("aim_npo"), t_arrow) arrow_ctl = icon.create(arrow_npo, setName("aim_%s" % ctlName), t_arrow, icon="arrow", w=1, po=datatypes.Vector(0, 0, radius), color=4) if len(ctlName.split("_")) == 2 and ctlName.split("_")[-1] == "ghost": pass else: pm.sets(ctlSet, add=arrow_ctl) attribute.setKeyableAttributes(arrow_ctl, params=["rx", "ry", "rz"]) # tracking custom trigger if side == "R": tt = t_arrow else: tt = t aimTrigger_root = primitive.addTransform( center_lookat, setName("aimTrigger_root"), tt) aimTrigger_lvl = primitive.addTransform( aimTrigger_root, setName("aimTrigger_lvl"), tt) aimTrigger_lvl.attr("tz").set(1.0) aimTrigger_ref = primitive.addTransform( aimTrigger_lvl, setName("aimTrigger_ref"), tt) aimTrigger_ref.attr("tz").set(0.0) # connect trigger with arrow_ctl pm.parentConstraint(arrow_ctl, aimTrigger_ref, mo=True) # Controls lists upControls = [] trackLvl = [] # upper eyelid controls upperCtlNames = ["inCorner", "upInMid", "upMid", "upOutMid", "outCorner"] cvs = upCrv_ctl.getCVs(space="world") if side == "R" and not sideRange: # if side == "R": cvs = [cv for cv in reversed(cvs)] for i, cv in enumerate(cvs): if utils.is_odd(i): color = 14 wd = .5 icon_shape = "circle" params = ["tx", "ty", "tz"] else: color = 4 wd = .7 icon_shape = "square" params = ["tx", "ty", "tz", "ro", "rx", "ry", "rz", "sx", "sy", "sz"] t = transform.setMatrixPosition(t, cvs[i]) npo = primitive.addTransform(center_lookat, setName("%s_npo" % upperCtlNames[i]), t) npoBase = npo if i == 2: # we add an extra level to input the tracking ofset values npo = primitive.addTransform(npo, setName("%s_trk" % upperCtlNames[i]), t) trackLvl.append(npo) ctl = icon.create(npo, setName("%s_%s" % (upperCtlNames[i], ctlName)), t, icon=icon_shape, w=wd, d=wd, ro=datatypes.Vector(1.57079633, 0, 0), po=datatypes.Vector(0, 0, offset), color=color) attribute.add_mirror_config_channels(ctl) node.add_controller_tag(ctl, over_ctl) upControls.append(ctl) if len(ctlName.split("_")) == 2 and ctlName.split("_")[-1] == "ghost": pass else: pm.sets(ctlSet, add=ctl) attribute.setKeyableAttributes(ctl, params) if side == "R": npoBase.attr("ry").set(180) npoBase.attr("sz").set(-1) # adding parent average contrains to odd controls for i, ctl in enumerate(upControls): if utils.is_odd(i): pm.parentConstraint(upControls[i - 1], upControls[i + 1], ctl.getParent(), mo=True) # lower eyelid controls lowControls = [upControls[0]] lowerCtlNames = ["inCorner", "lowInMid", "lowMid", "lowOutMid", "outCorner"] cvs = lowCrv_ctl.getCVs(space="world") if side == "R" and not sideRange: cvs = [cv for cv in reversed(cvs)] for i, cv in enumerate(cvs): # we skip the first and last point since is already in the uper eyelid if i in [0, 4]: continue if utils.is_odd(i): color = 14 wd = .5 icon_shape = "circle" params = ["tx", "ty", "tz"] else: color = 4 wd = .7 icon_shape = "square" params = ["tx", "ty", "tz", "ro", "rx", "ry", "rz", "sx", "sy", "sz"] t = transform.setMatrixPosition(t, cvs[i]) npo = primitive.addTransform(center_lookat, setName("%s_npo" % lowerCtlNames[i]), t) npoBase = npo if i == 2: # we add an extra level to input the tracking ofset values npo = primitive.addTransform(npo, setName("%s_trk" % lowerCtlNames[i]), t) trackLvl.append(npo) ctl = icon.create(npo, setName("%s_%s" % (lowerCtlNames[i], ctlName)), t, icon=icon_shape, w=wd, d=wd, ro=datatypes.Vector(1.57079633, 0, 0), po=datatypes.Vector(0, 0, offset), color=color) attribute.add_mirror_config_channels(ctl) lowControls.append(ctl) if len(ctlName.split("_")) == 2 and ctlName.split("_")[-1] == "ghost": pass else: pm.sets(ctlSet, add=ctl) attribute.setKeyableAttributes(ctl, params) # mirror behaviout on R side controls if side == "R": npoBase.attr("ry").set(180) npoBase.attr("sz").set(-1) for lctl in reversed(lowControls[1:]): node.add_controller_tag(lctl, over_ctl) lowControls.append(upControls[-1]) # adding parent average contrains to odd controls for i, ctl in enumerate(lowControls): if utils.is_odd(i): pm.parentConstraint(lowControls[i - 1], lowControls[i + 1], ctl.getParent(), mo=True) # Connecting control crvs with controls applyop.gear_curvecns_op(upCrv_ctl, upControls) applyop.gear_curvecns_op(lowCrv_ctl, lowControls) # adding wires w1 = pm.wire(upCrv, w=upBlink)[0] w2 = pm.wire(lowCrv, w=lowBlink)[0] w3 = pm.wire(upTarget, w=upCrv_ctl)[0] w4 = pm.wire(lowTarget, w=lowCrv_ctl)[0] # adding blendshapes bs_upBlink = pm.blendShape(upTarget, midTarget, upBlink, n="blendShapeUpBlink") bs_lowBlink = pm.blendShape(lowTarget, midTarget, lowBlink, n="blendShapeLowBlink") bs_mid = pm.blendShape(lowTarget, upTarget, midTarget, n="blendShapeLowBlink") # setting blendshape reverse connections rev_node = pm.createNode("reverse") pm.connectAttr(bs_upBlink[0].attr(midTarget.name()), rev_node + ".inputX") pm.connectAttr(rev_node + ".outputX", bs_upBlink[0].attr(upTarget.name())) rev_node = pm.createNode("reverse") pm.connectAttr(bs_lowBlink[0].attr(midTarget.name()), rev_node + ".inputX") pm.connectAttr(rev_node + ".outputX", bs_lowBlink[0].attr(lowTarget.name())) rev_node = pm.createNode("reverse") pm.connectAttr(bs_mid[0].attr(upTarget.name()), rev_node + ".inputX") pm.connectAttr(rev_node + ".outputX", bs_mid[0].attr(lowTarget.name())) # setting default values bs_mid[0].attr(upTarget.name()).set(blinkH) # joints root jnt_root = primitive.addTransformFromPos( eye_root, setName("joints"), pos=bboxCenter) # head joint if headJnt: try: headJnt = pm.PyNode(headJnt) jnt_base = headJnt except pm.MayaNodeError: pm.displayWarning( "Aborted can not find %s " % headJnt) return else: # Eye root jnt_base = jnt_root eyeTargets_root = primitive.addTransform(eye_root, setName("targets")) eyeCenter_jnt = rigbits.addJnt(arrow_ctl, jnt_base, grp=defset, jntName=setName("center_jnt")) # Upper Eyelid joints ################################################## cvs = upCrv.getCVs(space="world") upCrv_info = node.createCurveInfoNode(upCrv) # aim constrain targets and joints upperEyelid_aimTargets = [] upperEyelid_jnt = [] upperEyelid_jntRoot = [] for i, cv in enumerate(cvs): # aim targets trn = primitive.addTransformFromPos(eyeTargets_root, setName("upEyelid_aimTarget", i), pos=cv) upperEyelid_aimTargets.append(trn) # connecting positions with crv pm.connectAttr(upCrv_info + ".controlPoints[%s]" % str(i), trn.attr("translate")) # joints jntRoot = primitive.addJointFromPos(jnt_root, setName("upEyelid_jnt_base", i), pos=bboxCenter) jntRoot.attr("radius").set(.08) jntRoot.attr("visibility").set(False) upperEyelid_jntRoot.append(jntRoot) applyop.aimCns(jntRoot, trn, axis="zy", wupObject=jnt_root) jnt_ref = primitive.addJointFromPos(jntRoot, setName("upEyelid_jnt_ref", i), pos=cv) jnt_ref.attr("radius").set(.08) jnt_ref.attr("visibility").set(False) jnt = rigbits.addJnt(jnt_ref, jnt_base, grp=defset, jntName=setName("upEyelid_jnt", i)) upperEyelid_jnt.append(jnt) # Lower Eyelid joints ################################################## cvs = lowCrv.getCVs(space="world") lowCrv_info = node.createCurveInfoNode(lowCrv) # aim constrain targets and joints lowerEyelid_aimTargets = [] lowerEyelid_jnt = [] lowerEyelid_jntRoot = [] for i, cv in enumerate(cvs): if i in [0, len(cvs) - 1]: continue # aim targets trn = primitive.addTransformFromPos(eyeTargets_root, setName("lowEyelid_aimTarget", i), pos=cv) lowerEyelid_aimTargets.append(trn) # connecting positions with crv pm.connectAttr(lowCrv_info + ".controlPoints[%s]" % str(i), trn.attr("translate")) # joints jntRoot = primitive.addJointFromPos(jnt_root, setName("lowEyelid_base", i), pos=bboxCenter) jntRoot.attr("radius").set(.08) jntRoot.attr("visibility").set(False) lowerEyelid_jntRoot.append(jntRoot) applyop.aimCns(jntRoot, trn, axis="zy", wupObject=jnt_root) jnt_ref = primitive.addJointFromPos(jntRoot, setName("lowEyelid_jnt_ref", i), pos=cv) jnt_ref.attr("radius").set(.08) jnt_ref.attr("visibility").set(False) jnt = rigbits.addJnt(jnt_ref, jnt_base, grp=defset, jntName=setName("lowEyelid_jnt", i)) lowerEyelid_jnt.append(jnt) # Channels # Adding and connecting attributes for the blink up_ctl = upControls[2] blink_att = attribute.addAttribute( over_ctl, "blink", "float", 0, minValue=0, maxValue=1) blinkMult_att = attribute.addAttribute( over_ctl, "blinkMult", "float", 1, minValue=1, maxValue=2) midBlinkH_att = attribute.addAttribute( over_ctl, "blinkHeight", "float", blinkH, minValue=0, maxValue=1) mult_node = node.createMulNode(blink_att, blinkMult_att) pm.connectAttr(mult_node + ".outputX", bs_upBlink[0].attr(midTarget.name())) pm.connectAttr(mult_node + ".outputX", bs_lowBlink[0].attr(midTarget.name())) pm.connectAttr(midBlinkH_att, bs_mid[0].attr(upTarget.name())) low_ctl = lowControls[2] # Adding channels for eye tracking upVTracking_att = attribute.addAttribute(up_ctl, "vTracking", "float", .02, minValue=0, maxValue=1, keyable=False, channelBox=True) upHTracking_att = attribute.addAttribute(up_ctl, "hTracking", "float", .01, minValue=0, maxValue=1, keyable=False, channelBox=True) lowVTracking_att = attribute.addAttribute(low_ctl, "vTracking", "float", .01, minValue=0, maxValue=1, keyable=False, channelBox=True) lowHTracking_att = attribute.addAttribute(low_ctl, "hTracking", "float", .01, minValue=0, maxValue=1, keyable=False, channelBox=True) mult_node = node.createMulNode(upVTracking_att, aimTrigger_ref.attr("ty")) pm.connectAttr(mult_node + ".outputX", trackLvl[0].attr("ty")) mult_node = node.createMulNode(upHTracking_att, aimTrigger_ref.attr("tx")) pm.connectAttr(mult_node + ".outputX", trackLvl[0].attr("tx")) mult_node = node.createMulNode(lowVTracking_att, aimTrigger_ref.attr("ty")) pm.connectAttr(mult_node + ".outputX", trackLvl[1].attr("ty")) mult_node = node.createMulNode(lowHTracking_att, aimTrigger_ref.attr("tx")) pm.connectAttr(mult_node + ".outputX", trackLvl[1].attr("tx")) # Tension on blink node.createReverseNode(blink_att, w1.scale[0]) node.createReverseNode(blink_att, w3.scale[0]) node.createReverseNode(blink_att, w2.scale[0]) node.createReverseNode(blink_att, w4.scale[0]) ########################################### # Reparenting ########################################### if parent: try: if isinstance(parent, basestring): parent = pm.PyNode(parent) parent.addChild(eye_root) except pm.MayaNodeError: pm.displayWarning("The eye rig can not be parent to: %s. Maybe " "this object doesn't exist." % parent) ########################################### # Auto Skinning ########################################### if doSkin: # eyelid vertex rows totalLoops = rigidLoops + falloffLoops vertexLoopList = meshNavigation.getConcentricVertexLoop(vertexList, totalLoops) vertexRowList = meshNavigation.getVertexRowsFromLoops(vertexLoopList) # we set the first value 100% for the first initial loop skinPercList = [1.0] # we expect to have a regular grid topology for r in range(rigidLoops): for rr in range(2): skinPercList.append(1.0) increment = 1.0 / float(falloffLoops) # we invert to smooth out from 100 to 0 inv = 1.0 - increment for r in range(falloffLoops): for rr in range(2): if inv < 0.0: inv = 0.0 skinPercList.append(inv) inv -= increment # this loop add an extra 0.0 indices to avoid errors for r in range(10): for rr in range(2): skinPercList.append(0.0) # base skin geo = pm.listRelatives(edgeLoopList[0], parent=True)[0] # Check if the object has a skinCluster objName = pm.listRelatives(geo, parent=True)[0] skinCluster = skin.getSkinCluster(objName) if not skinCluster: skinCluster = pm.skinCluster(headJnt, geo, tsb=True, nw=2, n='skinClsEyelid') eyelidJoints = upperEyelid_jnt + lowerEyelid_jnt pm.progressWindow(title='Auto skinning process', progress=0, max=len(eyelidJoints)) firstBoundary = False for jnt in eyelidJoints: pm.progressWindow(e=True, step=1, status='\nSkinning %s' % jnt) skinCluster.addInfluence(jnt, weight=0) v = meshNavigation.getClosestVertexFromTransform(geo, jnt) for row in vertexRowList: if v in row: it = 0 # iterator inc = 1 # increment for i, rv in enumerate(row): try: perc = skinPercList[it] t_val = [(jnt, perc), (headJnt, 1.0 - perc)] pm.skinPercent(skinCluster, rv, transformValue=t_val) if rv.isOnBoundary(): # we need to compare with the first boundary # to check if the row have inverted direction # and offset the value if not firstBoundary: firstBoundary = True firstBoundaryValue = it else: if it < firstBoundaryValue: it -= 1 elif it > firstBoundaryValue: it += 1 inc = 2 except IndexError: continue it = it + inc pm.progressWindow(e=True, endProgress=True) # Eye Mesh skinning skinCluster = skin.getSkinCluster(eyeMesh) if not skinCluster: skinCluster = pm.skinCluster(eyeCenter_jnt, eyeMesh, tsb=True, nw=1, n='skinClsEye')
def addObjects(self): self.normal = self.getNormalFromPos(self.guide.apos) self.length0 = vec.getDistance(self.guide.apos[0], self.guide.apos[1]) self.length1 = vec.getDistance(self.guide.apos[1], self.guide.apos[2]) self.length2 = vec.getDistance(self.guide.apos[2], self.guide.apos[3]) # FK Controlers ----------------------------------- t = tra.getTransformLookingAt(self.guide.apos[0], self.guide.apos[1], self.normal, "xz", self.negate) ### FK NEUTRAL POSE IS DIFFERENT self.fk0_npo = pri.addTransform(self.root, self.getName("fk0_npo"), t) self.fk0_ctl = self.addCtl(self.fk0_npo, "fk0_ctl", t, self.color_fk, "cube", w=self.length0, h=self.size*.1, d=self.size*.1, po=dt.Vector(.5*self.length0*self.n_factor,0,0)) t = tra.getTransformLookingAt(self.guide.apos[1], self.guide.apos[2], self.normal, "xz", self.negate) self.fk1_ctl = self.addCtl(self.fk0_ctl, "fk1_ctl", t, self.color_fk, "cube", w=self.length1, h=self.size*.1, d=self.size*.1, po=dt.Vector(.5*self.length1*self.n_factor,0,0)) t = tra.getTransformLookingAt(self.guide.apos[2], self.guide.apos[3], self.normal, "xz", self.negate) self.fk2_ctl = self.addCtl(self.fk1_ctl, "fk2_ctl", t, self.color_fk, "cube", w=self.length2, h=self.size*.1, d=self.size*.1, po=dt.Vector(.5*self.length2*self.n_factor,0,0)) self.fk_ctl = [self.fk0_ctl, self.fk1_ctl, self.fk2_ctl] # IK Controlers ----------------------------------- self.ik_cns = pri.addTransformFromPos(self.root, self.getName("ik_cns"), self.guide.pos["wrist"]) self.ikcns_ctl = self.addCtl(self.ik_cns, "ikcns_ctl", tra.getTransformFromPos(self.guide.pos["wrist"]), self.color_ik, "null", w=self.size*.12) ### IK CONTROLER POSE IS DIFFERENT m = tra.getTransformLookingAt(self.guide.pos["wrist"], self.guide.pos["eff"], self.normal, "xz", False) self.ik_ctl = self.addCtl(self.ikcns_ctl, "ik_ctl", m, self.color_ik, "cube", w=self.size*.12, h=self.size*.12, d=self.size*.12) # upv v = self.guide.apos[2] - self.guide.apos[0] v = self.normal ^ v v.normalize() v *= self.size*.5 v += self.guide.apos[1] self.upv_cns = pri.addTransformFromPos(self.root, self.getName("upv_cns"), v) self.upv_ctl = self.addCtl(self.upv_cns, "upv_ctl", tra.getTransform(self.upv_cns), self.color_ik, "diamond", w=self.size*.12) att.setKeyableAttributes(self.upv_ctl, self.t_params) # References -------------------------------------- self.ik_ref = pri.addTransform(self.ik_ctl, self.getName("ik_ref"), tra.getTransform(self.ik_ctl)) self.fk_ref = pri.addTransform(self.fk_ctl[2], self.getName("fk_ref"), tra.getTransform(self.ik_ctl)) # Chain -------------------------------------------- # The outputs of the ikfk2bone solver self.bone0 = pri.addLocator(self.root, self.getName("0_jnt"), tra.getTransform(self.fk_ctl[0])) self.bone0_shp = self.bone0.getShape() self.bone0_shp.setAttr("localPositionX", self.n_factor*.5) self.bone0_shp.setAttr("localScale", .5, 0, 0) self.bone0.setAttr("sx", self.length0) self.bone0.setAttr("visibility", False) self.bone1 = pri.addLocator(self.root, self.getName("1_jnt"), tra.getTransform(self.fk_ctl[1])) self.bone1_shp = self.bone1.getShape() self.bone1_shp.setAttr("localPositionX", self.n_factor*.5) self.bone1_shp.setAttr("localScale", .5, 0, 0) self.bone1.setAttr("sx", self.length1) self.bone1.setAttr("visibility", False) self.ctrn_loc = pri.addTransformFromPos(self.root, self.getName("ctrn_loc"), self.guide.apos[1]) self.eff_loc = pri.addTransformFromPos(self.root, self.getName("eff_loc"), self.guide.apos[2]) # Mid Controler ------------------------------------ self.mid_ctl = self.addCtl(self.ctrn_loc, "mid_ctl", tra.getTransform(self.ctrn_loc), self.color_ik, "sphere", w=self.size*.2) # Twist references --------------------------------- x = dt.Vector(0,-1,0) x = x * tra.getTransform(self.eff_loc) z = dt.Vector(self.normal.x,self.normal.y,self.normal.z) z = z * tra.getTransform(self.eff_loc) m = tra.getRotationFromAxis(x, z, "xz", self.negate) m = tra.setMatrixPosition(m, tra.getTranslation(self.ik_ctl)) self.tws0_loc = pri.addTransform(self.root, self.getName("tws0_loc"), tra.getTransform(self.fk_ctl[0])) self.tws0_rot = pri.addTransform(self.tws0_loc, self.getName("tws0_rot"), tra.getTransform(self.fk_ctl[0])) self.tws1_loc = pri.addTransform(self.ctrn_loc, self.getName("tws1_loc"), tra.getTransform(self.ctrn_loc)) self.tws1_rot = pri.addTransform(self.tws1_loc, self.getName("tws1_rot"), tra.getTransform(self.ctrn_loc)) self.tws2_loc = pri.addTransform(self.root, self.getName("tws2_loc"), tra.getTransform(self.fk_ctl[2])) self.tws2_rot = pri.addTransform(self.tws2_loc, self.getName("tws2_rot"), tra.getTransform(self.fk_ctl[2])) self.tws2_rot.setAttr("sx", .001) # Divisions ---------------------------------------- # We have at least one division at the start, the end and one for the elbow. self.divisions = self.settings["div0"] + self.settings["div1"] + 3 self.div_cns = [] for i in range(self.divisions): div_cns = pri.addTransform(self.root, self.getName("div%s_loc" % i)) self.div_cns.append(div_cns) self.addShadow(div_cns, i) # End reference ------------------------------------ # To help the deformation on the wrist self.end_ref = pri.addTransform(self.tws2_rot, self.getName("end_ref"), m) self.addShadow(self.end_ref, "end")
def addObjects(self): self.normal = self.getNormalFromPos(self.guide.apos) self.binormal = self.getBiNormalFromPos(self.guide.apos) self.length0 = vec.getDistance(self.guide.apos[0], self.guide.apos[1]) self.length1 = vec.getDistance(self.guide.apos[1], self.guide.apos[2]) self.length2 = vec.getDistance(self.guide.apos[2], self.guide.apos[3]) # FK Controlers ----------------------------------- # *ms* set npo @ Tpose, to make the fk rotation work best with rot order"yzx" self.fk_cns = pri.addTransformFromPos(self.root, self.getName("fk_cns"), self.guide.apos[0]) tpv = self.guide.apos[0] + ( (self.guide.apos[1] - self.guide.apos[0]) * [1, 0, 0]) t = tra.getTransformLookingAt(self.guide.apos[0], tpv, self.normal, "xz", self.negate) # *ms* add FK isolation self.fk0_npo = pri.addTransform(self.fk_cns, self.getName("fk0_npo"), t) t = tra.getTransformLookingAt(self.guide.apos[0], self.guide.apos[1], self.normal, "xz", self.negate) self.fk0_ctl = self.addCtl(self.fk0_npo, "fk0_ctl", t, self.color_fk, "cube", w=self.length0 * .55, h=self.size * .1, d=self.size * .1, po=dt.Vector( .35 * self.length0 * self.n_factor, 0, 0)) att.setKeyableAttributes(self.fk0_ctl) # *ms* add fk roll control Simage style self.fk0_roll_ctl = self.addCtl(self.fk0_ctl, "fk0_roll_ctl", t, self.color_fk, "cube", w=self.length0 * .45, h=self.size * .1, d=self.size * .1, po=dt.Vector( .85 * self.length0 * self.n_factor, 0, 0)) att.setKeyableAttributes(self.fk0_roll_ctl) t = tra.getTransformLookingAt(self.guide.apos[1], self.guide.apos[2], self.normal, "xz", self.negate) self.fk1_npo = pri.addTransform(self.fk0_roll_ctl, self.getName("fk1_npo"), t) self.fk1_ctl = self.addCtl(self.fk1_npo, "fk1_ctl", t, self.color_fk, "cube", w=self.length1, h=self.size * .1, d=self.size * .1, po=dt.Vector( .5 * self.length1 * self.n_factor, 0, 0)) att.setKeyableAttributes(self.fk1_ctl) t = tra.getTransformLookingAt(self.guide.apos[2], self.guide.apos[3], self.normal, "xz", self.negate) # *ms* buffer object to feed into ikfk solver for hand seperation self.fk2_mtx = pri.addTransform(self.fk1_ctl, self.getName("fk2_mtx"), t) # fk2_npo is need to take the effector position self.fk2_npo = pri.addTransform(self.fk1_ctl, self.getName("fk2_npo"), t) self.fk2_ctl = self.addCtl(self.fk2_npo, "fk2_ctl", t, self.color_fk, "cube", w=self.length2, h=self.size * .1, d=self.size * .1, po=dt.Vector( .5 * self.length2 * self.n_factor, 0, 0)) att.setKeyableAttributes(self.fk2_ctl) self.fk_ctl = [self.fk0_roll_ctl, self.fk1_ctl, self.fk2_ctl] for x in self.fk_ctl: att.setInvertMirror(x, ["tx", "ty", "tz"]) # IK Controlers ----------------------------------- self.ik_cns = pri.addTransformFromPos(self.root, self.getName("ik_cns"), self.guide.pos["wrist"]) self.ikcns_ctl = self.addCtl(self.ik_cns, "ikcns_ctl", tra.getTransformFromPos( self.guide.pos["wrist"]), self.color_ik, "null", w=self.size * .12) att.setInvertMirror(self.ikcns_ctl, ["tx", "ty", "tz"]) if self.negate: m = tra.getTransformLookingAt(self.guide.pos["wrist"], self.guide.pos["eff"], self.normal, "x-y", True) else: m = tra.getTransformLookingAt(self.guide.pos["wrist"], self.guide.pos["eff"], self.normal, "xy", False) self.ik_ctl = self.addCtl(self.ikcns_ctl, "ik_ctl", m, self.color_ik, "cube", w=self.size * .12, h=self.size * .12, d=self.size * .12) att.setKeyableAttributes(self.ik_ctl) att.setInvertMirror(self.ik_ctl, ["tx", "ry", "rz"]) # upv v = self.guide.apos[2] - self.guide.apos[0] v = self.normal ^ v v.normalize() v *= self.size * .5 v += self.guide.apos[1] # *ms* auto up vector ------------------------------ self.upv_cns = pri.addTransformFromPos(self.root, self.getName("upv_cns"), self.guide.apos[0]) self.upv_auv = pri.addTransformFromPos(self.upv_cns, self.getName("upv_auv"), self.guide.apos[0]) self.upv_mtx = pri.addTransformFromPos(self.upv_cns, self.getName("upv_mtx"), self.guide.apos[0]) self.upv_npo = pri.addTransformFromPos(self.upv_mtx, self.getName("upv_npo"), v) self.upv_ctl = self.addCtl(self.upv_npo, "upv_ctl", tra.getTransform(self.upv_npo), self.color_ik, "diamond", w=self.size * .12) att.setKeyableAttributes(self.upv_ctl, self.t_params) att.setInvertMirror(self.upv_ctl, ["tx"]) # References -------------------------------------- # Calculate again the transfor for the IK ref. This way align with FK trnIK_ref = tra.getTransformLookingAt(self.guide.pos["wrist"], self.guide.pos["eff"], self.normal, "xz", self.negate) self.ik_ref = pri.addTransform(self.ik_ctl, self.getName("ik_ref"), trnIK_ref) self.fk_ref = pri.addTransform(self.fk_ctl[2], self.getName("fk_ref"), trnIK_ref) # Chain -------------------------------------------- # The outputs of the ikfk2bone solver self.bone0 = pri.addLocator(self.root, self.getName("0_bone"), tra.getTransform(self.fk_ctl[0])) self.bone0_shp = self.bone0.getShape() self.bone0_shp.setAttr("localPositionX", self.n_factor * .5) self.bone0_shp.setAttr("localScale", .5, 0, 0) self.bone0.setAttr("sx", self.length0) self.bone0.setAttr("visibility", False) self.bone1 = pri.addLocator(self.root, self.getName("1_bone"), tra.getTransform(self.fk_ctl[1])) self.bone1_shp = self.bone1.getShape() self.bone1_shp.setAttr("localPositionX", self.n_factor * .5) self.bone1_shp.setAttr("localScale", .5, 0, 0) self.bone1.setAttr("sx", self.length1) self.bone1.setAttr("visibility", False) self.ctrn_loc = pri.addTransformFromPos(self.root, self.getName("ctrn_loc"), self.guide.apos[1]) self.eff_npo = pri.addTransformFromPos(self.root, self.getName("eff_npo"), self.guide.apos[2]) self.eff_loc = pri.addTransformFromPos(self.eff_npo, self.getName("eff_loc"), self.guide.apos[2]) # Mid Controler ------------------------------------ self.mid_ctl = self.addCtl(self.ctrn_loc, "mid_ctl", tra.getTransform(self.ctrn_loc), self.color_ik, "sphere", w=self.size * .2) att.setInvertMirror(self.mid_ctl, ["tx", "ty", "tz"]) # *ms* add elbow thickness # # Twist references --------------------------------- # x = dt.Vector(0,-1,0) # x = x * tra.getTransform(self.eff_loc) # z = dt.Vector(self.normal.x,self.normal.y,self.normal.z) # z = z * tra.getTransform(self.eff_loc) # m = tra.getRotationFromAxis(x, z, "xz", self.negate) # m = tra.setMatrixPosition(m, tra.getTranslation(self.ik_ctl)) #Roll join ref #self.rollRef = pri.add2DChain(self.root, self.getName("rollChain"), self.guide.apos[:2], self.normal, self.negate) #for x in self.rollRef: # x.setAttr("visibility", False) self.tws0_npo = pri.addTransform(self.root, self.getName("tws0_npo"), tra.getTransform(self.fk_ctl[0])) self.tws0_loc = pri.addTransform(self.tws0_npo, self.getName("tws0_loc"), tra.getTransform(self.fk_ctl[0])) self.tws0_rot = pri.addTransform(self.tws0_loc, self.getName("tws0_rot"), tra.getTransform(self.fk_ctl[0])) self.tws1_npo = pri.addTransform(self.ctrn_loc, self.getName("tws1_npo"), tra.getTransform(self.ctrn_loc)) self.tws1_loc = pri.addTransform(self.tws1_npo, self.getName("tws1_loc"), tra.getTransform(self.ctrn_loc)) self.tws1_rot = pri.addTransform(self.tws1_loc, self.getName("tws1_rot"), tra.getTransform(self.ctrn_loc)) self.tws2_npo = pri.addTransform(self.root, self.getName("tws2_npo"), tra.getTransform(self.fk_ctl[2])) self.tws2_loc = pri.addTransform(self.tws2_npo, self.getName("tws2_loc"), tra.getTransform(self.fk_ctl[2])) self.tws2_rot = pri.addTransform(self.tws2_loc, self.getName("tws2_rot"), tra.getTransform(self.fk_ctl[2])) # Divisions ---------------------------------------- # We have at least one division at the start, the end and one for the elbow. + 2 for elbow angle control self.divisions = self.settings["div0"] + self.settings["div1"] + 3 + 2 self.div_cns = [] for i in range(self.divisions): div_cns = pri.addTransform(self.root, self.getName("div%s_loc" % i)) self.div_cns.append(div_cns) self.jnt_pos.append([div_cns, i]) # End reference ------------------------------------ # To help the deformation on the wrist self.jnt_pos.append([self.eff_loc, 'end']) # self.end_ref = pri.addTransform(self.eff_loc, self.getName("end_ref"), m) # for a in "xyz": # self.end_ref.attr("s%s"%a).set(1.0) # self.end_ref.attr("r%s"%a).set(0.0) # self.jnt_pos.append([self.end_ref, 'end']) #match IK FK references self.match_fk0_off = pri.addTransform(self.root, self.getName("matchFk0_npo"), tra.getTransform(self.fk_ctl[1])) # self.match_fk0_off.attr("tx").set(1.0) self.match_fk0 = pri.addTransform(self.match_fk0_off, self.getName("fk0_mth"), tra.getTransform(self.fk_ctl[0])) self.match_fk1_off = pri.addTransform(self.root, self.getName("matchFk1_npo"), tra.getTransform(self.fk_ctl[2])) # self.match_fk1_off.attr("tx").set(1.0) self.match_fk1 = pri.addTransform(self.match_fk1_off, self.getName("fk1_mth"), tra.getTransform(self.fk_ctl[1])) self.match_fk2 = pri.addTransform(self.ik_ctl, self.getName("fk2_mth"), tra.getTransform(self.fk_ctl[2])) self.match_ik = pri.addTransform(self.fk2_ctl, self.getName("ik_mth"), tra.getTransform(self.ik_ctl)) self.match_ikUpv = pri.addTransform(self.fk0_ctl, self.getName("upv_mth"), tra.getTransform(self.upv_ctl))
def addObjects(self): """Add all the objects needed to create the component.""" self.normal = self.guide.blades["blade"].z * -1 self.binormal = self.guide.blades["blade"].x self.isFk = self.settings["mode"] != 1 self.isIk = self.settings["mode"] != 0 self.isFkIk = self.settings["mode"] == 2 self.WIP = self.options["mode"] # FK controllers ------------------------------------ if self.isFk: self.fk_npo = [] self.fk_ctl = [] self.fk_ref = [] self.fk_off = [] t = self.guide.tra["root"] self.ik_cns = primitive.addTransform(self.root, self.getName("ik_cns"), t) parent = self.ik_cns tOld = False fk_ctl = None self.previusTag = self.parentCtlTag for i, t in enumerate( transform.getChainTransform(self.guide.apos, self.normal, self.negate)): dist = vector.getDistance(self.guide.apos[i], self.guide.apos[i + 1]) if self.settings["neutralpose"] or not tOld: tnpo = t else: tnpo = transform.setMatrixPosition( tOld, transform.getPositionFromMatrix(t)) if i: tref = transform.setMatrixPosition( tOld, transform.getPositionFromMatrix(t)) fk_ref = primitive.addTransform( fk_ctl, self.getName("fk%s_ref" % i), tref) self.fk_ref.append(fk_ref) else: tref = t fk_off = primitive.addTransform(parent, self.getName("fk%s_off" % i), tref) fk_npo = primitive.addTransform(fk_off, self.getName("fk%s_npo" % i), tnpo) fk_ctl = self.addCtl(fk_npo, "fk%s_ctl" % i, t, self.color_fk, "cube", w=dist, h=self.size * .1, d=self.size * .1, po=datatypes.Vector( dist * .5 * self.n_factor, 0, 0), tp=self.previusTag) self.fk_off.append(fk_off) self.fk_npo.append(fk_npo) self.fk_ctl.append(fk_ctl) tOld = t self.previusTag = fk_ctl # IK controllers ------------------------------------ if self.isIk: normal = vector.getTransposedVector( self.normal, [self.guide.apos[0], self.guide.apos[1]], [self.guide.apos[-2], self.guide.apos[-1]]) t = transform.getTransformLookingAt(self.guide.apos[-2], self.guide.apos[-1], normal, "xy", self.negate) t = transform.setMatrixPosition(t, self.guide.apos[-1]) self.ik_cns = primitive.addTransform(self.root, self.getName("ik_cns"), t) self.ikcns_ctl = self.addCtl(self.ik_cns, "ikcns_ctl", t, self.color_ik, "null", w=self.size, tp=self.parentCtlTag) self.ik_ctl = self.addCtl(self.ikcns_ctl, "ik_ctl", t, self.color_ik, "cube", w=self.size * .3, h=self.size * .3, d=self.size * .3, tp=self.ikcns_ctl) attribute.setKeyableAttributes(self.ik_ctl, self.t_params) v = self.guide.apos[-1] - self.guide.apos[0] v = v ^ self.normal v.normalize() v *= self.size v += self.guide.apos[1] self.upv_cns = primitive.addTransformFromPos( self.root, self.getName("upv_cns"), v) self.upv_ctl = self.addCtl(self.upv_cns, "upv_ctl", transform.getTransform(self.upv_cns), self.color_ik, "diamond", w=self.size * .1, tp=self.parentCtlTag) attribute.setKeyableAttributes(self.upv_ctl, self.t_params) # Chain self.chain = primitive.add2DChain(self.root, self.getName("chain"), self.guide.apos, self.normal, self.negate) self.chain[0].attr("visibility").set(self.WIP) # Chain of deformers ------------------------------- self.loc = [] parent = self.root for i, t in enumerate( transform.getChainTransform(self.guide.apos, self.normal, self.negate)): loc = primitive.addTransform(parent, self.getName("%s_loc" % i), t) self.loc.append(loc) self.jnt_pos.append([loc, i, None, False])
def addObjects(self): """Add all the objects needed to create the component.""" self.setup = primitive.addTransformFromPos(self.setupWS, self.getName("WS")) attribute.lockAttribute(self.setup) self.WIP = self.options["mode"] self.normal = self.getNormalFromPos(self.guide.apos) self.length0 = vector.getDistance(self.guide.apos[0], self.guide.apos[1]) self.length1 = vector.getDistance(self.guide.apos[1], self.guide.apos[2]) self.length2 = vector.getDistance(self.guide.apos[2], self.guide.apos[3]) self.length3 = vector.getDistance(self.guide.apos[3], self.guide.apos[4]) # 3bones chain self.chain3bones = primitive.add2DChain( self.setup, self.getName("chain3bones%s_jnt"), self.guide.apos[0:4], self.normal, False, self.WIP) # 2bones chain self.chain2bones = primitive.add2DChain( self.setup, self.getName("chain2bones%s_jnt"), self.guide.apos[0:3], self.normal, False, self.WIP) # Leg chain self.legBones = primitive.add2DChain(self.root, self.getName("legBones%s_jnt"), self.guide.apos[0:4], self.normal, False, self.WIP) # Leg chain FK ref self.legBonesFK = primitive.add2DChain(self.root, self.getName("legFK%s_jnt"), self.guide.apos[0:4], self.normal, False, self.WIP) # Leg chain IK ref self.legBonesIK = primitive.add2DChain(self.root, self.getName("legIK%s_jnt"), self.guide.apos[0:4], self.normal, False, self.WIP) # 1 bone chain for upv ref self.legChainUpvRef = primitive.add2DChain( self.root, self.getName("legUpvRef%s_jnt"), [self.guide.apos[0], self.guide.apos[3]], self.normal, False, self.WIP) # mid joints self.mid1_jnt = primitive.addJoint( self.legBones[0], self.getName("mid1_jnt"), self.legBones[1].getMatrix(worldSpace=True), self.WIP) self.mid1_jnt.attr("radius").set(3) self.mid1_jnt.setAttr("jointOrient", 0, 0, 0) self.mid2_jnt = primitive.addJoint( self.legBones[1], self.getName("mid2_jnt"), self.legBones[2].getMatrix(worldSpace=True), self.WIP) self.mid2_jnt.attr("radius").set(3) self.mid2_jnt.setAttr("jointOrient", 0, 0, 0) # base Controlers ----------------------------------- t = transform.getTransformFromPos(self.guide.apos[0]) self.root_npo = primitive.addTransform(self.root, self.getName("root_npo"), t) self.root_ctl = self.addCtl(self.root_npo, "root_ctl", t, self.color_fk, "circle", w=self.length0 / 6, tp=self.parentCtlTag) attribute.lockAttribute(self.root_ctl, ["sx", "sy", "sz", "v"]) # FK Controlers ----------------------------------- t = transform.getTransformLookingAt(self.guide.apos[0], self.guide.apos[1], self.normal, "xz", self.negate) self.fk0_npo = primitive.addTransform(self.root_ctl, self.getName("fk0_npo"), t) self.fk0_ctl = self.addCtl(self.fk0_npo, "fk0_ctl", t, self.color_fk, "cube", w=self.length0, h=self.size * .1, d=self.size * .1, po=datatypes.Vector( .5 * self.length0 * self.n_factor, 0, 0), tp=self.root_ctl) attribute.setKeyableAttributes(self.fk0_ctl) t = transform.getTransformLookingAt(self.guide.apos[1], self.guide.apos[2], self.normal, "xz", self.negate) self.fk1_npo = primitive.addTransform(self.fk0_ctl, self.getName("fk1_npo"), t) self.fk1_ctl = self.addCtl(self.fk1_npo, "fk1_ctl", t, self.color_fk, "cube", w=self.length1, h=self.size * .1, d=self.size * .1, po=datatypes.Vector( .5 * self.length1 * self.n_factor, 0, 0), tp=self.fk0_ctl) attribute.setKeyableAttributes(self.fk1_ctl) t = transform.getTransformLookingAt(self.guide.apos[2], self.guide.apos[3], self.normal, "xz", self.negate) self.fk2_npo = primitive.addTransform(self.fk1_ctl, self.getName("fk2_npo"), t) self.fk2_ctl = self.addCtl(self.fk2_npo, "fk2_ctl", t, self.color_fk, "cube", w=self.length2, h=self.size * .1, d=self.size * .1, po=datatypes.Vector( .5 * self.length2 * self.n_factor, 0, 0), tp=self.fk1_ctl) attribute.setKeyableAttributes(self.fk2_ctl) t = transform.getTransformLookingAt(self.guide.apos[3], self.guide.apos[4], self.normal, "xz", self.negate) self.fk3_npo = primitive.addTransform(self.fk2_ctl, self.getName("fk3_npo"), t) self.fk3_ctl = self.addCtl(self.fk3_npo, "fk3_ctl", t, self.color_fk, "cube", w=self.length3, h=self.size * .1, d=self.size * .1, po=datatypes.Vector( .5 * self.length3 * self.n_factor, 0, 0), tp=self.fk2_ctl) attribute.setKeyableAttributes(self.fk3_ctl) self.fk_ctl = [self.fk0_ctl, self.fk1_ctl, self.fk2_ctl, self.fk3_ctl] for x in self.fk_ctl: attribute.setInvertMirror(x, ["tx", "ty", "tz"]) # Mid Controlers ------------------------------------ self.knee_lvl = primitive.addTransform( self.root, self.getName("knee_lvl"), transform.getTransform(self.mid1_jnt)) self.knee_ctl = self.addCtl(self.knee_lvl, "knee_ctl", transform.getTransform(self.mid1_jnt), self.color_ik, "sphere", w=self.size * .2, tp=self.root_ctl) attribute.setInvertMirror(self.knee_ctl, ["tx", "ty", "tz"]) attribute.lockAttribute(self.knee_ctl, ["sx", "sy", "sz", "v"]) self.ankle_lvl = primitive.addTransform( self.root, self.getName("ankle_lvl"), transform.getTransform(self.mid2_jnt)) self.ankle_ctl = self.addCtl(self.ankle_lvl, "ankle_ctl", transform.getTransform(self.mid2_jnt), self.color_ik, "sphere", w=self.size * .2, tp=self.knee_ctl) attribute.setInvertMirror(self.ankle_ctl, ["tx", "ty", "tz"]) attribute.lockAttribute(self.ankle_ctl, ["sx", "sy", "sz", "v"]) # IK controls -------------------------------------------------------- # foot IK if self.settings["ikOri"]: t = transform.getTransformLookingAt(self.guide.pos["foot"], self.guide.pos["eff"], self.x_axis, "zx", False) else: t = transform.getTransformLookingAt(self.guide.apos[3], self.guide.apos[4], self.normal, "z-x", False) self.ik_cns = primitive.addTransform(self.root_ctl, self.getName("ik_cns"), t) self.ikcns_ctl = self.addCtl(self.ik_cns, "ikcns_ctl", t, self.color_ik, "null", w=self.size * .12, tp=self.ankle_ctl) attribute.setInvertMirror(self.ikcns_ctl, ["tx"]) attribute.lockAttribute(self.ikcns_ctl, ["sx", "sy", "sz", "v"]) self.ik_ctl = self.addCtl(self.ikcns_ctl, "ik_ctl", t, self.color_ik, "cube", w=self.size * .12, h=self.size * .12, d=self.size * .12, tp=self.ikcns_ctl) attribute.setKeyableAttributes(self.ik_ctl) attribute.setRotOrder(self.ik_ctl, "XZY") attribute.setInvertMirror(self.ik_ctl, ["tx", "ry", "rz"]) attribute.lockAttribute(self.ik_ctl, ["sx", "sy", "sz", "v"]) # 2 bones ik layer self.ik2b_ikCtl_ref = primitive.addTransform( self.ik_ctl, self.getName("ik2B_A_ref"), t) self.ik2b_bone_ref = primitive.addTransform(self.chain3bones[3], self.getName("ik2B_B_ref"), t) self.ik2b_blend = primitive.addTransform(self.ik_ctl, self.getName("ik2B_blend"), t) self.roll_ctl = self.addCtl(self.ik2b_blend, "roll_ctl", t, self.color_ik, "crossarrow", w=self.length2 * .5 * self.n_factor, tp=self.ik_ctl) self.ik2b_ik_npo = primitive.addTransform( self.roll_ctl, self.getName("ik2B_ik_npo"), transform.getTransform(self.chain3bones[-1])) self.ik2b_ik_ref = primitive.addTransformFromPos( self.ik2b_ik_npo, self.getName("ik2B_ik_ref"), self.guide.pos["ankle"]) attribute.lockAttribute(self.roll_ctl, ["tx", "ty", "tz", "sx", "sy", "sz", "v"]) # upv v = self.guide.apos[2] - self.guide.apos[0] v = self.normal ^ v v.normalize() v *= self.size * .5 v += self.guide.apos[1] self.upv_lvl = primitive.addTransformFromPos(self.root, self.getName("upv_lvl"), v) self.upv_cns = primitive.addTransformFromPos(self.upv_lvl, self.getName("upv_cns"), v) self.upv_ctl = self.addCtl(self.upv_cns, "upv_ctl", transform.getTransform(self.upv_cns), self.color_ik, "diamond", w=self.size * .12, tp=self.ik_ctl) attribute.setInvertMirror(self.upv_ctl, ["tx"]) attribute.setKeyableAttributes(self.upv_ctl, ["tx", "ty", "tz"]) # Soft IK objects 3 bones chain -------------------------------- t = transform.getTransformLookingAt(self.guide.pos["root"], self.guide.pos["foot"], self.x_axis, "zx", False) self.aim_tra = primitive.addTransform(self.root_ctl, self.getName("aimSoftIK"), t) t = transform.getTransformFromPos(self.guide.pos["foot"]) self.wristSoftIK = primitive.addTransform(self.aim_tra, self.getName("wristSoftIK"), t) self.softblendLoc = primitive.addTransform( self.root, self.getName("softblendLoc"), t) # Soft IK objects 2 Bones chain ---------------------------- t = transform.getTransformLookingAt(self.guide.pos["root"], self.guide.pos["ankle"], self.x_axis, "zx", False) self.aim_tra2 = primitive.addTransform(self.root_ctl, self.getName("aimSoftIK2"), t) t = transform.getTransformFromPos(self.guide.pos["ankle"]) self.ankleSoftIK = primitive.addTransform(self.aim_tra2, self.getName("ankleSoftIK"), t) self.softblendLoc2 = primitive.addTransform( self.root, self.getName("softblendLoc2"), t) # References -------------------------------------- self.ik_ref = primitive.addTransform( self.ik_ctl, self.getName("ik_ref"), transform.getTransform(self.ik_ctl)) self.fk_ref = primitive.addTransform( self.fk_ctl[3], self.getName("fk_ref"), transform.getTransform(self.ik_ctl)) # twist references -------------------------------------- self.rollRef = primitive.add2DChain(self.root, self.getName("rollChain"), self.guide.apos[:2], self.normal, False, self.WIP) self.tws0_loc = primitive.addTransform( self.rollRef[0], self.getName("tws0_loc"), transform.getTransform(self.legBones[0])) self.tws0_rot = primitive.addTransform( self.tws0_loc, self.getName("tws0_rot"), transform.getTransform(self.legBones[0])) self.tws0_rot.setAttr("sx", .001) self.tws1_loc = primitive.addTransform( self.mid1_jnt, self.getName("tws1_loc"), transform.getTransform(self.mid1_jnt)) self.tws1_rot = primitive.addTransform( self.tws1_loc, self.getName("tws1_rot"), transform.getTransform(self.mid1_jnt)) self.tws1_rot.setAttr("sx", .001) self.tws2_loc = primitive.addTransform( self.mid2_jnt, self.getName("tws2_loc"), transform.getTransform(self.mid2_jnt)) self.tws2_rot = primitive.addTransform( self.tws2_loc, self.getName("tws2_rot"), transform.getTransform(self.mid2_jnt)) self.tws2_rot.setAttr("sx", .001) self.tws3_loc = primitive.addTransform( self.legBones[3], self.getName("tws3_loc"), transform.getTransform(self.legBones[3])) self.tws3_rot = primitive.addTransform( self.tws3_loc, self.getName("tws3_rot"), transform.getTransform(self.legBones[3])) self.tws3_rot.setAttr("sx", .001) # Divisions ---------------------------------------- # We have at least one division at the start, the end and one for # the knee and one ankle o_set = self.settings self.divisions = o_set["div0"] + o_set["div1"] + o_set["div2"] + 4 self.div_cns = [] for i in range(self.divisions): div_cns = primitive.addTransform(self.root_ctl, self.getName("div%s_loc" % i)) self.div_cns.append(div_cns) self.jnt_pos.append([div_cns, i]) # End reference ------------------------------------ # To help the deformation on the foot self.end_ref = primitive.addTransform( self.tws3_rot, self.getName("end_ref"), transform.getTransform(self.legBones[3])) self.jnt_pos.append([self.end_ref, 'end'])
def addObjects(self): self.normal = self.getNormalFromPos(self.guide.apos) self.length0 = vec.getDistance(self.guide.apos[0], self.guide.apos[1]) self.length1 = vec.getDistance(self.guide.apos[1], self.guide.apos[2]) self.length2 = vec.getDistance(self.guide.apos[2], self.guide.apos[3]) # FK Controlers ----------------------------------- t = tra.getTransformLookingAt(self.guide.apos[0], self.guide.apos[1], self.normal, "xz", self.negate) ### FK NEUTRAL POSE IS DIFFERENT self.fk0_npo = pri.addTransform(self.root, self.getName("fk0_npo"), t) self.fk0_ctl = self.addCtl(self.fk0_npo, "fk0_ctl", t, self.color_fk, "cube", w=self.length0, h=self.size * .1, d=self.size * .1, po=dt.Vector( .5 * self.length0 * self.n_factor, 0, 0)) t = tra.getTransformLookingAt(self.guide.apos[1], self.guide.apos[2], self.normal, "xz", self.negate) self.fk1_ctl = self.addCtl(self.fk0_ctl, "fk1_ctl", t, self.color_fk, "cube", w=self.length1, h=self.size * .1, d=self.size * .1, po=dt.Vector( .5 * self.length1 * self.n_factor, 0, 0)) t = tra.getTransformLookingAt(self.guide.apos[2], self.guide.apos[3], self.normal, "xz", self.negate) self.fk2_ctl = self.addCtl(self.fk1_ctl, "fk2_ctl", t, self.color_fk, "cube", w=self.length2, h=self.size * .1, d=self.size * .1, po=dt.Vector( .5 * self.length2 * self.n_factor, 0, 0)) self.fk_ctl = [self.fk0_ctl, self.fk1_ctl, self.fk2_ctl] # IK Controlers ----------------------------------- self.ik_cns = pri.addTransformFromPos(self.root, self.getName("ik_cns"), self.guide.pos["wrist"]) self.ikcns_ctl = self.addCtl(self.ik_cns, "ikcns_ctl", tra.getTransformFromPos( self.guide.pos["wrist"]), self.color_ik, "null", w=self.size * .12) ### IK CONTROLER POSE IS DIFFERENT m = tra.getTransformLookingAt(self.guide.pos["wrist"], self.guide.pos["eff"], self.normal, "xz", False) self.ik_ctl = self.addCtl(self.ikcns_ctl, "ik_ctl", m, self.color_ik, "cube", w=self.size * .12, h=self.size * .12, d=self.size * .12) # upv v = self.guide.apos[2] - self.guide.apos[0] v = self.normal ^ v v.normalize() v *= self.size * .5 v += self.guide.apos[1] self.upv_cns = pri.addTransformFromPos(self.root, self.getName("upv_cns"), v) self.upv_ctl = self.addCtl(self.upv_cns, "upv_ctl", tra.getTransform(self.upv_cns), self.color_ik, "diamond", w=self.size * .12) att.setKeyableAttributes(self.upv_ctl, self.t_params) # References -------------------------------------- self.ik_ref = pri.addTransform(self.ik_ctl, self.getName("ik_ref"), tra.getTransform(self.ik_ctl)) self.fk_ref = pri.addTransform(self.fk_ctl[2], self.getName("fk_ref"), tra.getTransform(self.ik_ctl)) # Chain -------------------------------------------- # The outputs of the ikfk2bone solver self.bone0 = pri.addLocator(self.root, self.getName("0_jnt"), tra.getTransform(self.fk_ctl[0])) self.bone0_shp = self.bone0.getShape() self.bone0_shp.setAttr("localPositionX", self.n_factor * .5) self.bone0_shp.setAttr("localScale", .5, 0, 0) self.bone0.setAttr("sx", self.length0) self.bone0.setAttr("visibility", False) self.bone1 = pri.addLocator(self.root, self.getName("1_jnt"), tra.getTransform(self.fk_ctl[1])) self.bone1_shp = self.bone1.getShape() self.bone1_shp.setAttr("localPositionX", self.n_factor * .5) self.bone1_shp.setAttr("localScale", .5, 0, 0) self.bone1.setAttr("sx", self.length1) self.bone1.setAttr("visibility", False) self.ctrn_loc = pri.addTransformFromPos(self.root, self.getName("ctrn_loc"), self.guide.apos[1]) self.eff_loc = pri.addTransformFromPos(self.root, self.getName("eff_loc"), self.guide.apos[2]) # Mid Controler ------------------------------------ self.mid_ctl = self.addCtl(self.ctrn_loc, "mid_ctl", tra.getTransform(self.ctrn_loc), self.color_ik, "sphere", w=self.size * .2) # Twist references --------------------------------- x = dt.Vector(0, -1, 0) x = x * tra.getTransform(self.eff_loc) z = dt.Vector(self.normal.x, self.normal.y, self.normal.z) z = z * tra.getTransform(self.eff_loc) m = tra.getRotationFromAxis(x, z, "xz", self.negate) m = tra.setMatrixPosition(m, tra.getTranslation(self.ik_ctl)) self.tws0_loc = pri.addTransform(self.root, self.getName("tws0_loc"), tra.getTransform(self.fk_ctl[0])) self.tws0_rot = pri.addTransform(self.tws0_loc, self.getName("tws0_rot"), tra.getTransform(self.fk_ctl[0])) self.tws1_loc = pri.addTransform(self.ctrn_loc, self.getName("tws1_loc"), tra.getTransform(self.ctrn_loc)) self.tws1_rot = pri.addTransform(self.tws1_loc, self.getName("tws1_rot"), tra.getTransform(self.ctrn_loc)) self.tws2_loc = pri.addTransform(self.root, self.getName("tws2_loc"), tra.getTransform(self.fk_ctl[2])) self.tws2_rot = pri.addTransform(self.tws2_loc, self.getName("tws2_rot"), tra.getTransform(self.fk_ctl[2])) self.tws2_rot.setAttr("sx", .001) # Divisions ---------------------------------------- # We have at least one division at the start, the end and one for the elbow. self.divisions = self.settings["div0"] + self.settings["div1"] + 3 self.div_cns = [] for i in range(self.divisions): div_cns = pri.addTransform(self.root, self.getName("div%s_loc" % i)) self.div_cns.append(div_cns) self.addShadow(div_cns, i) # End reference ------------------------------------ # To help the deformation on the wrist self.end_ref = pri.addTransform(self.tws2_rot, self.getName("end_ref"), m) self.addShadow(self.end_ref, "end")
def addObjects(self): """Add all the objects needed to create the component.""" self.WIP = self.options["mode"] self.normal = self.getNormalFromPos(self.guide.apos) self.binormal = self.getBiNormalFromPos(self.guide.apos) self.length0 = vector.getDistance(self.guide.apos[0], self.guide.apos[1]) self.length1 = vector.getDistance(self.guide.apos[1], self.guide.apos[2]) self.length2 = vector.getDistance(self.guide.apos[2], self.guide.apos[3]) # 1 bone chain for upv ref self.armChainUpvRef = primitive.add2DChain( self.root, self.getName("armUpvRef%s_jnt"), [self.guide.apos[0], self.guide.apos[2]], self.normal, False, self.WIP) negateOri = self.armChainUpvRef[1].getAttr("jointOrientZ") * -1 self.armChainUpvRef[1].setAttr("jointOrientZ", negateOri) # FK Controlers ----------------------------------- t = transform.getTransformLookingAt(self.guide.apos[0], self.guide.apos[1], self.normal, "xz", self.negate) self.fk0_npo = primitive.addTransform(self.root, self.getName("fk0_npo"), t) vec_po = datatypes.Vector(.5 * self.length0 * self.n_factor, 0, 0) self.fk0_ctl = self.addCtl(self.fk0_npo, "fk0_ctl", t, self.color_fk, "cube", w=self.length0, h=self.size * .1, d=self.size * .1, po=vec_po, tp=self.parentCtlTag) attribute.setKeyableAttributes( self.fk0_ctl, ["tx", "ty", "tz", "ro", "rx", "ry", "rz", "sx"]) t = transform.getTransformLookingAt(self.guide.apos[1], self.guide.apos[2], self.normal, "xz", self.negate) self.fk1_npo = primitive.addTransform(self.fk0_ctl, self.getName("fk1_npo"), t) vec_po = datatypes.Vector(.5 * self.length1 * self.n_factor, 0, 0) self.fk1_ctl = self.addCtl(self.fk1_npo, "fk1_ctl", t, self.color_fk, "cube", w=self.length1, h=self.size * .1, d=self.size * .1, po=vec_po, tp=self.fk0_ctl) attribute.setKeyableAttributes( self.fk1_ctl, ["tx", "ty", "tz", "ro", "rx", "ry", "rz", "sx"]) t = transform.getTransformLookingAt(self.guide.apos[2], self.guide.apos[3], self.normal, "xz", self.negate) self.fk2_npo = primitive.addTransform(self.fk1_ctl, self.getName("fk2_npo"), t) vec_po = datatypes.Vector(.5 * self.length2 * self.n_factor, 0, 0) self.fk2_ctl = self.addCtl(self.fk2_npo, "fk2_ctl", t, self.color_fk, "cube", w=self.length2, h=self.size * .1, d=self.size * .1, po=vec_po, tp=self.fk1_ctl) attribute.setKeyableAttributes(self.fk2_ctl) self.fk_ctl = [self.fk0_ctl, self.fk1_ctl, self.fk2_ctl] for x in self.fk_ctl: attribute.setInvertMirror(x, ["tx", "ty", "tz"]) # IK upv --------------------------------- v = self.guide.apos[2] - self.guide.apos[0] v = self.normal ^ v v.normalize() v *= self.size * .5 v += self.guide.apos[1] self.upv_cns = primitive.addTransformFromPos(self.root, self.getName("upv_cns"), v) self.upv_ctl = self.addCtl(self.upv_cns, "upv_ctl", transform.getTransform(self.upv_cns), self.color_ik, "diamond", w=self.size * .12, tp=self.parentCtlTag) if self.settings["mirrorMid"]: if self.negate: self.upv_cns.rz.set(180) self.upv_cns.sy.set(-1) else: attribute.setInvertMirror(self.upv_ctl, ["tx"]) attribute.setKeyableAttributes(self.upv_ctl, self.t_params) # IK Controlers ----------------------------------- self.ik_cns = primitive.addTransformFromPos( self.root, self.getName("ik_cns"), self.guide.pos["wrist"]) t = transform.getTransformFromPos(self.guide.pos["wrist"]) self.ikcns_ctl = self.addCtl(self.ik_cns, "ikcns_ctl", t, self.color_ik, "null", w=self.size * .12, tp=self.parentCtlTag) attribute.setInvertMirror(self.ikcns_ctl, ["tx", "ty", "tz"]) if self.negate: m = transform.getTransformLookingAt(self.guide.pos["wrist"], self.guide.pos["eff"], self.normal, "x-y", True) else: m = transform.getTransformLookingAt(self.guide.pos["wrist"], self.guide.pos["eff"], self.normal, "xy", False) self.ik_ctl = self.addCtl(self.ikcns_ctl, "ik_ctl", m, self.color_ik, "cube", w=self.size * .12, h=self.size * .12, d=self.size * .12, tp=self.upv_ctl) if self.settings["mirrorIK"]: if self.negate: self.ik_cns.sx.set(-1) self.ik_ctl.rz.set(self.ik_ctl.rz.get() * -1) else: attribute.setInvertMirror(self.ik_ctl, ["tx", "ry", "rz"]) attribute.setKeyableAttributes(self.ik_ctl) self.ik_ctl_ref = primitive.addTransform(self.ik_ctl, self.getName("ikCtl_ref"), m) # IK rotation controls if self.settings["ikTR"]: self.ikRot_npo = primitive.addTransform(self.root, self.getName("ikRot_npo"), m) self.ikRot_cns = primitive.addTransform(self.ikRot_npo, self.getName("ikRot_cns"), m) self.ikRot_ctl = self.addCtl(self.ikRot_cns, "ikRot_ctl", m, self.color_ik, "sphere", w=self.size * .12, tp=self.ik_ctl) attribute.setKeyableAttributes(self.ikRot_ctl, self.r_params) # References -------------------------------------- # Calculate again the transfor for the IK ref. This way align with FK trnIK_ref = transform.getTransformLookingAt(self.guide.pos["wrist"], self.guide.pos["eff"], self.normal, "xz", self.negate) self.ik_ref = primitive.addTransform(self.ik_ctl_ref, self.getName("ik_ref"), trnIK_ref) self.fk_ref = primitive.addTransform(self.fk_ctl[2], self.getName("fk_ref"), trnIK_ref) # Chain -------------------------------------------- # The outputs of the ikfk2bone solver self.bone0 = primitive.addLocator( self.root, self.getName("0_bone"), transform.getTransform(self.fk_ctl[0])) self.bone0_shp = self.bone0.getShape() self.bone0_shp.setAttr("localPositionX", self.n_factor * .5) self.bone0_shp.setAttr("localScale", .5, 0, 0) self.bone0.setAttr("sx", self.length0) self.bone0.setAttr("visibility", False) self.bone1 = primitive.addLocator( self.root, self.getName("1_bone"), transform.getTransform(self.fk_ctl[1])) self.bone1_shp = self.bone1.getShape() self.bone1_shp.setAttr("localPositionX", self.n_factor * .5) self.bone1_shp.setAttr("localScale", .5, 0, 0) self.bone1.setAttr("sx", self.length1) self.bone1.setAttr("visibility", False) self.ctrn_loc = primitive.addTransformFromPos(self.root, self.getName("ctrn_loc"), self.guide.apos[1]) self.eff_loc = primitive.addTransformFromPos(self.root, self.getName("eff_loc"), self.guide.apos[2]) # Mid Controler ------------------------------------ t = transform.getTransform(self.ctrn_loc) self.mid_cns = primitive.addTransform(self.ctrn_loc, self.getName("mid_cns"), t) self.mid_ctl = self.addCtl(self.mid_cns, "mid_ctl", t, self.color_ik, "sphere", w=self.size * .2, tp=self.parentCtlTag) attribute.setKeyableAttributes(self.mid_ctl, params=["tx", "ty", "tz", "ro", "rx", "ry", "rz", "sx"]) if self.settings["mirrorMid"]: if self.negate: self.mid_cns.rz.set(180) self.mid_cns.sz.set(-1) self.mid_ctl_twst_npo = primitive.addTransform( self.mid_ctl, self.getName("mid_twst_npo"), t) self.mid_ctl_twst_ref = primitive.addTransform( self.mid_ctl_twst_npo, self.getName("mid_twst_ref"), t) else: self.mid_ctl_twst_ref = self.mid_ctl attribute.setInvertMirror(self.mid_ctl, ["tx", "ty", "tz"]) # Roll join ref self.rollRef = primitive.add2DChain(self.root, self.getName( "rollChain"), self.guide.apos[:2], self.normal, self.negate) for x in self.rollRef: x.setAttr("visibility", False) self.tws0_loc = primitive.addTransform( self.rollRef[0], self.getName("tws0_loc"), transform.getTransform(self.fk_ctl[0])) self.tws0_rot = primitive.addTransform( self.tws0_loc, self.getName("tws0_rot"), transform.getTransform(self.fk_ctl[0])) self.tws1_npo = primitive.addTransform( self.ctrn_loc, self.getName("tws1_npo"), transform.getTransform(self.ctrn_loc)) self.tws1_loc = primitive.addTransform( self.tws1_npo, self.getName("tws1_loc"), transform.getTransform(self.ctrn_loc)) self.tws1_rot = primitive.addTransform( self.tws1_loc, self.getName("tws1_rot"), transform.getTransform(self.ctrn_loc)) self.tws2_npo = primitive.addTransform( self.root, self.getName("tws2_npo"), transform.getTransform(self.fk_ctl[2])) self.tws2_loc = primitive.addTransform( self.tws2_npo, self.getName("tws2_loc"), transform.getTransform(self.fk_ctl[2])) self.tws2_rot = primitive.addTransform( self.tws2_loc, self.getName("tws2_rot"), transform.getTransform(self.fk_ctl[2])) # Divisions ---------------------------------------- # We have at least one division at the start, the end and one for the # elbow. + 2 for elbow angle control self.divisions = self.settings["div0"] + self.settings["div1"] + 3 + 2 self.div_cns = [] if self.settings["extraTweak"]: tagP = self.parentCtlTag self.tweak_ctl = [] for i in range(self.divisions): div_cns = primitive.addTransform(self.root, self.getName("div%s_loc" % i)) self.div_cns.append(div_cns) if self.settings["extraTweak"]: t = transform.getTransform(div_cns) tweak_ctl = self.addCtl(div_cns, "tweak%s_ctl" % i, t, self.color_fk, "square", w=self.size * .15, d=self.size * .15, ro=datatypes.Vector([0, 0, 1.5708]), tp=tagP) attribute.setKeyableAttributes(tweak_ctl) tagP = tweak_ctl self.tweak_ctl.append(tweak_ctl) self.jnt_pos.append([tweak_ctl, i, None, False]) else: self.jnt_pos.append([div_cns, i]) # End reference ------------------------------------ # To help the deformation on the wrist self.jnt_pos.append([self.eff_loc, 'end']) # match IK FK references self.match_fk0_off = primitive.addTransform( self.root, self.getName("matchFk0_npo"), transform.getTransform(self.fk_ctl[1])) self.match_fk0 = primitive.addTransform( self.match_fk0_off, self.getName("fk0_mth"), transform.getTransform(self.fk_ctl[0])) self.match_fk1_off = primitive.addTransform( self.root, self.getName( "matchFk1_npo"), transform.getTransform(self.fk_ctl[2])) self.match_fk1 = primitive.addTransform( self.match_fk1_off, self.getName("fk1_mth"), transform.getTransform(self.fk_ctl[1])) if self.settings["ikTR"]: reference = self.ikRot_ctl self.match_ikRot = primitive.addTransform( self.fk2_ctl, self.getName("ikRot_mth"), transform.getTransform(self.ikRot_ctl)) else: reference = self.ik_ctl self.match_fk2 = primitive.addTransform( reference, self.getName("fk2_mth"), transform.getTransform(self.fk_ctl[2])) self.match_ik = primitive.addTransform( self.fk2_ctl, self.getName("ik_mth"), transform.getTransform(self.ik_ctl)) self.match_ikUpv = primitive.addTransform( self.fk0_ctl, self.getName("upv_mth"), transform.getTransform(self.upv_ctl))
def addObjects(self): """ """ self.WIP = self.options["mode"] self.normal = self.getNormalFromPos(self.guide.apos) self.binormal = self.getBiNormalFromPos(self.guide.apos) self.length0 = vec.getDistance(self.guide.apos[0], self.guide.apos[1]) self.length1 = vec.getDistance(self.guide.apos[1], self.guide.apos[2]) self.length2 = vec.getDistance(self.guide.apos[2], self.guide.apos[3]) # 1 bone chain for upv ref self.armChainUpvRef = pri.add2DChain( self.root, self.getName("armUpvRef%s_jnt"), [self.guide.apos[0], self.guide.apos[2]], self.normal, False, self.WIP) self.armChainUpvRef[1].setAttr( "jointOrientZ", self.armChainUpvRef[1].getAttr("jointOrientZ") * -1) # FK Controlers ----------------------------------- t = tra.getTransformLookingAt(self.guide.apos[0], self.guide.apos[1], self.normal, "xz", self.negate) self.fk0_npo = pri.addTransform(self.root, self.getName("fk0_npo"), t) self.fk0_ctl = self.addCtl(self.fk0_npo, "fk0_ctl", t, self.color_fk, "cube", w=self.length0, h=self.size * .1, d=self.size * .1, po=dt.Vector( .5 * self.length0 * self.n_factor, 0, 0)) att.setKeyableAttributes(self.fk0_ctl) t = tra.getTransformLookingAt(self.guide.apos[1], self.guide.apos[2], self.normal, "xz", self.negate) self.fk1_npo = pri.addTransform(self.fk0_ctl, self.getName("fk1_npo"), t) self.fk1_ctl = self.addCtl(self.fk1_npo, "fk1_ctl", t, self.color_fk, "cube", w=self.length1, h=self.size * .1, d=self.size * .1, po=dt.Vector( .5 * self.length1 * self.n_factor, 0, 0)) att.setKeyableAttributes(self.fk1_ctl) t = tra.getTransformLookingAt(self.guide.apos[2], self.guide.apos[3], self.normal, "xz", self.negate) self.fk2_npo = pri.addTransform(self.fk1_ctl, self.getName("fk2_npo"), t) self.fk2_ctl = self.addCtl(self.fk2_npo, "fk2_ctl", t, self.color_fk, "cube", w=self.length2, h=self.size * .1, d=self.size * .1, po=dt.Vector( .5 * self.length2 * self.n_factor, 0, 0)) att.setKeyableAttributes(self.fk2_ctl) self.fk_ctl = [self.fk0_ctl, self.fk1_ctl, self.fk2_ctl] for x in self.fk_ctl: att.setInvertMirror(x, ["tx", "ty", "tz"]) # IK Controlers ----------------------------------- self.ik_cns = pri.addTransformFromPos(self.root, self.getName("ik_cns"), self.guide.pos["wrist"]) self.ikcns_ctl = self.addCtl(self.ik_cns, "ikcns_ctl", tra.getTransformFromPos( self.guide.pos["wrist"]), self.color_ik, "null", w=self.size * .12) att.setInvertMirror(self.ikcns_ctl, ["tx", "ty", "tz"]) if self.negate: m = tra.getTransformLookingAt(self.guide.pos["wrist"], self.guide.pos["eff"], self.normal, "x-y", True) else: m = tra.getTransformLookingAt(self.guide.pos["wrist"], self.guide.pos["eff"], self.normal, "xy", False) self.ik_ctl = self.addCtl(self.ikcns_ctl, "ik_ctl", m, self.color_ik, "cube", w=self.size * .12, h=self.size * .12, d=self.size * .12) att.setKeyableAttributes(self.ik_ctl) att.setInvertMirror(self.ik_ctl, ["tx", "ry", "rz"]) # upv v = self.guide.apos[2] - self.guide.apos[0] v = self.normal ^ v v.normalize() v *= self.size * .5 v += self.guide.apos[1] self.upv_cns = pri.addTransformFromPos(self.root, self.getName("upv_cns"), v) self.upv_ctl = self.addCtl(self.upv_cns, "upv_ctl", tra.getTransform(self.upv_cns), self.color_ik, "diamond", w=self.size * .12) att.setKeyableAttributes(self.upv_ctl, self.t_params) att.setInvertMirror(self.upv_ctl, ["tx"]) #IK rotation controls if self.settings["ikTR"]: self.ikRot_npo = pri.addTransform(self.root, self.getName("ikRot_npo"), m) self.ikRot_cns = pri.addTransform(self.ikRot_npo, self.getName("ikRot_cns"), m) self.ikRot_ctl = self.addCtl(self.ikRot_cns, "ikRot_ctl", m, self.color_ik, "sphere", w=self.size * .12) att.setKeyableAttributes(self.ikRot_ctl, ["rx", "ry", "rz"]) # References -------------------------------------- # Calculate again the transfor for the IK ref. This way align with FK trnIK_ref = tra.getTransformLookingAt(self.guide.pos["wrist"], self.guide.pos["eff"], self.normal, "xz", self.negate) self.ik_ref = pri.addTransform(self.ik_ctl, self.getName("ik_ref"), trnIK_ref) self.fk_ref = pri.addTransform(self.fk_ctl[2], self.getName("fk_ref"), trnIK_ref) # Chain -------------------------------------------- # The outputs of the ikfk2bone solver self.bone0 = pri.addLocator(self.root, self.getName("0_bone"), tra.getTransform(self.fk_ctl[0])) self.bone0_shp = self.bone0.getShape() self.bone0_shp.setAttr("localPositionX", self.n_factor * .5) self.bone0_shp.setAttr("localScale", .5, 0, 0) self.bone0.setAttr("sx", self.length0) self.bone0.setAttr("visibility", False) self.bone1 = pri.addLocator(self.root, self.getName("1_bone"), tra.getTransform(self.fk_ctl[1])) self.bone1_shp = self.bone1.getShape() self.bone1_shp.setAttr("localPositionX", self.n_factor * .5) self.bone1_shp.setAttr("localScale", .5, 0, 0) self.bone1.setAttr("sx", self.length1) self.bone1.setAttr("visibility", False) self.ctrn_loc = pri.addTransformFromPos(self.root, self.getName("ctrn_loc"), self.guide.apos[1]) self.eff_loc = pri.addTransformFromPos(self.root, self.getName("eff_loc"), self.guide.apos[2]) # Mid Controler ------------------------------------ self.mid_ctl = self.addCtl(self.ctrn_loc, "mid_ctl", tra.getTransform(self.ctrn_loc), self.color_ik, "sphere", w=self.size * .2) att.setInvertMirror(self.mid_ctl, ["tx", "ty", "tz"]) #Roll join ref self.rollRef = pri.add2DChain(self.root, self.getName("rollChain"), self.guide.apos[:2], self.normal, self.negate) for x in self.rollRef: x.setAttr("visibility", False) self.tws0_loc = pri.addTransform(self.rollRef[0], self.getName("tws0_loc"), tra.getTransform(self.fk_ctl[0])) self.tws0_rot = pri.addTransform(self.tws0_loc, self.getName("tws0_rot"), tra.getTransform(self.fk_ctl[0])) self.tws1_npo = pri.addTransform(self.ctrn_loc, self.getName("tws1_npo"), tra.getTransform(self.ctrn_loc)) self.tws1_loc = pri.addTransform(self.tws1_npo, self.getName("tws1_loc"), tra.getTransform(self.ctrn_loc)) self.tws1_rot = pri.addTransform(self.tws1_loc, self.getName("tws1_rot"), tra.getTransform(self.ctrn_loc)) self.tws2_npo = pri.addTransform(self.root, self.getName("tws2_npo"), tra.getTransform(self.fk_ctl[2])) self.tws2_loc = pri.addTransform(self.tws2_npo, self.getName("tws2_loc"), tra.getTransform(self.fk_ctl[2])) self.tws2_rot = pri.addTransform(self.tws2_loc, self.getName("tws2_rot"), tra.getTransform(self.fk_ctl[2])) # Divisions ---------------------------------------- # We have at least one division at the start, the end and one for the elbow. + 2 for elbow angle control self.divisions = self.settings["div0"] + self.settings["div1"] + 3 + 2 self.div_cns = [] for i in range(self.divisions): div_cns = pri.addTransform(self.root, self.getName("div%s_loc" % i)) self.div_cns.append(div_cns) self.jnt_pos.append([div_cns, i]) # End reference ------------------------------------ # To help the deformation on the wrist self.jnt_pos.append([self.eff_loc, 'end']) #match IK FK references self.match_fk0_off = pri.addTransform(self.root, self.getName("matchFk0_npo"), tra.getTransform(self.fk_ctl[1])) # self.match_fk0_off.attr("tx").set(1.0) self.match_fk0 = pri.addTransform(self.match_fk0_off, self.getName("fk0_mth"), tra.getTransform(self.fk_ctl[0])) self.match_fk1_off = pri.addTransform(self.root, self.getName("matchFk1_npo"), tra.getTransform(self.fk_ctl[2])) # self.match_fk1_off.attr("tx").set(1.0) self.match_fk1 = pri.addTransform(self.match_fk1_off, self.getName("fk1_mth"), tra.getTransform(self.fk_ctl[1])) self.match_fk2 = pri.addTransform(self.ik_ctl, self.getName("fk2_mth"), tra.getTransform(self.fk_ctl[2])) self.match_ik = pri.addTransform(self.fk2_ctl, self.getName("ik_mth"), tra.getTransform(self.ik_ctl)) self.match_ikUpv = pri.addTransform(self.fk0_ctl, self.getName("upv_mth"), tra.getTransform(self.upv_ctl))
def addObjects(self): self.WIP = self.options["mode"] self.normal = self.getNormalFromPos(self.guide.apos) self.binormal = self.getBiNormalFromPos(self.guide.apos) self.length0 = vec.getDistance(self.guide.apos[0], self.guide.apos[1]) self.length1 = vec.getDistance(self.guide.apos[1], self.guide.apos[2]) self.length2 = vec.getDistance(self.guide.apos[2], self.guide.apos[3]) # FK Controlers ----------------------------------- t = tra.getTransformLookingAt(self.guide.apos[0], self.guide.apos[1], self.normal, "xz", self.negate) self.fk0_npo = pri.addTransform(self.root, self.getName("fk0_npo"), t) self.fk0_ctl = self.addCtl(self.fk0_npo, "fk0_ctl", t, self.color_fk, "cube", w=self.length0, h=self.size * .1, d=self.size * .1, po=dt.Vector( .5 * self.length0 * self.n_factor, 0, 0)) att.setKeyableAttributes(self.fk0_ctl) t = tra.getTransformLookingAt(self.guide.apos[1], self.guide.apos[2], self.normal, "xz", self.negate) self.fk1_npo = pri.addTransform(self.fk0_ctl, self.getName("fk1_npo"), t) self.fk1_ctl = self.addCtl(self.fk1_npo, "fk1_ctl", t, self.color_fk, "cube", w=self.length1, h=self.size * .1, d=self.size * .1, po=dt.Vector( .5 * self.length1 * self.n_factor, 0, 0)) att.setKeyableAttributes(self.fk1_ctl) t = tra.getTransformLookingAt(self.guide.apos[2], self.guide.apos[3], self.normal, "xz", self.negate) self.fk2_npo = pri.addTransform(self.fk1_ctl, self.getName("fk2_npo"), t) self.fk2_ctl = self.addCtl(self.fk2_npo, "fk2_ctl", t, self.color_fk, "cube", w=self.length2, h=self.size * .1, d=self.size * .1, po=dt.Vector( .5 * self.length2 * self.n_factor, 0, 0)) att.setKeyableAttributes(self.fk2_ctl) self.fk_ctl = [self.fk0_ctl, self.fk1_ctl, self.fk2_ctl] for x in self.fk_ctl: att.setInvertMirror(x, ["tx", "ty", "tz"]) # IK Controlers ----------------------------------- self.ik_cns = pri.addTransformFromPos(self.root, self.getName("ik_cns"), self.guide.pos["wrist"]) self.ikcns_ctl = self.addCtl(self.ik_cns, "ikcns_ctl", tra.getTransformFromPos( self.guide.pos["wrist"]), self.color_ik, "null", w=self.size * .12) att.setInvertMirror(self.ikcns_ctl, ["tx", "ty", "tz"]) if self.negate: m = tra.getTransformLookingAt(self.guide.pos["wrist"], self.guide.pos["eff"], self.normal, "x-y", True) else: m = tra.getTransformLookingAt(self.guide.pos["wrist"], self.guide.pos["eff"], self.normal, "xy", False) self.ik_ctl = self.addCtl(self.ikcns_ctl, "ik_ctl", m, self.color_ik, "cube", w=self.size * .12, h=self.size * .12, d=self.size * .12) att.setKeyableAttributes(self.ik_ctl) att.setInvertMirror(self.ik_ctl, ["tx", "ry", "rz"]) # upv v = self.guide.apos[2] - self.guide.apos[0] v = self.normal ^ v v.normalize() v *= self.size * .5 v += self.guide.apos[1] self.upv_cns = pri.addTransformFromPos(self.root, self.getName("upv_cns"), v) self.upv_ctl = self.addCtl(self.upv_cns, "upv_ctl", tra.getTransform(self.upv_cns), self.color_ik, "diamond", w=self.size * .12) att.setInvertMirror(self.upv_ctl, ["tx"]) # References -------------------------------------- # Calculate again the transfor for the IK ref. This way align with FK trnIK_ref = tra.getTransformLookingAt(self.guide.pos["wrist"], self.guide.pos["eff"], self.normal, "xz", self.negate) self.ik_ref = pri.addTransform(self.ik_ctl, self.getName("ik_ref"), trnIK_ref) self.fk_ref = pri.addTransform(self.fk_ctl[2], self.getName("fk_ref"), trnIK_ref) # Chain -------------------------------------------- # The outputs of the ikfk2bone solver self.bone0 = pri.addLocator(self.root, self.getName("0_bone"), tra.getTransform(self.fk_ctl[0])) self.bone0_shp = self.bone0.getShape() self.bone0_shp.setAttr("localPositionX", self.n_factor * .5) self.bone0_shp.setAttr("localScale", .5, 0, 0) self.bone0.setAttr("sx", self.length0) bShape = self.bone0.getShape() bShape.setAttr("visibility", False) self.bone1 = pri.addLocator(self.root, self.getName("1_bone"), tra.getTransform(self.fk_ctl[1])) self.bone1_shp = self.bone1.getShape() self.bone1_shp.setAttr("localPositionX", self.n_factor * .5) self.bone1_shp.setAttr("localScale", .5, 0, 0) self.bone1.setAttr("sx", self.length1) bShape = self.bone1.getShape() bShape.setAttr("visibility", False) #Elbow control tA = tra.getTransformLookingAt(self.guide.apos[0], self.guide.apos[1], self.normal, "xz", self.negate) tA = tra.setMatrixPosition(tA, self.guide.apos[1]) tB = tra.getTransformLookingAt(self.guide.apos[1], self.guide.apos[2], self.normal, "xz", self.negate) t = tra.getInterpolateTransformMatrix(tA, tB) self.ctrn_loc = pri.addTransform(self.root, self.getName("ctrn_loc"), t) #match IK FK references self.match_fk0_off = pri.addTransform(self.root, self.getName("matchFk0_npo"), tra.getTransform(self.fk_ctl[1])) # self.match_fk0_off.attr("tx").set(1.0) self.match_fk0 = pri.addTransform(self.match_fk0_off, self.getName("fk0_mth"), tra.getTransform(self.fk_ctl[0])) self.match_fk1_off = pri.addTransform(self.root, self.getName("matchFk1_npo"), tra.getTransform(self.fk_ctl[2])) # self.match_fk1_off.attr("tx").set(1.0) self.match_fk1 = pri.addTransform(self.match_fk1_off, self.getName("fk1_mth"), tra.getTransform(self.fk_ctl[1])) self.match_fk2 = pri.addTransform(self.ik_ctl, self.getName("fk2_mth"), tra.getTransform(self.fk_ctl[2])) self.match_ik = pri.addTransform(self.fk2_ctl, self.getName("ik_mth"), tra.getTransform(self.ik_ctl)) self.match_ikUpv = pri.addTransform(self.fk0_ctl, self.getName("upv_mth"), tra.getTransform(self.upv_ctl)) # Eff locator self.eff_loc = pri.addTransformFromPos(self.root, self.getName("eff_loc"), self.guide.apos[2]) # Mid Controler ------------------------------------ self.mid_ctl = self.addCtl(self.ctrn_loc, "mid_ctl", tra.getTransform(self.ctrn_loc), self.color_ik, "sphere", w=self.size * .2) att.setInvertMirror(self.mid_ctl, ["tx", "ty", "tz"]) #Roll join ref--------------------------------- self.tws0_loc = pri.addTransform(self.root, self.getName("tws0_loc"), tra.getTransform(self.fk_ctl[0])) self.tws1_npo = pri.addTransform(self.ctrn_loc, self.getName("tws1_npo"), tra.getTransform(self.ctrn_loc)) self.tws1_loc = pri.addTransform(self.tws1_npo, self.getName("tws1_loc"), tra.getTransform(self.ctrn_loc)) self.tws1A_npo = pri.addTransform(self.mid_ctl, self.getName("tws1A_npo"), tA) self.tws1A_loc = pri.addTransform(self.tws1A_npo, self.getName("tws1A_loc"), tA) self.tws1B_npo = pri.addTransform(self.mid_ctl, self.getName("tws1B_npo"), tB) self.tws1B_loc = pri.addTransform(self.tws1B_npo, self.getName("tws1B_loc"), tB) self.tws2_npo = pri.addTransform(self.root, self.getName("tws2_npo"), tra.getTransform(self.fk_ctl[2])) self.tws2_loc = pri.addTransform(self.tws2_npo, self.getName("tws2_loc"), tra.getTransform(self.fk_ctl[2])) # Roll twist chain --------------------------------- #Arm self.armChainPos = [] ii = 1.0 / (self.settings["div0"] + 1) i = 0.0 for p in range(self.settings["div0"] + 2): self.armChainPos.append( vec.linearlyInterpolate(self.guide.pos["root"], self.guide.pos["elbow"], blend=i)) i = i + ii self.armTwistChain = pri.add2DChain(self.root, self.getName("armTwist%s_jnt"), self.armChainPos, self.normal, False, self.WIP) #Forearm self.forearmChainPos = [] ii = 1.0 / (self.settings["div1"] + 1) i = 0.0 for p in range(self.settings["div1"] + 2): self.forearmChainPos.append( vec.linearlyInterpolate(self.guide.pos["elbow"], self.guide.pos["wrist"], blend=i)) i = i + ii self.forearmTwistChain = pri.add2DChain( self.root, self.getName("forearmTwist%s_jnt"), self.forearmChainPos, self.normal, False, self.WIP) pm.parent(self.forearmTwistChain[0], self.mid_ctl) #Hand Aux chain and nonroll self.auxChainPos = [] ii = .5 i = 0.0 for p in range(3): self.auxChainPos.append( vec.linearlyInterpolate(self.guide.pos["wrist"], self.guide.pos["eff"], blend=i)) i = i + ii t = self.root.getMatrix(worldSpace=True) self.aux_npo = pri.addTransform(self.root, self.getName("aux_npo"), t) self.auxTwistChain = pri.add2DChain(self.aux_npo, self.getName("auxTwist%s_jnt"), self.auxChainPos, self.normal, False, self.WIP) #Non Roll join ref --------------------------------- self.armRollRef = pri.add2DChain(self.root, self.getName("armRollRef%s_jnt"), self.armChainPos[:2], self.normal, False, self.WIP) self.forearmRollRef = pri.add2DChain( self.aux_npo, self.getName("forearmRollRef%s_jnt"), self.auxChainPos[:2], self.normal, False, self.WIP) # Divisions ---------------------------------------- # We have at least one division at the start, the end and one for the elbow. + 2 for elbow angle control self.divisions = self.settings["div0"] + self.settings["div1"] + 4 self.div_cns = [] for i in range(self.divisions): div_cns = pri.addTransform(self.root, self.getName("div%s_loc" % i)) self.div_cns.append(div_cns) self.jnt_pos.append([div_cns, i]) # End reference ------------------------------------ # To help the deformation on the wrist self.end_ref = pri.addTransform(self.eff_loc, self.getName("end_ref"), tra.getTransform(self.eff_loc)) if self.negate: self.end_ref.attr("rz").set(180.0) self.jnt_pos.append([self.end_ref, "end"]) # Tangent controls t = tra.getInterpolateTransformMatrix(self.fk_ctl[0], self.tws1A_npo, .3333) self.armTangentA_loc = pri.addTransform( self.root, self.getName("armTangentA_loc"), self.fk_ctl[0].getMatrix(worldSpace=True)) self.armTangentA_npo = pri.addTransform( self.armTangentA_loc, self.getName("armTangentA_npo"), t) self.armTangentA_ctl = self.addCtl(self.armTangentA_npo, "armTangentA_ctl", t, self.color_ik, "circle", w=self.size * .2, ro=dt.Vector(0, 0, 1.570796)) t = tra.getInterpolateTransformMatrix(self.fk_ctl[0], self.tws1A_npo, .6666) self.armTangentB_npo = pri.addTransform( self.tws1A_loc, self.getName("armTangentB_npo"), t) self.armTangentB_ctl = self.addCtl(self.armTangentB_npo, "armTangentB_ctl", t, self.color_ik, "circle", w=self.size * .2, ro=dt.Vector(0, 0, 1.570796)) tC = self.tws1B_npo.getMatrix(worldSpace=True) tC = tra.setMatrixPosition(tC, self.guide.apos[2]) t = tra.getInterpolateTransformMatrix(self.tws1B_npo, tC, .3333) self.forearmTangentA_npo = pri.addTransform( self.tws1B_loc, self.getName("forearmTangentA_npo"), t) self.forearmTangentA_ctl = self.addCtl(self.forearmTangentA_npo, "forearmTangentA_ctl", t, self.color_ik, "circle", w=self.size * .2, ro=dt.Vector(0, 0, 1.570796)) t = tra.getInterpolateTransformMatrix(self.tws1B_npo, tC, .6666) self.forearmTangentB_loc = pri.addTransform( self.root, self.getName("forearmTangentB_loc"), tC) self.forearmTangentB_npo = pri.addTransform( self.forearmTangentB_loc, self.getName("forearmTangentB_npo"), t) self.forearmTangentB_ctl = self.addCtl(self.forearmTangentB_npo, "forearmTangentB_ctl", t, self.color_ik, "circle", w=self.size * .2, ro=dt.Vector(0, 0, 1.570796)) t = self.mid_ctl.getMatrix(worldSpace=True) self.elbowTangent_npo = pri.addTransform( self.mid_ctl, self.getName("elbowTangent_npo"), t) self.elbowTangent_ctl = self.addCtl(self.elbowTangent_npo, "elbowTangent_ctl", t, self.color_fk, "circle", w=self.size * .25, ro=dt.Vector(0, 0, 1.570796))
def addObjects(self): self.normal = self.guide.blades["blade"].z*-1 self.binormal = self.guide.blades["blade"].x self.isFk = self.settings["mode"] != 1 self.isIk = self.settings["mode"] != 0 self.isFkIk = self.settings["mode"] == 2 self.WIP = self.options["mode"] # FK controllers ------------------------------------ if self.isFk: self.fk_npo = [] self.fk_ctl = [] t = self.guide.tra["root"] self.ik_cns = pri.addTransform(self.root, self.getName("ik_cns"), t) parent = self.ik_cns tOld = False for i, t in enumerate(tra.getChainTransform(self.guide.apos, self.normal, self.negate)): dist = vec.getDistance(self.guide.apos[i], self.guide.apos[i+1]) if self.settings["neutralpose"] or not tOld: tnpo = t else: tnpo = tra.setMatrixPosition(tOld, tra.getPositionFromMatrix(t)) fk_npo = pri.addTransform(parent, self.getName("fk%s_npo"%i), tnpo) fk_ctl = self.addCtl(fk_npo, "fk%s_ctl"%i, t, self.color_fk, "cube", w=dist, h=self.size*.1, d=self.size*.1, po=dt.Vector(dist*.5*self.n_factor,0,0)) parent = fk_ctl self.fk_npo.append(fk_npo) self.fk_ctl.append(fk_ctl) tOld = t # IK controllers ------------------------------------ if self.isIk: normal = vec.getTransposedVector(self.normal, [self.guide.apos[0], self.guide.apos[1]], [self.guide.apos[-2], self.guide.apos[-1]]) t = tra.getTransformLookingAt(self.guide.apos[-2], self.guide.apos[-1], normal, "xy", self.negate) t = tra.setMatrixPosition(t, self.guide.apos[-1]) self.ik_cns = pri.addTransform(self.root, self.getName("ik_cns"), t) self.ikcns_ctl = self.addCtl(self.ik_cns, "ikcns_ctl", t, self.color_ik, "null", w=self.size) self.ik_ctl = self.addCtl(self.ikcns_ctl, "ik_ctl", t, self.color_ik, "cube", w=self.size*.3, h=self.size*.3, d=self.size*.3) v = self.guide.apos[-1] - self.guide.apos[0] v = v ^ self.normal v.normalize() v *= self.size v += self.guide.apos[1] self.upv_cns = pri.addTransformFromPos(self.root, self.getName("upv_cns"), v) self.upv_ctl = self.addCtl(self.upv_cns, "upv_ctl", tra.getTransform(self.upv_cns), self.color_ik, "diamond", w=self.size*.1) # Chain self.chain = pri.add2DChain(self.root, self.getName("chain"), self.guide.apos, self.normal, self.negate) self.chain[0].attr("visibility").set(self.WIP) # Chain of deformers ------------------------------- self.loc = [] parent = self.root for i, t in enumerate(tra.getChainTransform(self.guide.apos, self.normal, self.negate)): loc = pri.addTransform(parent, self.getName("%s_loc"%i), t) self.loc.append(loc) self.jnt_pos.append([loc, i]) parent = loc