Spaces:
Running on Zero
Running on Zero
update to glb export in client
Browse files
app.py
CHANGED
|
@@ -23,8 +23,13 @@ import pandas as pd
|
|
| 23 |
import plotly.graph_objs as go
|
| 24 |
import spaces
|
| 25 |
from embed4d import model3d_viewer
|
|
|
|
| 26 |
from myo_tools.mjs.marker.marker_api import get_marker_names
|
| 27 |
-
from myo_tools.utils.file_ops.dataframe_utils import
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
from myo_tools.utils.file_ops.io_utils import from_qpos_to_joint_angles
|
| 29 |
from myo_tools.utils.mocap_ops.mocap_utils import rotate_mocap_ydown_to_zup
|
| 30 |
from myosdk import Client
|
|
@@ -216,7 +221,6 @@ def run_retargeting_c3d(api_key, c3d_files, markerset_file):
|
|
| 216 |
result = client.create_retarget_job(
|
| 217 |
tracker=f,
|
| 218 |
markerset=markerset_path,
|
| 219 |
-
export_glb=True,
|
| 220 |
stream_status=True, # Stream status updates automatically
|
| 221 |
)
|
| 222 |
|
|
@@ -238,16 +242,20 @@ def run_retargeting_c3d(api_key, c3d_files, markerset_file):
|
|
| 238 |
# Download qpos file
|
| 239 |
result.download_qpos(out_path)
|
| 240 |
output_files.append(out_path)
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 251 |
|
| 252 |
assert os.path.exists(
|
| 253 |
output_files[0]
|
|
@@ -443,7 +451,9 @@ def run_retargeting_video(
|
|
| 443 |
f"🔹 MyoSDK client initialized in { time.time() - init_time:.2f} seconds"
|
| 444 |
)
|
| 445 |
|
| 446 |
-
markerset_file_name =
|
|
|
|
|
|
|
| 447 |
marker_names = get_marker_names(markerset_file_name)
|
| 448 |
|
| 449 |
from_array_to_dataframe(
|
|
@@ -470,7 +480,6 @@ def run_retargeting_video(
|
|
| 470 |
result = client.create_retarget_job(
|
| 471 |
tracker=fn_parquet,
|
| 472 |
markerset=markerset_file_name,
|
| 473 |
-
export_glb=True,
|
| 474 |
stream_status=True, # Stream status updates automatically
|
| 475 |
)
|
| 476 |
|
|
@@ -497,14 +506,18 @@ def run_retargeting_video(
|
|
| 497 |
out_path
|
| 498 |
), f"Failed to download retargeted data for {os.path.basename(video_path)}"
|
| 499 |
|
| 500 |
-
|
| 501 |
-
glb_path =
|
| 502 |
-
|
| 503 |
-
|
| 504 |
-
|
| 505 |
-
|
| 506 |
-
|
| 507 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 508 |
# Load angles from first output file
|
| 509 |
status.append("🔹 Loading animation and angle data...")
|
| 510 |
yield "\n".join(status), None, None, gr.update(visible=False), gr.update(
|
|
@@ -805,4 +818,4 @@ if __name__ == "__main__":
|
|
| 805 |
app.launch(
|
| 806 |
share=True,
|
| 807 |
# server_port=7860,
|
| 808 |
-
)
|
|
|
|
| 23 |
import plotly.graph_objs as go
|
| 24 |
import spaces
|
| 25 |
from embed4d import model3d_viewer
|
| 26 |
+
from myo_tools.mj.core.mj_api import get_model
|
| 27 |
from myo_tools.mjs.marker.marker_api import get_marker_names
|
| 28 |
+
from myo_tools.utils.file_ops.dataframe_utils import (
|
| 29 |
+
from_array_to_dataframe,
|
| 30 |
+
from_dataframe_to_array,
|
| 31 |
+
)
|
| 32 |
+
from myo_tools.utils.file_ops.gltf_utils import MujocoGLTFExporter
|
| 33 |
from myo_tools.utils.file_ops.io_utils import from_qpos_to_joint_angles
|
| 34 |
from myo_tools.utils.mocap_ops.mocap_utils import rotate_mocap_ydown_to_zup
|
| 35 |
from myosdk import Client
|
|
|
|
| 221 |
result = client.create_retarget_job(
|
| 222 |
tracker=f,
|
| 223 |
markerset=markerset_path,
|
|
|
|
| 224 |
stream_status=True, # Stream status updates automatically
|
| 225 |
)
|
| 226 |
|
|
|
|
| 242 |
# Download qpos file
|
| 243 |
result.download_qpos(out_path)
|
| 244 |
output_files.append(out_path)
|
| 245 |
+
mjb_path = out_path.replace(".parquet", ".mjb")
|
| 246 |
+
glb_path = out_path.replace(".parquet", ".glb")
|
| 247 |
+
result.download_model(mjb_path)
|
| 248 |
+
|
| 249 |
+
mj_model = get_model(mjb_path)[0]
|
| 250 |
+
[sim_time, qpos, _] = from_dataframe_to_array(out_path)
|
| 251 |
+
exporter = MujocoGLTFExporter(mj_model)
|
| 252 |
+
exporter.export_glb(
|
| 253 |
+
glb_path,
|
| 254 |
+
[{"qpos": qpos[t, :]} for t in range(qpos.shape[0])],
|
| 255 |
+
1 / (sim_time[1] - sim_time[0]),
|
| 256 |
+
)
|
| 257 |
+
output_glb_files.append(glb_path)
|
| 258 |
+
print(f"Exported GLB file to {glb_path}")
|
| 259 |
|
| 260 |
assert os.path.exists(
|
| 261 |
output_files[0]
|
|
|
|
| 451 |
f"🔹 MyoSDK client initialized in { time.time() - init_time:.2f} seconds"
|
| 452 |
)
|
| 453 |
|
| 454 |
+
markerset_file_name = (
|
| 455 |
+
os.path.dirname(__file__) + "/./markersets/movi_metrabs_markerset.xml"
|
| 456 |
+
)
|
| 457 |
marker_names = get_marker_names(markerset_file_name)
|
| 458 |
|
| 459 |
from_array_to_dataframe(
|
|
|
|
| 480 |
result = client.create_retarget_job(
|
| 481 |
tracker=fn_parquet,
|
| 482 |
markerset=markerset_file_name,
|
|
|
|
| 483 |
stream_status=True, # Stream status updates automatically
|
| 484 |
)
|
| 485 |
|
|
|
|
| 506 |
out_path
|
| 507 |
), f"Failed to download retargeted data for {os.path.basename(video_path)}"
|
| 508 |
|
| 509 |
+
mjb_path = out_path.replace(".parquet", ".mjb")
|
| 510 |
+
glb_path = out_path.replace(".parquet", ".glb")
|
| 511 |
+
result.download_model(mjb_path)
|
| 512 |
+
|
| 513 |
+
mj_model = get_model(mjb_path)[0]
|
| 514 |
+
[sim_time, qpos, _] = from_dataframe_to_array(out_path)
|
| 515 |
+
exporter = MujocoGLTFExporter(mj_model)
|
| 516 |
+
exporter.export_glb(
|
| 517 |
+
glb_path,
|
| 518 |
+
[{"qpos": qpos[t, :]} for t in range(qpos.shape[0])],
|
| 519 |
+
1 / (sim_time[1] - sim_time[0]),
|
| 520 |
+
)
|
| 521 |
# Load angles from first output file
|
| 522 |
status.append("🔹 Loading animation and angle data...")
|
| 523 |
yield "\n".join(status), None, None, gr.update(visible=False), gr.update(
|
|
|
|
| 818 |
app.launch(
|
| 819 |
share=True,
|
| 820 |
# server_port=7860,
|
| 821 |
+
)
|