Spaces:
No application file
No application file
Delete viz_utils.py
Browse files- viz_utils.py +0 -50
viz_utils.py
DELETED
|
@@ -1,50 +0,0 @@
|
|
| 1 |
-
import numpy as np
|
| 2 |
-
import plotly.graph_objects as go
|
| 3 |
-
|
| 4 |
-
CHAIN = [-1, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 9, 9, 12, 13, 14, 16, 17, 18, 19]
|
| 5 |
-
|
| 6 |
-
JOINT_NAMES = [
|
| 7 |
-
"Hips", "RightUpLeg", "RightLeg", "RightFoot", "LeftUpLeg", "LeftLeg", "LeftFoot",
|
| 8 |
-
"Spine", "Spine1", "Spine2", "Neck", "Head", "RightShoulder", "RightArm", "RightForeArm",
|
| 9 |
-
"RightHand", "LeftShoulder", "LeftArm", "LeftForeArm", "LeftHand", "RightToeBase", "LeftToeBase"
|
| 10 |
-
]
|
| 11 |
-
|
| 12 |
-
def save_bvh_for_blender(xyz_data, filename):
|
| 13 |
-
seq_len, n_joints, _ = xyz_data.shape
|
| 14 |
-
with open(filename, 'w') as f:
|
| 15 |
-
f.write("HIERARCHY\n")
|
| 16 |
-
def write_joint(idx, indent_level):
|
| 17 |
-
indent = "\t" * indent_level
|
| 18 |
-
name = JOINT_NAMES[idx] if idx < len(JOINT_NAMES) else f"Joint_{idx}"
|
| 19 |
-
if idx == 0: f.write(f"{indent}ROOT {name}\n")
|
| 20 |
-
else: f.write(f"{indent}JOINT {name}\n")
|
| 21 |
-
f.write(f"{indent}{{\n")
|
| 22 |
-
f.write(f"{indent}\tOFFSET 0.00 0.00 0.00\n")
|
| 23 |
-
f.write(f"{indent}\tCHANNELS 3 Xposition Yposition Zposition\n")
|
| 24 |
-
children = [i for i, p in enumerate(CHAIN) if p == idx]
|
| 25 |
-
if len(children) > 0:
|
| 26 |
-
for child in children: write_joint(child, indent_level + 1)
|
| 27 |
-
else:
|
| 28 |
-
f.write(f"{indent}\tEnd Site\n{indent}\t{{\n{indent}\t\tOFFSET 0.00 0.00 0.00\n{indent}\t}}\n")
|
| 29 |
-
f.write(f"{indent}}}\n")
|
| 30 |
-
write_joint(0, 0)
|
| 31 |
-
f.write(f"MOTION\nFrames: {seq_len}\nFrame Time: 0.050000\n")
|
| 32 |
-
for i in range(seq_len):
|
| 33 |
-
row = xyz_data[i].flatten()
|
| 34 |
-
f.write(" ".join([f"{val:.6f}" for val in row]) + "\n")
|
| 35 |
-
return filename
|
| 36 |
-
|
| 37 |
-
def plot_skeleton(xyz_data):
|
| 38 |
-
xyz = xyz_data[::4]
|
| 39 |
-
xyz = xyz - xyz[0:1, 0:1, :]
|
| 40 |
-
frames = []
|
| 41 |
-
for k in range(len(xyz)):
|
| 42 |
-
x_p, y_p, z_p = [], [], []
|
| 43 |
-
for child, parent in enumerate(CHAIN):
|
| 44 |
-
if parent == -1 or child >= xyz.shape[1]: continue
|
| 45 |
-
x_p.extend([xyz[k, parent, 0], xyz[k, child, 0], None])
|
| 46 |
-
y_p.extend([xyz[k, parent, 2], xyz[k, child, 2], None])
|
| 47 |
-
z_p.extend([xyz[k, parent, 1], xyz[k, child, 1], None])
|
| 48 |
-
frames.append(go.Frame(data=[go.Scatter3d(x=x_p, y=y_p, z=z_p, mode='lines+markers', marker=dict(size=4, color='red'), line=dict(color='blue', width=4))]))
|
| 49 |
-
fig = go.Figure(data=frames[0].data, layout=go.Layout(title="Motion Preview", scene=dict(xaxis=dict(range=[-2, 2], autorange=False), yaxis=dict(range=[-2, 2], autorange=False), zaxis=dict(range=[-0, 2], autorange=False), aspectmode='cube'), updatemenus=[dict(type="buttons", buttons=[dict(label="Play", method="animate", args=[None])])]), frames=frames)
|
| 50 |
-
return fig
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|