File size: 1,236 Bytes
54d168a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | """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")
|