Add from_xml_string to MuJoCo WASM bindings.

This change introduces new functions to load an `mjModel` from an XML string. Two overloads are provided: one that creates a temporary VFS and one that uses a MjVFS arg.

Also updated other places where `from_xml_string` should be used: demos, readme, etc.

PiperOrigin-RevId: 882581762
Change-Id: I8428196f8f56ae9630fcd4f0bb6763cdc1c43da0
This commit is contained in:
Google DeepMind
2026-03-12 07:35:08 -07:00
committed by Copybara-Service
parent df0bc58578
commit b294d15558
7 changed files with 159 additions and 28 deletions
+26 -9
View File
@@ -549,29 +549,46 @@ def _build_struct_bindings(
MJDATA_ACCESSORS
#undef X_ACCESSOR""".lstrip())
elif w == "MjModel":
builder.line(
"// mj_loadXML is deprecated and will be removed in a future release"
)
builder.line(
'.class_function("mj_loadXML",'
" emscripten::select_overload<std::unique_ptr<MjModel>(std::string)>(&mj_loadXML_wrapper_1))"
)
builder.line(
'.class_function("from_xml_path",'
" emscripten::select_overload<std::unique_ptr<MjModel>(std::string)>(&mj_loadXML_wrapper_1))"
)
builder.line(
'.class_function("mj_loadXML",'
" emscripten::select_overload<std::unique_ptr<MjModel>(std::string,"
" const MjVFS&)>(&mj_loadXML_wrapper_2))"
)
builder.line(
'.class_function("from_xml_path",'
" emscripten::select_overload<std::unique_ptr<MjModel>(std::string,"
" const MjVFS&)>(&mj_loadXML_wrapper_2))"
)
f2 = common.wrapped_function_name(
introspect_functions.FUNCTIONS["mj_loadModel"]
)
builder.line(
"// mj_loadModel is deprecated and will be removed in a future"
" release"
)
builder.line(f'.class_function("mj_loadModel", &{f2})')
builder.line(f'.class_function("from_binary_path", &{f2})')
builder.line(
'.class_function("from_xml_string",'
" emscripten::select_overload<std::unique_ptr<MjModel>(const"
" std::string&)>(&from_xml_string_wrapper_1))"
)
builder.line(
'.class_function("from_xml_string",'
" emscripten::select_overload<std::unique_ptr<MjModel>(const"
" std::string&, const MjVFS&)>(&from_xml_string_wrapper_2))"
)
builder.line(
'.class_function("from_xml_path",'
" emscripten::select_overload<std::unique_ptr<MjModel>(std::string)>(&mj_loadXML_wrapper_1))"
)
builder.line(
'.class_function("from_xml_path",'
" emscripten::select_overload<std::unique_ptr<MjModel>(std::string,"
" const MjVFS&)>(&mj_loadXML_wrapper_2))"
)
builder.line(".constructor<const MjModel &>()")
builder.line("""
// Binds the functions on MjModel that return accessors.