Add mjv_camera2GLCamera to mujoco.h.
PiperOrigin-RevId: 956698065 Change-Id: I36856d7142bb5e798c5a90c19609288ddd7c4aac
This commit is contained in:
committed by
Copybara-Service
parent
a3425c72a7
commit
8b78378868
@@ -2623,6 +2623,15 @@ Set perturb force,torque in d->xfrc_applied, if selected body is dynamic.
|
||||
|
||||
Return the average of two OpenGL cameras.
|
||||
|
||||
.. _mjv_camera2GLCamera:
|
||||
|
||||
`mjv_camera2GLCamera <#mjv_camera2GLCamera>`__
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
.. mujoco-include:: mjv_camera2GLCamera
|
||||
|
||||
Converts a mjvCamera to a mjvGLCamera.
|
||||
|
||||
.. _mjv_select:
|
||||
|
||||
`mjv_select <#mjv_select>`__
|
||||
|
||||
@@ -3696,6 +3696,8 @@ void mjv_applyPerturbPose(const mjModel* m, mjData* d, const mjvPerturb* pert,
|
||||
int flg_paused);
|
||||
void mjv_applyPerturbForce(const mjModel* m, mjData* d, const mjvPerturb* pert);
|
||||
mjvGLCamera mjv_averageCamera(const mjvGLCamera* cam1, const mjvGLCamera* cam2);
|
||||
mjvGLCamera mjv_camera2GLCamera(const mjModel* model, const mjData* data,
|
||||
const mjvCamera* mjv_camera);
|
||||
int mjv_select(const mjModel* m, const mjData* d, const mjvOption* vopt,
|
||||
mjtNum aspectratio, mjtNum relx, mjtNum rely,
|
||||
const mjvScene* scn, mjtNum selpnt[3],
|
||||
|
||||
@@ -788,6 +788,10 @@ MJAPI void mjv_applyPerturbForce(const mjModel* m, mjData* d, const mjvPerturb*
|
||||
// Return the average of two OpenGL cameras.
|
||||
MJAPI mjvGLCamera mjv_averageCamera(const mjvGLCamera* cam1, const mjvGLCamera* cam2);
|
||||
|
||||
// Converts a mjvCamera to a mjvGLCamera.
|
||||
MJAPI mjvGLCamera mjv_camera2GLCamera(const mjModel* model, const mjData* data,
|
||||
const mjvCamera* mjv_camera);
|
||||
|
||||
// Select geom, flex or skin with mouse; return bodyid; -1: none selected.
|
||||
// Nullable: geomid, flexid, skinid
|
||||
MJAPI int mjv_select(const mjModel* m, const mjData* d, const mjvOption* vopt,
|
||||
|
||||
@@ -854,6 +854,7 @@ PYBIND11_MODULE(_functions, pymodule, pybind11::mod_gil_not_used()) {
|
||||
Def<traits::mjv_applyPerturbPose>(pymodule);
|
||||
Def<traits::mjv_applyPerturbForce>(pymodule);
|
||||
// Skipped: mjv_averageCamera (defined in structs.cc due to the return type)
|
||||
// Skipped: mjv_camera2GLCamera (defined in structs.cc due to the return type)
|
||||
Def<traits::mjv_select>(pymodule);
|
||||
|
||||
// Visualization
|
||||
|
||||
@@ -4972,6 +4972,32 @@ FUNCTIONS: Mapping[str, FunctionDecl] = dict([
|
||||
),
|
||||
doc='Return the average of two OpenGL cameras.',
|
||||
)),
|
||||
('mjv_camera2GLCamera',
|
||||
FunctionDecl(
|
||||
name='mjv_camera2GLCamera',
|
||||
return_type=ValueType(name='mjvGLCamera'),
|
||||
parameters=(
|
||||
FunctionParameterDecl(
|
||||
name='model',
|
||||
type=PointerType(
|
||||
inner_type=ValueType(name='mjModel', is_const=True),
|
||||
),
|
||||
),
|
||||
FunctionParameterDecl(
|
||||
name='data',
|
||||
type=PointerType(
|
||||
inner_type=ValueType(name='mjData', is_const=True),
|
||||
),
|
||||
),
|
||||
FunctionParameterDecl(
|
||||
name='mjv_camera',
|
||||
type=PointerType(
|
||||
inner_type=ValueType(name='mjvCamera', is_const=True),
|
||||
),
|
||||
),
|
||||
),
|
||||
doc='Converts a mjvCamera to a mjvGLCamera.',
|
||||
)),
|
||||
('mjv_select',
|
||||
FunctionDecl(
|
||||
name='mjv_select',
|
||||
|
||||
@@ -1421,9 +1421,10 @@ This is useful for example when the MJB is not available as a file on disk.)"));
|
||||
|
||||
mjvFigure.def_readonly("linename", &MjvFigureWrapper::linename);
|
||||
|
||||
// mjv_averageCamera returns an mjvGLCamera and we need to call the wrapper's
|
||||
// constructor on the return value. Defining the binding for this function
|
||||
// in this file to avoid symbol dependency across modules.
|
||||
// mjv_averageCamera and mjv_camera2GLCamera both return an mjvGLCamera.
|
||||
// We need to call the wrapper's constructor on the return value. Defining the
|
||||
// binding for these functions in this file to avoid symbol dependency across
|
||||
// modules.
|
||||
m.def(
|
||||
"mjv_averageCamera",
|
||||
[](const MjvGLCameraWrapper& cam1, const MjvGLCameraWrapper& cam2) {
|
||||
@@ -1435,6 +1436,19 @@ This is useful for example when the MJB is not available as a file on disk.)"));
|
||||
py::arg("cam1"), py::arg("cam2"),
|
||||
py::doc(python_traits::mjv_averageCamera::doc));
|
||||
|
||||
m.def(
|
||||
"mjv_camera2GLCamera",
|
||||
[](const MjModelWrapper& m, const MjDataWrapper& d,
|
||||
const MjvCameraWrapper& cam) {
|
||||
return MjvGLCameraWrapper([&m, &d, &cam]() {
|
||||
py::gil_scoped_release no_gil;
|
||||
return InterceptMjErrors(mjv_camera2GLCamera)(m.get(), d.get(),
|
||||
cam.get());
|
||||
}());
|
||||
},
|
||||
py::arg("m"), py::arg("d"), py::arg("cam"),
|
||||
py::doc(python_traits::mjv_camera2GLCamera::doc));
|
||||
|
||||
m.def("_recompile_spec_addr", [](uintptr_t spec_addr, const MjModelWrapper& m,
|
||||
const MjDataWrapper& d) {
|
||||
return RecompileSpec(reinterpret_cast<raw::MjSpec*>(spec_addr), m, d);
|
||||
|
||||
@@ -7225,6 +7225,9 @@ public static unsafe extern void mjv_applyPerturbForce(mjModel_* m, mjData_* d,
|
||||
[DllImport("mujoco", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static unsafe extern mjvGLCamera_ mjv_averageCamera(mjvGLCamera_* cam1, mjvGLCamera_* cam2);
|
||||
|
||||
[DllImport("mujoco", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static unsafe extern mjvGLCamera_ mjv_camera2GLCamera(mjModel_* model, mjData_* data, mjvCamera_* mjv_camera);
|
||||
|
||||
[DllImport("mujoco", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static unsafe extern int mjv_select(mjModel_* m, mjData_* d, mjvOption_* vopt, double aspectratio, double relx, double rely, mjvScene_* scn, double* selpnt, int* geomid, int* flexid, int* skinid);
|
||||
|
||||
|
||||
@@ -3732,6 +3732,12 @@ void mjv_applyPerturbPose_wrapper(const MjModel& m, MjData& d, const MjvPerturb&
|
||||
mjv_applyPerturbPose(m.get(), d.get(), pert.get(), flg_paused);
|
||||
}
|
||||
|
||||
MjvGLCamera mjv_camera2GLCamera_wrapper(const MjModel& model, const MjData& data, const MjvCamera& mjv_camera) {
|
||||
MjvGLCamera result;
|
||||
*result.get() = mjv_camera2GLCamera(model.get(), data.get(), mjv_camera.get());
|
||||
return result;
|
||||
}
|
||||
|
||||
void mjv_cameraFrame_wrapper(const val& headpos, const val& forward, const val& up, const val& right, const MjData& d, const MjvCamera& cam) {
|
||||
UNPACK_NULLABLE_VALUE(mjtNum, headpos);
|
||||
UNPACK_NULLABLE_VALUE(mjtNum, forward);
|
||||
@@ -6629,6 +6635,7 @@ EMSCRIPTEN_BINDINGS(mujoco_bindings) {
|
||||
function("mjv_alignToCamera", &mjv_alignToCamera_wrapper);
|
||||
function("mjv_applyPerturbForce", &mjv_applyPerturbForce_wrapper);
|
||||
function("mjv_applyPerturbPose", &mjv_applyPerturbPose_wrapper);
|
||||
function("mjv_camera2GLCamera", &mjv_camera2GLCamera_wrapper);
|
||||
function("mjv_cameraFrame", &mjv_cameraFrame_wrapper);
|
||||
function("mjv_cameraFrustum", &mjv_cameraFrustum_wrapper);
|
||||
function("mjv_cameraInModel", &mjv_cameraInModel_wrapper);
|
||||
|
||||
Reference in New Issue
Block a user