DragMesh-3-Scene / scenesmith_full /patch_mujoco_export.py
Neptune-T's picture
Add files using upload-large-folder tool
54d168a verified
Raw History Blame Contribute Delete
1.24 kB
"""Fix mujoco API compatibility in export script."""
from pathlib import Path
path = Path("/home/zhanghao/scene/scenesmith_full/scripts/export_scene_to_mujoco.py")
text = path.read_text()
# Fix joint.axis assignment
old_axis = """ joint.axis = axis_values"""
new_axis = """ joint.axis = np.array(axis_values, dtype=np.float64).reshape(3, 1)"""
if old_axis in text:
text = text.replace(old_axis, new_axis)
print("Patched joint.axis")
else:
print("axis pattern not found")
# Fix joint.pos assignment
old_pos = """ if joint_pos is not None:
joint.pos = joint_pos"""
new_pos = """ if joint_pos is not None:
joint.pos = np.array(joint_pos, dtype=np.float64).reshape(3, 1)"""
if old_pos in text:
text = text.replace(old_pos, new_pos)
print("Patched joint.pos")
else:
print("pos pattern not found")
# Fix joint.range (list -> np array)
old_range = """ joint.range = [lower, upper]"""
new_range = """ joint.range = np.array([lower, upper], dtype=np.float64)"""
if old_range in text:
text = text.replace(old_range, new_range)
print("Patched joint.range")
else:
print("range pattern not found")
path.write_text(text)
print("Done")