Suite Workflows: Five End-to-End Clash Queries#

samples/clash_suite_api/ holds one clash processor written twice. One version uses the ovclash_suite Python package. The other is C++ over the C ABI of the Suite API, <ovclash_suite/ovclash_suite.h>. This tutorial runs the five queries that the sample’s launchers run. It then rebuilds the core of one run in Python and in C, so you can map a real workflow onto the calls behind it.

How the processor works:

  • Each run executes exactly one clash query. There are no built-in named modes: the command line supplies the stage, the search sets of the scope, the settings and every output path.

  • A run opens the stage and runs the detection pipeline.

  • When you request an output, the run also inserts a ClashQuery record into a store: a SQLite store, one .ovclashdb database file (--clashdb), a directory store, one folder of JSON files (--clashdir), or both. It saves the results it found and can write a JSON and an HTML report (--json, --html).

  • Without --clashdb, --clashdir, --json or --html, a run only prints the counts.

Prerequisites#

  • The sample. The SDK archive has it at <sdk>/samples/clash_suite_api, and the ovclash wheel at <site-packages>/ovclash/samples/clash_suite_api. <sdk> is the extracted SDK archive, and <site-packages> is the Location that python -m pip show ovclash prints. Each package ships only the launchers for its own platform. The wheel ships only the Python processor.

  • A Python interpreter for the Python launcher. The launcher starts from the interpreter that PYTHON names, python3 on Linux and python on Windows by default. With the wheel, activate the environment the wheel is installed in. The SDK archive does not bundle ovstage. The launchers use the interpreter when the pinned ovstage is available to it, and otherwise install that version with pip into a per-user cached virtual environment; Samples describes the selection. When that install fails, for example without access to the package index, see Sample Python setup failed.

  • The time_sampled.usda stage. The SDK archive and the wheel ship it as samples/data/time_sampled.usda.

  • For the C++ processor and the C example only: the SDK archive, a C++17 compiler and CMake 3.16 or later. The C++ processor also needs the ovstage include directory that holds ovx/string_types.h; the installed ovstage package supplies it. The C++ launcher builds the sample in a build directory inside a Linux SDK archive. An extracted Windows SDK archive builds it under a per-user cache, %LOCALAPPDATA%\ovclash\samples\<SDK-path hash>\clash_suite_api, which keeps compiler paths short. Set OVCLASH_SAMPLE_BUILD_ROOT to a writable directory when the default is not writable, for example in a read-only Linux SDK archive. Building the C++ samples describes the build, and Building and running the shipped samples its failures.

If you do not need query records, .ovclashdb stores or HTML/JSON export, the canonical ovclash API is the smaller surface; see Choosing an API Layer.

Step 1: Run all five cases#

Run the commands of this tutorial from the samples directory of the SDK archive or of the wheel’s ovclash package. First run all five cases. The C++ launcher ships only in the SDK archive.

On Linux:

./clash_suite_api/run_clash_suite_api_python.sh
./clash_suite_api/run_clash_suite_api_cpp.sh

On Windows:

clash_suite_api\run_clash_suite_api_python.bat
clash_suite_api\run_clash_suite_api_cpp.bat

By default the launchers write the outputs to a directory inside the package root: the SDK archive root, or the wheel’s ovclash package directory. Pass --output-dir DIR to choose another directory, for example when the package root is not writable.

Each case writes <case>.ovclashdb, <case>.json and <case>.html. Expected results:

Case

Console line

Stored records

static

Fetching 1 overlaps and 0 duplicate pairs...

1 clash

dynamic

Fetching 8 overlaps and 0 duplicate pairs...

8 clashes, with one frame per overlapping sample

duplicates

Fetching 0 overlaps and 1 duplicate pairs...

1 duplicate record

point_cloud

Fetching 6 overlaps and 0 duplicate pairs...

6 point-cloud clashes

dynamic_point_cloud

Fetching 14 overlaps and 0 duplicate pairs...

14 point-cloud clashes

Step 2: Run one case as a custom command#

The launcher passes everything after -- to the processor unchanged. Rules for a custom command:

  • No path resolution. The launcher does not resolve paths in a custom command. From the samples directory, data/time_sampled.usda is the packaged stage.

  • Writable current directory. Relative output paths resolve against the current directory. When it is not writable, pass absolute paths.

  • Windows. Use clash_suite_api\run_clash_suite_api_python.bat with the same arguments on one line. Quote a value that contains ,, ;, = or one of & | < > ^, because cmd splits or interprets it first.

