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
+1 -14
View File
@@ -45,9 +45,6 @@
#include "xml/xml_base.h"
#include "xml/xml_util.h"
#include "tinyxml2.h"
#ifdef mjUSEUSD
#include <mujoco/experimental/usd/usd.h>
#endif // mjUSEUSD
namespace {
using std::string;
@@ -3446,21 +3443,11 @@ void mjXReader::Asset(XMLElement* section, const mjVFS* vfs) {
ReadAttrTxt(elem, "content_type", content_type);
// parse the child
mjSpec* child = nullptr;
std::array<char, 1024> error;
auto filename = modelfiledir_ + ReadAttrFile(elem, "file", vfs).value();
#ifdef mjUSEUSD
if (content_type == "text/usd") {
child = mj_parseUSD(filename.c_str(), vfs, error.data(), error.size());
} else {
#endif // mjUSEUSD
child = mj_parse(filename.c_str(), content_type.c_str(), vfs,
mjSpec* child = mj_parse(filename.c_str(), content_type.c_str(), vfs,
error.data(), error.size());
#ifdef mjUSEUSD
}
#endif // mjUSEUSD
if (!child) {
throw mjXError(elem, "could not parse model file with error: %s", error.data());
}