Collector#

class omni.kit.tool.collect.Collector(
usd_path: str,
collect_dir: str,
usd_only: bool = False,
flat_collection: bool = False,
material_only: bool = False,
failure_options=<CollectorFailureOptions.SILENT: 0>,
skip_existing: bool = False,
max_concurrent_tasks=32,
texture_option=FlatCollectionTextureOptions.BY_MDL,
force_non_read_only=True,
exclusion_rules={},
default_prim_only=False,
**kwargs,
)#

Bases: object

Collector provides API to collect USD file with its dependencies that are scattered around different places.

Methods

__init__(usd_path, collect_dir[, usd_only, ...])

Constructor.

add_copy_task(source, target[, skip_if_existed])

Internal.

add_write_task(target, content)

Internal.

cancel()

Cancel the collector if it's in progress.

collect([progress_callback, finish_callback])

Collects stage in an asynchronous way.

destroy()

Destructor to release all resources.

get_source_target_url_mapping()

Gets the mapping of all source files to target files.

get_status()

Gets the collector status.

get_target_url(source_url)

Gets the target url that the source url is collected to.

is_cancelled()

Collector is cancelled or not.

is_copy_skipped(source_url)

Checkes if it skips copying source_url during collection.

is_finished()

Collect is done or not.

open_or_create_layer(layer_path[, clear])

Deprecated.

wait_all_unfinished_tasks([all_completed])

Internal.

Attributes

collect_mapping_file_url

The mapping file path.

source_stage_url

The source url to be collected.

target_folder

The target folder to collect assets into.

__init__(
usd_path: str,
collect_dir: str,
usd_only: bool = False,
flat_collection: bool = False,
material_only: bool = False,
failure_options=<CollectorFailureOptions.SILENT: 0>,
skip_existing: bool = False,
max_concurrent_tasks=32,
texture_option=FlatCollectionTextureOptions.BY_MDL,
force_non_read_only=True,
exclusion_rules={},
default_prim_only=False,
**kwargs,
)#

Constructor.

Parameters:
  • usd_path (str) – The usd stage to be collected.

  • collect_dir (str) – The target folder to collect the usd stage to.

  • usd_only (bool, Optional) – Collects usd files only or not. If it’s True, it will ignore all asset types except USD files. Default is False.

  • flat_collection (bool, Optional) – Collects stage without keeping the original dir structure. Default is False.

  • material_only (bool, Optional) – Collects material and textures only or not. If it’s True, it will ignore all other asset types. Default is False. If both `usd_only` and `material_only` are true, it will collect all asset types.

  • skip_existing (bool, Optional) – If files already exist in the target location, don’t copy them again. Default is False.

  • max_concurrent_tasks (int, Optional) – The maximum concurrent tasks to run at the same time. Default is 32.

  • texture_option (FlatCollectionTextureOptions, Optional) – Specifies how textures are grouped in flat collection mode. This is to avoid name collision which results in textures overwriting each other in the cases where textures for different assets are not uniquely named.

  • force_non_read_only (bool, Optional) – If it’s true and source file copied is read-only, it will set the target file writable. By default, it’s true, which means to make all copied files writable. For USD and MDL files, they will always be writable after copy as it needs to be modified during collecting.

  • exclusion_rules (Dict[str, str], Optional) –

    Collector will collect and re-map all dependencies if no exclusion rules are given. It allows you to specify the rules to exclude specified URLs so they won’t be collected, and provide options to map them to new locations. Here is an example.

    {
        "s3://test-path/": "/mount/test-path/",
        "s3://another-path/": None
    }
    

    Here, it defines two rules to exclude the urls prefixed by the key. The first rule will map those URLs prefixed with “s3://test-path/” into location “/mount/test-path/”, and the second one will keep those URLs untouched in the collected file.

  • default_prim_only (bool, Optional) – If it’s True, it will only collect the assets under the default prim, and only save default prim in the main usd file. By default, it’s false, which means to collect all the assets. See DefaultPrimOnlyOptions for more customizations.

Keyword Arguments:
  • default_prim_option (DefaultPrimOnlyOptions, Optional) – Specifies how to collect default prims when default_prim_only is True. This option can be used to skip collecting assets that are not used in the stage composition. By default, it only collects default prim for root layer. REMINDER: When the option is to collect default prim only for all layers, it’s likely that non-default prims in a layer are referenced in any layers and they are removed which causes invalid references.

  • convert_usda_to_usdc (bool, Optional) – If it’s True, it will convert ascii USD files (.usda) to binary format (.usdc). By default, it is False and keeps the original format for all USD files.

async add_copy_task(
source: str,
target: str,
skip_if_existed=False,
)#

Internal. Adds a copy task that copies file from source to target.

Parameters:
  • source (str) – The source url to copy.

  • target (str) – The target url to copy source url into.

  • skip_if_existed (bool, Optional) – If it should skip copy when the target file exists already.

async add_write_task(target: str, content: str | bytes)#

Internal. Adds a write task that writes target file.

Parameters:
  • target (str) – The target url to write.

  • content – (Union[str, bytes]): The content to write. It could be str, or bytes.

cancel()#

Cancel the collector if it’s in progress.

async collect(
progress_callback: Callable[[int, int], None] | None = None,
finish_callback: Callable[[], None] | None = None,
) Tuple[bool, str]#

Collects stage in an asynchronous way.

Parameters:
  • progress_callback (Callable[[int, int], None]) – The progress callback that notifies the current progress in (current_step, total_steps) style.

  • finish_callback (Callable[[], None]) – Finish callback when task is done or cancelled.

Returns:

The success status and the path of the collected stage root if it exists.

Return type:

Tuple[bool, str]

destroy()#

Destructor to release all resources.

get_source_target_url_mapping() Dict[str, str]#

Gets the mapping of all source files to target files. It returns valid value when collect task is done. See get_status() to query collector status.

Returns:

A dict that key is the source url of files, and value is the target url of files.

Return type:

Dict[str, str]

get_status() CollectorStatus#

Gets the collector status. See CollectorStatus for more details.

Returns:

The current status of the collector.

Return type:

CollectorStatus

get_target_url(source_url: str) str#

Gets the target url that the source url is collected to. It returns valid value when collect task is done. See get_status() to query collector status.

Parameters:

source_url (str) – The source url to query.

Returns:

The corresponding target url that the source url has been collected to.

Return type:

str

is_cancelled()#

Collector is cancelled or not. REMINDER: This function is DEPRECATED. See get_status() for more accurate status.

Returns:

Collection is cancelled or not.

Return type:

bool

is_copy_skipped(source_url) bool#

Checkes if it skips copying source_url during collection. It returns valid value when collect task is done. See get_status() to query collector status.

Returns:

Successful or not.

Return type:

bool

is_finished()#

Collect is done or not. It returns True no matter it’s cancelled or successfully done. REMINDER: This function is DEPRECATED. See get_status() for more accurate status.

Returns:

Collection is finished or not.

Return type:

bool

async open_or_create_layer(layer_path, clear=True)#

Deprecated.

async wait_all_unfinished_tasks(all_completed=False)#

Internal.

property collect_mapping_file_url#

The mapping file path. Mapping file records the collection history of this collector. It can help avoiding duplication in collection if the target file exists and is not changed.

property source_stage_url: str#

The source url to be collected.

property target_folder: str#

The target folder to collect assets into.