Move OpenUSD parsing to usd_decoder

Add usd_decoder to mujoco/plugin.
  - Previously was src/experimental/usd/usd_to_mjspec.cc, now that same spec is returned by the plugin.

PiperOrigin-RevId: 854350962
Change-Id: Ia980190a557c50ce8197980922a2594b613859b4
This commit is contained in:
Sam Haves
2026-01-09 14:47:37 -08:00
committed by Copybara-Service
parent 64a2345c07
commit a5dc57c0c3
17 changed files with 270 additions and 317 deletions
+1
View File
@@ -196,6 +196,7 @@ if(SIMULATE_BUILD_EXECUTABLE)
target_link_libraries(
simulate
mujoco::usd::mjcf
usd_decoder_plugin
)
endif()
+17 -21
View File
@@ -25,9 +25,6 @@
#include <string>
#include <thread>
#if defined(mjUSEUSD)
#include <mujoco/experimental/usd/usd.h>
#endif
#include <mujoco/mujoco.h>
#include "glfw_adapter.h"
#include "simulate.h"
@@ -241,22 +238,26 @@ mjModel* LoadModel(const char* file, mj::Simulate& sim) {
if (!mnew) {
mju::strcpy_arr(loadError, "could not load binary model");
}
#if defined(mjUSEUSD)
} else if (extension == ".usda" || extension == ".usd" ||
extension == ".usdc" || extension == ".usdz" ) {
mnew = mj_loadUSD(filename, nullptr, loadError, kErrorLength);
#endif
} else {
} else if (extension == ".xml") {
mnew = mj_loadXML(filename, nullptr, loadError, kErrorLength);
// remove trailing newline character from loadError
if (loadError[0]) {
int error_length = mju::strlen_arr(loadError);
if (loadError[error_length-1] == '\n') {
loadError[error_length-1] = '\0';
}
} else {
mjSpec* spec = mj_parse(filename, nullptr, nullptr, loadError, kErrorLength);
if (!spec) {
mju::strcpy_arr(loadError, "could not parse model");
} else {
mnew = mj_compile(spec, nullptr);
mj_deleteSpec(spec);
}
}
// remove trailing newline character from loadError
if (loadError[0]) {
int error_length = mju::strlen_arr(loadError);
if (loadError[error_length-1] == '\n') {
loadError[error_length-1] = '\0';
}
}
auto load_interval = mj::Simulate::Clock::now() - load_start;
double load_seconds = Seconds(load_interval).count();
@@ -516,11 +517,6 @@ int main(int argc, char** argv) {
// scan for libraries in the plugin directory to load additional plugins
scanPluginLibraries();
#if defined(mjUSEUSD)
// If USD is used, print the version.
std::printf("OpenUSD version v%d.%02d\n", PXR_MINOR_VERSION, PXR_PATCH_VERSION);
#endif
mjvCamera cam;
mjv_defaultCamera(&cam);