I’m writing a new connector in which I pretend to create a usd, and define models and textures with relative paths, if the user provides a full path for the USD like omniverse://server/projects/projectname/bigusdfile.usd and I would like to put referenced models in the path omniverse://server/projects/projectname/_refs/models/simplemodel.usd and materials under omniverse://server/projects/projectname/_refs/materials/simple_material.mdl for this I would need to get the url omniverse://server/projects/projectnamme/ and concatenate the _refs/ to use omniClientCopy functions to upload the predefined models and materials.
I tried using omniClientBreakUrl, and the breakdown path gives me the .usd file as well
I could search for the last ‘/’ char in the breakdown path, but as I saw in one of the tutorial videos, directly manipulating/searching the url is not recommended
my ideal solution would be a function like omniClientGetParentUrl or something along those lines, but i couldnt find any function like that.
You’re looking for one of my favorite functions in the whole library… omniClientMakeRelativeUrl(). We encounter this issue a lot so we made a helper for that reason. Let me know if it doesn’t do what you need and I’ll spend more time trying to work out an example for you.
// This makes "otherUrl" relative to "baseUrl"
// It attempts to make the shortest URL possible while guaranteeing that you can pass the returned relative URL and
// baseUrl to omniClientComibneUrls and get back the original otherUrl (except that the returned URL is normalized)
// buffer rules are the same as omniClientMakeUrl
// Note that trailing slashes matter here!
// ("/a/b/c", "/a/d") = "../d"
// ("/a/b/c/", "/a/d") = "../../d"
// The reason is because trailing slashes also matter in the baseUrl for omniClientCombineUrls
OMNICLIENT_EXPORT(char*)
omniClientMakeRelativeUrl(char const* baseUrl, char const* otherUrl, char* buffer, size_t* bufferSize)
OMNICLIENT_NOEXCEPT;