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.WIP = self.options["mode"] if self.negate and self.settings["overrideNegate"]: self.negate = False self.n_factor = 1 if self.settings["overrideNegate"]: self.mirror_conf = [0, 0, 1, 1, 1, 0, 0, 0, 0] else: self.mirror_conf = [0, 0, 0, 0, 0, 0, 0, 0, 0] # FK controllers ------------------------------------ self.fk_npo = [] self.fk_ctl = [] t = self.guide.tra["root"] parent = self.root 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)) fk_npo = primitive.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=datatypes.Vector(dist * .5 * self.n_factor, 0, 0), tp=self.previusTag, mirrorConf=self.mirror_conf) self.fk_npo.append(fk_npo) self.fk_ctl.append(fk_ctl) tOld = t self.previusTag = fk_ctl parent = fk_ctl if self.settings["addJoints"]: jnt_name = "_".join([self.name, str(i + 1).zfill(2)]) self.jnt_pos.append([fk_ctl, jnt_name, None, False])
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.previousTag = 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) # ro is rotation offset. Yup. They coded it in radians... 1.5708 rad is 90 deg :\ fk_ctl = self.addCtl( fk_npo, "fk%s_ctl" % i, t, self.color_fk, "compas", w=dist, po=datatypes.Vector(0, 0, 0), ro=datatypes.Vector(-1.5708, 0 - 1.5708), tp=self.previousTag, ) # lock vis attribute.lockAttribute(fk_ctl, attributes=['v']) # set rotateOrder to xzy. "Barrel roll" rotx remains stable. Spread roty stays on plane of hands. fk_ctl.rotateOrder.set(3) self.fk_off.append(fk_off) self.fk_npo.append(fk_npo) self.fk_ctl.append(fk_ctl) tOld = t self.previousTag = 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) attribute.lockAttribute(self.ik_ctl, attributes=['v']) 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.normal = self.guide.blades["blade"].z * -1 self.binormal = self.guide.blades["blade"].x self.WIP = self.options["mode"] if self.negate and self.settings["overrideNegate"]: self.negate = False self.n_factor = 1 if self.settings["overrideNegate"]: self.mirror_conf = [0, 0, 1, 1, 1, 0, 0, 0, 0] else: self.mirror_conf = [0, 0, 0, 0, 0, 0, 0, 0, 0] # FK controllers ------------------------------------ self.fk_npo = [] self.fk_global_in = [] self.fk_local_in = [] self.fk_local_out = [] self.fk_global_out = [] self.fk_global_ref = [] self.fk_ctl = [] self.tweak_ctl = [] self.upv_curv_lvl = [] t = self.guide.tra["root"] parent = self.root tOld = False fk_ctl = None self.previusTag = self.parentCtlTag for i, t in enumerate(transform.getChainTransform(self.guide.apos, self.normal, self.negate)): self.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)) # global input global_t = transform.setMatrixPosition( datatypes.Matrix(), transform.getPositionFromMatrix(t)) fk_global_npo = primitive.addTransform( parent, self.getName("fk%s_global_npo" % i), global_t) fk_global_in = primitive.addTransform( fk_global_npo, self.getName("fk%s_global_in" % i), global_t) self.fk_global_in.append(fk_global_in) # local input fk_local_npo = primitive.addTransform( fk_global_in, self.getName("fk%s_local_npo" % i), tnpo) fk_local_in = primitive.addTransform( fk_local_npo, self.getName("fk%s_local_in" % i), tnpo) self.fk_local_in.append(fk_local_in) # output fk_global_out_npo = primitive.addTransform( parent, self.getName("fk%s_global_out_npo" % i), global_t) fk_global_out = primitive.addTransform( fk_global_out_npo, self.getName("fk%s_global_out" % i), global_t) self.fk_global_out.append(fk_global_out) fk_local_out_npo = primitive.addTransform( parent, self.getName("fk%s_local_out_npo" % i), tnpo) fk_local_out = primitive.addTransform( fk_local_out_npo, self.getName("fk%s_local_out" % i), tnpo) self.fk_local_out.append(fk_local_out) # fk npo fk_npo = primitive.addTransform( fk_local_in, self.getName("fk%s_npo" % i), tnpo) self.fk_npo.append(fk_npo) # ctl fk_ctl = self.addCtl( fk_npo, "fk%s_ctl" % i, t, self.color_fk, "cube", w=self.dist, h=self.size * .1, d=self.size * .1, po=datatypes.Vector(self.dist * .5 * self.n_factor, 0, 0), tp=self.previusTag, mirrorConf=self.mirror_conf) self.fk_ctl.append(fk_ctl) # fk global ref fk_global_ref = primitive.addTransform( fk_ctl, self.getName("fk%s_global_ref" % i), global_t) self.fk_global_ref.append(fk_global_ref) attribute.setKeyableAttributes(fk_global_ref, []) parent = fk_ctl self.previusTag = fk_ctl if self.settings["addJoints"]: self.jnt_pos.append([fk_ctl, i, None, False])
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.WIP = self.options["mode"] if self.negate and self.settings["overrideNegate"]: self.negate = False self.n_factor = 1 if self.settings["overrideNegate"]: self.mirror_conf = [0, 0, 1, 1, 1, 0, 0, 0, 0] else: self.mirror_conf = [0, 0, 0, 0, 0, 0, 0, 0, 0] # FK controllers ------------------------------------ self.fk_npo = [] self.fk_global_in = [] self.fk_local_in = [] self.fk_local_out = [] self.fk_global_out = [] self.fk_global_ref = [] self.fk_ctl = [] self.tweak_ctl = [] self.upv_curv_lvl = [] t = self.guide.tra["root"] parent = self.root tOld = False fk_ctl = None self.previusTag = self.parentCtlTag for i, t in enumerate( transform.getChainTransform(self.guide.apos, self.normal, self.negate)): self.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)) # global input global_t = transform.setMatrixPosition( datatypes.Matrix(), transform.getPositionFromMatrix(t)) fk_global_npo = primitive.addTransform( parent, self.getName("fk%s_global_npo" % i), global_t) fk_global_in = primitive.addTransform( fk_global_npo, self.getName("fk%s_global_in" % i), global_t) self.fk_global_in.append(fk_global_in) # local input fk_local_npo = primitive.addTransform( fk_global_in, self.getName("fk%s_local_npo" % i), tnpo) fk_local_in = primitive.addTransform( fk_local_npo, self.getName("fk%s_local_in" % i), tnpo) self.fk_local_in.append(fk_local_in) # output fk_global_out_npo = primitive.addTransform( parent, self.getName("fk%s_global_out_npo" % i), global_t) fk_global_out = primitive.addTransform( fk_global_out_npo, self.getName("fk%s_global_out" % i), global_t) self.fk_global_out.append(fk_global_out) fk_local_out_npo = primitive.addTransform( parent, self.getName("fk%s_local_out_npo" % i), tnpo) fk_local_out = primitive.addTransform( fk_local_out_npo, self.getName("fk%s_local_out" % i), tnpo) self.fk_local_out.append(fk_local_out) # fk npo fk_npo = primitive.addTransform(fk_local_in, self.getName("fk%s_npo" % i), tnpo) self.fk_npo.append(fk_npo) # ctl fk_ctl = self.addCtl(fk_npo, "fk%s_ctl" % i, t, self.color_fk, "cube", w=self.dist, h=self.size * .1, d=self.size * .1, po=datatypes.Vector( self.dist * .5 * self.n_factor, 0, 0), tp=self.previusTag, mirrorConf=self.mirror_conf) self.fk_ctl.append(fk_ctl) # fk global ref fk_global_ref = primitive.addTransform( fk_ctl, self.getName("fk%s_global_ref" % i), global_t) self.fk_global_ref.append(fk_global_ref) attribute.setKeyableAttributes(fk_global_ref, []) parent = fk_ctl if not self.settings["simpleFK"]: tweak_ctl = self.addCtl(fk_ctl, "tweak%s_ctl" % i, t, self.color_ik, "square", w=self.size * .15, h=self.size * .15, d=self.size * .15, ro=datatypes.Vector([0, 0, 1.5708]), tp=self.previusTag, mirrorConf=self.mirror_conf) upv_curv_lvl = primitive.addTransform( tweak_ctl, self.getName("upv%s_lvl" % i), t) upv_curv_lvl.attr("tz").set(.01) self.tweak_ctl.append(tweak_ctl) self.upv_curv_lvl.append(upv_curv_lvl) tOld = t self.previusTag = fk_ctl if not self.settings["simpleFK"]: # add end control tweak_npo = primitive.addTransform(fk_ctl, self.getName("tweakEnd_npo"), t) tweak_ctl = self.addCtl(tweak_npo, "tweakEnd_ctl", t, self.color_ik, "square", w=self.size * .15, h=self.size * .15, d=self.size * .15, ro=datatypes.Vector([0, 0, 1.5708]), tp=self.previusTag, mirrorConf=self.mirror_conf) upv_curv_lvl = primitive.addTransform(tweak_ctl, self.getName("upvEnd_lvl"), t) upv_curv_lvl.attr("tz").set(.01) if self.negate: self.off_dist = self.dist * -1 else: self.off_dist = self.dist tweak_npo.attr("tx").set(self.off_dist) self.tweak_ctl.append(tweak_ctl) self.upv_curv_lvl.append(upv_curv_lvl) # add length offset control if keep length # This option will be added only if keep length is active if self.settings["keepLength"]: self.tweakTip_npo = primitive.addTransform( tweak_ctl, self.getName("tweakTip_npo"), t) tweak_ctl = self.addCtl(self.tweakTip_npo, "tweakTip_ctl", t, self.color_fk, "square", w=self.size * .1, h=self.size * .1, d=self.size * .1, ro=datatypes.Vector([0, 0, 1.5708]), tp=self.previusTag, mirrorConf=self.mirror_conf) upv_curv_lvl = primitive.addTransform( tweak_ctl, self.getName("upvTip_lvl"), t) upv_curv_lvl.attr("tz").set(.01) # move to align with the parent self.tweakTip_npo.attr("tx").set(0) self.tweak_ctl.append(tweak_ctl) self.upv_curv_lvl.append(upv_curv_lvl) # add visual reference self.line_ref = icon.connection_display_curve( self.getName("visualRef"), [self.tweakTip_npo.getParent(), tweak_ctl]) # set keyable attr for tweak controls [ attribute.setKeyableAttributes(t_ctl, ["tx", "ty", "tz", "rx"]) for t_ctl in self.tweak_ctl ] # Curves ------------------------------------------- self.mst_crv = curve.addCnsCurve(self.root, self.getName("mst_crv"), self.tweak_ctl[:], 3) self.upv_crv = curve.addCnsCurve(self.root, self.getName("upv_crv"), self.upv_curv_lvl, 3) self.mst_crv.setAttr("visibility", False) self.upv_crv.setAttr("visibility", False) # Divisions self.div_cns = [] self.upv_cns = [] if self.settings["overrideJntNb"]: self.def_number = self.settings["jntNb"] else: self.def_number = len(self.guide.apos) if self.settings["extraTweak"]: tagP = self.parentCtlTag self.extratweak_ctl = [] for i in range(self.def_number): # References div_cns = primitive.addTransform(self.root, self.getName("%s_cns" % i)) pm.setAttr(div_cns + ".inheritsTransform", False) self.div_cns.append(div_cns) upv_cns = primitive.addTransform(self.root, self.getName("%s_upv" % i)) pm.setAttr(upv_cns + ".inheritsTransform", False) self.upv_cns.append(upv_cns) # self.jnt_pos.append([div_cns, i]) if self.settings["extraTweak"]: t = transform.getTransform(div_cns) ro_vector = datatypes.Vector([0, 0, 1.5708]) tweak_ctl = self.addCtl(div_cns, "extraTweak%s_ctl" % i, t, self.color_fk, "square", w=self.size * .08, d=self.size * .08, ro=ro_vector, tp=tagP) attribute.setKeyableAttributes(tweak_ctl) tagP = tweak_ctl self.extratweak_ctl.append(tweak_ctl) self.jnt_pos.append([tweak_ctl, i, None, False]) else: self.jnt_pos.append([div_cns, i])
def addObjects(self): self.WIP = self.options["mode"] self.normal = self.guide.blades["blade"].z * -1 self.binormal = self.guide.blades["blade"].x # FK controllers ------------------------------------ self.fk_npo = [] self.fk_ctl = [] t = self.guide.tra["root"] self.fk_cns = pri.addTransform(self.root, self.getName("fk_cns"), t) parent = self.fk_cns tOld = False for i, t in enumerate( tra.getChainTransform(self.guide.apos, self.normal, self.negate)): parent = self._add_fk(i, parent, t, tOld) # IK controllers ------------------------------------ normal = vec.getTransposedVector( self.normal, [self.guide.apos[0], self.guide.apos[1]], [self.guide.apos[-3], self.guide.apos[-2]]) if self.negate: t = tra.getTransformLookingAt(self.guide.apos[-3], self.guide.apos[-2], normal, "xy", self.negate) t = tra.setMatrixPosition(t, self.guide.apos[-2]) else: t = tra.getTransformLookingAt(self.guide.apos[-3], self.guide.apos[-2], normal, "x-y", self.negate) t = tra.setMatrixPosition(t, self.guide.apos[-2]) self.ik_cns = pri.addTransform(self.root, self.getName("ik_cns"), t) self.ik_ctl = self.addCtl(self.ik_cns, "ik_ctl", t, self.color_ik, "cube", w=self.size * .15, h=self.size * .15, d=self.size * .15) self.ikRot_npo = pri.addTransform(self.root, self.getName("ikRot_npo"), t) self.ikRot_cns = pri.addTransform(self.ikRot_npo, self.getName("ikRot_cns"), t) self.ikRot_ctl = self.addCtl(self.ikRot_cns, "ikRot_ctl", t, self.color_fk, "flower", w=self.size * .35, h=self.size * .35, d=self.size * .35, ro=dt.Vector(0, math.radians(90), 0)) v = self.guide.apos[-2] - 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[0:-1], 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 # End reference ------------------------------------ self.end_ref = pri.addTransform(self.chain[-1], self.getName("end_ref"), t) self.jnt_pos.append([self.loc[-1], 'end']) # 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)) 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]) # match IK FK references self.match_ik = pri.addTransform(self.fk_ctl[2], self.getName("ik_mth"), tra.getTransform(self.ik_ctl)) mid = (len(self.fk_ctl) - 1) / 2 self.match_ikUpv = pri.addTransform(self.fk_ctl[mid], self.getName("upv_mth"), tra.getTransform(self.upv_ctl)) if True or self.settings["ikTR"]: reference = self.ikRot_ctl self.match_ikRot = pri.addTransform( self.fk_ctl[-1], self.getName("ikRot_mth"), tra.getTransform(self.ikRot_ctl)) else: reference = self.ik_ctl self.match_fk0_off = pri.addTransform(self.root, self.getName("matchFk0_npo"), tra.getTransform(self.fk_ctl[1])) 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 = pri.addTransform(self.match_fk1_off, self.getName("fk1_mth"), tra.getTransform(self.fk_ctl[1])) # self.match_fk2_off = pri.addTransform(self.root, self.getName("matchFk2_npo"), tra.getTransform(self.fk_ctl[2])) # self.match_fk2 = pri.addTransform(self.match_fk2_off, self.getName("fk2_mth"), tra.getTransform(self.fk_ctl[1])) self.match_fk2 = pri.addTransform(reference, self.getName("fk2_mth"), tra.getTransform(self.fk_ctl[2])) # 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)
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.WIP = self.options["mode"] if self.negate and self.settings["overrideNegate"]: self.negate = False self.n_factor = 1 # FK controllers ------------------------------------ self.fk_npo = [] self.fk_ctl = [] self.tweak_npo = [] self.tweak_ctl = [] self.curv_pos = [] self.upv_curv_pos = [] self.upv_curv_lvl = [] self.tangentsCtl = [] t = self.guide.tra["root"] parent = self.root tOld = False fk_ctl = None self.previusTag = self.parentCtlTag for i, t in enumerate(transform.getChainTransform(self.guide.apos, self.normal, self.negate)): self.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)) fk_npo = primitive.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=self.dist, h=self.size * .1, d=self.size * .1, po=datatypes.Vector(self.dist * .5 * self.n_factor, 0, 0), tp=self.previusTag) tweak_npo = primitive.addTransform( parent, self.getName("tweak%s_npo" % i), tnpo) self.tweak_npo.append(tweak_npo) tweak_ctl = self.addCtl( tweak_npo, "tweak%s_ctl" % i, t, self.color_ik, "cube", w=self.size * .15, h=self.size * .05, d=self.size * .15, ro=datatypes.Vector([0, 0, 1.5708]), tp=self.previusTag) upv_curv_lvl = primitive.addTransform( tweak_ctl, self.getName("upv%s_lvl" % i), t) upv_curv_lvl.attr("tz").set(.01) self.fk_npo.append(fk_npo) self.fk_ctl.append(fk_ctl) self.tweak_ctl.append(tweak_ctl) self.upv_curv_lvl.append(upv_curv_lvl) tOld = t self.previusTag = fk_ctl parent = fk_ctl # TANGENTS tangents = [] tangents_npo = [] tangents_upv = [] if not i: letters = "A" else: letters = "AB" for tang in letters: tang_npo = primitive.addTransform( tweak_ctl, self.getName("tng{}{}_npo".format(tang, str(i))), t) tangents_npo.append(tang_npo) tang_ctl = self.addCtl( tang_npo, "tng{}{}_ctl".format(tang, str(i)), t, self.color_ik, "square", w=self.size * .07, h=self.size * .07, d=self.size * .07, ro=datatypes.Vector([0, 0, 1.5708]), tp=self.previusTag) upv_tang_curv_lvl = primitive.addTransform( tang_ctl, self.getName("tngUpv{}{}_lvl".format(tang, str(i))), t) upv_tang_curv_lvl.attr("tz").set(.01) tangents_upv.append(upv_tang_curv_lvl) tangents.append(tang_ctl) tangents_npo[0].attr("tx").set(self.dist * .3333) # delete the first B tangent if not i: self.curv_pos.append(tweak_ctl) self.curv_pos.append(tangents[0]) self.upv_curv_pos.append(upv_curv_lvl) self.upv_curv_pos.append(tangents_upv[0]) else: self.curv_pos.append(tangents[1]) self.curv_pos.append(tweak_ctl) self.curv_pos.append(tangents[0]) self.upv_curv_pos.append(tangents_upv[1]) self.upv_curv_pos.append(upv_curv_lvl) self.upv_curv_pos.append(tangents_upv[0]) tangents_npo[1].attr("tx").set(self.dist * -.3333) self.tangentsCtl.extend(tangents) # ========== # self.jnt_pos.append([fk_ctl, i, None, False]) # add end control tweak_npo = primitive.addTransform( fk_ctl, self.getName("tweakEnd_npo"), t) tweak_ctl = self.addCtl( tweak_npo, "tweakEnd_ctl", t, self.color_ik, "cube", w=self.size * .15, h=self.size * .05, d=self.size * .15, ro=datatypes.Vector([0, 0, 1.5708]), tp=self.previusTag) upv_curv_lvl = primitive.addTransform( tweak_ctl, self.getName("upvEnd_lvl"), t) upv_curv_lvl.attr("tz").set(.01) if self.negate: self.off_dist = self.dist * -1 else: self.off_dist = self.dist tweak_npo.attr("tx").set(self.off_dist) self.tweak_ctl.append(tweak_ctl) self.upv_curv_lvl.append(upv_curv_lvl) # tangent END tang_npo = primitive.addTransform( tweak_ctl, self.getName("tngEnd{}_npo".format(tang, str(i))), t) tang_ctl = self.addCtl( tang_npo, "tngEnd{}_ctl".format(tang, str(i)), t, self.color_ik, "square", w=self.size * .07, h=self.size * .07, d=self.size * .07, ro=datatypes.Vector([0, 0, 1.5708]), tp=self.previusTag) upv_tang_curv_lvl = primitive.addTransform( tang_ctl, self.getName("tngUpv{}{}_lvl".format(tang, str(i))), t) upv_tang_curv_lvl.attr("tz").set(.01) tangents_upv.append(upv_tang_curv_lvl) tang_npo.attr("tx").set(self.dist * -.3333) self.curv_pos.append(tang_ctl) self.curv_pos.append(tweak_ctl) self.upv_curv_pos.append(tang_ctl) self.upv_curv_pos.append(upv_curv_lvl) self.tangentsCtl.append(tang_ctl) # add length offset control if keep length # This option will be added only if keep length is active if self.settings["keepLength"]: self.tweakTip_npo = primitive.addTransform( tweak_ctl, self.getName("tweakTip_npo"), t) tweak_ctl = self.addCtl( self.tweakTip_npo, "tweakTip_ctl", t, self.color_fk, "square", w=self.size * .1, h=self.size * .1, d=self.size * .1, ro=datatypes.Vector([0, 0, 1.5708]), tp=self.previusTag) upv_curv_lvl = primitive.addTransform( tweak_ctl, self.getName("upvTip_lvl"), t) upv_curv_lvl.attr("tz").set(.01) # move to align with the parent self.tweakTip_npo.attr("tx").set(0) self.tweak_ctl.append(tweak_ctl) self.upv_curv_lvl.append(upv_curv_lvl) # add visual reference self.line_ref = icon.connection_display_curve( self.getName("visualRef"), [self.tweakTip_npo.getParent(), tweak_ctl]) # Curves ------------------------------------------- self.mst_crv = curve.addCnsCurve(self.root, self.getName("mst_crv"), self.curv_pos, 3) self.slv_crv = curve.addCurve(self.root, self.getName("slv_crv"), [datatypes.Vector()] * 32, False, 3) self.upv_crv = curve.addCnsCurve(self.root, self.getName("upv_crv"), self.upv_curv_pos, 3) self.slv_upv_crv = curve.addCurve(self.root, self.getName("slv_upv_crv"), [datatypes.Vector()] * 32, False, 3) self.mst_crv.setAttr("template", True) self.slv_crv.setAttr("visibility", False) self.upv_crv.setAttr("visibility", False) self.slv_upv_crv.setAttr("visibility", False) # Divisions self.div_cns = [] self.upv_cns = [] tagP = self.parentCtlTag self.Extra_tweak_npo = [] self.Extra_tweak_ctl = [] if self.settings["overrideJntNb"]: self.def_number = self.settings["jntNb"] else: self.def_number = len(self.guide.apos) for i in range(self.def_number): # References div_cns = primitive.addTransform(self.root, self.getName("%s_cns" % i)) pm.setAttr(div_cns + ".inheritsTransform", False) self.div_cns.append(div_cns) upv_cns = primitive.addTransform(self.root, self.getName("%s_upv" % i)) pm.setAttr(upv_cns + ".inheritsTransform", False) self.upv_cns.append(upv_cns) t = transform.getTransform(div_cns) extraTweak_npo = primitive.addTransform( div_cns, self.getName("extraTweak{}_npo".format(tang, str(i))), t) self.Extra_tweak_npo.append(extraTweak_npo) Extra_tweak_ctl = self.addCtl(extraTweak_npo, "extraTweak%s_ctl" % i, t, self.color_fk, "circle", w=self.size * .15, d=self.size * .15, ro=datatypes.Vector([0, 0, 1.5708]), tp=tagP) attribute.setKeyableAttributes(Extra_tweak_ctl) self.Extra_tweak_ctl.append(Extra_tweak_ctl) self.jnt_pos.append([Extra_tweak_ctl, i])
def add2DChain(parent, name, positions, normal, negate=False, vis=True): """Create a 2D joint chain. Like Softimage 2D chain. Warning: This function will create un expected results if all the positions are not in the same 2D plane. Arguments: parent (dagNode): The parent for the chain. name (str): The node name. positions(list of vectors): the positons to define the chain. normal (vector): The normal vector to define the direction of the chain. negate (bool): If True will negate the direction of the chain Returns; list of dagNodes: The list containg all the joints of the chain >>> self.rollRef = pri.add2DChain( self.root, self.getName("rollChain"), self.guide.apos[:2], self.normal, self.negate) """ if "%s" not in name: name += "%s" transforms = transform.getChainTransform(positions, normal, negate) t = transform.setMatrixPosition(transforms[-1], positions[-1]) transforms.append(t) chain = [] for i, t in enumerate(transforms): node = addJoint(parent, name % i, t, vis) chain.append(node) parent = node # moving rotation value to joint orient for i, jnt in enumerate(chain): if i == 0: jnt.setAttr("jointOrient", jnt.getAttr("rotate")) jnt.setAttr("rotate", 0, 0, 0) elif i == len(chain) - 1: jnt.setAttr("jointOrient", 0, 0, 0) jnt.setAttr("rotate", 0, 0, 0) else: # This will fail if chain is not always oriented the same # way (like X chain) v0 = positions[i] - positions[i - 1] v1 = positions[i + 1] - positions[i] angle = datatypes.degrees(v0.angle(v1)) jnt.setAttr("rotate", 0, 0, 0) jnt.setAttr("jointOrient", 0, 0, angle) # check if we have to negate Z angle by comparing the guide # position and the resulting position. if i >= 1: # round the position values to 6 decimals precission # TODO: test with less precision and new check after apply # Ik solver if ([round(elem, 4) for elem in transform.getTranslation(jnt)] != [round(elem, 4) for elem in positions[i]]): jp = jnt.getParent() # Aviod intermediate e.g. `transform3` groups that can appear # between joints due to basic moving around. while jp.type() == "transform": jp = jp.getParent() jp.setAttr("jointOrient", 0, 0, jp.attr("jointOrient").get()[2] * -1) jnt.setAttr("radius", 1.5) return chain
def add2DChain2(parent, name, positions, normal, negate=False, vis=True): """Experimental 2D Chain creation function. Create a 2D joint chain. Like Softimage 2D chain. Warning: This function is WIP and not ready for production. Warning: This function will create un expected results if all the positions are not in the same 2D plane. Arguments: parent (dagNode): The parent for the chain. name (str): The node name. positions(list of vectors): the positons to define the chain. normal (vector): The normal vector to define the direction of the chain. negate (bool): If True will negate the direction of the chain Returns; list of dagNodes: The list containg all the joints of the chain >>> self.chain3bones = pri.add2DChain2( self.setup, self.getName("chain3bones%s_jnt"), self.guide.apos[0:4], self.normal, False) """ if "%s" not in name: name += "%s" transforms = transform.getChainTransform(positions, normal, negate) t = transform.setMatrixPosition(transforms[-1], positions[-1]) transforms.append(t) chain = [] for i, t in enumerate(transforms): node = addJoint(parent, name % i, t, vis) chain.append(node) parent = node # moving rotation value to joint orient for i, jnt in enumerate(chain): if i == 0: jnt.setAttr("jointOrient", jnt.getAttr("rotate")) elif i == len(chain) - 1: jnt.setAttr("jointOrient", 0, 0, 0) else: # This will fail if chain is not always oriented the same # way (like Z chain) v0 = positions[i] - positions[i - 1] v1 = positions[i + 1] - positions[i] angle = datatypes.degrees(v0.angle(v1)) jnt.setAttr("jointOrient", 0, 0, angle) jnt.setAttr("rotate", 0, 0, 0) jnt.setAttr("radius", 1.5) return chain
def addObjects(self): # blades computation self.normal = self.guide.blades["blade"].z self.binormal = self.guide.blades["blade"].x self.fk_npo = [] self.fk_ctl = [] self.spring_cns = [] self.spring_aim = [] self.spring_lvl = [] self.spring_ref = [] self.spring_npo = [] self.spring_target = [] self.fk_local_out = [] self.fk_global_out = [] self.fk_global_ref = [] parent = self.root self.previousTag = 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]) # output global_t = transform.setMatrixPosition( datatypes.Matrix(), transform.getPositionFromMatrix(t)) fk_global_out_npo = primitive.addTransform( parent, self.getName("fk%s_global_out_npo" % i), global_t) fk_global_out = primitive.addTransform( fk_global_out_npo, self.getName("fk%s_global_out" % i), global_t) self.fk_global_out.append(fk_global_out) fk_local_out_npo = primitive.addTransform( parent, self.getName("fk%s_local_out_npo" % i), t) fk_local_out = primitive.addTransform( fk_local_out_npo, self.getName("fk%s_local_out" % i), t) self.fk_local_out.append(fk_local_out) fk_npo = primitive.addTransform(parent, self.getName("fk%s_npo" % i), t) spring_aim = primitive.addTransform( fk_npo, self.getName("spring%s_aim" % i), t) spring_cns = primitive.addTransform( fk_npo, self.getName("spring%s_cns" % i), t) fk_ctl = self.addCtl(spring_cns, "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.previousTag, lp=False) self.previousTag = fk_ctl t = transform.getTransformFromPos(self.guide.apos[i + 1]) spring_npo = primitive.addTransform( parent, self.getName("spring%s_npo" % i), t) spring_target = primitive.addTransform( spring_npo, self.getName("spring%s" % i), t) parent = fk_ctl self.spring_cns.append(spring_cns) self.spring_aim.append(spring_aim) self.addToGroup(spring_cns, "PLOT") self.fk_npo.append(fk_npo) self.fk_ctl.append(fk_ctl) attribute.setKeyableAttributes(self.fk_ctl, self.tr_params) self.spring_target.append(spring_target) # fk global ref fk_global_ref = primitive.addTransform( fk_ctl, self.getName("fk%s_global_ref" % i), global_t) self.fk_global_ref.append(fk_global_ref) attribute.setKeyableAttributes(fk_global_ref, []) # 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]) parent = loc