For one Python command without the -- separator, the sample directory also has run_custom_clash.sh and run_custom_clash.bat; The Clash Processor introduces them. The Clash Processor guide beside the sample, samples/clash_suite_api/clash_processor.md, explains how they pick a runtime.

Static clash#

The plain case: two meshes at one time. /Root/Xform_Primitives/Cube is a block that reaches through the ground plane /Root/Xform_Primitives/Plane, so the query reports one clash.

./clash_suite_api/run_clash_suite_api_python.sh -- \
    --stage data/time_sampled.usda \
    --object-a /Root/Xform_Primitives/Cube \
    --object-b /Root/Xform_Primitives/Plane \
    --query-name "Example Static Query" \
    --json static.json --html static.html --clashdb static.ovclashdb

The run first prints its arguments under Clash Processor Arguments: and the derived engine settings under Clash Engine Settings:. The rest of the output looks like this, where each <seconds> is a measured duration:

Creating new query in 'static.ovclashdb'...
Setting up clash detection engine...
Loading stage 'data/time_sampled.usda'...
Stage loaded in <seconds>s.
Resolved static time: 0.0 s
Running Clash Detection Engine... [11/11] 100% done (11 steps in <seconds>s).
Fetching 1 overlaps and 0 duplicate pairs...
Fetching, serializing and saving results... 100% done (<seconds>s).
Exporting to HTML file 'static.html'...
Exporting to JSON file 'static.json'...
Saved clash store 'static.ovclashdb'.
Releasing clash results and closing the stage...
Cleanup time: <seconds>s
Clash detection time: <seconds>s
Fetching, serialization and saving time: <seconds>s
Total elapsed time: <seconds>s

static.ovclashdb holds one clash_query row and one clash_info row per clashing pair. static.json and static.html list the same records as a table.

Dynamic clash#

Meshes against meshes, sampled over a time range: a dynamic query. /Root/STATION_TIME_SAMPLED is an animated platform, and /Root/Xform_Primitives holds static primitives. The query samples the range from 3 to 20 seconds. It reports where the platform’s meshes clash with the block /Root/Xform_Primitives/Cube. --tolerance 5 is a clearance distance in stage units: meshes closer than 5 units count as clashing even when they do not touch.

./clash_suite_api/run_clash_suite_api_python.sh -- \
    --stage data/time_sampled.usda \
    --object-a /Root/STATION_TIME_SAMPLED \
    --object-b /Root/Xform_Primitives \
    --mode dynamic --tolerance 5 --start-time 3 --end-time 20 \
    --query-name "Example Dynamic Query" \
    --json dynamic.json --html dynamic.html --clashdb dynamic.ovclashdb

Expected key lines:

Resolved dynamic start time: 3.0 s
Resolved dynamic end time: 20.0 s
Running Clash Detection Engine... [415/415] 100% done (415 steps in <seconds>s).
Fetching 8 overlaps and 0 duplicate pairs...

A dynamic clash record owns one ClashFrameInfo per sample where the pair overlapped. Its start_time and end_time bracket those samples. The Clash Start, Clash End and Records columns of the reports show start_time, end_time and num_records. See The object model for the record types.

Times are in seconds. The engine converts them to USD time codes, the stage’s own time unit, with the stage’s timeCodesPerSecond. --time-codes-per-second sets only the sampling rate of a dynamic run. It defaults to the stage’s rate. The two processors resolve times differently:

  • Python processor. It resolves the times through ClashDetection.set_settings().

    • In a dynamic run, a --start-time or --end-time of 0 takes the stage’s start or end time.

    • In a static run, --static-time is clamped to the stage’s time range.

    • If the stage’s timeline cannot be read at all, a static run uses --static-time unclamped. On a binary (crate) stage, a dynamic run then needs an explicit range and otherwise fails.

  • C++ processor. It writes the times into ovclash_suite_run_settings_t unchanged. 0 means time 0, and --static-time is not clamped. A dynamic C++ run therefore needs an explicit --end-time.

Point-cloud clash with an ROI include#

