bonsaiviewer: View Selected Model from the models panel context menu

Right-clicking a model in the models panel now offers "View Selected Model",
which frames the camera on just that model's geometry — View All, scoped to
one model. With several models selected the action reads "View Selected
Models" and frames their union, matching how the panel's existing Move to
Group already treats a multi-selection.

The AABB fold behind viewAll moves into InstanceCompose, which exists so this
kind of logic is unit-testable without a Qt window or a wgpu device (populating
ViewportCore's model map needs a real GPU, so the fold was previously
untestable in place). It splits in two:

- sceneWorldAabb   — every VISIBLE model, what viewAll frames.
- modelsWorldAabb  — only the named models, hidden or not. A model the caller
                     named explicitly is framed even if hidden; second-guessing
                     that is worse than honouring it. Models with no loaded
                     geometry contribute nothing, and if none of them do the
                     camera is left alone rather than flying to the origin.

Both are covered by six new cases in test_instance_compose (131 total).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Dion Moult
2026-07-14 13:53:30 +10:00
parent 89bb3074de
commit e4f8475ce8
10 changed files with 249 additions and 18 deletions
@@ -262,6 +262,30 @@ void removeModel(SessionState& session, ViewportWindow& viewport, QWidget& host,
session.setStatusMessage("Models", "Model removed");
}
void viewModels(SessionState& session, ViewportWindow& viewport, const QStringList& model_ids) {
// Federation ids are the panel's currency; the viewport speaks session
// model ids. sessionModelIdForModelId returns 0 for a model the viewport
// has never been given geometry for — skip those rather than framing id 0.
std::vector<uint32_t> session_model_ids;
session_model_ids.reserve(std::size_t(model_ids.size()));
for (const QString& model_id : model_ids) {
const uint32_t session_model_id = session.sessionModelIdForModelId(model_id);
if (session_model_id != 0) session_model_ids.push_back(session_model_id);
}
if (!viewport.viewModels(session_model_ids)) {
session.setStatusMessage("Models", "Nothing to view — no loaded geometry");
return;
}
QString label = QString("%1 models").arg(model_ids.size());
if (model_ids.size() == 1) {
const Federation::Model* model = session.federation()->findById(model_ids.front());
label = model ? model->display_name : model_ids.front();
}
session.setStatusMessage("Models", QString("Viewing %1").arg(label));
}
namespace detail {
void loadModels(SessionState& session, const QStringList& paths, const QStringList& model_ids) {