Exemple #1
0
 def set_model(self, model):
     self.model = model
     if model:
         self.data = model.data
     else:
         self.data = None
     if self.running:
         if model:
             functions.mjr_makeContext(model.ptr, byref(self.con), 150)
         else:
             functions.mjr_makeContext(None, byref(self.con), 150)
         self.render()
     if model:
         self.autoscale()
Exemple #2
0
    def start(self, window):
        self.running = True

        width, height = glfw.get_framebuffer_size(window)
        width1, height = glfw.get_window_size(window)
        self.scale = width * 1.0 / width1

        self.window = window

        functions.mjv_defaultCamera(self.cam)
        functions.mjv_defaultOption(self.vopt)
        functions.mjr_defaultContext(self.con)
        functions.mjv_makeScene(self.scn, 1000)

        if self.model:
            functions.mjr_makeContext(self.model, self.con, 150)
            self.autoscale()
        else:
            functions.mjr_makeContext(None, self.con, 150)
Exemple #3
0
 def set_model(self, model):
     self.model = model
     if model:
         self.sim = MjSim(self.model)
         self.data = self.sim.data
         self.ctx = MjRenderContext(self.sim)
         self.con = self.ctx.con
         self.cam = self.ctx.cam
         self.scn = self.ctx.scn
         self.vopt = self.ctx.vopt
     else:
         self.data = None
     if self.running:
         if model:
             functions.mjr_makeContext(self.model, self.con, 150)
         else:
             functions.mjr_makeContext(None, self.con, 150)
         self.render()
     if model:
         self.autoscale()
Exemple #4
0
    def start(self, window):
        self.running = True

        width, height = glfw.get_framebuffer_size(window)
        width1, height = glfw.get_window_size(window)
        self.scale = width * 1.0 / width1

        self.window = window

        functions.mjv_makeObjects(byref(self.objects), 1000)

        functions.mjv_defaultCamera(byref(self.cam))
        functions.mjv_defaultOption(byref(self.vopt))
        functions.mjr_defaultOption(byref(self.ropt))

        functions.mjr_defaultContext(byref(self.con))

        if self.model:
            functions.mjr_makeContext(self.sim.ptr, byref(self.con), 150)
            self.autoscale()
        else:
            functions.mjr_makeContext(None, byref(self.con), 150)
Exemple #5
0
    def start(self):
        logger.info('initializing glfw@%s', glfw.get_version())

        glfw.set_error_callback(_glfw_error_callback)

        if not glfw.init():
            raise Exception('glfw failed to initialize')

        window = None
        if self.visible:
            glfw.window_hint(glfw.SAMPLES, 4)
        else:
            glfw.window_hint(glfw.VISIBLE, 0)

        # try stereo if refresh rate is at least 100Hz
        stereo_available = False

        _, _, refresh_rate = glfw.get_video_mode(glfw.get_primary_monitor())
        if refresh_rate >= 100:
            glfw.window_hint(glfw.STEREO, 1)
            window = glfw.create_window(self.init_width, self.init_height,
                                        self.title, None, None)
            if window:
                stereo_available = True

        # no stereo: try mono
        if not window:
            glfw.window_hint(glfw.STEREO, 0)
            window = glfw.create_window(self.init_width, self.init_height,
                                        self.title, None, None)

        if not window:
            glfw.terminate()
            return

        self.running = True

        # Make the window's context current
        glfw.make_context_current(window)

        if self.go_fast:
            # Let's go faster than 60 Hz
            glfw.swap_interval(0)

        self._init_framebuffer_object()

        width, height = glfw.get_framebuffer_size(window)
        width1, height = glfw.get_window_size(window)
        self._scale = width * 1.0 / width1

        self.window = window

        functions.mjv_makeObjects(byref(self.objects), 1000)

        functions.mjv_defaultCamera(byref(self.cam))
        functions.mjv_defaultOption(byref(self.vopt))
        functions.mjr_defaultOption(byref(self.ropt))

        functions.mjr_defaultContext(byref(self.con))

        if self.model:
            functions.mjr_makeContext(self.sim.ptr, byref(self.con), 150)
            self.autoscale()
        else:
            functions.mjr_makeContext(None, byref(self.con), 150)

        glfw.set_cursor_pos_callback(window, self.handle_mouse_move)
        glfw.set_mouse_button_callback(window, self.handle_mouse_button)
        glfw.set_scroll_callback(window, self.handle_scroll)