Python Quickstart: Open a Stage and Find Overlaps#
This tutorial runs the smallest end-to-end ovclash workflow in Python. You create a runtime, open a
USD stage, scope the
query to two prims, run the
pipeline and read the overlaps. It uses the
ovclash package, a thin ctypes binding of the clash C ABI of the
canonical API (ovclash.h).
You will:
run a query script that prints the overlaps it finds;
learn what each call does;
run the packaged
clash_apisample;run one query from the command line.
Prerequisites#
Python 3.10 or newer with the ovclash wheel installed. Installation has the install command. pip also installs the wheel’s only runtime dependency, the pinned
ovstagewheel. You do not needusd-core: ovclash reads the stage through ovstage. Only the optionalviewer-openusdextra, a pip extra that adds NumPy,warp-langandusd-core, installsusd-core. When pip finds no matching distribution, check the platform and Python version against System requirements and the package index that pip is configured for. When the import fails afterwards, see Loading the Python packages.Or the SDK archive.
<sdk>stands for the absolute path of the extracted SDK archive. The SDK archive does not bundle ovstage: install the version that itsrequirements.txtpins into the same interpreter, withpython -m pip install -r <sdk>/requirements.txt. When pip cannot reach its package index, use a mirror or install the pin from a local wheel file, as Sample Python setup failed describes. Then set two variables:Variable
Values
Required
Default
Effect
PYTHONPATHContains
<sdk>/pythonYes
Unset
Makes the SDK archive’s Python packages importable.
OVCLASH_LIB<sdk>/bin/ovclash.dllon Windows,<sdk>/lib/libovclash.soon LinuxYes
Unset
Selects the native library. It must be an absolute path.
No native library found shows the commands for each shell and the error when a variable is missing.
The
time_sampled.usdastage. The wheel ships it in<site-packages>/ovclash/samples/data/, where<site-packages>is theLocationthatpython -m pip show ovclashprints, and the SDK archive in<sdk>/samples/data/. Its prims/Root/Xform_Primitives/Cubeand/Root/Xform_Primitives/Planeoverlap, so the query in Step 1 finds one overlap.
Step 1: Run a query#
Save this script as quickstart.py in the directory that holds time_sampled.usda. To run it
from elsewhere, pass the stage’s full path to open_stage.
from ovclash import ClashRuntime, RunSettings, backend_info
print(f"Backend: {backend_info().backend_name}")
with ClashRuntime() as runtime:
runtime.open_stage("time_sampled.usda")
runtime.set_run_settings(RunSettings(single_threaded=True))
runtime.set_scope(["/Root/Xform_Primitives/Cube"], ["/Root/Xform_Primitives/Plane"])
for index, step in enumerate(runtime.create_pipeline()):
print(f"[{index + 1}] {step.name}")
runtime.run_pipeline_step(index)
print(f"Overlaps: {runtime.get_overlap_count()}")
for index in range(runtime.get_overlap_count()):
overlap = runtime.get_overlap_record(index)
print(f" {overlap.name0} <-> {overlap.name1} ({overlap.nb_elements} elements)")
Run it:
python quickstart.py
Expected output:
Backend: ovstage
[1] Releasing previous data...
[2] Finding meshes...
[3] Computing initial mesh data...
[4] Finding shared meshes...
[5] Cooking meshes...
[6] Computing global mesh data...
[7] Building BVH...
[8] Running broad-phase...
[9] Purging duplicates...
[10] Running narrow-phase...
[11] Processing results...
Overlaps: 1
/Root/Xform_Primitives/Cube <-> /Root/Xform_Primitives/Plane (10 elements)
A static query has 11 pipeline steps. The cube reaches through the plane, so the query reports one overlap with 10 clashing elements.
Step 2: Understand each call#
The Developer Guide covers each step in depth.
ovclash Python lists every RunSettings field with its type and
default.
ClashRuntime()creates the native context. As a context manager it callsdestroy()on exit.destroy()also closes any open overlap report or async pipeline.open_stage(path)opens a local USD file. Asset URIs are rejected. A relative path resolves against the current directory. On failure it raisesRuntimeErrorwith the native error text.runtime.last_error()returns the same text.set_run_settings(settings)applies aRunSettings. It also accepts keyword updates.Without a
settingsargument the base isRunSettings(). Every field you do not set returns to its default.To keep the applied values, pass
runtime.get_run_settings()as the base.Parallel execution is the default. The script selects serial execution with
single_threaded=True.
set_scope(paths_a, paths_b)records the A/B scope. Each entry is an absolute prim path and also covers the prim’s descendants.The runtime applies the scope when
create_pipelinebuilds the pipeline. You may callset_scopebefore or afterset_run_settings.An invalid path raises
RuntimeErrorfromcreate_pipeline, not fromset_scope.A successful
open_stagedrops the recorded scope.A non-empty scope turns off full-scene traversal. To scan the whole stage again, call
set_scope([], [])andset_run_settings(runtime.get_run_settings(), enable_full_scene=True), then rebuild the pipeline. Setting a scope has the full rules.
create_pipeline()returns onePipelineStepDataper step.run_pipeline_step(index)runs one step. Run the steps in ascending order from 0.run_pipeline()creates and runs the whole pipeline in one call.run_async()runs the pipeline off the calling thread; see Async Pipelines.
get_overlap_count()andget_overlap_record(index)read the results.get_overlap_record(index)returns anovclash.OverlapRecord:name0andname1(strorNone),nb_recordsandnb_elements(int),type(ovclash.OverlapType) andtime(float, in seconds). Key overlaps by prim pair gives the type, values and meaning of each field.get_overlap_details(index)adds the clash hash and the mesh hashes,min_distanceandmax_local_depth.get_overlap_report(index)builds the face, outline and point buffers. Close the report, or use it as a context manager.The overlap index order is not contractual. Key on the names or the clash hash, not the index; see Overlap index order is not contractual.
Step 3: Run the packaged sample#
Before you begin: install the wheel or prepare the SDK archive as Prerequisites describes.
samples/clash_api/clash_api_python.py is the full version of the same flow. It adds overlap
details, overlap reports with face, outline and point buffers,
duplicate search, point-vs-mesh queries against
point clouds, dynamic queries, the asynchronous pipeline,
query statistics and a JSON summary.
The sample ships in the wheel at <site-packages>/ovclash/samples/clash_api/ and in the SDK
archive at <sdk>/samples/clash_api/. Each package carries only the launchers for its own
platform. The SDK archive also holds ClashApi.cpp, the same program in C++ over ovclash.h,
and its run_clash_api_cpp launcher. The wheel does not ship them.
From the package root (<site-packages>/ovclash or <sdk>), on Linux:
bash samples/clash_api/run_clash_api_python.sh
On Windows:
samples\clash_api\run_clash_api_python.bat
The launcher reads the packaged backend, the one that the package’s native
library was built with, from samples/ovclash_backend.txt and finds the packaged runtime. It then
runs five example queries against samples/data/time_sampled.usda:
Example |
Result on |
|---|---|
Static clash |
1 overlap |
Dynamic clash, 3 to 20 seconds, tolerance 5 |
8 overlaps |
Duplicate search |
0 overlaps and 1 duplicate mesh pair |
Point-cloud clash |
6 overlaps |
Dynamic point-cloud clash |
14 overlaps |
The static example prints this. <version> is the installed ovclash version, <stage> is the
path of the bundled stage, <output-dir> is the output directory, and <seconds> is the run’s
wall-clock time:
=== Running static clash query ===
ovclash <version>
Backend: ovstage
Query: Example Static Query
Comment: A static clash query between the gray block and the ground plane.
Opening stage '<stage>'...
Running pipeline (11 steps)...
[1/11] Releasing previous data...
...
[11/11] Processing results...
Overlaps: 1
[0] /Root/Xform_Primitives/Cube <-> /Root/Xform_Primitives/Plane (mesh-vs-mesh, id=0x37a006cb02c4a437d94f59d46c9170f5, elements=10, records=1, time=0.0000, minDist=0.0000, maxDepth=-1.0000)
faces0=4 faces1=1 segments=10 points0=0 pointSize0=0.0000
Stats: meshes=2 shared=0 cooked=2 pointClouds=0
[perf] total: <seconds>s
Wrote JSON summary to '<output-dir>/static.json'.
Launcher rules:
Interpreter. A packaged copy starts from
PYTHONif set, elsepython3on Linux orpythonon Windows. With the wheel, run the launcher from the environment where the wheel is installed.SDK archive bindings. In an SDK archive the launcher imports the archive’s own Python packages, so the wheel need not be installed. When the interpreter lacks the archive’s pinned ovstage runtime, the launcher installs it with pip into a per-user cached virtual environment and runs there. When that install fails, for example without access to the package index, see Sample Python setup failed.
Output. The launcher writes one JSON summary per example to an output directory inside the package root. Pass
--output-dir DIRto write them elsewhere, for example when the package root is read-only.
To run one custom query instead of the five examples, pass the sample’s arguments after --.
They form the query’s whole argument list, so they must name the stage too. Relative paths
resolve against the current directory. From the package root:
bash samples/clash_api/run_clash_api_python.sh -- --stage samples/data/time_sampled.usda --object-a /Root/Xform_Primitives/Cube --object-b /Root/Xform_Primitives/Plane
samples\clash_api\run_clash_api_python.bat -- --stage samples\data\time_sampled.usda --object-a /Root/Xform_Primitives/Cube --object-b /Root/Xform_Primitives/Plane
Add --json PATH to the custom query to also write a JSON summary.
samples.md describes the launchers, their runtime selection and their output, and
samples/clash_api/README.md in the package lists every sample option.
Step 4: Run a query from the command line#
The ovclash package has a module entry point. It runs one query and prints a JSON summary. It
is the quickest check that an install works. From the directory that holds
time_sampled.usda:
python -m ovclash --stage time_sampled.usda --scope-a /Root/Xform_Primitives/Cube --scope-b /Root/Xform_Primitives/Plane
Expected output on stdout:
{
"duplicate_count": 0,
"duplicates": [],
"overlap_count": 1,
"overlaps": [
{
"name0": "/Root/Xform_Primitives/Cube",
"name1": "/Root/Xform_Primitives/Plane",
"nb_elements": 10,
"time": 0.0,
"type": 0
}
],
"pipeline_steps": [
"Releasing previous data...",
"Finding meshes...",
"Computing initial mesh data...",
"Finding shared meshes...",
"Cooking meshes...",
"Computing global mesh data...",
"Building BVH...",
"Running broad-phase...",
"Purging duplicates...",
"Running narrow-phase...",
"Processing results..."
],
"stage": "time_sampled.usda"
}
stderr receives the version header, ovclash <version> - Standalone query CLI, where
<version> is the installed ovclash version, and every diagnostic, so you can pipe stdout
straight into a JSON parser. The command exits with status 0 on success.
Command line lists every option, the type of each output key and the
exit statuses. With the SDK archive, run the module in the environment from
Prerequisites.
Result#
You can open a stage from Python, scope and run a query, and read the overlaps it found. You can do it from your own code, from the packaged sample or from the module entry point.
Next steps#
Suite Workflows: the
ovclash_suiteproduct API, with query records,.ovclashdbpersistence and HTML/JSON export.Choosing an API Layer: why
ovclashandovclash_suiteare peers rather than layers, and which one to use.Async Pipelines: running the pipeline off the calling thread and polling it for progress.
Concepts: the terms that the rest of the documentation uses.
Python guide: both Python packages, the command line and the native library lookup.