(self,
             size=_DEFAULT_PITCH_SIZE,
             goal_size=None,
             top_camera_distance=_TOP_CAMERA_DISTANCE,
             field_box=False,
             field_box_offset=0.0,
             hoarding_color_scheme_id=0,
             name='pitch')
Construct a pitch with walls and position detectors.

    Args:
      size: a tuple of (length, width) of the pitch.
      goal_size: optional (depth, width, height) indicating the goal size.
        If not specified, the goal size is inferred from pitch size with a fixed
        default ratio.
      top_camera_distance: the distance of the top-down camera to the pitch.
      field_box: adds a "field box" that collides with the ball but not the
        walkers.
      field_box_offset: offset for the fieldbox if used.
      hoarding_color_scheme_id: An integer with value 0, 1, 2, or 3, specifying
        a preset scheme for the hoarding colors.
      name: the name of this arena.
Construct a pitch with walls and position detectors.
Construct a pitch with walls and position detectors .
def _build(self,
             size=_DEFAULT_PITCH_SIZE,
             goal_size=None,
             top_camera_distance=_TOP_CAMERA_DISTANCE,
             field_box=False,
             field_box_offset=0.0,
             hoarding_color_scheme_id=0,
             name='pitch'):
    """Construct a pitch with walls and position detectors.

    Args:
      size: a tuple of (length, width) of the pitch.
      goal_size: optional (depth, width, height) indicating the goal size.
        If not specified, the goal size is inferred from pitch size with a fixed
        default ratio.
      top_camera_distance: the distance of the top-down camera to the pitch.
      field_box: adds a "field box" that collides with the ball but not the
        walkers.
      field_box_offset: offset for the fieldbox if used.
      hoarding_color_scheme_id: An integer with value 0, 1, 2, or 3, specifying
        a preset scheme for the hoarding colors.
      name: the name of this arena.
    """
    super()._build(name=name)
    self._size = size
    self._goal_size = goal_size
    self._top_camera_distance = top_camera_distance
    self._hoarding_color_scheme_id = hoarding_color_scheme_id

    self._top_camera = self._mjcf_root.worldbody.add(
        'camera',
        name='top_down',
        pos=[0, 0, top_camera_distance],
        zaxis=[0, 0, 1],
        fovy=_top_down_cam_fovy(self._size, top_camera_distance))

    # Set the `extent`, an "average distance" to 0.1 * pitch length.
    extent = 0.1 * max(self._size)
    self._mjcf_root.statistic.extent = extent
    self._mjcf_root.statistic.center = (0, 0, extent)
    # The near and far clipping planes are scaled by `extent`.
    self._mjcf_root.visual.map.zfar = 50             # 5 pitch lengths
    self._mjcf_root.visual.map.znear = 0.1 / extent  # 10 centimeters

    # Add skybox.
    self._mjcf_root.asset.add(
        'texture',
        name='skybox',
        type='skybox',
        builtin='gradient',
        rgb1=(.7, .9, .9),
        rgb2=(.03, .09, .27),
        width=400,
        height=400)

    # Add and position corner lights.
    self._corner_lights = [self._mjcf_root.worldbody.add('light', cutoff=60)
                           for _ in range(4)]
    _reposition_corner_lights(self._corner_lights, size)

    # Increase shadow resolution, (default is 1024).
    self._mjcf_root.visual.quality.shadowsize = 8192

    # Build groundplane.
    if len(self._size) != 2:
      raise ValueError('`size` should be a sequence of length 2: got {!r}'
                       .format(self._size))
    self._field_texture = self._mjcf_root.asset.add(
        'texture',
        type='2d',
        file=_get_texture('pitch_nologo_l'),
        name='fieldplane')
    self._field_material = self._mjcf_root.asset.add(
        'material', name='fieldplane', texture=self._field_texture)

    self._ground_geom = self._mjcf_root.worldbody.add(
        'geom',
        name='ground',
        type='plane',
        material=self._field_material,
        size=list(self._size) + [max(self._size) * _GROUND_GEOM_GRID_RATIO])

    # Build walls.
    self._walls = []
    for wall_pos, wall_xyaxes in _wall_pos_xyaxes(self._size):
      self._walls.append(
          self._mjcf_root.worldbody.add(
              'geom',
              type='plane',
              rgba=[.1, .1, .1, .8],
              pos=wall_pos,
              size=[1e-7, 1e-7, 1e-7],
              xyaxes=wall_xyaxes))

    # Build goal position detectors.
    # If field_box is enabled, offset goal by 1.0 such that ball reaches the
    # goal position detector before bouncing off the field_box.
    self._fb_offset = field_box_offset if field_box else 0.0
    goal_size = self._get_goal_size()
    self._home_goal = Goal(
        direction=1,
        make_net=False,
        pos=(-self._size[0] + goal_size[0] + self._fb_offset, 0,
             goal_size[2]),
        size=goal_size,
        rgba=(.2, .2, 1, 0.5),
        visible=True,
        name='home_goal')
    self.attach(self._home_goal)

    self._away_goal = Goal(
        direction=-1,
        make_net=False,
        pos=(self._size[0] - goal_size[0] - self._fb_offset, 0, goal_size[2]),
        size=goal_size,
        rgba=(1, .2, .2, 0.5),
        visible=True,
        name='away_goal')
    self.attach(self._away_goal)

    # Build inverted field position detectors.
    self._field = props.PositionDetector(
        pos=(0, 0),
        size=(self._size[0] - 2 * goal_size[0],
              self._size[1] - 2 * goal_size[0]),
        inverted=True,
        visible=False,
        name='field')
    self.attach(self._field)

    # Build field perimeter.
    def _visual_plane():
      return self._mjcf_root.worldbody.add(
          'geom',
          type='plane',
          size=(1, 1, 1),
          rgba=(0.306, 0.682, 0.223, 1),
          contype=0,
          conaffinity=0)

    self._perimeter = [_visual_plane() for _ in range(8)]
    self._update_perimeter()

    # Build field box.
    self._field_box = []
    if field_box:
      for box_pos, box_size in _fieldbox_pos_size(
          (self._field.upper - self._field.lower) / 2.0, goal_size):
        self._field_box.append(
            self._mjcf_root.worldbody.add(
                'geom',
                type='box',
                rgba=[.3, .3, .3, .0],
                pos=box_pos,
                size=box_size))

    # Build hoarding sites.
    def _box_site():
      return self._mjcf_root.worldbody.add('site', type='box', size=(1, 1, 1))
    self._hoarding = [_box_site() for _ in range(4 * _NUM_HOARDING)]
    self._update_hoarding()
