engine: one scene builder for the window and headless pictures

engine::view::build (Style, Show, Palette) is the viewport's builder,
moved from ui-egui; ui-egui maps theme::Tokens onto a Palette and calls
it. Palette::LIGHT now equals the light theme's tokens. Test: the app's
scene and engine::view::frame's are identical for the same session.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UhhZMBTviDQxZvwnyP89fo
This commit is contained in:
jyvikoandClaude Opus 5.5 authored and Irakli Kourtis committed 2026-10-16 08:29:38 -04:00
1 parent 6136770c1c
commit 78b8fc8d6c
4 files changed
+156 -115

No files matched your search

+22
View File
@@ -2715,6 +2715,28 @@ mod tests {
assert!(png.starts_with(&[0x89, b'P', b'N', b'G']));
}
/// The window and the headless pictures build one scene: the same session gives the same
/// faces, lines and points from the app's viewport and from `engine::view` (the light theme
/// is `Palette::LIGHT`), meshed or not.
#[test]
fn the_window_and_headless_pictures_build_one_scene() {
use fieldcraft_engine::view::{self, Palette};
assert_eq!(theme::Tokens::light().palette(), Palette::LIGHT);
let mut app = ModelApp::new(Session::default());
app.ui.dark = false;
app.run_script(&fieldcraft_engine::sample::script()).unwrap();
draw(&mut app, &egui::Context::default(), 1280.0, 800.0);
let headless =
view::frame(&app.session, &fieldcraft_render::Orientation::of(fieldcraft_render::StandardView::Iso), 320, 200, &Palette::LIGHT, None);
let window = app.scene().1.clone();
assert!(!window.tris.is_empty() && !window.lines.is_empty());
assert_eq!(window.tris, headless.scene.tris);
assert_eq!(window.lines, headless.scene.lines);
assert_eq!(window.points, headless.scene.points);
assert_eq!(window.fills, headless.scene.fills);
assert_eq!(window.background, headless.scene.background);
}
/// `ui.render` draws with the viewport's pipelines on the window's device when there is one
/// (here a device the `FIELDCRAFT_GPU` policy opens, as the app's), says so, and draws on
/// the CPU with the reason when the GPU could not be set up.