Add mj_loadBinary binding to WASM.
This change adds an Emscripten binding for loading binary MuJoCo models (`.mjb`) from the virtual filesystem. The new binding, `mj_loadBinary`, takes a filename and an `MjVFS` object, enabling the loading of models that reference assets within the VFS. PiperOrigin-RevId: 859740455 Change-Id: I9f9d8bbba0b57422e2356867e4282a1b04566475
This commit is contained in:
committed by
Copybara-Service
parent
61f13cd8f1
commit
e1992e62d7
@@ -8017,6 +8017,15 @@ void mj_saveModel_wrapper(const MjModel& m, const StringOrNull& filename, const
|
||||
mj_saveModel(m.get(), filename_.data(), buffer_.data(), static_cast<int>(buffer_.size()));
|
||||
}
|
||||
|
||||
std::unique_ptr<MjModel> mj_loadModel_wrapper(std::string filename, const MjVFS& vfs) {
|
||||
mjModel *model = mj_loadModel(filename.c_str(), vfs.get());
|
||||
if (!model) {
|
||||
printf("mj_loadModel: failed to load from mjb");
|
||||
return nullptr;
|
||||
}
|
||||
return std::unique_ptr<MjModel>(new MjModel(model));
|
||||
}
|
||||
|
||||
std::unique_ptr<MjSpec> parseXMLString_wrapper(const std::string &xml) {
|
||||
char error[1000];
|
||||
mjSpec *ptr = mj_parseXMLString(xml.c_str(), nullptr, error, sizeof(error));
|
||||
@@ -11206,6 +11215,7 @@ EMSCRIPTEN_BINDINGS(mujoco_bindings) {
|
||||
.property("uselimit", &MjLROpt::uselimit, &MjLROpt::set_uselimit, reference());
|
||||
emscripten::class_<MjModel>("MjModel")
|
||||
.class_function("mj_loadXML", &mj_loadXML_wrapper, take_ownership())
|
||||
.class_function("mj_loadBinary", &mj_loadModel_wrapper, take_ownership())
|
||||
.constructor<const MjModel &>()
|
||||
// Binds the functions on MjModel that return accessors.
|
||||
#define X_ACCESSOR(NAME, Name, OBJTYPE, field_name, nfield) \
|
||||
|
||||
Reference in New Issue
Block a user