def loadMhpFile(rig, scn, filepath):
unit = Matrix()
for pb in rig.pose.bones:
pb.matrix_basis = unit
(pname, ext) = os.path.splitext(filepath)
mhppath = pname + ".mhp"
fp = open(mhppath, "rU")
for line in fp:
words = line.split()
if len(words) < 4:
continue
try:
pb = rig.pose.bones[words[0]]
except KeyError:
print("Warning: Did not find bone %s" % words[0])
continue
if isMuscleBone(pb):
pass
elif words[1] == "quat":
q = Quaternion((float(words[2]), float(words[3]), float(words[4]), float(words[5])))
mat = q.to_matrix().to_4x4()
pb.matrix_basis = mat
elif words[1] == "gquat":
q = Quaternion((float(words[2]), float(words[3]), float(words[4]), float(words[5])))
mat = q.to_matrix().to_4x4()
maty = mat[1].copy()
matz = mat[2].copy()
mat[1] = -matz
mat[2] = maty
pb.matrix_basis = pb.bone.matrix_local.inverted() * mat
elif words[1] == "matrix":
rows = []
n = 2
for i in range(4):
rows.append((float(words[n]), float(words[n+1]), float(words[n+2]), float(words[n+3])))
n += 4
mat = Matrix(rows)
if pb.parent:
pb.matrix_basis = mat
else:
maty = mat[1].copy()
matz = mat[2].copy()
mat[1] = -matz
mat[2] = maty
pb.matrix_basis = pb.bone.matrix_local.inverted() * mat
elif words[1] == "scale":
pass
else:
print("WARNING: Unknown line in mcp file:\n%s" % line)
fp.close()
print("Mhp file %s loaded" % mhppath)
评论列表
文章目录