(self,
             visual,
             marker_rgba,
             walker_id=None,
             initializer=None,
             name='walker')
Build a soccer-specific Humanoid walker.
Build a soccer-specific Humanoid walker.
Build a soccer - specific Humanoid walker .
def _build(self,
             visual,
             marker_rgba,
             walker_id=None,
             initializer=None,
             name='walker'):
    """Build a soccer-specific Humanoid walker."""
    if not isinstance(visual, Humanoid.Visual):
      raise ValueError('`visual` must be one of `Humanoid.Visual`.')

    if len(marker_rgba) != 4:
      raise ValueError('`marker_rgba` must be a sequence of length 4.')

    if walker_id is None and visual != Humanoid.Visual.GEOM:
      raise ValueError(
          '`walker_id` must be set unless `visual` is set to `Visual.GEOM`.')

    if walker_id is not None and not 0 <= walker_id <= _MAX_WALKER_ID:
      raise ValueError(_INVALID_WALKER_ID.format(walker_id))

    if visual == Humanoid.Visual.JERSEY:
      team = 'R' if marker_rgba[0] > marker_rgba[2] else 'B'
      marker_rgba = None  # disable geom coloring for None geom visual.
    else:
      marker_rgba[-1] = .7

    super(Humanoid, self)._build(
        marker_rgba=marker_rgba,
        initializer=initializer,
        include_face=True)

    self._mjcf_root.model = name

    # Changes to humanoid geoms for visual improvements.
    # Hands: hide hand geoms and add slightly larger visual geoms.
    for hand_name in ['lhand', 'rhand']:
      hand = self._mjcf_root.find('body', hand_name)
      for geom in hand.find_all('geom'):
        geom.rgba = (0, 0, 0, 0)
        if geom.name == hand_name:
          geom_size = geom.size * 1.3  # Palm rescaling.
        else:
          geom_size = geom.size * 1.5  # Finger rescaling.
        geom.parent.add(
            'geom',
            name=geom.name + '_visual',
            type=geom.type,
            quat=geom.quat,
            mass=0,
            contype=0,
            conaffinity=0,
            size=geom_size,
            pos=geom.pos * 1.5)

    # Lighting: remove tracking light as we have multiple walkers in the scene.
    tracking_light = self._mjcf_root.find('light', 'tracking_light')
    tracking_light.remove()

    if visual == Humanoid.Visual.JERSEY:
      shirt_number = walker_id + 1
      self._mjcf_root.asset.add(
          'texture',
          name='skin',
          type='2d',
          file=os.path.join(_ASSETS_PATH, f'{team}_{walker_id + 1:02d}.png'))
      self._mjcf_root.asset.add('material', name='skin', texture='skin')
      self._mjcf_root.asset.add(
          'skin',
          name='skin',
          file=os.path.join(_ASSETS_PATH, 'jersey.skn'),
          material='skin')
      for geom in self._mjcf_root.find_all('geom'):
        if geom.name in _INTERIOR_GEOMS:
          geom.rgba = (0.0, 0.0, 0.0, 0.0)
      _add_visual_only_geoms(self._mjcf_root)

    # Initialize previous action.
    self._prev_action = np.zeros(shape=self.action_spec.shape,
                                 dtype=self.action_spec.dtype)
def _build ( self , visual , marker_rgba , walker_id = None , initializer = None , name = 'walker' ) : if not isinstance ( visual , Humanoid . Visual ) : raise ValueError ( '`visual` must be one of `Humanoid.Visual`.' ) if len ( marker_rgba ) != 4 : raise ValueError ( '`marker_rgba` must be a sequence of length 4.' ) if walker_id is None and visual != Humanoid . Visual . GEOM : raise ValueError ( '`walker_id` must be set unless `visual` is set to `Visual.GEOM`.' ) if walker_id is not None and not 0 <= walker_id <= _MAX_WALKER_ID : raise ValueError ( _INVALID_WALKER_ID . format ( walker_id ) ) if visual == Humanoid . Visual . JERSEY : team = 'R' if marker_rgba [ 0 ] > marker_rgba [ 2 ] else 'B' marker_rgba = None # disable geom coloring for None geom visual. else : marker_rgba [ - 1 ] = .7 super ( Humanoid , self ) . _build ( marker_rgba = marker_rgba , initializer = initializer , include_face = True ) self . _mjcf_root . model = name # Changes to humanoid geoms for visual improvements. # Hands: hide hand geoms and add slightly larger visual geoms. for hand_name in [ 'lhand' , 'rhand' ] : hand = self . _mjcf_root . find ( 'body' , hand_name ) for geom in hand . find_all ( 'geom' ) : geom . rgba = ( 0 , 0 , 0 , 0 ) if geom . name == hand_name : geom_size = geom . size * 1.3 # Palm rescaling. else : geom_size = geom . size * 1.5 # Finger rescaling. geom . parent . add ( 'geom' , name = geom . name + '_visual' , type = geom . type , quat = geom . quat , mass = 0 , contype = 0 , conaffinity = 0 , size = geom_size , pos = geom . pos * 1.5 ) # Lighting: remove tracking light as we have multiple walkers in the scene. tracking_light = self . _mjcf_root . find ( 'light' , 'tracking_light' ) tracking_light . remove ( ) if visual == Humanoid . Visual . JERSEY : shirt_number = walker_id + 1 self . _mjcf_root . asset . add ( 'texture' , name = 'skin' , type = '2d' , file = os . path . join ( _ASSETS_PATH , f'{team}_{walker_id + 1:02d}.png' ) ) self . _mjcf_root . asset . add ( 'material' , name = 'skin' , texture = 'skin' ) self . _mjcf_root . asset . add ( 'skin' , name = 'skin' , file = os . path . join ( _ASSETS_PATH , 'jersey.skn' ) , material = 'skin' ) for geom in self . _mjcf_root . find_all ( 'geom' ) : if geom . name in _INTERIOR_GEOMS : geom . rgba = ( 0.0 , 0.0 , 0.0 , 0.0 ) _add_visual_only_geoms ( self . _mjcf_root ) # Initialize previous action. self . _prev_action = np . zeros ( shape = self . action_spec . shape , dtype = self . action_spec . dtype )