Version 2.1.2: Python bindings, OBJ assets support, bugfixes.
PiperOrigin-RevId: 434731612 Change-Id: I0cfda3e7a3d1c72036764986efc252ffa1b8c6b0
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
// Copyright 2022 DeepMind Technologies Limited
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include <vector>
|
||||
#include <mjmodel.h>
|
||||
#include <mjvisualize.h>
|
||||
#include <mujoco.h>
|
||||
#include <pybind11/cast.h>
|
||||
#include <pybind11/pybind11.h>
|
||||
#include <pybind11/stl.h>
|
||||
|
||||
namespace mujoco::python {
|
||||
namespace {
|
||||
|
||||
namespace py = ::pybind11;
|
||||
|
||||
template <auto N>
|
||||
py::tuple MakeTuple(
|
||||
const char* (&strings)[N]) {
|
||||
py::list result;
|
||||
for (int i = 0; i < N; i++) {
|
||||
result.append(py::str(strings[i]));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
template <auto N>
|
||||
py::tuple MakeTuple(const char* (&strings)[N][3]) {
|
||||
py::list result;
|
||||
for (int i = 0; i < N; i++) {
|
||||
result.append(py::make_tuple(
|
||||
py::str(strings[i][0]),
|
||||
py::str(strings[i][1]),
|
||||
py::str(strings[i][2])));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
PYBIND11_MODULE(_constants, pymodule) {
|
||||
#define X(var) pymodule.attr(#var) = var
|
||||
|
||||
// from mjmodel.h
|
||||
X(mjPI);
|
||||
X(mjMAXVAL);
|
||||
X(mjMINMU);
|
||||
X(mjMINIMP);
|
||||
X(mjMAXIMP);
|
||||
X(mjMAXCONPAIR);
|
||||
X(mjMAXVFS);
|
||||
X(mjMAXVFSNAME);
|
||||
X(mjNEQDATA);
|
||||
X(mjNDYN);
|
||||
X(mjNGAIN);
|
||||
X(mjNBIAS);
|
||||
X(mjNREF);
|
||||
X(mjNIMP);
|
||||
X(mjNSOLVER);
|
||||
|
||||
// from mjvisualize.h
|
||||
X(mjNGROUP);
|
||||
X(mjMAXLIGHT);
|
||||
X(mjMAXOVERLAY);
|
||||
X(mjMAXLINE);
|
||||
X(mjMAXLINEPNT);
|
||||
X(mjMAXPLANEGRID);
|
||||
|
||||
// from mujoco.h
|
||||
X(mjVERSION_HEADER);
|
||||
|
||||
#undef X
|
||||
pymodule.attr("mjDISABLESTRING") = MakeTuple(mjDISABLESTRING);
|
||||
pymodule.attr("mjENABLESTRING") = MakeTuple(mjENABLESTRING);
|
||||
pymodule.attr("mjTIMERSTRING") = MakeTuple(mjTIMERSTRING);
|
||||
pymodule.attr("mjLABELSTRING") = MakeTuple(mjLABELSTRING);
|
||||
pymodule.attr("mjFRAMESTRING") = MakeTuple(mjFRAMESTRING);
|
||||
pymodule.attr("mjVISSTRING") = MakeTuple(mjVISSTRING);
|
||||
pymodule.attr("mjRNDSTRING") = MakeTuple(mjRNDSTRING);
|
||||
}
|
||||
} // namespace
|
||||
} // namespace mujoco::python
|
||||
Reference in New Issue
Block a user