Skip to content

Commit

Permalink
Repository Updates (#583)
Browse files Browse the repository at this point in the history
  • Loading branch information
cwfitzgerald committed Mar 10, 2024
1 parent 331e1e4 commit 87f9ac4
Show file tree
Hide file tree
Showing 87 changed files with 647 additions and 2,206 deletions.
1 change: 1 addition & 0 deletions .rustfmt.toml
@@ -1,4 +1,5 @@
max_width = 120
use_small_heuristics = "Max"
use_field_init_shorthand = true
use_try_shorthand = true
edition = "2021"
6 changes: 3 additions & 3 deletions build.bash
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions deny.toml
Expand Up @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions examples/Cargo.toml
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions examples/resources/index.html
Expand Up @@ -13,8 +13,9 @@

<body style="margin: 0px">
<script type="module">
import init from "./{{example}}.js";
init();
import init, {main_with_name} from "./rend3-examples.js";
await init();
main_with_name("{{example}}");
</script>
</body>

Expand Down
14 changes: 3 additions & 11 deletions examples/src/animation/mod.rs
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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),
);
}

Expand Down
20 changes: 7 additions & 13 deletions examples/src/cube/mod.rs
Expand Up @@ -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,
}));
}
}

Expand Down Expand Up @@ -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)]
Expand Down
36 changes: 0 additions & 36 deletions examples/src/cube_no_framework/Cargo.toml

This file was deleted.

10 changes: 2 additions & 8 deletions examples/src/cube_no_framework/mod.rs
Expand Up @@ -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(
Expand All @@ -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();

Expand Down
28 changes: 5 additions & 23 deletions examples/src/egui/mod.rs
Expand Up @@ -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);
}
_ => {}
}
Expand Down Expand Up @@ -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");
}
});
Expand All @@ -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();
Expand Down Expand Up @@ -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 {
Expand Down
65 changes: 26 additions & 39 deletions 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;
Expand All @@ -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;

Expand All @@ -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 <example_name>");
println!();
println!("Usage: cargo run <example_name>\n");
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 {
#[cfg_attr(target_arch = "wasm32", wasm_bindgen)]
pub fn main_with_name(example_name: Option<String>) {
let Some(example_name) = example_name else {
print_examples();
return;
};

let Some(example) = EXAMPLES.iter().find(|example| example.name == example_name) else {
println!("Unknown example: {}", example_name);
println!();
println!("Unknown example: {}\n", example_name);
print_examples();
return;
};

(example.run)();
}

#[cfg_attr(target_os = "android", ndk_glue::main(backtrace = "on", logger(level = "debug")))]
pub fn main() {
main_with_name(std::env::args().nth(1))
}

0 comments on commit 87f9ac4

Please sign in to comment.