Skip to content

Commit

Permalink
updates for compatibility with mujoco 3.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
rohanpsingh committed Nov 14, 2023
1 parent edfc2d3 commit 3e98063
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 15 deletions.
39 changes: 28 additions & 11 deletions mujoco_viewer/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import yaml
from threading import Lock

MUJOCO_VERSION=tuple(map(int, mujoco.__version__.split('.')))

class Callbacks:
def __init__(self, hide_menus):
Expand Down Expand Up @@ -254,18 +255,34 @@ def _mouse_button_callback(self, window, button, act, mods):
rely = (self.viewport.height - y) / height
selpnt = np.zeros((3, 1), dtype=np.float64)
selgeom = np.zeros((1, 1), dtype=np.int32)
selflex = np.zeros((1, 1), dtype=np.int32)
selskin = np.zeros((1, 1), dtype=np.int32)
selbody = mujoco.mjv_select(
self.model,
self.data,
self.vopt,
aspectratio,
relx,
rely,
self.scn,
selpnt,
selgeom,
selskin)

if MUJOCO_VERSION>=(3,0,0):
selbody = mujoco.mjv_select(
self.model,
self.data,
self.vopt,
aspectratio,
relx,
rely,
self.scn,
selpnt,
selgeom,
selflex,
selskin)
else:
selbody = mujoco.mjv_select(
self.model,
self.data,
self.vopt,
aspectratio,
relx,
rely,
self.scn,
selpnt,
selgeom,
selskin)

# set lookat point, start tracking is requested
if selmode == 2 or selmode == 3:
Expand Down
14 changes: 11 additions & 3 deletions mujoco_viewer/mujoco_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import yaml
from .callbacks import Callbacks

MUJOCO_VERSION=tuple(map(int, mujoco.__version__.split('.')))

class MujocoViewer(Callbacks):
def __init__(
Expand Down Expand Up @@ -317,9 +318,16 @@ def add_overlay(gridpos, text1, text2):
add_overlay(
bottomleft, "FPS", "%d%s" %
(1 / self._time_per_render, ""))
add_overlay(
bottomleft, "Solver iterations", str(
self.data.solver_iter + 1))

if MUJOCO_VERSION>=(3,0,0):
add_overlay(
bottomleft, "Max solver iters", str(
max(self.data.solver_niter) + 1))
else:
add_overlay(
bottomleft, "Solver iterations", str(
self.data.solver_iter + 1))

add_overlay(
bottomleft, "Step", str(
round(
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os
from setuptools import find_packages, setup

VERSION = '0.1.3'
VERSION = '0.1.4'

INSTALL_REQUIRES = (
['mujoco >= 2.1.5',
Expand Down

0 comments on commit 3e98063

Please sign in to comment.