def addOperators(self): # Visibilities ------------------------------------- if self.isFkIk: for fk_ctl in self.fk_ctl: par.addExpression(fk_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) # IK Chain ----------------------------------------- if self.isIk: # Leash aop.clsCtrOp(self.upv_ctl, self.chain.bones[0], [0]) # Constraint and up vector self.chain.eff.Kinematics.AddConstraint("Position", self.ik_ctl, False) xsi.ApplyOp("SkeletonUpVector", self.chain.bones[0].FullName+";"+self.upv_ctl.FullName, 3, "siPersistentOperation", "", 0) par.addExpression(self.chain.roll, self.pRoll.FullName) # Chain of deformers ------------------------------- for i, loc in enumerate(self.loc): if self.settings["type"] == 0: # fk only loc.Kinematics.addConstraint("Pose", self.fk_ctl[i]) elif self.settings["type"] == 1: # ik only loc.Kinematics.addConstraint("Pose", self.chain.bones[i]) elif self.settings["type"] == 2: # fk/ik # orientation cns = loc.Kinematics.AddConstraint("Orientation", self.fk_ctl[i]) cns = loc.Kinematics.AddConstraint("Orientation", self.chain.bones[i]) par.addExpression(cns.Parameters("blendweight"), self.pBlend.FullName) # position / scaling for s in "xyz": par.addExpression(loc.Kinematics.Local.Parameters("pos%s"%s), self.fk_ctl[i].Kinematics.Local.Parameters("pos%s"%s).FullName+" * (1 - "+self.pBlend.FullName+") + "+self.chain.bones[i].Kinematics.Local.Parameters("pos%s"%s).FullName +" * "+self.pBlend.FullName) par.addExpression(loc.Kinematics.Local.Parameters("scl%s"%s), self.fk_ctl[i].Kinematics.Local.Parameters("scl%s"%s).FullName+" * (1 - "+self.pBlend.FullName+") + "+self.chain.bones[i].Kinematics.Local.Parameters("scl%s"%s).FullName +" * "+self.pBlend.FullName) # Default Values ----------------------------------- if self.isFkIk: self.pBlend.Value = self.settings["blend"]
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): # Controlers Limits ------------------------------- # pos_0 = self.crv[0].ActivePrimitive.Geometry.Curves(0).EvaluatePosition(0)[0] # pos_1 = self.crv[0].ActivePrimitive.Geometry.Curves(0).EvaluatePosition(4)[0] # pos_0 = XSIMath.MapObjectPositionToWorldSpace(self.crv[0].Kinematics.Global.Transform, pos_0) # pos_1 = XSIMath.MapObjectPositionToWorldSpace(self.crv[0].Kinematics.Global.Transform, pos_1) # lim_min = pos_0.Y - self.ctl[0].Kinematics.Global.Transform.Translation.Y # lim_max = pos_1.Y - self.ctl[0].Kinematics.Global.Transform.Translation.Y for ctl, crv, upv, centers, off, perc in zip(self.ctl, self.crv, self.upv, self.ctr, self.off, self.percentages): # crv_geo = crv.ActivePrimitive.Geometry # crv_0 = crv_geo.Curves(0) # crv_tra = crv.Kinematics.Global.Transform # Set Limits ---------------------------------- par.setLimit(ctl, ["posy"], -1, 1) # ctl.Kinematics.Local.Parameters("posyminactive").Value = True # ctl.Kinematics.Local.Parameters("posymaxactive").Value = True # ctl.Kinematics.Local.Parameters("posyminlimit").Value = lim_min # ctl.Kinematics.Local.Parameters("posymaxlimit").Value = lim_max # Path Constraint ----------------------------- constraints = [] for ctr in centers: cns = aop.pathCns(ctr, crv, 0, perc, True, upv, False) ope.setConstraintTangency(cns, [0,1,0], [0,0,-1]) constraints.append(cns) pos_min = "max(0,-%s)*%s"%(ctl.Kinematics.Local.Parameters("posy").FullName,perc) pos_max = "max(0,%s)*%s"%(ctl.Kinematics.Local.Parameters("posy").FullName,100-perc) par.addExpression(constraints[1].Parameters("perc"), "%s - %s + %s"%(perc,pos_min,pos_max)) cns_perc = constraints[1].Parameters("perc").FullName par.addExpression(constraints[0].Parameters("perc"), cns_perc + " * .5 ") par.addExpression(constraints[2].Parameters("perc"), cns_perc + " + (100 - "+cns_perc+" ) * .5 ") # Connect Offset to Controler for s in "xz": par.addExpression(off.Kinematics.Local.Parameters("pos%s"%s), ctl.Kinematics.Local.Parameters("pos%s"%s).FullName+" * "+str(self.scale)) for s in "yz": par.addExpression(off.Kinematics.Local.Parameters("rot%s"%s), ctl.Kinematics.Local.Parameters("rot%s"%s).FullName) for s in "x": par.addExpression(off.Kinematics.Local.Parameters("scl%s"%s), ctl.Kinematics.Local.Parameters("scl%s"%s).FullName) # Constrained Curve ------------------------------- for i in range(self.crv_count): if i == self.inter_crv: centers = self.off else: centers = [ctr[i] for ctr in self.ctr] for ctr, pnts in zip(centers, [[0,1],[2],[3,4]]): aop.clsCtrOp(self.cns_crv[i], ctr, pnts) # Shadows ----------------------------------------- constraints = [] for i in range(self.shd_count): u = i/4.0 for j in range(self.crv_count): if j == self.inter_crv: cns = aop.pathCns(self.loc[j*self.shd_count+i], self.cns_crv[j], 1, u, True, None, False) constraints.append(cns) else: cns = aop.pathCns(self.loc[j*self.shd_count+i], self.cns_crv[j], 1, u, True, self.upv[0], False) # Connect Roll aop.gear_pointAtObjectAxis(constraints[0], self.ctl[0], [0,0,1]) aop.spinePointAtOp(constraints[1], self.ctl[0], self.ctl[1], .5) aop.gear_pointAtObjectAxis(constraints[2], self.ctl[1], [0,0,1]) aop.spinePointAtOp(constraints[3], self.ctl[1], self.ctl[2], .5) aop.gear_pointAtObjectAxis(constraints[4], self.ctl[2], [0,0,1])
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]
def addOperators(self): # Controlers Limits ------------------------------- # pos_0 = self.crv[0].ActivePrimitive.Geometry.Curves(0).EvaluatePosition(0)[0] # pos_1 = self.crv[0].ActivePrimitive.Geometry.Curves(0).EvaluatePosition(4)[0] # pos_0 = XSIMath.MapObjectPositionToWorldSpace(self.crv[0].Kinematics.Global.Transform, pos_0) # pos_1 = XSIMath.MapObjectPositionToWorldSpace(self.crv[0].Kinematics.Global.Transform, pos_1) # lim_min = pos_0.Y - self.ctl[0].Kinematics.Global.Transform.Translation.Y # lim_max = pos_1.Y - self.ctl[0].Kinematics.Global.Transform.Translation.Y for ctl, crv, upv, centers, off, perc in zip(self.ctl, self.crv, self.upv, self.ctr, self.off, self.percentages): # crv_geo = crv.ActivePrimitive.Geometry # crv_0 = crv_geo.Curves(0) # crv_tra = crv.Kinematics.Global.Transform # Set Limits ---------------------------------- par.setLimit(ctl, ["posy"], -1, 1) # ctl.Kinematics.Local.Parameters("posyminactive").Value = True # ctl.Kinematics.Local.Parameters("posymaxactive").Value = True # ctl.Kinematics.Local.Parameters("posyminlimit").Value = lim_min # ctl.Kinematics.Local.Parameters("posymaxlimit").Value = lim_max # Path Constraint ----------------------------- constraints = [] for ctr in centers: cns = aop.pathCns(ctr, crv, 0, perc, True, upv, False) ope.setConstraintTangency(cns, [0, 1, 0], [0, 0, -1]) constraints.append(cns) pos_min = "max(0,-%s)*%s" % ( ctl.Kinematics.Local.Parameters("posy").FullName, perc) pos_max = "max(0,%s)*%s" % ( ctl.Kinematics.Local.Parameters("posy").FullName, 100 - perc) par.addExpression(constraints[1].Parameters("perc"), "%s - %s + %s" % (perc, pos_min, pos_max)) cns_perc = constraints[1].Parameters("perc").FullName par.addExpression(constraints[0].Parameters("perc"), cns_perc + " * .5 ") par.addExpression(constraints[2].Parameters("perc"), cns_perc + " + (100 - " + cns_perc + " ) * .5 ") # Connect Offset to Controler for s in "xz": par.addExpression( off.Kinematics.Local.Parameters("pos%s" % s), ctl.Kinematics.Local.Parameters("pos%s" % s).FullName + " * " + str(self.scale)) for s in "yz": par.addExpression( off.Kinematics.Local.Parameters("rot%s" % s), ctl.Kinematics.Local.Parameters("rot%s" % s).FullName) for s in "x": par.addExpression( off.Kinematics.Local.Parameters("scl%s" % s), ctl.Kinematics.Local.Parameters("scl%s" % s).FullName) # Constrained Curve ------------------------------- for i in range(self.crv_count): if i == self.inter_crv: centers = self.off else: centers = [ctr[i] for ctr in self.ctr] for ctr, pnts in zip(centers, [[0, 1], [2], [3, 4]]): aop.clsCtrOp(self.cns_crv[i], ctr, pnts) # Shadows ----------------------------------------- constraints = [] for i in range(self.shd_count): u = i / 4.0 for j in range(self.crv_count): if j == self.inter_crv: cns = aop.pathCns(self.loc[j * self.shd_count + i], self.cns_crv[j], 1, u, True, None, False) constraints.append(cns) else: cns = aop.pathCns(self.loc[j * self.shd_count + i], self.cns_crv[j], 1, u, True, self.upv[0], False) # Connect Roll aop.gear_pointAtObjectAxis(constraints[0], self.ctl[0], [0, 0, 1]) aop.spinePointAtOp(constraints[1], self.ctl[0], self.ctl[1], .5) aop.gear_pointAtObjectAxis(constraints[2], self.ctl[1], [0, 0, 1]) aop.spinePointAtOp(constraints[3], self.ctl[1], self.ctl[2], .5) aop.gear_pointAtObjectAxis(constraints[4], self.ctl[2], [0, 0, 1])
def addOperators(self): # Visibilities ------------------------------------- if self.isFkIk: for fk_ctl in self.fk_ctl: par.addExpression( fk_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) # IK Chain ----------------------------------------- if self.isIk: # Leash aop.clsCtrOp(self.upv_ctl, self.chain.bones[0], [0]) # Constraint and up vector self.chain.eff.Kinematics.AddConstraint("Position", self.ik_ctl, False) xsi.ApplyOp( "SkeletonUpVector", self.chain.bones[0].FullName + ";" + self.upv_ctl.FullName, 3, "siPersistentOperation", "", 0) par.addExpression(self.chain.roll, self.pRoll.FullName) # Chain of deformers ------------------------------- for i, loc in enumerate(self.loc): if self.settings["type"] == 0: # fk only loc.Kinematics.addConstraint("Pose", self.fk_ctl[i]) elif self.settings["type"] == 1: # ik only loc.Kinematics.addConstraint("Pose", self.chain.bones[i]) elif self.settings["type"] == 2: # fk/ik # orientation cns = loc.Kinematics.AddConstraint("Orientation", self.fk_ctl[i]) cns = loc.Kinematics.AddConstraint("Orientation", self.chain.bones[i]) par.addExpression(cns.Parameters("blendweight"), self.pBlend.FullName) # position / scaling for s in "xyz": par.addExpression( loc.Kinematics.Local.Parameters("pos%s" % s), self.fk_ctl[i].Kinematics.Local.Parameters( "pos%s" % s).FullName + " * (1 - " + self.pBlend.FullName + ") + " + self.chain.bones[i].Kinematics.Local.Parameters( "pos%s" % s).FullName + " * " + self.pBlend.FullName) par.addExpression( loc.Kinematics.Local.Parameters("scl%s" % s), self.fk_ctl[i].Kinematics.Local.Parameters( "scl%s" % s).FullName + " * (1 - " + self.pBlend.FullName + ") + " + self.chain.bones[i].Kinematics.Local.Parameters( "scl%s" % s).FullName + " * " + self.pBlend.FullName) # Default Values ----------------------------------- if self.isFkIk: self.pBlend.Value = self.settings["blend"]