Skip to content

Commit

Permalink
automatically download asset
Browse files Browse the repository at this point in the history
  • Loading branch information
QuanyiLi committed Aug 22, 2023
1 parent 3789e7b commit b58863f
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@
/metadrive/assets/textures/heightfield.png
**/test_read_copy_waymo
/metadrive/tests/vis_functionality/*.png
/assets/
**/assets/
6 changes: 2 additions & 4 deletions metadrive/component/sensors/depth_camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class DepthCamera(BaseCamera):
GROUND = None
GROUND_MODEL = None

def __init__(self, engine, width, height, cuda=False):
def __init__(self, engine, width, height, *, cuda=False):
self.BUFFER_W, self.BUFFER_H = width, height
self.VIEW_GROUND = True # default true
super(DepthCamera, self).__init__(engine, False, cuda)
Expand Down Expand Up @@ -48,11 +48,9 @@ def __init__(self, engine, width, height, cuda=False):
if self.VIEW_GROUND:
ground = PNMImage(257, 257, 4)
ground.fill(1., 1., 1.)
ground_tex = Texture("white lane line")
ground_tex.load(ground)

self.GROUND = GeoMipTerrain("mySimpleTerrain")
self.GROUND.setHeightfield(ground_tex)
self.GROUND.setHeightfield(ground)
self.GROUND.setAutoFlatten(GeoMipTerrain.AFMStrong)
# terrain.setBruteforce(True)
# # Since the terrain is a texture, shader will not calculate the depth information, we add a moving terrain
Expand Down
2 changes: 1 addition & 1 deletion metadrive/component/sensors/mini_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class MiniMap(BaseCamera):
CAM_MASK = CamMask.MiniMap
display_region_size = [0., 1 / 3, 0.8, 1.0]

def __init__(self, engine, width, height, z_pos, cuda=False):
def __init__(self, engine, width, height, z_pos, *, cuda=False):
self.BUFFER_W, self.BUFFER_H, height = width, height, z_pos
super(MiniMap, self).__init__(engine=engine, need_cuda=cuda)

Expand Down
2 changes: 1 addition & 1 deletion metadrive/component/sensors/rgb_camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class RGBCamera(BaseCamera):
CAM_MASK = CamMask.RgbCam
PBR_ADAPT = False

def __init__(self, engine, width, height, cuda=False):
def __init__(self, engine, width, height, *, cuda=False):
self.BUFFER_W, self.BUFFER_H = width, height
super(RGBCamera, self).__init__(engine, True, cuda)
cam = self.get_cam()
Expand Down
7 changes: 4 additions & 3 deletions metadrive/engine/core/engine_core.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import logging
from metadrive.render_pipeline.rpcore.rpobject import RPObject
import sys
import time
from typing import Optional, Union, Tuple
Expand All @@ -22,6 +21,7 @@
from metadrive.engine.core.sky_box import SkyBox
from metadrive.engine.core.terrain import Terrain
from metadrive.render_pipeline.rpcore import RenderPipeline
from metadrive.render_pipeline.rpcore.rpobject import RPObject
from metadrive.utils.utils import is_mac, setup_logger


Expand Down Expand Up @@ -502,7 +502,8 @@ def get_sensor(self, sensor_id):

def add_image_sensor(self, name: str, cls, args):
if self.global_config["image_on_cuda"] and name == self.global_config["vehicle_config"]["image_source"]:
args.append(True)
sensor = cls(self, *args)
sensor = cls(self, *args, cuda=True)
else:
sensor = cls(self, *args, cuda=False)
assert isinstance(sensor, ImageBuffer), "This API is for adding image sensor"
self.sensors[name] = sensor
5 changes: 3 additions & 2 deletions metadrive/tests/vis_functionality/vis_depth_cam_ground.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ def get_image(env):
"use_render": True,
"image_observation": True,
"rgb_clip": True,
"interface_panel": [DepthCamera, VehiclePanel],
"vehicle_config": dict(depth_camera=(800, 600, True), rgb_camera=(800, 600), image_source="depth_camera"),
"interface_panel": ["depth_camera"],
"sensors": dict(depth_camera=(DepthCamera, 800, 600)),
"vehicle_config": dict(image_source="depth_camera"),
# "map_config": {
# BaseMap.GENERATE_TYPE: MapGenerateMethod.BIG_BLOCK_NUM,
# BaseMap.GENERATE_CONFIG: 12,
Expand Down
26 changes: 12 additions & 14 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import sys
from os import path

import os
import zipfile
import urllib.request
from setuptools import setup, find_namespace_packages # This should be place at top!

ROOT_DIR = os.path.dirname(__file__)
Expand All @@ -28,23 +31,17 @@ def is_win():

""" ===== Remember to modify the PG_EDITION at first ====="""
version = "0.3.0.1"

import os
import zipfile
import requests

ASSET_URL = "https://github.com/metadriverse/metadrive/releases/download/MetaDrive-0.3.0.1/assets.zip"

def post_install():
ASSET_URL = "https://github.com/metadriverse/metadrive/releases/download/MetaDrive-0.3.0.1/assets.zip"
TARGET_DIR = os.path.join(os.path.dirname(__file__), 'metadrive', 'assets')

# Fetch the zip file from Google Drive
response = requests.get(ASSET_URL, stream=True)
TARGET_DIR = os.path.join(os.path.dirname(__file__), 'metadrive')
if os.path.exists(os.path.join(TARGET_DIR, "assets")):
return
zip_path = os.path.join(TARGET_DIR, 'assets.zip')

with open(zip_path, 'wb') as f:
for chunk in response.iter_content(chunk_size=8192):
f.write(chunk)
# Fetch the zip file
print("Retrieve the assets from {}".format(ASSET_URL))
urllib.request.urlretrieve(ASSET_URL, zip_path)

# Extract the zip file to the desired location
with zipfile.ZipFile(zip_path, 'r') as zip_ref:
Expand Down Expand Up @@ -91,7 +88,6 @@ def post_install():
"aioboto3"
]


# Or try:
# pip install git+https://github.com/waymo-research/waymo-open-dataset.git
waymo_requirement = [
Expand Down Expand Up @@ -138,6 +134,8 @@ def post_install():
"""
How to publish to pypi? Noted by Zhenghao in Dec 27, 2020.
Note: make sure you have the assets dir locally. we will include the assets with the .wheel file
0. Rename version in metadrive/constants.py and setup.py
1. Remove old files and ext_modules from setup() to get a clean wheel for all platforms in py3-none-any.wheel
Expand Down

0 comments on commit b58863f

Please sign in to comment.