forked from ros-controls/mujoco_ros2_control
-
Notifications
You must be signed in to change notification settings - Fork 3
Visualize virtual gantry in MuJoCo viewer #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
lgulich
merged 10 commits into
impedence-control-support
from
lgulich/virtual-gantry-visualization-styling
May 4, 2026
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0aa0dd5
Visualize virtual gantry in MuJoCo viewer
lgulich f180980
Make virtual gantry visualization more visible
lgulich 5b7fd81
Fix virtual gantry visualization rendering
lgulich aabc1d5
Move gantry visualization behind torso
lgulich 5473a7b
Render gantry at physical mount point
lgulich b29c20d
Test gantry visualization uses configured mount
lgulich 28ffeb7
Tune gantry visualization marker size
lgulich 9e567f7
Keep gantry visualization state out of interface header
lgulich 0cdfa1c
Address gantry visualization review comments
lgulich fcf2318
Move MuJoCo simulate changes to patch file
lgulich File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
mujoco_ros2_control/patches/mujoco_simulate_managed_user_scn.patch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| --- a/simulate.cc | ||
| +++ b/simulate.cc | ||
| @@ -2161,6 +2161,27 @@ void Simulate::Sync(bool state_only) { | ||
| // update scene or sync data from user in passive mode | ||
| if (!is_passive_) { | ||
| mjv_updateScene(m_, d_, &this->opt, &this->pert, &this->cam, mjCAT_ALL, &this->scn); | ||
| + | ||
| + // append geoms from user_scn to scratch space | ||
| + if (user_scn) { | ||
| + user_scn_geoms_.clear(); | ||
| + user_scn_geoms_.reserve(user_scn->ngeom); | ||
| + for (int i = 0; i < user_scn->ngeom; ++i) { | ||
| + user_scn_geoms_.push_back(user_scn->geoms[i]); | ||
| + } | ||
| + } | ||
| + | ||
| + // pick up rendering flags changed via user_scn | ||
| + if (user_scn) { | ||
| + for (int i = 0; i < mjNRNDFLAG; ++i) { | ||
| + if (user_scn->flags[i] != user_scn_flags_prev_[i]) { | ||
| + scn.flags[i] = user_scn->flags[i]; | ||
| + pending_.ui_update_rendering = true; | ||
| + } | ||
| + } | ||
| + Copy(user_scn->flags, scn.flags); | ||
| + Copy(user_scn_flags_prev_, user_scn->flags); | ||
| + } | ||
| } else { | ||
| if (state_only) { | ||
| int state_size = mj_stateSize(m_, mjSTATE_INTEGRATION); | ||
| @@ -2400,6 +2421,27 @@ void Simulate::LoadOnRenderThread() { | ||
| // update scene in managed mode, in passive mode copy data from user (update in RenderLoop) | ||
| if (!is_passive_) { | ||
| mjv_updateScene(this->m_, this->d_, &this->opt, &this->pert, &this->cam, mjCAT_ALL, &this->scn); | ||
| + | ||
| + // append geoms from user_scn to scratch space | ||
| + if (user_scn) { | ||
| + user_scn_geoms_.clear(); | ||
| + user_scn_geoms_.reserve(user_scn->ngeom); | ||
| + for (int i = 0; i < user_scn->ngeom; ++i) { | ||
| + user_scn_geoms_.push_back(user_scn->geoms[i]); | ||
| + } | ||
| + } | ||
| + | ||
| + // pick up rendering flags changed via user_scn | ||
| + if (user_scn) { | ||
| + for (int i = 0; i < mjNRNDFLAG; ++i) { | ||
| + if (user_scn->flags[i] != user_scn_flags_prev_[i]) { | ||
| + scn.flags[i] = user_scn->flags[i]; | ||
| + pending_.ui_update_rendering = true; | ||
| + } | ||
| + } | ||
| + Copy(user_scn->flags, scn.flags); | ||
| + Copy(user_scn_flags_prev_, user_scn->flags); | ||
| + } | ||
| } else { | ||
| mjopt_prev_ = m_->opt; | ||
| opt_prev_ = opt; | ||
| @@ -2864,6 +2906,19 @@ void Simulate::RenderLoop() { | ||
| // update scene, doing a full sync if in fully managed mode | ||
| if (!is_passive_) { | ||
| Sync(); | ||
| + | ||
| + // add user geoms to scene | ||
| + int nusergeom = user_scn_geoms_.size(); | ||
| + int ngeom = std::min(nusergeom, this->scn.maxgeom - this->scn.ngeom); | ||
| + if (ngeom < nusergeom) { | ||
| + mj_warning(this->d_, mjWARN_VGEOMFULL, this->scn.maxgeom); | ||
| + } | ||
| + std::memcpy(this->scn.geoms + this->scn.ngeom, user_scn_geoms_.data(), | ||
| + ngeom * sizeof(mjvGeom)); | ||
| + for (int i = 0; i < ngeom; ++i) { | ||
| + this->scn.geomorder[this->scn.ngeom + i] = this->scn.ngeom + i; | ||
| + } | ||
| + this->scn.ngeom += ngeom; | ||
| } else if (m_passive_ && d_passive_) { | ||
| // the user has called Sync() in their code | ||
| mjv_updateScene(m_passive_, d_passive_, | ||
| @@ -2877,6 +2932,9 @@ void Simulate::RenderLoop() { | ||
| } | ||
| std::memcpy(this->scn.geoms + this->scn.ngeom, user_scn_geoms_.data(), | ||
| ngeom * sizeof(mjvGeom)); | ||
| + for (int i = 0; i < ngeom; ++i) { | ||
| + this->scn.geomorder[this->scn.ngeom + i] = this->scn.ngeom + i; | ||
| + } | ||
| this->scn.ngeom += ngeom; | ||
| } | ||
| } // MutexLock (unblocks simulation thread) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.