Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ramp rendering #759

Merged
merged 6 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 9 additions & 19 deletions metadrive/component/pgblock/pg_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
)
Expand Down
14 changes: 10 additions & 4 deletions metadrive/component/road_network/node_road_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions metadrive/tests/vis_env/vis_metadrive_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -23,15 +23,15 @@
# "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,
"daytime": "19:00",
"interface_panel": [],
"need_inverse_traffic": False,
"norm_pixel": True,
"map": 1,
"map": "rrRRr",
# "agent_policy": ExpertPolicy,
"random_traffic": False,
"map_region_size": 1024,
Expand Down Expand Up @@ -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)
Expand Down
Loading