Enable procedural plugin activation in Python bindings.
PiperOrigin-RevId: 746055614 Change-Id: Idcc2f62fdfeccdca356e3d1acadf168b46a98881
This commit is contained in:
committed by
Copybara-Service
parent
b1f8d444f2
commit
a209134315
@@ -84,6 +84,7 @@ def _value_binding_code(
|
|||||||
fulltype = fulltype.replace('mjOption', 'raw::MjOption')
|
fulltype = fulltype.replace('mjOption', 'raw::MjOption')
|
||||||
fulltype = fulltype.replace('mjVisual', 'raw::MjVisual')
|
fulltype = fulltype.replace('mjVisual', 'raw::MjVisual')
|
||||||
fulltype = fulltype.replace('mjStatistic', 'raw::MjStatistic')
|
fulltype = fulltype.replace('mjStatistic', 'raw::MjStatistic')
|
||||||
|
element = '.element' if fullvarname == 'plugin' else ''
|
||||||
|
|
||||||
def_property_args = (
|
def_property_args = (
|
||||||
f'"{varname}"',
|
f'"{varname}"',
|
||||||
@@ -91,7 +92,7 @@ def _value_binding_code(
|
|||||||
return self.{fullvarname};
|
return self.{fullvarname};
|
||||||
}}""",
|
}}""",
|
||||||
f"""[]({rawclassname}& self, {fulltype} {varname}) {{
|
f"""[]({rawclassname}& self, {fulltype} {varname}) {{
|
||||||
self.{fullvarname} = {varname};
|
self.{fullvarname}{element} = {varname}{element};
|
||||||
}}""",
|
}}""",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -483,6 +483,13 @@ PYBIND11_MODULE(_specs, m) {
|
|||||||
py::arg("suffix") = py::none(), py::arg("site") = py::none(),
|
py::arg("suffix") = py::none(), py::arg("site") = py::none(),
|
||||||
py::arg("frame") = py::none(),
|
py::arg("frame") = py::none(),
|
||||||
py::return_value_policy::reference_internal);
|
py::return_value_policy::reference_internal);
|
||||||
|
mjSpec.def(
|
||||||
|
"activate_plugin",
|
||||||
|
[](MjSpec& self, std::string& name) {
|
||||||
|
mjs_activatePlugin(self.ptr, name.c_str());
|
||||||
|
},
|
||||||
|
py::arg("name"),
|
||||||
|
py::return_value_policy::reference_internal);
|
||||||
|
|
||||||
// ============================= MJSBODY =====================================
|
// ============================= MJSBODY =====================================
|
||||||
mjsBody.def(
|
mjsBody.def(
|
||||||
|
|||||||
@@ -835,22 +835,19 @@ class SpecsTest(absltest.TestCase):
|
|||||||
self.assertEqual(model.nsensor, 9)
|
self.assertEqual(model.nsensor, 9)
|
||||||
|
|
||||||
def test_plugin(self):
|
def test_plugin(self):
|
||||||
xml = """
|
spec = mujoco.MjSpec()
|
||||||
<mujoco>
|
spec.activate_plugin('mujoco.elasticity.cable')
|
||||||
<extension>
|
plugin = spec.add_plugin(
|
||||||
<plugin plugin="mujoco.elasticity.cable"/>
|
name='instance_name',
|
||||||
</extension>
|
plugin_name='mujoco.elasticity.cable',
|
||||||
</mujoco>
|
active=True,
|
||||||
"""
|
info='info',
|
||||||
|
)
|
||||||
spec = mujoco.MjSpec.from_string(xml)
|
|
||||||
self.assertIsNotNone(spec.worldbody)
|
|
||||||
|
|
||||||
body = spec.worldbody.add_body()
|
body = spec.worldbody.add_body()
|
||||||
|
body.plugin = plugin
|
||||||
body.plugin.plugin_name = 'mujoco.elasticity.cable'
|
body.plugin.plugin_name = 'mujoco.elasticity.cable'
|
||||||
body.plugin.id = spec.add_plugin()
|
|
||||||
body.plugin.active = True
|
body.plugin.active = True
|
||||||
self.assertEqual(body.plugin.id, 0)
|
|
||||||
|
|
||||||
geom = body.add_geom()
|
geom = body.add_geom()
|
||||||
geom.type = mujoco.mjtGeom.mjGEOM_BOX
|
geom.type = mujoco.mjtGeom.mjGEOM_BOX
|
||||||
|
|||||||
Reference in New Issue
Block a user