Add USD content type support in MJCF.
PiperOrigin-RevId: 788075561 Change-Id: If37cc254cab0411454de7663e0b3ff9f2b263281
This commit is contained in:
committed by
Copybara-Service
parent
3434f5d9c7
commit
a04e0385e4
@@ -18,11 +18,21 @@
|
||||
#include <mujoco/mujoco.h>
|
||||
#include <pxr/usd/usd/common.h>
|
||||
|
||||
// Given a USD file parse to a spec, then compile and return the low-level model.
|
||||
// Given a USD file parse to a spec, then compile and return the low-level
|
||||
// model.
|
||||
//
|
||||
// Particular care is taken for physics data to be lossless but visual
|
||||
// data such as materials may be lossy.
|
||||
MJAPI mjModel* mj_loadUSD(const char* filename, const mjVFS* vfs, char* error, int error_sz);
|
||||
MJAPI mjModel* mj_loadUSD(const char* filename, const mjVFS* vfs, char* error,
|
||||
int error_sz);
|
||||
|
||||
// Given a USD layer identifier, this function will do a best effort conversion
|
||||
// from the composed stage to mjSpec.
|
||||
//
|
||||
// Particular care is taken for physics data to be lossless but visual
|
||||
// data such as materials may be lossy.
|
||||
MJAPI mjSpec* mj_parseUSD(const char* identifier, const mjVFS* vfs, char* error,
|
||||
int error_sz);
|
||||
|
||||
// Given a USD stage, this function will do a best effort conversion to
|
||||
// mjSpec.
|
||||
|
||||
@@ -1744,3 +1744,10 @@ mjSpec* mj_parseUSDStage(const pxr::UsdStageRefPtr stage) {
|
||||
|
||||
return spec;
|
||||
}
|
||||
|
||||
MJAPI mjSpec* mj_parseUSD(const char* identifier, const mjVFS* vfs, char* error,
|
||||
int error_sz) {
|
||||
auto stage = pxr::UsdStage::Open(identifier);
|
||||
return mj_parseUSDStage(stage);
|
||||
}
|
||||
|
||||
|
||||
@@ -45,6 +45,9 @@
|
||||
#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;
|
||||
@@ -3332,6 +3335,10 @@ void mjXReader::Asset(XMLElement* section, const mjVFS* vfs) {
|
||||
|
||||
if (content_type == "text/xml") {
|
||||
child = mj_parseXML(filename.c_str(), vfs, error.data(), error.size());
|
||||
#ifdef mjUSEUSD
|
||||
} else if (content_type == "text/usd") {
|
||||
child = mj_parseUSD(filename.c_str(), vfs, error.data(), error.size());
|
||||
#endif // mjUSEUSD
|
||||
} else {
|
||||
throw mjXError(elem, "unsupported content_type: %s", content_type.c_str());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user