Overview#

An extension wraps around RTX Raycast Query to provide simpler raycast interface into the stage.

Class List#

  • IRaycastQuery: Interface class for Raycast Query operations. This class represents the interface for performing Raycast Query operations in the current scene. This class is thread-safe and can be called from any thread. There are two sets of functions to do raycast query:

    • The combination of add_raycast_sequence/remove_raycast_sequence, submit_ray_to_raycast_sequence, get_latest_result_from_raycast_sequence as a way to cast multiple rays into the scene and get result by polling.

    • submit_raycast_query as a single call that casts one Ray into the scene and returns hit result via callback.

  • Result: An enumeration class called “Result” which represents the possible error codes for a raycast query system.

  • RayQueryResult: Alias of the struct rtx::raytracing::RaycastQueryResult, represents the result of a raycast query. Inclued whether this query is valid, the hit position, normal and so on.

  • Ray: Alias of the struct rtx::raytracing::RaycastQueryRay, defines a ray that is used as input for a raycast query.

Example Usage#

import omni.kit.raycast.query
from pxr import Gf

# get raycast interface
raycast = omni.kit.raycast.query.acquire_raycast_query_interface()

# set up a cube for test
stage = omni.usd.get_context().get_stage()
CUBE_PATH = "/Cube"
cube = UsdGeom.Cube.Define(stage, CUBE_PATH)
UsdGeom.XformCommonAPI(cube.GetPrim()).SetTranslate(Gf.Vec3d(123.45, 0, 0))

# generate a ray
ray = omni.kit.raycast.query.Ray((1000, 0, 0), (-1, 0, 0))

def callback(ray, result):
    if result.valid:
        # Got the raycast result in the callback
        print(Gf.Vec3d(*result.hit_position)
        print(result.hit_t)
        print(Gf.Vec3d(*result.normal))
        print(result.get_target_usd_path())

raycast.submit_raycast_query(ray, callback)