diff --git a/.gitignore b/.gitignore index 129c595c..a0874be4 100644 --- a/.gitignore +++ b/.gitignore @@ -9,8 +9,8 @@ cargo-timing* Cargo.lock /profile.json -/examples/scene-viewer/resources/default-scene/ -/examples/scene-viewer/resources/rend3-default-scene.tar +/examples/src/scene_viewer/resources/default-scene/ +/examples/src/scene_viewer/resources/rend3-default-scene.tar *-diff.png *-success.png diff --git a/Cargo.toml b/Cargo.toml index d82f5965..edfa56b7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,14 +1,7 @@ [workspace] resolver = "2" members = [ - "examples/animation", - "examples/cube", - "examples/cube-no-framework", - "examples/egui", - "examples/scene-viewer", - "examples/skinning", - "examples/static-gltf", - "examples/textured-quad", + "examples/", "rend3", "rend3-anim", "rend3-egui", diff --git a/examples/Cargo.toml b/examples/Cargo.toml new file mode 100644 index 00000000..f5c8959b --- /dev/null +++ b/examples/Cargo.toml @@ -0,0 +1,86 @@ +[package] +name = "rend3-examples" +license = "MIT OR Apache-2.0 OR Zlib" +version = "0.3.0" +authors = ["The rend3 Developers"] +edition = "2021" +publish = false +rust-version = "1.71" + +[lib] +crate-type = ["lib", "cdylib"] + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +# error handling +anyhow = "1" +# The egui immediate mode gui library +egui = {git = "https://github.com/emilk/egui.git", branch="master"} +# Winit integration with egui (turn off the clipboard feature) +egui-winit = { git = "https://github.com/emilk/egui.git", branch="master", default-features = false, features = ["links", "wayland"] } +# logging +env_logger = { version = "0.10", default-features = false, features = ["auto-color", "humantime"] } +# Linear algebra library +glam = "0.24" +# gltf model loading +gltf = "1.4" +# 0.7 is a completely unrelated library +histogram = "0.6" +# Logging infrastructure +log = "0.4" +# Inline string +indoc = "1" +# Importing images +image = { version = "0.24", default-features = false, features = [ + "png", + "jpeg", + "tiff", +] } +# profiling +profiling = "1" +# argument parsing +pico-args = "0.5" +# block on async functions +pollster = "0.3" +# Renderer core +rend3 = { version = "^0.3.0", path = "../rend3" } +# Play animations on imported gltf models +rend3-anim = { version = "^0.3.0", path = "../rend3-anim" } +# Egui integration with rend3 +rend3-egui = { version = "^0.3.0", path = "../rend3-egui" } +# Programmable render list that dictates how the scene renders +rend3-routine = { version = "^0.3.0", path = "../rend3-routine" } +# Framework that deals with the event loop, setting up the renderer, and platform differences. +rend3-framework = { version = "^0.3.0", path = "../rend3-framework" } +# Import gltf models +rend3-gltf = { version = "^0.3.0", path = "../rend3-gltf" } +# Opening URL's +webbrowser = "0.8.2" +# Instant but portable to the web +web-time = "0.2" +# windowing +winit = "0.29.4" +# Integration with wgpu +wgpu = "0.18" +# Profiling with wgpu +wgpu-profiler = "0.15" + +[target.'cfg(target_arch = "wasm32")'.dependencies] +console_log = "1" +console_error_panic_hook = "0.1" +js-sys = "0.3" +web-sys = "0.3" +wasm-bindgen = "0.2.83" +wasm-bindgen-futures = "0.4" + +[target.'cfg(target_os = "android")'.dependencies] +ndk-glue = { version = "0.7", features = ["logger"] } + +[package.metadata.android] +build_targets = ["aarch64-linux-android"] + +[package.metadata.android.sdk] +min_sdk_version = 28 +target_sdk_version = 28 +compile_sdk_version = 28 diff --git a/examples/README.md b/examples/README.md index 12d5b4f7..aa8e859b 100644 --- a/examples/README.md +++ b/examples/README.md @@ -1,6 +1,6 @@ # rend3 Examples -The examples are separate crates, so to run an example run `cargo run --bin `. +The examples are separate crates, so to run an example run `cargo run `. If you want to demo running rend3, [`scene-viewer`](scene-viewer) is what you should use. It is a full fledged gltf viewer. diff --git a/examples/animation/Cargo.toml b/examples/animation/Cargo.toml deleted file mode 100644 index a75061cd..00000000 --- a/examples/animation/Cargo.toml +++ /dev/null @@ -1,57 +0,0 @@ -[package] -name = "rend3-animation-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" - -[lib] -crate-type = ["lib", "cdylib"] - -[[bin]] -name = "animation" -path = "src/main.rs" - -[dependencies] -# logging -env_logger = { version = "0.10", default-features = false, features = ["auto-color", "humantime"] } -# Linear algebra library -glam = "0.24" -# block on async functions -pollster = "0.3" -# 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" } -# Framework that deals with the event loop, setting up the renderer, and platform differences. -rend3-framework = { version = "^0.3.0", path = "../../rend3-framework" } -# Play animations on imported gltf models -rend3-anim = { version = "^0.3.0", path = "../../rend3-anim" } -# Import gltf models -rend3-gltf = { version = "^0.3.0", path = "../../rend3-gltf" } -# std::time::Instant that works on wasm -web-time = "0.2" -# windowing -winit = "0.29.4" -image = { version = "0.24", default-features = false, features = ["jpeg"] } - -[target.'cfg(target_arch = "wasm32")'.dependencies] -console_log = "1" -console_error_panic_hook = "0.1" -js-sys = "0.3" -web-sys = "0.3" -wasm-bindgen = "0.2.83" -wasm-bindgen-futures = "0.4" - -[target.'cfg(target_os = "android")'.dependencies] -ndk-glue = { version = "0.7", features = ["logger"] } - -[package.metadata.android] -build_targets = ["aarch64-linux-android"] - -[package.metadata.android.sdk] -min_sdk_version = 28 -target_sdk_version = 28 -compile_sdk_version = 28 diff --git a/examples/animation/src/main.rs b/examples/animation/src/main.rs deleted file mode 100644 index 81fe1ff7..00000000 --- a/examples/animation/src/main.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - rend3_animation_example::main(); -} diff --git a/examples/cube/Cargo.toml b/examples/cube/Cargo.toml deleted file mode 100644 index 29d59db0..00000000 --- a/examples/cube/Cargo.toml +++ /dev/null @@ -1,50 +0,0 @@ -[package] -name = "rend3-cube-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" - -[lib] -crate-type = ["lib", "cdylib"] - -[[bin]] -name = "cube" -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" } -# Framework that deals with the event loop, setting up the renderer, and platform differences. -rend3-framework = { version = "^0.3.0", path = "../../rend3-framework" } -# 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" -wasm-bindgen = "0.2.83" -wasm-bindgen-futures = "0.4" - -[target.'cfg(target_os = "android")'.dependencies] -ndk-glue = { version = "0.7", features = ["logger"] } - -[package.metadata.android] -build_targets = ["aarch64-linux-android"] - -[package.metadata.android.sdk] -min_sdk_version = 28 -target_sdk_version = 28 -compile_sdk_version = 28 diff --git a/examples/cube/src/main.rs b/examples/cube/src/main.rs deleted file mode 100644 index acc92958..00000000 --- a/examples/cube/src/main.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - rend3_cube_example::main(); -} diff --git a/examples/egui/Cargo.toml b/examples/egui/Cargo.toml deleted file mode 100644 index 5968016d..00000000 --- a/examples/egui/Cargo.toml +++ /dev/null @@ -1,42 +0,0 @@ -[package] -name = "rend3-egui-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 = "egui" -path = "src/main.rs" - -[dependencies] -# The egui immediate mode gui library -egui = {git = "https://github.com/emilk/egui.git", branch="master"} -# Winit integration with egui (turn off the clipboard feature) -egui-winit = { git = "https://github.com/emilk/egui.git", branch="master", default-features = false, features = ["links", "wayland"] } -# logging -env_logger = { version = "0.10", default-features = false, features = ["auto-color", "humantime"] } -# Linear algebra library -glam = "0.24" -# Importing png's -image = { version = "0.24.3", default-features = false, features = ["png"] } -# Renderer core -rend3 = { version = "^0.3.0",path = "../../rend3" } -# Egui renderer integration -rend3-egui = { version = "^0.3.0",path = "../../rend3-egui" } -# Framework that deals with the event loop, setting up the renderer, and platform differences. -rend3-framework = { version = "^0.3.0", path = "../../rend3-framework" } -# Programmable render list that dictates how the scene renders -rend3-routine = { version = "^0.3.0",path = "../../rend3-routine" } -# Windowing -winit = "0.29.4" -# Opening URL's -webbrowser = "0.8.2" -# Creating textures -wgpu = "0.18" - -[target.'cfg(not(target_arch = "wasm32"))'.dependencies] -# Winit integration with egui -egui-winit = { git = "https://github.com/emilk/egui.git", branch="master", default-features = false, features = ["clipboard", "links", "wayland"] } diff --git a/examples/scene-viewer/Cargo.toml b/examples/scene-viewer/Cargo.toml deleted file mode 100644 index 9ed22f14..00000000 --- a/examples/scene-viewer/Cargo.toml +++ /dev/null @@ -1,85 +0,0 @@ -[package] -name = "scene-viewer" -version = "0.3.0" -authors = ["The rend3 Developers"] -edition = "2021" -description = "A gltf scene viewer based on the rend3 3D rendering engine." -readme = "README.md" -repository = "https://github.com/BVE-Reborn/rend3" -license = "MIT OR Apache-2.0 OR Zlib" -keywords = ["3d", "graphics", "rend3", "renderer", "wgpu"] -categories = [ - "game-development", - "graphics", - "rendering", - "rendering::engine", - "wasm", -] -rust-version = "1.71" -exclude = [ - "bistro.jpg", - "emerald-square.jpg", - "scifi-base.jpg", - "screenshot.jpg", - "resources/default-scene", - "resources/rend3-default-scene.tar", -] - -[lib] -name = "rend3_scene_viewer_example" -crate-type = ["lib", "cdylib"] - - -[features] -tracy = ["profiling/profile-with-tracy", "tracy-client"] - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -anyhow = "1" -cfg-if = "1" -glam = "0.24" -# 0.7 is a completely unrelated library -histogram = "0.6" -image = { version = "0.24", default-features = false, features = [ - "png", - "jpeg", - "tiff", -] } -indoc = "2" -log = "0.4" -pico-args = "0.5" -pollster = "0.3" -profiling = { version = "1", default-features = false } -rend3 = { version = "^0.3.0", path = "../../rend3" } -rend3-framework = { version = "^0.3.0", path = "../../rend3-framework" } -rend3-gltf = { version = "^0.3.0", default-features = false, path = "../../rend3-gltf", features = [ - "ddsfile", - "ktx2", -] } -rend3-routine = { version = "^0.3.0", path = "../../rend3-routine" } -rustc-hash = "1" -smallvec = "1" -tracy-client = { version = "0.16", optional = true } -web-time = "0.2" -wgpu = "0.18.0" -wgpu-profiler = "0.15.0" -winit = "0.29.4" - -[target.'cfg(target_arch = "wasm32")'.dependencies] -wasm-bindgen-futures = "0.4" - -[target.'cfg(target_os = "android")'.dependencies] -ndk-glue = { version = "0.7", features = ["logger"] } - -[package.metadata.android] -build_targets = ["aarch64-linux-android"] -assets = "resources" - -[package.metadata.android.sdk] -min_sdk_version = 28 -target_sdk_version = 28 -compile_sdk_version = 28 - -[package.metadata.android.application.activity] -orientation = "landscape" diff --git a/examples/scene-viewer/src/main.rs b/examples/scene-viewer/src/main.rs deleted file mode 100644 index fc85b512..00000000 --- a/examples/scene-viewer/src/main.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - rend3_scene_viewer_example::main() -} diff --git a/examples/scene-viewer/src/platform.rs b/examples/scene-viewer/src/platform.rs deleted file mode 100644 index 1685e2e4..00000000 --- a/examples/scene-viewer/src/platform.rs +++ /dev/null @@ -1,57 +0,0 @@ -#![allow(non_snake_case, unused)] -cfg_if::cfg_if!( - if #[cfg(target_os = "macos")] { - // https://stackoverflow.com/a/16125341 reference - pub mod Scancodes { - pub const W: u32 = 0x0D; - pub const A: u32 = 0x00; - pub const S: u32 = 0x01; - pub const D: u32 = 0x02; - pub const Q: u32 = 0x0C; - pub const Z: u32 = 0x06; - pub const P: u32 = 0x23; - pub const SEMICOLON: u32 = 0x29; - pub const QUOTE: u32 = 0x27; - pub const COMMA: u32 = 0x2B; - pub const PERIOD: u32 = 0x2F; - pub const SHIFT: u32 = 0x38; - pub const ESCAPE: u32 = 0x35; - pub const LALT: u32 = 0x3A; // Actually Left Option - } - } else if #[cfg(target_arch = "wasm32")] { - pub mod Scancodes { - use winit::keyboard::KeyCode; - pub const W: u32 = KeyCode::KeyW as u32; - pub const A: u32 = KeyCode::KeyA as u32; - pub const S: u32 = KeyCode::KeyS as u32; - pub const D: u32 = KeyCode::KeyD as u32; - pub const Q: u32 = KeyCode::KeyQ as u32; - pub const Z: u32 = KeyCode::KeyZ as u32; - pub const P: u32 = KeyCode::KeyP as u32; - pub const SEMICOLON: u32 = KeyCode::Semicolon as u32; - pub const QUOTE: u32 = KeyCode::Quote as u32; - pub const COMMA: u32 = KeyCode::Comma as u32; - pub const PERIOD: u32 = KeyCode::Period as u32; - pub const SHIFT: u32 = KeyCode::ShiftLeft as u32; - pub const ESCAPE: u32 = KeyCode::Escape as u32; - pub const LALT: u32 = KeyCode::AltLeft as u32; - } - } else { - pub mod Scancodes { - pub const W: u32 = 0x11; - pub const A: u32 = 0x1E; - pub const S: u32 = 0x1F; - pub const D: u32 = 0x20; - pub const Q: u32 = 0x10; - pub const Z: u32 = 0x2C; - pub const P: u32 = 0x19; - pub const SEMICOLON: u32 = 0x27; - pub const QUOTE: u32 = 0x28; - pub const COMMA: u32 = 0x33; - pub const PERIOD: u32 = 0x34; - pub const SHIFT: u32 = 0x2A; - pub const ESCAPE: u32 = 0x01; - pub const LALT: u32 = 0x38; - } - } -); diff --git a/examples/skinning/Cargo.toml b/examples/skinning/Cargo.toml deleted file mode 100644 index 40c1ad78..00000000 --- a/examples/skinning/Cargo.toml +++ /dev/null @@ -1,54 +0,0 @@ -[package] -name = "rend3-skinning-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" - -[lib] -crate-type = ["lib", "cdylib"] - -[[bin]] -name = "skinning" -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" -# block on async functions -pollster = "0.3" -# 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" } -# Framework that deals with the event loop, setting up the renderer, and platform differences. -rend3-framework = { version = "^0.3.0", path = "../../rend3-framework" } -# Import gltf models -rend3-gltf = { version = "^0.3.0", path = "../../rend3-gltf" } -# 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" -wasm-bindgen = "0.2.83" -wasm-bindgen-futures = "0.4" - -[target.'cfg(target_os = "android")'.dependencies] -ndk-glue = { version = "0.7", features = ["logger"] } - -[package.metadata.android] -build_targets = ["aarch64-linux-android"] - -[package.metadata.android.sdk] -min_sdk_version = 28 -target_sdk_version = 28 -compile_sdk_version = 28 diff --git a/examples/skinning/src/main.rs b/examples/skinning/src/main.rs deleted file mode 100644 index e9a9f454..00000000 --- a/examples/skinning/src/main.rs +++ /dev/null @@ -1,3 +0,0 @@ -fn main() { - rend3_skinning_example::main(); -} diff --git a/examples/animation/README.md b/examples/src/animation/README.md similarity index 100% rename from examples/animation/README.md rename to examples/src/animation/README.md diff --git a/examples/animation/src/lib.rs b/examples/src/animation/mod.rs similarity index 96% rename from examples/animation/src/lib.rs rename to examples/src/animation/mod.rs index 24131389..2851ba4d 100644 --- a/examples/animation/src/lib.rs +++ b/examples/src/animation/mod.rs @@ -7,7 +7,7 @@ const SAMPLE_COUNT: rend3::types::SampleCount = rend3::types::SampleCount::One; /// The application data, can only be obtained at `setup` time, so it's under an /// Option in the main struct. -struct AnimatedObject { +pub struct AnimatedObject { loaded_scene: rend3_gltf::LoadedGltfScene, loaded_instance: rend3_gltf::GltfSceneInstance, animation_data: rend3_anim::AnimationData, @@ -55,7 +55,10 @@ 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"), "/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,7 +91,10 @@ impl rend3_framework::App for AnimationExample { last_frame_time: web_time::Instant::now(), }; - let path = Path::new(concat!(env!("CARGO_MANIFEST_DIR"), "/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( @@ -184,7 +190,6 @@ impl rend3_framework::App for AnimationExample { } } -#[cfg_attr(target_os = "android", ndk_glue::main(backtrace = "on", logger(level = "debug")))] pub fn main() { let app = AnimationExample::default(); rend3_framework::start( diff --git a/examples/animation/resources/LICENSE b/examples/src/animation/resources/LICENSE similarity index 100% rename from examples/animation/resources/LICENSE rename to examples/src/animation/resources/LICENSE diff --git a/examples/animation/resources/cube_3.gltf b/examples/src/animation/resources/cube_3.gltf similarity index 100% rename from examples/animation/resources/cube_3.gltf rename to examples/src/animation/resources/cube_3.gltf diff --git a/examples/animation/resources/scene.bin b/examples/src/animation/resources/scene.bin similarity index 100% rename from examples/animation/resources/scene.bin rename to examples/src/animation/resources/scene.bin diff --git a/examples/animation/resources/scene.gltf b/examples/src/animation/resources/scene.gltf similarity index 100% rename from examples/animation/resources/scene.gltf rename to examples/src/animation/resources/scene.gltf diff --git a/examples/animation/resources/textures/rabbit_baseColor.jpeg b/examples/src/animation/resources/textures/rabbit_baseColor.jpeg similarity index 100% rename from examples/animation/resources/textures/rabbit_baseColor.jpeg rename to examples/src/animation/resources/textures/rabbit_baseColor.jpeg diff --git a/examples/cube/README.md b/examples/src/cube/README.md similarity index 100% rename from examples/cube/README.md rename to examples/src/cube/README.md diff --git a/examples/cube/src/lib.rs b/examples/src/cube/mod.rs similarity index 99% rename from examples/cube/src/lib.rs rename to examples/src/cube/mod.rs index fcba6468..ac89807f 100644 --- a/examples/cube/src/lib.rs +++ b/examples/src/cube/mod.rs @@ -56,7 +56,7 @@ fn create_mesh() -> rend3::types::Mesh { const SAMPLE_COUNT: rend3::types::SampleCount = rend3::types::SampleCount::One; #[derive(Default)] -struct CubeExample { +pub struct CubeExample { object_handle: Option, directional_light_handle: Option, point_lights: Vec, diff --git a/examples/cube/screenshot.png b/examples/src/cube/screenshot.png similarity index 100% rename from examples/cube/screenshot.png rename to examples/src/cube/screenshot.png diff --git a/examples/cube-no-framework/Cargo.toml b/examples/src/cube_no_framework/Cargo.toml similarity index 100% rename from examples/cube-no-framework/Cargo.toml rename to examples/src/cube_no_framework/Cargo.toml diff --git a/examples/cube-no-framework/README.md b/examples/src/cube_no_framework/README.md similarity index 100% rename from examples/cube-no-framework/README.md rename to examples/src/cube_no_framework/README.md diff --git a/examples/cube-no-framework/src/main.rs b/examples/src/cube_no_framework/mod.rs similarity index 99% rename from examples/cube-no-framework/src/main.rs rename to examples/src/cube_no_framework/mod.rs index 31c0cc47..5fc2f35d 100644 --- a/examples/cube-no-framework/src/main.rs +++ b/examples/src/cube_no_framework/mod.rs @@ -55,7 +55,7 @@ fn create_mesh() -> rend3::types::Mesh { .unwrap() } -fn main() { +pub fn main() { // Setup logging env_logger::init(); diff --git a/examples/egui/src/images/rust-logo-128x128-blk.png b/examples/src/egui/images/rust-logo-128x128-blk.png similarity index 100% rename from examples/egui/src/images/rust-logo-128x128-blk.png rename to examples/src/egui/images/rust-logo-128x128-blk.png diff --git a/examples/egui/src/main.rs b/examples/src/egui/mod.rs similarity index 99% rename from examples/egui/src/main.rs rename to examples/src/egui/mod.rs index cc5b3200..5fed2a3e 100644 --- a/examples/egui/src/main.rs +++ b/examples/src/egui/mod.rs @@ -262,7 +262,7 @@ impl rend3_framework::App for EguiExample { } } -fn main() { +pub fn main() { let app = EguiExample::default(); rend3_framework::start( app, diff --git a/examples/egui/screenshot.png b/examples/src/egui/screenshot.png similarity index 100% rename from examples/egui/screenshot.png rename to examples/src/egui/screenshot.png diff --git a/examples/src/lib.rs b/examples/src/lib.rs new file mode 100644 index 00000000..cb8faef0 --- /dev/null +++ b/examples/src/lib.rs @@ -0,0 +1,74 @@ +mod animation; +mod cube; +mod cube_no_framework; +mod egui; +mod scene_viewer; +mod skinning; +mod static_gltf; +mod textured_quad; + +struct ExampleDesc { + name: &'static str, + run: fn(), +} + +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, + }, +]; + +fn print_examples() { + println!("Usage: cargo run "); + println!(); + println!("Available examples:"); + for example in EXAMPLES { + println!(" {}", example.name); + } +} + +#[cfg_attr(target_os = "android", ndk_glue::main(backtrace = "on", logger(level = "debug")))] +pub fn main() { + let Some(example_name) = std::env::args().nth(1) else { + print_examples(); + return; + }; + + let Some(example) = EXAMPLES.iter().find(|example| example.name == example_name) else { + println!("Unknown example: {}", example_name); + println!(); + print_examples(); + return; + }; + + (example.run)(); +} diff --git a/examples/src/main.rs b/examples/src/main.rs new file mode 100644 index 00000000..b818ccfd --- /dev/null +++ b/examples/src/main.rs @@ -0,0 +1,3 @@ +fn main() { + rend3_examples::main(); +} diff --git a/examples/scene-viewer/README.md b/examples/src/scene_viewer/README.md similarity index 100% rename from examples/scene-viewer/README.md rename to examples/src/scene_viewer/README.md diff --git a/examples/scene-viewer/bistro.jpg b/examples/src/scene_viewer/bistro.jpg similarity index 100% rename from examples/scene-viewer/bistro.jpg rename to examples/src/scene_viewer/bistro.jpg diff --git a/examples/scene-viewer/emerald-square.jpg b/examples/src/scene_viewer/emerald-square.jpg similarity index 100% rename from examples/scene-viewer/emerald-square.jpg rename to examples/src/scene_viewer/emerald-square.jpg diff --git a/examples/scene-viewer/src/lib.rs b/examples/src/scene_viewer/mod.rs similarity index 94% rename from examples/scene-viewer/src/lib.rs rename to examples/src/scene_viewer/mod.rs index ed2a5a1f..800af1fb 100644 --- a/examples/scene-viewer/src/lib.rs +++ b/examples/src/scene_viewer/mod.rs @@ -15,17 +15,12 @@ use rend3_gltf::GltfSceneInstance; use rend3_routine::{pbr::NormalTextureYDirection, skybox::SkyboxRoutine}; use web_time::Instant; use wgpu_profiler::GpuTimerScopeResult; -#[cfg(target_arch = "wasm32")] -use winit::keyboard::PhysicalKey::Code; -#[cfg(not(target_arch = "wasm32"))] -use winit::platform::scancode::PhysicalKeyExtScancode; use winit::{ event::{DeviceEvent, ElementState, Event, KeyEvent, MouseButton, WindowEvent}, + keyboard::{KeyCode, PhysicalKey}, window::{Fullscreen, WindowBuilder}, }; -mod platform; - async fn load_skybox_image(loader: &rend3_framework::AssetLoader, data: &mut Vec, path: &str) { let decoded = image::load_from_memory( &loader @@ -130,7 +125,7 @@ async fn load_gltf( Some((scene, instance)) } -fn button_pressed(map: &HashMap, key: u32) -> bool { +fn button_pressed(map: &HashMap, key: KeyCode) -> bool { map.get(&key).map_or(false, |b| *b) } @@ -277,7 +272,7 @@ Controls: --camera x,y,z,pitch,yaw Spawns the camera at the given position. Press Period to get the current camera position. "; -struct SceneViewer { +pub struct SceneViewer { absolute_mouse: bool, desired_backend: Option, desired_device_name: Option, @@ -295,7 +290,7 @@ struct SceneViewer { fullscreen: bool, - scancode_status: FastHashMap, + scancode_status: FastHashMap, camera_pitch: f32, camera_yaw: f32, camera_location: Vec3A, @@ -312,7 +307,8 @@ impl SceneViewer { #[cfg(feature = "tracy")] tracy_client::Client::start(); - let mut args = Arguments::from_vec(std::env::args_os().skip(1).collect()); + // Skip the first two arguments, which are the binary name and the example name. + let mut args = Arguments::from_vec(std::env::args_os().skip(2).collect()); // Meta let help = args.contains(["-h", "--help"]); @@ -446,15 +442,7 @@ impl rend3_framework::App for SceneViewer { } fn scale_factor(&self) -> f32 { - // Android has very low memory bandwidth, so lets run internal buffers at half - // res by default - cfg_if::cfg_if! { - if #[cfg(target_os = "android")] { - 0.5 - } else { - 1.0 - } - } + 1.0 } fn setup(&mut self, context: rend3_framework::SetupContext<'_>) { @@ -476,7 +464,7 @@ impl rend3_framework::App for SceneViewer { let routines = Arc::clone(context.routines); spawn(async move { let loader = rend3_framework::AssetLoader::new_local( - concat!(env!("CARGO_MANIFEST_DIR"), "/resources/"), + concat!(env!("CARGO_MANIFEST_DIR"), "/src/scene_viewer/resources/"), "", "http://localhost:8000/resources/", ); @@ -542,27 +530,27 @@ impl rend3_framework::App for SceneViewer { let forward = -rotation.z_axis; let up = rotation.y_axis; let side = -rotation.x_axis; - let velocity = if button_pressed(&self.scancode_status, platform::Scancodes::SHIFT) { + let velocity = if button_pressed(&self.scancode_status, KeyCode::ShiftLeft) { self.run_speed } else { self.walk_speed }; - if button_pressed(&self.scancode_status, platform::Scancodes::W) { + if button_pressed(&self.scancode_status, KeyCode::KeyW) { self.camera_location += forward * velocity * delta_time.as_secs_f32(); } - if button_pressed(&self.scancode_status, platform::Scancodes::S) { + if button_pressed(&self.scancode_status, KeyCode::KeyS) { self.camera_location -= forward * velocity * delta_time.as_secs_f32(); } - if button_pressed(&self.scancode_status, platform::Scancodes::A) { + if button_pressed(&self.scancode_status, KeyCode::KeyA) { self.camera_location += side * velocity * delta_time.as_secs_f32(); } - if button_pressed(&self.scancode_status, platform::Scancodes::D) { + if button_pressed(&self.scancode_status, KeyCode::KeyD) { self.camera_location -= side * velocity * delta_time.as_secs_f32(); } - if button_pressed(&self.scancode_status, platform::Scancodes::Q) { + if button_pressed(&self.scancode_status, KeyCode::KeyQ) { self.camera_location += up * velocity * delta_time.as_secs_f32(); } - if button_pressed(&self.scancode_status, platform::Scancodes::PERIOD) { + if button_pressed(&self.scancode_status, KeyCode::Period) { println!( "{x},{y},{z},{pitch},{yaw}", x = self.camera_location.x, @@ -573,11 +561,11 @@ impl rend3_framework::App for SceneViewer { ); } - if button_pressed(&self.scancode_status, platform::Scancodes::ESCAPE) { + if button_pressed(&self.scancode_status, winit::keyboard::KeyCode::Escape) { self.grabber.as_mut().unwrap().request_ungrab(context.window); } - if button_pressed(&self.scancode_status, platform::Scancodes::P) { + if button_pressed(&self.scancode_status, KeyCode::KeyP) { // write out gpu side performance info into a trace readable by chrome://tracing if let Some(ref stats) = self.previous_profiling_stats { println!("Outputing gpu timing chrome trace to profile.json"); @@ -668,11 +656,11 @@ impl rend3_framework::App for SceneViewer { }, .. } => { - #[cfg(not(target_arch = "wasm32"))] - let scancode = PhysicalKeyExtScancode::to_scancode(physical_key).unwrap(); - #[cfg(target_arch = "wasm32")] - let scancode = if let Code(kk) = physical_key { kk as u32 } else { 0 }; - log::info!("WE scancode {:x}", scancode); + let PhysicalKey::Code(scancode) = physical_key else { + return; + }; + + log::info!("Key Pressed {:?}", scancode); self.scancode_status.insert( scancode, match state { diff --git a/examples/scene-viewer/resources/skybox/back.jpg b/examples/src/scene_viewer/resources/skybox/back.jpg similarity index 100% rename from examples/scene-viewer/resources/skybox/back.jpg rename to examples/src/scene_viewer/resources/skybox/back.jpg diff --git a/examples/scene-viewer/resources/skybox/bottom.jpg b/examples/src/scene_viewer/resources/skybox/bottom.jpg similarity index 100% rename from examples/scene-viewer/resources/skybox/bottom.jpg rename to examples/src/scene_viewer/resources/skybox/bottom.jpg diff --git a/examples/scene-viewer/resources/skybox/front.jpg b/examples/src/scene_viewer/resources/skybox/front.jpg similarity index 100% rename from examples/scene-viewer/resources/skybox/front.jpg rename to examples/src/scene_viewer/resources/skybox/front.jpg diff --git a/examples/scene-viewer/resources/skybox/left.jpg b/examples/src/scene_viewer/resources/skybox/left.jpg similarity index 100% rename from examples/scene-viewer/resources/skybox/left.jpg rename to examples/src/scene_viewer/resources/skybox/left.jpg diff --git a/examples/scene-viewer/resources/skybox/right.jpg b/examples/src/scene_viewer/resources/skybox/right.jpg similarity index 100% rename from examples/scene-viewer/resources/skybox/right.jpg rename to examples/src/scene_viewer/resources/skybox/right.jpg diff --git a/examples/scene-viewer/resources/skybox/top.jpg b/examples/src/scene_viewer/resources/skybox/top.jpg similarity index 100% rename from examples/scene-viewer/resources/skybox/top.jpg rename to examples/src/scene_viewer/resources/skybox/top.jpg diff --git a/examples/scene-viewer/scifi-base.jpg b/examples/src/scene_viewer/scifi-base.jpg similarity index 100% rename from examples/scene-viewer/scifi-base.jpg rename to examples/src/scene_viewer/scifi-base.jpg diff --git a/examples/scene-viewer/screenshot.jpg b/examples/src/scene_viewer/screenshot.jpg similarity index 100% rename from examples/scene-viewer/screenshot.jpg rename to examples/src/scene_viewer/screenshot.jpg diff --git a/examples/skinning/README.md b/examples/src/skinning/README.md similarity index 100% rename from examples/skinning/README.md rename to examples/src/skinning/README.md diff --git a/examples/skinning/RiggedSimple.glb b/examples/src/skinning/RiggedSimple.glb similarity index 100% rename from examples/skinning/RiggedSimple.glb rename to examples/src/skinning/RiggedSimple.glb diff --git a/examples/skinning/src/lib.rs b/examples/src/skinning/mod.rs similarity index 98% rename from examples/skinning/src/lib.rs rename to examples/src/skinning/mod.rs index e0735a26..467c2a80 100644 --- a/examples/skinning/src/lib.rs +++ b/examples/src/skinning/mod.rs @@ -6,7 +6,7 @@ use winit::event::WindowEvent; const SAMPLE_COUNT: rend3::types::SampleCount = rend3::types::SampleCount::One; #[derive(Default)] -struct SkinningExample { +pub struct SkinningExample { loaded_scene: Option, loaded_instance: Option, directional_light_handle: Option, @@ -79,7 +79,7 @@ impl rend3_framework::App for SkinningExample { }); // Load a gltf model with animation data - let path = Path::new(concat!(env!("CARGO_MANIFEST_DIR"), "/RiggedSimple.glb")); + let path = Path::new(concat!(env!("CARGO_MANIFEST_DIR"), "/src/skinning/RiggedSimple.glb")); 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( @@ -178,7 +178,6 @@ impl rend3_framework::App for SkinningExample { } } -#[cfg_attr(target_os = "android", ndk_glue::main(backtrace = "on", logger(level = "debug")))] pub fn main() { let app = SkinningExample::default(); rend3_framework::start( diff --git a/examples/skinning/screenshot.png b/examples/src/skinning/screenshot.png similarity index 100% rename from examples/skinning/screenshot.png rename to examples/src/skinning/screenshot.png diff --git a/examples/static-gltf/README.md b/examples/src/static_gltf/README.md similarity index 100% rename from examples/static-gltf/README.md rename to examples/src/static_gltf/README.md diff --git a/examples/static-gltf/data.glb b/examples/src/static_gltf/data.glb similarity index 100% rename from examples/static-gltf/data.glb rename to examples/src/static_gltf/data.glb diff --git a/examples/static-gltf/src/main.rs b/examples/src/static_gltf/mod.rs similarity index 97% rename from examples/static-gltf/src/main.rs rename to examples/src/static_gltf/mod.rs index 7a0e517e..732954c0 100644 --- a/examples/static-gltf/src/main.rs +++ b/examples/src/static_gltf/mod.rs @@ -70,7 +70,10 @@ impl rend3_framework::App for GltfExample { // Create mesh and calculate smooth normals based on vertices. // // We do not need to keep these handles alive once we make the object - let (mesh, material) = load_gltf(context.renderer, concat!(env!("CARGO_MANIFEST_DIR"), "/data.glb")); + let (mesh, material) = load_gltf( + context.renderer, + concat!(env!("CARGO_MANIFEST_DIR"), "/src/static_gltf/data.glb"), + ); // Combine the mesh and the material with a location to give an object. let object = rend3::types::Object { @@ -169,7 +172,7 @@ impl rend3_framework::App for GltfExample { } } -fn main() { +pub fn main() { let app = GltfExample::default(); rend3_framework::start( app, diff --git a/examples/static-gltf/screenshot.png b/examples/src/static_gltf/screenshot.png similarity index 100% rename from examples/static-gltf/screenshot.png rename to examples/src/static_gltf/screenshot.png diff --git a/examples/textured-quad/Cargo.toml b/examples/src/textured_quad/Cargo.toml similarity index 100% rename from examples/textured-quad/Cargo.toml rename to examples/src/textured_quad/Cargo.toml diff --git a/examples/textured-quad/README.md b/examples/src/textured_quad/README.md similarity index 100% rename from examples/textured-quad/README.md rename to examples/src/textured_quad/README.md diff --git a/examples/textured-quad/src/checker.png b/examples/src/textured_quad/checker.png similarity index 100% rename from examples/textured-quad/src/checker.png rename to examples/src/textured_quad/checker.png diff --git a/examples/textured-quad/src/main.rs b/examples/src/textured_quad/mod.rs similarity index 99% rename from examples/textured-quad/src/main.rs rename to examples/src/textured_quad/mod.rs index 9723371e..d51bde4a 100644 --- a/examples/textured-quad/src/main.rs +++ b/examples/src/textured_quad/mod.rs @@ -188,7 +188,7 @@ impl rend3_framework::App for TexturedQuadExample { } } -fn main() { +pub fn main() { let app = TexturedQuadExample::default(); rend3_framework::start( app, diff --git a/examples/textured-quad/screenshot.png b/examples/src/textured_quad/screenshot.png similarity index 100% rename from examples/textured-quad/screenshot.png rename to examples/src/textured_quad/screenshot.png diff --git a/examples/static-gltf/Cargo.toml b/examples/static-gltf/Cargo.toml deleted file mode 100644 index 74bbccc9..00000000 --- a/examples/static-gltf/Cargo.toml +++ /dev/null @@ -1,30 +0,0 @@ -[package] -name = "rend3-static-gltf-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 = "static-gltf" -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" -# parsing model files -gltf = { version = "1.0", default-features = false, features = ["import", "utils"] } -# Renderer core -rend3 = { version = "^0.3.0", path = "../../rend3"} -# Framework that deals with the event loop, setting up the renderer, and platform differences. -rend3-framework = { version = "^0.3.0", path = "../../rend3-framework" } -# Programmable render list that dictates how the scene renders -rend3-routine = { version = "^0.3.0", path = "../../rend3-routine" } -# windowing -winit = "0.29.4" diff --git a/rend3-framework/Cargo.toml b/rend3-framework/Cargo.toml index 217fd4ae..28d7c177 100644 --- a/rend3-framework/Cargo.toml +++ b/rend3-framework/Cargo.toml @@ -21,7 +21,7 @@ profiling = { version = "1", default-features = false } rend3 = { version = "0.3.0", path = "../rend3" } rend3-routine = { version = "0.3.0", path = "../rend3-routine" } thiserror = { version = "1" } -winit = "0.29.4" +winit = { version = "0.29.4", features = ["rwh_05"] } wgpu = "0.18.0" [target.'cfg(not(target_arch = "wasm32"))'.dependencies]