Hello USD Users,
I’m currently working on a USD resolver that implements a custom context, and i would like to call a function on the context to modify the reselution at runtime.
Overview
Our context supports thinks like URIs, startup pinning, and now we want to introduce runtime redirection. The idea is to let departments like lighting load a redirection file at runtime, which dynamically load whatever the redirection specifies instead of what the sceene defined.
Problem
If a stage is created from scratch (e.g., Usd.Stage.CreateNew
), there’s no redirection file initially tied to it. We want to:
- Get the resolver context from the stage.
- Modify the context to include a redirection file.
- Reload the stage so that the redirection rules take effect.
However, I haven’t been able to find a way to get a resolver context that is subsequently used in further resolution.
Here’s an example of what I’ve tried:
# Create a stage
stage = Usd.Stage.CreateNew(usd_path)
# Get the resolver
res = Ar.GetResolver()
# Get the resolver context from the stage
ctx = stage.GetPathResolverContext().Get()[0]
# Add the redirection file to the context
ctx.setRedirectionFile(str(rdf_path))
# Modify the redirection file
rdf = ctx.getRedirectionFile()
rdf.addRedirection("missingRef.usda", "./sphere.usda")
# Define a prim that references data in the redirection file
# This reference should resolve based on the updated context
prim = stage.DefinePrim("/test", "Xform")
prim.GetReferences().AddReference("missingRef.usda")
Issue
When running the above code:
- The resolver context obtained from the stage doesn’t seem to affect resolution when modified.
- i assume that im getting a copy or simmilar and not the context for the stage.
- i know that GetPathResolverContext is defined for consumers to resolve the same way as the stage so i guess this wont help.
- i also read that context can be thread dependend so modifiying for “the stage” sounds a bit imposible ?
Questions
- How can I modify the resolver context for a newly created stage (not loaded from disk) and ensure it’s used in further resolution?
- Is there a standard way to reload or recompute a stage’s composition to reflect changes in the context or redirection file? (maybe via AR::Notice on the cpp side?)
- are there problems known with eg houdini and the multi node system they use regarding context changes ?
Any insights, suggestions, or best practices would be greatly appreciated. Thank you in advance!