0.2.0-dev Download ZIP
45 lines ·1.3 KB Raw
| 1 | import sys |
| 2 | |
| 3 | import numpy as np |
| 4 | |
| 5 | from motionbricks.io.usd import load_skeleton_from_usd |
| 6 | from motionbricks.io.utils import SOMA_SKELETON_PRIM_PATH, get_asset_file |
| 7 | |
| 8 | skeleton = load_skeleton_from_usd(get_asset_file("human", "soma_base_skel_minimal_no_root.usd"), SOMA_SKELETON_PRIM_PATH) |
| 9 | names = list(skeleton.joint_names) |
| 10 | parents = skeleton.parent_indices.numpy().astype(int).tolist() |
| 11 | reference = skeleton.reference_local_transforms.numpy().astype(np.float32) |
| 12 | |
| 13 | |
| 14 | def number(value): |
| 15 | value = np.float32(value) |
| 16 | if value == 0: |
| 17 | return "-0f" if np.signbit(value) else "0f" |
| 18 | return f"{str(value)}f" |
| 19 | |
| 20 | |
| 21 | lines = [ |
| 22 | "namespace EvilEngine.GenerativeMotion;", |
| 23 | "", |
| 24 | "public static partial class SomaSkeleton", |
| 25 | "{", |
| 26 | " private static readonly string[] JointNames =", |
| 27 | " [", |
| 28 | *[f' "{name}",' for name in names], |
| 29 | " ];", |
| 30 | "", |
| 31 | " private static readonly int[] JointParents =", |
| 32 | " [", |
| 33 | *[f" {parent}," for parent in parents], |
| 34 | " ];", |
| 35 | "", |
| 36 | " private static readonly float[] ReferenceValues =", |
| 37 | " [", |
| 38 | *[" " + ", ".join(number(v) for v in row) + "," for row in reference], |
| 39 | " ];", |
| 40 | "}", |
| 41 | "", |
| 42 | ] |
| 43 | with open(sys.argv[1], "w", newline="\n") as out: |
| 44 | out.write("\n".join(lines)) |
| 45 | print(f"{len(names)} joints written to {sys.argv[1]}") |