Ejemplo n.º 1
0
    def __init__(self, physics):
        super(Visualizer, self).__init__()
        # initialize rendering engine
        enginewrapper.init()
        # save a reference to the physics
        self._physics = physics
        # create the scene for the abstract visualization stage
        self._scene = wrapper.MjvScene()
        self._scene_option = wrapper.MjvOption()
        # a perturbation object, just for completion
        self._perturb = wrapper.MjvPerturb()
        self._perturb.active = 0
        self._perturb.select = 0

        # create a mjvcamera, as it seems is needed for this stage
        self._render_camera = wrapper.MjvCamera()
        self._render_camera.fixedcamid = -1
        self._render_camera.type_ = enums.mjtCamera.mjCAMERA_FREE

        # a list to store the geometries from the abstract visualization stage
        self._geometries = {}
        # the meshes wrapped by the bindings
        self._meshes = {}

        # keys
        self._single_keys = [False for i in range(1024)]

        # make a first update to initialize objects
        mjlib.mjv_updateScene(self._physics.model.ptr, self._physics.data.ptr,
                              self._scene_option.ptr, self._perturb.ptr,
                              self._render_camera.ptr,
                              enums.mjtCatBit.mjCAT_ALL, self._scene.ptr)
        self._collect_geometries()
        self._update_geometries_meshes()
Ejemplo n.º 2
0
 def update(self):
     # abstract visualization stage - retrieve the viz data
     mjlib.mjv_updateScene(self._physics.model.ptr, self._physics.data.ptr,
                           self._scene_option.ptr, self._perturb.ptr,
                           self._render_camera.ptr,
                           enums.mjtCatBit.mjCAT_ALL, self._scene.ptr)
     self._collect_geometries()
     self._update_geometries_meshes()
     # request rendering to the engine backend
     enginewrapper.update()
Ejemplo n.º 3
0
    def update(self, scene_option=None):
        """Updates geometry used for rendering.

    Args:
      scene_option: A custom `wrapper.MjvOption` instance to use to render
        the scene instead of the default.  If None, will use the default.
    """
        scene_option = scene_option or self._scene_option
        mjlib.mjv_updateScene(self._physics.model.ptr, self._physics.data.ptr,
                              scene_option.ptr, self._perturb.ptr,
                              self._render_camera.ptr,
                              enums.mjtCatBit.mjCAT_ALL, self._scene.ptr)
Ejemplo n.º 4
0
    def render(self, perturbation=None):
        """Renders the scene form this camera's perspective.

    Args:
      perturbation: (Optional), instance of Perturbation.
    Returns:
      Rendered scene, instance of MjvScene.
    """
        perturb_to_render = perturbation.ptr if perturbation else None
        mjlib.mjv_updateScene(self._model.ptr, self._data.ptr,
                              self._options.visualization.ptr,
                              perturb_to_render, self._camera.ptr,
                              enums.mjtCatBit.mjCAT_ALL, self._scene.ptr)
        return self._scene