Add mjs_bodyToFrame() to convert a body to a frame.
Also add test for attaching the world body. PiperOrigin-RevId: 685603933 Change-Id: I3cfe7d226d6f032b5a587e44d0f4f18207977188
This commit is contained in:
committed by
Copybara-Service
parent
52a0149cd1
commit
766cd20273
@@ -573,6 +573,17 @@ PYBIND11_MODULE(_specs, m) {
|
||||
return new_frame;
|
||||
},
|
||||
py::return_value_policy::reference_internal);
|
||||
mjsBody.def(
|
||||
"to_frame",
|
||||
[](raw::MjsBody* self) -> raw::MjsFrame* {
|
||||
raw::MjsFrame* frame = mjs_bodyToFrame(&self);
|
||||
if (!frame) {
|
||||
throw pybind11::value_error(mjs_getError(mjs_getSpec(self->element)));
|
||||
}
|
||||
// TODO: set the body to py::none
|
||||
return frame;
|
||||
},
|
||||
py::return_value_policy::reference_internal);
|
||||
|
||||
// ============================= MJSFRAME ====================================
|
||||
mjsFrame.def_property_readonly(
|
||||
|
||||
@@ -866,6 +866,13 @@ class SpecsTest(absltest.TestCase):
|
||||
model = parent.compile()
|
||||
np.testing.assert_array_equal(model.body_pos[1], [1, 2, 3])
|
||||
|
||||
def test_body_to_frame(self):
|
||||
spec = mujoco.MjSpec()
|
||||
body = spec.worldbody.add_body(pos=[1, 2, 3])
|
||||
spec.compile()
|
||||
frame = body.to_frame()
|
||||
np.testing.assert_array_equal(frame.pos, [1, 2, 3])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
absltest.main()
|
||||
|
||||
Reference in New Issue
Block a user