Files
materialcraft/apps/materialcraft-web/src/main.rs
T
chasse20 c469b530b6 Auto: Align normal previews and reduce fallback image buffers
Match preview defaults to the accepted DirectX normal convention. Preserve finite HDR blur values and infer missing dot operands from the connected vector width.

Avoid full-size fallback images in channel shuffle and raster compositing, skip incompatible background resampling, and return early for missing gradients. Complete scoped naming, spacing and comment cleanup and remove the unused workspace bytemuck declaration.

Integrate main's shared format readers and external web library resources.

Validated with affected-package release tests, Clippy, layer and wasm checks, panic_hunt, offscreen snapshots, and comparable resource probes.
2026-11-16 23:03:07 +00:00

52 lines
2.3 KiB
Rust

//! MaterialCraft in the browser.
//!
//! Runs the same [`materialcraft_ui_egui::MaterialCraftApp`] as the desktop app through eframe's web
//! runner (wgpu: WebGPU where available, WebGL2 otherwise). Build with `trunk build --release`
//! from this directory (`packaging/web/package.sh` zips the result).
//!
//! Differences from the desktop app: no control server (browsers can't listen on sockets), and
//! file I/O in the browser is still to come (see ROADMAP.md).
//!
//! URL query flag: `?webgl` forces the WebGL2 backend instead of WebGPU.
#![forbid(unsafe_code)]
#![deny(clippy::unwrap_used, clippy::expect_used, clippy::panic, clippy::unimplemented, clippy::todo, clippy::unreachable)]
#[cfg(target_arch = "wasm32")]
mod web;
#[cfg(target_arch = "wasm32")]
fn main() {
web::start();
}
#[cfg(not(target_arch = "wasm32"))]
fn main() {
eprintln!("materialcraft-web only runs in the browser: build it with `trunk build --release` in apps/materialcraft-web");
}
#[cfg(test)]
mod tests {
/// A WebAssembly module that never downloads runs no Rust, so the page itself replaces the
/// endless "Loading" with a way to retry, without a hand-written script.
#[test]
fn loading_page_offers_a_reload_when_startup_stalls() {
let html = include_str!("../index.html");
let (_, hint) = html.split_once("<p id=\"materialcraft_stalled\">").expect("stalled-startup hint in the loading element");
assert!(hint.contains("failed to") && hint.contains("<a href=\"\">Reload</a>"), "{hint}");
assert!(html.contains("animation: materialcraft-stalled"), "the hint appears after a delay");
assert!(html.contains("id=\"materialcraft_canvas\"") && html.contains("data-cargo-profile=\"wasm-release\""));
assert!(!html.contains("<script"), "trunk injects the generated loader; the page has no script of its own");
}
/// The SBS library's bitmaps would push the wasm past the 25 MiB file cap of Cloudflare Pages,
/// so the page ships them beside it, where `web::LIBRARY_URL` downloads them from.
#[test]
fn loading_page_ships_the_library_resources_beside_the_wasm() {
let html = include_str!("../index.html");
assert!(html.contains(r#"<link data-trunk rel="copy-dir" href="../../assets/sbs/resources" data-target-path="sbs/resources" />"#), "{html}");
}
}