Add WASM binding for mj_compile.

It does not support model assets management via VFS yet.

PiperOrigin-RevId: 844864882
Change-Id: I422d7896ed024fc6f5c3fa923a58cdc9059f3bee
This commit is contained in:
Google DeepMind
2025-12-15 11:56:41 -08:00
committed by Copybara-Service
parent eef71832db
commit 477a14dcb2
4 changed files with 46 additions and 1 deletions
+10
View File
@@ -33,6 +33,7 @@
#include <mujoco/mjmodel.h>
#include <mujoco/mjvisualize.h>
#include <mujoco/mujoco.h>
#include <mujoco/mjspec.h>
#include "engine/engine_util_errmem.h"
#include "wasm/unpack.h"
@@ -406,6 +407,15 @@ std::unique_ptr<MjSpec> parseXMLString_wrapper(const std::string &xml) {
return std::unique_ptr<MjSpec>(new MjSpec(ptr));
}
std::unique_ptr<MjModel> mj_compile_wrapper(const MjSpec& spec) {
mjSpec* spec_ptr = spec.get();
mjModel* model = mj_compile(spec_ptr, nullptr);
if (!model || mjs_isWarning(spec_ptr)) {
mju_error("%s", mjs_getError(spec_ptr));
}
return std::unique_ptr<MjModel>(new MjModel(model));
}
void error_wrapper(const String& msg) { mju_error("%s\n", msg.as<const std::string>().data()); }
int mj_saveLastXML_wrapper(const String& filename, const MjModel& m) {