예제 #1
0
  def _build(self, size=(10, 10), aesthetic='default', name='bowl'):
    super()._build(name=name)

    self._hfield = self._mjcf_root.asset.add(
        'hfield',
        name='terrain',
        nrow=201,
        ncol=201,
        size=(6, 6, 0.5, 0.1))

    if aesthetic != 'default':
      ground_info = locomotion_arenas_assets.get_ground_texture_info(aesthetic)
      sky_info = locomotion_arenas_assets.get_sky_texture_info(aesthetic)
      texturedir = locomotion_arenas_assets.get_texturedir(aesthetic)
      self._mjcf_root.compiler.texturedir = texturedir

      self._texture = self._mjcf_root.asset.add(
          'texture', name='aesthetic_texture', file=ground_info.file,
          type=ground_info.type)
      self._material = self._mjcf_root.asset.add(
          'material', name='aesthetic_material', texture=self._texture,
          texuniform='true')
      self._skybox = self._mjcf_root.asset.add(
          'texture', name='aesthetic_skybox', file=sky_info.file,
          type='skybox', gridsize=sky_info.gridsize,
          gridlayout=sky_info.gridlayout)
      self._terrain_geom = self._mjcf_root.worldbody.add(
          'geom',
          name='terrain',
          type='hfield',
          pos=(0, 0, -0.01),
          hfield='terrain',
          material=self._material)
      self._ground_geom = self._mjcf_root.worldbody.add(
          'geom',
          type='plane',
          name='groundplane',
          size=list(size) + [0.5],
          material=self._material)
    else:
      self._terrain_geom = self._mjcf_root.worldbody.add(
          'geom',
          name='terrain',
          type='hfield',
          rgba=(0.2, 0.3, 0.4, 1),
          pos=(0, 0, -0.01),
          hfield='terrain')
      self._ground_geom = self._mjcf_root.worldbody.add(
          'geom',
          type='plane',
          name='groundplane',
          rgba=(0.2, 0.3, 0.4, 1),
          size=list(size) + [0.5])

    self._mjcf_root.visual.headlight.set_attributes(
        ambient=[.4, .4, .4], diffuse=[.8, .8, .8], specular=[.1, .1, .1])

    self._regenerate = True
예제 #2
0
    def _build(self,
               platform_length=1.,
               gap_length=2.5,
               corridor_width=4,
               corridor_length=40,
               ground_rgba=(0.5, 0.5, 0.5, 1),
               visible_side_planes=False,
               aesthetic='default',
               name='gaps_corridor'):
        """Builds the corridor.

    Args:
      platform_length: A number or a `composer.variation.Variation` object that
        specifies the size of the platforms along the corridor.
      gap_length: A number or a `composer.variation.Variation` object that
        specifies the size of the gaps along the corridor.
      corridor_width: A number or a `composer.variation.Variation` object that
        specifies the width of the corridor.
      corridor_length: A number or a `composer.variation.Variation` object that
        specifies the length of the corridor.
      ground_rgba: A sequence of 4 numbers or a `composer.variation.Variation`
        object specifying the color of the ground.
      visible_side_planes: Whether to the side planes that bound the corridor's
        perimeter should be rendered.
      aesthetic: option to adjust the material properties and skybox
      name: The name of this arena.
    """
        super(GapsCorridor,
              self)._build(corridor_width=corridor_width,
                           corridor_length=corridor_length,
                           visible_side_planes=visible_side_planes,
                           name=name)

        self._platform_length = platform_length
        self._gap_length = gap_length
        self._ground_rgba = ground_rgba
        self._aesthetic = aesthetic

        if self._aesthetic != 'default':
            ground_info = locomotion_arenas_assets.get_ground_texture_info(
                aesthetic)
            sky_info = locomotion_arenas_assets.get_sky_texture_info(aesthetic)
            texturedir = locomotion_arenas_assets.get_texturedir(aesthetic)
            self._mjcf_root.compiler.texturedir = texturedir

            self._ground_texture = self._mjcf_root.asset.add(
                'texture',
                name='aesthetic_texture',
                file=ground_info.file,
                type=ground_info.type)
            self._ground_material = self._mjcf_root.asset.add(
                'material',
                name='aesthetic_material',
                texture=self._ground_texture,
                texuniform='true')
            # remove existing skybox
            for texture in self._mjcf_root.asset.find_all('texture'):
                if texture.type == 'skybox':
                    texture.remove()
            self._skybox = self._mjcf_root.asset.add(
                'texture',
                name='aesthetic_skybox',
                file=sky_info.file,
                type='skybox',
                gridsize=sky_info.gridsize,
                gridlayout=sky_info.gridlayout)

        self._ground_body = self._mjcf_root.worldbody.add('body',
                                                          name='ground')
