Skip to content

Commit 6b197e1

Browse files
haroonqcopybara-github
authored andcommitted
Reset free camera when loading a new model.
PiperOrigin-RevId: 871622663 Change-Id: I1f1a4681752f7436c7bc7adbe64dcea286c5620c
1 parent fa43e2c commit 6b197e1

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/experimental/studio/app.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ void App::RequestModelLoad(std::string model_file) {
149149
void App::RequestModelReload() {
150150
if (model_kind_ == kModelFromFile) {
151151
pending_load_ = model_path_;
152+
preserve_camera_on_load_ = true;
152153
}
153154
}
154155

@@ -199,6 +200,16 @@ void App::OnModelLoaded(std::string filename, ModelKind model_kind) {
199200
const int state_size = mj_stateSize(model, mjSTATE_INTEGRATION);
200201
history_.Init(state_size);
201202

203+
if (!preserve_camera_on_load_) {
204+
const int model_cam = model->vis.global.cameraid;
205+
if (model_cam >= 0 && model_cam < model->ncam) {
206+
ui_.camera_idx = platform::SetCamera(model, &camera_, model_cam);
207+
} else {
208+
mjv_defaultFreeCamera(model, &camera_);
209+
}
210+
}
211+
preserve_camera_on_load_ = false;
212+
202213
// Initialize the speed based on the model's default real-time setting.
203214
float min_error = FLT_MAX;
204215
const float desired = mju_log(100 * model->vis.global.realtime);

src/experimental/studio/app.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ class App {
232232
std::string load_error_;
233233
std::string step_error_;
234234
std::optional<std::string> pending_load_;
235+
bool preserve_camera_on_load_ = false;
235236
ModelKind model_kind_ = kEmptyModel;
236237

237238
std::unique_ptr<platform::Window> window_;

0 commit comments

Comments
 (0)