A point-vs-mesh query: point cloud against mesh. /Root/Points holds two UsdGeomPoints prims. Search set B holds two prim paths, given as one quoted, space-separated value. --roi-include /Root/ROI names a region-of-interest (ROI) prim.

./clash_suite_api/run_clash_suite_api_python.sh -- \
    --stage data/time_sampled.usda \
    --object-a /Root/Points \
    --object-b "/Root/Xform_Primitives /Root/STATION_TIME_SAMPLED" \
    --roi-include /Root/ROI --point-clouds --logging \
    --query-name "Example Point Clouds Query" \
    --json point_cloud.json --html point_cloud.html --clashdb point_cloud.ovclashdb

Expected key line:

Fetching 6 overlaps and 0 duplicate pairs...

Note

The ROI changes nothing. Every clash store saves --roi-include and --roi-exclude with the query, but no ovclash query path reads them. Results are identical with and without them. They exist so that a query record stays compatible with that of Kit.

A point-cloud clash record has the overlap type OverlapType.POINT_CLOUD_MESH (OVCLASH_SUITE_OVERLAP_POINT_CLOUD_MESH). It reports point indices, not mesh faces or outlines. The depth entry points are mesh-only. --point-clouds adds a point-vs-mesh pass; it does not turn the query into a point-only search. See Point clouds are additive.

Dynamic point-cloud clash#

The same search sets as Point-cloud clash with an ROI include, sampled from 3 to 20 seconds, without the ROI.

./clash_suite_api/run_clash_suite_api_python.sh -- \
    --stage data/time_sampled.usda \
    --object-a /Root/Points \
    --object-b "/Root/Xform_Primitives /Root/STATION_TIME_SAMPLED" \
    --point-clouds --mode dynamic --tolerance 5 --start-time 3 --end-time 20 --logging \
    --query-name "Example Dynamic Point Clouds Query" \
    --json dynamic_point_cloud.json --html dynamic_point_cloud.html \
    --clashdb dynamic_point_cloud.ovclashdb

Expected key line:

Fetching 14 overlaps and 0 duplicate pairs...
  • --tolerance 5 does not widen the point-vs-mesh test. The point-vs-mesh narrow phase ignores the tolerance; see ovclash_set_tolerance in Epsilons and cutoffs.

  • --logging adds the engine log, per-phase [perf] markers and one progress line per update.

Step 3: Rebuild the dynamic case in Python#

clash_suite_api_python.py imports its clash API from the public ovclash_suite module and only version_string from ovclash. This script is the core of one ClashProcessor.run() with the dynamic case’s values. It leaves out argument handling and progress output.

Save it as suite_dynamic.py in the directory that holds time_sampled.usda:

import time
from pathlib import Path

from ovclash_suite import (
    ClashData,
    ClashDetection,
    ClashQuery,
    default_run_settings,
    run_settings_to_query_settings_dict,
)

STAGE = "time_sampled.usda"
STORE = "dynamic.ovclashdb"
SCOPE_A = ["/Root/STATION_TIME_SAMPLED"]
SCOPE_B = ["/Root/Xform_Primitives"]

# 1. Build the settings once. The query stores them, and the runtime applies them.
settings = default_run_settings().with_updates(
    dynamic=True,
    tolerance=5.0,
    dynamic_start_time=3.0,
    dynamic_end_time=20.0,
    start_time=3.0,
    end_time=20.0,
    set_times=True,
)
query = ClashQuery(
    query_name="Example Dynamic Query",
    object_a_path=" ".join(SCOPE_A),
    object_b_path=" ".join(SCOPE_B),
    clash_detect_settings=run_settings_to_query_settings_dict(settings),
)

Path(STORE).unlink(missing_ok=True)  # replace earlier results, as the processor does
data = ClashData()
clash = ClashDetection()
try:
    # 2. Open the store and insert the query. The insert sets query.identifier.
    data.open(STORE)
    data.insert_query(query)

    # 3. Open the stage and apply the stored settings and the scope.
    clash.open_stage(STAGE)
    clash.set_settings(query.clash_detect_settings)
    clash.set_scope_paths(SCOPE_A, SCOPE_B)

    # 4. Run detection on a worker thread and wait for it.
    step_count = clash.create_pipeline()
    with clash.run_async_pipeline() as pipeline:
        while pipeline.is_running():
            time.sleep(0.05)  # pipeline.step_data() has the current step and progress
        pipeline.finish()
    print(f"Ran {step_count} pipeline steps and found {clash.get_nb_overlaps()} overlaps.")

    # 5. Write the results under the query, then save the store.
    for progress in clash.fetch_and_save_overlaps(None, data, query, async_mode=True):
        pass
    data.save()
    stored = data.get_overlaps_count_by_query_id(query.identifier)
    print(f"Saved {stored} clashes under query {query.identifier} in {STORE}.")
