Merge pull request #2496 from jjyyxx:patch-1

PiperOrigin-RevId: 736457846
Change-Id: I3b4b1554dd15e9ca73abee5c31d4758f694f5b44
This commit is contained in:
Copybara-Service
2025-03-13 04:33:45 -07:00
3 changed files with 39 additions and 5 deletions
+23 -1
View File
@@ -1415,7 +1415,29 @@ PYBIND11_MODULE(_structs, m) {
mjVisual.def("__deepcopy__", [](const MjVisualWrapper& other, py::dict) {
return MjVisualWrapper(other);
});
DefineStructFunctions(mjVisual);
mjVisual.def("__eq__", StructsEqual<MjVisualWrapper>);
// Special __repr__ implementation for MjVisual, since:
// 1. Types under MjVisual confuse StructRepr;
// 2. StructRepr does not handle the indentation of nested structs well.
mjVisual.def("__repr__", [](py::object self) {
std::ostringstream result;
result << "<"
<< self.attr("__class__").attr("__name__").cast<std::string_view>();
#define X(type, var) \
result << "\n " #var ": "; \
StructReprImpl<type>(self.attr(#var), result, 2);
X(raw::MjVisualGlobal, global_)
X(raw::MjVisualQuality, quality)
X(MjVisualHeadlightWrapper, headlight)
X(raw::MjVisualMap, map)
X(raw::MjVisualScale, scale)
X(MjVisualRgbaWrapper, rgba)
#undef X
result << "\n>";
return result.str();
});
py::class_<raw::MjVisualGlobal> mjVisualGlobal(mjVisual, "Global");
mjVisualGlobal.def("__copy__", [](const raw::MjVisualGlobal& other) {