Skip to content

Moves meshes in the RayCaster to classvar to be shared between sensors #2183

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

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Changes from 6 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
fa22292
move meshes to classvar
pascal-roth Mar 28, 2025
4c7c4fb
Merge branch 'main' into fearture/mesh-storing-raycaster
pascal-roth Mar 31, 2025
58d344e
Update source/isaaclab/isaaclab/sensors/ray_caster/ray_caster.py
pascal-roth Mar 31, 2025
28ee6a7
Merge branch 'main' into fearture/mesh-storing-raycaster
pascal-roth Mar 31, 2025
abc7073
Merge branch 'fearture/mesh-storing-raycaster' of github.com:pascal-r…
pascal-roth Mar 31, 2025
971f449
fix
pascal-roth Mar 31, 2025
4e83850
start to add test
pascal-roth Apr 7, 2025
d07e430
test working
pascal-roth Apr 7, 2025
afcef7d
Merge branch 'main' into fearture/mesh-storing-raycaster
pascal-roth Apr 7, 2025
1b78363
Merge branch 'main' into fearture/mesh-storing-raycaster
kellyguo11 Apr 7, 2025
7de6dbb
Merge branch 'main' into fearture/mesh-storing-raycaster
kellyguo11 Apr 8, 2025
ec46bf0
Merge branch 'main' into fearture/mesh-storing-raycaster
pascal-roth Apr 10, 2025
89f13fc
Merge branch 'main' into fearture/mesh-storing-raycaster
pascal-roth Apr 15, 2025
f8c3723
Merge branch 'main' into fearture/mesh-storing-raycaster
kellyguo11 May 13, 2025
390f5e6
Merge branch 'main' into fearture/mesh-storing-raycaster
kellyguo11 May 14, 2025
e40569f
Merge branch 'main' into fearture/mesh-storing-raycaster
pascal-roth May 14, 2025
ba80e13
Merge branch 'main' into fearture/mesh-storing-raycaster
kellyguo11 May 15, 2025
746a65d
Merge branch 'main' into fearture/mesh-storing-raycaster
pascal-roth May 15, 2025
89bde1a
Merge branch 'main' into fearture/mesh-storing-raycaster
kellyguo11 May 16, 2025
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
33 changes: 30 additions & 3 deletions source/isaaclab/isaaclab/sensors/ray_caster/ray_caster.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import re
import torch
from collections.abc import Sequence
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, ClassVar

import omni.log
import omni.physics.tensors.impl.api as physx
Expand Down Expand Up @@ -49,6 +49,22 @@ class RayCaster(SensorBase):
cfg: RayCasterCfg
"""The configuration parameters."""

# Class variables to share meshes and mesh_views across instances
meshes: ClassVar[dict[str, wp.Mesh]] = {}
"""A dictionary to store warp meshes for raycasting, shared across all instances.

The keys correspond to the prim path for the meshes, and values are the corresponding warp Mesh objects.
"""

mesh_views: ClassVar[dict[str, XFormPrim | physx.ArticulationView | physx.RigidBodyView]] = {}
"""A dictionary to store mesh views for raycasting, shared across all instances.

The keys correspond to the prim path for the mesh views, and values are the corresponding view objects.
"""

_instance_count: ClassVar[int] = 0
"""A counter to track the number of RayCaster instances, used to manage class variable lifecycle."""

def __init__(self, cfg: RayCasterCfg):
"""Initializes the ray-caster object.

Expand All @@ -69,8 +85,9 @@ def __init__(self, cfg: RayCasterCfg):
super().__init__(cfg)
# Create empty variables for storing output data
self._data = RayCasterData()
# the warp meshes used for raycasting.
self.meshes: dict[str, wp.Mesh] = {}

# increment the instance count
RayCaster._instance_count += 1

def __str__(self) -> str:
"""Returns: A string containing information about the instance."""
Expand Down Expand Up @@ -157,6 +174,10 @@ def _initialize_warp_meshes(self):

# read prims to ray-cast
for mesh_prim_path in self.cfg.mesh_prim_paths:
# check if mesh already casted into warp mesh
if mesh_prim_path in RayCaster.meshes:
continue

# check if the prim is a plane - handle PhysX plane as a special case
# if a plane exists then we need to create an infinite mesh that is a plane
mesh_prim = sim_utils.get_first_matching_child_prim(
Expand Down Expand Up @@ -289,3 +310,9 @@ def _invalidate_initialize_callback(self, event):
# set all existing views to None to invalidate them
self._physics_sim_view = None
self._view = None

def __del__(self):
RayCaster._instance_count -= 1
if RayCaster._instance_count == 0:
RayCaster.meshes.clear()
RayCaster.mesh_views.clear()
Loading