From 07a31a28809e4cb461711223563d80eabc712873 Mon Sep 17 00:00:00 2001 From: Yunsong Zhou Date: Thu, 11 Apr 2024 16:27:30 -0700 Subject: [PATCH] draw cross line and fix cyclist length/width --- .../component/traffic_participants/cyclist.py | 98 +++++++++---------- .../traffic_participants/pedestrian.py | 96 +++++++++--------- metadrive/component/vehicle/vehicle_type.py | 86 ++++++++-------- 3 files changed, 142 insertions(+), 138 deletions(-) diff --git a/metadrive/component/traffic_participants/cyclist.py b/metadrive/component/traffic_participants/cyclist.py index ecb3b7556..f5440d6cd 100644 --- a/metadrive/component/traffic_participants/cyclist.py +++ b/metadrive/component/traffic_participants/cyclist.py @@ -73,8 +73,6 @@ def __init__(self, position, heading_theta, random_seed, name=None, **kwargs): if self.render: model = AssetLoader.loader.loadModel(AssetLoader.file_path("models", "box.bam")) model.setScale((self.WIDTH, self.LENGTH, self.HEIGHT)) - # model.setScale((self.LENGTH, self.WIDTH, self.LENGTH)) - print("CyclistBoundingBox: ", self.LENGTH, self.WIDTH, self.HEIGHT) model.setTwoSided(False) self._instance = model.instanceTo(self.origin) @@ -82,53 +80,55 @@ def __init__(self, position, heading_theta, random_seed, name=None, **kwargs): from panda3d.core import Material, LVecBase4 import seaborn as sns - # ========== Draw the contour of the bounding box ========== - # Draw the bottom of the car first - line_seg = LineSegs("bounding_box_contour1") - zoffset = model.getZ() - line_seg.setThickness(2) - line_color = [0.0, 0.0, 0.0] - out_offset = 0.02 - w = self.WIDTH / 2 + out_offset - l = self.LENGTH / 2 + out_offset - h = self.HEIGHT / 2 + out_offset - line_seg.moveTo(w, l, h + zoffset) - line_seg.drawTo(-w, l, h + zoffset) - line_seg.drawTo(-w, l, -h + zoffset) - line_seg.drawTo(w, l, -h + zoffset) - line_seg.drawTo(w, l, h + zoffset) - - # draw cross line - line_seg.moveTo(w, l, h + zoffset) - line_seg.drawTo(w, -l, -h + zoffset) - line_seg.moveTo(w, -l, h + zoffset) - line_seg.drawTo(w, l, -h + zoffset) - - line_seg.moveTo(w, -l, h + zoffset) - line_seg.drawTo(-w, -l, h + zoffset) - line_seg.drawTo(-w, -l, -h + zoffset) - line_seg.drawTo(w, -l, -h + zoffset) - line_seg.drawTo(w, -l, h + zoffset) - - # draw vertical & horizontal line - line_seg.moveTo(-w, l, 0 + zoffset) - line_seg.drawTo(-w, -l, 0 + zoffset) - line_seg.moveTo(-w, 0, h + zoffset) - line_seg.drawTo(-w, 0, -h + zoffset) - - line_seg.moveTo(w, l, h + zoffset) - line_seg.drawTo(w, -l, h + zoffset) - line_seg.moveTo(-w, l, h + zoffset) - line_seg.drawTo(-w, -l, h + zoffset) - line_seg.moveTo(-w, l, -h + zoffset) - line_seg.drawTo(-w, -l, -h + zoffset) - line_seg.moveTo(w, l, -h + zoffset) - line_seg.drawTo(w, -l, -h + zoffset) - line_np = NodePath(line_seg.create(True)) - line_material = Material() - line_material.setBaseColor(LVecBase4(*line_color[:3], 1)) - line_np.setMaterial(line_material, True) - line_np.reparentTo(self.origin) + show_contour = self.config["show_contour"] if "show_contour" in self.config else False + if show_contour: + # ========== Draw the contour of the bounding box ========== + # Draw the bottom of the car first + line_seg = LineSegs("bounding_box_contour1") + zoffset = model.getZ() + line_seg.setThickness(2) + line_color = [0.0, 0.0, 0.0] + out_offset = 0.02 + w = self.WIDTH / 2 + out_offset + l = self.LENGTH / 2 + out_offset + h = self.HEIGHT / 2 + out_offset + line_seg.moveTo(w, l, h + zoffset) + line_seg.drawTo(-w, l, h + zoffset) + line_seg.drawTo(-w, l, -h + zoffset) + line_seg.drawTo(w, l, -h + zoffset) + line_seg.drawTo(w, l, h + zoffset) + + # draw cross line + line_seg.moveTo(w, l, h + zoffset) + line_seg.drawTo(w, -l, -h + zoffset) + line_seg.moveTo(w, -l, h + zoffset) + line_seg.drawTo(w, l, -h + zoffset) + + line_seg.moveTo(w, -l, h + zoffset) + line_seg.drawTo(-w, -l, h + zoffset) + line_seg.drawTo(-w, -l, -h + zoffset) + line_seg.drawTo(w, -l, -h + zoffset) + line_seg.drawTo(w, -l, h + zoffset) + + # draw vertical & horizontal line + line_seg.moveTo(-w, l, 0 + zoffset) + line_seg.drawTo(-w, -l, 0 + zoffset) + line_seg.moveTo(-w, 0, h + zoffset) + line_seg.drawTo(-w, 0, -h + zoffset) + + line_seg.moveTo(w, l, h + zoffset) + line_seg.drawTo(w, -l, h + zoffset) + line_seg.moveTo(-w, l, h + zoffset) + line_seg.drawTo(-w, -l, h + zoffset) + line_seg.moveTo(-w, l, -h + zoffset) + line_seg.drawTo(-w, -l, -h + zoffset) + line_seg.moveTo(w, l, -h + zoffset) + line_seg.drawTo(w, -l, -h + zoffset) + line_np = NodePath(line_seg.create(True)) + line_material = Material() + line_material.setBaseColor(LVecBase4(*line_color[:3], 1)) + line_np.setMaterial(line_material, True) + line_np.reparentTo(self.origin) color = sns.color_palette("colorblind") color.remove(color[2]) # Remove the green and leave it for special vehicle diff --git a/metadrive/component/traffic_participants/pedestrian.py b/metadrive/component/traffic_participants/pedestrian.py index 1809112d9..5955f57e2 100644 --- a/metadrive/component/traffic_participants/pedestrian.py +++ b/metadrive/component/traffic_participants/pedestrian.py @@ -158,53 +158,55 @@ def __init__(self, position, heading_theta, width, length, height, random_seed=N from panda3d.core import Material import seaborn as sns - # ========== Draw the contour of the bounding box ========== - # Draw the bottom of the car first - line_seg = LineSegs("bounding_box_contour1") - zoffset = model.getZ() - line_seg.setThickness(2) - line_color = [0.0, 0.0, 1.0] - out_offset = 0.02 - w = self.WIDTH / 2 + out_offset - l = self.LENGTH / 2 + out_offset - h = self.HEIGHT / 2 + out_offset - line_seg.moveTo(w, l, h + zoffset) - line_seg.drawTo(-w, l, h + zoffset) - line_seg.drawTo(-w, l, -h + zoffset) - line_seg.drawTo(w, l, -h + zoffset) - line_seg.drawTo(w, l, h + zoffset) - - # draw cross line - line_seg.moveTo(w, l, h + zoffset) - line_seg.drawTo(w, -l, -h + zoffset) - line_seg.moveTo(w, -l, h + zoffset) - line_seg.drawTo(w, l, -h + zoffset) - - line_seg.moveTo(w, -l, h + zoffset) - line_seg.drawTo(-w, -l, h + zoffset) - line_seg.drawTo(-w, -l, -h + zoffset) - line_seg.drawTo(w, -l, -h + zoffset) - line_seg.drawTo(w, -l, h + zoffset) - - # draw vertical & horizontal line - line_seg.moveTo(-w, l, 0 + zoffset) - line_seg.drawTo(-w, -l, 0 + zoffset) - line_seg.moveTo(-w, 0, h + zoffset) - line_seg.drawTo(-w, 0, -h + zoffset) - - line_seg.moveTo(w, l, h + zoffset) - line_seg.drawTo(w, -l, h + zoffset) - line_seg.moveTo(-w, l, h + zoffset) - line_seg.drawTo(-w, -l, h + zoffset) - line_seg.moveTo(-w, l, -h + zoffset) - line_seg.drawTo(-w, -l, -h + zoffset) - line_seg.moveTo(w, l, -h + zoffset) - line_seg.drawTo(w, -l, -h + zoffset) - line_np = NodePath(line_seg.create(True)) - line_material = Material() - line_material.setBaseColor(LVecBase4(*line_color[:3], 1)) - line_np.setMaterial(line_material, True) - line_np.reparentTo(self.origin) + show_contour = self.config["show_contour"] if "show_contour" in self.config else False + if show_contour: + # ========== Draw the contour of the bounding box ========== + # Draw the bottom of the car first + line_seg = LineSegs("bounding_box_contour1") + zoffset = model.getZ() + line_seg.setThickness(2) + line_color = [0.0, 0.0, 1.0] + out_offset = 0.02 + w = self.WIDTH / 2 + out_offset + l = self.LENGTH / 2 + out_offset + h = self.HEIGHT / 2 + out_offset + line_seg.moveTo(w, l, h + zoffset) + line_seg.drawTo(-w, l, h + zoffset) + line_seg.drawTo(-w, l, -h + zoffset) + line_seg.drawTo(w, l, -h + zoffset) + line_seg.drawTo(w, l, h + zoffset) + + # draw cross line + line_seg.moveTo(w, l, h + zoffset) + line_seg.drawTo(w, -l, -h + zoffset) + line_seg.moveTo(w, -l, h + zoffset) + line_seg.drawTo(w, l, -h + zoffset) + + line_seg.moveTo(w, -l, h + zoffset) + line_seg.drawTo(-w, -l, h + zoffset) + line_seg.drawTo(-w, -l, -h + zoffset) + line_seg.drawTo(w, -l, -h + zoffset) + line_seg.drawTo(w, -l, h + zoffset) + + # draw vertical & horizontal line + line_seg.moveTo(-w, l, 0 + zoffset) + line_seg.drawTo(-w, -l, 0 + zoffset) + line_seg.moveTo(-w, 0, h + zoffset) + line_seg.drawTo(-w, 0, -h + zoffset) + + line_seg.moveTo(w, l, h + zoffset) + line_seg.drawTo(w, -l, h + zoffset) + line_seg.moveTo(-w, l, h + zoffset) + line_seg.drawTo(-w, -l, h + zoffset) + line_seg.moveTo(-w, l, -h + zoffset) + line_seg.drawTo(-w, -l, -h + zoffset) + line_seg.moveTo(w, l, -h + zoffset) + line_seg.drawTo(w, -l, -h + zoffset) + line_np = NodePath(line_seg.create(True)) + line_material = Material() + line_material.setBaseColor(LVecBase4(*line_color[:3], 1)) + line_np.setMaterial(line_material, True) + line_np.reparentTo(self.origin) color = sns.color_palette("colorblind") color.remove(color[2]) # Remove the green and leave it for special vehicle diff --git a/metadrive/component/vehicle/vehicle_type.py b/metadrive/component/vehicle/vehicle_type.py index 601e5b6b5..d4de1189c 100644 --- a/metadrive/component/vehicle/vehicle_type.py +++ b/metadrive/component/vehicle/vehicle_type.py @@ -318,48 +318,50 @@ def _add_visualization(self): car_model.setHpr(*HPR) car_model.instanceTo(self.origin) - # ========== Draw the contour of the bounding box ========== - # Draw the bottom of the car first - line_seg = LineSegs("bounding_box_contour1") - zoffset = car_model.getZ() - line_seg.setThickness(2) - line_color = [1.0, 0.0, 0.0] - out_offset = 0.02 - w = self.WIDTH / 2 + out_offset - l = self.LENGTH / 2 + out_offset - h = self.HEIGHT / 2 + out_offset - line_seg.moveTo(w, l, h + zoffset) - line_seg.drawTo(-w, l, h + zoffset) - line_seg.drawTo(-w, l, -h + zoffset) - line_seg.drawTo(w, l, -h + zoffset) - line_seg.drawTo(w, l, h + zoffset) - line_seg.drawTo(-w, l, -h + zoffset) - line_seg.moveTo(-w, l, h + zoffset) - line_seg.drawTo(w, l, -h + zoffset) - - line_seg.moveTo(w, -l, h + zoffset) - line_seg.drawTo(-w, -l, h + zoffset) - line_seg.drawTo(-w, -l, -h + zoffset) - line_seg.drawTo(w, -l, -h + zoffset) - line_seg.drawTo(w, -l, h + zoffset) - line_seg.moveTo(-w, -l, 0 + zoffset) - line_seg.drawTo(w, -l, 0 + zoffset) - line_seg.moveTo(0, -l, h + zoffset) - line_seg.drawTo(0, -l, -h + zoffset) - - line_seg.moveTo(w, l, h + zoffset) - line_seg.drawTo(w, -l, h + zoffset) - line_seg.moveTo(-w, l, h + zoffset) - line_seg.drawTo(-w, -l, h + zoffset) - line_seg.moveTo(-w, l, -h + zoffset) - line_seg.drawTo(-w, -l, -h + zoffset) - line_seg.moveTo(w, l, -h + zoffset) - line_seg.drawTo(w, -l, -h + zoffset) - line_np = NodePath(line_seg.create(True)) - line_material = Material() - line_material.setBaseColor(LVecBase4(*line_color[:3], 1)) - line_np.setMaterial(line_material, True) - line_np.reparentTo(self.origin) + show_contour = self.config["show_contour"] if "show_contour" in self.config else False + if show_contour: + # ========== Draw the contour of the bounding box ========== + # Draw the bottom of the car first + line_seg = LineSegs("bounding_box_contour1") + zoffset = car_model.getZ() + line_seg.setThickness(2) + line_color = [1.0, 0.0, 0.0] + out_offset = 0.02 + w = self.WIDTH / 2 + out_offset + l = self.LENGTH / 2 + out_offset + h = self.HEIGHT / 2 + out_offset + line_seg.moveTo(w, l, h + zoffset) + line_seg.drawTo(-w, l, h + zoffset) + line_seg.drawTo(-w, l, -h + zoffset) + line_seg.drawTo(w, l, -h + zoffset) + line_seg.drawTo(w, l, h + zoffset) + line_seg.drawTo(-w, l, -h + zoffset) + line_seg.moveTo(-w, l, h + zoffset) + line_seg.drawTo(w, l, -h + zoffset) + + line_seg.moveTo(w, -l, h + zoffset) + line_seg.drawTo(-w, -l, h + zoffset) + line_seg.drawTo(-w, -l, -h + zoffset) + line_seg.drawTo(w, -l, -h + zoffset) + line_seg.drawTo(w, -l, h + zoffset) + line_seg.moveTo(-w, -l, 0 + zoffset) + line_seg.drawTo(w, -l, 0 + zoffset) + line_seg.moveTo(0, -l, h + zoffset) + line_seg.drawTo(0, -l, -h + zoffset) + + line_seg.moveTo(w, l, h + zoffset) + line_seg.drawTo(w, -l, h + zoffset) + line_seg.moveTo(-w, l, h + zoffset) + line_seg.drawTo(-w, -l, h + zoffset) + line_seg.moveTo(-w, l, -h + zoffset) + line_seg.drawTo(-w, -l, -h + zoffset) + line_seg.moveTo(w, l, -h + zoffset) + line_seg.drawTo(w, -l, -h + zoffset) + line_np = NodePath(line_seg.create(True)) + line_material = Material() + line_material.setBaseColor(LVecBase4(*line_color[:3], 1)) + line_np.setMaterial(line_material, True) + line_np.reparentTo(self.origin) if self.config["random_color"]: material = Material()