예제 #3
0
    def _build(self,
               maze,
               xy_scale=2.0,
               z_height=2.0,
               skybox_texture=None,
               wall_textures=None,
               floor_textures=None,
               aesthetic='default',
               name='maze'):
        """Initializes this maze arena.

    Args:
      maze: A `labmaze.BaseMaze` instance.
      xy_scale: The size of each maze cell in metres.
      z_height: The z-height of the maze in metres.
      skybox_texture: (optional) A `composer.Entity` that provides a texture
        asset for the skybox.
      wall_textures: (optional) Either a `composer.Entity` that provides texture
        assets for the maze walls, or a dict mapping printable characters to
        such Entities. In the former case, the maze walls are assumed to be
        represented by '*' in the maze's entity layer. In the latter case,
        the dict's keys specify the different characters that can be present
        in the maze's entity layer, and the dict's values are the corresponding
        texture providers.
      floor_textures: (optional) A `composer.Entity` that provides texture
        assets for the maze floor. Unlike with walls, we do not currently
        support per-variation floor texture. Instead, we sample textures from
        the same texture provider for each variation in the variations layer.
      aesthetic: option to adjust the material properties and skybox
      name: (optional) A string, the name of this arena.
    """
        super(MazeWithTargets, self)._build(name)
        self._maze = maze
        self._xy_scale = xy_scale
        self._z_height = z_height

        self._x_offset = (self._maze.width - 1) / 2
        self._y_offset = (self._maze.height - 1) / 2

        self._mjcf_root.default.geom.rgba = [1, 1, 1, 1]

        if aesthetic != 'default':
            sky_info = locomotion_arenas_assets.get_sky_texture_info(aesthetic)
            texturedir = locomotion_arenas_assets.get_texturedir(aesthetic)
            self._mjcf_root.compiler.texturedir = texturedir
            self._skybox = self._mjcf_root.asset.add(
                'texture',
                name='outdoor',
                file=sky_info.file,
                type='skybox',
                gridsize=sky_info.gridsize,
                gridlayout=sky_info.gridlayout)
        elif skybox_texture:
            self._skybox_texture = skybox_texture.texture
            self.attach(skybox_texture)
        else:
            self._skybox_texture = self._mjcf_root.asset.add(
                'texture',
                type='skybox',
                name='skybox',
                builtin='gradient',
                rgb1=[.4, .6, .8],
                rgb2=[0, 0, 0],
                width=100,
                height=100)

        self._texturing_geom_names = []
        self._texturing_material_names = []
        if wall_textures:
            if isinstance(wall_textures, dict):
                for texture_provider in set(wall_textures.values()):
                    self.attach(texture_provider)
                self._wall_textures = {
                    wall_char: texture_provider.textures
                    for wall_char, texture_provider in six.iteritems(
                        wall_textures)
                }
            else:
                self.attach(wall_textures)
                self._wall_textures = {
                    _DEFAULT_WALL_CHAR: wall_textures.textures
                }
        else:
            self._wall_textures = {
                _DEFAULT_WALL_CHAR: [
                    self._mjcf_root.asset.add('texture',
                                              type='2d',
                                              name='wall',
                                              builtin='flat',
                                              rgb1=[.8, .8, .8],
                                              width=100,
                                              height=100)
                ]
            }

        if aesthetic != 'default':
            ground_info = locomotion_arenas_assets.get_ground_texture_info(
                aesthetic)
            self._floor_textures = [
                self._mjcf_root.asset.add('texture',
                                          name='grass_main',
                                          file=ground_info.file,
                                          type=ground_info.type),
                self._mjcf_root.asset.add('texture',
                                          name='grass',
                                          file=ground_info.file,
                                          type=ground_info.type)
            ]
        elif floor_textures:
            self._floor_textures = floor_textures.textures
            self.attach(floor_textures)
        else:
            self._floor_textures = [
                self._mjcf_root.asset.add('texture',
                                          type='2d',
                                          name='floor',
                                          builtin='flat',
                                          rgb1=[.2, .2, .2],
                                          width=100,
                                          height=100)
            ]

        ground_x = ((self._maze.width - 1) + 1) * (xy_scale / 2)
        ground_y = ((self._maze.height - 1) + 1) * (xy_scale / 2)
        self._mjcf_root.worldbody.add('geom',
                                      name='ground',
                                      type='plane',
                                      pos=[0, 0, 0],
                                      size=[ground_x, ground_y, 1],
                                      rgba=[0, 0, 0, 0])

        self._maze_body = self._mjcf_root.worldbody.add('body',
                                                        name='maze_body')

        self._mjcf_root.visual.map.znear = 0.0005

        # Choose the FOV so that the maze always fits nicely within the frame
        # irrespective of actual maze size.
        maze_size = max(self._maze.width, self._maze.height)
        top_camera_fovy = (360 / np.pi) * np.arctan2(
            _TOP_CAMERA_Y_PADDING_FACTOR * maze_size * self._xy_scale / 2,
            _TOP_CAMERA_DISTANCE)
        self._top_camera = self._mjcf_root.worldbody.add(
            'camera',
            name='top_camera',
            pos=[0, 0, _TOP_CAMERA_DISTANCE],
            zaxis=[0, 0, 1],
            fovy=top_camera_fovy)

        self._target_positions = ()
        self._spawn_positions = ()

        self._text_maze_regenerated_hook = None
        self._tile_geom_names = {}
