def getChainTransform(positions, normal, negate=False): """ Get a tranformation list from a positions list and normal. Args: positions(list of vector): List with the chain positions. normal (vector): Normal direction. negate (bool): If true invert the chain orientation. returns: list of matrix: The list containing the transformation matrix for the chain. >>> tra.getChainTransform(self.guide.apos, self.normal, self.negate) """ # Draw transforms = [] for i in range(len(positions) - 1): v0 = positions[i - 1] v1 = positions[i] v2 = positions[i + 1] # Normal Offset if i > 0: normal = vec.getTransposedVector(normal, [v0, v1], [v1, v2]) t = getTransformLookingAt(v1, v2, normal, "xz", negate) transforms.append(t) return transforms
def addObjects(self): self.normal = self.guide.blades["blade"].z self.binormal = self.guide.blades["blade"].x self.isFk = self.settings["mode"] != 1 self.isIk = self.settings["mode"] != 0 self.isFkIk = self.settings["mode"] == 2 # FK controlers ------------------------------------ if self.isFk: self.fk_npo = [] self.fk_ctl = [] parent = self.root for i, t in enumerate(tra.getChainTransform(self.guide.apos, self.normal, self.negate)): dist = vec.getDistance(self.guide.apos[i], self.guide.apos[i+1]) fk_npo = pri.addTransform(parent, self.getName("fk%s_npo"%i), t) fk_ctl = self.addCtl(fk_npo, "fk%s_ctl"%i, t, self.color_fk, "cube", w=dist, h=self.size*.1, d=self.size*.1, po=dt.Vector(dist*.5*self.n_factor,0,0)) parent = fk_ctl self.fk_npo.append(fk_npo) self.fk_ctl.append(fk_ctl) # IK controlers ------------------------------------ if self.isIk: normal = vec.getTransposedVector(self.normal, [self.guide.apos[0], self.guide.apos[1]], [self.guide.apos[-2], self.guide.apos[-1]]) t = tra.getTransformLookingAt(self.guide.apos[-2], self.guide.apos[-1], normal, "xy", self.negate) t = tra.setMatrixPosition(t, self.guide.apos[-1]) self.ik_cns = pri.addTransform(self.root, self.getName("ik_cns"), t) self.ikcns_ctl = self.addCtl(self.ik_cns, "ikcns_ctl", t, self.color_ik, "null", w=self.size) self.ik_ctl = self.addCtl(self.ikcns_ctl, "ik_ctl", t, self.color_ik, "cube", w=self.size*.3, h=self.size*.3, d=self.size*.3) v = self.guide.apos[-1] - self.guide.apos[0] v = v ^ self.normal v.normalize() v *= self.size v += self.guide.apos[1] self.upv_cns = pri.addTransformFromPos(self.root, self.getName("upv_cns"), v) self.upv_ctl = self.addCtl(self.upv_cns, "upv_ctl", tra.getTransform(self.upv_cns), self.color_ik, "diamond", w=self.size*.1) # Chain self.chain = pri.add2DChain(self.root, self.getName("chain"), self.guide.apos, self.normal, self.negate) self.ikh = pri.addIkHandle(self.root, self.getName("ikh"), self.chain) # Chain of deformers ------------------------------- self.loc = [] parent = self.root for i, t in enumerate(tra.getChainTransform(self.guide.apos, self.normal, self.negate)): loc = pri.addTransform(parent, self.getName("%s_loc"%i), t) self.addShadow(loc, i) self.loc.append(loc) parent = loc
def getChainTransform(positions, normal, negate=False): # Draw transforms = [] for i in range(len(positions) - 1): v0 = positions[i - 1] v1 = positions[i] v2 = positions[i + 1] # Normal Offset if i > 0: normal = vec.getTransposedVector(normal, [v0, v1], [v1, v2]) t = getTransformLookingAt(v1, v2, normal, "xz", negate) transforms.append(t) return transforms
def getChainTransform(positions, normal, negate=False): # Draw transforms = [] for i in range(len(positions)-1): v0 = positions[i-1] v1 = positions[i] v2 = positions[i+1] # Normal Offset if i > 0: normal = vec.getTransposedVector(normal, [v0, v1], [v1, v2]) t = getTransformLookingAt(v1, v2, normal, "xz", negate) transforms.append(t) return transforms
def addObjects(self): """Add all the objects needed to create the component.""" self.normal = self.guide.blades["blade"].z * -1 self.binormal = self.guide.blades["blade"].x self.isFk = self.settings["mode"] != 1 self.isIk = self.settings["mode"] != 0 self.isFkIk = self.settings["mode"] == 2 self.WIP = self.options["mode"] # FK controllers ------------------------------------ if self.isFk: self.fk_npo = [] self.fk_ctl = [] self.fk_ref = [] self.fk_off = [] t = self.guide.tra["root"] self.ik_cns = primitive.addTransform(self.root, self.getName("ik_cns"), t) parent = self.ik_cns tOld = False fk_ctl = None self.previusTag = self.parentCtlTag for i, t in enumerate( transform.getChainTransform(self.guide.apos, self.normal, self.negate)): dist = vector.getDistance(self.guide.apos[i], self.guide.apos[i + 1]) if self.settings["neutralpose"] or not tOld: tnpo = t else: tnpo = transform.setMatrixPosition( tOld, transform.getPositionFromMatrix(t)) if i: tref = transform.setMatrixPosition( tOld, transform.getPositionFromMatrix(t)) fk_ref = primitive.addTransform( fk_ctl, self.getName("fk%s_ref" % i), tref) self.fk_ref.append(fk_ref) else: tref = t fk_off = primitive.addTransform(parent, self.getName("fk%s_off" % i), tref) fk_npo = primitive.addTransform(fk_off, self.getName("fk%s_npo" % i), tnpo) fk_ctl = self.addCtl(fk_npo, "fk%s_ctl" % i, t, self.color_fk, "cube", w=dist, h=self.size * .1, d=self.size * .1, po=datatypes.Vector( dist * .5 * self.n_factor, 0, 0), tp=self.previusTag) self.fk_off.append(fk_off) self.fk_npo.append(fk_npo) self.fk_ctl.append(fk_ctl) tOld = t self.previusTag = fk_ctl # IK controllers ------------------------------------ if self.isIk: normal = vector.getTransposedVector( self.normal, [self.guide.apos[0], self.guide.apos[1]], [self.guide.apos[-2], self.guide.apos[-1]]) t = transform.getTransformLookingAt(self.guide.apos[-2], self.guide.apos[-1], normal, "xy", self.negate) t = transform.setMatrixPosition(t, self.guide.apos[-1]) self.ik_cns = primitive.addTransform(self.root, self.getName("ik_cns"), t) self.ikcns_ctl = self.addCtl(self.ik_cns, "ikcns_ctl", t, self.color_ik, "null", w=self.size, tp=self.parentCtlTag) self.ik_ctl = self.addCtl(self.ikcns_ctl, "ik_ctl", t, self.color_ik, "cube", w=self.size * .3, h=self.size * .3, d=self.size * .3, tp=self.ikcns_ctl) attribute.setKeyableAttributes(self.ik_ctl, self.t_params) v = self.guide.apos[-1] - self.guide.apos[0] v = v ^ self.normal v.normalize() v *= self.size v += self.guide.apos[1] self.upv_cns = primitive.addTransformFromPos( self.root, self.getName("upv_cns"), v) self.upv_ctl = self.addCtl(self.upv_cns, "upv_ctl", transform.getTransform(self.upv_cns), self.color_ik, "diamond", w=self.size * .1, tp=self.parentCtlTag) attribute.setKeyableAttributes(self.upv_ctl, self.t_params) # Chain self.chain = primitive.add2DChain(self.root, self.getName("chain"), self.guide.apos, self.normal, self.negate) self.chain[0].attr("visibility").set(self.WIP) # Chain of deformers ------------------------------- self.loc = [] parent = self.root for i, t in enumerate( transform.getChainTransform(self.guide.apos, self.normal, self.negate)): loc = primitive.addTransform(parent, self.getName("%s_loc" % i), t) self.loc.append(loc) self.jnt_pos.append([loc, i, None, False])
def addObjects(self): self.normal = self.guide.blades["blade"].z*-1 self.binormal = self.guide.blades["blade"].x self.isFk = self.settings["mode"] != 1 self.isIk = self.settings["mode"] != 0 self.isFkIk = self.settings["mode"] == 2 self.WIP = self.options["mode"] # FK controllers ------------------------------------ if self.isFk: self.fk_npo = [] self.fk_ctl = [] t = self.guide.tra["root"] self.ik_cns = pri.addTransform(self.root, self.getName("ik_cns"), t) parent = self.ik_cns tOld = False for i, t in enumerate(tra.getChainTransform(self.guide.apos, self.normal, self.negate)): dist = vec.getDistance(self.guide.apos[i], self.guide.apos[i+1]) if self.settings["neutralpose"] or not tOld: tnpo = t else: tnpo = tra.setMatrixPosition(tOld, tra.getPositionFromMatrix(t)) fk_npo = pri.addTransform(parent, self.getName("fk%s_npo"%i), tnpo) fk_ctl = self.addCtl(fk_npo, "fk%s_ctl"%i, t, self.color_fk, "cube", w=dist, h=self.size*.1, d=self.size*.1, po=dt.Vector(dist*.5*self.n_factor,0,0)) parent = fk_ctl self.fk_npo.append(fk_npo) self.fk_ctl.append(fk_ctl) tOld = t # IK controllers ------------------------------------ if self.isIk: normal = vec.getTransposedVector(self.normal, [self.guide.apos[0], self.guide.apos[1]], [self.guide.apos[-2], self.guide.apos[-1]]) t = tra.getTransformLookingAt(self.guide.apos[-2], self.guide.apos[-1], normal, "xy", self.negate) t = tra.setMatrixPosition(t, self.guide.apos[-1]) self.ik_cns = pri.addTransform(self.root, self.getName("ik_cns"), t) self.ikcns_ctl = self.addCtl(self.ik_cns, "ikcns_ctl", t, self.color_ik, "null", w=self.size) self.ik_ctl = self.addCtl(self.ikcns_ctl, "ik_ctl", t, self.color_ik, "cube", w=self.size*.3, h=self.size*.3, d=self.size*.3) v = self.guide.apos[-1] - self.guide.apos[0] v = v ^ self.normal v.normalize() v *= self.size v += self.guide.apos[1] self.upv_cns = pri.addTransformFromPos(self.root, self.getName("upv_cns"), v) self.upv_ctl = self.addCtl(self.upv_cns, "upv_ctl", tra.getTransform(self.upv_cns), self.color_ik, "diamond", w=self.size*.1) # Chain self.chain = pri.add2DChain(self.root, self.getName("chain"), self.guide.apos, self.normal, self.negate) self.chain[0].attr("visibility").set(self.WIP) # Chain of deformers ------------------------------- self.loc = [] parent = self.root for i, t in enumerate(tra.getChainTransform(self.guide.apos, self.normal, self.negate)): loc = pri.addTransform(parent, self.getName("%s_loc"%i), t) self.loc.append(loc) self.jnt_pos.append([loc, i]) parent = loc