Question:
I’m looking into the USD Paths code. I found that it lists all assets with ModifyAssetPaths, but I want to know which prim is using a specific asset.
Currently, I can traverse the stage and collect all prims, but I can’t figure out how to retrieve the asset path(s) that a given prim is referencing.
For example If a prim is using a texture (e.g. in a material)
I want to be able to trace back from the asset path to the prim(s) that depend on it.
What I tried:
-
I can see asset paths when calling ModifyAssetPaths, but that just lists all of them—it doesn’t tell me which prim owns them.
-
I traversed all prims with stage.Traverse(), but I don’t see a direct way to query which asset paths are authored on each prim.
Question:
How can I find which prim(s) are using a specific asset path in USD?
I asked this question to Perplexity and also our engineers. So far Perplexity says this:
To find which prim(s) are referencing a specific asset path in USD (such as a texture or payload), you need to traverse all prims in your USD stage and inspect their authored properties, relationships, references, and payloads for any matching asset paths.
How To Approach This
- Traverse all prims on the stage (
stage.Traverse()).
- For each prim, iterate through its attributes and relationships to check if they reference an asset path:
- Asset references can appear as attribute values (like in
inputs:file, displayColor, inputs:texture:file, etc.).
- Asset paths can also be inside references or payloads (
prim.GetReferences(), prim.GetPayloads()), or sometimes relationships.
- Material assignments often store asset paths within property values; inspect shader nodes like
UsdShade.Input.Get() or similar.
- Match the asset path you’re searching for against each property or reference value.
Example pseudocode snippet (Python + Usd/PXR):
from pxr import Usd
asset_path_to_find = "<your_asset_path>"
stage = Usd.Stage.Open("your.usd")
for prim in stage.Traverse():
for attr in prim.GetAttributes():
val = attr.Get()
if isinstance(val, str) and asset_path_to_find in val:
print(f"Prim {prim.GetPath()} uses asset {asset_path_to_find} in attribute {attr.GetName()}")
# Check references
for ref in prim.GetReferences().GetAddedReferences():
if asset_path_to_find in ref.assetPath:
print(f"Prim {prim.GetPath()} references asset {asset_path_to_find}")
# Check payloads
for pl in prim.GetPayloads().GetAddedPayloads():
if asset_path_to_find in pl.assetPath:
print(f"Prim {prim.GetPath()} uses asset {asset_path_to_find} as a payload")
1 Like
I tried the suggested code, but ran into a couple of issues:
-
Methods like GetAddedReferences() and GetAddedPayloads() don’t seem to exist on the objects returned by prim.GetReferences() or prim.GetPayloads().
-
I’m not sure what “references” and “payloads” are supposed to represent in USD, so I may be misunderstanding how to use them.
What I did manage:
- By traversing prims and prim.GetAttributes(), I was able to find some asset paths.
What didn’t work:
- This approach doesn’t catch assets coming from Nucleus like:
omniverse://192.168.1.30/Library/usd/test.usd
doesn’t show up when I only inspect attributes.
The code should not care whether the asset is local to your computer, or on Nucleus. Furthermore, it should not care whether the asset is actually in the current usd file, or in an external file that is referenced. References and payloads are files that are brought into the current usd file. So car.usd may reference wheel.usd.
1 Like