当前位置: 首页>>代码示例>>Python>>正文


Python mujoco_py.MjRenderContextOffscreen方法代码示例

本文整理汇总了Python中mujoco_py.MjRenderContextOffscreen方法的典型用法代码示例。如果您正苦于以下问题:Python mujoco_py.MjRenderContextOffscreen方法的具体用法?Python mujoco_py.MjRenderContextOffscreen怎么用?Python mujoco_py.MjRenderContextOffscreen使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mujoco_py的用法示例。


在下文中一共展示了mujoco_py.MjRenderContextOffscreen方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _reset_internal

# 需要导入模块: import mujoco_py [as 别名]
# 或者: from mujoco_py import MjRenderContextOffscreen [as 别名]
def _reset_internal(self):
        """Resets simulation internal configurations."""
        # instantiate simulation from MJCF model
        self._load_model()
        self.mjpy_model = self.model.get_model(mode="mujoco_py")
        self.sim = MjSim(self.mjpy_model)
        self.initialize_time(self.control_freq)

        # create visualization screen or renderer
        if self.has_renderer and self.viewer is None:
            self.viewer = MujocoPyRenderer(self.sim)
            self.viewer.viewer.vopt.geomgroup[0] = (
                1 if self.render_collision_mesh else 0
            )
            self.viewer.viewer.vopt.geomgroup[1] = 1 if self.render_visual_mesh else 0

            # hiding the overlay speeds up rendering significantly
            self.viewer.viewer._hide_overlay = True

        elif self.has_offscreen_renderer:
            if self.sim._render_context_offscreen is None:
                render_context = MjRenderContextOffscreen(self.sim)
                self.sim.add_render_context(render_context)
            self.sim._render_context_offscreen.vopt.geomgroup[0] = (
                1 if self.render_collision_mesh else 0
            )
            self.sim._render_context_offscreen.vopt.geomgroup[1] = (
                1 if self.render_visual_mesh else 0
            )

        # additional housekeeping
        self.sim_state_initial = self.sim.get_state()
        self._get_reference()
        self.cur_time = 0
        self.timestep = 0
        self.done = False 
开发者ID:StanfordVL,项目名称:robosuite,代码行数:38,代码来源:base.py

示例2: reset_from_xml_string

# 需要导入模块: import mujoco_py [as 别名]
# 或者: from mujoco_py import MjRenderContextOffscreen [as 别名]
def reset_from_xml_string(self, xml_string):
        """Reloads the environment from an XML description of the environment."""

        # if there is an active viewer window, destroy it
        self.close()

        # load model from xml
        self.mjpy_model = load_model_from_xml(xml_string)

        self.sim = MjSim(self.mjpy_model)
        self.initialize_time(self.control_freq)
        if self.has_renderer and self.viewer is None:
            self.viewer = MujocoPyRenderer(self.sim)
            self.viewer.viewer.vopt.geomgroup[0] = (
                1 if self.render_collision_mesh else 0
            )
            self.viewer.viewer.vopt.geomgroup[1] = 1 if self.render_visual_mesh else 0

            # hiding the overlay speeds up rendering significantly
            self.viewer.viewer._hide_overlay = True

        elif self.has_offscreen_renderer:
            render_context = MjRenderContextOffscreen(self.sim)
            render_context.vopt.geomgroup[0] = 1 if self.render_collision_mesh else 0
            render_context.vopt.geomgroup[1] = 1 if self.render_visual_mesh else 0
            self.sim.add_render_context(render_context)

        self.sim_state_initial = self.sim.get_state()
        self._get_reference()
        self.cur_time = 0
        self.timestep = 0
        self.done = False

        # necessary to refresh MjData
        self.sim.forward() 
开发者ID:StanfordVL,项目名称:robosuite,代码行数:37,代码来源:base.py

示例3: __init__

# 需要导入模块: import mujoco_py [as 别名]
# 或者: from mujoco_py import MjRenderContextOffscreen [as 别名]
def __init__(self,
                 wrapped_env,
                 imsize=32,
                 keep_prev=0,
                 init_camera=None,
                 camera_name=None,
                 transpose=False,
                 grayscale=False,
                 normalize=False,
    ):
        self.quick_init(locals())
        super().__init__(wrapped_env)

        self.imsize = imsize
        if grayscale:
            self.image_length = self.imsize * self.imsize
        else:
            self.image_length = 3 * self.imsize * self.imsize
        # This is torch format rather than PIL image
        self.image_shape = (self.imsize, self.imsize)
        # Flattened past image queue
        self.history_length = keep_prev + 1
        self.history = deque(maxlen=self.history_length)
        # init camera
        if init_camera is not None:
            sim = self._wrapped_env.sim
            viewer = mujoco_py.MjRenderContextOffscreen(sim, device_id=-1)
            init_camera(viewer.cam)
            sim.add_render_context(viewer)
        self.camera_name = camera_name # None means default camera
        self.transpose = transpose
        self.grayscale = grayscale
        self.normalize = normalize
        self._render_local = False

        self.observation_space = Box(low=0.0,
                                     high=1.0,
                                     shape=(self.image_length * self.history_length,)) 
