feat(viewport): tile-relative input + overlays in unified model
Route every per-frame interaction through the active model tile's screen rectangle so a tiled VPORTS layout behaves like independent panes while still sharing one shader widget: - pick / draw / snap / box+lasso: cursor mapped to tile-local space; the hover-activates-tile rule on ViewportMove keeps the active tile under the cursor, so the picked camera matches what the user sees. - pan: switched to Camera::pan_screen(dx, dy, viewport_height) so the world-per-pixel rate matches the active tile's height instead of the full canvas. - grid: clipped via Frame::with_clip to the active tile rect; world→screen adds the tile origin so the lines align with the panel. - UCS icon: origin offset by the tile rect so the gizmo sits in the active tile's bottom-left corner. - render-mode picker (+ split buttons) and ViewCube hit-area: positioned via active_model_tile_bounds with leading Spaces, mirroring the floating-viewport pattern. - ViewCube hover: driven by the CursorMoved/ViewportMove handlers into a new Scene::viewcube_hover cell, so the highlight survives the cube hit-area overlay masking events from shader::Program::update. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
parent
6fe25e4b5f
commit
417a708275
7 changed files with 330 additions and 86 deletions
|
|
@ -40,7 +40,9 @@ pub use image_model::ImageModel;
|
|||
pub use mesh_model::MeshLodSet;
|
||||
pub use object::{GripApply, GripDef};
|
||||
pub use pipeline::uniforms::Uniforms;
|
||||
pub use pipeline::viewcube::{hit_test, CubeRegion, VIEWCUBE_DRAW_PX, VIEWCUBE_PAD, VIEWCUBE_PX};
|
||||
pub use pipeline::viewcube::{
|
||||
hit_test, hover_id, CubeRegion, VIEWCUBE_DRAW_PX, VIEWCUBE_PAD, VIEWCUBE_PX,
|
||||
};
|
||||
pub use selection::SelectionState;
|
||||
pub use wire_model::WireModel;
|
||||
|
||||
|
|
@ -548,6 +550,12 @@ pub struct Scene {
|
|||
/// in expand_insert / tessellate_entity. 0 means "not yet set" — culling
|
||||
/// falls back to None.
|
||||
last_world_per_pixel: std::cell::Cell<f32>,
|
||||
/// ViewCube hover region (0..25, face/edge/corner index), driven by the
|
||||
/// `CursorMoved` message that the cube hit-area overlay publishes. Lives
|
||||
/// here so the unified render path can read it for the active viewport
|
||||
/// without depending on the shader widget's internal `Program::State`
|
||||
/// (which can miss events under overlapping overlays).
|
||||
pub viewcube_hover: std::cell::Cell<Option<usize>>,
|
||||
}
|
||||
|
||||
impl Scene {
|
||||
|
|
@ -597,6 +605,7 @@ impl Scene {
|
|||
entity_index_cache: RefCell::new(None),
|
||||
last_render_aspect: std::cell::Cell::new(16.0 / 9.0),
|
||||
last_world_per_pixel: std::cell::Cell::new(0.0),
|
||||
viewcube_hover: std::cell::Cell::new(None),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -4390,6 +4399,27 @@ impl Scene {
|
|||
self.active_model_tile.set(0);
|
||||
}
|
||||
|
||||
/// Screen-pixel rectangle of the active Model tile within a canvas of
|
||||
/// `(vw, vh)`. Full canvas outside the Model layout or for a single
|
||||
/// tile. Used to map cursor coordinates into the active tile so pick /
|
||||
/// pan / ViewCube work per-pane in a tiled layout.
|
||||
pub fn active_model_tile_bounds(&self, vw: f32, vh: f32) -> iced::Rectangle {
|
||||
if self.current_layout != "Model" {
|
||||
return iced::Rectangle { x: 0.0, y: 0.0, width: vw, height: vh };
|
||||
}
|
||||
let tiles = self.model_tiles.borrow();
|
||||
let active = self.active_model_tile.get().min(tiles.len().saturating_sub(1));
|
||||
match tiles.get(active) {
|
||||
Some(t) => iced::Rectangle {
|
||||
x: t.rect.x * vw,
|
||||
y: t.rect.y * vh,
|
||||
width: (t.rect.width * vw).max(1.0),
|
||||
height: (t.rect.height * vh).max(1.0),
|
||||
},
|
||||
None => iced::Rectangle { x: 0.0, y: 0.0, width: vw, height: vh },
|
||||
}
|
||||
}
|
||||
|
||||
/// The viewports to render this frame, one entry per scissor pass.
|
||||
///
|
||||
/// - **Model layout**: a single full-canvas instance driven by the
|
||||
|
|
|
|||
Loading…
Reference in a new issue