|
| 1 | +--- a/simulate.cc |
| 2 | ++++ b/simulate.cc |
| 3 | +@@ -2161,6 +2161,27 @@ void Simulate::Sync(bool state_only) { |
| 4 | + // update scene or sync data from user in passive mode |
| 5 | + if (!is_passive_) { |
| 6 | + mjv_updateScene(m_, d_, &this->opt, &this->pert, &this->cam, mjCAT_ALL, &this->scn); |
| 7 | ++ |
| 8 | ++ // append geoms from user_scn to scratch space |
| 9 | ++ if (user_scn) { |
| 10 | ++ user_scn_geoms_.clear(); |
| 11 | ++ user_scn_geoms_.reserve(user_scn->ngeom); |
| 12 | ++ for (int i = 0; i < user_scn->ngeom; ++i) { |
| 13 | ++ user_scn_geoms_.push_back(user_scn->geoms[i]); |
| 14 | ++ } |
| 15 | ++ } |
| 16 | ++ |
| 17 | ++ // pick up rendering flags changed via user_scn |
| 18 | ++ if (user_scn) { |
| 19 | ++ for (int i = 0; i < mjNRNDFLAG; ++i) { |
| 20 | ++ if (user_scn->flags[i] != user_scn_flags_prev_[i]) { |
| 21 | ++ scn.flags[i] = user_scn->flags[i]; |
| 22 | ++ pending_.ui_update_rendering = true; |
| 23 | ++ } |
| 24 | ++ } |
| 25 | ++ Copy(user_scn->flags, scn.flags); |
| 26 | ++ Copy(user_scn_flags_prev_, user_scn->flags); |
| 27 | ++ } |
| 28 | + } else { |
| 29 | + if (state_only) { |
| 30 | + int state_size = mj_stateSize(m_, mjSTATE_INTEGRATION); |
| 31 | +@@ -2400,6 +2421,27 @@ void Simulate::LoadOnRenderThread() { |
| 32 | + // update scene in managed mode, in passive mode copy data from user (update in RenderLoop) |
| 33 | + if (!is_passive_) { |
| 34 | + mjv_updateScene(this->m_, this->d_, &this->opt, &this->pert, &this->cam, mjCAT_ALL, &this->scn); |
| 35 | ++ |
| 36 | ++ // append geoms from user_scn to scratch space |
| 37 | ++ if (user_scn) { |
| 38 | ++ user_scn_geoms_.clear(); |
| 39 | ++ user_scn_geoms_.reserve(user_scn->ngeom); |
| 40 | ++ for (int i = 0; i < user_scn->ngeom; ++i) { |
| 41 | ++ user_scn_geoms_.push_back(user_scn->geoms[i]); |
| 42 | ++ } |
| 43 | ++ } |
| 44 | ++ |
| 45 | ++ // pick up rendering flags changed via user_scn |
| 46 | ++ if (user_scn) { |
| 47 | ++ for (int i = 0; i < mjNRNDFLAG; ++i) { |
| 48 | ++ if (user_scn->flags[i] != user_scn_flags_prev_[i]) { |
| 49 | ++ scn.flags[i] = user_scn->flags[i]; |
| 50 | ++ pending_.ui_update_rendering = true; |
| 51 | ++ } |
| 52 | ++ } |
| 53 | ++ Copy(user_scn->flags, scn.flags); |
| 54 | ++ Copy(user_scn_flags_prev_, user_scn->flags); |
| 55 | ++ } |
| 56 | + } else { |
| 57 | + mjopt_prev_ = m_->opt; |
| 58 | + opt_prev_ = opt; |
| 59 | +@@ -2864,6 +2906,19 @@ void Simulate::RenderLoop() { |
| 60 | + // update scene, doing a full sync if in fully managed mode |
| 61 | + if (!is_passive_) { |
| 62 | + Sync(); |
| 63 | ++ |
| 64 | ++ // add user geoms to scene |
| 65 | ++ int nusergeom = user_scn_geoms_.size(); |
| 66 | ++ int ngeom = std::min(nusergeom, this->scn.maxgeom - this->scn.ngeom); |
| 67 | ++ if (ngeom < nusergeom) { |
| 68 | ++ mj_warning(this->d_, mjWARN_VGEOMFULL, this->scn.maxgeom); |
| 69 | ++ } |
| 70 | ++ std::memcpy(this->scn.geoms + this->scn.ngeom, user_scn_geoms_.data(), |
| 71 | ++ ngeom * sizeof(mjvGeom)); |
| 72 | ++ for (int i = 0; i < ngeom; ++i) { |
| 73 | ++ this->scn.geomorder[this->scn.ngeom + i] = this->scn.ngeom + i; |
| 74 | ++ } |
| 75 | ++ this->scn.ngeom += ngeom; |
| 76 | + } else if (m_passive_ && d_passive_) { |
| 77 | + // the user has called Sync() in their code |
| 78 | + mjv_updateScene(m_passive_, d_passive_, |
| 79 | +@@ -2877,6 +2932,9 @@ void Simulate::RenderLoop() { |
| 80 | + } |
| 81 | + std::memcpy(this->scn.geoms + this->scn.ngeom, user_scn_geoms_.data(), |
| 82 | + ngeom * sizeof(mjvGeom)); |
| 83 | ++ for (int i = 0; i < ngeom; ++i) { |
| 84 | ++ this->scn.geomorder[this->scn.ngeom + i] = this->scn.ngeom + i; |
| 85 | ++ } |
| 86 | + this->scn.ngeom += ngeom; |
| 87 | + } |
| 88 | + } // MutexLock (unblocks simulation thread) |
0 commit comments