Generating relative asset paths?

Hi,

Is there a correct way to generate relative file paths using native usd api’s? I see that Sdf.Path has a MakeRelatviePath, but this doesn’t seem correct as I am trying to may relative paths for asset paths, sublayers etc. This fails when you have a path with a digit in it for example: /some/file/system/path/2048x1156/.

Or would it be better to just fall back to using python’s pathlib to generate these?

Yeah, Sdf.Path is about scenegraph paths, not assetPaths. I don’t believe we provide any such functionality, so pathlib sounds like a good way to go.

Thanks @spiff! I am glad I wasn’t overlooking something obvious!

Out of curiosity where would you use a relative path in a usd file? Its not possible to do this with composition arcs right (I am pretty sure I tried and it said it must be an absolute path)…

Relative paths can be used in any asset-path, so long as the resolver knows how to resolve them. So in the ArDefaultResolver, a path like references = @ceramicMaterialsLibrary.usd@ would be perfectly fine, and would trigger a search through all of the directories listed in the configured searchPath.

You’d use this style anytime you want to have the flexibility to reorganize such assets without needing to touch your existing documents.

Sorry I meant a relative prim path’s…i.e what is the purpose of the Sdf.Path().MakeRelativePath() within the scene graph?

It’s not really a necessary thing… SdfLayer absolutizes paths as they are authored, and as they are read from usda files (which can be hand-edited to contain relative paths). We have a few pieces of internal code that make use of it either for display purposes (a common scenario is for a prim to target lots of its descendant prims, and relativizing the paths for display reduces clutter), and I saw a site that uses it before sticking paths as keys into a map, though I’m not sure really why that’s advantageous.

1 Like