finally:
    clash.destroy()
    data.destroy()

Run it with python suite_dynamic.py. Expected output:

Ran 415 pipeline steps and found 8 overlaps.
Saved 8 clashes under query 1 in dynamic.ovclashdb.

What each part does:

  • Build the settings once. default_run_settings().with_updates(...) returns an ovclash_suite.RunSettings, whose fields match ovclash_suite_run_settings_t; ovclash_suite Python gives the type and default of each. run_settings_to_query_settings_dict() converts it into the mapping that the ClashQuery stores and ClashDetection.set_settings() applies. The saved query therefore matches the run.

  • set_settings() and set_scope_paths() raise RuntimeError when the runtime rejects the input.

  • Persistence goes through the runtime. fetch_and_save_overlaps() is a generator that yields progress. Exhaust or close it before you close the store.

    • Its first argument is unused; pass None.

    • The second must be an open serializer or ClashData; None raises ValueError.

    • For detection without persistence, run the pipeline and read get_nb_overlaps() and get_overlap_data() directly.

  • A failed fetch can leave partial results. A fetch that fails during extraction, preparation or scheduling, or that you close early, can leave completed clash records pending. Closing a built-in store may commit them. A serializer callback failure rolls back the whole pending transaction instead. See Saving detection results.

  • Export is not a method. export_to_html() and export_to_json() are module-level functions that take columns and rows. See Export.

The processor runs detection and fetch-and-save asynchronously by default. With --async false it runs the pipeline steps on the calling thread and passes async_mode=False, which is also the library default. The failure and partial-write rules are the same in every mode.

Step 4: Rebuild the dynamic case in C#

ClashSuiteApi.cpp is the same processor in C++ over <ovclash_suite/ovclash_suite.h>. It wraps the runtime, store and export-text handles in small RAII structs (RuntimeHandle, DataHandle, ExportTextHandle), whose destructors release the handles (resource acquisition is initialization). Its check() helper turns a failed ovclash_suite_result_t into an exception. The exception carries ovclash_suite_get_thread_last_error() and the handle’s own error text.

This C program runs the dynamic case end to end, synchronously. It writes dynamic_c.ovclashdb. It fills ovclash_suite_run_settings_t, whose fields Suite C lists, and ovclash_suite_query_view_t, whose fields match the ClashQuery table of The object model. Save it as a C source file:

#include <ovclash_suite/ovclash_suite.h>

#include <stdio.h>
#include <string.h>

static ovclash_suite_string_t text(const char* value)
{
    ovclash_suite_string_t span = { value, strlen(value) };
    return span;
}

/* Print the thread-local error text and report whether the call succeeded. */
static int ok(ovclash_suite_result_t result, const char* what)
{
    if (result.status == OVCLASH_SUITE_STATUS_SUCCESS) return 1;
    ovclash_suite_string_t error = ovclash_suite_get_thread_last_error();
    fprintf(stderr, "%s failed: %.*s\n", what, (int)error.length, error.ptr ? error.ptr : "");
    return 0;
}

