Skip to content

Commit

Permalink
draw cross line and fix cyclist length/width
Browse files Browse the repository at this point in the history
  • Loading branch information
Yunsong Zhou committed Apr 11, 2024
1 parent f2a9326 commit 07a31a2
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 138 deletions.
98 changes: 49 additions & 49 deletions metadrive/component/traffic_participants/cyclist.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,62 +73,62 @@ 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)

# Add some color to help debug
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
Expand Down
96 changes: 49 additions & 47 deletions metadrive/component/traffic_participants/pedestrian.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
86 changes: 44 additions & 42 deletions metadrive/component/vehicle/vehicle_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 07a31a2

Please sign in to comment.