mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-12 10:33:20 +00:00
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:
@@ -193,22 +193,12 @@ void ViewportCore::buildViewProj(Eigen::Matrix4f& view_out,
|
||||
}
|
||||
|
||||
bool ViewportCore::computeSceneAabb(float mn[3], float mx[3]) const {
|
||||
bool any = false;
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
mn[i] = std::numeric_limits<float>::infinity();
|
||||
mx[i] = -std::numeric_limits<float>::infinity();
|
||||
}
|
||||
for (const auto& [session_model_id, m] : models_gpu_) {
|
||||
if (m.hidden) continue;
|
||||
for (const auto& inst : m.instances) {
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
mn[i] = std::min(mn[i], inst.world_aabb_min[i]);
|
||||
mx[i] = std::max(mx[i], inst.world_aabb_max[i]);
|
||||
}
|
||||
any = true;
|
||||
}
|
||||
}
|
||||
return any;
|
||||
return InstanceCompose::sceneWorldAabb(models_gpu_, mn, mx);
|
||||
}
|
||||
|
||||
bool ViewportCore::computeModelsAabb(const std::vector<uint32_t>& session_model_ids,
|
||||
float mn[3], float mx[3]) const {
|
||||
return InstanceCompose::modelsWorldAabb(models_gpu_, session_model_ids, mn, mx);
|
||||
}
|
||||
|
||||
float ViewportCore::chunkScreenAreaPx(const ModelGpuData::Chunk& c,
|
||||
@@ -438,6 +428,15 @@ void ViewportCore::viewAll() {
|
||||
cx, cy, cz, camera_distance_, radius);
|
||||
}
|
||||
|
||||
bool ViewportCore::viewModels(const std::vector<uint32_t>& session_model_ids) {
|
||||
float mn[3], mx[3];
|
||||
if (!computeModelsAabb(session_model_ids, mn, mx)) return false;
|
||||
frameAabb(mn, mx, 1.10f); // same padding as viewAll
|
||||
Log::info().noquote().nospace()
|
||||
<< "[wgpu] viewModels framed " << session_model_ids.size() << " model(s)";
|
||||
return true;
|
||||
}
|
||||
|
||||
void ViewportCore::setCamera(float tx, float ty, float tz,
|
||||
float dist, float yaw_deg, float pitch_deg) {
|
||||
camera_target_[0] = tx;
|
||||
|
||||
Reference in New Issue
Block a user