-
Beta Was this translation helpful? Give feedback.
Answered by
njroussel
Feb 27, 2025
Replies: 1 comment 2 replies
-
Hi @itsghaniz This is pretty awkward to do. Here's how I'd go about it, it relies on the fact that we have unique import mitsuba as mi
import drjit as dr
mi.set_variant('cuda_ad_rgb')
# Find the `ShapePtr` of the object you're interested in
scene = mi.load_dict(mi.cornell_box())
large_box_ptr = None
for shape in scene.shapes():
if shape.id() == "large-box": # arbitrary choice
large_box_ptr = mi.ShapePtr(shape)
assert large_box_ptr is not None
# Trace a bunch of rays
x = dr.linspace(mi.Float, 0, 1, 10)
y = dr.linspace(mi.Float, 0, 1, 10)
points = dr.meshgrid(x, y)
ray, _ = scene.sensors()[0].sample_ray(
time=0.,
sample1=0.,
sample2=points,
sample3=mi.Vector2f(0.0)
)
si = scene.ray_intersect(ray)
# Keep only those that hit our shape
mask = si.is_valid() & (si.shape == large_box_ptr)
valid_idx = dr.compress(mask)
valid_si = dr.gather(mi.SurfaceInteraction3f, si, valid_idx)
# Check that `valid_si` only has intersections with the large box
assert dr.width(valid_si) > 0
for i in range(dr.width(valid_si)):
shape_scalar = dr.slice(valid_si.shape, i)
assert shape_scalar.id() == 'large-box' |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
merlinND
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @itsghaniz
This is pretty awkward to do.
Here's how I'd go about it, it relies on the fact that we have unique
ShapePtr
identifiers for each shape object: