PixarAnimationStudios / OpenUSD

Universal Scene Description
http://www.openusd.org
Other
6.18k stars 1.23k forks source link

Expose bindings to ArAsset, to support performing OpenAsset(resolvedPath) from Python #3318

Closed philsawicki closed 1 month ago

philsawicki commented 2 months ago

Description of Change(s)

This PR exposes Python bindings for ArAsset of the Asset Resolver module, ultimately enabling operations such as ArResolver.OpenAsset(resolvedPath) to allow reading ArAsset buffers from Python (which was previously only available from C++).

The proposed changes enable features such as querying contents of assets referenced within USD Stages by way of the path resolution behaviors already implemented within Asset Resolvers.

Python Sample

This PR enables the following type of workflow from Python (see unit tests included in the PR for practical examples).

Assumptions:

The following Python snippet illustrates using the OpenAsset(resolvedPath: Ar.ResolvedPath), which was previously not exposed:

# [...]

# Retrieve the content of the ArAsset referenced by the Attribute on the Stage:
json_asset = Ar.GetResolver().OpenAsset(resolvedPath=resolved_json_asset_path)
print(f'JSON asset size: {json_asset.GetSize()}')
print(f'JSON asset data: {json_asset.Read()}')

Which produces the following output:

JSON asset size: 68
JSON asset data: {"name": "example", "value": 1234, "child-object": {"key": "value"}}
jesschimein commented 2 months ago

Filed as internal issue #USD-10194

jesschimein commented 2 months ago

/AzurePipelines run

azure-pipelines[bot] commented 2 months ago
Azure Pipelines successfully started running 1 pipeline(s).