diff --git a/.rustfmt.toml b/.rustfmt.toml index c641f101..cbcd4e91 100644 --- a/.rustfmt.toml +++ b/.rustfmt.toml @@ -1,4 +1,5 @@ max_width = 120 +use_small_heuristics = "Max" use_field_init_shorthand = true use_try_shorthand = true edition = "2021" diff --git a/build.bash b/build.bash index 06e441e0..5888eb7f 100755 --- a/build.bash +++ b/build.bash @@ -12,12 +12,12 @@ case $1 in else WASM_BUILD_DIR=debug fi - cargo build --target wasm32-unknown-unknown $BUILD_FLAGS --bin $@ + cargo build --target wasm32-unknown-unknown $BUILD_FLAGS --bin rend3-examples mkdir -p target/generated/ rm -rf target/generated/* - cp -r examples/$1/resources target/generated/ || true + cp -r examples/src/$1/resources target/generated/ || true sed "s/{{example}}/$1/g" > target/generated/index.html < examples/resources/index.html - wasm-bindgen --out-dir target/generated --target web target/wasm32-unknown-unknown/$WASM_BUILD_DIR/$1.wasm + wasm-bindgen --out-dir target/generated --target web target/wasm32-unknown-unknown/$WASM_BUILD_DIR/rend3-examples.wasm ;; serve) shift diff --git a/deny.toml b/deny.toml index b83173f0..f381f5ef 100644 --- a/deny.toml +++ b/deny.toml @@ -15,12 +15,13 @@ wildcards = "allow" skip = [ # gltf / reqwest { name = "base64", version = "0.13.1" }, + # ndk_glue + { name = "env_logger", version = "0.10.2" }, ] skip-tree = [ # winit brings in lots of duplicate deps that we can't fix { name = "winit", version = "0.29.4" }, - # loom is depended on by tracy-client but under a custom cfg that is never on. - { name = "loom", version = "0.5" }, + ] [advisories] diff --git a/examples/Cargo.toml b/examples/Cargo.toml index 73acd448..3c4fbbce 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -24,9 +24,9 @@ egui = "0.26" # Winit integration with egui (turn off the clipboard feature) egui-winit = { version = "0.26", default-features = false, features = ["links", "wayland"] } # logging -env_logger = { version = "0.10", default-features = false, features = ["auto-color", "humantime"] } +env_logger = { version = "0.11", default-features = false, features = ["auto-color", "humantime"] } # Linear algebra library -glam = "0.24" +glam = "0.25" # gltf model loading gltf = "1.4" # Channel diff --git a/examples/resources/index.html b/examples/resources/index.html index c9f866db..3c4c9640 100644 --- a/examples/resources/index.html +++ b/examples/resources/index.html @@ -13,8 +13,9 @@
diff --git a/examples/src/animation/mod.rs b/examples/src/animation/mod.rs index 15dc0226..03878665 100644 --- a/examples/src/animation/mod.rs +++ b/examples/src/animation/mod.rs @@ -53,10 +53,7 @@ impl rend3_framework::App for AnimationExample { // Load a gltf model with animation data // Needs to be stored somewhere, otherwise all the data gets freed. - let path = Path::new(concat!( - env!("CARGO_MANIFEST_DIR"), - "/src/animation/resources/scene.gltf" - )); + let path = Path::new(concat!(env!("CARGO_MANIFEST_DIR"), "/src/animation/resources/scene.gltf")); let gltf_data = std::fs::read(path).unwrap(); let parent_directory = path.parent().unwrap(); let (loaded_scene, loaded_instance) = pollster::block_on(rend3_gltf::load_gltf( @@ -88,10 +85,7 @@ impl rend3_framework::App for AnimationExample { animation_time: 0.0, }; - let path = Path::new(concat!( - env!("CARGO_MANIFEST_DIR"), - "/src/animation/resources/cube_3.gltf" - )); + let path = Path::new(concat!(env!("CARGO_MANIFEST_DIR"), "/src/animation/resources/cube_3.gltf")); let gltf_data = std::fs::read(path).unwrap(); let parent_directory = path.parent().unwrap(); let (loaded_scene, loaded_instance) = pollster::block_on(rend3_gltf::load_gltf( @@ -167,9 +161,7 @@ pub fn main() { let app = AnimationExample::default(); rend3_framework::start( app, - winit::window::WindowBuilder::new() - .with_title("animation-example") - .with_maximized(true), + winit::window::WindowBuilder::new().with_title("animation-example").with_maximized(true), ); } diff --git a/examples/src/cube/mod.rs b/examples/src/cube/mod.rs index 94bf9ff6..22b82b21 100644 --- a/examples/src/cube/mod.rs +++ b/examples/src/cube/mod.rs @@ -125,13 +125,12 @@ impl rend3_framework::App for CubeExample { ]; for (position, color) in lights { - self.point_lights - .push(context.renderer.add_point_light(rend3::types::PointLight { - position, - color, - radius: 2.0, - intensity: 4.0, - })); + self.point_lights.push(context.renderer.add_point_light(rend3::types::PointLight { + position, + color, + radius: 2.0, + intensity: 4.0, + })); } } @@ -184,12 +183,7 @@ impl rend3_framework::App for CubeExample { pub fn main() { let app = CubeExample::default(); - rend3_framework::start( - app, - winit::window::WindowBuilder::new() - .with_title("cube-example") - .with_maximized(true), - ); + rend3_framework::start(app, winit::window::WindowBuilder::new().with_title("cube-example").with_maximized(true)); } #[cfg(test)] diff --git a/examples/src/cube_no_framework/Cargo.toml b/examples/src/cube_no_framework/Cargo.toml deleted file mode 100644 index bdaef2da..00000000 --- a/examples/src/cube_no_framework/Cargo.toml +++ /dev/null @@ -1,36 +0,0 @@ -[package] -name = "rend3-cube-no-framework-example" -license = "MIT OR Apache-2.0 OR Zlib" -version = "0.3.0" -authors = ["The rend3 Developers"] -edition = "2021" -publish = false -rust-version = "1.71" - -[[bin]] -name = "cube-no-framework" -path = "src/main.rs" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -# logging -env_logger = { version = "0.10", default-features = false, features = ["auto-color", "humantime"] } -# Linear algebra library -glam = "0.24" -# Renderer core -rend3 = { version = "^0.3.0", path = "../../rend3" } -# Programmable render list that dictates how the scene renders -rend3-routine = { version = "^0.3.0", path = "../../rend3-routine" } -# Provides `block_on` to wait for futures from sync code -pollster = "0.3" -# windowing -winit = "0.29.4" - -[target.'cfg(target_arch = "wasm32")'.dependencies] -console_log = "1" -console_error_panic_hook = "0.1" -js-sys = "0.3" -web-sys = "0.3.67" -wasm-bindgen = "0.2.83" -wasm-bindgen-futures = "0.4" diff --git a/examples/src/cube_no_framework/mod.rs b/examples/src/cube_no_framework/mod.rs index 03f6d0fc..e764e898 100644 --- a/examples/src/cube_no_framework/mod.rs +++ b/examples/src/cube_no_framework/mod.rs @@ -179,10 +179,7 @@ pub fn main() { event_loop .run(move |event, _event_loop_window_target| match event { // Window was resized, need to resize renderer. - winit::event::Event::WindowEvent { - event: winit::event::WindowEvent::Resized(physical_size), - .. - } => { + winit::event::Event::WindowEvent { event: winit::event::WindowEvent::Resized(physical_size), .. } => { resolution = glam::UVec2::new(physical_size.width, physical_size.height); // Reconfigure the surface for the new size. rend3::configure_surface( @@ -196,10 +193,7 @@ pub fn main() { renderer.set_aspect_ratio(resolution.x as f32 / resolution.y as f32); } // Render! - winit::event::Event::WindowEvent { - event: winit::event::WindowEvent::RedrawRequested, - .. - } => { + winit::event::Event::WindowEvent { event: winit::event::WindowEvent::RedrawRequested, .. } => { // Get a frame let frame = surface.get_current_texture().unwrap(); diff --git a/examples/src/egui/mod.rs b/examples/src/egui/mod.rs index 8fb7cf11..cf3a4634 100644 --- a/examples/src/egui/mod.rs +++ b/examples/src/egui/mod.rs @@ -155,8 +155,7 @@ impl rend3_framework::App for EguiExample { #[allow(clippy::single_match)] match event { winit::event::WindowEvent::Resized(size) => { - data.egui_routine - .resize(size.width, size.height, window.scale_factor() as f32); + data.egui_routine.resize(size.width, size.height, window.scale_factor() as f32); } _ => {} } @@ -192,13 +191,7 @@ impl rend3_framework::App for EguiExample { ); } ui.label("Want to get rusty?"); - if ui - .add(egui::widgets::ImageButton::new(( - self.rust_logo, - egui::Vec2::splat(64.0), - ))) - .clicked() - { + if ui.add(egui::widgets::ImageButton::new((self.rust_logo, egui::Vec2::splat(64.0)))).clicked() { webbrowser::open("https://www.rust-lang.org").expect("failed to open URL"); } }); @@ -207,16 +200,10 @@ impl rend3_framework::App for EguiExample { // End the UI frame. Now let's draw the UI with our Backend, we could also // handle the output here - let egui::FullOutput { - shapes, textures_delta, .. - } = data.context.end_frame(); + let egui::FullOutput { shapes, textures_delta, .. } = data.context.end_frame(); let paint_jobs = data.context.tessellate(shapes, scale_factor); - let input = rend3_egui::Input { - clipped_meshes: &paint_jobs, - textures_delta, - context: data.context.clone(), - }; + let input = rend3_egui::Input { clipped_meshes: &paint_jobs, textures_delta, context: data.context.clone() }; // Swap the instruction buffers so that our frame's changes can be processed. context.renderer.swap_instruction_buffers(); @@ -269,12 +256,7 @@ impl rend3_framework::App for EguiExample { pub fn main() { let app = EguiExample::default(); - rend3_framework::start( - app, - winit::window::WindowBuilder::new() - .with_title("egui") - .with_maximized(true), - ) + rend3_framework::start(app, winit::window::WindowBuilder::new().with_title("egui").with_maximized(true)) } fn vertex(pos: [f32; 3]) -> glam::Vec3 { diff --git a/examples/src/lib.rs b/examples/src/lib.rs index 0b3ab4d0..cba9e27c 100644 --- a/examples/src/lib.rs +++ b/examples/src/lib.rs @@ -1,3 +1,8 @@ +#![allow(clippy::arc_with_non_send_sync)] + +#[cfg(target_arch = "wasm32")] +use wasm_bindgen::prelude::*; + mod animation; mod cube; mod cube_no_framework; @@ -7,6 +12,9 @@ mod skinning; mod static_gltf; mod textured_quad; +#[cfg(target_arch = "wasm32")] +use log::info as println; + #[cfg(test)] mod tests; @@ -16,62 +24,41 @@ struct ExampleDesc { } const EXAMPLES: &[ExampleDesc] = &[ - ExampleDesc { - name: "animation", - run: animation::main, - }, - ExampleDesc { - name: "cube", - run: cube::main, - }, - ExampleDesc { - name: "cube-no-framework", - run: cube_no_framework::main, - }, - ExampleDesc { - name: "egui", - run: egui::main, - }, - ExampleDesc { - name: "scene-viewer", - run: scene_viewer::main, - }, - ExampleDesc { - name: "skinning", - run: skinning::main, - }, - ExampleDesc { - name: "static-gltf", - run: static_gltf::main, - }, - ExampleDesc { - name: "textured-quad", - run: textured_quad::main, - }, + ExampleDesc { name: "animation", run: animation::main }, + ExampleDesc { name: "cube", run: cube::main }, + ExampleDesc { name: "cube-no-framework", run: cube_no_framework::main }, + ExampleDesc { name: "egui", run: egui::main }, + ExampleDesc { name: "scene_viewer", run: scene_viewer::main }, + ExampleDesc { name: "skinning", run: skinning::main }, + ExampleDesc { name: "static_gltf", run: static_gltf::main }, + ExampleDesc { name: "textured_quad", run: textured_quad::main }, ]; fn print_examples() { - println!("Usage: cargo run