diff --git a/Cargo.toml b/Cargo.toml index 197db38d9..f4f250caa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,7 +26,7 @@ text = ["swash", "lyon"] # Text mesh generation features [dependencies] glow = "0.14" cgmath = "0.18" -three-d-asset = {version = "0.7"} +three-d-asset = "0.8" thiserror = "2" open-enum = "0.5" winit = {version = "0.28", optional = true} @@ -51,7 +51,7 @@ instant = "0.1.11" [dev-dependencies] rand = "0.7" -three-d-asset = {version = "0.7", features = ["hdr", "gltf", "obj", "vol", "pcd", "png", "jpeg", "http", "data-url"] } +three-d-asset = {version = "0.8", features = ["hdr", "gltf", "obj", "vol", "pcd", "png", "jpeg", "http", "data-url"] } noise = {version = "0.6", default-features = false} winit = "0.28" @@ -118,6 +118,7 @@ path = "examples/sprites/src/main.rs" [[example]] name = "texture" path = "examples/texture/src/main.rs" +required-features = ["egui-gui"] [[example]] name = "volume" diff --git a/examples/animation/Cargo.toml b/examples/animation/Cargo.toml index fdb6d0f57..9a2587cb8 100644 --- a/examples/animation/Cargo.toml +++ b/examples/animation/Cargo.toml @@ -9,7 +9,7 @@ crate-type = ["cdylib"] [dependencies] three-d = { path = "../../" } -three-d-asset = {version = "0.7", features = ["gltf", "png", "jpeg", "http", "data-url"] } +three-d-asset = {version = "0.8", features = ["gltf", "png", "jpeg", "http", "data-url"] } [target.'cfg(not(target_arch = "wasm32"))'.dependencies] tokio = { version = "1", features = ["macros", "rt-multi-thread"] } diff --git a/examples/animation/src/main.rs b/examples/animation/src/main.rs index c1bf653b3..faa8a53ff 100644 --- a/examples/animation/src/main.rs +++ b/examples/animation/src/main.rs @@ -25,7 +25,7 @@ pub async fn run() { 0.1, 1000.0, ); - let mut control = OrbitControl::new(*camera.target(), 1.0, 1000.0); + let mut control = OrbitControl::new(camera.target(), 1.0, 1000.0); // Source: https://github.com/KhronosGroup/glTF-Sample-Models/tree/master/2.0 let mut loaded = if let Ok(loaded) = @@ -47,8 +47,8 @@ pub async fn run() { .for_each(|part| part.compute_normals()); let mut model = Model::::new(&context, &cpu_model).unwrap(); - let light0 = DirectionalLight::new(&context, 1.0, Srgba::WHITE, &vec3(0.0, -0.5, -0.5)); - let light1 = DirectionalLight::new(&context, 1.0, Srgba::WHITE, &vec3(0.0, 0.5, 0.5)); + let light0 = DirectionalLight::new(&context, 1.0, Srgba::WHITE, vec3(0.0, -0.5, -0.5)); + let light1 = DirectionalLight::new(&context, 1.0, Srgba::WHITE, vec3(0.0, 0.5, 0.5)); // main loop window.render_loop(move |mut frame_input| { diff --git a/examples/assets/checkerboard.jpg b/examples/assets/checkerboard.jpg new file mode 100644 index 000000000..efcfb0eb0 Binary files /dev/null and b/examples/assets/checkerboard.jpg differ diff --git a/examples/environment/Cargo.toml b/examples/environment/Cargo.toml index c9c43ec4f..c095ce31d 100644 --- a/examples/environment/Cargo.toml +++ b/examples/environment/Cargo.toml @@ -9,7 +9,7 @@ crate-type = ["cdylib"] [dependencies] three-d = { path = "../../", features=["egui-gui"] } -three-d-asset = {version = "0.7",features = ["hdr", "http"] } +three-d-asset = {version = "0.8",features = ["hdr", "http"] } [target.'cfg(not(target_arch = "wasm32"))'.dependencies] tokio = { version = "1", features = ["macros", "rt-multi-thread"] } diff --git a/examples/environment/src/main.rs b/examples/environment/src/main.rs index 6e66eee69..899b20f2c 100644 --- a/examples/environment/src/main.rs +++ b/examples/environment/src/main.rs @@ -25,7 +25,7 @@ pub async fn run() { 0.1, 1000.0, ); - let mut control = OrbitControl::new(*camera.target(), 1.0, 100.0); + let mut control = OrbitControl::new(camera.target(), 1.0, 100.0); // Source: https://polyhaven.com/ let mut loaded = if let Ok(loaded) = diff --git a/examples/fireworks/src/main.rs b/examples/fireworks/src/main.rs index 274368eca..fbcdb9df8 100644 --- a/examples/fireworks/src/main.rs +++ b/examples/fireworks/src/main.rs @@ -88,7 +88,7 @@ pub fn run() { Srgba::new_opaque(40, 178, 222), ]; let mut square = CpuMesh::square(); - square.transform(&Mat4::from_scale(0.6)).unwrap(); + square.transform(Mat4::from_scale(0.6)).unwrap(); // A particle system is created with an acceleration of -9.82 in the y direction to simulate gravity. let particles = ParticleSystem::new( diff --git a/examples/fog/Cargo.toml b/examples/fog/Cargo.toml index 7332113c1..b815c6ea4 100644 --- a/examples/fog/Cargo.toml +++ b/examples/fog/Cargo.toml @@ -9,7 +9,7 @@ crate-type = ["cdylib"] [dependencies] three-d = { path = "../../" } -three-d-asset = {version = "0.7",features = ["obj", "http"] } +three-d-asset = {version = "0.8",features = ["obj", "http"] } [target.'cfg(not(target_arch = "wasm32"))'.dependencies] tokio = { version = "1", features = ["macros", "rt-multi-thread"] } diff --git a/examples/fog/src/main.rs b/examples/fog/src/main.rs index 2b1c9fd71..98523bbad 100644 --- a/examples/fog/src/main.rs +++ b/examples/fog/src/main.rs @@ -39,7 +39,7 @@ pub async fn run() { .for_each(|m| m.material.render_states.cull = Cull::Back); let ambient = AmbientLight::new(&context, 0.4, Srgba::WHITE); - let directional = DirectionalLight::new(&context, 2.0, Srgba::WHITE, &vec3(-1.0, -1.0, -1.0)); + let directional = DirectionalLight::new(&context, 2.0, Srgba::WHITE, vec3(-1.0, -1.0, -1.0)); // Fog let mut fog_effect = FogEffect { diff --git a/examples/forest/Cargo.toml b/examples/forest/Cargo.toml index 5ab861f52..9f73f97a8 100644 --- a/examples/forest/Cargo.toml +++ b/examples/forest/Cargo.toml @@ -9,7 +9,7 @@ crate-type = ["cdylib"] [dependencies] three-d = { path = "../../" } -three-d-asset = {version = "0.7",features = ["obj", "jpeg", "http"] } +three-d-asset = {version = "0.8",features = ["obj", "jpeg", "http"] } [target.'cfg(not(target_arch = "wasm32"))'.dependencies] tokio = { version = "1", features = ["macros", "rt-multi-thread"] } diff --git a/examples/forest/src/main.rs b/examples/forest/src/main.rs index c08deeebf..6ea549387 100644 --- a/examples/forest/src/main.rs +++ b/examples/forest/src/main.rs @@ -51,12 +51,12 @@ pub async fn run() { // Lights let ambient = AmbientLight::new(&context, 0.3, Srgba::WHITE); - let directional = DirectionalLight::new(&context, 4.0, Srgba::WHITE, &vec3(-1.0, -1.0, -1.0)); + let directional = DirectionalLight::new(&context, 4.0, Srgba::WHITE, vec3(-1.0, -1.0, -1.0)); // Imposters let mut aabb = AxisAlignedBoundingBox::EMPTY; model.iter().for_each(|m| { - aabb.expand_with_aabb(&m.aabb()); + aabb.expand_with_aabb(m.aabb()); }); let size = aabb.size(); let t = 100; diff --git a/examples/headless/Cargo.toml b/examples/headless/Cargo.toml index 209c46620..b6453a843 100644 --- a/examples/headless/Cargo.toml +++ b/examples/headless/Cargo.toml @@ -9,7 +9,7 @@ crate-type = ["cdylib"] [dependencies] three-d = { path = "../../", features=["headless"] } -three-d-asset = {version = "0.7", features=["png"]} +three-d-asset = {version = "0.8", features=["png"]} [target.'cfg(target_arch = "wasm32")'.dependencies] log = "0.4" diff --git a/examples/image/Cargo.toml b/examples/image/Cargo.toml index 1458787b8..cd51ea2d7 100644 --- a/examples/image/Cargo.toml +++ b/examples/image/Cargo.toml @@ -9,7 +9,7 @@ crate-type = ["cdylib"] [dependencies] three-d = { path = "../../", features=["egui-gui"] } -three-d-asset = {version = "0.7",features = ["hdr", "http"] } +three-d-asset = {version = "0.8",features = ["hdr", "http"] } [target.'cfg(not(target_arch = "wasm32"))'.dependencies] tokio = { version = "1", features = ["macros", "rt-multi-thread"] } diff --git a/examples/instanced_draw_order/src/main.rs b/examples/instanced_draw_order/src/main.rs index 39ff7e27a..9dac71989 100644 --- a/examples/instanced_draw_order/src/main.rs +++ b/examples/instanced_draw_order/src/main.rs @@ -58,7 +58,7 @@ pub fn main() { let mut thin_cube = CpuMesh::cube(); thin_cube - .transform(&Mat4::from_nonuniform_scale(1.0, 1.0, 0.04)) + .transform(Mat4::from_nonuniform_scale(1.0, 1.0, 0.04)) .unwrap(); let transparent_models = Gm::new( @@ -116,7 +116,7 @@ pub fn main() { ); opaque_model.set_transformation(Mat4::from_translation(vec3(0.0, -0.4, -3.0))); - let light0 = DirectionalLight::new(&context, 1.0, Srgba::WHITE, &vec3(0.0, -0.5, -0.5)); + let light0 = DirectionalLight::new(&context, 1.0, Srgba::WHITE, vec3(0.0, -0.5, -0.5)); let ambient_light = three_d::renderer::light::AmbientLight::new(&context, 0.8, Srgba::WHITE); window.render_loop(move |mut frame_input| { diff --git a/examples/instanced_shapes/src/main.rs b/examples/instanced_shapes/src/main.rs index 9f0627c35..24fd9388a 100644 --- a/examples/instanced_shapes/src/main.rs +++ b/examples/instanced_shapes/src/main.rs @@ -20,8 +20,8 @@ pub fn main() { ); let mut control = OrbitControl::new(vec3(0.0, 0.0, 0.0), 1.0, 1000.0); - let light0 = DirectionalLight::new(&context, 1.0, Srgba::WHITE, &vec3(0.0, -0.5, -0.5)); - let light1 = DirectionalLight::new(&context, 1.0, Srgba::WHITE, &vec3(0.0, 0.5, 0.5)); + let light0 = DirectionalLight::new(&context, 1.0, Srgba::WHITE, vec3(0.0, -0.5, -0.5)); + let light1 = DirectionalLight::new(&context, 1.0, Srgba::WHITE, vec3(0.0, 0.5, 0.5)); // Container for non instanced meshes. let mut non_instanced_meshes = Vec::new(); diff --git a/examples/lighting/Cargo.toml b/examples/lighting/Cargo.toml index ae25fb9f9..9933995d6 100644 --- a/examples/lighting/Cargo.toml +++ b/examples/lighting/Cargo.toml @@ -9,7 +9,7 @@ crate-type = ["cdylib"] [dependencies] three-d = { path = "../../", features=["egui-gui"] } -three-d-asset = {version = "0.7",features = ["gltf", "jpeg", "http"] } +three-d-asset = {version = "0.8",features = ["gltf", "jpeg", "http"] } [target.'cfg(not(target_arch = "wasm32"))'.dependencies] tokio = { version = "1", features = ["macros", "rt-multi-thread"] } diff --git a/examples/lighting/src/main.rs b/examples/lighting/src/main.rs index 9b52ba237..16e0cd608 100644 --- a/examples/lighting/src/main.rs +++ b/examples/lighting/src/main.rs @@ -36,7 +36,7 @@ pub async fn run() { 0.1, 30.0, ); - let mut control = OrbitControl::new(*camera.target(), 1.0, 100.0); + let mut control = OrbitControl::new(camera.target(), 1.0, 100.0); let mut gui = three_d::GUI::new(&context); // Source: https://github.com/KhronosGroup/glTF-Sample-Models/tree/master/2.0 @@ -60,9 +60,9 @@ pub async fn run() { let mut cpu_plane = CpuMesh::square(); cpu_plane .transform( - &(Mat4::from_translation(vec3(0.0, -1.0, 0.0)) + Mat4::from_translation(vec3(0.0, -1.0, 0.0)) * Mat4::from_scale(10.0) - * Mat4::from_angle_x(degrees(-90.0))), + * Mat4::from_angle_x(degrees(-90.0)), ) .unwrap(); let mut plane = Gm::new( @@ -81,15 +81,14 @@ pub async fn run() { ); let mut ambient = AmbientLight::new(&context, 0.2, Srgba::WHITE); - let mut directional0 = DirectionalLight::new(&context, 1.0, Srgba::RED, &vec3(0.0, -1.0, 0.0)); - let mut directional1 = - DirectionalLight::new(&context, 1.0, Srgba::GREEN, &vec3(0.0, -1.0, 0.0)); + let mut directional0 = DirectionalLight::new(&context, 1.0, Srgba::RED, vec3(0.0, -1.0, 0.0)); + let mut directional1 = DirectionalLight::new(&context, 1.0, Srgba::GREEN, vec3(0.0, -1.0, 0.0)); let mut spot0 = SpotLight::new( &context, 2.0, Srgba::BLUE, - &vec3(0.0, 0.0, 0.0), - &vec3(0.0, -1.0, 0.0), + vec3(0.0, 0.0, 0.0), + vec3(0.0, -1.0, 0.0), degrees(25.0), Attenuation { constant: 0.1, @@ -101,7 +100,7 @@ pub async fn run() { &context, 1.0, Srgba::GREEN, - &vec3(0.0, 0.0, 0.0), + vec3(0.0, 0.0, 0.0), Attenuation { constant: 0.5, linear: 0.05, @@ -112,7 +111,7 @@ pub async fn run() { &context, 1.0, Srgba::RED, - &vec3(0.0, 0.0, 0.0), + vec3(0.0, 0.0, 0.0), Attenuation { constant: 0.5, linear: 0.05, diff --git a/examples/lights/Cargo.toml b/examples/lights/Cargo.toml index 2fa489382..d3a13ff6c 100644 --- a/examples/lights/Cargo.toml +++ b/examples/lights/Cargo.toml @@ -9,7 +9,7 @@ crate-type = ["cdylib"] [dependencies] three-d = { path = "../../", features=["egui-gui"] } -three-d-asset = {version = "0.7",features = ["gltf", "png", "jpeg", "http"] } +three-d-asset = {version = "0.8",features = ["gltf", "png", "jpeg", "http"] } [target.'cfg(not(target_arch = "wasm32"))'.dependencies] rand = "0.7" diff --git a/examples/lights/src/main.rs b/examples/lights/src/main.rs index 00cdc0284..6640c3172 100644 --- a/examples/lights/src/main.rs +++ b/examples/lights/src/main.rs @@ -44,7 +44,7 @@ pub async fn run() { let mut aabb = AxisAlignedBoundingBox::EMPTY; for m in model.iter() { - aabb.expand_with_aabb(&m.aabb()); + aabb.expand_with_aabb(m.aabb()); } let size = aabb.size(); @@ -154,7 +154,7 @@ impl Glow { ); Self { aabb, - light: PointLight::new(&context, 1.0, Srgba::WHITE, &pos, Attenuation::default()), + light: PointLight::new(&context, 1.0, Srgba::WHITE, pos, Attenuation::default()), velocity: vec3( rng.gen::() * 2.0 - 1.0, rng.gen::() * 2.0 - 1.0, diff --git a/examples/logo/Cargo.toml b/examples/logo/Cargo.toml index 59951939f..3c0e3e3c7 100644 --- a/examples/logo/Cargo.toml +++ b/examples/logo/Cargo.toml @@ -9,7 +9,7 @@ crate-type = ["cdylib"] [dependencies] three-d = { path = "../../" } -three-d-asset = {version = "0.7",features = ["png", "http"] } +three-d-asset = {version = "0.8",features = ["png", "http"] } [target.'cfg(not(target_arch = "wasm32"))'.dependencies] tokio = { version = "1", features = ["macros", "rt-multi-thread"] } diff --git a/examples/mandelbrot/src/main.rs b/examples/mandelbrot/src/main.rs index 547b1b780..58eb98f83 100644 --- a/examples/mandelbrot/src/main.rs +++ b/examples/mandelbrot/src/main.rs @@ -82,9 +82,8 @@ pub fn main() { if button == Some(MouseButton::Left) { let speed = 0.003 * camera.position().z.abs(); let right = camera.right_direction(); - let up = right.cross(camera.view_direction()); - let delta = -right * speed * delta.0 + up * speed * delta.1; - camera.translate(&delta); + let up = camera.up_orthogonal(); + camera.translate(-right * speed * delta.0 + up * speed * delta.1); redraw = true; } } @@ -94,7 +93,7 @@ pub fn main() { let distance = camera.position().z.abs(); let mut target = camera.position_at_pixel(position); target.z = 0.0; - camera.zoom_towards(&target, distance * 0.05 * delta.1, 0.00001, 10.0); + camera.zoom_towards(target, distance * 0.05 * delta.1, 0.00001, 10.0); redraw = true; } _ => {} diff --git a/examples/normals/Cargo.toml b/examples/normals/Cargo.toml index 7c95bf34d..58236f9c1 100644 --- a/examples/normals/Cargo.toml +++ b/examples/normals/Cargo.toml @@ -9,7 +9,7 @@ crate-type = ["cdylib"] [dependencies] three-d = { path = "../../" } -three-d-asset = {version = "0.7",features = ["gltf", "png", "http"] } +three-d-asset = {version = "0.8",features = ["gltf", "png", "http"] } [target.'cfg(not(target_arch = "wasm32"))'.dependencies] tokio = { version = "1", features = ["macros", "rt-multi-thread"] } diff --git a/examples/normals/src/main.rs b/examples/normals/src/main.rs index c95e3a630..d5da76e8a 100644 --- a/examples/normals/src/main.rs +++ b/examples/normals/src/main.rs @@ -76,10 +76,10 @@ pub async fn run() { 0.1, 1000.0, ); - let mut control = OrbitControl::new(*camera.target(), 1.0, 100.0); + let mut control = OrbitControl::new(camera.target(), 1.0, 100.0); let ambient = AmbientLight::new(&context, 0.4, Srgba::WHITE); - let directional = DirectionalLight::new(&context, 2.0, Srgba::WHITE, &vec3(0.0, -1.0, 0.0)); + let directional = DirectionalLight::new(&context, 2.0, Srgba::WHITE, vec3(0.0, -1.0, 0.0)); // main loop window.render_loop(move |mut frame_input| { diff --git a/examples/pbr/Cargo.toml b/examples/pbr/Cargo.toml index bc47d18e3..09d37452d 100644 --- a/examples/pbr/Cargo.toml +++ b/examples/pbr/Cargo.toml @@ -9,7 +9,7 @@ crate-type = ["cdylib"] [dependencies] three-d = { path = "../../", features=["egui-gui"] } -three-d-asset = {version = "0.7",features = ["gltf", "hdr", "jpeg", "http"] } +three-d-asset = {version = "0.8",features = ["gltf", "hdr", "jpeg", "http"] } [target.'cfg(not(target_arch = "wasm32"))'.dependencies] tokio = { version = "1", features = ["macros", "rt-multi-thread"] } diff --git a/examples/pbr/src/main.rs b/examples/pbr/src/main.rs index c0e4c605e..4997233d1 100644 --- a/examples/pbr/src/main.rs +++ b/examples/pbr/src/main.rs @@ -25,7 +25,7 @@ pub async fn run() { 0.1, 1000.0, ); - let mut control = OrbitControl::new(*camera.target(), 1.0, 100.0); + let mut control = OrbitControl::new(camera.target(), 1.0, 100.0); let mut gui = three_d::GUI::new(&context); let mut loaded = if let Ok(loaded) = three_d_asset::io::load_async(&[ diff --git a/examples/picking/Cargo.toml b/examples/picking/Cargo.toml index 05e927d93..9ab67f51c 100644 --- a/examples/picking/Cargo.toml +++ b/examples/picking/Cargo.toml @@ -9,7 +9,7 @@ crate-type = ["cdylib"] [dependencies] three-d = { path = "../../" } -three-d-asset = {version = "0.7",features = ["obj", "http"] } +three-d-asset = {version = "0.8",features = ["obj", "http"] } [target.'cfg(not(target_arch = "wasm32"))'.dependencies] tokio = { version = "1", features = ["macros", "rt-multi-thread"] } diff --git a/examples/picking/src/main.rs b/examples/picking/src/main.rs index 35c88a35f..4224cba59 100644 --- a/examples/picking/src/main.rs +++ b/examples/picking/src/main.rs @@ -25,10 +25,10 @@ pub async fn run() { 0.1, 1000.0, ); - let mut control = OrbitControl::new(*camera.target(), 1.0, 100.0); + let mut control = OrbitControl::new(camera.target(), 1.0, 100.0); let mut sphere = CpuMesh::sphere(8); - sphere.transform(&Mat4::from_scale(0.1)).unwrap(); + sphere.transform(Mat4::from_scale(0.1)).unwrap(); let mut pick_mesh = Gm::new( Mesh::new(&context, &sphere), PhysicalMaterial::new_opaque( @@ -41,7 +41,7 @@ pub async fn run() { ); let ambient = AmbientLight::new(&context, 0.4, Srgba::WHITE); - let directional = DirectionalLight::new(&context, 2.0, Srgba::WHITE, &vec3(-1.0, -1.0, -1.0)); + let directional = DirectionalLight::new(&context, 2.0, Srgba::WHITE, vec3(-1.0, -1.0, -1.0)); let mut loaded = three_d_asset::io::load_async(&["examples/assets/suzanne.obj"]) .await diff --git a/examples/point_cloud/Cargo.toml b/examples/point_cloud/Cargo.toml index 159df2b50..5a9c8ca60 100644 --- a/examples/point_cloud/Cargo.toml +++ b/examples/point_cloud/Cargo.toml @@ -9,7 +9,7 @@ crate-type = ["cdylib"] [dependencies] three-d = { path = "../../" } -three-d-asset = {version = "0.7",features = ["pcd", "http"] } +three-d-asset = {version = "0.8",features = ["pcd", "http"] } [target.'cfg(not(target_arch = "wasm32"))'.dependencies] tokio = { version = "1.16", features = ["macros", "rt-multi-thread"] } diff --git a/examples/point_cloud/src/main.rs b/examples/point_cloud/src/main.rs index 0a905f7cc..43f382e66 100644 --- a/examples/point_cloud/src/main.rs +++ b/examples/point_cloud/src/main.rs @@ -25,7 +25,7 @@ pub async fn run() { 0.01, 100.0, ); - let mut control = OrbitControl::new(*camera.target(), 0.1, 3.0); + let mut control = OrbitControl::new(camera.target(), 0.1, 3.0); // Load point cloud let mut loaded = three_d_asset::io::load_async(&["examples/assets/hand.pcd"]) @@ -34,7 +34,7 @@ pub async fn run() { let cpu_point_cloud: PointCloud = loaded.deserialize("hand.pcd").unwrap(); let mut point_mesh = CpuMesh::sphere(4); - point_mesh.transform(&Mat4::from_scale(0.001)).unwrap(); + point_mesh.transform(Mat4::from_scale(0.001)).unwrap(); let mut point_cloud = Gm { geometry: InstancedMesh::new(&context, &cpu_point_cloud.into(), &point_mesh), diff --git a/examples/shapes/src/main.rs b/examples/shapes/src/main.rs index 671bdb1df..f03dc9ee6 100644 --- a/examples/shapes/src/main.rs +++ b/examples/shapes/src/main.rs @@ -18,7 +18,7 @@ pub fn main() { 0.1, 1000.0, ); - let mut control = OrbitControl::new(*camera.target(), 1.0, 100.0); + let mut control = OrbitControl::new(camera.target(), 1.0, 100.0); let mut sphere = Gm::new( Mesh::new(&context, &CpuMesh::sphere(16)), @@ -92,8 +92,8 @@ pub fn main() { }, ); - let light0 = DirectionalLight::new(&context, 1.0, Srgba::WHITE, &vec3(0.0, -0.5, -0.5)); - let light1 = DirectionalLight::new(&context, 1.0, Srgba::WHITE, &vec3(0.0, 0.5, 0.5)); + let light0 = DirectionalLight::new(&context, 1.0, Srgba::WHITE, vec3(0.0, -0.5, -0.5)); + let light1 = DirectionalLight::new(&context, 1.0, Srgba::WHITE, vec3(0.0, 0.5, 0.5)); window.render_loop(move |mut frame_input| { camera.set_viewport(frame_input.viewport); diff --git a/examples/sprites/Cargo.toml b/examples/sprites/Cargo.toml index e0ee4e716..d99c312bf 100644 --- a/examples/sprites/Cargo.toml +++ b/examples/sprites/Cargo.toml @@ -9,7 +9,7 @@ crate-type = ["cdylib"] [dependencies] three-d = { path = "../../" } -three-d-asset = {version = "0.7",features = ["jpeg", "http"] } +three-d-asset = {version = "0.8",features = ["jpeg", "http"] } [target.'cfg(not(target_arch = "wasm32"))'.dependencies] tokio = { version = "1", features = ["macros", "rt-multi-thread"] } diff --git a/examples/statues/Cargo.toml b/examples/statues/Cargo.toml index f8102c365..2fefe7943 100644 --- a/examples/statues/Cargo.toml +++ b/examples/statues/Cargo.toml @@ -9,7 +9,7 @@ crate-type = ["cdylib"] [dependencies] three-d = { path = "../../", features=["egui-gui"] } -three-d-asset = {version = "0.7",features = ["obj", "png", "http"] } +three-d-asset = {version = "0.8",features = ["obj", "png", "http"] } [target.'cfg(not(target_arch = "wasm32"))'.dependencies] tokio = { version = "1", features = ["macros", "rt-multi-thread"] } diff --git a/examples/statues/src/main.rs b/examples/statues/src/main.rs index 54afd6f97..d10e76559 100644 --- a/examples/statues/src/main.rs +++ b/examples/statues/src/main.rs @@ -42,9 +42,9 @@ pub async fn run() { 10000.0, ); let mut control = OrbitControl::new( - *primary_camera.target(), - 0.5 * primary_camera.target().distance(*primary_camera.position()), - 5.0 * primary_camera.target().distance(*primary_camera.position()), + primary_camera.target(), + 0.5 * primary_camera.target().distance(primary_camera.position()), + 5.0 * primary_camera.target().distance(primary_camera.position()), ); // Models from http://texturedmesh.isti.cnr.it/ @@ -95,7 +95,7 @@ pub async fn run() { &context, 10.0, Srgba::new_opaque(204, 178, 127), - &vec3(0.0, -1.0, -1.0), + vec3(0.0, -1.0, -1.0), ); directional.generate_shadow_map( 1024, @@ -112,7 +112,7 @@ pub async fn run() { ..Default::default() }, )); - aabb.expand_with_aabb(&geometry.aabb()); + aabb.expand_with_aabb(geometry.aabb()); } bounding_boxes.push(Gm::new( BoundingBox::new_with_thickness(&context, aabb, 3.0), @@ -169,7 +169,7 @@ pub async fn run() { .iter() .flatten() .chain(&fountain) - .filter(|o| primary_camera.in_frustum(&o.aabb())) + .filter(|o| primary_camera.in_frustum(o.aabb())) { object.render(camera, &[&ambient, &directional]); } diff --git a/examples/terrain/Cargo.toml b/examples/terrain/Cargo.toml index a49abe818..221dc4ffb 100644 --- a/examples/terrain/Cargo.toml +++ b/examples/terrain/Cargo.toml @@ -9,7 +9,7 @@ crate-type = ["cdylib"] [dependencies] three-d = { path = "../../", features=["egui-gui"] } -three-d-asset = {version = "0.7",features = ["gltf", "jpeg", "png", "hdr", "http"] } +three-d-asset = {version = "0.8",features = ["gltf", "jpeg", "png", "hdr", "http"] } noise = {version = "0.6", default-features = false} [target.'cfg(not(target_arch = "wasm32"))'.dependencies] diff --git a/examples/terrain/src/main.rs b/examples/terrain/src/main.rs index b33591d46..d0c63e94d 100644 --- a/examples/terrain/src/main.rs +++ b/examples/terrain/src/main.rs @@ -232,7 +232,7 @@ pub async fn run() { camera.target().y + y_new - camera.position().y, camera.target().z, ); - let up = *camera.up(); + let up = camera.up(); camera.set_view(vec3(p.x, y_new, p.y), target, up); terrain.set_center(p); diff --git a/examples/text/src/main.rs b/examples/text/src/main.rs index e330015cf..841574b85 100644 --- a/examples/text/src/main.rs +++ b/examples/text/src/main.rs @@ -72,7 +72,7 @@ pub fn main() { let right = camera.right_direction(); let up = right.cross(camera.view_direction()); let delta = -right * speed * delta.0 + up * speed * delta.1; - camera.translate(&delta); + camera.translate(delta); } } _ => {} diff --git a/examples/texture/Cargo.toml b/examples/texture/Cargo.toml index a2d5b6b71..42368695a 100644 --- a/examples/texture/Cargo.toml +++ b/examples/texture/Cargo.toml @@ -8,8 +8,8 @@ edition = "2021" crate-type = ["cdylib"] [dependencies] -three-d = { path = "../../" } -three-d-asset = {version = "0.7",features = ["obj", "png", "jpeg", "http"] } +three-d = { path = "../../", features=["egui-gui"] } +three-d-asset = {version = "0.8",features = ["obj", "png", "jpeg", "http"] } [target.'cfg(not(target_arch = "wasm32"))'.dependencies] tokio = { version = "1", features = ["macros", "rt-multi-thread"] } diff --git a/examples/texture/src/main.rs b/examples/texture/src/main.rs index e75250696..8539000c7 100644 --- a/examples/texture/src/main.rs +++ b/examples/texture/src/main.rs @@ -18,14 +18,14 @@ pub async fn run() { let mut camera = Camera::new_perspective( window.viewport(), - vec3(4.0, 1.5, 4.0), + vec3(0.0, 1.0, 20.0), vec3(0.0, 1.0, 0.0), vec3(0.0, 1.0, 0.0), degrees(45.0), 0.1, 1000.0, ); - let mut control = OrbitControl::new(*camera.target(), 1.0, 100.0); + let mut control = OrbitControl::new(camera.target(), 1.0, 100.0); let mut loaded = three_d_asset::io::load_async(&[ "examples/assets/skybox_evening/right.jpg", @@ -35,6 +35,7 @@ pub async fn run() { "examples/assets/skybox_evening/back.jpg", "examples/assets/Skybox_example.png", "examples/assets/PenguinBaseMesh.obj", + "examples/assets/checkerboard.jpg", ]) .await .unwrap(); @@ -71,28 +72,123 @@ pub async fn run() { m.material.render_states.cull = Cull::Back; }); + // Ground + let mut cpu_texture: CpuTexture = loaded.deserialize("checkerboard").unwrap(); + cpu_texture.data.to_color(); + let mut ground_geometry = CpuMesh::square(); + ground_geometry + .uvs + .as_mut() + .unwrap() + .iter_mut() + .for_each(|uv| *uv = 5.0 * (*uv - vec2(0.4, 0.4))); + let mut ground_object = Gm::new( + Mesh::new(&context, &ground_geometry), + ColorMaterial::default(), + ); + ground_object.set_transformation( + Mat4::from_translation(vec3(0.0, -1.0, 0.0)) + * Mat4::from_angle_x(degrees(-90.0)) + * Mat4::from_scale(20.0), + ); + // Lights let ambient = AmbientLight::new(&context, 0.4, Srgba::WHITE); - let directional = DirectionalLight::new(&context, 2.0, Srgba::WHITE, &vec3(0.0, -1.0, -1.0)); + let directional = DirectionalLight::new(&context, 2.0, Srgba::WHITE, vec3(0.0, -1.0, -1.0)); + + // GUI + let mut gui = three_d::GUI::new(&context); + let mut max_ratio = 1; + let mut max_levels = 8; + let mut mipmap_filter = Interpolation::Nearest; + let mut min_filter = Interpolation::Nearest; + let mut mag_filter = Interpolation::Nearest; + let mut wrap_s = Wrapping::Repeat; + let mut wrap_t = Wrapping::Repeat; // main loop window.render_loop(move |mut frame_input| { - let mut redraw = frame_input.first_frame; - redraw |= camera.set_viewport(frame_input.viewport); - redraw |= control.handle_events(&mut camera, &mut frame_input.events); + let mut panel_width = 0.0; + gui.update( + &mut frame_input.events, + frame_input.accumulated_time, + frame_input.viewport, + frame_input.device_pixel_ratio, + |gui_context| { + use three_d::egui::*; + SidePanel::left("side_panel").show(gui_context, |ui| { + ui.heading("Debug panel for ground texture"); + ui.label("Wrap s"); + ui.radio_value(&mut wrap_s, Wrapping::ClampToEdge, "ClampToEdge"); + ui.radio_value(&mut wrap_s, Wrapping::MirroredRepeat, "MirroredRepeat"); + ui.radio_value(&mut wrap_s, Wrapping::Repeat, "Repeat"); + ui.label("Wrap t"); + ui.radio_value(&mut wrap_t, Wrapping::ClampToEdge, "ClampToEdge"); + ui.radio_value(&mut wrap_t, Wrapping::MirroredRepeat, "MirroredRepeat"); + ui.radio_value(&mut wrap_t, Wrapping::Repeat, "Repeat"); + ui.label("Min filter"); + ui.radio_value(&mut min_filter, Interpolation::Nearest, "Nearest"); + ui.radio_value(&mut min_filter, Interpolation::Linear, "Linear"); + ui.label("Mag filter"); + ui.radio_value(&mut mag_filter, Interpolation::Nearest, "Nearest"); + ui.radio_value(&mut mag_filter, Interpolation::Linear, "Linear"); + ui.label("Mipmap settings"); + ui.add(Slider::new(&mut max_levels, 1..=8).text("Max levels")); + ui.add(Slider::new(&mut max_ratio, 1..=8).text("Max ratio of anisotropy")); + ui.radio_value(&mut mipmap_filter, Interpolation::Nearest, "Nearest"); + ui.radio_value(&mut mipmap_filter, Interpolation::Linear, "Linear"); + }); + panel_width = gui_context.used_rect().width(); + }, + ); + + let viewport = Viewport { + x: (panel_width * frame_input.device_pixel_ratio) as i32, + y: 0, + width: frame_input.viewport.width + - (panel_width * frame_input.device_pixel_ratio) as u32, + height: frame_input.viewport.height, + }; + camera.set_viewport(viewport); + control.handle_events(&mut camera, &mut frame_input.events); + + // Update ground texture texture settings + let mipmap = Some(Mipmap { + max_ratio, + max_levels, + filter: mipmap_filter, + }); + if cpu_texture.mipmap != mipmap + || cpu_texture.min_filter != min_filter + || cpu_texture.mag_filter != mag_filter + || cpu_texture.wrap_s != wrap_s + || cpu_texture.wrap_t != wrap_t + { + cpu_texture.min_filter = min_filter; + cpu_texture.mag_filter = mag_filter; + cpu_texture.mipmap = mipmap; + cpu_texture.wrap_s = wrap_s; + cpu_texture.wrap_t = wrap_t; + ground_object.material.texture = + Some(Texture2DRef::from_cpu_texture(&context, &cpu_texture)); + } // draw - if redraw { - frame_input.screen().clear(ClearState::default()).render( + frame_input + .screen() + .clear(ClearState::default()) + .render( &camera, - penguin.into_iter().chain(&box_object).chain(&skybox), + penguin + .into_iter() + .chain(&box_object) + .chain(&ground_object) + .chain(&skybox), &[&ambient, &directional], - ); - } + ) + .write(|| gui.render()) + .unwrap(); - FrameOutput { - swap_buffers: redraw, - ..Default::default() - } + FrameOutput::default() }); } diff --git a/examples/triangle_core/Cargo.toml b/examples/triangle_core/Cargo.toml index d9132c3e1..0234258bd 100644 --- a/examples/triangle_core/Cargo.toml +++ b/examples/triangle_core/Cargo.toml @@ -8,7 +8,7 @@ crate-type = ["cdylib"] [dependencies] three-d = { path = "../../" } -three-d-asset = {version = "0.7"} +three-d-asset = {version = "0.8"} [target.'cfg(target_arch = "wasm32")'.dependencies] log = "0.4" diff --git a/examples/volume/Cargo.toml b/examples/volume/Cargo.toml index f7baa0b12..b9276ab11 100644 --- a/examples/volume/Cargo.toml +++ b/examples/volume/Cargo.toml @@ -9,7 +9,7 @@ crate-type = ["cdylib"] [dependencies] three-d = { path = "../../", features=["egui-gui"] } -three-d-asset = {version = "0.7",features = ["vol", "http"] } +three-d-asset = {version = "0.8",features = ["vol", "http"] } [target.'cfg(not(target_arch = "wasm32"))'.dependencies] tokio = { version = "1", features = ["macros", "rt-multi-thread"] } diff --git a/examples/volume/src/main.rs b/examples/volume/src/main.rs index 9282e4f87..d0c65b71d 100644 --- a/examples/volume/src/main.rs +++ b/examples/volume/src/main.rs @@ -25,7 +25,7 @@ pub async fn run() { 0.1, 1000.0, ); - let mut control = OrbitControl::new(*camera.target(), 0.25, 100.0); + let mut control = OrbitControl::new(camera.target(), 0.25, 100.0); // Source: https://web.cs.ucdavis.edu/~okreylos/PhDStudies/Spring2000/ECS277/DataSets.html let cpu_voxel_grid = three_d_asset::io::load_async(&["examples/assets/Skull.vol"]) @@ -36,8 +36,8 @@ pub async fn run() { let mut voxel_grid = VoxelGrid::::new(&context, &cpu_voxel_grid); let ambient = AmbientLight::new(&context, 0.4, Srgba::WHITE); - let directional1 = DirectionalLight::new(&context, 2.0, Srgba::WHITE, &vec3(-1.0, -1.0, -1.0)); - let directional2 = DirectionalLight::new(&context, 2.0, Srgba::WHITE, &vec3(1.0, 1.0, 1.0)); + let directional1 = DirectionalLight::new(&context, 2.0, Srgba::WHITE, vec3(-1.0, -1.0, -1.0)); + let directional2 = DirectionalLight::new(&context, 2.0, Srgba::WHITE, vec3(1.0, 1.0, 1.0)); // main loop let mut gui = three_d::GUI::new(&context); diff --git a/examples/winit_window/src/main.rs b/examples/winit_window/src/main.rs index 3e4274673..fe8af5bba 100644 --- a/examples/winit_window/src/main.rs +++ b/examples/winit_window/src/main.rs @@ -40,7 +40,7 @@ pub fn main() { 0.1, 10.0, ); - let mut control = OrbitControl::new(*camera.target(), 1.0, 100.0); + let mut control = OrbitControl::new(camera.target(), 1.0, 100.0); // Create model let mut model = Gm::new( diff --git a/examples/wireframe/Cargo.toml b/examples/wireframe/Cargo.toml index c3b6f4a0b..6ccaa999c 100644 --- a/examples/wireframe/Cargo.toml +++ b/examples/wireframe/Cargo.toml @@ -9,7 +9,7 @@ crate-type = ["cdylib"] [dependencies] three-d = { path = "../../" } -three-d-asset = {version = "0.7",features = ["obj", "http"] } +three-d-asset = {version = "0.8",features = ["obj", "http"] } [target.'cfg(not(target_arch = "wasm32"))'.dependencies] tokio = { version = "1", features = ["macros", "rt-multi-thread"] } diff --git a/examples/wireframe/src/main.rs b/examples/wireframe/src/main.rs index a4b9c15a0..f69ccd334 100644 --- a/examples/wireframe/src/main.rs +++ b/examples/wireframe/src/main.rs @@ -27,7 +27,7 @@ pub async fn run() { 0.1, 1000.0, ); - let mut control = OrbitControl::new(*camera.target(), 0.1 * scene_radius, 100.0 * scene_radius); + let mut control = OrbitControl::new(camera.target(), 0.1 * scene_radius, 100.0 * scene_radius); let mut loaded = three_d_asset::io::load_async(&["examples/assets/suzanne.obj"]) .await @@ -35,7 +35,7 @@ pub async fn run() { let mut cpu_mesh: CpuMesh = loaded.deserialize("suzanne.obj").unwrap(); cpu_mesh - .transform(&Mat4::from_translation(vec3(0.0, 2.0, 0.0))) + .transform(Mat4::from_translation(vec3(0.0, 2.0, 0.0))) .unwrap(); let mut model_material = PhysicalMaterial::new_opaque( &context, @@ -60,7 +60,7 @@ pub async fn run() { wireframe_material.render_states.cull = Cull::Back; let mut cylinder = CpuMesh::cylinder(10); cylinder - .transform(&Mat4::from_nonuniform_scale(1.0, 0.007, 0.007)) + .transform(Mat4::from_nonuniform_scale(1.0, 0.007, 0.007)) .unwrap(); let edges = Gm::new( InstancedMesh::new(&context, &edge_transformations(&cpu_mesh), &cylinder), @@ -68,15 +68,15 @@ pub async fn run() { ); let mut sphere = CpuMesh::sphere(8); - sphere.transform(&Mat4::from_scale(0.015)).unwrap(); + sphere.transform(Mat4::from_scale(0.015)).unwrap(); let vertices = Gm::new( InstancedMesh::new(&context, &vertex_transformations(&cpu_mesh), &sphere), wireframe_material, ); let ambient = AmbientLight::new(&context, 0.7, Srgba::WHITE); - let directional0 = DirectionalLight::new(&context, 2.0, Srgba::WHITE, &vec3(-1.0, -1.0, -1.0)); - let directional1 = DirectionalLight::new(&context, 2.0, Srgba::WHITE, &vec3(1.0, 1.0, 1.0)); + let directional0 = DirectionalLight::new(&context, 2.0, Srgba::WHITE, vec3(-1.0, -1.0, -1.0)); + let directional1 = DirectionalLight::new(&context, 2.0, Srgba::WHITE, vec3(1.0, 1.0, 1.0)); // main loop window.render_loop(move |mut frame_input| { diff --git a/src/core/texture.rs b/src/core/texture.rs index abe499bd1..c8c17c8f0 100644 --- a/src/core/texture.rs +++ b/src/core/texture.rs @@ -39,7 +39,8 @@ pub(in crate::core) use depth_texture2d_multisample::*; use data_type::*; pub use three_d_asset::texture::{ - Interpolation, Texture2D as CpuTexture, Texture3D as CpuTexture3D, TextureData, Wrapping, + Interpolation, Mipmap, Texture2D as CpuTexture, Texture3D as CpuTexture3D, TextureData, + Wrapping, }; /// The basic data type used for each channel of each pixel in a texture. @@ -282,19 +283,22 @@ fn set_parameters( target: u32, min_filter: Interpolation, mag_filter: Interpolation, - mip_map_filter: Option, + mipmap: Option, wrap_s: Wrapping, wrap_t: Wrapping, wrap_r: Option, ) { unsafe { - match mip_map_filter { + match mipmap { None => context.tex_parameter_i32( target, crate::context::TEXTURE_MIN_FILTER, interpolation_from(min_filter), ), - Some(Interpolation::Nearest) => { + Some(Mipmap { + filter: Interpolation::Nearest, + .. + }) => { if min_filter == Interpolation::Nearest { context.tex_parameter_i32( target, @@ -309,7 +313,10 @@ fn set_parameters( ) } } - Some(Interpolation::Linear) => { + Some(Mipmap { + filter: Interpolation::Linear, + .. + }) => { if min_filter == Interpolation::Nearest { context.tex_parameter_i32( target, @@ -326,6 +333,25 @@ fn set_parameters( } _ => panic!("Can only sample textures using 'NEAREST' or 'LINEAR' interpolation"), } + if let Some(Mipmap { max_ratio, .. }) = mipmap { + let extensions = context.supported_extensions(); + // Desktop + if extensions.contains("GL_ARB_texture_filter_anisotropic") || + extensions.contains("GL_EXT_texture_filter_anisotropic") || + // Web + extensions.contains("EXT_texture_filter_anisotropic") + { + let max_ratio = max_ratio.min( + context.get_parameter_i32(crate::context::MAX_TEXTURE_MAX_ANISOTROPY_EXT) + as u32, + ); + context.tex_parameter_i32( + target, + crate::context::TEXTURE_MAX_ANISOTROPY_EXT, + max_ratio as i32, + ); + } + } context.tex_parameter_i32( target, crate::context::TEXTURE_MAG_FILTER, @@ -348,7 +374,7 @@ fn set_parameters( } fn calculate_number_of_mip_maps( - mip_map_filter: Option, + mipmap: Option, width: u32, height: u32, depth: Option, @@ -360,13 +386,13 @@ fn calculate_number_of_mip_maps( return 1; } - if mip_map_filter.is_some() { + if let Some(Mipmap { max_levels, .. }) = mipmap { let max_size = width.max(height).max(depth.unwrap_or(0)); if max_size < 2 { 1 } else { let power_of_two = max_size.next_power_of_two(); - (power_of_two as f64).log2() as u32 + ((power_of_two as f64).log2() as u32).min(max_levels.max(1)) } } else { 1 diff --git a/src/core/texture/texture2d.rs b/src/core/texture/texture2d.rs index 2f557187a..5fb66b0a7 100644 --- a/src/core/texture/texture2d.rs +++ b/src/core/texture/texture2d.rs @@ -46,7 +46,7 @@ impl Texture2D { cpu_texture.height, cpu_texture.min_filter, cpu_texture.mag_filter, - cpu_texture.mip_map_filter, + cpu_texture.mipmap, cpu_texture.wrap_s, cpu_texture.wrap_t, ); @@ -67,13 +67,12 @@ impl Texture2D { height: u32, min_filter: Interpolation, mag_filter: Interpolation, - mip_map_filter: Option, + mipmap: Option, wrap_s: Wrapping, wrap_t: Wrapping, ) -> Self { let id = generate(context); - let number_of_mip_maps = - calculate_number_of_mip_maps::(mip_map_filter, width, height, None); + let number_of_mip_maps = calculate_number_of_mip_maps::(mipmap, width, height, None); let texture = Self { context: context.clone(), id, @@ -91,7 +90,7 @@ impl Texture2D { if number_of_mip_maps == 1 { None } else { - mip_map_filter + mipmap }, wrap_s, wrap_t, diff --git a/src/core/texture/texture2d_array.rs b/src/core/texture/texture2d_array.rs index eee992dfe..871c8908f 100644 --- a/src/core/texture/texture2d_array.rs +++ b/src/core/texture/texture2d_array.rs @@ -136,7 +136,7 @@ impl Texture2DArray { data.len() as u32, cpu_texture.min_filter, cpu_texture.mag_filter, - cpu_texture.mip_map_filter, + cpu_texture.mipmap, cpu_texture.wrap_s, cpu_texture.wrap_t, ); @@ -156,13 +156,12 @@ impl Texture2DArray { depth: u32, min_filter: Interpolation, mag_filter: Interpolation, - mip_map_filter: Option, + mipmap: Option, wrap_s: Wrapping, wrap_t: Wrapping, ) -> Self { let id = generate(context); - let number_of_mip_maps = - calculate_number_of_mip_maps::(mip_map_filter, width, height, None); + let number_of_mip_maps = calculate_number_of_mip_maps::(mipmap, width, height, None); let texture = Self { context: context.clone(), id, @@ -181,7 +180,7 @@ impl Texture2DArray { if number_of_mip_maps == 1 { None } else { - mip_map_filter + mipmap }, wrap_s, wrap_t, diff --git a/src/core/texture/texture3d.rs b/src/core/texture/texture3d.rs index 90cd1db8a..e48a3f1ef 100644 --- a/src/core/texture/texture3d.rs +++ b/src/core/texture/texture3d.rs @@ -47,7 +47,7 @@ impl Texture3D { cpu_texture.depth, cpu_texture.min_filter, cpu_texture.mag_filter, - cpu_texture.mip_map_filter, + cpu_texture.mipmap, cpu_texture.wrap_s, cpu_texture.wrap_t, cpu_texture.wrap_r, @@ -68,14 +68,14 @@ impl Texture3D { depth: u32, min_filter: Interpolation, mag_filter: Interpolation, - mip_map_filter: Option, + mipmap: Option, wrap_s: Wrapping, wrap_t: Wrapping, wrap_r: Wrapping, ) -> Self { let id = generate(context); let number_of_mip_maps = - calculate_number_of_mip_maps::(mip_map_filter, width, height, Some(depth)); + calculate_number_of_mip_maps::(mipmap, width, height, Some(depth)); let texture = Self { context: context.clone(), id, @@ -94,7 +94,7 @@ impl Texture3D { if number_of_mip_maps == 1 { None } else { - mip_map_filter + mipmap }, wrap_s, wrap_t, diff --git a/src/core/texture/texture_cube_map.rs b/src/core/texture/texture_cube_map.rs index 9e65d9d84..7406bd698 100644 --- a/src/core/texture/texture_cube_map.rs +++ b/src/core/texture/texture_cube_map.rs @@ -282,7 +282,7 @@ impl TextureCubeMap { cpu_texture.height, cpu_texture.min_filter, cpu_texture.mag_filter, - cpu_texture.mip_map_filter, + cpu_texture.mipmap, cpu_texture.wrap_s, cpu_texture.wrap_t, wrap_r, @@ -309,14 +309,13 @@ impl TextureCubeMap { height: u32, min_filter: Interpolation, mag_filter: Interpolation, - mip_map_filter: Option, + mipmap: Option, wrap_s: Wrapping, wrap_t: Wrapping, wrap_r: Wrapping, ) -> Self { let id = generate(context); - let number_of_mip_maps = - calculate_number_of_mip_maps::(mip_map_filter, width, height, None); + let number_of_mip_maps = calculate_number_of_mip_maps::(mipmap, width, height, None); let texture = Self { context: context.clone(), id, @@ -334,7 +333,7 @@ impl TextureCubeMap { if number_of_mip_maps == 1 { None } else { - mip_map_filter + mipmap }, wrap_s, wrap_t, @@ -453,7 +452,7 @@ impl TextureCubeMap { texture_size, Interpolation::Linear, Interpolation::Linear, - Some(Interpolation::Linear), + Some(Mipmap::default()), Wrapping::ClampToEdge, Wrapping::ClampToEdge, Wrapping::ClampToEdge, diff --git a/src/renderer.rs b/src/renderer.rs index cf25ca672..da0851a11 100644 --- a/src/renderer.rs +++ b/src/renderer.rs @@ -93,7 +93,7 @@ macro_rules! impl_render_target_extensions_body { ) -> &Self { let (mut deferred_objects, mut forward_objects): (Vec<_>, Vec<_>) = objects .into_iter() - .filter(|o| camera.in_frustum(&o.aabb())) + .filter(|o| camera.in_frustum(o.aabb())) .partition(|o| o.material_type() == MaterialType::Deferred); // Deferred @@ -197,7 +197,7 @@ macro_rules! impl_render_target_extensions_body { self.write_partially::(scissor_box, || { for geometry in geometries .into_iter() - .filter(|o| camera.in_frustum(&o.aabb())) + .filter(|o| camera.in_frustum(o.aabb())) { render_with_material(&self.context, camera, geometry, material, lights); } @@ -248,7 +248,7 @@ macro_rules! impl_render_target_extensions_body { self.write_partially::(scissor_box, || { for geometry in geometries .into_iter() - .filter(|o| camera.in_frustum(&o.aabb())) + .filter(|o| camera.in_frustum(o.aabb())) { render_with_effect( &self.context, diff --git a/src/renderer/control/first_person_control.rs b/src/renderer/control/first_person_control.rs index df719e5a6..9aed7f1f9 100644 --- a/src/renderer/control/first_person_control.rs +++ b/src/renderer/control/first_person_control.rs @@ -38,7 +38,7 @@ impl FirstPersonControl { Event::MouseWheel { delta, handled, .. } => { if !*handled { let v = camera.view_direction() * self.speed * delta.1; - camera.translate(&v); + camera.translate(v); *handled = true; change = true; } diff --git a/src/renderer/control/fly_control.rs b/src/renderer/control/fly_control.rs index 6face8aa1..5415f3ba0 100644 --- a/src/renderer/control/fly_control.rs +++ b/src/renderer/control/fly_control.rs @@ -37,7 +37,7 @@ impl FlyControl { let right = camera.right_direction(); let up = right.cross(camera.view_direction()); camera.translate( - &(-right * delta.0 * self.speed + up * delta.1 * self.speed), + -right * delta.0 * self.speed + up * delta.1 * self.speed, ); *handled = true; change = true; @@ -47,7 +47,7 @@ impl FlyControl { Event::MouseWheel { delta, handled, .. } => { if !*handled { let v = camera.view_direction() * self.speed * delta.1; - camera.translate(&v); + camera.translate(v); *handled = true; change = true; } diff --git a/src/renderer/control/free_orbit_control.rs b/src/renderer/control/free_orbit_control.rs index 61b386268..9ee65cd32 100644 --- a/src/renderer/control/free_orbit_control.rs +++ b/src/renderer/control/free_orbit_control.rs @@ -36,8 +36,8 @@ impl FreeOrbitControl { } => { if !*handled { if Some(MouseButton::Left) == *button { - let speed = 0.01 * self.target.distance(*camera.position()) + 0.001; - camera.rotate_around(&self.target, speed * delta.0, speed * delta.1); + let speed = 0.01 * self.target.distance(camera.position()) + 0.001; + camera.rotate_around(self.target, speed * delta.0, speed * delta.1); *handled = true; change = true; } @@ -45,9 +45,9 @@ impl FreeOrbitControl { } Event::MouseWheel { delta, handled, .. } => { if !*handled { - let speed = 0.01 * self.target.distance(*camera.position()) + 0.001; + let speed = 0.01 * self.target.distance(camera.position()) + 0.001; camera.zoom_towards( - &self.target, + self.target, speed * delta.1, self.min_distance, self.max_distance, @@ -58,9 +58,9 @@ impl FreeOrbitControl { } Event::PinchGesture { delta, handled, .. } => { if !*handled { - let speed = self.target.distance(*camera.position()) + 0.1; + let speed = self.target.distance(camera.position()) + 0.1; camera.zoom_towards( - &self.target, + self.target, speed * *delta, self.min_distance, self.max_distance, diff --git a/src/renderer/control/orbit_control.rs b/src/renderer/control/orbit_control.rs index 1ee85a3cc..ae55c5c7b 100644 --- a/src/renderer/control/orbit_control.rs +++ b/src/renderer/control/orbit_control.rs @@ -36,9 +36,9 @@ impl OrbitControl { } => { if !*handled { if Some(MouseButton::Left) == *button { - let speed = 0.01 * self.target.distance(*camera.position()) + 0.001; + let speed = 0.01 * self.target.distance(camera.position()) + 0.001; camera.rotate_around_with_fixed_up( - &self.target, + self.target, speed * delta.0, speed * delta.1, ); @@ -49,9 +49,9 @@ impl OrbitControl { } Event::MouseWheel { delta, handled, .. } => { if !*handled { - let speed = 0.01 * self.target.distance(*camera.position()) + 0.001; + let speed = 0.01 * self.target.distance(camera.position()) + 0.001; camera.zoom_towards( - &self.target, + self.target, speed * delta.1, self.min_distance, self.max_distance, @@ -62,9 +62,9 @@ impl OrbitControl { } Event::PinchGesture { delta, handled, .. } => { if !*handled { - let speed = self.target.distance(*camera.position()) + 0.1; + let speed = self.target.distance(camera.position()) + 0.1; camera.zoom_towards( - &self.target, + self.target, speed * *delta, self.min_distance, self.max_distance, diff --git a/src/renderer/geometry/instanced_mesh.rs b/src/renderer/geometry/instanced_mesh.rs index aa8e50043..577a83d74 100644 --- a/src/renderer/geometry/instanced_mesh.rs +++ b/src/renderer/geometry/instanced_mesh.rs @@ -88,9 +88,10 @@ impl InstancedMesh { fn update_aabb(&mut self) { let mut aabb = AxisAlignedBoundingBox::EMPTY; for transformation in self.instances.transformations.iter() { - let mut aabb2 = self.aabb_local; - aabb2.transform(&(transformation * self.transformation)); - aabb.expand_with_aabb(&aabb2); + aabb.expand_with_aabb( + self.aabb_local + .transformed(transformation * self.transformation), + ); } self.aabb = aabb; } @@ -100,7 +101,7 @@ impl InstancedMesh { /// fn update_instance_buffers(&self, camera: Option<&Camera>) { let mut s = self.instance_buffers.write().unwrap(); - let indices = if let Some(position) = camera.map(|c| *c.position()) { + let indices = if let Some(position) = camera.map(|c| c.position()) { s.1 = position; // Need to order by using the position. let distances = self @@ -222,7 +223,7 @@ impl Geometry for InstancedMesh { ) { // Check if we need a reorder, this only applies to transparent materials. if render_states.blend != Blend::Disabled - && *camera.position() != self.instance_buffers.read().unwrap().1 + && camera.position() != self.instance_buffers.read().unwrap().1 { self.update_instance_buffers(Some(camera)); } @@ -328,7 +329,7 @@ impl Geometry for InstancedMesh { fn aabb(&self) -> AxisAlignedBoundingBox { let mut aabb = self.aabb; - aabb.transform(&self.current_transformation); + aabb.transform(self.current_transformation); aabb } diff --git a/src/renderer/geometry/line.rs b/src/renderer/geometry/line.rs index 1cf78fad7..8383a36d5 100644 --- a/src/renderer/geometry/line.rs +++ b/src/renderer/geometry/line.rs @@ -21,7 +21,7 @@ impl Line { thickness: f32, ) -> Self { let mut mesh = CpuMesh::square(); - mesh.transform(&(Mat4::from_scale(0.5) * Mat4::from_translation(vec3(1.0, 0.0, 0.0)))) + mesh.transform(Mat4::from_scale(0.5) * Mat4::from_translation(vec3(1.0, 0.0, 0.0))) .unwrap(); let mut line = Self { mesh: Mesh::new(context, &mesh), diff --git a/src/renderer/geometry/mesh.rs b/src/renderer/geometry/mesh.rs index 77f39a4ce..e69495cf5 100644 --- a/src/renderer/geometry/mesh.rs +++ b/src/renderer/geometry/mesh.rs @@ -127,9 +127,7 @@ impl<'a> IntoIterator for &'a Mesh { impl Geometry for Mesh { fn aabb(&self) -> AxisAlignedBoundingBox { - let mut aabb = self.aabb; - aabb.transform(&self.current_transformation); - aabb + self.aabb.transformed(self.current_transformation) } fn animate(&mut self, time: f32) { diff --git a/src/renderer/geometry/rectangle.rs b/src/renderer/geometry/rectangle.rs index 0a3d3eaec..f194c4111 100644 --- a/src/renderer/geometry/rectangle.rs +++ b/src/renderer/geometry/rectangle.rs @@ -23,7 +23,7 @@ impl Rectangle { height: f32, ) -> Self { let mut mesh = CpuMesh::square(); - mesh.transform(&(Mat4::from_scale(0.5))).unwrap(); + mesh.transform(Mat4::from_scale(0.5)).unwrap(); let mut rectangle = Self { mesh: Mesh::new(context, &mesh), width, diff --git a/src/renderer/light/directional_light.rs b/src/renderer/light/directional_light.rs index 5be2bf7df..ce3e0799c 100644 --- a/src/renderer/light/directional_light.rs +++ b/src/renderer/light/directional_light.rs @@ -24,7 +24,7 @@ impl DirectionalLight { context: &Context, intensity: f32, color: Srgba, - direction: &Vec3, + direction: Vec3, ) -> DirectionalLight { DirectionalLight { context: context.clone(), @@ -32,7 +32,7 @@ impl DirectionalLight { shadow_texture: None, intensity, color, - direction: *direction, + direction, } } @@ -61,15 +61,15 @@ impl DirectionalLight { let viewport = Viewport::new_at_origo(texture_size, texture_size); let mut aabb = AxisAlignedBoundingBox::EMPTY; for geometry in geometries.clone() { - aabb.expand_with_aabb(&geometry.aabb()); + aabb.expand_with_aabb(geometry.aabb()); } if aabb.is_empty() { return; } let target = aabb.center(); let position = target - aabb.max().distance(aabb.min()) * self.direction; - let z_far = aabb.distance_max(&position); - let z_near = aabb.distance(&position); + let z_far = aabb.distance_max(position); + let z_near = aabb.distance(position); let frustum_height = aabb.max().distance(aabb.min()); // TODO: more tight fit let shadow_camera = Camera::new_orthographic( viewport, @@ -100,7 +100,7 @@ impl DirectionalLight { .write::(|| { for geometry in geometries .into_iter() - .filter(|g| shadow_camera.in_frustum(&g.aabb())) + .filter(|g| shadow_camera.in_frustum(g.aabb())) { render_with_material( &self.context, diff --git a/src/renderer/light/environment.rs b/src/renderer/light/environment.rs index b9a7aed07..2b11f1744 100644 --- a/src/renderer/light/environment.rs +++ b/src/renderer/light/environment.rs @@ -47,7 +47,7 @@ impl Environment { irradiance_size, Interpolation::Linear, Interpolation::Linear, - Some(Interpolation::Linear), + Some(Mipmap::default()), Wrapping::ClampToEdge, Wrapping::ClampToEdge, Wrapping::ClampToEdge, @@ -77,7 +77,7 @@ impl Environment { prefilter_size, Interpolation::Linear, Interpolation::Linear, - Some(Interpolation::Linear), + Some(Mipmap::default()), Wrapping::ClampToEdge, Wrapping::ClampToEdge, Wrapping::ClampToEdge, diff --git a/src/renderer/light/point_light.rs b/src/renderer/light/point_light.rs index 5299f4b68..da987c5e6 100644 --- a/src/renderer/light/point_light.rs +++ b/src/renderer/light/point_light.rs @@ -21,13 +21,13 @@ impl PointLight { _context: &Context, intensity: f32, color: Srgba, - position: &Vec3, + position: Vec3, attenuation: Attenuation, ) -> PointLight { PointLight { intensity, color, - position: *position, + position, attenuation, } } diff --git a/src/renderer/light/spot_light.rs b/src/renderer/light/spot_light.rs index deb21f679..06ee03029 100644 --- a/src/renderer/light/spot_light.rs +++ b/src/renderer/light/spot_light.rs @@ -30,8 +30,8 @@ impl SpotLight { context: &Context, intensity: f32, color: Srgba, - position: &Vec3, - direction: &Vec3, + position: Vec3, + direction: Vec3, cutoff: impl Into, attenuation: Attenuation, ) -> SpotLight { @@ -40,8 +40,8 @@ impl SpotLight { shadow_texture: None, intensity, color, - position: *position, - direction: *direction, + position, + direction, cutoff: cutoff.into(), attenuation, shadow_matrix: Mat4::identity(), @@ -78,8 +78,8 @@ impl SpotLight { for geometry in geometries.clone() { let aabb = geometry.aabb(); if !aabb.is_empty() { - z_far = z_far.max(aabb.distance_max(&self.position)); - z_near = z_near.min(aabb.distance(&self.position)); + z_far = z_far.max(aabb.distance_max(self.position)); + z_near = z_near.min(aabb.distance(self.position)); } } @@ -114,7 +114,7 @@ impl SpotLight { .write::(|| { for geometry in geometries .into_iter() - .filter(|g| shadow_camera.in_frustum(&g.aabb())) + .filter(|g| shadow_camera.in_frustum(g.aabb())) { render_with_material( &self.context, diff --git a/src/renderer/object/axes.rs b/src/renderer/object/axes.rs index a2c04272c..5a7d097cc 100644 --- a/src/renderer/object/axes.rs +++ b/src/renderer/object/axes.rs @@ -15,7 +15,7 @@ impl Axes { pub fn new(context: &Context, radius: f32, length: f32) -> Self { let mut cpu_mesh = CpuMesh::arrow(0.9, 0.6, 16); cpu_mesh - .transform(&Mat4::from_nonuniform_scale(length, radius, radius)) + .transform(Mat4::from_nonuniform_scale(length, radius, radius)) .unwrap(); let model = Gm::new( InstancedMesh::new( diff --git a/src/renderer/object/imposters.rs b/src/renderer/object/imposters.rs index ded41af3e..7f04f2e3d 100644 --- a/src/renderer/object/imposters.rs +++ b/src/renderer/object/imposters.rs @@ -32,7 +32,7 @@ impl Imposters { objects .clone() .into_iter() - .for_each(|o| aabb.expand_with_aabb(&o.aabb())); + .for_each(|o| aabb.expand_with_aabb(o.aabb())); let mut sprites = Sprites::new(context, positions, Some(vec3(0.0, 1.0, 0.0))); sprites.set_transformation(get_sprite_transform(aabb)); Imposters { @@ -63,7 +63,7 @@ impl Imposters { objects .clone() .into_iter() - .for_each(|o| aabb.expand_with_aabb(&o.aabb())); + .for_each(|o| aabb.expand_with_aabb(o.aabb())); self.sprites.set_transformation(get_sprite_transform(aabb)); self.material .update(aabb, objects, lights, max_texture_size); diff --git a/src/renderer/object/voxel_grid.rs b/src/renderer/object/voxel_grid.rs index a3b1f6cea..9d2393e13 100644 --- a/src/renderer/object/voxel_grid.rs +++ b/src/renderer/object/voxel_grid.rs @@ -14,7 +14,7 @@ impl VoxelGrid { /// pub fn new(context: &Context, cpu_voxel_grid: &CpuVoxelGrid) -> Self { let mut cube = CpuMesh::cube(); - cube.transform(&Mat4::from_nonuniform_scale( + cube.transform(Mat4::from_nonuniform_scale( 0.5 * cpu_voxel_grid.size.x, 0.5 * cpu_voxel_grid.size.y, 0.5 * cpu_voxel_grid.size.z,