def getJoint(joint, obj, locations): try: loc = locations[joint] except: loc = mhxbones.calcJointPos(obj, joint) locations[joint] = loc return loc
def setupRigJoint (words, obj, verts, locations): key = words[0] typ = words[1] if typ == 'joint': loc = mhxbones.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 = eval(words[5]) 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)