Add the override_assets attribute to MjSpec.

When specified, child asset with repeated names will override parent's, rather than throw an error. Default behavior is to override.

PiperOrigin-RevId: 717979621
Change-Id: I18022dc266619b4ba1a8636d1c60f85b0eb5f862
This commit is contained in:
Alessio Quaglino
2025-01-21 10:38:14 -08:00
committed by Copybara-Service
parent 1412a29dac
commit 6a7a7a5f80
2 changed files with 16 additions and 4 deletions
+2 -3
View File
@@ -1039,7 +1039,7 @@ class SpecsTest(absltest.TestCase):
# Attach another spec to frame (referenced by name) and compile again.
child3 = mujoco.MjSpec()
child3.assets = {'cube3.obj': 'cube3_content'}
child3.assets = {'cube2.obj': 'new_cube2_content'}
body3 = child3.worldbody.add_body(name='body')
self.assertIsNotNone(parent.attach(child3, frame='frame', prefix='child3-'))
body3.pos = [-2, -2, -2]
@@ -1053,8 +1053,7 @@ class SpecsTest(absltest.TestCase):
np.testing.assert_array_equal(model3.body_quat[2], [0, 0, 0, 1])
np.testing.assert_array_equal(model3.body_quat[3], [0, 0, 0, 1])
self.assertEqual(parent.assets['cube.obj'], 'cube_content')
self.assertEqual(parent.assets['cube2.obj'], 'cube2_content')
self.assertEqual(parent.assets['cube3.obj'], 'cube3_content')
self.assertEqual(parent.assets['cube2.obj'], 'new_cube2_content')
# Fail to attach to a frame that does not exist.
child4 = mujoco.MjSpec()