int main(void)
{
    const char* store = "dynamic_c.ovclashdb";
    const ovclash_suite_string_t scope_a[] = { text("/Root/STATION_TIME_SAMPLED") };
    const ovclash_suite_string_t scope_b[] = { text("/Root/Xform_Primitives") };
    ovclash_suite_runtime_t* runtime = NULL;
    ovclash_suite_data_t* data = NULL;
    ovclash_suite_fetch_and_save_t* fetch = NULL;
    ovclash_suite_stage_timeline_data_t timeline;
    ovclash_suite_run_settings_t settings;
    ovclash_suite_query_view_t query;
    char settings_json[8192];
    char timestamp[64];
    char user[256];
    size_t json_size = 0u;
    size_t timestamp_size = 0u;
    size_t user_size = 0u;
    int64_t query_id = -1;
    uint32_t step_count = 0u;
    uint32_t complete = 0u;
    uint32_t overlap_count = 0u;
    int status = 1;

    remove(store); /* replace earlier results, as the processor does */
    if (!ok(ovclash_suite_create_runtime(&runtime), "create runtime") ||
        !ok(ovclash_suite_data_create(&data), "create data") ||
        !ok(ovclash_suite_open_stage(runtime, text("time_sampled.usda")), "open stage") ||
        !ok(ovclash_suite_get_stage_timeline_data(runtime, &timeline), "read timeline") ||
        !ok(ovclash_suite_get_default_run_settings(&settings), "default settings"))
        goto cleanup;

    /* Times are explicit fields in C; set_times applies start_time and end_time. */
    settings.dynamic = 1u;
    settings.tolerance = 5.0;
    settings.dynamic_start_time = settings.start_time = 3.0;
    settings.dynamic_end_time = settings.end_time = 20.0;
    settings.time_codes_per_second = timeline.time_codes_per_second;
    settings.set_times = 1u;
    if (!ok(ovclash_suite_set_run_settings(runtime, &settings), "set settings") ||
        !ok(ovclash_suite_set_scope(runtime, scope_a, 1u, scope_b, 1u), "set scope") ||
        !ok(ovclash_suite_run_settings_to_query_settings_json(&settings, settings_json, sizeof(settings_json),
                                                              &json_size),
            "settings JSON") ||
        !ok(ovclash_suite_current_timestamp(timestamp, sizeof(timestamp), &timestamp_size), "timestamp") ||
        !ok(ovclash_suite_current_user_name(user, sizeof(user), &user_size), "user name"))
        goto cleanup;

    /* Store the query with the settings it ran with. */
    memset(&query, 0, sizeof(query));
    query.identifier = -1;
    query.query_name = text("Example Dynamic Query");
    query.object_a_path = scope_a[0];
    query.object_b_path = scope_b[0];
    query.settings_json.ptr = settings_json;
    query.settings_json.length = json_size;
    query.creation_timestamp.ptr = query.last_modified_timestamp.ptr = timestamp;
    query.creation_timestamp.length = query.last_modified_timestamp.length = timestamp_size;
    query.last_modified_by.ptr = user;
    query.last_modified_by.length = user_size;
    if (!ok(ovclash_suite_data_open(data, text(store)), "open store") ||
        !ok(ovclash_suite_data_insert_query_with_commit(data, &query, 1u, 1u, &query_id), "insert query"))
        goto cleanup;

    /* Run detection synchronously, one step at a time. */
    if (!ok(ovclash_suite_create_pipeline(runtime, &step_count), "create pipeline")) goto cleanup;
    for (uint32_t step = 0u; step < step_count; ++step)
    {
        if (!ok(ovclash_suite_run_pipeline_step(runtime, step), "run step")) goto cleanup;
    }
    if (!ok(ovclash_suite_get_nb_overlaps(runtime, &overlap_count), "count overlaps")) goto cleanup;
    printf("Ran %u pipeline steps and found %u overlaps.\n", step_count, overlap_count);

    /* Persist the results in bounded batches; the completing call commits. */
    if (!ok(ovclash_suite_runtime_fetch_and_save_begin(runtime, data, NULL, query_id, settings.tolerance,
                                                       settings.depth_epsilon, settings.only_find_duplicates,
                                                       1u /* resolve_stale */, &fetch),
            "begin fetch"))
        goto cleanup;
    while (!complete)
    {
        double progress = 0.0;
        if (!ok(ovclash_suite_runtime_fetch_and_save_next(fetch, &progress, &complete), "fetch")) goto cleanup;
    }
    if (!ok(ovclash_suite_data_get_overlap_count_by_query(data, query_id, &overlap_count), "count stored"))
        goto cleanup;
    printf("Saved %u clashes under query %lld in %s.\n", overlap_count, (long long)query_id, store);
    status = 0;

cleanup:
    ovclash_suite_runtime_fetch_and_save_destroy(fetch); /* each destroy accepts NULL */
    ovclash_suite_data_destroy(data); /* closing a built-in store attempts to commit */
    ovclash_suite_destroy_runtime(runtime);
    return status;
}