开发者ID:snasiriany,项目名称:leap,代码行数:40,代码来源:wrappers.py

示例4: _setup_render_rgb

# 需要导入模块: import mujoco_py [as 别名]
# 或者: from mujoco_py import MjRenderContextOffscreen [as 别名]
def _setup_render_rgb(sim: mujoco_py.MjSim) -> mujoco_py.MjSim:
  # create copy of simulation to customize rendering context
  # flags defined in mjvisualize.h
  render_sim = mujoco_py.MjSim(sim.model)
  render_sim.set_state(sim.get_state())
  render_ctx = mujoco_py.MjRenderContextOffscreen(render_sim)
  render_ctx.scn.stereo = 2 # side-by-side rendering
  return render_sim 
开发者ID:ogroth,项目名称:shapestacks,代码行数:10,代码来源:record_scenario.py

示例5: _setup_render_seg

# 需要导入模块: import mujoco_py [as 别名]
# 或者: from mujoco_py import MjRenderContextOffscreen [as 别名]
def _setup_render_seg(sim: mujoco_py.MjSim) -> mujoco_py.MjSim:
  # create copy of simulation to customize rendering context
  # flags defined in mjvisualize.h
  render_sim = mujoco_py.MjSim(sim.model)
  render_sim.set_state(sim.get_state())
  render_ctx = mujoco_py.MjRenderContextOffscreen(render_sim)
  render_ctx.vopt.flags[1] = 0 # textures off
  render_ctx.vopt.flags[17] = 0 # static body off
  render_ctx.scn.flags[0] = 0 # shadow off
  render_ctx.scn.flags[2] = 0 # reflection off
  render_ctx.scn.flags[4] = 0 # skybox off
  render_ctx.scn.stereo = 2 # side-by-side rendering
  return render_sim 
开发者ID:ogroth,项目名称:shapestacks,代码行数:15,代码来源:record_scenario.py

示例6: _setup_render_depth

# 需要导入模块: import mujoco_py [as 别名]
# 或者: from mujoco_py import MjRenderContextOffscreen [as 别名]
def _setup_render_depth(sim: mujoco_py.MjSim) -> mujoco_py.MjSim:
  # create copy of simulation to customize rendering context
  # flags defined in mjvisualize.h
  render_sim = mujoco_py.MjSim(sim.model)
  render_sim.set_state(sim.get_state())
  render_ctx = mujoco_py.MjRenderContextOffscreen(render_sim)
  render_ctx.vopt.flags[1] = 0 # textures off
  render_ctx.scn.flags[0] = 0 # shadow off
  render_ctx.scn.flags[2] = 0 # reflection off
  render_ctx.scn.flags[4] = 0 # skybox off
  render_ctx.scn.stereo = 2 # side-by-side rendering
  return render_sim 
开发者ID:ogroth,项目名称:shapestacks,代码行数:14,代码来源:record_scenario.py

示例7: _get_viewer

# 需要导入模块: import mujoco_py [as 别名]
# 或者: from mujoco_py import MjRenderContextOffscreen [as 别名]
def _get_viewer(self, mode):
        self.viewer = self._viewers.get(mode)
        if self.viewer is None:
            if mode == 'human':
                self.viewer = mujoco_py.MjViewer(self.sim)
            elif mode == 'rgb_array' or mode == 'depth_array':
                self.viewer = mujoco_py.MjRenderContextOffscreen(self.sim, -1)
                
            self.viewer_setup()
            self._viewers[mode] = self.viewer
        return self.viewer 
开发者ID:joanby,项目名称:ia-course,代码行数:13,代码来源:mujoco_env.py

示例8: get_current_image_obs

# 需要导入模块: import mujoco_py [as 别名]
# 或者: from mujoco_py import MjRenderContextOffscreen [as 别名]
def get_current_image_obs(self):
        # print(self._get_viewer)
        # print(self._get_viewer())
        # self.viewer = mujoco_py.MjRenderContextOffscreen(self.sim, -1)
        # self.viewer = mujoco_py.MjViewer()
        # self.viewer.start()
        # self.viewer.set_model(self.model)
        # self.viewer_setup()
        # self._get_viewer()

        
        # image = self.viewer.get_image()
        # pil_image = Image.frombytes('RGB', (image[1], image[2]), image[0])
        # pil_image = pil_image.resize((125,125), Image.ANTIALIAS)
        # image = np.flipud(np.array(pil_image))

        # image = self.render(mode='rgb_array', width=125, height=125)
        # transpose to make it have correct ordering of dimensions for pytorch
        # image = image.transpose((2,0,1))
        # image = np.array(image).astype(np.float32)
        # image /= 255.0

        image = self.render(mode='rgb_array', width=500, height=500)
        image = Image.fromarray(image)
        image = image.resize((125,125), PIL.Image.LANCZOS)
        image = np.array(image)
        image = image.transpose((2,0,1))
        image = np.array(image).astype(np.float32)
        image /= 255.0

        X = np.concatenate([
            self.sim.data.qpos.flat[:7],
            self.sim.data.qvel.flat[:7],
            self.get_body_com('tips_arm'),
            self.get_body_com('goal'),
        ]).copy()
        X = (X - self.state_mean) / self.state_std

        return image, X 
