| 56 | return carla.Vector2D(lat2y(a[0]), lon2x(a[1])) |
| 57 | |
| 58 | def spawn_imagery(client, zoom, min_lat, min_lon, max_lat, max_lon, offset): |
| 59 | bottom_left_id = deg2num(zoom, min_lat, min_lon) |
| 60 | top_right_id = deg2num(zoom, max_lat, max_lon) |
| 61 | top_left_id = (zoom, top_right_id[1], bottom_left_id[2]) |
| 62 | bottom_right_id = (zoom, bottom_left_id[1], top_right_id[2]) |
| 63 | |
| 64 | if bottom_right_id[1] >= top_left_id[1]: |
| 65 | height = bottom_right_id[1] - top_left_id[1] + 1 |
| 66 | else: |
| 67 | height = (top_left_id[1] + 1) + (2 ** zoom - bottom_right_id[1]) |
| 68 | |
| 69 | if bottom_right_id[2] >= top_left_id[2]: |
| 70 | width = bottom_right_id[2] - top_left_id[2] + 1 |
| 71 | else: |
| 72 | width = (top_left_id[2] + 1) + (2 ** zoom - bottom_right_id[2]) |
| 73 | |
| 74 | for row in range(top_left_id[1], bottom_right_id[1] + 1): |
| 75 | for column in range(top_left_id[2], bottom_right_id[2] + 1): |
| 76 | |
| 77 | path = IMAGERY_PATH/'{}/{}_{}.jpeg'.format(zoom, row, column) |
| 78 | |
| 79 | if not path.exists(): |
| 80 | print('Path not found! {}/{}_{}'.format(zoom, row, column)) |
| 81 | continue |
| 82 | |
| 83 | with path.open('rb') as f: |
| 84 | data = [ord(b) if isinstance(b, str) else b for b in f.read()] |
| 85 | |
| 86 | bounds_min = project(num2deg(zoom, row + 1, column)) + offset |
| 87 | bounds_min = carla.Vector3D(bounds_min.x, bounds_min.y, VERTICAL_OFFSET) |
| 88 | bounds_max = project(num2deg(zoom, row, column + 1)) + offset |
| 89 | bounds_max = carla.Vector3D(bounds_max.x, bounds_max.y, VERTICAL_OFFSET) |
| 90 | |
| 91 | client.get_world().spawn_dynamic_tile_mesh(bounds_min, bounds_max, data, 9) |
| 92 | |
| 93 | def main(args): |
| 94 | client = carla.Client(args.host, args.port) |