Files
raea/bench/bridge/examples/plain_page.rs
shinyobjectz 57f3ef8db3 Windows: canonicalize goes through dunce and the home folder through user_home (all but five crates)
canonicalize() through std gives \\?\C:\... on Windows: a path Git for Windows can neither read nor lock, Rolldown can't resolve, and which shares no root with the C:\... git and everything else print. It broke a new workspace's git config (fixed in apps/workspace earlier today). Here the calls in the apps (CapCut, check, direction, engines, fingerprint, game, interchange, judge, solid, sound, targets, tools), the bundler, the CLI, the modules loader, the native shim's realpath, the page's motion, io (assets, gen, home, shell), runtime/bundle/lib, js, track and world, the systems (fingerprint-use, footage, index, ml, page-net), the bridge bench's examples and the sdk/ui test tools use dunce::canonicalize, which gives C:\... wherever a path can be said so and is std's own call on the Mac and Linux.

Reads of the home folder took HOME alone, which Windows doesn't set for an app opened from the Start menu or Explorer, so the taste file, the settings file, the inbox, the npm store, the caches (sounds, splats, goo, ingest, speech, Core ML, the portable perceive models), the node shim's os.homedir() and CapCut's drafts were looked for under whatever folder raea ran in. raea_io_home::user_home() reads HOME, then USERPROFILE (Git for Windows' order; an empty one counts as unset), and models(), caches(), logs(), env_path() and offline() use it, as do the places that had their own fallback.

