Add a github: resource provider scheme to MuJoCo Live.
This resolves to https://raw.githubusercontent.com/... under the hood. PiperOrigin-RevId: 916050807 Change-Id: I1630e29a5b5aad0e39cdd8aa4cfc1ff1a71f19d9
This commit is contained in:
committed by
Copybara-Service
parent
99b01b9f87
commit
a03191b9e8
@@ -195,6 +195,35 @@ void Init() {
|
||||
http_provider.prefix = "https";
|
||||
mjp_registerResourceProvider(&http_provider);
|
||||
|
||||
// Register a "github:" resource provider that resolves
|
||||
// github:org/repo/branch/path/to/file.xml to
|
||||
// https://raw.githubusercontent.com/org/repo/branch/path/to/file.xml
|
||||
mjpResourceProvider github_provider;
|
||||
mjp_defaultResourceProvider(&github_provider);
|
||||
|
||||
github_provider.open = [](mjResource* resource) {
|
||||
std::string name(resource->name);
|
||||
// Strip the "github:" prefix and prepend the raw.githubusercontent URL.
|
||||
std::string url =
|
||||
"https://raw.githubusercontent.com/" + name.substr(strlen("github:"));
|
||||
return FetchCache::Instance().Fetch(url.c_str());
|
||||
};
|
||||
github_provider.read = [](mjResource* resource, const void** buffer) {
|
||||
std::string name(resource->name);
|
||||
std::string url =
|
||||
"https://raw.githubusercontent.com/" + name.substr(strlen("github:"));
|
||||
return FetchCache::Instance().Read(url.c_str(), buffer);
|
||||
};
|
||||
github_provider.close = [](mjResource* resource) {
|
||||
std::string name(resource->name);
|
||||
std::string url =
|
||||
"https://raw.githubusercontent.com/" + name.substr(strlen("github:"));
|
||||
FetchCache::Instance().Close(url.c_str());
|
||||
};
|
||||
|
||||
github_provider.prefix = "github";
|
||||
mjp_registerResourceProvider(&github_provider);
|
||||
|
||||
g_app = new mujoco::studio::App({
|
||||
.width = width,
|
||||
.height = height,
|
||||
|
||||
Reference in New Issue
Block a user