Clash Detection Engine Encapsulation

Overview

File Name: clash_detect.py

This file provides a ClashDetection class. This class provides methods for initializing and managing clash detection pipelines, setting configurations, processing overlaps, and handling clash data. It interfaces with the underlying clash detection API (by leveraging the omni.physx.clashdetection extension) to perform these operations.

ClashDetection Class

class ClashDetection

Handles setup, configuration, and processing of clash detections.

Constructor

__init__() None

Initializes a new instance of the ClashDetection class, setting up the clash detection API and context.

Methods

destroy() None

Releases the clash detection API and context. Should be called to clean up resources when the clash detection is no longer needed.

reset() None

Resets the clash detection context to its initial state, clearing any existing configurations or data.

get_nb_overlaps() int

Returns the number of overlaps (clashes) detected in the current context.

Returns

The number of detected overlaps (clashes).

Return type

int

set_settings(settings: Dict[str, Any], stage: Usd.Stage = None) bool

Configures the clash detection settings based on the provided dictionary.

Note

Settings which are not provided in the dictionary are left unchanged.

Optionally takes a USD stage to apply settings relevant to the stage.

Parameters
  • settings – A dictionary of settings to apply.

  • stage – An optional USD stage to apply settings to.

Returns

True if settings were successfully applied, False otherwise.

Return type

bool

get_list_of_prims_int_paths(stage: Usd.Stage, prim_str_path: str) List[int]

Gets a list of prims in ‘int path’ form.

It is a class method.

Parameters
  • cls – The class instance.

  • stage (Usd.Stage) – The USD stage.

  • prim_str_path (str) – The prim string path.

Returns

List of prims in ‘int path’ form.

Return type

List[int]

set_scope(stage: Usd.Stage, obj_a: str, obj_b: str) bool

Sets the scope of clash detection to specific objects within a USD stage.

  • If both obj_a and obj_b are empty -> process full scene.

  • If only the obj_a list contains items -> limit processing only to obj_a items.

  • If obj_a and obj_b lists contain items -> process obj_a against obj_b.

Parameters
  • stage (Usd.Stage) – The USD stage.

  • obj_a (str) – The first object or group of objects.

  • obj_b (str) – The second object or group of objects.

Returns

True if the scope was successfully set, False otherwise.

Return type

bool

create_pipeline() int

Creates the clash detection pipeline.

Returns

The number of pipeline steps.

Return type

int

get_pipeline_step_data(index: int) Any

Gets data for a specific pipeline step.

Parameters

index (int) – The index of the pipeline step.

Returns

Data for the specified pipeline step.

Return type

Any

run_pipeline_step(index: int) None

Runs a specific step in the clash detection pipeline.

Parameters

index (int) – The index of the pipeline step.

get_overlap_data(overlap_index: int, frame_index: int) OverlapData

Gets overlap data for a specific index and frame.

Parameters
  • overlap_index (int) – The overlap index.

  • frame_index (int) – The frame index.

Returns

Data of the specified overlap.

Return type

OverlapData

get_overlap_report(overlap_index: int, frame_index: int, mesh_index: MeshIndex, flags: OverlapReportFlag) Dict[str, Any]

Gets the overlap report for a specific overlap, frame, and mesh.

Parameters
  • overlap_index (int) – The overlap index.

  • frame_index (int) – The frame index.

  • mesh_index (MeshIndex) – The mesh index.

  • flags (OverlapReportFlag) – Flags for the overlap report.

Returns

The overlap report.

Return type

Dict[str, Any]

get_overlap_faces(overlap_index: int, frame_index: int, mesh_index: int) List[int]

Gets the overlap faces for a specific overlap, frame, and mesh.

Parameters
  • overlap_index (int) – The overlap index.

  • frame_index (int) – The frame index.

  • mesh_index (int) – The mesh index.

Returns

The overlap faces.

Return type

List[int]

get_overlap_outline(overlap_index: int, frame_index: int) List[float]

Gets the overlap outline for a specific overlap and frame. It is a flat array of floats grouped in sets of three, representing x, y, and z coordinates.

Parameters
  • overlap_index (int) – The overlap index.

  • frame_index (int) – The frame index.

Returns

The overlap outline.

Return type

List[float]

process_overlap(stage: Usd.Stage, idx: int, existing_clash_info_items: Dict[str, ClashInfo], query_identifier: int, setting_tolerance: float) Optional[ClashInfo]:

Processes a detected overlap, updating or creating a ClashInfo object as necessary.

Parameters
  • stage (Usd.Stage) – The USD stage.

  • idx (int) – The index of the overlap.

  • existing_clash_info_items (Dict[str, ClashInfo]) – A dictionary of existing clash info items.

  • query_identifier (int) – The identifier for the clash query.

  • setting_tolerance (float) – The tolerance setting for clash detection.

Returns

A ClashInfo object if it’s a new clash, None otherwise.

Return type

Optional[ClashInfo]

fetch_and_save_overlaps(stage: Usd.Stage, clash_data: ClashData, clash_query: ClashQuery) Generator[int, None, None]

Fetches detected overlaps and saves them to the provided ClashData object. This method is a generator that yields progress updates.

Parameters
  • stage (Usd.Stage) – The USD stage.

  • clash_data (ClashData) – The ClashData object to save overlaps to.

  • clash_query (ClashQuery) – The ClashQuery object.

Returns

A generator yielding progress values.

Return type

Generator[int, None, None]

Properties

clash_detect_api -> Any

Returns the underlying clash detection API interface used by this instance.

Returns

Clash detection engine API.

clash_detect_context -> Any

Provides access to the current clash detection context.

Returns

Clash detection engine API context.