def _setup_world(self): """ Helper method for handling setup of the MuJoCo world. """ fid = open(self.simParams['xmlfile'], 'r') xmlStr = fid.read() self._model = cymj.load_model_from_xml(xmlStr) self.sim = cymj.MjSim(self._model) for nm in self.camera_names(): self.camPrms[nm] = {} self.camPrms[nm]['width'] = self.prms['image_width'] self.camPrms[nm]['height'] = self.prms['image_height']
def initMuJoCo(filename, width2, height): ''' load model, init simulation and rendering ''' global window, sim, ctx assert glfw.init(), 'Could not initialize GLFW' glfw.window_hint(glfw.SAMPLES, 0) glfw.window_hint(glfw.DOUBLEBUFFER, True) glfw.window_hint(glfw.RESIZABLE, 0) window = glfw.create_window(width2 // 4, height // 2, "mjvive.py", None, None) assert window, "Could not create GLFW window" glfw.make_context_current(window) glfw.swap_interval(0) # GLEW init required in C++, not in Python sim = MjSim(load_model_from_xml(open(filename).read())) sim.forward() sim.model.vis.global_.offwidth = width2 sim.model.vis.global_.offheight = height sim.model.vis.quality.offsamples = 8 ctx = MjRenderContext(sim) ctx.scn.enabletransform = 1 ctx.scn.translate[1:3] = -0.5 ctx.scn.rotate[0:2] = math.cos(-0.25 * math.pi), math.sin(-0.25 * math.pi) ctx.scn.scale = 1 ctx.scn.stereo = STEREO_SIDEBYSIDE