diff --git a/python/mujoco/mjdata_meta.h b/python/mujoco/mjdata_meta.h index c432c4df..bebc891a 100644 --- a/python/mujoco/mjdata_meta.h +++ b/python/mujoco/mjdata_meta.h @@ -15,6 +15,9 @@ #ifndef MUJOCO_PYTHON_MJDATA_META_H_ #define MUJOCO_PYTHON_MJDATA_META_H_ +#include +#include + #include #include #include "raw.h" @@ -67,6 +70,23 @@ template class MjWrapper; struct MjDataMetadata { public: friend class _impl::MjWrapper; + explicit MjDataMetadata(const raw::MjModel* m) + : +#define X(var) var(m->var), + MJMODEL_INTS +#undef X + +#define X(dtype, var, n) \ + var([](dtype* src, int len) { \ + dtype* dst = new dtype[len]; \ + std::memcpy(dst, src, len * sizeof(dtype)); \ + return dst; \ + }(m->var, m->n)), + + MJDATA_METADATA +#undef X + is_dual(mj_isDual(m)) { + } #define X(var) int var; MJMODEL_INTS @@ -81,23 +101,6 @@ struct MjDataMetadata { MjDataMetadata() = default; MjDataMetadata(const MjDataMetadata& other) = default; MjDataMetadata(MjDataMetadata&& other) = default; - explicit MjDataMetadata(const raw::MjModel* m) - : -#define X(var) var(m->var), - MJMODEL_INTS -#undef X - -#define X(dtype, var, n) \ - var( \ - [](dtype* src, int len) { \ - dtype* dst = new dtype[len]; \ - std::memcpy(dst, src, len * sizeof(dtype)); \ - return dst; \ - }(m->var, m->n)), - - MJDATA_METADATA -#undef X - is_dual(mj_isDual(m)) {} }; } // namespace mujoco::python diff --git a/python/mujoco/structs.cc b/python/mujoco/structs.cc index 04e18bbf..73612b57 100644 --- a/python/mujoco/structs.cc +++ b/python/mujoco/structs.cc @@ -39,6 +39,7 @@ #include "errors.h" #include "function_traits.h" #include "indexers.h" +#include "mjdata_meta.h" #include "raw.h" #include "serialization.h" #include diff --git a/python/mujoco/structs.h b/python/mujoco/structs.h index 93f1df9f..8d282619 100644 --- a/python/mujoco/structs.h +++ b/python/mujoco/structs.h @@ -477,7 +477,7 @@ class MjWrapper : public WrapperBase { pybind11::bytes text_data_bytes; pybind11::bytes names_bytes; - private: + protected: explicit MjWrapper(raw::MjModel* ptr); MjModelIndexer indexer_; @@ -584,7 +584,7 @@ class MjWrapper: public WrapperBase { py_array_or_tuple_t solver_fwdinv; py_array_or_tuple_t energy; - private: + protected: // Internal constructor which takes ownership of given mjData pointer. // Used for deserialization. explicit MjWrapper(MjDataMetadata&& metadata, raw::MjData* d);