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

UsdUtilsComputeAllDependencies - Dependency identifiers get modified #2074

Closed
ColinKennedy opened this issue Oct 28, 2022 · 1 comment
Closed

Comments

@ColinKennedy
Copy link

ColinKennedy commented Oct 28, 2022

Description of Issue

When calling UsdUtils.ComputeAllDependencies in Python (and I imagine in C++ as well), only the first returned Layer, the input Layer, has expected identifier and resolvedPath values.

Steps to Reproduce

  1. Write a custom resolver where MyCustomResolver::_CreateIdentifier and MyCustomResolver::_Resolve return different values (if you want a minimum repro, I can write one)
  2. Observe the following behavior

Without ComputeAllDependencies:

dependency = "database:I_am_a_dependency.usda"
layer = Sdf.Layer.FindOrOpen(dependency)
layer.identifier  # "database:I_am_a_dependency.usda"
layer.resolvedPath  # "databaseresolvedpath:/path/to/I_am_a_dependency.usda"

With ComputeAllDependencies:

uri = "database:top_uri.usda"
dependency = "database:I_am_a_dependency.usda"
UsdUtils.ComputeAllDependencies(uri)
layer = Sdf.Layer.FindOrOpen(dependency)
layer.identifier  # "databaseresolvedpath:/path/to/I_am_a_dependency.usda"            <-- This changed!
layer.resolvedPath  # "databaseresolvedpath:/path/to/I_am_a_dependency.usda"

As mentioned in the related usd-interest forum post, I don't know if this is somehow intended behavior but it causes problems in other areas. For example:

Without ComputeAllDependencies:

dependency = "database:I_am_a_dependency.usda"
layer = Sdf.Layer.FindOrOpen(dependency)
layer.identifier  # "database:I_am_a_dependency.usda"
layer.resolvedPath  # "databaseresolvedpath:/path/to/I_am_a_dependency.usda"
layer.assetName  # "I_am_a_dependency"
layer.version  # "latest"
layer.GetAssetInfo()  # {"filesystemPath": "/path/to/I_am_a_dependency.usda"}
# ... etc ...

With ComputeAllDependencies:

uri = "database:top_uri.usda"
dependency = "database:I_am_a_dependency.usda"
layers, assets, unresolved = UsdUtils.ComputeAllDependencies(uri)  # <-- Note, ``dependency`` is a sublayer / reference / payload in ``uri``, so it gets modified as a result of ``uri`` being called
layer = Sdf.Layer.FindOrOpen(dependency)
layer.identifier  # "databaseresolvedpath:/path/to/I_am_a_dependency.usda"         <-- Expected "database:I_am_a_dependency.usda" aka ``dependency``
layer.resolvedPath  # "databaseresolvedpath:/path/to/I_am_a_dependency.usda"
layer.assetName  # ""
layer.version  # ""
layer.GetAssetInfo()  # {}
# ... etc ...

Note that even though the identifier / URI dependency was given to layer = Sdf.Layer.FindOrOpen(dependency), the returned layer still has a returned identifier of "databasepath:/path/to/I_am_a_dependency.usda"

Possible explanation why this is happening

I'm guessing that somewhere within UsdUtils.ComputeAllDependencies implementation, when accessing dependent Layers, roughly the following code is being called

Sdf.Layer.FindOrOpen(
    Ar.GetResolver().Resolve(Ar.GetResolver().CreateIdentifier(dependency, parentResolvedPath)).GetPathString()
)

Because the resolvedPath of the dependency is being passed as input to Sdf.Layer.FindOrOpen, the layer that's opened, the returned Layer is forced to treat its input text as an identifier.

Instead, I would've expected this code:

Sdf.Layer.FindOrOpen(
-    Ar.GetResolver().Resolve(Ar.GetResolver().CreateIdentifier(dependency, parentResolvedPath)).GetPathString()
+    Ar.GetResolver().CreateIdentifier(dependency, parentResolvedPath)
)

Then the returned Layer would have "identifier as identifier, resolvedPath as resolvedPath", as opposed to "resolvedPath as identifier, resolvedPath as resolvedPath"

System Information (OS, Hardware)

Package Versions

  • USD 22.08 (This bug, I've noticed in USD 19.11 as well, in Ar 1.0)
  • Python 3

Build Flags

A default build_usd.py install

Related Information

Possibly related issue: #2073

If "Possible explanation why this is happening" is a correct guess, then it makes sense why anonymous Layers being passed to UsdUtils.ComputeAllDependencies(anonymous.identifier) return empty. After all, if you call Ar.GetResolver().Resolve on an anonymous Layer, it always returns an empty string!

Related Information, Continued

A (rather long) usd-interest forum post: https://groups.google.com/g/usd-interest/c/JSfSTNIJRug

I posted this before hearing back on that post. Apologies if this post is a bit premature, but I figured a GitHub issue is probably the best place to discuss this specific behavior (bug?)

@sunyab
Copy link
Contributor

sunyab commented Nov 4, 2022

Filed as internal issue #USD-7737

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

No branches or pull requests

2 participants