Change site.attach to accept a spec instead of a body.
Add site.attach_body for attaching a body to a site. PiperOrigin-RevId: 703047770 Change-Id: Ibc1f916f8741872135220461cda7cebc4b418913
This commit is contained in:
committed by
Copybara-Service
parent
10239a673b
commit
503e5e1815
+23
-1
@@ -746,7 +746,7 @@ PYBIND11_MODULE(_specs, m) {
|
||||
},
|
||||
py::return_value_policy::reference_internal);
|
||||
mjsSite.def(
|
||||
"attach",
|
||||
"attach_body",
|
||||
[](raw::MjsSite& self, raw::MjsBody& body,
|
||||
std::optional<std::string>& prefix,
|
||||
std::optional<std::string>& suffix) -> raw::MjsBody* {
|
||||
@@ -762,6 +762,28 @@ PYBIND11_MODULE(_specs, m) {
|
||||
py::arg("body"), py::arg("prefix") = py::none(),
|
||||
py::arg("suffix") = py::none(),
|
||||
py::return_value_policy::reference_internal);
|
||||
mjsSite.def(
|
||||
"attach",
|
||||
[](raw::MjsSite& self, MjSpec& spec,
|
||||
std::optional<std::string>& prefix,
|
||||
std::optional<std::string>& suffix) -> raw::MjsFrame* {
|
||||
auto world = mjs_findBody(spec.ptr, "world");
|
||||
if (!world) {
|
||||
throw pybind11::value_error(
|
||||
mjs_getError(mjs_getSpec(self.element)));
|
||||
}
|
||||
const char* p = prefix.has_value() ? prefix.value().c_str() : "";
|
||||
const char* s = suffix.has_value() ? suffix.value().c_str() : "";
|
||||
auto attached_world = mjs_attachToSite(&self, world, p, s);
|
||||
if (!attached_world) {
|
||||
throw pybind11::value_error(
|
||||
mjs_getError(mjs_getSpec(self.element)));
|
||||
}
|
||||
return mjs_bodyToFrame(&attached_world);
|
||||
},
|
||||
py::arg("body"), py::arg("prefix") = py::none(),
|
||||
py::arg("suffix") = py::none(),
|
||||
py::return_value_policy::reference_internal);
|
||||
|
||||
// ============================= MJSCAMERA ===================================
|
||||
mjsCamera.def("delete",
|
||||
|
||||
Reference in New Issue
Block a user