Build it against the SDK archive’s include directory and link the ovclash library, as Linking shows. When the build cannot find the headers or the program does not start, see Configuring with CMake and Starting a C or C++ program. Run it from the directory that holds time_sampled.usda. Expected output:

Ran 415 pipeline steps and found 8 overlaps.
Saved 8 clashes under query 1 in dynamic_c.ovclashdb.

Differences from Python:

  • Times are explicit fields. The C ABI takes the times as ovclash_suite_run_settings_t fields instead of the Python settings mapping. time_codes_per_second 0 selects a single sample, so pass the stage rate from ovclash_suite_get_stage_timeline_data().

  • The query needs its metadata. ovclash_suite_run_settings_to_query_settings_json() produces the settings JSON that the query stores. Fill both timestamps with ovclash_suite_current_timestamp() and last_modified_by with ovclash_suite_current_user_name(). The Python package cannot read a query whose timestamps are empty: fetch_all_queries() raises ValueError.

  • Fetch-and-save is incremental. Each ovclash_suite_runtime_fetch_and_save_next() call processes a bounded batch. The call that reports completion has committed. The processor’s default asynchronous path uses ovclash_suite_run_pipeline_async() and ovclash_suite_runtime_fetch_and_save_async() instead, polling ovclash_suite_async_is_running() and ovclash_suite_fetch_async_is_running().

Processor options#

Run either processor with --help for every option, or with --version for the ovclash version. The options you need most:

Option

Value

Default

Effect

--stage USD

A stage file path

None; a stage is required, here or as the first positional argument

The stage to process.

--object-a PATHS, --object-b PATHS

Prim paths

None

Search sets A and B. Repeat the option, or separate paths with spaces, commas or semicolons. Quote a separated list so that the shell keeps it as one argument.

--mode static|dynamic

static or dynamic

static

Static runs evaluate one time, --static-time. Dynamic runs sample --start-time to --end-time.

--static-time, --start-time, --end-time

Seconds

0

The times of the run. In the Python processor, a dynamic 0 takes the stage’s start or end time; see Dynamic clash.

--duplicates, --point-clouds

Flags

Off

Duplicate mesh search, which merges both search sets into search set A; and point-vs-mesh clash.

--tolerance

Stage units

0

Clearance distance: meshes closer than this count as clashing. 0 reports only meshes that touch or intersect.

--clashdb FILE, --clashdir FOLDER

Paths

None

The SQLite and directory stores to write.

--append

Flag

Off

Adds to the existing results of each store instead of replacing them.

--json FILE, --html FILE

Paths

None

Report paths.

--async [true|false]

true or false

true

Asynchronous detection and fetch-and-save.

--logging

Flag

Off

The engine log with per-phase [perf] markers.

The Clash Processor guide, samples/clash_suite_api/clash_processor.md beside the sample, is the complete command-line reference. It also covers the engine settings, the threading options, the exit statuses and recipes for common checks.

Output stores#

  • Two store types. --clashdb FILE writes a SQLite store and --clashdir FOLDER a directory store of readable JSON records. Pass both to save one detection run to each store. Persistence compares the two, and Directory serializer describes the directory layout.

  • Saving to both stores is not atomic. If the second save fails, the first store keeps its results.

  • Without --append, a run replaces the existing results of every requested store. With --append, each run adds a new query, and the clashes of each run stay under their own query.

  • Each run saves under a new query. The processors never save again under an existing query, so the reconciliation of absent clashes and the clash-state updates of Clash states find no earlier results to act on here.

The Clash Processor guide lists the replacement rules and the paths that must not collide with a directory store.

Which runtime runs#

The launchers run the library of the SDK archive or wheel that contains them. Pass --install-root DIR, or set OVCLASH_INSTALL_ROOT, only to run against another SDK archive.

Note

The standalone API does not load .clashDetection files from a USD stage automatically. The processor opens each requested SQLite file or directory store explicitly. Reading the Kit legacy container is a separate, explicit operation; see Legacy Containers.

Result#

You can run each of the five query shapes, rebuild a run from Python or C, and pick the option that controls each part of the query. Each processor run ends with its detection, persistence and total times. --logging adds per-phase [perf] markers. Performance covers further investigation.

Next steps#