File tree Expand file tree Collapse file tree 2 files changed +12
-0
lines changed
Expand file tree Collapse file tree 2 files changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -149,6 +149,7 @@ void App::RequestModelLoad(std::string model_file) {
149149void 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 );
Original file line number Diff line number Diff 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_;
You can’t perform that action at this time.
0 commit comments