def setupRigJoint(words, obj, verts, locations): key = words[0] typ = words[1] if typ == 'joint': loc = mh2proxy.calcJointPos(obj, words[2]) locations[key] = loc elif typ == 'vertex': v = int(words[2]) locations[key] = verts[v].co elif typ == 'position': x = locations[words[2]] y = locations[words[3]] z = locations[words[4]] locations[key] = [x[0], y[1], z[2]] elif typ == 'line': k1 = float(words[2]) k2 = float(words[4]) locations[key] = vadd(vmul(locations[words[3]], k1), vmul(locations[words[5]], k2)) elif typ == 'offset': x = float(words[3]) y = float(words[4]) z = float(words[5]) locations[key] = vadd(locations[words[2]], [x, y, z]) elif typ == 'voffset': v = int(words[2]) x = float(words[3]) y = float(words[4]) z = float(words[5]) try: loc = verts[v].co except: loc = verts[v] locations[key] = vadd(loc, [x, y, z]) elif typ == 'front': raw = locations[words[2]] head = locations[words[3]] tail = locations[words[4]] offs = map(float, words[5].strip().lstrip('[').rstrip(']').split(',')) vec = aljabr.vsub(tail, head) vec2 = aljabr.vdot(vec, vec) vraw = aljabr.vsub(raw, head) x = aljabr.vdot(vec, vraw) / vec2 rvec = aljabr.vmul(vec, x) nloc = aljabr.vadd(head, rvec, offs) locations[key] = nloc else: raise NameError("Unknown %s" % typ)
def setupRigJoint (words, obj, verts, locations): key = words[0] typ = words[1] if typ == 'joint': loc = mh2proxy.calcJointPos(obj, words[2]) locations[key] = loc elif typ == 'vertex': v = int(words[2]) locations[key] = verts[v].co elif typ == 'position': x = locations[words[2]] y = locations[words[3]] z = locations[words[4]] locations[key] = [x[0],y[1],z[2]] elif typ == 'line': k1 = float(words[2]) k2 = float(words[4]) locations[key] = vadd(vmul(locations[words[3]], k1), vmul(locations[words[5]], k2)) elif typ == 'offset': x = float(words[3]) y = float(words[4]) z = float(words[5]) locations[key] = vadd(locations[words[2]], [x,y,z]) elif typ == 'voffset': v = int(words[2]) x = float(words[3]) y = float(words[4]) z = float(words[5]) try: loc = verts[v].co except: loc = verts[v] locations[key] = vadd(loc, [x,y,z]) elif typ == 'front': raw = locations[words[2]] head = locations[words[3]] tail = locations[words[4]] offs = map(float, words[5].strip().lstrip('[').rstrip(']').split(',')) vec = aljabr.vsub(tail, head) vec2 = aljabr.vdot(vec, vec) vraw = aljabr.vsub(raw, head) x = aljabr.vdot(vec, vraw) / vec2 rvec = aljabr.vmul(vec, x) nloc = aljabr.vadd(head, rvec, offs) locations[key] = nloc else: raise NameError("Unknown %s" % typ)
def setupRigJoint (words, obj, coord, locations): key = words[0] typ = words[1] if typ == 'joint': locations[key] = mh2proxy.calcJointPos(obj, words[2]) elif typ == 'vertex': vn = int(words[2]) locations[key] = obj.coord[vn] elif typ == 'position': x = locations[int(words[2])] y = locations[int(words[3])] z = locations[int(words[4])] locations[key] = np.array((x[0],y[1],z[2])) elif typ == 'line': k1 = float(words[2]) vn1 = int(words[3]) k2 = float(words[4]) vn2 = int(words[5]) locations[key] = k1*locations[vn1] + k2*locations[vn2] elif typ == 'offset': vn = int(words[2]) x = float(words[3]) y = float(words[4]) z = float(words[5]) locations[key] = locations[vn] + np.array((x,y,z)) elif typ == 'voffset': vn = int(words[2]) x = float(words[3]) y = float(words[4]) z = float(words[5]) try: loc = obj.coord[vn] except: loc = coord[vn] locations[key] = loc + np.array((x,y,z)) elif typ == 'front': raw = locations[words[2]] head = locations[words[3]] tail = locations[words[4]] offs = map(float, words[5].strip().lstrip('[').rstrip(']').split(',')) offs = np.array(offs) vec = tail - head vraw = raw - head x = np.dot(vec,vraw) / np.dot(vec, vec) locations[key] = head + x*vec + offs else: raise NameError("Unknown %s" % typ)
def setupRigJoint(words, obj, coord, locations): key = words[0] typ = words[1] if typ == 'joint': locations[key] = mh2proxy.calcJointPos(obj, words[2]) elif typ == 'vertex': vn = int(words[2]) locations[key] = obj.coord[vn] elif typ == 'position': x = locations[int(words[2])] y = locations[int(words[3])] z = locations[int(words[4])] locations[key] = np.array((x[0], y[1], z[2])) elif typ == 'line': k1 = float(words[2]) vn1 = int(words[3]) k2 = float(words[4]) vn2 = int(words[5]) locations[key] = k1 * locations[vn1] + k2 * locations[vn2] elif typ == 'offset': vn = int(words[2]) x = float(words[3]) y = float(words[4]) z = float(words[5]) locations[key] = locations[vn] + np.array((x, y, z)) elif typ == 'voffset': vn = int(words[2]) x = float(words[3]) y = float(words[4]) z = float(words[5]) try: loc = obj.coord[vn] except: loc = coord[vn] locations[key] = loc + np.array((x, y, z)) elif typ == 'front': raw = locations[words[2]] head = locations[words[3]] tail = locations[words[4]] offs = map(float, words[5].strip().lstrip('[').rstrip(']').split(',')) offs = np.array(offs) vec = tail - head vraw = raw - head x = np.dot(vec, vraw) / np.dot(vec, vec) locations[key] = head + x * vec + offs else: raise NameError("Unknown %s" % typ)
def setupLocations(obj): global locations locations = {} for j in joints: loc = mh2proxy.calcJointPos(obj, j) locations[j] = loc for (j, v) in vertLocations: locations[j] = obj.verts[v].co for (j, h, t, k) in otherLocations: hloc = locations[h] tloc = locations[t] vec = vsub(tloc, hloc) vec2 = vmul(vec, k) loc = vadd(tloc, vec2) locations[j] = loc for (j, l, r, a) in midLocations: left = vmul(locations[l], 1 - a) right = vmul(locations[r], a) locations[j] = vadd(left, right)
def newSetupJoints(obj, joints): the.Locations = {} for (key, typ, data) in joints: #print(key) if typ == 'j': loc = mh2proxy.calcJointPos(obj, data) the.Locations[key] = loc the.Locations[data] = loc elif typ == 'v': v = int(data) the.Locations[key] = obj.verts[v].co elif typ == 'x': the.Locations[key] = [ float(data[0]), float(data[2]), -float(data[1]) ] elif typ == 'vo': v = int(data[0]) loc = obj.verts[v].co the.Locations[key] = [ loc[0] + float(data[1]), loc[1] + float(data[3]), loc[2] - float(data[2]) ] elif typ == 'vl': ((k1, v1), (k2, v2)) = data loc1 = obj.verts[int(v1)].co loc2 = obj.verts[int(v2)].co the.Locations[key] = vadd(vmul(loc1, k1), vmul(loc2, k2)) elif typ == 'f': (raw, head, tail, offs) = data rloc = the.Locations[raw] hloc = the.Locations[head] tloc = the.Locations[tail] #print(raw, rloc) vec = aljabr.vsub(tloc, hloc) vec2 = aljabr.vdot(vec, vec) vraw = aljabr.vsub(rloc, hloc) x = aljabr.vdot(vec, vraw) / vec2 rvec = aljabr.vmul(vec, x) nloc = aljabr.vadd(hloc, rvec, offs) #print(key, nloc) the.Locations[key] = nloc elif typ == 'b': the.Locations[key] = the.Locations[data] elif typ == 'p': x = the.Locations[data[0]] y = the.Locations[data[1]] z = the.Locations[data[2]] the.Locations[key] = [x[0], y[1], z[2]] elif typ == 'vz': v = int(data[0]) z = obj.verts[v].co[2] loc = the.Locations[data[1]] the.Locations[key] = [loc[0], loc[1], z] elif typ == 'X': r = the.Locations[data[0]] (x, y, z) = data[1] r1 = [float(x), float(y), float(z)] the.Locations[key] = aljabr.vcross(r, r1) elif typ == 'l': ((k1, joint1), (k2, joint2)) = data the.Locations[key] = vadd(vmul(the.Locations[joint1], k1), vmul(the.Locations[joint2], k2)) elif typ == 'o': (joint, offsSym) = data if type(offsSym) == str: offs = the.Locations[offsSym] else: offs = offsSym the.Locations[key] = vadd(the.Locations[joint], offs) else: raise NameError("Unknown %s" % typ) return
def setupJoints(self): """ Evaluate symbolic expressions for joint locations and store them in self.locations. Joint locations are specified symbolically in the *Joints list in the beginning of the rig_*.py files (e.g. ArmJoints in rig_arm.py). """ for (key, typ, data) in self.joints: if typ == 'j': loc = mh2proxy.calcJointPos(self.mesh, data) self.locations[key] = loc self.locations[data] = loc elif typ == 'v': v = int(data) self.locations[key] = self.mesh.coord[v] elif typ == 'x': self.locations[key] = np.array( (float(data[0]), float(data[2]), -float(data[1]))) elif typ == 'vo': v = int(data[0]) offset = np.array( (float(data[1]), float(data[3]), -float(data[2]))) self.locations[key] = self.mesh.coord[v] + offset elif typ == 'vl': ((k1, v1), (k2, v2)) = data loc1 = self.mesh.coord[int(v1)] loc2 = self.mesh.coord[int(v2)] self.locations[key] = k1 * loc1 + k2 * loc2 elif typ == 'f': (raw, head, tail, offs) = data rloc = self.locations[raw] hloc = self.locations[head] tloc = self.locations[tail] vec = tloc - hloc vraw = rloc - hloc x = np.dot(vec, vraw) / np.dot(vec, vec) self.locations[key] = hloc + x * vec + np.array(offs) elif typ == 'b': self.locations[key] = self.locations[data] elif typ == 'p': x = self.locations[data[0]] y = self.locations[data[1]] z = self.locations[data[2]] self.locations[key] = np.array((x[0], y[1], z[2])) elif typ == 'vz': v = int(data[0]) z = self.mesh.coord[v][2] loc = self.locations[data[1]] self.locations[key] = np.array((loc[0], loc[1], z)) elif typ == 'X': r = self.locations[data[0]] (x, y, z) = data[1] r1 = np.array([float(x), float(y), float(z)]) self.locations[key] = np.cross(r, r1) elif typ == 'l': ((k1, joint1), (k2, joint2)) = data self.locations[key] = k1 * self.locations[ joint1] + k2 * self.locations[joint2] elif typ == 'o': (joint, offsSym) = data if type(offsSym) == str: offs = self.locations[offsSym] else: offs = np.array(offsSym) self.locations[key] = self.locations[joint] + offs else: raise NameError("Unknown %s" % typ) return
def setupJoints (self): """ Evaluate symbolic expressions for joint locations and store them in self.locations. Joint locations are specified symbolically in the *Joints list in the beginning of the rig_*.py files (e.g. ArmJoints in rig_arm.py). """ for (key, typ, data) in self.joints: if typ == 'j': loc = mh2proxy.calcJointPos(self.mesh, data) self.locations[key] = loc self.locations[data] = loc elif typ == 'v': v = int(data) self.locations[key] = self.mesh.coord[v] elif typ == 'x': self.locations[key] = np.array((float(data[0]), float(data[2]), -float(data[1]))) elif typ == 'vo': v = int(data[0]) offset = np.array((float(data[1]), float(data[3]), -float(data[2]))) self.locations[key] = self.mesh.coord[v] + offset elif typ == 'vl': ((k1, v1), (k2, v2)) = data loc1 = self.mesh.coord[int(v1)] loc2 = self.mesh.coord[int(v2)] self.locations[key] = k1*loc1 + k2*loc2 elif typ == 'f': (raw, head, tail, offs) = data rloc = self.locations[raw] hloc = self.locations[head] tloc = self.locations[tail] vec = tloc - hloc vraw = rloc - hloc x = np.dot(vec, vraw)/np.dot(vec,vec) self.locations[key] = hloc + x*vec + np.array(offs) elif typ == 'b': self.locations[key] = self.locations[data] elif typ == 'p': x = self.locations[data[0]] y = self.locations[data[1]] z = self.locations[data[2]] self.locations[key] = np.array((x[0],y[1],z[2])) elif typ == 'vz': v = int(data[0]) z = self.mesh.coord[v][2] loc = self.locations[data[1]] self.locations[key] = np.array((loc[0],loc[1],z)) elif typ == 'X': r = self.locations[data[0]] (x,y,z) = data[1] r1 = np.array([float(x), float(y), float(z)]) self.locations[key] = np.cross(r, r1) elif typ == 'l': ((k1, joint1), (k2, joint2)) = data self.locations[key] = k1*self.locations[joint1] + k2*self.locations[joint2] elif typ == 'o': (joint, offsSym) = data if type(offsSym) == str: offs = self.locations[offsSym] else: offs = np.array(offsSym) self.locations[key] = self.locations[joint] + offs else: raise NameError("Unknown %s" % typ) return
def newSetupJoints (obj, joints): the.Locations = {} for (key, typ, data) in joints: #print(key) if typ == 'j': loc = mh2proxy.calcJointPos(obj, data) the.Locations[key] = loc the.Locations[data] = loc elif typ == 'v': v = int(data) the.Locations[key] = obj.verts[v].co elif typ == 'x': the.Locations[key] = [float(data[0]), float(data[2]), -float(data[1])] elif typ == 'vo': v = int(data[0]) loc = obj.verts[v].co the.Locations[key] = [loc[0]+float(data[1]), loc[1]+float(data[3]), loc[2]-float(data[2])] elif typ == 'vl': ((k1, v1), (k2, v2)) = data loc1 = obj.verts[int(v1)].co loc2 = obj.verts[int(v2)].co the.Locations[key] = vadd(vmul(loc1, k1), vmul(loc2, k2)) elif typ == 'f': (raw, head, tail, offs) = data rloc = the.Locations[raw] hloc = the.Locations[head] tloc = the.Locations[tail] #print(raw, rloc) vec = aljabr.vsub(tloc, hloc) vec2 = aljabr.vdot(vec, vec) vraw = aljabr.vsub(rloc, hloc) x = aljabr.vdot(vec, vraw) / vec2 rvec = aljabr.vmul(vec, x) nloc = aljabr.vadd(hloc, rvec, offs) #print(key, nloc) the.Locations[key] = nloc elif typ == 'b': the.Locations[key] = the.Locations[data] elif typ == 'p': x = the.Locations[data[0]] y = the.Locations[data[1]] z = the.Locations[data[2]] the.Locations[key] = [x[0],y[1],z[2]] elif typ == 'vz': v = int(data[0]) z = obj.verts[v].co[2] loc = the.Locations[data[1]] the.Locations[key] = [loc[0],loc[1],z] elif typ == 'X': r = the.Locations[data[0]] (x,y,z) = data[1] r1 = [float(x), float(y), float(z)] the.Locations[key] = aljabr.vcross(r, r1) elif typ == 'l': ((k1, joint1), (k2, joint2)) = data the.Locations[key] = vadd(vmul(the.Locations[joint1], k1), vmul(the.Locations[joint2], k2)) elif typ == 'o': (joint, offsSym) = data if type(offsSym) == str: offs = the.Locations[offsSym] else: offs = offsSym the.Locations[key] = vadd(the.Locations[joint], offs) else: raise NameError("Unknown %s" % typ) return