in fairmotion/data/bvh.py [0:0]
def _write_hierarchy(motion, file, joint, scale=1.0, rot_order="XYZ", tab=""):
def rot_order_to_str(order):
if order == "xyz" or order == "XYZ":
return "Xrotation Yrotation Zrotation"
elif order == "zyx" or order == "ZYX":
return "Zrotation Yrotation Xrotation"
else:
raise NotImplementedError
joint_order = [joint.name]
is_root_joint = joint.parent_joint is None
if is_root_joint:
file.write(tab + "ROOT %s\n" % joint.name)
else:
file.write(tab + "JOINT %s\n" % joint.name)
file.write(tab + "{\n")
R, p = conversions.T2Rp(joint.xform_from_parent_joint)
p *= scale
file.write(tab + "\tOFFSET %f %f %f\n" % (p[0], p[1], p[2]))
if is_root_joint:
file.write(
tab
+ "\tCHANNELS 6 Xposition Yposition Zposition %s\n"
% rot_order_to_str(rot_order)
)
else:
file.write(tab + "\tCHANNELS 3 %s\n" % rot_order_to_str(rot_order))
for child_joint in joint.child_joints:
child_joint_order = _write_hierarchy(
motion, file, child_joint, scale, rot_order, tab + "\t"
)
joint_order.extend(child_joint_order)
if len(joint.child_joints) == 0:
file.write(tab + "\tEnd Site\n")
file.write(tab + "\t{\n")
file.write(tab + "\t\tOFFSET %f %f %f\n" % (0.0, 0.0, 0.0))
file.write(tab + "\t}\n")
file.write(tab + "}\n")
return joint_order