mujoco-py
mujoco-py copied to clipboard
Adding objects to the scene via OpenGL in mjviewer
Hi,
I was wondering if I could add primitive objects to the scene dynamically that is not present in the XML file. I don't want the physics of the objects to be simulated by mujoco. My core purpose is to translucent primitive shape in the scene that would show the prediction. For example, I have an box object in the scene that is described by the XML file. I want to overlay this box with an OpenGL cube that could be called from mjviewer so that I could remove this overlayed cube from time and again.
I tried adding it using the following bit of code to mjviewer.py. This draws a cube when independently tested. But I am unable to get it draw in the scene. Is it possible to do this or am I wasting time? Thanks for the time.
def drawCube(self, pos, ori, size):
#this function expects center of the cube, orientation, and size as (length(x), breadh(y), height(z))
glfw.make_context_current(self.window)
self.gui_lock.acquire()
gl.glClear(gl.GL_COLOR_BUFFER_BIT | gl.GL_DEPTH_BUFFER_BIT)
gl.glLoadIdentity()
gl.glTranslatef(pos[0],pos[1],pos[2])
gl.glScalef(size[0],size[1],size[0])
gl.glRotatef(ori[0],1.0,0.0,0.0)
gl.glRotatef(ori[1],0.0,1.0,0.0)
gl.glRotatef(ori[2],0.0,0.0,1.0)
# Draw Cube (multiple quads)
gl.glBegin(gl.GL_QUADS)
gl.glColor3f(0.0,1.0,0.0)
gl.glVertex3f( 1.0, 1.0,-1.0)
gl.glVertex3f(-1.0, 1.0,-1.0)
gl.glVertex3f(-1.0, 1.0, 1.0)
gl.glVertex3f( 1.0, 1.0, 1.0)
gl.glColor3f(1.0,0.0,0.0)
gl.glVertex3f( 1.0,-1.0, 1.0)
gl.glVertex3f(-1.0,-1.0, 1.0)
gl.glVertex3f(-1.0,-1.0,-1.0)
gl.glVertex3f( 1.0,-1.0,-1.0)
gl.glColor3f(0.0,1.0,0.0)
gl.glVertex3f( 1.0, 1.0, 1.0)
gl.glVertex3f(-1.0, 1.0, 1.0)
gl.glVertex3f(-1.0,-1.0, 1.0)
gl.glVertex3f( 1.0,-1.0, 1.0)
gl.glColor3f(1.0,1.0,0.0)
gl.glVertex3f( 1.0,-1.0,-1.0)
gl.glVertex3f(-1.0,-1.0,-1.0)
gl.glVertex3f(-1.0, 1.0,-1.0)
gl.glVertex3f( 1.0, 1.0,-1.0)
gl.glColor3f(0.0,0.0,1.0)
gl.glVertex3f(-1.0, 1.0, 1.0)
gl.glVertex3f(-1.0, 1.0,-1.0)
gl.glVertex3f(-1.0,-1.0,-1.0)
gl.glVertex3f(-1.0,-1.0, 1.0)
gl.glColor3f(1.0,0.0,1.0)
gl.glVertex3f( 1.0, 1.0,-1.0)
gl.glVertex3f( 1.0, 1.0, 1.0)
gl.glVertex3f( 1.0,-1.0, 1.0)
gl.glVertex3f( 1.0,-1.0,-1.0)
gl.glEnd()
self.gui_lock.release()
Hi!
Is there a chance that this issue led to some new functionality since 2017 that allows to add transparent objects, i.e. that do not change the dynamics of simulator?
In particular, I'm interested in highlighting some parts of the simulator while rendering given the coordinates in terms of the robots' state space. In other words, given the state of the robot of the same dimensionality as vector obtained from env.reset(), I need to place a transparent object in that state of the environment.
Does anyone know to do this? Thanks!