开发者ID:KamyarGh,项目名称:rl_swiss,代码行数:41,代码来源:mil_pusher_env.py

示例9: _get_viewer

# 需要导入模块: import mujoco_py [as 别名]
# 或者: from mujoco_py import MjRenderContextOffscreen [as 别名]
def _get_viewer(self, mode):
        self.viewer = self._viewers.get(mode)
        if self.viewer is None:
            if mode == 'human':
                self.viewer = mujoco_py.MjViewer(self.sim)
            elif mode == 'rgb_array':
                self.viewer = mujoco_py.MjRenderContextOffscreen(self.sim, device_id=-1)
            self._viewer_setup()
            self._viewers[mode] = self.viewer
        return self.viewer

    # Extension methods
    # ---------------------------- 
开发者ID:hust512,项目名称:DQN-DDPG_Stock_Trading,代码行数:15,代码来源:robot_env.py

示例10: _get_viewer

# 需要导入模块: import mujoco_py [as 别名]
# 或者: from mujoco_py import MjRenderContextOffscreen [as 别名]
def _get_viewer(self, mode):
        self.viewer = self._viewers.get(mode)
        if self.viewer is None:
            if mode == 'human':
                self.viewer = mujoco_py.MjViewer(self.sim)
            elif mode == 'rgb_array' or mode == 'depth_array':
                self.viewer = mujoco_py.MjRenderContextOffscreen(self.sim, -1)

            self.viewer_setup()
            self._viewers[mode] = self.viewer
        return self.viewer 
开发者ID:hust512,项目名称:DQN-DDPG_Stock_Trading,代码行数:13,代码来源:mujoco_env.py

示例11: initialize_camera

# 需要导入模块: import mujoco_py [as 别名]
# 或者: from mujoco_py import MjRenderContextOffscreen [as 别名]
def initialize_camera(self):
        # set camera parameters for viewing
        sim = self.sim
        viewer = mujoco_py.MjRenderContextOffscreen(sim)
        camera = viewer.cam
        camera.type = 1
        camera.trackbodyid = 0
        camera.elevation = -20
        sim.add_render_context(viewer) 
开发者ID:katerakelly,项目名称:oyster,代码行数:11,代码来源:wrappers.py

示例12: render

# 需要导入模块: import mujoco_py [as 别名]
# 或者: from mujoco_py import MjRenderContextOffscreen [as 别名]
def render(self, mode='human', close=False):
        if mode == 'human':
            if self.viewer is None:
                self.viewer = MjViewer(self.sim)
            self.viewer.render()
        elif mode == 'rgb_array':
            if self.rgb_viewer is None:
                self.rgb_viewer = MjRenderContextOffscreen(self.sim, 0)
            self.rgb_viewer.render(500, 500)
            # window size used for old mujoco-py:
            data = self.rgb_viewer.read_pixels(500, 500, depth=False)
            # original image is upside-down, so flip it
            return data[::-1, :, :] 
开发者ID:NervanaSystems,项目名称:coach,代码行数:15,代码来源:pendulum_with_goals.py

示例13: __init__

# 需要导入模块: import mujoco_py [as 别名]
# 或者: from mujoco_py import MjRenderContextOffscreen [as 别名]
def __init__(self,
                 wrapped_env,
                 imsize=32,
                 keep_prev=0,
                 init_camera=None,
                 camera_name=None,
                 transpose=False,
                 grayscale=False,
                 normalize=False,
                 ):
        import mujoco_py
        super().__init__(wrapped_env)

        self.imsize = imsize
        if grayscale:
            self.image_length = self.imsize * self.imsize
        else:
            self.image_length = 3 * self.imsize * self.imsize
        # This is torch format rather than PIL image
        self.image_shape = (self.imsize, self.imsize)
        # Flattened past image queue
        self.history_length = keep_prev + 1
        self.history = deque(maxlen=self.history_length)
        # init camera
        if init_camera is not None:
            sim = self._wrapped_env.sim
            viewer = mujoco_py.MjRenderContextOffscreen(sim, device_id=-1)
            init_camera(viewer.cam)
            sim.add_render_context(viewer)
        self.camera_name = camera_name  # None means default camera
        self.transpose = transpose
        self.grayscale = grayscale
        self.normalize = normalize
        self._render_local = False

        self.observation_space = Box(low=0.0,
                                     high=1.0,
                                     shape=(
                                     self.image_length * self.history_length,)) 
开发者ID:vitchyr,项目名称:rlkit,代码行数:41,代码来源:mujoco_image_env.py


注:本文中的mujoco_py.MjRenderContextOffscreen方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。