diff --git a/src/experimental/studio/app.cc b/src/experimental/studio/app.cc index ec1f4a1f..4c250f36 100644 --- a/src/experimental/studio/app.cc +++ b/src/experimental/studio/app.cc @@ -149,6 +149,7 @@ void App::RequestModelLoad(std::string model_file) { void App::RequestModelReload() { if (model_kind_ == kModelFromFile) { pending_load_ = model_path_; + preserve_camera_on_load_ = true; } } @@ -199,6 +200,16 @@ void App::OnModelLoaded(std::string filename, ModelKind model_kind) { const int state_size = mj_stateSize(model, mjSTATE_INTEGRATION); history_.Init(state_size); + if (!preserve_camera_on_load_) { + const int model_cam = model->vis.global.cameraid; + if (model_cam >= 0 && model_cam < model->ncam) { + ui_.camera_idx = platform::SetCamera(model, &camera_, model_cam); + } else { + mjv_defaultFreeCamera(model, &camera_); + } + } + preserve_camera_on_load_ = false; + // Initialize the speed based on the model's default real-time setting. float min_error = FLT_MAX; const float desired = mju_log(100 * model->vis.global.realtime); diff --git a/src/experimental/studio/app.h b/src/experimental/studio/app.h index adcfab87..170aadd6 100644 --- a/src/experimental/studio/app.h +++ b/src/experimental/studio/app.h @@ -232,6 +232,7 @@ class App { std::string load_error_; std::string step_error_; std::optional pending_load_; + bool preserve_camera_on_load_ = false; ModelKind model_kind_ = kEmptyModel; std::unique_ptr window_;