Skip to content
0.2.0-dev Download ZIP
45 lines ·1.3 KB Raw
1import sys
2
3import numpy as np
4
5from motionbricks.io.usd import load_skeleton_from_usd
6from motionbricks.io.utils import SOMA_SKELETON_PRIM_PATH, get_asset_file
7
8skeleton = load_skeleton_from_usd(get_asset_file("human", "soma_base_skel_minimal_no_root.usd"), SOMA_SKELETON_PRIM_PATH)
9names = list(skeleton.joint_names)
10parents = skeleton.parent_indices.numpy().astype(int).tolist()
11reference = skeleton.reference_local_transforms.numpy().astype(np.float32)
12
13
14def 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
21lines = [
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]
43with open(sys.argv[1], "w", newline="\n") as out:
44 out.write("\n".join(lines))
45print(f"{len(names)} joints written to {sys.argv[1]}")