Queries and Results#
A query asks one question about one version of a population or view. This page describes the four query families, how a query chooses its version, the two kinds of result, and the fields that every query shares.
Query Families#
Query shapes and stored geometry are separate vocabularies. A population stores five geometry families: sphere, box, capsule, convex hull, and triangle mesh. Every query family works against all five.
Each query family supports one or more hit modes, as the following table shows:
Query Family |
Closest |
Any |
Multiple |
|---|---|---|---|
Raycast |
Yes |
Yes |
Yes |
Sphere sweep |
Yes |
Yes |
Yes |
Box sweep |
Yes |
Yes |
Yes |
Overlap |
No |
Yes |
Yes |
The three hit modes answer three different questions:
Closest reports the first contact along the path, or no hit.
Any reports one hit and makes no promise about which one. Use it when you only need to know whether something is there.
Multiple reports every hit up to a capacity that you choose, in no particular order. It also reports whether more hits existed.
Every call in this section runs on the calling thread and returns when the answer is ready. In
C, each call is a function that takes the instance and a descriptor. In Python, each call is a
method of Target, which population.target and
view.target return.
Tip
To run many queries of one family at once, on the CPU or on a CUDA device, use a batch plan.
Raycasts#
A ray has an origin, a unit_direction, and a closed interval from min_distance to
max_distance along that direction. The following figure casts the same ray in each of the three
hit modes:
Each mode has one C function and one Python method, as the following table shows:
Mode |
C Function |
Python Method |
|---|---|---|
Closest |
||
Any |
||
Multiple |
The multiple mode writes hits into storage that you size. In C, you pass an array of
ovspatialquery_raycast_hit_t rows and its capacity, and stored_hit_count says how
many rows are valid. In Python, raycast_multiple takes a capacity and returns a
MultipleResult. In both, truncated is true when more
hits existed than fit, and the stored hits are then the nearest ones.
A ray can cross a triangle mesh more than once, for example through both walls of a closed mesh
or both sides of a U shape. By default the multiple mode reports every triangle the ray crosses,
each hit with its own source face, so you see every surface along the ray. A single-sided mesh
reports only the crossings through its front faces unless the query sets MESH_BOTH_SIDES (refer
to Sweeps and Single-Sided Meshes). A ray through a shared edge
or vertex can report each triangle that shares it. Spheres, boxes, capsules, and convex hulls
report one hit each.
When you only need to know which objects the ray reaches and where it reaches each one first,
set mesh_hits to OVSPATIALQUERY_MESH_HITS_NEAREST in C, or pass
mesh_hits=MeshHits.NEAREST in Python. Each object then reports one hit, its nearest contact,
and the query does less work on meshes. Every crossing needs a ray with no width, so a multiple
raycast with a nonzero contact_tolerance must ask for NEAREST; otherwise it fails with
NOT_SUPPORTED.
Sphere Sweeps#
A sphere sweep moves a sphere of radius from center along unit_direction, over the interval
from min_distance to max_distance. The closest sweep reports the first contact. The following
figure sweeps a sphere past two boxes:
An exact sphere sweep hit reports the following values:
query_positionis the sphere’s center at contact.The contact point on the object is
object_positionin C andpositionin Python.distanceis how far the center traveled fromcenter.
The call is ovspatialquery_sweep_sphere_closest_sync() in C and
sweep_sphere_closest in Python.
Box Sweeps#
A box sweep moves an oriented box along a straight path. The box has half_extents and a
rotation_xyzw quaternion, and it keeps that orientation along the whole path. A hit reports
the same values as a sphere sweep hit. The following figure sweeps a rotated box toward two boxes:
The call is ovspatialquery_sweep_box_closest_sync() in C and
sweep_box_closest in Python.
Sweep Hit Modes#
Sphere and box sweeps have the any and multiple modes of raycasts too. The following table lists their calls:
Sweep |
C |
Python |
|---|---|---|
Sphere, any |
||
Sphere, multiple |
||
Box, any |
||
Box, multiple |
An any sweep returns a hit of whichever object it finds first, with the same values a closest sweep reports for that object. It makes no promise that the object is the nearest one.
A multiple sweep reports one hit per object it reaches, at that object’s first contact. A
triangle mesh reports one hit, not one per triangle, the same way PhysX’s sweeps do. An object
the shape already touches or overlaps at min_distance is reported at min_distance. In C, you
pass an array of ovspatialquery_sphere_sweep_hit_t rows and its capacity, which box
sweeps share. In Python, the call takes a capacity and returns a
MultipleResult. As for raycasts, truncated is true
when more objects were reached than fit, and the stored hits are then the nearest ones.
Sweeps and Single-Sided Meshes#
A sweep decides per triangle whether a single-sided mesh can stop it, from the triangle’s front
normal (v1 - v0) x (v2 - v0) and the sweep’s unit_direction, the same way PhysX’s sweeps do:
A triangle whose front normal points along the motion is ignored, so a sphere or box resting on a floor can leave it.
A sphere also meets a triangle it moves exactly parallel to; a box ignores it.
Every other triangle stops the sweep wherever the shape first touches it, on its face, an edge or a vertex, from either side. A shape falling past the open edge of a floor tile stops at the edge, and a sweep that starts touching such a triangle reports it at
min_distance, even with its center below the tile.
Double-sided triangles always count. A sphere’s contact from behind reports a normal that points from the contact toward the sphere’s center.
To let one query see a single-sided mesh from behind without republishing it, set
QueryFlag.MESH_BOTH_SIDES in one of these places:
On a single query, pass
both_sides=Trueorquery_flags=QueryFlag.MESH_BOTH_SIDEStoRaycastQuery,SphereSweepQuery, orBoxSweepQuery.On a raycast, sphere-sweep, or box-sweep plan, pass the same argument to
enqueue. It applies to every row of that launch.In C, set
OVSPATIALQUERY_QUERY_MESH_BOTH_SIDESinquery_flags.
Every triangle then counts from both sides, as PhysX’s eMESH_BOTH_SIDES makes it. A ray also
reports back faces. On a single-sided mesh, its normal stays the triangle’s front normal, as PhysX
reports it, so a normal that points along the ray marks a back-face hit. A double-sided mesh still
reports the normal facing the ray. A sweep ignores no triangle. Other shapes, bounds-candidate
precision, and overlaps ignore the flag, and a flag bit this version does not know is refused with
NOT_SUPPORTED.
Important
rotation_xyzw stores the quaternion with w last, so the identity rotation is (0, 0, 0, 1).
The value (1, 0, 0, 0) is a valid half turn about x, so passing it as the identity fails
silently. A quaternion that is not unit length returns INVALID_ARGUMENT.
Overlaps#
An overlap tests one query shape at one pose and reports the objects that it touches. The shape is a sphere, an oriented box, or an axis-aligned box (AABB). An overlap has no path, so its hits carry the object’s identity and no distance or contact point. The following figure tests the same sphere in both hit modes:
Each mode has one C function and one Python method, as the following table shows:
Mode |
C Function |
Python Method |
|---|---|---|
Any |
||
Multiple |
In C, the shape is an ovspatialquery_overlap_shape_t tagged SPHERE, BOX, or
AABB. In Python, the query’s shape is a Sphere, an
OrientedBox, or an Aabb.
The multiple mode sizes its storage and reports truncated as a raycast does.
Version Selection#
Every query names one target, a population or a view, and one version of that target. The version selection is one of two kinds:
HEADreads the newest version at the moment the call admits the query.RETAINED_EXACTreads one exact ordinal, which is the head or a retained earlier head. Any other ordinal returnsORDINAL_NOT_RETAINED.
In Python, the version is the query’s ordinal field:
OrdinalSelection.head() (the default) or
OrdinalSelection.retained_exact(101). Every result reports source_ordinal, the version that
it read. A query that asked for the head therefore knows which version it got.
Note
How many earlier heads a population keeps is fixed when you create it. For details, refer to populations and their versions.
Result Types#
A query asks for one precision, which decides what kind of result it returns:
BOUNDS_CANDIDATEstops where the query meets an object’s published bounding box.EXACTtests the stored surface.
The two answers are different record arms with different field names. The truth tag says which
arm a row holds, so a candidate is never mistaken for a surface point. The following figure casts
the same ray at both precisions:
An exact hit on a triangle mesh names the face as it was authored in USD. For a quad, the hit reports the quad’s index, three of its four corners, and barycentric weights over those corners. The triangles that the library builds internally never appear in a result.
An explicit triangle mesh reports the submitted triangle’s index and the corners 0, 1, and 2 by
default. If you triangulated polygons yourself, register each triangle’s polygon index in
source_face_indices and its three corners within that polygon in source_face_corner_indices.
Its hits then report the polygon and its corners, as an ovstage mesh does. Per-face materials
must then agree across the triangles of one polygon.
In Python, single queries default to EXACT. Batch plans default to BOUNDS_CANDIDATE, because
a version prepared only on a CUDA device can be read only at that precision. In C, a zeroed
descriptor selects BOUNDS_CANDIDATE.
Note
Raycasts also accept
EXACT_SINGLE.
It lets the library evaluate surfaces in single precision, which can change whether a ray hits,
its distance, or its face near numerical boundaries. Its results are still exact surface hits.
Sweeps and overlaps return NOT_SUPPORTED for it.
Query Fields#
Each query also carries the following fields:
query_bitsaccepts only objects whose participation bits intersect these bits. Zero accepts every object.min_distanceandmax_distancebound the part of a ray or sweep that counts. A sweep that already touches an object atmin_distancereports that object atmin_distance.contact_tolerancegrows the query shape by a distance in caller units before the contact test.
Coordinate Precision#
World positions and distances are double precision. Directions, normals, and sweep rotations are
single precision. Overlap BOX rotations also accept float64[Q,4] and retain double precision
for those rows. Stored local vertices are float32. Every coordinate, size, and distance must lie
within ±2⁶⁰ caller units. Outside that range, a call returns INVALID_ARGUMENT and a batch row
reports BATCH_ROW_INVALID_ARGUMENT, instead of rounding. Results near edges and touching
surfaces can differ between implementations, and the library promises no universal error bound.