def addOperators(self): # Visibilities ------------------------------------- par.addExpression(self.ik0_ctl.Properties("visibility").Parameters("viewvis"), self.pShowIk.FullName) par.addExpression(self.ik1_ctl.Properties("visibility").Parameters("viewvis"), self.pShowIk.FullName) par.addExpression(self.tan0_ctl.Properties("visibility").Parameters("viewvis"), self.pShowIk.FullName) par.addExpression(self.tan1_ctl.Properties("visibility").Parameters("viewvis"), self.pShowIk.FullName) for fk_ctl in self.fk_ctl[1:-1]: par.addExpression(fk_ctl.Properties("visibility").Parameters("viewvis"), self.pShowFk.FullName) # Tangent position --------------------------------- d = vec.getDistance(self.guide.apos[0], self.guide.apos[1]) exp = self.pTan0.FullName + " * " + str(self.tan0_ctl.Parameters("nposy").Value)+" * (ctr_dist("+self.ik0_ctl.FullName+","+self.ik1_ctl.FullName+") / "+str(d)+")" par.addExpression(self.tan0_ctl.Parameters("nposy"), exp) exp = self.pTan1.FullName + " * " + str(self.tan1_ctl.Parameters("nposy").Value)+" * (ctr_dist("+self.ik0_ctl.FullName+","+self.ik1_ctl.FullName+") / "+str(d)+")" par.addExpression(self.tan1_ctl.Parameters("nposy"), exp) # Curves ------------------------------------------- op = aop.sn_curveslide2_op(self.slv_crv, self.mst_crv, 0, 1.5, .5, .5) par.addExpression(op.Parameters("position"), self.pPosition.FullName) par.addExpression(op.Parameters("maxstretch"), self.pMaxStretch.FullName) par.addExpression(op.Parameters("maxsquash"), self.pMaxSquash.FullName) par.addExpression(op.Parameters("softness"), self.pSoftness.FullName) # Division ----------------------------------------- for i in range(self.settings["division"]): # References u = i / (self.settings["division"] - 1.0) div_cns = self.div_cns[i] cns = aop.pathCns(div_cns, self.slv_crv, 0, u*100, True, None, False) cns.Parameters("dirx").Value = 0 cns.Parameters("diry").Value = 1 cns.Parameters("dirz").Value = 0 cns.Parameters("upx").Value = 0 cns.Parameters("upy").Value = 0 cns.Parameters("upz").Value = -1 # Roll aop.spinePointAtOp(cns, self.ik0_ctl, self.ik1_ctl, u) # Squash n Stretch op = aop.sn_squashstretch2_op(div_cns, self.slv_crv, self.slv_crv.ActivePrimitive.Geometry.Curves(0).Length, "y") par.addExpression(op.Parameters("blend"), self.pVolume.FullName) par.addExpression(op.Parameters("driver"), self.pDriver.FullName) if self.options["mode"] == 1: # wip par.addExpression(op.Parameters("stretch"), self.pStretch[i]) par.addExpression(op.Parameters("squash"), self.pSquash[i]) else: op.Parameters("stretch").Value = self.st_value[i] op.Parameters("squash").Value = self.sq_value[i] # Controlers fk_ctl = self.fk_ctl[i] for s in "xyz": par.addExpression(fk_ctl.Parameters("npos"+s), div_cns.Parameters("pos"+s).FullName) par.addExpression(fk_ctl.Parameters("nrot"+s), div_cns.Parameters("rot"+s).FullName) par.addExpression(fk_ctl.Kinematics.Global.Parameters("scl"+s), div_cns.Kinematics.Global.Parameters("scl"+s).FullName) # Orientation Lock cns = self.div_cns[0].Kinematics.AddConstraint("Orientation", self.ik0_ctl, False) par.addExpression(cns.Parameters("blendweight"), self.pLockOri0.FullName) cns = self.div_cns[-1].Kinematics.AddConstraint("Orientation", self.ik1_ctl, False) par.addExpression(cns.Parameters("blendweight"), self.pLockOri1.FullName) # Volume ------------------------------------------- op = aop.sn_curvelength_op(self.pDriver, self.slv_crv) # Connections (Hooks) ------------------------------ self.cnx0.Kinematics.AddConstraint("Position", self.div_cns[0], False) self.cnx0.Kinematics.AddConstraint("Orientation", self.div_cns[0], False) self.cnx1.Kinematics.AddConstraint("Position", self.fk_ctl[-1], False) self.cnx1.Kinematics.AddConstraint("Orientation", self.fk_ctl[-1], False)
def addOperators(self): # Visibilities ------------------------------------- par.addExpression(self.fk0_ctl.Properties("visibility").Parameters("viewvis"), "1 - "+self.pBlend.FullName) par.addExpression(self.fk1_ctl.Properties("visibility").Parameters("viewvis"), "1 - "+self.pBlend.FullName) par.addExpression(self.fk2_ctl.Properties("visibility").Parameters("viewvis"), "1 - "+self.pBlend.FullName) par.addExpression(self.upv_ctl.Properties("visibility").Parameters("viewvis"), self.pBlend.FullName) par.addExpression(self.ikcns_ctl.Properties("visibility").Parameters("viewvis"), self.pBlend.FullName +" * "+ self.pIkCns.FullName) par.addExpression(self.ik_ctl.Properties("visibility").Parameters("viewvis"), self.pBlend.FullName) # Leash -------------------------------------------- aop.clsCtrOp(self.upv_ctl, self.mid_ctl, [0]) # IK Solver----------------------------------------- out = [self.bone0, self.bone1, None, self.eff_loc] op = aop.sn_ikfk2bone_op(out, self.root, self.ik_ctl, self.upv_ctl, self.fk0_ctl, self.fk1_ctl, self.fk2_ctl, self.length0, self.length1, self.negate) par.addExpression(op.Parameters("blend"), self.pBlend.FullName) par.addExpression(op.Parameters("roll"), self.pIkRoll.FullName) par.addExpression(op.Parameters("scaleA"), self.pScale.FullName) par.addExpression(op.Parameters("scaleB"), self.pScale.FullName) par.addExpression(op.Parameters("maxstretch"), self.pMaxStretch.FullName) par.addExpression(op.Parameters("softness"), self.pSoftness.FullName) par.addExpression(op.Parameters("slide"), self.pSlide.FullName) par.addExpression(op.Parameters("reverse"), self.pReverse.FullName) # I'm not using the output of the solver to get the ctrn because it only has a +/-180 degree # With this simple expression I have a much better result # Also remove scaling from ctrn for s in "xyz": par.addExpression(self.ctrn_loc.Kinematics.Local.Parameters("rot"+s), self.bone1.Kinematics.Local.Parameters("rot"+s).FullName + " * .5") par.addExpression(self.ctrn_loc.Kinematics.Global.Parameters("scl"+s), self.root.Kinematics.Global.Parameters("scl"+s).FullName) # Membrane par.addExpression(self.memb_loc.Kinematics.Local.Parameters("posy"), self.pStartPos.FullName+" + ("+self.pEndPos.FullName+" - "+self.pStartPos.FullName+") * ( 1 - ( ctr_dist("+self.root.Kinematics.Global.FullName+","+self.eff_loc.Kinematics.Global.FullName+") / "+self.pRestDist.FullName+"))") # Twist references --------------------------------- self.pRestDist.Value = vec.getDistance2(self.root, self.eff_loc) par.addExpression(self.pDriver, "(ctr_dist(%s, %s) + ctr_dist(%s, %s)) / %s" %(self.tws0_loc.Kinematics.Global.FullName, self.tws1_loc.Kinematics.Global.FullName, self.tws1_loc.Kinematics.Global.FullName, self.tws2_loc.Kinematics.Global.FullName, self.root.Kinematics.Global.Parameters("sclx").FullName)) self.tws0_loc.Kinematics.AddConstraint("Pose", self.root, True) aop.dirCns(self.tws0_loc, self.mid_ctl, None, False, self.n_sign+"xy") self.tws1_loc.Kinematics.AddConstraint("Position", self.mid_ctl) self.tws1_loc.Kinematics.AddConstraint("Scaling", self.mid_ctl) self.tws1_rot.Kinematics.AddConstraint("Orientation", self.mid_ctl) par.addExpression(self.tws1_rot.Parameters("rotx"), 0) par.addExpression(self.tws1_rot.Parameters("roty"), 0) par.addExpression(self.tws1_rot.Parameters("rotz"), 0) self.tws2_loc.Kinematics.AddConstraint("Position", self.eff_loc) self.tws2_loc.Kinematics.AddConstraint("Scaling", self.eff_loc) aop.poseCns(self.tws2_rot, self.eff_loc, False, False, True, False) par.addExpression(self.tws2_rot.Parameters("rotx"), 0) par.addExpression(self.tws2_rot.Parameters("roty"), 0) par.addExpression(self.tws2_rot.Parameters("rotz"), 0) par.setRotOrder(self.tws2_rot, "YZX") self.tws0_rot.SclX = .001 par.addExpression(self.tws1_rot.SclX, self.pRoundness.FullName + " + .001") self.tws2_rot.SclX = .001 # Divisions ---------------------------------------- # at 0 or 1 the division will follow exactly the rotation of the controler.. and we wont have this nice tangent + roll for i, div_cns in enumerate(self.div_cns): if i < (self.settings["div0"]+1): perc = i*.5 / (self.settings["div0"]+1.0) else: perc = .5 + (i-self.settings["div0"]-1.0)*.5 / (self.settings["div1"]+1.0) perc = max(.001, min(.999, perc)) # Roll if self.negate: op = aop.sn_rollsplinekine_op(div_cns, [self.tws2_rot, self.tws1_rot, self.tws0_rot], 1-perc) else: op = aop.sn_rollsplinekine_op(div_cns, [self.tws0_rot, self.tws1_rot, self.tws2_rot], perc) # Squash n Stretch op = aop.sn_squashstretch2_op(div_cns, self.root, self.pDriver.Value, "x") par.addExpression(op.Parameters("blend"), self.pVolume.FullName) par.addExpression(op.Parameters("driver"), self.pDriver.FullName) if self.options["mode"] == 1: # wip par.addExpression(op.Parameters("stretch"), self.pStretch[i]) par.addExpression(op.Parameters("squash"), self.pSquash[i]) else: op.Parameters("stretch").Value = self.st_value[i] op.Parameters("squash").Value = self.sq_value[i]
def addOperators(self): # Visibilities ------------------------------------- par.addExpression(self.fk0_ctl.Properties("visibility").Parameters("viewvis"), "1 - "+self.pBlend.FullName) par.addExpression(self.fk1_ctl.Properties("visibility").Parameters("viewvis"), "1 - "+self.pBlend.FullName) par.addExpression(self.fk2_ctl.Properties("visibility").Parameters("viewvis"), "1 - "+self.pBlend.FullName) par.addExpression(self.fk3_ctl.Properties("visibility").Parameters("viewvis"), "1 - "+self.pBlend.FullName) par.addExpression(self.upv_ctl.Properties("visibility").Parameters("viewvis"), self.pBlend.FullName) par.addExpression(self.ikcns_ctl.Properties("visibility").Parameters("viewvis"), self.pBlend.FullName +" * "+ self.pIkCns.FullName) par.addExpression(self.ik_ctl.Properties("visibility").Parameters("viewvis"), self.pBlend.FullName) if self.settings["roll"] == 0: par.addExpression(self.roll_ctl.Properties("visibility").Parameters("viewvis"), self.pBlend.FullName) # Leash -------------------------------------------- aop.clsCtrOp(self.upv_ctl, self.mid0_ctl, [0]) # IK Solver----------------------------------------- self.roll_ctl.Kinematics.AddConstraint("Position", self.ik_ref, False) self.ref_chn.eff.Kinematics.AddConstraint("Pose", self.roll_ctl, True) self.end_chn.eff.Kinematics.AddConstraint("Pose", self.roll_ctl, True) op = xsi.ApplyOp("SkeletonUpVector", self.ref_chn.bones[0].FullName+";"+self.upv_ctl.FullName)[0] par.addExpression(self.ref_chn.roll, self.pIkRoll.FullName + " + 180") op = xsi.ApplyOp("SkeletonUpVector", self.end_chn.bones[0].FullName+";"+self.upv_ctl.FullName)[0] par.addExpression(self.end_chn.roll, self.pIkRoll.FullName + " + 180") # ctrn for s in "xyz": par.addExpression(self.ctrn0_loc.Kinematics.Local.Parameters("rot" + s), self.ref_loc[1].Kinematics.Local.Parameters("rot" + s).FullName + " * .5") par.addExpression(self.ctrn0_loc.Kinematics.Global.Parameters("scl" + s), self.root.Kinematics.Global.Parameters("scl" + s).FullName) par.addExpression(self.ctrn1_loc.Kinematics.Local.Parameters("rot" + s), self.ref_loc[2].Kinematics.Local.Parameters("rot" + s).FullName + " * .5") par.addExpression(self.ctrn1_loc.Kinematics.Global.Parameters("scl" + s), self.root.Kinematics.Global.Parameters("scl" + s).FullName) self.ctrn0_loc.Kinematics.AddConstraint("Position", self.ref_loc[1], False) self.ctrn1_loc.Kinematics.AddConstraint("Position", self.ref_loc[2], False) # References Nulls --------------------------------- fk_ref = [self.fk0_ctl, self.fk1_ctl, self.fk2_ctl, self.fk_ref] ik_ref = [self.ref_chn.bones[0], self.ref_chn.bones[1], self.end_chn.bones[0], self.ik_ref] for i, ref_loc in enumerate(self.ref_loc): # fk cns = ref_loc.Kinematics.AddConstraint("Orientation", fk_ref[i], False) if i != len(self.ref_loc)-1: cns = aop.dirCns(ref_loc, fk_ref[i+1], None, False, self.n_sign+"xz") par.addExpression(cns.Parameters("blendweight"), "1 - " + self.pBlend.FullName) #ik cns = ref_loc.Kinematics.AddConstraint("Orientation", ik_ref[i], False) par.addExpression(cns.Parameters("blendweight"), self.pBlend.FullName) for s in "xyz": par.addExpression(ref_loc.Kinematics.Local.Parameters("rot"+s), 0) par.addExpression(self.ref_loc[1].Kinematics.Local.Parameters("posx"), self.n_sign+" (ctr_dist(%s.kine.global, %s.kine.global) * (1 - %s) + ctr_dist(%s.kine.global, %s.kine.global) * %s)"%(self.fk0_ctl.FullName, self.fk1_ctl.FullName, self.pBlend.FullName, self.ref_chn.bones[0].FullName, self.ref_chn.bones[1].FullName, self.pBlend.FullName)) par.addExpression(self.ref_loc[2].Kinematics.Local.Parameters("posx"), self.n_sign+" (ctr_dist(%s.kine.global, %s.kine.global) * (1 - %s) + ctr_dist(%s.kine.global, %s.kine.global) * %s)"%(self.fk1_ctl.FullName, self.fk2_ctl.FullName, self.pBlend.FullName, self.ref_chn.bones[1].FullName, self.end_chn.bones[0], self.pBlend.FullName)) par.addExpression(self.ref_loc[3].Kinematics.Local.Parameters("posx"), self.n_sign+" (ctr_dist(%s.kine.global, %s.kine.global) * (1 - %s) + ctr_dist(%s.kine.global, %s.kine.global) * %s)"%(self.fk2_ctl.FullName, self.fk3_ctl.FullName, self.pBlend.FullName, self.end_chn.bones[0].FullName, self.end_chn.eff, self.pBlend.FullName)) # Twist references --------------------------------- par.addExpression(self.pDriver, "(ctr_dist(%s, %s) + ctr_dist(%s, %s) + ctr_dist(%s, %s)) / %s" %(self.tws0_loc.Kinematics.Global.FullName, self.tws1_loc.Kinematics.Global.FullName, self.tws1_loc.Kinematics.Global.FullName, self.tws2_loc.Kinematics.Global.FullName, self.tws2_loc.Kinematics.Global.FullName, self.tws3_loc.Kinematics.Global.FullName, self.root.Kinematics.Global.Parameters("sclx").FullName)) self.tws1_loc.Kinematics.AddConstraint("Position", self.mid0_ctl) self.tws1_loc.Kinematics.AddConstraint("Scaling", self.mid0_ctl) self.tws1_rot.Kinematics.AddConstraint("Orientation", self.mid0_ctl) par.addExpression(self.tws1_rot.Parameters("rotx"), 0) par.addExpression(self.tws1_rot.Parameters("roty"), 0) par.addExpression(self.tws1_rot.Parameters("rotz"), 0) self.tws2_loc.Kinematics.AddConstraint("Position", self.mid1_ctl) self.tws2_loc.Kinematics.AddConstraint("Scaling", self.mid1_ctl) self.tws2_rot.Kinematics.AddConstraint("Orientation", self.mid1_ctl) par.addExpression(self.tws2_rot.Parameters("rotx"), 0) par.addExpression(self.tws2_rot.Parameters("roty"), 0) par.addExpression(self.tws2_rot.Parameters("rotz"), 0) self.tws3_loc.Kinematics.AddConstraint("Position", self.ref_loc[-1]) #self.tws3_loc.Kinematics.AddConstraint("Scaling", self.eff_loc) aop.poseCns(self.tws3_rot, self.fk_ref, True, False, True, False) cns = aop.poseCns(self.tws3_rot, self.ik_ref, True, False, True, False) par.addExpression(cns.Parameters("blendweight"), self.pBlend.FullName) par.addExpression(self.tws3_rot.Parameters("rotx"), self.ik_ctl.Parameters("rotx").FullName + " * (1 - "+self.pBlend.FullName+") + " + self.fk3_ctl.Parameters("rotx").FullName + " * " + self.pBlend.FullName) par.addExpression(self.tws3_rot.Parameters("roty"), 0) par.addExpression(self.tws3_rot.Parameters("rotz"), 0) self.tws0_rot.SclX = .001 par.addExpression(self.tws1_rot.SclX, self.pRoundness.FullName + " + .001") par.addExpression(self.tws2_rot.SclX, self.pRoundness.FullName + " + .001") self.tws3_rot.SclX = .001 # Divisions ---------------------------------------- # at 0 or 1 the division will follow exactly the rotation of the controler.. and we wont have this nice tangent + roll for i, div_cns in enumerate(self.div_cns): if i < (self.settings["div0"]+1): perc = i / ((self.settings["div0"]+1.0)*3) elif i < (self.settings["div0"]+self.settings["div1"]+2): perc = (1/3.0) + ((i-self.settings["div0"]-1.0) / ((self.settings["div1"]+1.0)*3)) else: perc = (2/3.0) + ((i-self.settings["div0"]-self.settings["div1"]-2.0) / ((self.settings["div2"]+1.0)*3)) perc = max(.001, min(.999, perc)) if self.negate: op = aop.sn_rollsplinekine_op(div_cns, [self.tws3_rot, self.tws2_rot, self.tws1_rot, self.tws0_rot], 1-perc) else: op = aop.sn_rollsplinekine_op(div_cns, [self.tws0_rot, self.tws1_rot, self.tws2_rot, self.tws3_rot], perc) # Squash n Stretch op = aop.sn_squashstretch2_op(div_cns, self.root, self.pDriver.Value, "x") par.addExpression(op.Parameters("blend"), self.pVolume.FullName) par.addExpression(op.Parameters("driver"), self.pDriver.FullName) if self.options["mode"] == 1: # wip par.addExpression(op.Parameters("stretch"), self.pStretch[i]) par.addExpression(op.Parameters("squash"), self.pSquash[i]) else: op.Parameters("stretch").Value = self.st_value[i] op.Parameters("squash").Value = self.sq_value[i]
def addOperators(self): # Visibilities ------------------------------------- par.addExpression( self.fk0_ctl.Properties("visibility").Parameters("viewvis"), "1 - " + self.pBlend.FullName) par.addExpression( self.fk1_ctl.Properties("visibility").Parameters("viewvis"), "1 - " + self.pBlend.FullName) par.addExpression( self.fk2_ctl.Properties("visibility").Parameters("viewvis"), "1 - " + self.pBlend.FullName) par.addExpression( self.fk3_ctl.Properties("visibility").Parameters("viewvis"), "1 - " + self.pBlend.FullName) par.addExpression( self.upv_ctl.Properties("visibility").Parameters("viewvis"), self.pBlend.FullName) par.addExpression( self.ikcns_ctl.Properties("visibility").Parameters("viewvis"), self.pBlend.FullName + " * " + self.pIkCns.FullName) par.addExpression( self.ik_ctl.Properties("visibility").Parameters("viewvis"), self.pBlend.FullName) if self.settings["roll"] == 0: par.addExpression( self.roll_ctl.Properties("visibility").Parameters("viewvis"), self.pBlend.FullName) # Leash -------------------------------------------- aop.clsCtrOp(self.upv_ctl, self.mid0_ctl, [0]) # IK Solver----------------------------------------- if self.settings["roll"] == 0: self.ref_chn.eff.Kinematics.AddConstraint("Pose", self.roll_ctl, True) self.end_chn.eff.Kinematics.AddConstraint("Pose", self.roll_ctl, True) else: self.ref_chn.eff.Kinematics.AddConstraint("Pose", self.ik_ref, True) self.end_chn.eff.Kinematics.AddConstraint("Pose", self.ik_ref, True) op = xsi.ApplyOp( "SkeletonUpVector", self.ref_chn.bones[0].FullName + ";" + self.upv_ctl.FullName)[0] par.addExpression(self.ref_chn.roll, self.pIkRoll.FullName + " + 180") op = xsi.ApplyOp( "SkeletonUpVector", self.end_chn.bones[0].FullName + ";" + self.upv_ctl.FullName)[0] par.addExpression(self.end_chn.roll, self.pIkRoll.FullName + " + 180") # Roll # cns = self.dir_ref.Kinematics.AddConstraint("Orientation", self.ik_ref, True) # cns = aop.dirCns(self.dir_ref, self.root, None, False, "yz") # # restLength = vec.getDistance(self.guide.apos[0], self.guide.apos[3]) # maxLength = self.ref_chn.length + self.end_chn.length # par.addExpression(cns.Parameters("blendweight"), "MIN(1, MAX(0, (ctr_dist("+self.root.FullName+".kine.global, "+self.ik_ref.FullName+".kine.global) - "+str(restLength)+") / " \ # +"("+str(maxLength - restLength)+")))") # ctrn for s in "xyz": par.addExpression( self.ctrn0_loc.Kinematics.Local.Parameters("rot" + s), self.ref_loc[1].Kinematics.Local.Parameters("rot" + s).FullName + " * .5") par.addExpression( self.ctrn0_loc.Kinematics.Global.Parameters("scl" + s), self.root.Kinematics.Global.Parameters("scl" + s).FullName) par.addExpression( self.ctrn1_loc.Kinematics.Local.Parameters("rot" + s), self.ref_loc[2].Kinematics.Local.Parameters("rot" + s).FullName + " * .5") par.addExpression( self.ctrn1_loc.Kinematics.Global.Parameters("scl" + s), self.root.Kinematics.Global.Parameters("scl" + s).FullName) self.ctrn0_loc.Kinematics.AddConstraint("Position", self.ref_loc[1], False) self.ctrn1_loc.Kinematics.AddConstraint("Position", self.ref_loc[2], False) # References Nulls --------------------------------- fk_ref = [ self.fk0_ctl, self.fk1_ctl, self.fk2_ctl, self.fk3_ctl, self.fk_ref ] ik_ref = [ self.ref_chn.bones[0], self.ref_chn.bones[1], self.end_chn.bones[0], self.ik_ref ] for i, ref_loc in enumerate(self.ref_loc): # fk cns = ref_loc.Kinematics.AddConstraint("Orientation", fk_ref[i], False) if i != len(self.ref_loc) - 1: cns = aop.dirCns(ref_loc, fk_ref[i + 1], None, False, self.n_sign + "xz") par.addExpression(cns.Parameters("blendweight"), "1 - " + self.pBlend.FullName) #ik cns = ref_loc.Kinematics.AddConstraint("Orientation", ik_ref[i], False) par.addExpression(cns.Parameters("blendweight"), self.pBlend.FullName) for s in "xyz": par.addExpression( ref_loc.Kinematics.Local.Parameters("rot" + s), 0) par.addExpression( self.ref_loc[1].Kinematics.Local.Parameters("posx"), self.n_sign + " (ctr_dist(%s.kine.global, %s.kine.global) * (1 - %s) + ctr_dist(%s.kine.global, %s.kine.global) * %s)" % (self.fk0_ctl.FullName, self.fk1_ctl.FullName, self.pBlend.FullName, self.ref_chn.bones[0].FullName, self.ref_chn.bones[1].FullName, self.pBlend.FullName)) par.addExpression( self.ref_loc[2].Kinematics.Local.Parameters("posx"), self.n_sign + " (ctr_dist(%s.kine.global, %s.kine.global) * (1 - %s) + ctr_dist(%s.kine.global, %s.kine.global) * %s)" % (self.fk1_ctl.FullName, self.fk2_ctl.FullName, self.pBlend.FullName, self.ref_chn.bones[1].FullName, self.end_chn.bones[0], self.pBlend.FullName)) par.addExpression( self.ref_loc[3].Kinematics.Local.Parameters("posx"), self.n_sign + " (ctr_dist(%s.kine.global, %s.kine.global) * (1 - %s) + ctr_dist(%s.kine.global, %s.kine.global) * %s)" % (self.fk2_ctl.FullName, self.fk3_ctl.FullName, self.pBlend.FullName, self.end_chn.bones[0].FullName, self.end_chn.eff, self.pBlend.FullName)) # Twist references --------------------------------- par.addExpression( self.pDriver, "ctr_dist(%s, %s) + ctr_dist(%s, %s) + ctr_dist(%s, %s)" % (self.tws0_loc.Kinematics.Global.FullName, self.tws1_loc.Kinematics.Global.FullName, self.tws1_loc.Kinematics.Global.FullName, self.tws2_loc.Kinematics.Global.FullName, self.tws2_loc.Kinematics.Global.FullName, self.tws3_loc.Kinematics.Global.FullName)) self.tws1_loc.Kinematics.AddConstraint("Position", self.mid0_ctl) self.tws1_loc.Kinematics.AddConstraint("Scaling", self.mid0_ctl) self.tws1_rot.Kinematics.AddConstraint("Orientation", self.mid0_ctl) par.addExpression(self.tws1_rot.Parameters("rotx"), 0) par.addExpression(self.tws1_rot.Parameters("roty"), 0) par.addExpression(self.tws1_rot.Parameters("rotz"), 0) self.tws2_loc.Kinematics.AddConstraint("Position", self.mid1_ctl) self.tws2_loc.Kinematics.AddConstraint("Scaling", self.mid1_ctl) self.tws2_rot.Kinematics.AddConstraint("Orientation", self.mid1_ctl) par.addExpression(self.tws2_rot.Parameters("rotx"), 0) par.addExpression(self.tws2_rot.Parameters("roty"), 0) par.addExpression(self.tws2_rot.Parameters("rotz"), 0) self.tws3_loc.Kinematics.AddConstraint("Position", self.ref_loc[-1]) #self.tws3_loc.Kinematics.AddConstraint("Scaling", self.eff_loc) aop.poseCns(self.tws3_rot, self.fk_ref, True, False, True, False) cns = aop.poseCns(self.tws3_rot, self.ik_ref, True, False, True, False) par.addExpression(cns.Parameters("blendweight"), self.pBlend.FullName) par.addExpression( self.tws3_rot.Parameters("rotx"), self.ik_ctl.Parameters("rotx").FullName + " * (1 - " + self.pBlend.FullName + ") + " + self.fk3_ctl.Parameters("rotx").FullName + " * " + self.pBlend.FullName) par.addExpression(self.tws3_rot.Parameters("roty"), 0) par.addExpression(self.tws3_rot.Parameters("rotz"), 0) self.tws0_rot.SclX = .001 par.addExpression(self.tws1_rot.SclX, self.pRoundness.FullName + " + .001") par.addExpression(self.tws2_rot.SclX, self.pRoundness.FullName + " + .001") self.tws3_rot.SclX = .001 # Divisions ---------------------------------------- # at 0 or 1 the division will follow exactly the rotation of the controler.. and we wont have this nice tangent + roll step = 1.0 / (self.divisions - 1.0) for i, div_cns in enumerate(self.div_cns): perc = max(.001, min(.999, i * step)) if self.negate: op = aop.sn_rollsplinekine_op(div_cns, [ self.tws3_rot, self.tws2_rot, self.tws1_rot, self.tws0_rot ], 1 - perc) else: op = aop.sn_rollsplinekine_op(div_cns, [ self.tws0_rot, self.tws1_rot, self.tws2_rot, self.tws3_rot ], perc) # Squash n Stretch op = aop.sn_squashstretch2_op(div_cns, self.root, self.pDriver.Value, "x") par.addExpression(op.Parameters("blend"), self.pVolume.FullName) par.addExpression(op.Parameters("driver"), self.pDriver.FullName) if self.options["mode"] == 1: # wip par.addExpression(op.Parameters("stretch"), self.pStretch[i]) par.addExpression(op.Parameters("squash"), self.pSquash[i]) else: op.Parameters("stretch").Value = self.st_value[i] op.Parameters("squash").Value = self.sq_value[i]
def addOperators(self): # Visibilities ------------------------------------- par.addExpression( self.ik_ctl.Properties("visibility").Parameters("viewvis"), self.pShowIk.FullName) for fk_ctl in self.fk_ctl: par.addExpression( fk_ctl.Properties("visibility").Parameters("viewvis"), self.pShowFk.FullName) # Tangent position --------------------------------- d = vec.getDistance(self.guide.pos["root"], self.guide.pos["neck"]) exp = self.pTan0.FullName + " * " + str( self.tan0_loc.Parameters("nposy").Value ) + " * (ctr_dist(" + self.root.FullName + "," + self.ik_ctl.FullName + ") / " + str( d) + ")" par.addExpression(self.tan0_loc.Parameters("nposy"), exp) exp = self.pTan1.FullName + " * " + str( self.tan1_loc.Parameters("nposy").Value ) + " * (ctr_dist(" + self.root.FullName + "," + self.ik_ctl.FullName + ") / " + str( d) + ")" par.addExpression(self.tan1_loc.Parameters("nposy"), exp) # Curves ------------------------------------------- op = aop.sn_curveslide2_op(self.slv_crv, self.mst_crv, 0, 1.5, .5, .5) par.addExpression(op.Parameters("position"), 0) par.addExpression(op.Parameters("maxstretch"), self.pMaxStretch.FullName) par.addExpression(op.Parameters("maxsquash"), self.pMaxSquash.FullName) par.addExpression(op.Parameters("softness"), self.pSoftness.FullName) # Division ----------------------------------------- for i in range(self.settings["division"]): # References u = i / (self.settings["division"] - 1.0) div_cns = self.div_cns[i] cns = aop.pathCns(div_cns, self.slv_crv, 0, u * 100, True, None, False) cns.Parameters("dirx").Value = 0 cns.Parameters("diry").Value = 1 cns.Parameters("dirz").Value = 0 cns.Parameters("upx").Value = 0 cns.Parameters("upy").Value = 0 cns.Parameters("upz").Value = -1 # Roll aop.spinePointAtOp(cns, self.root, self.ik_ctl, u) # Squash n Stretch op = aop.sn_squashstretch2_op( div_cns, self.slv_crv, self.slv_crv.ActivePrimitive.Geometry.Curves(0).Length, "y") par.addExpression(op.Parameters("blend"), self.pVolume.FullName) par.addExpression(op.Parameters("driver"), self.pDriver.FullName) if self.options["mode"] == 1: # wip par.addExpression(op.Parameters("stretch"), self.pStretch[i]) par.addExpression(op.Parameters("squash"), self.pSquash[i]) else: import gear op.Parameters("stretch").Value = self.st_value[i] op.Parameters("squash").Value = self.sq_value[i] # Controlers fk_ctl = self.fk_ctl[i] for s in "xyz": par.addExpression(fk_ctl.Parameters("npos" + s), div_cns.Parameters("pos" + s).FullName) par.addExpression(fk_ctl.Parameters("nrot" + s), div_cns.Parameters("rot" + s).FullName) par.addExpression( fk_ctl.Kinematics.Global.Parameters("scl" + s), div_cns.Kinematics.Global.Parameters("scl" + s).FullName) # Orientation Lock cns = self.div_cns[-1].Kinematics.AddConstraint( "Orientation", self.ik_ctl, False) par.addExpression(cns.Parameters("blendweight"), self.pLockOri.FullName) # Volume ------------------------------------------- op = aop.sn_curvelength_op(self.pDriver, self.slv_crv) # Head --------------------------------------------- self.fk_ctl[-1].AddChild(self.head_cns) if self.headref_count > 0: cns = self.head_cns.Kinematics.AddConstraint( "Orientation", self.fk_ctl[-1], True) par.addExpression(cns.Parameters("active"), self.pHeadRef.FullName + " == 0")
def addOperators(self): # Visibilities ------------------------------------- par.addExpression( self.fk0_ctl.Properties("visibility").Parameters("viewvis"), "1 - " + self.pBlend.FullName) par.addExpression( self.fk1_ctl.Properties("visibility").Parameters("viewvis"), "1 - " + self.pBlend.FullName) par.addExpression( self.fk2_ctl.Properties("visibility").Parameters("viewvis"), "1 - " + self.pBlend.FullName) par.addExpression( self.fk3_ctl.Properties("visibility").Parameters("viewvis"), "1 - " + self.pBlend.FullName) par.addExpression( self.upv_ctl.Properties("visibility").Parameters("viewvis"), self.pBlend.FullName) par.addExpression( self.ikcns_ctl.Properties("visibility").Parameters("viewvis"), self.pBlend.FullName + " * " + self.pIkCns.FullName) par.addExpression( self.ik_ctl.Properties("visibility").Parameters("viewvis"), self.pBlend.FullName) if self.settings["roll"] == 0: par.addExpression( self.roll_ctl.Properties("visibility").Parameters("viewvis"), self.pBlend.FullName) # Leash -------------------------------------------- aop.clsCtrOp(self.upv_ctl, self.mid0_ctl, [0]) # IK Solver----------------------------------------- self.roll_ctl.Kinematics.AddConstraint("Position", self.ik_ref, False) self.ref_chn.eff.Kinematics.AddConstraint("Pose", self.roll_ctl, True) self.end_chn.eff.Kinematics.AddConstraint("Pose", self.roll_ctl, True) op = xsi.ApplyOp( "SkeletonUpVector", self.ref_chn.bones[0].FullName + ";" + self.upv_ctl.FullName)[0] par.addExpression(self.ref_chn.roll, self.pIkRoll.FullName + " + 180") op = xsi.ApplyOp( "SkeletonUpVector", self.end_chn.bones[0].FullName + ";" + self.upv_ctl.FullName)[0] par.addExpression(self.end_chn.roll, self.pIkRoll.FullName + " + 180") # ctrn for s in "xyz": par.addExpression( self.ctrn0_loc.Kinematics.Local.Parameters("rot" + s), self.ref_loc[1].Kinematics.Local.Parameters("rot" + s).FullName + " * .5") par.addExpression( self.ctrn0_loc.Kinematics.Global.Parameters("scl" + s), self.root.Kinematics.Global.Parameters("scl" + s).FullName) par.addExpression( self.ctrn1_loc.Kinematics.Local.Parameters("rot" + s), self.ref_loc[2].Kinematics.Local.Parameters("rot" + s).FullName + " * .5") par.addExpression( self.ctrn1_loc.Kinematics.Global.Parameters("scl" + s), self.root.Kinematics.Global.Parameters("scl" + s).FullName) self.ctrn0_loc.Kinematics.AddConstraint("Position", self.ref_loc[1], False) self.ctrn1_loc.Kinematics.AddConstraint("Position", self.ref_loc[2], False) # References Nulls --------------------------------- fk_ref = [self.fk0_ctl, self.fk1_ctl, self.fk2_ctl, self.fk_ref] ik_ref = [ self.ref_chn.bones[0], self.ref_chn.bones[1], self.end_chn.bones[0], self.ik_ref ] for i, ref_loc in enumerate(self.ref_loc): # fk cns = ref_loc.Kinematics.AddConstraint("Orientation", fk_ref[i], False) if i != len(self.ref_loc) - 1: cns = aop.dirCns(ref_loc, fk_ref[i + 1], None, False, self.n_sign + "xz") par.addExpression(cns.Parameters("blendweight"), "1 - " + self.pBlend.FullName) #ik cns = ref_loc.Kinematics.AddConstraint("Orientation", ik_ref[i], False) par.addExpression(cns.Parameters("blendweight"), self.pBlend.FullName) for s in "xyz": par.addExpression( ref_loc.Kinematics.Local.Parameters("rot" + s), 0) par.addExpression( self.ref_loc[1].Kinematics.Local.Parameters("posx"), self.n_sign + " (ctr_dist(%s.kine.global, %s.kine.global) * (1 - %s) + ctr_dist(%s.kine.global, %s.kine.global) * %s)" % (self.fk0_ctl.FullName, self.fk1_ctl.FullName, self.pBlend.FullName, self.ref_chn.bones[0].FullName, self.ref_chn.bones[1].FullName, self.pBlend.FullName)) par.addExpression( self.ref_loc[2].Kinematics.Local.Parameters("posx"), self.n_sign + " (ctr_dist(%s.kine.global, %s.kine.global) * (1 - %s) + ctr_dist(%s.kine.global, %s.kine.global) * %s)" % (self.fk1_ctl.FullName, self.fk2_ctl.FullName, self.pBlend.FullName, self.ref_chn.bones[1].FullName, self.end_chn.bones[0], self.pBlend.FullName)) par.addExpression( self.ref_loc[3].Kinematics.Local.Parameters("posx"), self.n_sign + " (ctr_dist(%s.kine.global, %s.kine.global) * (1 - %s) + ctr_dist(%s.kine.global, %s.kine.global) * %s)" % (self.fk2_ctl.FullName, self.fk3_ctl.FullName, self.pBlend.FullName, self.end_chn.bones[0].FullName, self.end_chn.eff, self.pBlend.FullName)) # Global Scale for s in "xyz": par.addExpression( self.ref_loc[0].Kinematics.Global.Parameters("scl%s" % s), 1) par.addExpression( self.end_ref.Kinematics.Global.Parameters("scl%s" % s), self.root.Kinematics.Global.Parameters("scl%s" % s)) # Twist references --------------------------------- par.addExpression( self.pDriver, "(ctr_dist(%s, %s) + ctr_dist(%s, %s) + ctr_dist(%s, %s)) / %s" % (self.tws0_loc.Kinematics.Global.FullName, self.tws1_loc.Kinematics.Global.FullName, self.tws1_loc.Kinematics.Global.FullName, self.tws2_loc.Kinematics.Global.FullName, self.tws2_loc.Kinematics.Global.FullName, self.tws3_loc.Kinematics.Global.FullName, self.root.Kinematics.Global.Parameters("sclx").FullName)) self.tws0_loc.Kinematics.AddConstraint("Pose", self.root, True) aop.dirCns(self.tws0_loc, self.mid0_ctl, None, False, self.n_sign + "xy") self.tws1_loc.Kinematics.AddConstraint("Position", self.mid0_ctl) self.tws1_loc.Kinematics.AddConstraint("Scaling", self.mid0_ctl) self.tws1_rot.Kinematics.AddConstraint("Orientation", self.mid0_ctl) par.addExpression(self.tws1_rot.Parameters("rotx"), 0) par.addExpression(self.tws1_rot.Parameters("roty"), 0) par.addExpression(self.tws1_rot.Parameters("rotz"), 0) self.tws2_loc.Kinematics.AddConstraint("Position", self.mid1_ctl) self.tws2_loc.Kinematics.AddConstraint("Scaling", self.mid1_ctl) self.tws2_rot.Kinematics.AddConstraint("Orientation", self.mid1_ctl) par.addExpression(self.tws2_rot.Parameters("rotx"), 0) par.addExpression(self.tws2_rot.Parameters("roty"), 0) par.addExpression(self.tws2_rot.Parameters("rotz"), 0) self.tws3_loc.Kinematics.AddConstraint("Position", self.ref_loc[-1]) #self.tws3_loc.Kinematics.AddConstraint("Scaling", self.eff_loc) aop.poseCns(self.tws3_rot, self.fk_ref, False, False, True, False) cns = aop.poseCns(self.tws3_rot, self.ik_ref, True, False, True, False) par.addExpression(cns.Parameters("blendweight"), self.pBlend.FullName) par.addExpression(self.tws3_rot.Parameters("rotx"), 0) par.addExpression(self.tws3_rot.Parameters("roty"), 0) par.addExpression(self.tws3_rot.Parameters("rotz"), 0) par.setRotOrder(self.tws3_rot, "YZX") self.tws0_rot.SclX = .001 par.addExpression(self.tws1_rot.SclX, self.pRoundness.FullName + " + .001") par.addExpression(self.tws2_rot.SclX, self.pRoundness.FullName + " + .001") self.tws3_rot.SclX = .001 # Divisions ---------------------------------------- # at 0 or 1 the division will follow exactly the rotation of the controler.. and we wont have this nice tangent + roll for i, div_cns in enumerate(self.div_cns): if i < (self.settings["div0"] + 1): perc = i / ((self.settings["div0"] + 1.0) * 3) elif i < (self.settings["div0"] + self.settings["div1"] + 2): perc = (1 / 3.0) + ((i - self.settings["div0"] - 1.0) / ((self.settings["div1"] + 1.0) * 3)) else: perc = (2 / 3.0) + ( (i - self.settings["div0"] - self.settings["div1"] - 2.0) / ((self.settings["div2"] + 1.0) * 3)) perc = max(.001, min(.999, perc)) if self.negate: op = aop.sn_rollsplinekine_op(div_cns, [ self.tws3_rot, self.tws2_rot, self.tws1_rot, self.tws0_rot ], 1 - perc) else: op = aop.sn_rollsplinekine_op(div_cns, [ self.tws0_rot, self.tws1_rot, self.tws2_rot, self.tws3_rot ], perc) # Squash n Stretch op = aop.sn_squashstretch2_op(div_cns, self.root, self.pDriver.Value, "x") par.addExpression(op.Parameters("blend"), self.pVolume.FullName) par.addExpression(op.Parameters("driver"), self.pDriver.FullName) if self.options["mode"] == 1: # wip par.addExpression(op.Parameters("stretch"), self.pStretch[i]) par.addExpression(op.Parameters("squash"), self.pSquash[i]) else: op.Parameters("stretch").Value = self.st_value[i] op.Parameters("squash").Value = self.sq_value[i]