예제 #4
0
    def _build(self,
               size=(8, 8),
               reflectance=.2,
               aesthetic='default',
               name='floor',
               top_camera_y_padding_factor=1.1,
               top_camera_distance=100):
        super()._build(name=name)
        self._size = size
        self._top_camera_y_padding_factor = top_camera_y_padding_factor
        self._top_camera_distance = top_camera_distance

        self._mjcf_root.visual.headlight.set_attributes(ambient=[.4, .4, .4],
                                                        diffuse=[.8, .8, .8],
                                                        specular=[.1, .1, .1])

        if aesthetic != 'default':
            ground_info = locomotion_arenas_assets.get_ground_texture_info(
                aesthetic)
            sky_info = locomotion_arenas_assets.get_sky_texture_info(aesthetic)
            texturedir = locomotion_arenas_assets.get_texturedir(aesthetic)
            self._mjcf_root.compiler.texturedir = texturedir

            self._ground_texture = self._mjcf_root.asset.add(
                'texture',
                name='aesthetic_texture',
                file=ground_info.file,
                type=ground_info.type)
            self._ground_material = self._mjcf_root.asset.add(
                'material',
                name='aesthetic_material',
                texture=self._ground_texture,
                texuniform='true')
            self._skybox = self._mjcf_root.asset.add(
                'texture',
                name='aesthetic_skybox',
                file=sky_info.file,
                type='skybox',
                gridsize=sky_info.gridsize,
                gridlayout=sky_info.gridlayout)
        else:
            self._ground_texture = self._mjcf_root.asset.add(
                'texture',
                rgb1=[.2, .3, .4],
                rgb2=[.1, .2, .3],
                type='2d',
                builtin='checker',
                name='groundplane',
                width=200,
                height=200,
                mark='edge',
                markrgb=[0.8, 0.8, 0.8])
            self._ground_material = self._mjcf_root.asset.add(
                'material',
                name='groundplane',
                texrepeat=[2,
                           2],  # Makes white squares exactly 1x1 length units.
                texuniform=True,
                reflectance=reflectance,
                texture=self._ground_texture)

        # Build groundplane.
        self._ground_geom = self._mjcf_root.worldbody.add(
            'geom',
            type='plane',
            name='groundplane',
            material=self._ground_material,
            size=list(size) + [_GROUNDPLANE_QUAD_SIZE])

        # Choose the FOV so that the floor always fits nicely within the frame
        # irrespective of actual floor size.
        fovy_radians = 2 * np.arctan2(top_camera_y_padding_factor * size[1],
                                      top_camera_distance)
        self._top_camera = self._mjcf_root.worldbody.add(
            'camera',
            name='top_camera',
            pos=[0, 0, top_camera_distance],
            quat=[1, 0, 0, 0],
            fovy=np.rad2deg(fovy_radians))
