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 cf8d287 commit f2a9326
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 2 deletions.
55 changes: 54 additions & 1 deletion metadrive/component/traffic_participants/cyclist.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
from metadrive.constants import CollisionGroup
from metadrive.engine.asset_loader import AssetLoader
from metadrive.engine.physics_node import BaseRigidBodyNode

from panda3d.core import TransparencyAttrib, LineSegs, NodePath, BoundingHexahedron
from panda3d.core import Material, Vec3, LVecBase4

class Cyclist(BaseTrafficParticipant):
MASS = 80 # kg
Expand Down Expand Up @@ -62,6 +63,7 @@ class CyclistBoundingBox(BaseTrafficParticipant):

def __init__(self, position, heading_theta, random_seed, name=None, **kwargs):
config = {"width": kwargs["width"], "length": kwargs["length"], "height": kwargs["height"]}
# config = {"width": kwargs["length"], "length": kwargs["width"], "height": kwargs["height"]}
super(CyclistBoundingBox, self).__init__(position, heading_theta, random_seed, name=name, config=config)
self.set_metadrive_type(self.TYPE_NAME)
n = BaseRigidBodyNode(self.name, self.TYPE_NAME)
Expand All @@ -71,12 +73,63 @@ 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)

color = sns.color_palette("colorblind")
color.remove(color[2]) # Remove the green and leave it for special vehicle
idx = 0
Expand Down
52 changes: 51 additions & 1 deletion metadrive/component/traffic_participants/pedestrian.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
from metadrive.engine.asset_loader import AssetLoader
from metadrive.engine.physics_node import BaseRigidBodyNode
from metadrive.utils.math import norm

from panda3d.core import TransparencyAttrib, LineSegs, NodePath, BoundingHexahedron
from panda3d.core import Material, Vec3, LVecBase4

class Pedestrian(BaseTrafficParticipant):
MASS = 70 # kg
Expand Down Expand Up @@ -156,6 +157,55 @@ def __init__(self, position, heading_theta, width, length, height, random_seed=N
# Add some color to help debug
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)

color = sns.color_palette("colorblind")
color.remove(color[2]) # Remove the green and leave it for special vehicle
idx = 0
Expand Down

0 comments on commit f2a9326

Please sign in to comment.