Skip to content

Commit

Permalink
Fix contact bug (#574)
Browse files Browse the repository at this point in the history
* fix-contact-bug

* engine core

* fix drawer

* format
  • Loading branch information
QuanyiLi committed Dec 7, 2023
1 parent 73187f6 commit b8a66c9
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 14 deletions.
3 changes: 2 additions & 1 deletion metadrive/component/vehicle/base_vehicle.py
Original file line number Diff line number Diff line change
Expand Up @@ -772,14 +772,15 @@ def _state_check(self):

# only for visualization detection
if self.render:
debug_static_world = self.engine.global_config["debug_static_world"] and self.engine.global_config["debug"]
res = rect_region_detection(
self.engine,
self.position,
np.rad2deg(self.heading_theta),
self.LENGTH,
self.WIDTH,
CollisionGroup.LaneSurface,
in_static_world=False
in_static_world=not debug_static_world
)
if not res.hasHit():
contacts.add(MetaDriveType.GROUND)
Expand Down
20 changes: 13 additions & 7 deletions metadrive/engine/core/draw.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from direct.directtools.DirectGeometry import LineNodePath
from metadrive.engine.asset_loader import AssetLoader
from panda3d.core import VBase4, NodePath
from panda3d.core import VBase4, NodePath, Material
from metadrive.constants import CamMask
from panda3d.core import LVecBase4f

Expand Down Expand Up @@ -30,15 +30,15 @@ def draw_lines(self, lineList, colorList=None):
self.create()


class ColorSphereNodePath:
class ColorSphereNodePath(NodePath):
def __init__(self, parent=None, scale=1):
super(ColorSphereNodePath, self).__init__("Point Debugger")
scale /= 10
from metadrive.engine.engine_utils import get_engine
self.scale = scale
self.engine = get_engine()
self.origin = NodePath("Point Debugger")
self.origin.hide(CamMask.Shadow)
self.origin.reparentTo(self.engine.render if parent is None else parent)
self.hide(CamMask.Shadow)
self.reparentTo(self.engine.render if parent is None else parent)
self._existing_points = []
self._dying_points = []

Expand All @@ -60,10 +60,16 @@ def draw_points(self, points, colors=None):
model = self.engine.loader.loadModel(AssetLoader.file_path("models", "sphere.egg"))
model.setScale(self.scale)
model.reparentTo(np)
material = Material()
if colors:
np.setColor(LVecBase4f(*colors[k]))
material.setBaseColor(LVecBase4f(*colors[k]))
else:
material.setBaseColor(LVecBase4f(1, 1, 1, 1))
material.setShininess(64)
# material.setEmission((1, 1, 1, 1))
np.setMaterial(material, True)
np.setPos(*point)
np.reparentTo(self.origin)
np.reparentTo(self)
self._existing_points.append(np)

def reset(self):
Expand Down
4 changes: 2 additions & 2 deletions metadrive/engine/core/engine_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,8 @@ def __init__(self, global_config):
use_occlusion_maps=False
)
self.pbrpipe.render_node = self.pbr_render
self.pbrpipe.render_node.set_antialias(AntialiasAttrib.M_auto)
self.pbrpipe._recompile_pbr()
# self.pbrpipe.render_node.set_antialias(AntialiasAttrib.M_auto)
# self.pbrpipe._recompile_pbr()
# self.pbrpipe.manager.cleanup()
#
# # filter
Expand Down
1 change: 1 addition & 0 deletions metadrive/tests/test_sensors/test_main_camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def test_main_camera(config, render=False):
start = time.time()
for i in range(1, 10):
o, r, tm, tc, info = env.step([0, 1])
assert "LANE_SURFACE_STREET" in env.vehicle.contact_results
assert env.observation_space.contains(o)
# Reverse
assert o["image"].shape == (config["height"], config["width"], 3, config["stack_size"])
Expand Down
8 changes: 4 additions & 4 deletions metadrive/tests/vis_env/vis_metadrive_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@
"start_seed": 74,
# "_disable_detector_mask":True,
# "debug_physics_world": True,
"debug": True,
# "debug": True,
# "global_light": False,
"debug_static_world": True,
# "debug_static_world": True,
"static_traffic_object": False,
"show_interface": True,
"random_agent_model": True,
"random_spawn_lane_index": False,
"random_lane_width": False,
# "image_observation": True,
"show_coordinates": True,
# "show_coordinates": True,
# "debug_static_world": True,
"manual_control": True,
"use_render": True,
Expand All @@ -31,7 +31,7 @@
"interface_panel": [],
"need_inverse_traffic": False,
"norm_pixel": True,
"map": 3,
"map": 1,
# "agent_policy": ExpertPolicy,
"random_traffic": False,
"map_region_size": 1024,
Expand Down

0 comments on commit b8a66c9

Please sign in to comment.