The caches that had their own copy of "this variable, else this folder under home" (splats, goo, ingest, the npm store, Core ML's models) now call raea_io_home::env_path and models(), and raea_io_home::real canonicalizes a path or keeps it as given, so tools/dupes.max comes down to 289 exact and 58 near. tools/skills.sh reads a variable from env_path("RAEA_...", ".raea/...") as it did from env::var, so files.md keeps RAEA_NPM_HOME on ~/.raea/npm (every generated reference is unchanged).

Five crates hold other sessions' uncommitted edits (engine/page/stage, engine/render, runtime/bundle, runtime/export, runtime/live): their few calls, and tools/windows-paths.sh, the check that keeps both at zero, land once those are committed.

Checked: cargo check --all-targets of every crate changed, and of sdk/ui/conformance and sdk/ui/parity. On a Windows 11 PC and on macOS the unit tests of raea-io-home (user_home's order and an empty HOME, now in caches_logs_and_the_home_folder_follow_the_platform), raea-app-check, raea-app-workspace, raea-app-registry and raea-core-facts pass (5, 27, 10, 7, 17).
2026-11-17 10:38:33 -08:00

178 lines
8.5 KiB
Rust

//! A plain Bevy App drawing a composition (docs/sdk.feature S6a, S8b; docs/blitz-bevy.feature B3 H5): DefaultPlugins as
//! any headless Bevy program sets them, then raea in one RaeaPlugin: raea's plugins (RaeaPlugins, Scene3dPlugin), React
//! (ReactPlugin, running the bundle in this App's World), ScenePlugin, which turns React's <Canvas3D> tree into the
//! scene's rows, and raea-page's PagePlugin and WorldPagePlugin, which draw its HTML layer on Blitz over the scene's
//! camera. No Engine and no second App: the App is the user's own. --scene-only leaves the page out (the 3D alone). The
//! frame is saved as a PNG, to compare with raea's own render on the Blitz page (RAEA_PAGE=blitz).
//!
//! --window draws into a window in place of an image (S6a's window target): a winit window made here, never shown and
//! never focused (no dock icon: macOS's Prohibited activation policy), handed to Bevy as a Window entity with its raw
//! handles, as bevy_winit does, so Bevy's renderer makes its surface and RenderTarget::Window draws there. The PNG is
//! the window's screenshot; it should equal the image target's.
//!
//! raea bundle EDIT.tsx --composition-bundle -o EDIT.js
//! cargo run --release -p raea-bridge-bench --example plain_page -- [--scene-only] [--window] EDIT.js OUT.png [WIDTH HEIGHT FRAME FPS]
use bevy::camera::RenderTarget;
use bevy::prelude::*;
use bevy::render::render_resource::TextureFormat;
use bevy::render::view::screenshot::{save_to_disk, Screenshot};
use bevy::window::{ExitCondition, RawHandleWrapper, WindowRef, WindowResolution, WindowWrapper};
use raea_runtime_page::RaeaPlugin;
use std::path::PathBuf;
struct Args {
js: PathBuf,
out: String,
size: (u32, u32),
frame: i64,
fps: f64,
scene_only: bool,
}
fn main() {
let mut args: Vec<String> = std::env::args().skip(1).collect();
let mut flag = |f: &str| args.iter().position(|a| a == f).map(|i| args.remove(i)).is_some();
let (scene_only, window) = (flag("--scene-only"), flag("--window"));
let (Some(js), Some(out)) = (args.first(), args.get(1)) else {
eprintln!("usage: plain_page [--scene-only] [--window] EDIT.js OUT.png [WIDTH HEIGHT FRAME FPS]");
std::process::exit(2);
};
let n = |i: usize, d: u32| args.get(i).and_then(|a| a.parse().ok()).unwrap_or(d);
let a = Args { js: dunce::canonicalize(&PathBuf::from(js)).expect("the bundle"), out: out.clone(), size: (n(2, 640), n(3, 360)), frame: n(4, 30) as i64, fps: n(5, 30) as f64, scene_only };
if window {
std::process::exit(in_window(a));
}
let mut app = app();
let image = app.world_mut().resource_mut::<Assets<Image>>().add(Image::new_target_texture(a.size.0, a.size.1, TextureFormat::Rgba8UnormSrgb, None));
std::process::exit(shoot(app, &a, RenderTarget::Image(image.clone().into()), Screenshot::image(image)));
}
/// DefaultPlugins as a headless Bevy program sets them: no window of Bevy's making (--window hands it one).
fn app() -> App {
let mut app = App::new();
app.add_plugins(
DefaultPlugins
.set(WindowPlugin { primary_window: None, exit_condition: ExitCondition::DontExit, close_when_requested: false, ..default() })
.set(bevy::render::RenderPlugin { synchronous_pipeline_compilation: true, ..default() })
.disable::<bevy::render::pipelined_rendering::PipelinedRenderingPlugin>(),
);
app
}
/// raea added to the App drawing into `target`, then the frame saved by `shot`: 0, or 1 with what went wrong.
fn shoot(mut app: App, a: &Args, target: RenderTarget, shot: Screenshot) -> i32 {
// raea in one add_plugins (docs/sdk.feature S8b): its Engine plugins, React, the scene and (unless scene_only) the page
app.add_plugins(RaeaPlugin { frame: Some(a.frame), fps: a.fps, scene_only: a.scene_only, ..RaeaPlugin::new(a.js.clone(), target, a.size) });
app.finish();
app.cleanup();
// React commits on its own thread: update until the scene's camera is in the World, then a few frames more so
// its pipelines and shadows are made, then one screenshot of the target
let mut seen = None;
for i in 0..600 {
app.update();
// the scene's camera, or with the page, the page drawn over it (or over a camera of its own, the 3D in its
// layered slot)
let cams = if a.scene_only {
app.world_mut().query::<&Camera3d>().iter(app.world()).count()
} else {
app.world_mut().query_filtered::<(), (With<Camera>, With<raea_runtime_twins::overlay::PageOverlay>)>().iter(app.world()).count()
};
if cams > 0 && seen.is_none() {
seen = Some(i);
}
if seen.is_some_and(|s| i >= s + 8) {
break;
}
std::thread::sleep(std::time::Duration::from_millis(5));
}
if seen.is_none() {
let kinds: std::collections::BTreeSet<String> = app.world_mut().query::<&raea_runtime_react::ReactKind>().iter(app.world()).map(|k| k.0.clone()).collect();
let ents = app.world().resource::<raea_runtime_react::ReactEntities>();
eprintln!("plain_page: no 3D camera after 600 updates; React applied {} commits ({} ops, {} nodes), kinds {:?}", ents.commits, ents.ops, ents.by_id.len(), kinds);
return 1;
}
app.world_mut().spawn(shot).observe(save_to_disk(a.out.clone()));
for _ in 0..60 {
app.update();
if std::path::Path::new(&a.out).exists() {
println!("plain_page: {}", a.out);
return 0;
}
}
eprintln!("plain_page: no frame saved");
1
}
/// --window: the frame drawn into a hidden window of winit's, which this program's event loop makes (macOS wants
/// windows made on the main thread, inside the loop).
fn in_window(a: Args) -> i32 {
use winit::application::ApplicationHandler;
use winit::event_loop::{ActiveEventLoop, EventLoop};
struct Run {
a: Args,
code: i32,
}
impl ApplicationHandler for Run {
fn resumed(&mut self, el: &ActiveEventLoop) {
let (w, h) = self.a.size;
let attrs = winit::window::Window::default_attributes()
.with_title("plain_page")
.with_visible(false)
.with_active(false)
.with_inner_size(winit::dpi::PhysicalSize::new(w, h));
self.code = match el.create_window(attrs).map(WindowWrapper::new) {
Ok(win) => match RawHandleWrapper::new(&win) {
Ok(handles) => {
let mut app = app();
// the window at the composition's size in pixels (scale 1: a pixel a pixel, as the image's)
let window = Window { resolution: WindowResolution::new(w, h).with_scale_factor_override(1.0), visible: false, focused: false, ..default() };
let e = app.world_mut().spawn((window, handles)).id();
let code = shoot(app, &self.a, RenderTarget::Window(WindowRef::Entity(e)), Screenshot::window(e));
drop(win);
code
}
Err(e) => {
eprintln!("plain_page: the window's handles: {e}");
1
}
},
Err(e) => {
eprintln!("plain_page: no window: {e}");
1
}
};
el.exit();
}
// the window is never shown, so nothing asks to close it; if the system does, the run ends unsaved
fn window_event(&mut self, el: &ActiveEventLoop, _: winit::window::WindowId, event: winit::event::WindowEvent) {
if matches!(event, winit::event::WindowEvent::CloseRequested) {
eprintln!("plain_page: the window was closed before the frame was saved");
el.exit();
}
}
}
let mut builder = EventLoop::builder();
// no dock icon and no focus taken from whatever is in front (the window is never shown either)
#[cfg(target_os = "macos")]
{
use winit::platform::macos::{ActivationPolicy, EventLoopBuilderExtMacOS};
builder.with_activation_policy(ActivationPolicy::Prohibited).with_activate_ignoring_other_apps(false);
}
let el = match builder.build() {
Ok(el) => el,
Err(e) => {
eprintln!("plain_page: no event loop: {e}");
return 1;
}
};
let mut run = Run { a, code: 1 };
if let Err(e) = el.run_app(&mut run) {
eprintln!("plain_page: the event loop: {e}");
return 1;
}
run.code
}