def render(self): if not self.data: return # Make the window's context current glfw.make_context_current(self.window) self.gui_lock.acquire() rect = self.get_rect() arr = (ctypes.c_double * 3)(0, 0, 0) functions.mjv_makeGeoms( self.sim.ptr, self.data.ptr, byref(self.objects), byref(self.vopt), mjCAT_ALL, 0, None, None, ctypes.cast(arr, ctypes.POINTER(ctypes.c_double))) functions.mjv_makeLights(self.sim.ptr, self.data.ptr, byref(self.objects)) functions.mjv_setCamera(self.sim.ptr, self.data.ptr, byref(self.cam)) functions.mjv_updateCameraPose(byref(self.cam), rect.width * 1.0 / rect.height) functions.mjr_render(0, rect, byref(self.objects), byref(self.ropt), byref(self.cam.pose), byref(self.con)) self.gui_lock.release()
def render(self): rect = self.get_rect() width = rect.width height = rect.height functions.mjv_addGeoms(self.model, self.data, self.vopt, None, CAT_ALL, self.scn) functions.mjv_updateCamera(self.model, self.data, self.cam, self.scn) functions.mjv_moveCamera(self.model, 5, width / height, height / height, self.scn, self.cam) functions.mjr_render(rect, self.scn, self.con)
def render(self): rect = self.get_rect() arr = (ctypes.c_double * 3)(0, 0, 0) functions.mjv_makeGeoms( self.sim.ptr, self.data.ptr, byref(self.objects), byref(self.vopt), mjCAT_ALL, 0, None, None, ctypes.cast(arr, ctypes.POINTER(ctypes.c_double))) functions.mjv_setCamera(self.sim.ptr, self.data.ptr, byref(self.cam)) functions.mjv_updateCameraPose(byref(self.cam), rect.width * 1.0 / rect.height) functions.mjr_render(0, rect, byref(self.objects), byref(self.ropt), byref(self.cam.pose), byref(self.con))
def render(self): super(GatherViewer, self).render() ctx = MjRenderContext(self.env.wrapped_env.sim) scn = ctx.scn con = ctx.con functions.mjv_makeScene(scn, 1000) scn.camera[0].frustum_near = 0.05 scn.camera[1].frustum_near = 0.05 for obj in self.env.objects: x, y, typ = obj qpos = np.zeros_like(self.green_ball_sim.data.qpos) qpos[0] = x qpos[1] = y if typ == APPLE: self.green_ball_sim.data.qpos[:] = qpos self.green_ball_sim.forward() self.green_ball_renderer.render() self.green_ball_ctx = MjRenderContext(self.green_ball_sim) functions.mjv_addGeoms(self.green_ball_sim.model, self.green_ball_sim.data, self.green_ball_ctx.vopt, self.green_ball_ctx.pert, CAT_ALL, scn) else: self.red_ball_sim.data.qpos[:] = qpos self.red_ball_sim.forward() self.red_ball_renderer.render() self.red_ball_ctx = MjRenderContext(self.red_ball_sim) functions.mjv_addGeoms(self.red_ball_sim.model, self.red_ball_sim.data, self.red_ball_ctx.vopt, self.red_ball_ctx.pert, CAT_ALL, scn) functions.mjv_addGeoms(self.env.wrapped_env.sim.model, self.env.wrapped_env.sim.data, ctx.vopt, ctx.pert, CAT_ALL, scn) functions.mjr_render(self.green_ball_renderer.get_rect(), scn, con) try: import OpenGL.GL as GL except ImportError: return def draw_rect(x, y, width, height): # start drawing a rectangle GL.glBegin(GL.GL_QUADS) # bottom left point GL.glVertex2f(x, y) # bottom right point GL.glVertex2f(x + width, y) # top right point GL.glVertex2f(x + width, y + height) # top left point GL.glVertex2f(x, y + height) def refresh2d(width, height): GL.glViewport(0, 0, width, height) GL.glMatrixMode(GL.GL_PROJECTION) GL.glLoadIdentity() GL.glOrtho(0.0, width, 0.0, height, 0.0, 1.0) GL.glMatrixMode(GL.GL_MODELVIEW) GL.glLoadIdentity() GL.glBegin(GL.GL_QUADS) GL.glLoadIdentity() width, height = glfw.get_framebuffer_size(self.window) refresh2d(width, height) GL.glDisable(GL.GL_LIGHTING) GL.glEnable(GL.GL_BLEND) GL.glColor4f(0.0, 0.0, 0.0, 0.8) draw_rect(10, 10, 300, 100) apple_readings, bomb_readings = self.env.get_readings() for idx, reading in enumerate(apple_readings): if reading > 0: GL.glColor4f(0.0, 1.0, 0.0, reading) draw_rect(20 * (idx + 1), 10, 5, 50) for idx, reading in enumerate(bomb_readings): if reading > 0: GL.glColor4f(1.0, 0.0, 0.0, reading) draw_rect(20 * (idx + 1), 60, 5, 50)
v_initPost() FPS = 90.0 lasttm = glfw.get_time() frametime = sim.data.time viewFull = PyMjrRect() viewFull.width, viewFull.height = 2 * hmd.width, hmd.height nullCam = PyMjvCamera() while not glfw.window_should_close(window): if sim.data.time - frametime > 1 / FPS or sim.data.time < frametime: functions.mjv_updateScene(sim.model, sim.data, ctx.vopt, ctx.pert, nullCam, CAT_ALL, ctx.scn) v_update() functions.mjr_setBuffer(FB_OFFSCREEN, ctx.con) functions.mjr_render(viewFull, ctx.scn, ctx.con) FPS = .9 * FPS + .1 / (glfw.get_time() - lasttm) lasttm = glfw.get_time() functions.mjr_overlay(FONT_BIG, GRID_BOTTOMLEFT, viewFull, 'FPS %.1f' % FPS, '', ctx.con) v_render() frametime = sim.data.time sim.step() glfw.poll_events() # close openvr.shutdown() gl.glDeleteTextures(1, hmd.idtex) del sim del ctx glfw.terminate()
def render(self): super(GatherViewer, self).render() tmpobjects = mjcore.MJVOBJECTS() functions.mjv_makeObjects(byref(tmpobjects), 1000) for obj in self.env.objects: x, y, typ = obj # print x, y qpos = np.zeros_like(self.green_ball_model.data.qpos) qpos[0, 0] = x qpos[1, 0] = y if typ == APPLE: self.green_ball_model.data.qpos = qpos self.green_ball_model.forward() self.green_ball_renderer.render() mjextra.append_objects(tmpobjects, self.green_ball_renderer.objects) else: self.red_ball_model.data.qpos = qpos self.red_ball_model.forward() self.red_ball_renderer.render() mjextra.append_objects(tmpobjects, self.red_ball_renderer.objects) mjextra.append_objects(tmpobjects, self.objects) functions.mjv_makeLights(self.sim.ptr, self.data.ptr, byref(tmpobjects)) functions.mjr_render(0, self.get_rect(), byref(tmpobjects), byref(self.ropt), byref(self.cam.pose), byref(self.con)) try: import OpenGL.GL as GL except: return def draw_rect(x, y, width, height): # start drawing a rectangle GL.glBegin(GL.GL_QUADS) # bottom left point GL.glVertex2f(x, y) # bottom right point GL.glVertex2f(x + width, y) # top right point GL.glVertex2f(x + width, y + height) # top left point GL.glVertex2f(x, y + height) GL.glEnd() def refresh2d(width, height): GL.glViewport(0, 0, width, height) GL.glMatrixMode(GL.GL_PROJECTION) GL.glLoadIdentity() GL.glOrtho(0.0, width, 0.0, height, 0.0, 1.0) GL.glMatrixMode(GL.GL_MODELVIEW) GL.glLoadIdentity() GL.glLoadIdentity() width, height = glfw.get_framebuffer_size(self.window) refresh2d(width, height) GL.glDisable(GL.GL_LIGHTING) GL.glEnable(GL.GL_BLEND) GL.glColor4f(0.0, 0.0, 0.0, 0.8) draw_rect(10, 10, 300, 100) apple_readings, bomb_readings = self.env.get_readings() for idx, reading in enumerate(apple_readings): if reading > 0: GL.glColor4f(0.0, 1.0, 0.0, reading) draw_rect(20 * (idx + 1), 10, 5, 50) for idx, reading in enumerate(bomb_readings): if reading > 0: GL.glColor4f(1.0, 0.0, 0.0, reading) draw_rect(20 * (idx + 1), 60, 5, 50)
v_initPre() initMuJoCo(filename, hmd.width * 2, hmd.height) v_initPost() FPS = 90.0 lasttm = glfw.get_time() frametime = sim.data.time viewFull = PyMjrRect() viewFull.width, viewFull.height = 2 * hmd.width, hmd.height nullCam = PyMjvCamera() while not glfw.window_should_close(window): if sim.data.time - frametime > 1 / FPS or sim.data.time < frametime: functions.mjv_updateScene(sim.model, sim.data, ctx.vopt, ctx.pert, nullCam, CAT_ALL, ctx.scn) v_update() functions.mjr_setBuffer(FB_OFFSCREEN, ctx.con) functions.mjr_render(viewFull, ctx.scn, ctx.con) FPS = .9 * FPS + .1 / (glfw.get_time() - lasttm) lasttm = glfw.get_time() functions.mjr_overlay(FONT_BIG, GRID_BOTTOMLEFT, viewFull, 'FPS %.1f' % FPS, '', ctx.con) v_render() frametime = sim.data.time sim.step() glfw.poll_events() # close openvr.shutdown() gl.glDeleteTextures(1, hmd.idtex) del sim del ctx glfw.terminate()