Rename simulate.fully_managed_ to simulate.is_passive_ with flipped semantics.
PiperOrigin-RevId: 570815258 Change-Id: Iaffdb0e52bcdb31cff7bd29cb820913e3838f0ee
This commit is contained in:
committed by
Copybara-Service
parent
3e12f0d50c
commit
e9613f0cc9
@@ -70,12 +70,12 @@ class SimulateWrapper {
|
|||||||
public:
|
public:
|
||||||
SimulateWrapper(std::unique_ptr<PlatformUIAdapter> platform_ui_adapter,
|
SimulateWrapper(std::unique_ptr<PlatformUIAdapter> platform_ui_adapter,
|
||||||
py::object scn, py::object cam, py::object opt,
|
py::object scn, py::object cam, py::object opt,
|
||||||
py::object pert, bool fully_managed)
|
py::object pert, bool is_passive)
|
||||||
: simulate_(new mujoco::Simulate(
|
: simulate_(new mujoco::Simulate(
|
||||||
std::move(platform_ui_adapter), scn.cast<MjvSceneWrapper&>().get(),
|
std::move(platform_ui_adapter), scn.cast<MjvSceneWrapper&>().get(),
|
||||||
cam.cast<MjvCameraWrapper&>().get(),
|
cam.cast<MjvCameraWrapper&>().get(),
|
||||||
opt.cast<MjvOptionWrapper&>().get(),
|
opt.cast<MjvOptionWrapper&>().get(),
|
||||||
pert.cast<MjvPerturbWrapper&>().get(), fully_managed)),
|
pert.cast<MjvPerturbWrapper&>().get(), is_passive)),
|
||||||
m_(py::none()),
|
m_(py::none()),
|
||||||
d_(py::none()),
|
d_(py::none()),
|
||||||
scn_(scn),
|
scn_(scn),
|
||||||
@@ -194,12 +194,13 @@ PYBIND11_MODULE(_simulate, pymodule) {
|
|||||||
py::class_<SimulateWrapper>(pymodule, "Simulate")
|
py::class_<SimulateWrapper>(pymodule, "Simulate")
|
||||||
.def_readonly_static("MAX_GEOM", &mujoco::Simulate::kMaxGeom)
|
.def_readonly_static("MAX_GEOM", &mujoco::Simulate::kMaxGeom)
|
||||||
.def(py::init([](py::object scn, py::object cam, py::object opt,
|
.def(py::init([](py::object scn, py::object cam, py::object opt,
|
||||||
py::object pert, bool fully_managed,
|
py::object pert, bool run_physics_thread,
|
||||||
py::object key_callback) {
|
py::object key_callback) {
|
||||||
|
bool is_passive = !run_physics_thread;
|
||||||
return std::make_unique<SimulateWrapper>(
|
return std::make_unique<SimulateWrapper>(
|
||||||
std::make_unique<UIAdapterWithPyCallback<UIAdapter>>(
|
std::make_unique<UIAdapterWithPyCallback<UIAdapter>>(
|
||||||
key_callback),
|
key_callback),
|
||||||
scn, cam, opt, pert, fully_managed);
|
scn, cam, opt, pert, is_passive);
|
||||||
}))
|
}))
|
||||||
.def("destroy", &SimulateWrapper::Destroy,
|
.def("destroy", &SimulateWrapper::Destroy,
|
||||||
py::call_guard<py::gil_scoped_release>())
|
py::call_guard<py::gil_scoped_release>())
|
||||||
|
|||||||
+2
-3
@@ -15,6 +15,7 @@
|
|||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
#include <cstdlib>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
@@ -22,8 +23,6 @@
|
|||||||
#include <new>
|
#include <new>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <type_traits>
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include <mujoco/mujoco.h>
|
#include <mujoco/mujoco.h>
|
||||||
#include "glfw_adapter.h"
|
#include "glfw_adapter.h"
|
||||||
@@ -490,7 +489,7 @@ int main(int argc, char** argv) {
|
|||||||
// simulate object encapsulates the UI
|
// simulate object encapsulates the UI
|
||||||
auto sim = std::make_unique<mj::Simulate>(
|
auto sim = std::make_unique<mj::Simulate>(
|
||||||
std::make_unique<mj::GlfwAdapter>(),
|
std::make_unique<mj::GlfwAdapter>(),
|
||||||
&scn, &cam, &opt, &pert, /* fully_managed = */ true
|
&scn, &cam, &opt, &pert, /* is_passive = */ false
|
||||||
);
|
);
|
||||||
|
|
||||||
const char* filename = nullptr;
|
const char* filename = nullptr;
|
||||||
|
|||||||
+40
-40
@@ -674,7 +674,7 @@ void UpdateWatch(mj::Simulate* sim, const mjModel* m, const mjData* d) {
|
|||||||
|
|
||||||
// make physics section of UI
|
// make physics section of UI
|
||||||
void MakePhysicsSection(mj::Simulate* sim, int oldstate) {
|
void MakePhysicsSection(mj::Simulate* sim, int oldstate) {
|
||||||
mjOption* opt = sim->fully_managed_ ? &sim->m_->opt : &sim->scnstate_.model.opt;
|
mjOption* opt = sim->is_passive_ ? &sim->scnstate_.model.opt : &sim->m_->opt;
|
||||||
mjuiDef defPhysics[] = {
|
mjuiDef defPhysics[] = {
|
||||||
{mjITEM_SECTION, "Physics", oldstate, nullptr, "AP"},
|
{mjITEM_SECTION, "Physics", oldstate, nullptr, "AP"},
|
||||||
{mjITEM_SELECT, "Integrator", 2, &(opt->integrator), "Euler\nRK4\nimplicit\nimplicitfast"},
|
{mjITEM_SELECT, "Integrator", 2, &(opt->integrator), "Euler\nRK4\nimplicit\nimplicitfast"},
|
||||||
@@ -866,8 +866,8 @@ void MakeRenderingSection(mj::Simulate* sim, const mjModel* m, int oldstate) {
|
|||||||
|
|
||||||
// make visualization section of UI
|
// make visualization section of UI
|
||||||
void MakeVisualizationSection(mj::Simulate* sim, const mjModel* m, int oldstate) {
|
void MakeVisualizationSection(mj::Simulate* sim, const mjModel* m, int oldstate) {
|
||||||
mjStatistic* stat = sim->fully_managed_ ? &sim->m_->stat : &sim->scnstate_.model.stat;
|
mjStatistic* stat = sim->is_passive_ ? &sim->scnstate_.model.stat : &sim->m_->stat;
|
||||||
mjVisual* vis = sim->fully_managed_ ? &sim->m_->vis : &sim->scnstate_.model.vis;
|
mjVisual* vis = sim->is_passive_ ? &sim->scnstate_.model.vis : &sim->m_->vis;
|
||||||
|
|
||||||
mjuiDef defVisualization[] = {
|
mjuiDef defVisualization[] = {
|
||||||
{mjITEM_SECTION, "Visualization", oldstate, nullptr, "AV"},
|
{mjITEM_SECTION, "Visualization", oldstate, nullptr, "AV"},
|
||||||
@@ -1001,7 +1001,7 @@ void MakeJointSection(mj::Simulate* sim, int oldstate) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// set data and name
|
// set data and name
|
||||||
if (sim->fully_managed_) {
|
if (!sim->is_passive_) {
|
||||||
defSlider[0].pdata = &sim->d_->qpos[sim->m_->jnt_qposadr[i]];
|
defSlider[0].pdata = &sim->d_->qpos[sim->m_->jnt_qposadr[i]];
|
||||||
} else {
|
} else {
|
||||||
defSlider[0].pdata = &sim->qpos_[sim->jnt_qposadr_[i]];
|
defSlider[0].pdata = &sim->qpos_[sim->jnt_qposadr_[i]];
|
||||||
@@ -1053,7 +1053,7 @@ void MakeControlSection(mj::Simulate* sim, int oldstate) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// set data and name
|
// set data and name
|
||||||
if (sim->fully_managed_) {
|
if (!sim->is_passive_) {
|
||||||
defSlider[0].pdata = &sim->d_->ctrl[i];
|
defSlider[0].pdata = &sim->d_->ctrl[i];
|
||||||
} else {
|
} else {
|
||||||
defSlider[0].pdata = &sim->ctrl_[i];
|
defSlider[0].pdata = &sim->ctrl_[i];
|
||||||
@@ -1242,16 +1242,16 @@ int UiPredicate(int category, void* userdata) {
|
|||||||
|
|
||||||
switch (category) {
|
switch (category) {
|
||||||
case 2: // require model
|
case 2: // require model
|
||||||
return sim->m_ || !sim->fully_managed_;
|
return sim->m_ || sim->is_passive_;
|
||||||
|
|
||||||
case 3: // require model and nkey
|
case 3: // require model and nkey
|
||||||
return sim->fully_managed_ && sim->nkey_;
|
return !sim->is_passive_ && sim->nkey_;
|
||||||
|
|
||||||
case 4: // require model and paused
|
case 4: // require model and paused
|
||||||
return sim->m_ && !sim->run;
|
return sim->m_ && !sim->run;
|
||||||
|
|
||||||
case 5: // require model and fully managed mode
|
case 5: // require model and fully managed mode
|
||||||
return sim->fully_managed_ && sim->m_;
|
return !sim->is_passive_ && sim->m_;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return 1;
|
return 1;
|
||||||
@@ -1401,7 +1401,7 @@ void UiEvent(mjuiState* state) {
|
|||||||
|
|
||||||
// physics section
|
// physics section
|
||||||
else if (it && it->sectionid==SECT_PHYSICS && sim->m_) {
|
else if (it && it->sectionid==SECT_PHYSICS && sim->m_) {
|
||||||
mjOption* opt = sim->fully_managed_ ? &sim->m_->opt : &sim->scnstate_.model.opt;
|
mjOption* opt = sim->is_passive_ ? &sim->scnstate_.model.opt : &sim->m_->opt;
|
||||||
|
|
||||||
// update disable flags in mjOption
|
// update disable flags in mjOption
|
||||||
opt->disableflags = 0;
|
opt->disableflags = 0;
|
||||||
@@ -1500,7 +1500,7 @@ void UiEvent(mjuiState* state) {
|
|||||||
if (state->type==mjEVENT_KEY && state->key!=0) {
|
if (state->type==mjEVENT_KEY && state->key!=0) {
|
||||||
switch (state->key) {
|
switch (state->key) {
|
||||||
case ' ': // Mode
|
case ' ': // Mode
|
||||||
if (sim->fully_managed_ && sim->m_) {
|
if (!sim->is_passive_ && sim->m_) {
|
||||||
sim->run = 1 - sim->run;
|
sim->run = 1 - sim->run;
|
||||||
sim->pert.active = 0;
|
sim->pert.active = 0;
|
||||||
|
|
||||||
@@ -1511,7 +1511,7 @@ void UiEvent(mjuiState* state) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case mjKEY_RIGHT: // step forward
|
case mjKEY_RIGHT: // step forward
|
||||||
if (sim->fully_managed_ && sim->m_ && !sim->run) {
|
if (!sim->is_passive_ && sim->m_ && !sim->run) {
|
||||||
ClearTimers(sim->d_);
|
ClearTimers(sim->d_);
|
||||||
|
|
||||||
// currently in scrubber: increment scrub, load state, update slider UI
|
// currently in scrubber: increment scrub, load state, update slider UI
|
||||||
@@ -1533,7 +1533,7 @@ void UiEvent(mjuiState* state) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case mjKEY_LEFT: // step backward
|
case mjKEY_LEFT: // step backward
|
||||||
if (sim->fully_managed_ && sim->m_) {
|
if (!sim->is_passive_ && sim->m_) {
|
||||||
sim->run = 0;
|
sim->run = 0;
|
||||||
ClearTimers(sim->d_);
|
ClearTimers(sim->d_);
|
||||||
|
|
||||||
@@ -1549,7 +1549,7 @@ void UiEvent(mjuiState* state) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case mjKEY_PAGE_UP: // select parent body
|
case mjKEY_PAGE_UP: // select parent body
|
||||||
if ((sim->m_ || !sim->fully_managed_) && sim->pert.select > 0) {
|
if ((sim->m_ || sim->is_passive_) && sim->pert.select > 0) {
|
||||||
sim->pert.select = sim->body_parentid_[sim->pert.select];
|
sim->pert.select = sim->body_parentid_[sim->pert.select];
|
||||||
sim->pert.skinselect = -1;
|
sim->pert.skinselect = -1;
|
||||||
|
|
||||||
@@ -1562,7 +1562,7 @@ void UiEvent(mjuiState* state) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case ']': // cycle up fixed cameras
|
case ']': // cycle up fixed cameras
|
||||||
if ((sim->m_ || !sim->fully_managed_) && sim->ncam_) {
|
if ((sim->m_ || !sim->is_passive_) && sim->ncam_) {
|
||||||
sim->cam.type = mjCAMERA_FIXED;
|
sim->cam.type = mjCAMERA_FIXED;
|
||||||
// camera = {0 or 1} are reserved for the free and tracking cameras
|
// camera = {0 or 1} are reserved for the free and tracking cameras
|
||||||
if (sim->camera < 2 || sim->camera == 2 + sim->ncam_ - 1) {
|
if (sim->camera < 2 || sim->camera == 2 + sim->ncam_ - 1) {
|
||||||
@@ -1576,7 +1576,7 @@ void UiEvent(mjuiState* state) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case '[': // cycle down fixed cameras
|
case '[': // cycle down fixed cameras
|
||||||
if ((sim->m_ || !sim->fully_managed_) && sim->ncam_) {
|
if ((sim->m_ || sim->is_passive_) && sim->ncam_) {
|
||||||
sim->cam.type = mjCAMERA_FIXED;
|
sim->cam.type = mjCAMERA_FIXED;
|
||||||
// camera = {0 or 1} are reserved for the free and tracking cameras
|
// camera = {0 or 1} are reserved for the free and tracking cameras
|
||||||
if (sim->camera <= 2) {
|
if (sim->camera <= 2) {
|
||||||
@@ -1590,14 +1590,14 @@ void UiEvent(mjuiState* state) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case mjKEY_F6: // cycle frame visualisation
|
case mjKEY_F6: // cycle frame visualisation
|
||||||
if (sim->m_ || !sim->fully_managed_) {
|
if (sim->m_ || sim->is_passive_) {
|
||||||
sim->opt.frame = (sim->opt.frame + 1) % mjNFRAME;
|
sim->opt.frame = (sim->opt.frame + 1) % mjNFRAME;
|
||||||
mjui0_update_section(sim, SECT_RENDERING);
|
mjui0_update_section(sim, SECT_RENDERING);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case mjKEY_F7: // cycle label visualisation
|
case mjKEY_F7: // cycle label visualisation
|
||||||
if (sim->m_ || !sim->fully_managed_) {
|
if (sim->m_ || sim->is_passive_) {
|
||||||
sim->opt.label = (sim->opt.label + 1) % mjNLABEL;
|
sim->opt.label = (sim->opt.label + 1) % mjNLABEL;
|
||||||
mjui0_update_section(sim, SECT_RENDERING);
|
mjui0_update_section(sim, SECT_RENDERING);
|
||||||
}
|
}
|
||||||
@@ -1610,7 +1610,7 @@ void UiEvent(mjuiState* state) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case '-': // slow down
|
case '-': // slow down
|
||||||
if (sim->fully_managed_) {
|
if (!sim->is_passive_) {
|
||||||
int numclicks = sizeof(sim->percentRealTime) / sizeof(sim->percentRealTime[0]);
|
int numclicks = sizeof(sim->percentRealTime) / sizeof(sim->percentRealTime[0]);
|
||||||
if (sim->real_time_index < numclicks-1 && !state->shift) {
|
if (sim->real_time_index < numclicks-1 && !state->shift) {
|
||||||
sim->real_time_index++;
|
sim->real_time_index++;
|
||||||
@@ -1620,7 +1620,7 @@ void UiEvent(mjuiState* state) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case '=': // speed up
|
case '=': // speed up
|
||||||
if (sim->fully_managed_ && sim->real_time_index > 0 && !state->shift) {
|
if (!sim->is_passive_ && sim->real_time_index > 0 && !state->shift) {
|
||||||
sim->real_time_index--;
|
sim->real_time_index--;
|
||||||
sim->speed_changed = true;
|
sim->speed_changed = true;
|
||||||
}
|
}
|
||||||
@@ -1633,7 +1633,7 @@ void UiEvent(mjuiState* state) {
|
|||||||
// 3D scroll
|
// 3D scroll
|
||||||
if (state->type==mjEVENT_SCROLL && state->mouserect==3) {
|
if (state->type==mjEVENT_SCROLL && state->mouserect==3) {
|
||||||
// emulate vertical mouse motion = 2% of window height
|
// emulate vertical mouse motion = 2% of window height
|
||||||
if (sim->fully_managed_) {
|
if (!sim->is_passive_) {
|
||||||
mjv_moveCamera(sim->m_, mjMOUSE_ZOOM, 0, -zoom_increment*state->sy, &sim->scn, &sim->cam);
|
mjv_moveCamera(sim->m_, mjMOUSE_ZOOM, 0, -zoom_increment*state->sy, &sim->scn, &sim->cam);
|
||||||
} else {
|
} else {
|
||||||
mjv_moveCameraFromState(
|
mjv_moveCameraFromState(
|
||||||
@@ -1646,7 +1646,7 @@ void UiEvent(mjuiState* state) {
|
|||||||
if (state->type==mjEVENT_PRESS && state->mouserect==3) {
|
if (state->type==mjEVENT_PRESS && state->mouserect==3) {
|
||||||
// set perturbation
|
// set perturbation
|
||||||
int newperturb = 0;
|
int newperturb = 0;
|
||||||
if (state->control && sim->pert.select>0 && (sim->m_ || !sim->fully_managed_)) {
|
if (state->control && sim->pert.select>0 && (sim->m_ || sim->is_passive_)) {
|
||||||
// right: translate; left: rotate
|
// right: translate; left: rotate
|
||||||
if (state->right) {
|
if (state->right) {
|
||||||
newperturb = mjPERT_TRANSLATE;
|
newperturb = mjPERT_TRANSLATE;
|
||||||
@@ -1659,7 +1659,7 @@ void UiEvent(mjuiState* state) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// handle double-click
|
// handle double-click
|
||||||
if (state->doubleclick && (sim->m_ || !sim->fully_managed_)) {
|
if (state->doubleclick && (sim->m_ || sim->is_passive_)) {
|
||||||
sim->pending_.select = true;
|
sim->pending_.select = true;
|
||||||
std::memcpy(&sim->pending_.select_state, state, sizeof(sim->pending_.select_state));
|
std::memcpy(&sim->pending_.select_state, state, sizeof(sim->pending_.select_state));
|
||||||
|
|
||||||
@@ -1672,7 +1672,7 @@ void UiEvent(mjuiState* state) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 3D release
|
// 3D release
|
||||||
if (state->type==mjEVENT_RELEASE && state->dragrect==3 && (sim->m_ || !sim->fully_managed_)) {
|
if (state->type==mjEVENT_RELEASE && state->dragrect==3 && (sim->m_ || sim->is_passive_)) {
|
||||||
// stop perturbation
|
// stop perturbation
|
||||||
sim->pert.active = 0;
|
sim->pert.active = 0;
|
||||||
sim->pending_.newperturb = 0;
|
sim->pending_.newperturb = 0;
|
||||||
@@ -1680,7 +1680,7 @@ void UiEvent(mjuiState* state) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 3D move
|
// 3D move
|
||||||
if (state->type==mjEVENT_MOVE && state->dragrect==3 && (sim->m_ || !sim->fully_managed_)) {
|
if (state->type==mjEVENT_MOVE && state->dragrect==3 && (sim->m_ || sim->is_passive_)) {
|
||||||
// determine action based on mouse button
|
// determine action based on mouse button
|
||||||
mjtMouse action;
|
mjtMouse action;
|
||||||
if (state->right) {
|
if (state->right) {
|
||||||
@@ -1694,7 +1694,7 @@ void UiEvent(mjuiState* state) {
|
|||||||
// move perturb or camera
|
// move perturb or camera
|
||||||
mjrRect r = state->rect[3];
|
mjrRect r = state->rect[3];
|
||||||
if (sim->pert.active) {
|
if (sim->pert.active) {
|
||||||
if (sim->fully_managed_) {
|
if (!sim->is_passive_) {
|
||||||
mjv_movePerturb(
|
mjv_movePerturb(
|
||||||
sim->m_, sim->d_, action, state->dx / r.height, -state->dy / r.height,
|
sim->m_, sim->d_, action, state->dx / r.height, -state->dy / r.height,
|
||||||
&sim->scn, &sim->pert);
|
&sim->scn, &sim->pert);
|
||||||
@@ -1704,7 +1704,7 @@ void UiEvent(mjuiState* state) {
|
|||||||
&sim->scn, &sim->pert);
|
&sim->scn, &sim->pert);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (sim->fully_managed_) {
|
if (!sim->is_passive_) {
|
||||||
mjv_moveCamera(
|
mjv_moveCamera(
|
||||||
sim->m_, action, state->dx / r.height, -state->dy / r.height,
|
sim->m_, action, state->dx / r.height, -state->dy / r.height,
|
||||||
&sim->scn, &sim->cam);
|
&sim->scn, &sim->cam);
|
||||||
@@ -1718,7 +1718,7 @@ void UiEvent(mjuiState* state) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Dropped files
|
// Dropped files
|
||||||
if (state->type == mjEVENT_FILESDROP && state->dropcount > 0 && sim->fully_managed_) {
|
if (state->type == mjEVENT_FILESDROP && state->dropcount > 0 && !sim->is_passive_) {
|
||||||
while (sim->droploadrequest.load()) {}
|
while (sim->droploadrequest.load()) {}
|
||||||
mju::strcpy_arr(sim->dropfilename, state->droppaths[0]);
|
mju::strcpy_arr(sim->dropfilename, state->droppaths[0]);
|
||||||
sim->droploadrequest.store(true);
|
sim->droploadrequest.store(true);
|
||||||
@@ -1739,8 +1739,8 @@ namespace mju = ::mujoco::sample_util;
|
|||||||
Simulate::Simulate(std::unique_ptr<PlatformUIAdapter> platform_ui,
|
Simulate::Simulate(std::unique_ptr<PlatformUIAdapter> platform_ui,
|
||||||
mjvScene* scn, mjvCamera* cam,
|
mjvScene* scn, mjvCamera* cam,
|
||||||
mjvOption* opt, mjvPerturb* pert,
|
mjvOption* opt, mjvPerturb* pert,
|
||||||
bool fully_managed)
|
bool is_passive)
|
||||||
: fully_managed_(fully_managed),
|
: is_passive_(is_passive),
|
||||||
scn(*scn),
|
scn(*scn),
|
||||||
cam(*cam),
|
cam(*cam),
|
||||||
opt(*opt),
|
opt(*opt),
|
||||||
@@ -1808,7 +1808,7 @@ void Simulate::Sync() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!fully_managed_) {
|
if (is_passive_) {
|
||||||
// synchronize m_->opt with changes made via the UI
|
// synchronize m_->opt with changes made via the UI
|
||||||
#define X(name) \
|
#define X(name) \
|
||||||
if (IsDifferent(scnstate_.model.opt.name, mjopt_prev_.name)) { \
|
if (IsDifferent(scnstate_.model.opt.name, mjopt_prev_.name)) { \
|
||||||
@@ -2007,7 +2007,7 @@ void Simulate::Sync() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// update scene
|
// update scene
|
||||||
if (fully_managed_) {
|
if (!is_passive_) {
|
||||||
mjv_updateScene(m_, d_, &this->opt, &this->pert, &this->cam, mjCAT_ALL, &this->scn);
|
mjv_updateScene(m_, d_, &this->opt, &this->pert, &this->cam, mjCAT_ALL, &this->scn);
|
||||||
} else {
|
} else {
|
||||||
mjv_updateSceneState(m_, d_, &this->opt, &scnstate_);
|
mjv_updateSceneState(m_, d_, &this->opt, &scnstate_);
|
||||||
@@ -2033,7 +2033,7 @@ void Simulate::Sync() {
|
|||||||
// clear timers once profiler info has been copied
|
// clear timers once profiler info has been copied
|
||||||
ClearTimers(d_);
|
ClearTimers(d_);
|
||||||
|
|
||||||
if (this->run || !this->fully_managed_) {
|
if (this->run || this->is_passive_) {
|
||||||
// clear old perturbations, apply new
|
// clear old perturbations, apply new
|
||||||
mju_zero(d_->xfrc_applied, 6*m_->nbody);
|
mju_zero(d_->xfrc_applied, 6*m_->nbody);
|
||||||
mjv_applyPerturbPose(m_, d_, &this->pert, 0); // mocap bodies only
|
mjv_applyPerturbPose(m_, d_, &this->pert, 0); // mocap bodies only
|
||||||
@@ -2148,7 +2148,7 @@ void Simulate::LoadOnRenderThread() {
|
|||||||
ctrl_prev_ = ctrl_;
|
ctrl_prev_ = ctrl_;
|
||||||
|
|
||||||
// allocate history buffer: smaller of {2000 states, 100 MB}
|
// allocate history buffer: smaller of {2000 states, 100 MB}
|
||||||
if (this->fully_managed_) {
|
if (!this->is_passive_) {
|
||||||
constexpr int kHistoryLength = 2000;
|
constexpr int kHistoryLength = 2000;
|
||||||
constexpr int kMaxHistoryBytes = 1e8;
|
constexpr int kMaxHistoryBytes = 1e8;
|
||||||
|
|
||||||
@@ -2172,7 +2172,7 @@ void Simulate::LoadOnRenderThread() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// re-create scene and context
|
// re-create scene and context
|
||||||
if (this->fully_managed_) {
|
if (!this->is_passive_) {
|
||||||
mjv_makeScene(this->m_, &this->scn, kMaxGeom);
|
mjv_makeScene(this->m_, &this->scn, kMaxGeom);
|
||||||
} else {
|
} else {
|
||||||
mjopt_prev_ = m_->opt;
|
mjopt_prev_ = m_->opt;
|
||||||
@@ -2204,7 +2204,7 @@ void Simulate::LoadOnRenderThread() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// update scene
|
// update scene
|
||||||
if (fully_managed_) {
|
if (!is_passive_) {
|
||||||
mjv_updateScene(this->m_, this->d_,
|
mjv_updateScene(this->m_, this->d_,
|
||||||
&this->opt, &this->pert, &this->cam, mjCAT_ALL, &this->scn);
|
&this->opt, &this->pert, &this->cam, mjCAT_ALL, &this->scn);
|
||||||
} else {
|
} else {
|
||||||
@@ -2274,7 +2274,7 @@ void Simulate::Render() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// no model
|
// no model
|
||||||
if (this->fully_managed_ && !this->m_) {
|
if (!this->is_passive_ && !this->m_) {
|
||||||
// blank screen
|
// blank screen
|
||||||
mjr_rectangle(rect, 0.2f, 0.3f, 0.4f, 1);
|
mjr_rectangle(rect, 0.2f, 0.3f, 0.4f, 1);
|
||||||
|
|
||||||
@@ -2322,7 +2322,7 @@ void Simulate::Render() {
|
|||||||
pending_.ui_update_physics = false;
|
pending_.ui_update_physics = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!fully_managed_) {
|
if (is_passive_) {
|
||||||
if (this->ui0_enable && this->ui0.sect[SECT_RENDERING].state &&
|
if (this->ui0_enable && this->ui0.sect[SECT_RENDERING].state &&
|
||||||
(cam_prev_.type != cam.type ||
|
(cam_prev_.type != cam.type ||
|
||||||
cam_prev_.fixedcamid != cam.fixedcamid ||
|
cam_prev_.fixedcamid != cam.fixedcamid ||
|
||||||
@@ -2490,7 +2490,7 @@ void Simulate::RenderLoop() {
|
|||||||
InitializeSensor(this);
|
InitializeSensor(this);
|
||||||
|
|
||||||
// make empty scene
|
// make empty scene
|
||||||
if (fully_managed_) {
|
if (!is_passive_) {
|
||||||
mjv_defaultScene(&this->scn);
|
mjv_defaultScene(&this->scn);
|
||||||
mjv_makeScene(nullptr, &this->scn, kMaxGeom);
|
mjv_makeScene(nullptr, &this->scn, kMaxGeom);
|
||||||
}
|
}
|
||||||
@@ -2587,7 +2587,7 @@ void Simulate::RenderLoop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// update scene, doing a full sync if in fully managed mode
|
// update scene, doing a full sync if in fully managed mode
|
||||||
if (this->fully_managed_) {
|
if (!this->is_passive_) {
|
||||||
Sync();
|
Sync();
|
||||||
} else {
|
} else {
|
||||||
scnstate_.data.warning[mjWARN_VGEOMFULL].number += mjv_updateSceneFromState(
|
scnstate_.data.warning[mjWARN_VGEOMFULL].number += mjv_updateSceneFromState(
|
||||||
@@ -2609,7 +2609,7 @@ void Simulate::RenderLoop() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fully_managed_){
|
if (!is_passive_){
|
||||||
mjv_freeScene(&this->scn);
|
mjv_freeScene(&this->scn);
|
||||||
} else {
|
} else {
|
||||||
mjv_freeSceneState(&scnstate_);
|
mjv_freeSceneState(&scnstate_);
|
||||||
|
|||||||
+3
-3
@@ -52,7 +52,7 @@ class Simulate {
|
|||||||
Simulate(
|
Simulate(
|
||||||
std::unique_ptr<PlatformUIAdapter> platform_ui_adapter,
|
std::unique_ptr<PlatformUIAdapter> platform_ui_adapter,
|
||||||
mjvScene* scn, mjvCamera* cam,
|
mjvScene* scn, mjvCamera* cam,
|
||||||
mjvOption* opt, mjvPerturb* pert, bool fully_managed);
|
mjvOption* opt, mjvPerturb* pert, bool is_passive);
|
||||||
|
|
||||||
// Synchronize mjModel and mjData state with UI inputs, and update
|
// Synchronize mjModel and mjData state with UI inputs, and update
|
||||||
// visualization.
|
// visualization.
|
||||||
@@ -90,9 +90,9 @@ class Simulate {
|
|||||||
// constants
|
// constants
|
||||||
static constexpr int kMaxFilenameLength = 1000;
|
static constexpr int kMaxFilenameLength = 1000;
|
||||||
|
|
||||||
// whether the viewer is operating in fully managed mode, where it can assume
|
// whether the viewer is operating in passive mode, where it cannot assume
|
||||||
// that it has exclusive access to mjModel, mjData, and various mjv objects
|
// that it has exclusive access to mjModel, mjData, and various mjv objects
|
||||||
bool fully_managed_ = true;
|
bool is_passive_ = false;
|
||||||
|
|
||||||
// model and data to be visualized
|
// model and data to be visualized
|
||||||
mjModel* mnew_ = nullptr;
|
mjModel* mnew_ = nullptr;
|
||||||
|
|||||||
Reference in New Issue
Block a user