mirror of
https://github.com/shinyobjectz/raea.git
synced 2026-12-01 06:53:19 -10:00
R3F26 (#130): the view a camera on the Engine's target draws moves to a crate of its own, raea-sys-viewbox (TagRowTarget, ViewBox, tag_row_view), with two tests: a box laid out after the first frames takes the camera's view and gives the frame's Viewport back when it goes, and a camera's own Viewport is left as it is. raea-render goes from 2,009 lines to 1,972, back under rask's 2,000
This commit is contained in:
1 parent
190ced1d1f
commit
b2f2f2af3d
8 files changed
+123
-45
No files matched your search
Generated
+9
@@ -14854,6 +14854,7 @@ dependencies = [
|
||||
"raea-sys-sprite",
|
||||
"raea-sys-text3d",
|
||||
"raea-sys-three-shader",
|
||||
"raea-sys-viewbox",
|
||||
"raea-sys-volume",
|
||||
"raea-sys-wear",
|
||||
"serde_json",
|
||||
@@ -16245,6 +16246,14 @@ dependencies = [
|
||||
"serde_json",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "raea-sys-viewbox"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"bevy",
|
||||
"raea-sys-frame",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "raea-sys-vision"
|
||||
version = "0.1.0"
|
||||
|
||||
@@ -119,6 +119,7 @@ members = [
|
||||
"systems/screen",
|
||||
"systems/matchmove",
|
||||
"systems/grid",
|
||||
"systems/viewbox",
|
||||
"systems/rendermap",
|
||||
"systems/meshseq",
|
||||
"systems/environment",
|
||||
|
||||
+4
-4
@@ -587,12 +587,12 @@ Feature: React Three Fiber both ways: an R3F scene drawn by raea, a raea composi
|
||||
And #130's five cases each draw the plane at its expected size and place
|
||||
Status (11-15): done. The cause was the engine's, not <R3F>'s: a camera in a page element (docs/sdk.feature S3a)
|
||||
is drawn as the element's box's own view (a SubCameraView: the box's size as the full view, offset by its
|
||||
place), but engine/render target.rs gave every camera on the Engine's target a w x h Viewport on the frames
|
||||
place), but raea-render's tag_row_view gave every camera on the Engine's target a w x h Viewport on the frames
|
||||
before the page had laid the box out, and skipped a camera with a Viewport after that, so the box's view never
|
||||
came and the page's was cropped to the box (raea's own camera in a box too). The Viewport it gives is now taken
|
||||
off when a box comes (unit tests in target.rs). #130's cases: 600 x 600 at fov 90, 80 px centred in the box
|
||||
(was 120 px centred on the page); fov 32, 278 px (three: 279); 1080 x 1920, 80 px (was nothing); 2160 x 3840
|
||||
with the box at (800, 1600), 80 px in the box. <R3F width height> (the box's size)
|
||||
off when a box comes (the new crate raea-sys-viewbox, with its tests). #130's cases: 600 x 600 at fov 90, 80 px
|
||||
centred in the box (was 120 px centred on the page); fov 32, 278 px (three: 279); 1080 x 1920, 80 px (was
|
||||
nothing); 2160 x 3840 with the box at (800, 1600), 80 px in the box. <R3F width height> (the box's size)
|
||||
makes R3F's own size, its camera's aspect and an orthographic camera's frame the box's: an orthographic plane
|
||||
R3F frames at zoom 40 is 80 px in a 400 x 300 box with them, 40 px without (R3F sizes it from the frame)
|
||||
|
||||
|
||||
@@ -33,6 +33,8 @@ raea-runtime-plugins = { path = "../../runtime/plugins" }
|
||||
raea-sys-screen = { path = "../../systems/screen" }
|
||||
raea-sys-matchmove = { path = "../../systems/matchmove" }
|
||||
raea-sys-grid = { path = "../../systems/grid" }
|
||||
# the view a camera on the Engine's target draws: the frame above its tag row, or a page's box (#130)
|
||||
raea-sys-viewbox = { path = "../../systems/viewbox" }
|
||||
raea-sys-rendermap = { path = "../../systems/rendermap" }
|
||||
raea-sys-meshseq = { path = "../../systems/meshseq" }
|
||||
raea-sys-environment = { path = "../../systems/environment" }
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
//! The target's side of a frame: the view box a tagged row draws in, supersampling (its downsample: raea-runtime-gpuframe), the render
|
||||
//! world's diagnostics forwarded.
|
||||
//! The target's side of a frame: the view box a tagged row draws in (raea-sys-viewbox), supersampling (its downsample:
|
||||
//! raea-runtime-gpuframe), the render world's diagnostics forwarded.
|
||||
|
||||
use super::*;
|
||||
pub(crate) use raea_sys_viewbox::{TagRowTarget, ViewBox, tag_row_view};
|
||||
|
||||
/// Bevy's render diagnostics (each pass's elapsed time, `render/...`), into the run's trace once a second.
|
||||
#[cfg(feature = "native")]
|
||||
@@ -13,45 +14,6 @@ pub(crate) fn forward_render_diagnostics(store: Res<bevy::diagnostic::Diagnostic
|
||||
if !passes.is_empty() { raea_io_trace::event("bevy_passes", serde_json::json!({"ms": passes})); }
|
||||
}
|
||||
|
||||
/// The Engine's target: the frame, and its tag row under it.
|
||||
#[derive(Resource)]
|
||||
pub(crate) struct TagRowTarget(pub(crate) Handle<Image>);
|
||||
|
||||
/// Engine::set_view_box's box, in target px.
|
||||
#[derive(Resource, Default)]
|
||||
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). 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 (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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// RAEA_SS (2, 3 or 4; 1 without it): how many times the frame's size it's drawn at. Not live, and only with the
|
||||
/// lossless readback, which the downsampling reads.
|
||||
pub(crate) fn supersampling(live: bool) -> u32 {
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
[package]
|
||||
name = "raea-sys-viewbox"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
license = "FSL-1.1-ALv2"
|
||||
publish = false
|
||||
description = "The view a camera on the Engine's target draws: the frame above its tag row, or the box a page lays out for it (Engine::set_view_box, #130)"
|
||||
|
||||
[dependencies]
|
||||
raea-sys-frame = { path = "../frame" }
|
||||
bevy = { version = "=0.20.0", default-features = false, features = ["std", "default_app", "3d_bevy_render"] }
|
||||
@@ -0,0 +1,92 @@
|
||||
//! The view a camera on the Engine's target draws: the frame above its tag row, or the box a page lays out for it
|
||||
//! (Engine::set_view_box). raea-render's Engine gives the target and the box.
|
||||
|
||||
use bevy::camera::RenderTarget;
|
||||
use bevy::prelude::*;
|
||||
|
||||
/// The Engine's target: the frame, and its tag row under it.
|
||||
#[derive(Resource)]
|
||||
pub struct TagRowTarget(pub Handle<Image>);
|
||||
|
||||
/// Engine::set_view_box's box, in target px.
|
||||
#[derive(Resource, Default)]
|
||||
pub struct ViewBox(pub 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). 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 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 (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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use bevy::render::render_resource::{Extent3d, TextureDimension, TextureFormat};
|
||||
|
||||
/// a 600 x 600 frame's target (its tag row under it), a camera on it, and its own view box
|
||||
fn app() -> (App, Entity, Handle<Image>) {
|
||||
let mut app = App::new();
|
||||
app.init_resource::<Assets<Image>>();
|
||||
let img = Image::new_fill(Extent3d { width: 600, height: 601, depth_or_array_layers: 1 }, TextureDimension::D2, &[0, 0, 0, 0], TextureFormat::Rgba8Unorm, bevy::asset::RenderAssetUsages::default());
|
||||
let h = app.world_mut().resource_mut::<Assets<Image>>().add(img);
|
||||
app.insert_resource(TagRowTarget(h.clone())).init_resource::<ViewBox>().add_systems(Update, tag_row_view);
|
||||
let cam = app.world_mut().spawn((Camera::default(), RenderTarget::Image(h.clone().into()))).id();
|
||||
(app, cam, h)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_box_laid_out_after_the_first_frames_takes_the_cameras_view_and_gives_it_back() {
|
||||
let (mut app, cam, _) = app();
|
||||
app.update();
|
||||
let c = app.world().get::<Camera>(cam).unwrap();
|
||||
assert_eq!(c.viewport.as_ref().map(|v| v.physical_size), Some(UVec2::new(600, 600)), "the frame above the tag row");
|
||||
// the page lays the box out (#130): the box's view, offset by its place, and no Viewport left from before
|
||||
app.world_mut().resource_mut::<ViewBox>().0 = Some([100, 100, 400, 400]);
|
||||
app.update();
|
||||
let c = app.world().get::<Camera>(cam).unwrap();
|
||||
assert!(c.viewport.is_none());
|
||||
let v = c.sub_camera_view.expect("the box's sub view");
|
||||
assert_eq!((v.full_size, v.offset, v.size), (UVec2::new(400, 400), Vec2::new(-100.0, -100.0), UVec2::new(600, 601)));
|
||||
// the box goes: the frame's Viewport again
|
||||
app.world_mut().resource_mut::<ViewBox>().0 = None;
|
||||
app.update();
|
||||
let c = app.world().get::<Camera>(cam).unwrap();
|
||||
assert!(c.sub_camera_view.is_none() && c.viewport.as_ref().is_some_and(|v| v.physical_size == UVec2::new(600, 600)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_cameras_own_viewport_is_left_as_it_is() {
|
||||
let (mut app, _, h) = app();
|
||||
let own = bevy::camera::Viewport { physical_position: UVec2::new(10, 20), physical_size: UVec2::new(50, 60), ..default() };
|
||||
let cam = app.world_mut().spawn((Camera { viewport: Some(own), ..default() }, RenderTarget::Image(h.into()))).id();
|
||||
app.world_mut().resource_mut::<ViewBox>().0 = Some([100, 100, 400, 400]);
|
||||
app.update();
|
||||
let c = app.world().get::<Camera>(cam).unwrap();
|
||||
assert!(c.sub_camera_view.is_none() && c.viewport.as_ref().is_some_and(|v| v.physical_position == UVec2::new(10, 20) && v.physical_size == UVec2::new(50, 60)));
|
||||
}
|
||||
}
|
||||
@@ -113,6 +113,7 @@ raea-runtime-scene3d = "runtime"
|
||||
raea-sys-screen = "systems"
|
||||
raea-sys-matchmove = "systems"
|
||||
raea-sys-grid = "systems"
|
||||
raea-sys-viewbox = "systems"
|
||||
raea-sys-rendermap = "systems"
|
||||
raea-sys-meshseq = "systems"
|
||||
raea-sys-environment = "systems"
|
||||
|
||||
Reference in new issue
Block a user