예제 #5
0
    def _build(self,
               corridor_width=0.8,
               corridor_length=250,
               visible_side_planes=False,
               aesthetic='grid',
               name='long_corridor'):
        """Builds the corridor.

        Args:
            corridor_width: A number or a `composer.variation.Variation` object that
                specifies the width of the corridor.
            corridor_length: A number or a `composer.variation.Variation` object that
                specifies the length of the corridor.
            visible_side_planes: Whether to the side planes that bound the corridor's
                perimeter should be rendered.
            aesthetic: option to adjust the material properties and skybox.
            name: The name of this arena.
        """
        super()._build(corridor_width=corridor_width,
                       corridor_length=corridor_length,
                       visible_side_planes=visible_side_planes,
                       name=name)

        self._aesthetic = aesthetic

        if self._aesthetic == 'grid':
            self._ground_texture = self._mjcf_root.asset.add(
                'texture',
                name='grid_tex',
                type='2d',
                builtin='checker',
                rgb1='.1 .2 .3',
                rgb2='.2 .3 .4',
                width='300',
                height='300',
                mark='edge',
                markrgb='.2 .3 .4')
            self._ground_material = self._mjcf_root.asset.add(
                'material',
                name='grid',
                texture='grid_tex',
                texrepeat='1 1',
                texuniform='true',
                reflectance='.2')

            # remove existing skybox
            for texture in self._mjcf_root.asset.find_all('texture'):
                if texture.type == 'skybox':
                    texture.remove()

            self._skybox = self._mjcf_root.asset.add('texture',
                                                     name='skybox',
                                                     type='skybox',
                                                     builtin='gradient',
                                                     rgb1='.4 .6 .8',
                                                     rgb2='0 0 0',
                                                     width='800',
                                                     height='800',
                                                     mark='random',
                                                     markrgb='1 1 1')

            self._ground_plane.material = self._ground_material
        elif self._aesthetic != 'default':
            ground_info = locomotion_arenas_assets.get_ground_texture_info(
                aesthetic)
            sky_info = locomotion_arenas_assets.get_sky_texture_info(aesthetic)
            texturedir = locomotion_arenas_assets.get_texturedir(aesthetic)
            self._mjcf_root.compiler.texturedir = texturedir

            self._ground_texture = self._mjcf_root.asset.add(
                'texture',
                name='aesthetic_texture',
                file=ground_info.file,
                type=ground_info.type)
            self._ground_material = self._mjcf_root.asset.add(
                'material',
                name='aesthetic_material',
                texture=self._ground_texture,
                texuniform='true')
            # remove existing skybox
            for texture in self._mjcf_root.asset.find_all('texture'):
                if texture.type == 'skybox':
                    texture.remove()
            self._skybox = self._mjcf_root.asset.add(
                'texture',
                name='aesthetic_skybox',
                file=sky_info.file,
                type='skybox',
                gridsize=sky_info.gridsize,
                gridlayout=sky_info.gridlayout)
예제 #6
0
  def _build(self, size=(8, 8), reflectance=.2, aesthetic='default',
             name='floor'):
    super(Floor, self)._build(name=name)
    self._size = size

    self._mjcf_root.visual.headlight.set_attributes(
        ambient=[.4, .4, .4], diffuse=[.8, .8, .8], specular=[.1, .1, .1])

    if aesthetic != 'default':
      ground_info = locomotion_arenas_assets.get_ground_texture_info(aesthetic)
      sky_info = locomotion_arenas_assets.get_sky_texture_info(aesthetic)
      texturedir = locomotion_arenas_assets.get_texturedir(aesthetic)
      self._mjcf_root.compiler.texturedir = texturedir

      self._ground_texture = self._mjcf_root.asset.add(
          'texture', name='grass', file=ground_info.file,
          type=ground_info.type)
      self._ground_material = self._mjcf_root.asset.add(
          'material', name='grass', texture=self._ground_texture,
          texuniform='true')
      self._skybox = self._mjcf_root.asset.add(
          'texture', name='outdoor', file=sky_info.file,
          type='skybox', gridsize=sky_info.gridsize,
          gridlayout=sky_info.gridlayout)
    else:
      self._ground_texture = self._mjcf_root.asset.add(
          'texture',
          rgb1=[.2, .3, .4],
          rgb2=[.1, .2, .3],
          type='2d',
          builtin='checker',
          name='groundplane',
          width=300,
          height=300,
          mark='edge',
          markrgb=[0.8, 0.8, 0.8])
      self._ground_material = self._mjcf_root.asset.add(
          'material',
          name='groundplane',
          texrepeat=[3, 3],
          texuniform=True,
          reflectance=reflectance,
          texture=self._ground_texture)

    # Build groundplane.
    self._ground_geom = self._mjcf_root.worldbody.add(
        'geom',
        type='plane',
        name='groundplane',
        material=self._ground_material,
        size=list(size) + [0.5])

    # Choose the FOV so that the floor always fits nicely within the frame
    # irrespective of actual floor size.
    fovy_radians = 2 * np.arctan2(_TOP_CAMERA_Y_PADDING_FACTOR * size[1],
                                  _TOP_CAMERA_DISTANCE)
    self._top_camera = self._mjcf_root.worldbody.add(
        'camera',
        name='top_camera',
        pos=[0, 0, _TOP_CAMERA_DISTANCE],
        zaxis=[0, 0, 1],
        fovy=np.rad2deg(fovy_radians))