def gear_ApplySpinePointAtOp_Execute(): start_obj = uit.pickSession(c.siGenericObjectFilter, "Pick Start Reference", True) if not start_obj: return end_obj = uit.pickSession(c.siGenericObjectFilter, "Pick End Reference", True) if not end_obj: return count = xsi.Selection.Count + 0.0 operators = [] for i, sel in enumerate(Application.Selection): path_cns = False for cns in sel.Kinematics.Constraints: if cns.Type in ["crvcns", "pathcns", "dircns"]: path_cns = cns break if not path_cns: gear.log( "There is no path ,curve or direction constraint on this object : %s" % sel.Name, gear.sev_warning) continue blend = i / count op = aop.spinePointAtOp(cns, start_obj, end_obj, blend) operators.append(op) xsi.InspectObj(operators)
def gear_ApplySpinePointAtOp_Execute(): start_obj = uit.pickSession(c.siGenericObjectFilter, "Pick Start Reference", True) if not start_obj: return end_obj = uit.pickSession(c.siGenericObjectFilter, "Pick End Reference", True) if not end_obj: return count = xsi.Selection.Count+0.0 operators = [] for i, sel in enumerate(Application.Selection): path_cns = False for cns in sel.Kinematics.Constraints: if cns.Type in ["crvcns", "pathcns"]: path_cns = cns break if not path_cns: gear.log("There is no path or curve constraint on this object : %s"%sel.Name, gear.sev_warning) continue blend = i/count op = aop.spinePointAtOp(cns, start_obj, end_obj, blend) operators.append(op) xsi.InspectObj(operators)
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.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): # 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.upv_ctl.Properties("visibility").Parameters("viewvis"), self.pBlend.FullName) par.addExpression(self.leash_crv.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) # Twist -------------------------------------------- for i, div_loc in enumerate(self.div0_loc): if i == 0: cns = aop.gear_dualUpVDirCns(div_loc, self.chain.root, self.chain.bones[1]) # cns = aop.dirCns(div_loc, self.chain.bones[1], None, False, "xy") # aop.gear_pointAtObjectAxis(cns, self.chain.root, [0,1,0]) elif i == self.settings["division0"]-1: continue else: d = i/(self.settings["division0"]-1.0) cns = aop.dirCns(div_loc, self.chain.bones[1], None, False, "xy") op = aop.spinePointAtOp(cns, self.div0_loc[0], self.chain.bones[0], d) for i, div_loc in enumerate(self.div_loc): d = i/(self.settings["division1"]-1.0) par.addExpression(div_loc.Parameters("rotx"), self.end_ref.Parameters("rotx").FullName+" * "+str(d)) # IK Solver----------------------------------------- # cns self.chain.eff.Kinematics.AddConstraint("Position", self.ik_ref, False) aop.chainUpvOp(self.chain, self.upv_ctl) for bone, fk_ctl, length, div in zip(self.chain.bones, [self.fk0_ctl, self.fk1_ctl], [self.length0, self.length1], self.div_loc): # for bone, fk in zip(self.chain.bones, [self.fk0_ctl, self.fk1_ctl]): # ik/fk orientation cns = bone.Kinematics.AddConstraint("Orientation", fk_ctl, False) par.addExpression(cns.Parameters("blendweight"), "1 - "+self.pBlend.FullName) # stretch fk_st = fk_ctl.Parameters("sclx").FullName + " * (1 - "+self.pBlend.FullName+")" root_eff_dist = "ctr_dist(%s.kine.global, %s.kine.global)"%(self.root.FullName, self.ik_ctl.FullName) ik_st = "cond("+root_eff_dist+" > "+str(self.chain.length)+", "+root_eff_dist+" / "+str(self.chain.length)+", 1) * "+self.pBlend.FullName parent_scl = bone.Parent3DObject.Parameters("sclx").FullName par.addExpression(bone.Parameters("sclx"), "("+fk_st+" + "+ik_st+")/"+parent_scl) # par.addExpression(div.Parameters("sclx"), bone.Parameters("length").FullName+"/"+str(length)) # blend / roll par.addExpression(self.chain.blend, self.pBlend) par.addExpression(self.chain.roll, self.pIkRoll) # ctr_loc self.ctrn_loc.Kinematics.AddConstraint("Position", self.chain.bones[1], False) for s in "xyz": par.addExpression(self.ctrn_loc.Kinematics.Local.Parameters("rot"+s), self.chain.bones[1].Kinematics.Local.Parameters("rot" + s).FullName + " * .5") # Stretch ----------------------------------------- # root_eff = "ctr_dist(%s.kine.global, %s.kine.global)"%(self.chain.root, self.ik_ref) # st_value = "(%s/%s)"%(root_eff,self.chain.length) # for bone in self.chain.bones: # par.addExpression(bone.Parameters("length"), # "cond(%s>%s,%s*%s,%s)*%s + %s*(1 - %s)"%(root_eff, # self.chain.length, # bone.Parameters("length").Value, # st_value, bone.Parameters("length").Value, # self.pBlend.FullName, # bone.Parameters("length").Value, # self.pBlend.FullName)) # Hook self.end_ref.Kinematics.AddConstraint("Position", self.chain.eff) self.end_ref.Kinematics.AddConstraint("Scaling", self.chain.eff) aop.poseCns(self.end_ref, self.fk2_ctl, True, False, True, False) cns = aop.poseCns(self.end_ref, self.ik_ref, True, False, True, False) par.addExpression(cns.Parameters("blendweight"), self.pBlend.fullName) par.addExpression(self.end_ref.Parameters("rotx"), 0) par.addExpression(self.end_ref.Parameters("roty"), 0) par.addExpression(self.end_ref.Parameters("rotz"), 0) par.setRotOrder(self.end_ref, "YZX") # Shape Reference --------------------------------- # shoulder aop.gear_rotationToPose(self.end_ref, self.chain.bones[1], self.ankle_outputs, "x", 0)
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])