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
-36
View File
@@ -31,12 +31,6 @@
#include "xml/xml_global.h"
#include "xml/xml_native_reader.h"
#include "xml/xml_util.h"
#if defined(mjUSEUSD)
#include <mujoco/experimental/usd/usd.h>
#include <pxr/usd/usd/stage.h>
#endif
//---------------------------------- Functions -----------------------------------------------------
@@ -75,36 +69,6 @@ mjModel* mj_loadXML(const char* filename, const mjVFS* vfs,
return m;
}
#if defined(mjUSEUSD)
// parse USD file, compile it, and return low-level model.
// if vfs is not NULL, look up files in vfs before reading from disk
// error can be NULL; otherwise assumed to have size error_sz
mjModel* mj_loadUSD(const char* filename, const mjVFS* vfs, char* error, int error_sz) {
auto stage = pxr::UsdStage::Open(filename);
if (stage == nullptr) {
mjCopyError(error, "Failed to load USD stage from file.", error_sz);
return nullptr;
}
// Parse USD into mjSpec.
std::unique_ptr<mjSpec, std::function<void(mjSpec*)> > spec(
mj_parseUSDStage(stage),
[](mjSpec* s) {
mj_deleteSpec(s);
});
// Compile new model.
mjModel* m = mj_compile(spec.get(), vfs);
if (!m) {
mjCopyError(error, mjs_getError(spec.get()), error_sz);
return nullptr;
}
SetGlobalXmlSpec(spec.release());
return m;
}
#endif
// update XML data structures with info from low-level model, save as MJCF
// returns 1 if successful, 0 otherwise