def _build ( self , size = _DEFAULT_PITCH_SIZE , goal_size = None , top_camera_distance = _TOP_CAMERA_DISTANCE , field_box = False , field_box_offset = 0.0 , hoarding_color_scheme_id = 0 , name = 'pitch' ) : super ( ) . _build ( name = name ) self . _size = size self . _goal_size = goal_size self . _top_camera_distance = top_camera_distance self . _hoarding_color_scheme_id = hoarding_color_scheme_id self . _top_camera = self . _mjcf_root . worldbody . add ( 'camera' , name = 'top_down' , pos = [ 0 , 0 , top_camera_distance ] , zaxis = [ 0 , 0 , 1 ] , fovy = _top_down_cam_fovy ( self . _size , top_camera_distance ) ) # Set the `extent`, an "average distance" to 0.1 * pitch length. extent = 0.1 * max ( self . _size ) self . _mjcf_root . statistic . extent = extent self . _mjcf_root . statistic . center = ( 0 , 0 , extent ) # The near and far clipping planes are scaled by `extent`. self . _mjcf_root . visual . map . zfar = 50 # 5 pitch lengths self . _mjcf_root . visual . map . znear = 0.1 / extent # 10 centimeters # Add skybox. self . _mjcf_root . asset . add ( 'texture' , name = 'skybox' , type = 'skybox' , builtin = 'gradient' , rgb1 = ( .7 , .9 , .9 ) , rgb2 = ( .03 , .09 , .27 ) , width = 400 , height = 400 ) # Add and position corner lights. self . _corner_lights = [ self . _mjcf_root . worldbody . add ( 'light' , cutoff = 60 ) for _ in range ( 4 ) ] _reposition_corner_lights ( self . _corner_lights , size ) # Increase shadow resolution, (default is 1024). self . _mjcf_root . visual . quality . shadowsize = 8192 # Build groundplane. if len ( self . _size ) != 2 : raise ValueError ( '`size` should be a sequence of length 2: got {!r}' . format ( self . _size ) ) self . _field_texture = self . _mjcf_root . asset . add ( 'texture' , type = '2d' , file = _get_texture ( 'pitch_nologo_l' ) , name = 'fieldplane' ) self . _field_material = self . _mjcf_root . asset . add ( 'material' , name = 'fieldplane' , texture = self . _field_texture ) self . _ground_geom = self . _mjcf_root . worldbody . add ( 'geom' , name = 'ground' , type = 'plane' , material = self . _field_material , size = list ( self . _size ) + [ max ( self . _size ) * _GROUND_GEOM_GRID_RATIO ] ) # Build walls. self . _walls = [ ] for wall_pos , wall_xyaxes in _wall_pos_xyaxes ( self . _size ) : self . _walls . append ( self . _mjcf_root . worldbody . add ( 'geom' , type = 'plane' , rgba = [ .1 , .1 , .1 , .8 ] , pos = wall_pos , size = [ 1e-7 , 1e-7 , 1e-7 ] , xyaxes = wall_xyaxes ) ) # Build goal position detectors. # If field_box is enabled, offset goal by 1.0 such that ball reaches the # goal position detector before bouncing off the field_box. self . _fb_offset = field_box_offset if field_box else 0.0 goal_size = self . _get_goal_size ( ) self . _home_goal = Goal ( direction = 1 , make_net = False , pos = ( - self . _size [ 0 ] + goal_size [ 0 ] + self . _fb_offset , 0 , goal_size [ 2 ] ) , size = goal_size , rgba = ( .2 , .2 , 1 , 0.5 ) , visible = True , name = 'home_goal' ) self . attach ( self . _home_goal ) self . _away_goal = Goal ( direction = - 1 , make_net = False , pos = ( self . _size [ 0 ] - goal_size [ 0 ] - self . _fb_offset , 0 , goal_size [ 2 ] ) , size = goal_size , rgba = ( 1 , .2 , .2 , 0.5 ) , visible = True , name = 'away_goal' ) self . attach ( self . _away_goal ) # Build inverted field position detectors. self . _field = props . PositionDetector ( pos = ( 0 , 0 ) , size = ( self . _size [ 0 ] - 2 * goal_size [ 0 ] , self . _size [ 1 ] - 2 * goal_size [ 0 ] ) , inverted = True , visible = False , name = 'field' ) self . attach ( self . _field ) # Build field perimeter. def _visual_plane ( ) : return self . _mjcf_root . worldbody . add ( 'geom' , type = 'plane' , size = ( 1 , 1 , 1 ) , rgba = ( 0.306 , 0.682 , 0.223 , 1 ) , contype = 0 , conaffinity = 0 ) self . _perimeter = [ _visual_plane ( ) for _ in range ( 8 ) ] self . _update_perimeter ( ) # Build field box. self . _field_box = [ ] if field_box : for box_pos , box_size in _fieldbox_pos_size ( ( self . _field . upper - self . _field . lower ) / 2.0 , goal_size ) : self . _field_box . append ( self . _mjcf_root . worldbody . add ( 'geom' , type = 'box' , rgba = [ .3 , .3 , .3 , .0 ] , pos = box_pos , size = box_size ) ) # Build hoarding sites. def _box_site ( ) : return self . _mjcf_root . worldbody . add ( 'site' , type = 'box' , size = ( 1 , 1 , 1 ) ) self . _hoarding = [ _box_site ( ) for _ in range ( 4 * _NUM_HOARDING ) ] self . _update_hoarding ( )