MuJoCo Web Viewer: Implement parallel chunked model downloading and in-place model reloading.

This change introduces parallel chunked downloading for large model files (.mjb) directly into WASM linear memory, enables model loading without full page reloads and reduces memory overhead.

Key changes:
- Implement a chunked model endpoint in the Python web server to support range requests.
- Add parallel chunked fetching in the frontend with retry logic and a single-fetch fallback.
- Increase initial WASM memory to 3 GB to accommodate large models and prevent heap fragmentation.
- Support in-place model reloading in the C++ client, including texture cache invalidation when the Filament context is recreated.
- Display a model download progress bar and model parsing/loading banner to the UI.
- Fixes model drag and drop (caused by typo in sessionId, corrected to session_id).

PiperOrigin-RevId: 960249236
Change-Id: Icac89e6a4ca099882aaf9b111744c1b6ab0cc6c1
This commit is contained in:
Matija Kecman
2026-08-06 05:51:01 -07:00
committed by Copybara-Service
parent 7fd2061f5c
commit 84950fa371
11 changed files with 406 additions and 98 deletions
@@ -226,9 +226,9 @@ void Session::Update() {
void Session::HandleRemoteUiState(RemoteUiState state, int close_code) {
remote_ui_state_ = state;
// No stream to manage, nothing left to claim (settled spectator), or the
// session itself is down or reloading — the /state policies rule then.
// session itself is down — the /state policies rule then.
if (state == RemoteUiState::kNoSocket || role_ == SessionRole::kSpectating ||
reload_pending_ || server_close_code_ != 0) {
server_close_code_ != 0) {
return;
}
const double now = emscripten_get_now() / 1000.0;
@@ -265,7 +265,7 @@ void Session::HandleRemoteUiState(RemoteUiState state, int close_code) {
void Session::HandleMessage(const uint8_t* data, uint32_t num_bytes) {
last_message_time_ = emscripten_get_now() / 1000.0;
if (reload_pending_ || !callbacks_.ReadyForPayload()) {
if (!callbacks_.ReadyForPayload()) {
return;
}
bytes_accum_ += num_bytes;
@@ -281,8 +281,10 @@ void Session::HandleMessage(const uint8_t* data, uint32_t num_bytes) {
} else if (view.model_crc32 != *model_crc32_) {
LOG(Info, "Model changed on the Python side (ident %u -> %u); reloading",
*model_crc32_, view.model_crc32);
reload_pending_ = true;
EM_ASM({ setTimeout(function() { location.reload(); }, 0); });
// Set the new CRC so subsequent payloads don't re-trigger while the new
// model is being fetched.
model_crc32_ = view.model_crc32;
callbacks_.OnModelChanged();
return;
}