Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Conversation

philsawicki
Copy link

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 existence of a Stage containing a "/TestPrim" Prim with a "custom:jsonFilePath" Attribute referencing a JSON asset.
  • A JSON asset located on disk with the following content:
{
    "name": "example",
    "value": 1234,
    "child-object": {
        "key": "value"
    }
}

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"}}
  • I have verified that all unit tests pass with the proposed changes
  • I have submitted a signed Contributor License Agreement

@jesschimein
Copy link
Contributor

Filed as internal issue #USD-10194

@jesschimein
Copy link
Contributor

/AzurePipelines run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@sunyab sunyab changed the base branch from release to dev October 7, 2024 16:34
@pixar-oss pixar-oss merged commit b45c1dc into PixarAnimationStudios:dev Oct 15, 2024
3 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants