Preserve time when recompiling a model.

Fixes #1890.

PiperOrigin-RevId: 662084324
Change-Id: I6aed40761cee5044e63426935d102123db295b25
This commit is contained in:
Alessio Quaglino
2024-08-12 07:59:53 -07:00
committed by Copybara-Service
parent d3a976e10d
commit 648fd56ed1
2 changed files with 5 additions and 0 deletions
+3
View File
@@ -91,13 +91,16 @@ mjModel* mj_compile(mjSpec* s, const mjVFS* vfs) {
// recompile spec into existing model and data while preserving the state
void mj_recompile(mjSpec* s, const mjVFS* vfs, mjModel* m, mjData* d) {
mjCModel* modelC = static_cast<mjCModel*>(s->element);
mjtNum time = 0;
if (d) {
time = d->time;
modelC->SaveState(d->qpos, d->qvel, d->act);
}
modelC->Compile(vfs, &m);
if (d) {
modelC->MakeData(m, &d);
modelC->RestoreState(d->qpos, d->qvel, d->act);
d->time = time;
}
}