Relative navigation in url

Hello

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.

I’m using c++

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;

Hello

Thank you very much for your help, i ended up using omniClientCombineUrls directly as the following code gives me the url i was expecting

	size_t sz = 150;
	char* buffer = new char[sz]();
	std::string fullPath = "omniverse://localhost/projects/project1/world.usd";
	auto url = omniClientCombineUrls(fullPath.c_str(), "_refs/",buffer,&sz);

url = omniverse://localhost/projects/project1/_refs/

as a side note, i also found out that

size_t sz = 150;
char* buffer = new char[sz]();
std::string fullPath = "omniverse://localhost/projects/project1/world.usd";
auto url = omniClientCombineUrls(fullPath.c_str(), ".",buffer,&sz);

returns url as omniverse://localhost/projects/project1/

Thanks again for your help

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.