diff --git a/SofaImGui/src/SofaImGui/ImGuiGUIEngine.cpp b/SofaImGui/src/SofaImGui/ImGuiGUIEngine.cpp index 0694fd9f63..db771cc290 100644 --- a/SofaImGui/src/SofaImGui/ImGuiGUIEngine.cpp +++ b/SofaImGui/src/SofaImGui/ImGuiGUIEngine.cpp @@ -79,6 +79,7 @@ #include #include #include +#include #include @@ -223,18 +224,21 @@ void ImGuiGUIEngine::loadFile(sofaglfw::SofaGLFWBaseGUI* baseGUI, sofa::core::sp sofa::simulation::node::initRoot(groot.get()); - auto camera = baseGUI->getCamera(); - if (camera) + + baseGUI->addCameraIfRequired(); + + if (baseGUI->getCamera()) { + if( groot->f_bbox.getValue().isValid()) { - camera->fitBoundingBox(groot->f_bbox.getValue().minBBox(), groot->f_bbox.getValue().maxBBox()); + baseGUI->getCamera()->fitBoundingBox(groot->f_bbox.getValue().minBBox(), groot->f_bbox.getValue().maxBBox()); } else { msg_warning_when(!groot->f_bbox.getValue().isValid(), "GUI") << "Global bounding box is invalid: " << groot->f_bbox.getValue(); } - baseGUI->changeCamera(camera); + baseGUI->changeCamera(baseGUI->getCamera()); } else {