Skip to content
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

Creating custom Overlays while using MuJoCo Viewer #44

Open
karthyyy opened this issue Feb 17, 2024 · 0 comments
Open

Creating custom Overlays while using MuJoCo Viewer #44

karthyyy opened this issue Feb 17, 2024 · 0 comments

Comments

@karthyyy
Copy link

karthyyy commented Feb 17, 2024

Hi,

I am using Mujoco_viewer for my onscreen and offline rendering. I need to add custom overlays to the rendering. So I disabled default overlays by setting "hide_menus='True'" as

viewer = mujoco_viewer.MujocoViewer(model, data, hide_menus='True')

Then custom overlays were created in my main file as given below

# Overlay Functions
_overlay = {}
def add_overlay(gridpos, text1, text2):

    if gridpos not in _overlay:
        _overlay[gridpos] = ["", ""]
    _overlay[gridpos][0] += text1 + "\n"
    _overlay[gridpos][1] += text2 + "\n"
   
# Add overlay here
def create_overlay(model ,data):
    topleft = mj.mjtGridPos.mjGRID_TOPLEFT
    topright = mj.mjtGridPos.mjGRID_TOPRIGHT
    bottomleft = mj.mjtGridPos.mjGRID_BOTTOMLEFT
    bottomright = mj.mjtGridPos.mjGRID_BOTTOMRIGHT   
 
    add_overlay(
        bottomleft,
        "Time", '%.2f' %data.time,
        )

From the MuJoCo literature, the steps are mentioned as

  1. Calling the function "create_overlay(model, data)"
  2. Add overlay items as follows
for gridpos, [t1, t2] in _overlay.items():

mj.mjr_overlay(
mj.mjtFontScale.mjFONTSCALE_150,
gridpos,
viewport,
t1,
t2,
context)
  1. Clear the overlay "_overlay.clear()"

The simulation code is given as

# Simulation
mj.mj_step(model, data)        
create_overlay(model, data) #create overlay
glfw.make_context_current(viewer.window)
viewer.render()  
_overlay.clear()  # clear overlay
glfw.make_context_current(None)

Doubt-1) Whether the locations of the functions "create_overlay(model, data)" and "_overlay.clear()" in the above simulation and rendering code are correct ?
Doubt-2) In add overlay items as given in step-2, what is 'viewport' and 'context' ?
Doubt-3) Is there any better method than the one mentioned here ?

Can you please help me with the same ?

Thanks
Karthik R

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant