mirror of
https://github.com/shinyobjectz/raea.git
synced 2026-12-01 06:53:19 -10:00
R3F26 (#130), engine: a camera in a page element draws its own view in the element's box (docs/sdk.feature S3a), not the page's cropped to it
engine/render target.rs tag_row_view gave a camera on the Engine's target a w x h Viewport (the frame above the tag row) on the frames before the page had laid its box out, a render's first draws, and skipped any camera with a Viewport after that, so a box's sub view (SubCameraView: the box's size as the full view, offset by its place) never came. The Viewport it gives (`ours`) is now taken off when a box comes, and given back when the box goes; a camera's own Viewport (a ViewportNode's) is left as it was. Viewports are compared by place and size (bevy_camera's Viewport has no PartialEq). #130's five cases, a 2 x 2 plane at the origin seen from z 5 in a 400 x 400 box: on a 600 x 600 page at fov 90 it is 80 px and centred in the box (was 120 px, centred on the page); at fov 32, 278 px (three: 279; was the whole box); at 1080 x 1920, 80 px in the box (was nothing); at 2160 x 3840 with the box at (800, 1600), 80 px in the box (was the whole box). raea's own camera in a box drew the same way and is fixed with it.
This commit is contained in:
1 parent
ca825d79ae
commit
3e391e2afa
1 file changed
+18
-6
@@ -24,18 +24,30 @@ pub(crate) struct ViewBox(pub(crate) Option<[u32; 4]>);
|
||||
/// A camera drawing to the Engine's target draws a w x h Viewport of it, the frame's own, above the tag row: a view of
|
||||
/// w x (h + 1) drew the 3D 0.14% larger and half a pixel low against a camera on a w x h target, a plain App's
|
||||
/// (docs/blitz-bevy.feature B3 H10), and against the looks' cells. With a view box, its own view is the box's (the
|
||||
/// target a sub view of it, offset by the box's place).
|
||||
pub(crate) fn tag_row_view(t: Res<TagRowTarget>, images: Res<Assets<Image>>, view_box: Option<Res<ViewBox>>, mut q: Query<(&mut Camera, &RenderTarget), Without<raea_sys_frame::TagCamera>>) {
|
||||
/// target a sub view of it, offset by the box's place). The Viewport this gave a camera (`ours`) is taken off when a
|
||||
/// box comes: a camera given it on the frames before the page had laid the box out (a render's first draws) kept it,
|
||||
/// and drew the whole page's view, cropped to the box (#130).
|
||||
pub(crate) fn tag_row_view(t: Res<TagRowTarget>, images: Res<Assets<Image>>, view_box: Option<Res<ViewBox>>, mut ours: Local<bevy::platform::collections::HashSet<Entity>>, mut q: Query<(Entity, &mut Camera, &RenderTarget), Without<raea_sys_frame::TagCamera>>) {
|
||||
let Some(img) = images.get(&t.0) else { return };
|
||||
let s = img.size();
|
||||
let view = match view_box.and_then(|v| v.0) {
|
||||
Some([x, y, w, h]) => bevy::camera::SubCameraView { full_size: UVec2::new(w, h), offset: Vec2::new(-(x as f32), -(y as f32)), size: s },
|
||||
None => bevy::camera::SubCameraView { full_size: UVec2::new(s.x, s.y - 1), offset: Vec2::ZERO, size: s },
|
||||
};
|
||||
for (mut c, rt) in &mut q {
|
||||
if c.viewport.is_some() { if c.sub_camera_view.is_some() { c.sub_camera_view = None; } continue; } // a camera with its own Viewport (a ViewportNode's) sees its viewport's shape, as Bevy sizes it, never the tag row
|
||||
if matches!(rt, RenderTarget::Image(i) if i.handle == t.0) && c.sub_camera_view != Some(view) {
|
||||
if view.offset == Vec2::ZERO { c.viewport = Some(bevy::camera::Viewport { physical_size: view.full_size, ..default() }) } else { c.sub_camera_view = Some(view) } // a w x h Viewport: Bevy's orthographic sub view takes its area from the w x (h + 1) target, 0.14% small (2d/sprite_slice), and a draw in clip space (a PhaseItem, custom_phase_item) maps to its h + 1 rows
|
||||
for (e, mut c, rt) in &mut q {
|
||||
// a camera with its own Viewport (a ViewportNode's) sees its viewport's shape, as Bevy sizes it, never the tag row
|
||||
if c.viewport.is_some() && !ours.contains(&e) { if c.sub_camera_view.is_some() { c.sub_camera_view = None; } continue; }
|
||||
if !matches!(rt, RenderTarget::Image(i) if i.handle == t.0) { continue; }
|
||||
if view.offset == Vec2::ZERO {
|
||||
// a w x h Viewport: Bevy's orthographic sub view takes its area from the w x (h + 1) target, 0.14% small
|
||||
// (2d/sprite_slice), and a draw in clip space (a PhaseItem, custom_phase_item) maps to its h + 1 rows
|
||||
if c.viewport.as_ref().is_none_or(|v| v.physical_position != UVec2::ZERO || v.physical_size != view.full_size) { c.viewport = Some(bevy::camera::Viewport { physical_size: view.full_size, ..default() }); }
|
||||
if c.sub_camera_view.is_some() { c.sub_camera_view = None; }
|
||||
ours.insert(e);
|
||||
} else {
|
||||
if c.viewport.is_some() { c.viewport = None; }
|
||||
if c.sub_camera_view != Some(view) { c.sub_camera_view = Some(view); }
|
||||
ours.remove(&e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user