diff --git a/metadrive/component/pgblock/pg_block.py b/metadrive/component/pgblock/pg_block.py index c2f1af836..557b37586 100644 --- a/metadrive/component/pgblock/pg_block.py +++ b/metadrive/component/pgblock/pg_block.py @@ -250,7 +250,6 @@ def create_in_world(self): for _from, to_dict in graph.items(): for _to, lanes in to_dict.items(): for _id, lane in enumerate(lanes): - self._construct_lane(lane, (_from, _to, _id)) # choose_side is a two-elemental list, the first element is for left side, @@ -278,24 +277,14 @@ def _construct_broken_line(self, lane, lateral, line_color, line_type): ) self._node_path_list.extend(node_path_list) - def _construct_continuous_line(self, lane, lateral, line_color, line_type): + def _construct_continuous_line(self, points, line_color, line_type): """ We process straight line to several pieces by default, which can be optimized through overriding this function Lateral: left[-1/2 * width] or right[1/2 * width] """ - segment_num = int(lane.length / PGDrivableAreaProperty.LANE_SEGMENT_LENGTH) - if segment_num == 0: - start = lane.position(0, lateral) - end = lane.position(lane.length, lateral) - node_path_list = self._construct_lane_line_segment(start, end, line_color, line_type) - self._node_path_list.extend(node_path_list) - for segment in range(segment_num): - start = lane.position(PGDrivableAreaProperty.LANE_SEGMENT_LENGTH * segment, lateral) - if segment == segment_num - 1: - end = lane.position(lane.length, lateral) - else: - end = lane.position((segment + 1) * PGDrivableAreaProperty.LANE_SEGMENT_LENGTH, lateral) - node_path_list = self._construct_lane_line_segment(start, end, line_color, line_type) + for p_1_index, p_1 in enumerate(points[:-1]): + p_2 = points[p_1_index + 1] + node_path_list = self._construct_lane_line_segment(p_1, p_2, line_color, line_type) self._node_path_list.extend(node_path_list) def _generate_sidewalk_from_line(self, lane, sidewalk_height=None, lateral_direction=1): @@ -345,16 +334,17 @@ def _construct_lane_line_in_block(self, lane, construct_left_right=(True, True)) for idx, line_type, line_color, need, in zip([-1, 1], lane.line_types, lane.line_colors, construct_left_right): if not need: continue - lateral = idx * lane.width_at(0) / 2 + seg_len = PGDrivableAreaProperty.LANE_SEGMENT_LENGTH + lateral = idx * lane.width / 2 if line_type == PGLineType.CONTINUOUS: - self._construct_continuous_line(lane, lateral, line_color, line_type) + self._construct_continuous_line(lane.get_polyline(seg_len, lateral=lateral), line_color, line_type) elif line_type == PGLineType.BROKEN: self._construct_broken_line(lane, lateral, line_color, line_type) elif line_type == PGLineType.SIDE: - self._construct_continuous_line(lane, lateral, line_color, line_type) + self._construct_continuous_line(lane.get_polyline(seg_len, lateral=lateral), line_color, line_type) self._generate_sidewalk_from_line(lane) elif line_type == PGLineType.GUARDRAIL: - self._construct_continuous_line(lane, lateral, line_color, line_type) + self._construct_continuous_line(lane.get_polyline(seg_len, lateral=lateral), line_color, line_type) self._generate_sidewalk_from_line( lane, sidewalk_height=PGDrivableAreaProperty.GUARDRAIL_HEIGHT, lateral_direction=idx ) diff --git a/metadrive/component/road_network/node_road_network.py b/metadrive/component/road_network/node_road_network.py index 85f02c642..68b4adb8e 100644 --- a/metadrive/component/road_network/node_road_network.py +++ b/metadrive/component/road_network/node_road_network.py @@ -300,10 +300,16 @@ def find_entry_exit(): ret = {} for _from, _to_dict in self.graph.items(): for _to, lanes in _to_dict.items(): - for k, lane in enumerate(lanes): - left_n = ["{}".format(l.index) for l in lanes[:k]] - right_n = ["{}".format(l.index) for l in lanes[k + 1:]] - ret["{}".format(lane.index)] = { + for k, lane, in enumerate(lanes): + if _from == Decoration.start and _to == Decoration.end: + left_n = [] + right_n = [] + id = "{}_decoration_{}".format(lane.index, k) + else: + left_n = ["{}".format(l.index) for l in lanes[:k]] + right_n = ["{}".format(l.index) for l in lanes[k + 1:]] + id = "{}".format(lane.index) + ret[id] = { SD.POLYLINE: lane.get_polyline(interval), SD.POLYGON: lane.polygon, # Convert to EdgeNetwork diff --git a/metadrive/tests/test_export_record_scenario/test_connectivity.py b/metadrive/tests/test_export_record_scenario/test_connectivity.py index fac221aaa..edaf5ed52 100644 --- a/metadrive/tests/test_export_record_scenario/test_connectivity.py +++ b/metadrive/tests/test_export_record_scenario/test_connectivity.py @@ -67,7 +67,10 @@ def test_search_path(render_export_env=False, render_load_env=False): edge_roadnet = copy.deepcopy(env.current_map.road_network) all_node_lanes = node_roadnet.get_all_lanes() all_edge_lanes = edge_roadnet.get_all_lanes() - diff = set(["{}".format(l.index) for l in all_node_lanes]) - set(["{}".format(l.index) for l in all_edge_lanes]) + diff = ( + set(["{}".format(l.index) if "decoration" not in l.index else "" for l in all_node_lanes]) - + set(["{}".format(l.index) if "decoration" not in l.index else "" for l in all_edge_lanes]) + ) assert len(diff) == 0 nodes = node_roadnet.shortest_path('>', "8S0_0_") print(nodes) diff --git a/metadrive/tests/test_functionality/test_load_carla_town.py b/metadrive/tests/test_functionality/_test_load_carla_town.py similarity index 91% rename from metadrive/tests/test_functionality/test_load_carla_town.py rename to metadrive/tests/test_functionality/_test_load_carla_town.py index d5199ebb8..e0781afca 100644 --- a/metadrive/tests/test_functionality/test_load_carla_town.py +++ b/metadrive/tests/test_functionality/_test_load_carla_town.py @@ -4,9 +4,13 @@ from metadrive.engine.asset_loader import initialize_asset_loader from metadrive.tests.vis_block.vis_block_base import TestBlock from metadrive.utils.opendrive.map_load import load_opendrive_map +""" +AS we now add opendrive support through SUMO API, this test script is deprecated +""" -def test_load_carla_town(): + +def _test_load_carla_town(): """ Test opendrive related feature Returns: None diff --git a/metadrive/tests/vis_env/vis_metadrive_env.py b/metadrive/tests/vis_env/vis_metadrive_env.py index c7797eff1..ba2f719f4 100644 --- a/metadrive/tests/vis_env/vis_metadrive_env.py +++ b/metadrive/tests/vis_env/vis_metadrive_env.py @@ -6,8 +6,8 @@ env = MetaDriveEnv( { "num_scenarios": 1, - "traffic_density": 0, - "start_seed": 74, + "traffic_density": 0.1, + "start_seed": 0, # "_disable_detector_mask":True, # "debug_physics_world": True, "debug": True, @@ -23,7 +23,7 @@ # "debug_static_world": True, "manual_control": True, "use_render": True, - "use_mesh_terrain": False, + # "use_mesh_terrain": True, "full_size_mesh": True, "accident_prob": 0, "decision_repeat": 5, @@ -31,7 +31,7 @@ "interface_panel": [], "need_inverse_traffic": False, "norm_pixel": True, - "map": 1, + "map": "rrRRr", # "agent_policy": ExpertPolicy, "random_traffic": False, "map_region_size": 1024, @@ -110,7 +110,7 @@ def lift_terrain_x(): start = time.time() - o, _ = env.reset(seed=74) + o, _ = env.reset() env.engine.accept("~", env.engine.terrain.reload_terrain_shader) # if env.config["render_pipeline"]: # env.engine.accept("5", env.engine.render_pipeline.reload_shaders)