def _make_wall_geoms(self, wall_char): walls = covering.make_walls(self._maze.entity_layer, wall_char=wall_char, make_odd_sized_walls=True) for i, wall in enumerate(walls): wall_mid = covering.GridCoordinates( (wall.start.y + wall.end.y - 1) / 2, (wall.start.x + wall.end.x - 1) / 2) wall_pos = np.array([ (wall_mid.x - self._x_offset) * self._xy_scale, -(wall_mid.y - self._y_offset) * self._xy_scale, self._z_height / 2 ]) wall_size = np.array([ (wall.end.x - wall_mid.x - 0.5) * self._xy_scale, (wall.end.y - wall_mid.y - 0.5) * self._xy_scale, self._z_height / 2 ]) self._maze_body.add('geom', name='wall{}_{}'.format(wall_char, i), type='box', pos=wall_pos, size=wall_size, group=_WALL_GEOM_GROUP) self._make_wall_texturing_planes(wall_char, i, wall_pos, wall_size)
def _make_floor_variations(self, build_tile_geoms_fn=None): """Builds the floor tiles. Args: build_tile_geoms_fn: An optional callable returning floor tile geoms. If not passed, the floor will be built using a default covering method. Takes a kwarg `wall_char` that can be used control how active floor tiles are selected. """ main_floor_texture = np.random.choice(self._floor_textures) for variation in _DEFAULT_FLOOR_CHAR + string.ascii_uppercase: if variation not in self._maze.variations_layer: break if build_tile_geoms_fn is None: # Break the floor variation down to odd-sized tiles. tiles = covering.make_walls(self._maze.variations_layer, wall_char=variation, make_odd_sized_walls=True) else: tiles = build_tile_geoms_fn(wall_char=variation) # Sample a texture that's not the same as the main floor texture. variation_texture = main_floor_texture if variation != _DEFAULT_FLOOR_CHAR: if len(self._floor_textures) == 1: return else: while variation_texture is main_floor_texture: variation_texture = np.random.choice( self._floor_textures) for i, tile in enumerate(tiles): tile_mid = covering.GridCoordinates( (tile.start.y + tile.end.y - 1) / 2, (tile.start.x + tile.end.x - 1) / 2) tile_pos = np.array([ (tile_mid.x - self._x_offset) * self._xy_scale, -(tile_mid.y - self._y_offset) * self._xy_scale, 0.0 ]) tile_size = np.array([ (tile.end.x - tile_mid.x - 0.5) * self._xy_scale, (tile.end.y - tile_mid.y - 0.5) * self._xy_scale, self._xy_scale ]) if variation == _DEFAULT_FLOOR_CHAR: tile_name = 'floor_{}'.format(i) else: tile_name = 'floor_{}_{}'.format(variation, i) self._tile_geom_names[tile.start] = tile_name self._texturing_material_names.append(tile_name) self._texturing_geom_names.append(tile_name) material = self._mjcf_root.asset.add( 'material', name=tile_name, texture=variation_texture, texrepeat=(2 * tile_size[[0, 1]] / self._xy_scale)) self._mjcf_root.worldbody.add('geom', name=tile_name, type='plane', material=material, pos=tile_pos, size=tile_size, contype=0, conaffinity=0)