Scene
Scene construction and management in RayD
Overview#
Scene is the top-level container for RayD. It holds meshes, builds and manages the OptiX BVH, and exposes all ray and edge queries.
import rayd as rd
import drjit as dr
rd.set_device(0)
scene = rd.Scene()
scene.add_mesh(mesh)
scene.build()Constructor#
rd.Scene(edge_bvh_backend="optix")| Parameter | Type | Default | Description |
|---|---|---|---|
edge_bvh_backend | str | "optix" | Backend for the edge BVH acceleration structure |
Setup Methods#
scene.add_mesh(mesh, dynamic=False) — Add a Mesh to the scene. Call before scene.build().
scene.build() — Build the OptiX BVH and edge acceleration structure. Must be called before any queries.
scene.sync() — Sync the BVH after mesh vertex or transform updates without a full rebuild.
scene.is_ready() — Returns True if the scene has been built and is ready for queries.
scene.has_pending_updates() — Returns True if there are unsynchronized mesh updates.
Mesh Update Methods#
scene.update_mesh_vertices(mesh_id, positions) — Update vertex positions for a specific mesh by index.
scene.set_mesh_transform(mesh_id, mat, set_left=True) — Set the transform for a mesh by index.
scene.append_mesh_transform(mesh_id, mat, append_left=True) — Multiply the current transform for a mesh by mat.
Properties#
| Property | Description |
|---|---|
scene.num_meshes | Number of meshes in the scene |
scene.version | Scene version counter — increments on each build |
scene.edge_version | Edge BVH version counter |
scene.edge_bvh_backend | The edge BVH backend string |
scene.last_sync_profile | SceneSyncProfile with timing data from the last sync |
Scene Geometry#
scene.global_geometry() — Returns a SceneGeometry with the merged vertex and face arrays across all meshes.
scene.mesh_face_offsets() — Per-mesh face offset array.
scene.mesh_edge_offsets() — Per-mesh edge offset array.
scene.mesh_vertex_offsets() — Per-mesh vertex offset array.
scene.triangle_edge_indices(prim_id, global_=True) — Returns a tuple of three edge index arrays for a given primitive.
scene.edge_adjacent_faces(edge_id, global_=True) — Returns a tuple of two face index arrays adjacent to a given edge.
Edge Management#
scene.edge_info() — Returns SceneEdgeInfo with per-edge geometry data.
scene.edge_topology() — Returns SceneEdgeTopology with per-edge vertex and face connectivity.
scene.edge_mask() — Returns the current scene-global edge mask.
scene.set_edge_mask(mask) — Filter the secondary-edge BVH. Accepts Mask or MaskAD. Does not modify edge_info() or edge_topology().
scene.edge_bvh_stats() — Returns SceneEdgeBVHStats with BVH quality metrics.
Ray Flags#
RayFlags controls what data is computed during intersection:
| Flag | Description |
|---|---|
RayFlags.None | No extra data |
RayFlags.Geometric | Geometric normal only |
RayFlags.ShadingN | Shading normal |
RayFlags.UV | UV coordinates |
RayFlags.All | All available data (default) |
its = scene.intersect(ray, flags=rd.RayFlags.Geometric)Next Steps#
- Intersection — ray-mesh intersection reference
- Edge queries — nearest-edge and visibility queries
- Multipath — reflection and diffraction queries