Reset free camera when loading a new model.
PiperOrigin-RevId: 871622663 Change-Id: I1f1a4681752f7436c7bc7adbe64dcea286c5620c
This commit is contained in:
committed by
Copybara-Service
parent
fa43e2c03b
commit
6b197e198a
@@ -149,6 +149,7 @@ void App::RequestModelLoad(std::string model_file) {
|
|||||||
void App::RequestModelReload() {
|
void App::RequestModelReload() {
|
||||||
if (model_kind_ == kModelFromFile) {
|
if (model_kind_ == kModelFromFile) {
|
||||||
pending_load_ = model_path_;
|
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);
|
const int state_size = mj_stateSize(model, mjSTATE_INTEGRATION);
|
||||||
history_.Init(state_size);
|
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.
|
// Initialize the speed based on the model's default real-time setting.
|
||||||
float min_error = FLT_MAX;
|
float min_error = FLT_MAX;
|
||||||
const float desired = mju_log(100 * model->vis.global.realtime);
|
const float desired = mju_log(100 * model->vis.global.realtime);
|
||||||
|
|||||||
@@ -232,6 +232,7 @@ class App {
|
|||||||
std::string load_error_;
|
std::string load_error_;
|
||||||
std::string step_error_;
|
std::string step_error_;
|
||||||
std::optional<std::string> pending_load_;
|
std::optional<std::string> pending_load_;
|
||||||
|
bool preserve_camera_on_load_ = false;
|
||||||
ModelKind model_kind_ = kEmptyModel;
|
ModelKind model_kind_ = kEmptyModel;
|
||||||
|
|
||||||
std::unique_ptr<platform::Window> window_;
|
std::unique_ptr<platform::Window> window_;
|
||||||
|
|||||||
Reference in New Issue
Block a user