diff --git a/examples/anim.rs b/examples/anim.rs index 84bc998..36d2702 100644 --- a/examples/anim.rs +++ b/examples/anim.rs @@ -87,7 +87,7 @@ fn make_indices(meta: &[u16]) -> Vec<[u32; 3]> { fn main() { let mut win = three::Window::new("Three-rs mesh blending example"); - let cam = win.factory.perspective_camera(60.0, 1.0 .. 1000.0); + let cam = win.factory.perspective_camera(60.0, 1.0..1000.0); cam.look_at( [100.0, 0.0, 100.0], [0.0, 0.0, 30.0], @@ -103,17 +103,16 @@ fn main() { faces: make_indices(INDICES), shapes: V_FLY .iter() - .map(|data| { - three::Shape { - vertices: make_vertices(data), - .. three::Shape::default() - } + .map(|data| three::Shape { + vertices: make_vertices(data), + ..three::Shape::default() }) .collect(), ..three::Geometry::default() }; - let mesh = win.factory + let mesh = win + .factory .mesh_dynamic(geom, three::material::Wireframe { color: 0xFFFFFF }); win.scene.add(&mesh); @@ -129,11 +128,7 @@ fn main() { if id0 == V_FLY.len() { id0 = 0; } - id1 = if id0 + 1 < V_FLY.len() { - id0 + 1 - } else { - 0 - }; + id1 = if id0 + 1 < V_FLY.len() { id0 + 1 } else { 0 }; timer.reset(); } win.render(&cam); diff --git a/examples/aviator/main.rs b/examples/aviator/main.rs index 7dba106..0b84f47 100644 --- a/examples/aviator/main.rs +++ b/examples/aviator/main.rs @@ -25,7 +25,7 @@ fn main() { let mut win = three::Window::new("Three-rs Aviator demo"); win.scene.background = three::Background::Color(COLOR_BACKGROUND); - let cam = win.factory.perspective_camera(60.0, 1.0 .. 1000.0); + let cam = win.factory.perspective_camera(60.0, 1.0..1000.0); cam.set_position([0.0, 100.0, 200.0]); win.scene.add(&cam); @@ -37,7 +37,7 @@ fn main() { let mut dir_light = win.factory.directional_light(0xffffff, 0.9); dir_light.look_at([150.0, 350.0, 350.0], [0.0, 0.0, 0.0], None); let shadow_map = win.factory.shadow_map(2048, 2048); - dir_light.set_shadow(shadow_map, 400.0, 1.0 .. 1000.0); + dir_light.set_shadow(shadow_map, 400.0, 1.0..1000.0); win.scene.add(&dir_light); let ambient_light = win.factory.ambient_light(0xdc8874, 0.5); win.scene.add(&ambient_light); diff --git a/examples/aviator/plane.rs b/examples/aviator/plane.rs index f859f87..34dd5fb 100644 --- a/examples/aviator/plane.rs +++ b/examples/aviator/plane.rs @@ -99,11 +99,7 @@ impl AirPlane { } } - pub fn update( - &mut self, - time: f32, - target: mint::Point2, - ) { + pub fn update(&mut self, time: f32, target: mint::Point2) { let q = Quaternion::from_angle_x(Rad(0.3 * time)); self.propeller_group.set_orientation(q); self.group diff --git a/examples/aviator/sky.rs b/examples/aviator/sky.rs index 3da0ba7..5b4d3e9 100644 --- a/examples/aviator/sky.rs +++ b/examples/aviator/sky.rs @@ -7,16 +7,12 @@ use three::{self, Object}; use COLOR_WHITE; - pub struct Sky { pub group: three::Group, } impl Sky { - fn make_cloud( - rng: &mut R, - factory: &mut three::Factory, - ) -> three::Group { + fn make_cloud(rng: &mut R, factory: &mut three::Factory) -> three::Group { let group = factory.group(); let geo = three::Geometry::cuboid(20.0, 20.0, 20.0); let material = three::material::Lambert { @@ -24,7 +20,7 @@ impl Sky { flat: true, }; let template = factory.mesh(geo, material.clone()); - for i in 0i32 .. rng.gen_range(3, 6) { + for i in 0i32..rng.gen_range(3, 6) { let m = factory.mesh_instance(&template); let rot = cgmath::Quaternion::::new(rng.gen(), rng.gen(), rng.gen(), rng.gen()); let q = rot.normalize(); @@ -42,14 +38,11 @@ impl Sky { group } - pub fn new( - rng: &mut R, - factory: &mut three::Factory, - ) -> Self { + pub fn new(rng: &mut R, factory: &mut three::Factory) -> Self { let group = factory.group(); let num = 20i32; let step_angle = PI * 2.0 / num as f32; - for i in 0 .. num { + for i in 0..num { let cloud = Self::make_cloud(rng, factory); let angle = cgmath::Rad(i as f32 * step_angle); let dist = rng.gen_range(750.0, 950.0); diff --git a/examples/gltf-morph-targets.rs b/examples/gltf-morph-targets.rs index 19d1c51..c7b3b2c 100644 --- a/examples/gltf-morph-targets.rs +++ b/examples/gltf-morph-targets.rs @@ -9,7 +9,10 @@ fn main() { window.scene.add(&light); window.scene.background = three::Background::Color(0xC6F0FF); - let default = concat!(env!("CARGO_MANIFEST_DIR"), "/test_data/AnimatedMorphCube/AnimatedMorphCube.gltf"); + let default = concat!( + env!("CARGO_MANIFEST_DIR"), + "/test_data/AnimatedMorphCube/AnimatedMorphCube.gltf" + ); let path = std::env::args().nth(1).unwrap_or(default.into()); // Load the contents of the glTF files. Scenes loaded from the file are returned as @@ -28,7 +31,7 @@ fn main() { // Create a camera with which to render the scene, and control it with the built-in // orbit controller, set to orbit the model. - let camera = window.factory.perspective_camera(60.0, 0.1 .. 20.0); + let camera = window.factory.perspective_camera(60.0, 0.1..20.0); let mut controls = three::controls::Orbit::builder(&camera) .position([-3.0, 3.0, -3.0]) .up([0.0, 1.0, 0.0]) diff --git a/examples/gltf-node-animation.rs b/examples/gltf-node-animation.rs index dccb878..71b3f99 100644 --- a/examples/gltf-node-animation.rs +++ b/examples/gltf-node-animation.rs @@ -9,7 +9,10 @@ fn main() { window.scene.add(&light); window.scene.background = three::Background::Color(0xC6F0FF); - let default = concat!(env!("CARGO_MANIFEST_DIR"), "/test_data/BoxAnimated/BoxAnimated.gltf"); + let default = concat!( + env!("CARGO_MANIFEST_DIR"), + "/test_data/BoxAnimated/BoxAnimated.gltf" + ); let path = std::env::args().nth(1).unwrap_or(default.into()); // Load the contents of the glTF files. Scenes loaded from the file are returned as @@ -28,7 +31,7 @@ fn main() { // Create a camera with which to render the scene, and control it with the built-in // orbit controller, set to orbit the model. - let camera = window.factory.perspective_camera(60.0, 0.1 .. 100.0); + let camera = window.factory.perspective_camera(60.0, 0.1..100.0); let mut controls = three::controls::Orbit::builder(&camera) .position([3.0, 3.0, 3.0]) .target([0.0, 1.0, 0.0]) diff --git a/examples/gltf-pbr-shader.rs b/examples/gltf-pbr-shader.rs index cc7c526..2a357ec 100644 --- a/examples/gltf-pbr-shader.rs +++ b/examples/gltf-pbr-shader.rs @@ -1,9 +1,6 @@ extern crate three; -use three::{ - camera::Camera, - Object, -}; +use three::{camera::Camera, Object}; fn main() { let mut win = three::Window::new("Three-rs glTF example"); @@ -12,7 +9,10 @@ fn main() { win.scene.add(&light); win.scene.background = three::Background::Color(0xC6F0FF); - let default = concat!(env!("CARGO_MANIFEST_DIR"), "/test_data/Lantern/Lantern.gltf"); + let default = concat!( + env!("CARGO_MANIFEST_DIR"), + "/test_data/Lantern/Lantern.gltf" + ); let path = std::env::args().nth(1).unwrap_or(default.into()); println!("Loading {:?} (this may take a while)", path); @@ -33,7 +33,7 @@ fn main() { // If we didn't find a camera in the glTF scene, create a default one to use. let cam = cam.unwrap_or_else(|| { - let default = win.factory.perspective_camera(60.0, 0.001 .. 100.0); + let default = win.factory.perspective_camera(60.0, 0.001..100.0); win.scene.add(&default); default }); @@ -52,10 +52,7 @@ fn main() { // Determine the current position of the camera so that we can use it to initialize the // camera controller. - let init = win.scene - .sync_guard() - .resolve_world(&cam) - .transform; + let init = win.scene.sync_guard().resolve_world(&cam).transform; // Create a first person camera controller, starting at the camera's current position. let mut controls = three::controls::FirstPerson::builder(&cam) diff --git a/examples/gltf-vertex-skinning.rs b/examples/gltf-vertex-skinning.rs index fd50c87..2182a48 100644 --- a/examples/gltf-vertex-skinning.rs +++ b/examples/gltf-vertex-skinning.rs @@ -9,7 +9,10 @@ fn main() { window.scene.add(&light); window.scene.background = three::Background::Color(0xC6F0FF); - let default = concat!(env!("CARGO_MANIFEST_DIR"), "/test_data/BrainStem/BrainStem.gltf"); + let default = concat!( + env!("CARGO_MANIFEST_DIR"), + "/test_data/BrainStem/BrainStem.gltf" + ); let path = std::env::args().nth(1).unwrap_or(default.into()); // Load the contents of the glTF files. Scenes loaded from the file are returned as @@ -28,7 +31,7 @@ fn main() { // Create a camera with which to render the scene, and control it with the built-in // orbit controller, set to orbit the model. - let camera = window.factory.perspective_camera(45.0, 0.1 .. 100.0); + let camera = window.factory.perspective_camera(45.0, 0.1..100.0); let mut controls = three::controls::Orbit::builder(&camera) .position([0.0, 3.0, -1.0]) .target([0.0, 0.0, -1.0]) diff --git a/examples/group.rs b/examples/group.rs index a22fd40..86775be 100644 --- a/examples/group.rs +++ b/examples/group.rs @@ -46,13 +46,11 @@ fn create_cubes( mat_id: usize, lev_id: usize, } - let mut stack = vec![ - Stack { - parent_id: 0, - mat_id: 1, - lev_id: 1, - }, - ]; + let mut stack = vec![Stack { + parent_id: 0, + mat_id: 1, + lev_id: 1, + }]; let axis = [ Vector3::unit_z(), @@ -61,13 +59,15 @@ fn create_cubes( Vector3::unit_y(), -Vector3::unit_y(), ]; - let children: Vec<_> = axis.iter() + let children: Vec<_> = axis + .iter() .map(|&axe| { Decomposed { disp: Vector3::new(0.0, 0.0, 1.0), rot: Quaternion::from_axis_angle(axe, Rad::turn_div_4()), scale: 1.0, - }.concat(&Decomposed { + } + .concat(&Decomposed { disp: Vector3::new(0.0, 0.0, 1.0), rot: Quaternion::one(), scale: 0.4, @@ -106,6 +106,7 @@ struct LevelDesc { color: three::Color, speed: f32, // in radians per second } +#[rustfmt::skip] const LEVELS: &[LevelDesc] = &[ LevelDesc { color: 0xffff80, speed: 0.7 }, LevelDesc { color: 0x8080ff, speed: -1.0 }, @@ -120,7 +121,7 @@ fn main() { let mut win = three::Window::new("Three-rs group example"); win.scene.background = three::Background::Color(0x204060); - let cam = win.factory.perspective_camera(60.0, 1.0 .. 100.0); + let cam = win.factory.perspective_camera(60.0, 1.0..100.0); cam.look_at([-1.8, -8.0, 7.0], [0.0, 0.0, 3.5], None); let light = win.factory.point_light(0xffffff, 1.0); @@ -129,7 +130,10 @@ fn main() { let materials = LEVELS .iter() - .map(|l| three::material::Lambert { color: l.color, flat: false }) + .map(|l| three::material::Lambert { + color: l.color, + flat: false, + }) .collect::>(); let levels = LEVELS .iter() diff --git a/examples/lights.rs b/examples/lights.rs index a3a9bdf..b668751 100644 --- a/examples/lights.rs +++ b/examples/lights.rs @@ -4,7 +4,7 @@ use three::Object; fn main() { let mut win = three::Window::new("Three-rs lights example"); - let cam = win.factory.perspective_camera(45.0, 1.0 .. 50.0); + let cam = win.factory.perspective_camera(45.0, 1.0..50.0); cam.look_at([-4.0, 15.0, 10.0], [0.0, 0.0, 2.0], None); let hemisphere_light = win.factory.hemisphere_light(0xffffff, 0x8080ff, 0.5); @@ -15,9 +15,10 @@ fn main() { let mut dir_light = win.factory.directional_light(0xffffff, 0.9); dir_light.look_at([15.0, 35.0, 35.0], [0.0, 0.0, 2.0], None); let shadow_map = win.factory.shadow_map(1024, 1024); - let _debug_shadow = win.renderer + let _debug_shadow = win + .renderer .debug_shadow_quad(&shadow_map, 1, [10, 10], [256, 256]); - dir_light.set_shadow(shadow_map, 40.0, 1.0 .. 200.0); + dir_light.set_shadow(shadow_map, 40.0, 1.0..200.0); let lights: [&three::object::Base; 4] = [ hemisphere_light.as_ref(), diff --git a/examples/materials.rs b/examples/materials.rs index 74e764c..ea09c3c 100644 --- a/examples/materials.rs +++ b/examples/materials.rs @@ -4,7 +4,7 @@ use three::Object; fn main() { let mut win = three::Window::new("Three-rs materials example"); - let cam = win.factory.perspective_camera(75.0, 1.0 .. 50.0); + let cam = win.factory.perspective_camera(75.0, 1.0..50.0); cam.set_position([0.0, 0.0, 10.0]); let light = win.factory.point_light(0xffffff, 0.5); @@ -17,19 +17,23 @@ fn main() { three::material::Basic { color: 0xFFFFFF, map: None, - }.into(), + } + .into(), three::material::Lambert { color: 0xFFFFFF, flat: true, - }.into(), + } + .into(), three::material::Lambert { color: 0xFFFFFF, flat: false, - }.into(), + } + .into(), three::material::Phong { color: 0xFFFFFF, glossiness: 80.0, - }.into(), + } + .into(), three::material::Pbr { base_color_factor: 0xFFFFFF, base_color_alpha: 1.0, @@ -43,7 +47,8 @@ fn main() { emissive_map: None, metallic_roughness_map: None, occlusion_map: None, - }.into(), + } + .into(), ]; let count = materials.len(); diff --git a/examples/mesh-update.rs b/examples/mesh-update.rs index b0c45e0..dfa8071 100644 --- a/examples/mesh-update.rs +++ b/examples/mesh-update.rs @@ -5,7 +5,6 @@ extern crate three; use cgmath::prelude::*; use std::f32::consts::PI; - fn make_tetrahedron_geometry() -> three::Geometry { let vertices = vec![ mint::Point3 { @@ -42,7 +41,7 @@ fn make_tetrahedron_geometry() -> three::Geometry { fn main() { let mut win = three::Window::new("Three-rs Mesh Update Example"); - let cam = win.factory.perspective_camera(60.0, 1.0 .. 10.0); + let cam = win.factory.perspective_camera(60.0, 1.0..10.0); let mut controls = three::controls::Orbit::builder(&cam) .position([0.0, 2.0, -5.0]) .target([0.0, 0.0, 0.0]) diff --git a/examples/obj.rs b/examples/obj.rs index 6027d5b..35dc741 100644 --- a/examples/obj.rs +++ b/examples/obj.rs @@ -8,7 +8,7 @@ fn main() { let obj_path = concat!(env!("CARGO_MANIFEST_DIR"), "/test_data/car.obj"); let path = args.nth(1).unwrap_or(obj_path.into()); let mut win = three::Window::new("Three-rs obj loading example"); - let cam = win.factory.perspective_camera(60.0, 1.0 .. 1000.0); + let cam = win.factory.perspective_camera(60.0, 1.0..1000.0); let mut controls = three::controls::Orbit::builder(&cam) .position([0.0, 2.0, -5.0]) .target([0.0, 0.0, 0.0]) diff --git a/examples/reload.rs b/examples/reload.rs index 2c1385f..e4b6d7b 100644 --- a/examples/reload.rs +++ b/examples/reload.rs @@ -1,8 +1,8 @@ extern crate notify; extern crate three; -use std::{env, fs, io}; use std::sync::mpsc; +use std::{env, fs, io}; use notify::Watcher; use std::path::{Path, PathBuf}; @@ -80,8 +80,7 @@ fn main() { println!("Edit sprite_vs.glsl or sprite_ps.glsl and review."); let mut win = three::Window::new("Three-rs shader reloading example"); - let cam = win.factory - .orthographic_camera([0.0, 0.0], 1.0, -1.0 .. 1.0); + let cam = win.factory.orthographic_camera([0.0, 0.0], 1.0, -1.0..1.0); let (tx, rx) = mpsc::channel(); let mut watcher = notify::watcher(tx, Duration::from_secs(1)).unwrap(); diff --git a/examples/shapes.rs b/examples/shapes.rs index bf3ff97..026783b 100644 --- a/examples/shapes.rs +++ b/examples/shapes.rs @@ -7,7 +7,7 @@ use three::Object; fn main() { let mut win = three::Window::new("Three-rs shapes example"); - let cam = win.factory.perspective_camera(75.0, 1.0 .. 50.0); + let cam = win.factory.perspective_camera(75.0, 1.0..50.0); cam.set_position([0.0, 0.0, 10.0]); let mbox = { diff --git a/examples/sprite.rs b/examples/sprite.rs index 4bf2005..663611c 100644 --- a/examples/sprite.rs +++ b/examples/sprite.rs @@ -21,15 +21,14 @@ impl Animator { self.sprite.set_texel_range(base, self.cell_size); } - fn update( - &mut self, - switch_row: Option, - ) { + fn update(&mut self, switch_row: Option) { if let Some(row) = switch_row { self.timer.reset(); self.current = [0, row]; self.update_uv(); - } else if self.timer.elapsed() >= self.duration && (self.repeat || self.current[0] < self.cell_counts[0]) { + } else if self.timer.elapsed() >= self.duration + && (self.repeat || self.current[0] < self.cell_counts[0]) + { self.timer.reset(); self.current[0] += 1; if self.current[0] < self.cell_counts[0] { @@ -44,8 +43,9 @@ impl Animator { fn main() { let mut win = three::Window::new("Three-rs sprite example"); - let cam = win.factory - .orthographic_camera([0.0, 0.0], 10.0, -10.0 .. 10.0); + let cam = win + .factory + .orthographic_camera([0.0, 0.0], 10.0, -10.0..10.0); let pikachu_path: String = format!("{}/test_data/pikachu_anim.png", env!("CARGO_MANIFEST_DIR")); let pikachu_path_str: &str = pikachu_path.as_str(); diff --git a/examples/text.rs b/examples/text.rs index 88ebae9..87f1e44 100644 --- a/examples/text.rs +++ b/examples/text.rs @@ -7,7 +7,7 @@ fn main() { let center = [0.0, 0.0]; let yextent = 1.0; - let zrange = -1.0 .. 1.0; + let zrange = -1.0..1.0; let camera = window.factory.orthographic_camera(center, yextent, zrange); let deja_vu = window.factory.load_font(format!( diff --git a/examples/tutorial.rs b/examples/tutorial.rs index d870eb2..a6769cf 100644 --- a/examples/tutorial.rs +++ b/examples/tutorial.rs @@ -19,7 +19,7 @@ fn main() { let center = [0.0, 0.0]; let yextent = 1.0; - let zrange = -1.0 .. 1.0; + let zrange = -1.0..1.0; let camera = window.factory.orthographic_camera(center, yextent, zrange); while window.update() { diff --git a/rustfmt.toml b/rustfmt.toml index ad34fa2..dccb320 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1,9 +1,3 @@ -reorder_imports = true -reorder_extern_crates = true -reorder_extern_crates_in_group = true -reorder_imported_names = true -reorder_imports_in_group = true + error_on_line_overflow = false -max_width = 15000 spaces_around_ranges = true -fn_args_density = "Vertical" diff --git a/src/animation.rs b/src/animation.rs index 495f9e2..e7e7932 100644 --- a/src/animation.rs +++ b/src/animation.rs @@ -112,7 +112,6 @@ use object::{Base, Object}; use std::hash::{Hash, Hasher}; use std::sync::mpsc; - /// A target of an animation. pub type Target = Base; @@ -249,10 +248,7 @@ pub struct Action { } impl PartialEq for Action { - fn eq( - &self, - other: &Action, - ) -> bool { + fn eq(&self, other: &Action) -> bool { self.pointer == other.pointer } } @@ -260,10 +256,7 @@ impl PartialEq for Action { impl Eq for Action {} impl Hash for Action { - fn hash( - &self, - state: &mut H, - ) { + fn hash(&self, state: &mut H) { self.pointer.hash(state); } } @@ -335,10 +328,7 @@ pub struct Mixer { } impl Action { - fn send( - &mut self, - operation: Operation, - ) -> &mut Self { + fn send(&mut self, operation: Operation) -> &mut Self { let message = (self.pointer.downgrade(), operation); let _ = self.tx.send(message); self @@ -365,10 +355,7 @@ impl Action { } /// Sets the animation loop mode. - pub fn set_loop_mode( - &mut self, - loop_mode: LoopMode, - ) -> &mut Self { + pub fn set_loop_mode(&mut self, loop_mode: LoopMode) -> &mut Self { self.send(Operation::SetLoopMode(loop_mode)) } } @@ -393,10 +380,7 @@ impl Mixer { } } - fn update_actions( - &mut self, - delta_time: f32, - ) { + fn update_actions(&mut self, delta_time: f32) { for action in self.actions.iter_mut() { action.update(delta_time); } @@ -412,10 +396,7 @@ impl Mixer { /// Spawns a new animation [`Action`] to be updated by this mixer. /// /// [`Action`]: struct.Action.html - pub fn action( - &mut self, - clip: Clip, - ) -> Action { + pub fn action(&mut self, clip: Clip) -> Action { let action_data = ActionData::new(clip); let pointer = self.actions.create(action_data); let tx = self.tx.clone(); @@ -423,10 +404,7 @@ impl Mixer { } /// Updates the actions owned by the mixer. - pub fn update( - &mut self, - delta_time: f32, - ) { + pub fn update(&mut self, delta_time: f32) { self.process_messages(); self.update_actions(delta_time); } @@ -445,10 +423,7 @@ impl ActionData { } /// Updates a single animation action. - fn update( - &mut self, - delta_time: f32, - ) { + fn update(&mut self, delta_time: f32) { if self.paused || !self.enabled { return; } @@ -546,10 +521,7 @@ impl ActionData { } impl Track { - fn frame_at_time( - &self, - t: f32, - ) -> FrameRef { + fn frame_at_time(&self, t: f32) -> FrameRef { if t < self.times[0] { // The clip hasn't started yet. return FrameRef::Unstarted; diff --git a/src/audio.rs b/src/audio.rs index a8a896c..33378df 100644 --- a/src/audio.rs +++ b/src/audio.rs @@ -36,42 +36,27 @@ impl Clip { } /// Passing true enforces looping sound. Defaults to `false`. - pub fn repeat( - &mut self, - enable: bool, - ) { + pub fn repeat(&mut self, enable: bool) { self.repeat = enable; } /// Clip the sound to the desired duration. - pub fn take_duration( - &mut self, - duration: Duration, - ) { + pub fn take_duration(&mut self, duration: Duration) { self.duration = Some(duration); } /// Play sound after desired delay. - pub fn delay( - &mut self, - delay: Duration, - ) { + pub fn delay(&mut self, delay: Duration) { self.delay = Some(delay); } /// Fade in sound in desired duration. - pub fn fade_in( - &mut self, - duration: Duration, - ) { + pub fn fade_in(&mut self, duration: Duration) { self.fade_in = Some(duration); } /// Adjust the playback speed. Defaults to `1.0`. - pub fn speed( - &mut self, - ratio: f32, - ) { + pub fn speed(&mut self, ratio: f32) { self.speed = ratio; } } @@ -124,10 +109,7 @@ impl Source { } /// Add clip to the queue. - pub fn play( - &self, - clip: &Clip, - ) { + pub fn play(&self, clip: &Clip) { let msg = hub::Operation::SetAudio(Operation::Append(clip.clone())); let _ = self.object.tx.send((self.object.node.downgrade(), msg)); } @@ -155,10 +137,7 @@ impl Source { /// Adjust playback volume. /// /// Default value is `1.0`. - pub fn set_volume( - &self, - volume: f32, - ) { + pub fn set_volume(&self, volume: f32) { let msg = hub::Operation::SetAudio(Operation::SetVolume(volume)); let _ = self.object.tx.send((self.object.node.downgrade(), msg)); } @@ -172,10 +151,7 @@ pub(crate) enum SourceInternal { } impl fmt::Debug for SourceInternal { - fn fmt( - &self, - f: &mut fmt::Formatter, - ) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { SourceInternal::D2(_) => write!(f, "SourceInternal::D2"), SourceInternal::D3(_) => write!(f, "SourceInternal::D3"), @@ -205,20 +181,14 @@ impl SourceInternal { } } - pub(crate) fn set_volume( - &mut self, - volume: f32, - ) { + pub(crate) fn set_volume(&mut self, volume: f32) { match *self { SourceInternal::D2(ref mut sink) => sink.set_volume(volume), _ => unimplemented!(), } } - pub(crate) fn append( - &mut self, - clip: Clip, - ) { + pub(crate) fn append(&mut self, clip: Clip) { match *self { SourceInternal::D2(ref mut sink) => { let vec: Vec = (&*clip.data).clone(); diff --git a/src/camera.rs b/src/camera.rs index 941a283..bebb5f6 100644 --- a/src/camera.rs +++ b/src/camera.rs @@ -105,7 +105,9 @@ pub struct Camera { } impl AsRef for Camera { - fn as_ref(&self) -> &Base { &self.object } + fn as_ref(&self) -> &Base { + &self.object + } } impl Object for Camera { @@ -128,7 +130,8 @@ impl Camera { /// Sets the projection used by the camera. pub fn set_projection>(&self, projection: P) { - self.as_ref().send(Operation::SetProjection(projection.into())); + self.as_ref() + .send(Operation::SetProjection(projection.into())); } } @@ -143,11 +146,7 @@ impl DowncastObject for Camera { impl Projection { /// Constructs an orthographic projection. - pub fn orthographic

( - center: P, - extent_y: f32, - range: ops::Range, - ) -> Self + pub fn orthographic

(center: P, extent_y: f32, range: ops::Range) -> Self where P: Into>, { @@ -160,10 +159,7 @@ impl Projection { } /// Constructs a perspective projection. - pub fn perspective( - fov_y: f32, - range: R, - ) -> Self + pub fn perspective(fov_y: f32, range: R) -> Self where R: Into, { @@ -174,10 +170,7 @@ impl Projection { } /// Computes the projection matrix representing the camera's projection. - pub fn matrix( - &self, - aspect_ratio: f32, - ) -> mint::ColumnMatrix4 { + pub fn matrix(&self, aspect_ratio: f32) -> mint::ColumnMatrix4 { match *self { Projection::Orthographic(ref x) => x.matrix(aspect_ratio), Projection::Perspective(ref x) => x.matrix(aspect_ratio), @@ -199,10 +192,7 @@ pub struct Orthographic { impl Orthographic { /// Computes the projection matrix representing the camera's projection. - pub fn matrix( - &self, - aspect_ratio: f32, - ) -> mint::ColumnMatrix4 { + pub fn matrix(&self, aspect_ratio: f32) -> mint::ColumnMatrix4 { let extent_x = aspect_ratio * self.extent_y; cgmath::ortho( self.center.x - extent_x, @@ -211,7 +201,8 @@ impl Orthographic { self.center.y + self.extent_y, self.range.start, self.range.end, - ).into() + ) + .into() } } @@ -227,17 +218,15 @@ pub struct Perspective { impl Perspective { /// Computes the projection matrix representing the camera's projection. - pub fn matrix( - &self, - aspect_ratio: f32, - ) -> mint::ColumnMatrix4 { + pub fn matrix(&self, aspect_ratio: f32) -> mint::ColumnMatrix4 { match self.zrange { ZRange::Finite(ref range) => cgmath::perspective( cgmath::Deg(self.fov_y), aspect_ratio, range.start, range.end, - ).into(), + ) + .into(), ZRange::Infinite(ref range) => { let f = 1.0 / (0.5 * self.fov_y.to_radians()).tan(); diff --git a/src/controls/first_person.rs b/src/controls/first_person.rs index a1b0e9a..ded745f 100644 --- a/src/controls/first_person.rs +++ b/src/controls/first_person.rs @@ -69,7 +69,7 @@ impl Builder { position: [0.0, 0.0, 0.0].into(), yaw: 0.0, pitch: 0.0, - pitch_range: Some(-PI / 2.0 .. PI / 2.0), + pitch_range: Some(-PI / 2.0..PI / 2.0), move_speed: 1.0, look_speed: 0.5, axes: Axes::default(), @@ -81,10 +81,7 @@ impl Builder { /// Set the initial yaw angle in radians. /// /// Default is 0.0. - pub fn yaw( - &mut self, - yaw: f32, - ) -> &mut Self { + pub fn yaw(&mut self, yaw: f32) -> &mut Self { self.yaw = yaw; self } @@ -92,10 +89,7 @@ impl Builder { /// Set the initial pitch angle in radians. /// /// Defaults to 0.0. - pub fn pitch( - &mut self, - pitch: f32, - ) -> &mut Self { + pub fn pitch(&mut self, pitch: f32) -> &mut Self { self.pitch = pitch; self } @@ -103,10 +97,7 @@ impl Builder { /// Set the initial pitch range in radians. /// /// Defaults to `Some(-PI / 2.0 .. PI / 2.0)`. - pub fn pitch_range( - &mut self, - range: Option>, - ) -> &mut Self { + pub fn pitch_range(&mut self, range: Option>) -> &mut Self { self.pitch_range = range; self } @@ -114,10 +105,7 @@ impl Builder { /// Set the initial position. /// /// Defaults to the world origin. - pub fn position

( - &mut self, - position: P, - ) -> &mut Self + pub fn position

(&mut self, position: P) -> &mut Self where P: Into>, { @@ -128,10 +116,7 @@ impl Builder { /// Setup the movement speed in world units per second. /// /// Defaults to 1.0 world units per second. - pub fn move_speed( - &mut self, - speed: f32, - ) -> &mut Self { + pub fn move_speed(&mut self, speed: f32) -> &mut Self { self.move_speed = speed; self } @@ -139,10 +124,7 @@ impl Builder { /// Setup mouse sensitivity. /// /// Defaults to 0.5 - pub fn look_speed( - &mut self, - speed: f32, - ) -> &mut Self { + pub fn look_speed(&mut self, speed: f32) -> &mut Self { self.look_speed = speed; self } @@ -151,10 +133,7 @@ impl Builder { /// down or up. /// /// Defaults to true. - pub fn vertical_movement( - &mut self, - value: bool, - ) -> &mut Self { + pub fn vertical_movement(&mut self, value: bool) -> &mut Self { self.vertical_move = value; self } @@ -162,10 +141,7 @@ impl Builder { /// Setup whether controlled object can adjust pitch using mouse. /// /// Defaults to true. - pub fn vertical_look( - &mut self, - value: bool, - ) -> &mut Self { + pub fn vertical_look(&mut self, value: bool) -> &mut Self { self.vertical_look = value; self } @@ -173,10 +149,7 @@ impl Builder { /// Setup key axis for moving forward/backward. /// /// Defaults to `W` and `S` keys. - pub fn axis_forward( - &mut self, - axis: Option, - ) -> &mut Self { + pub fn axis_forward(&mut self, axis: Option) -> &mut Self { self.axes.forward = axis; self } @@ -184,10 +157,7 @@ impl Builder { /// Setup button for "strafing" left/right. /// /// Defaults to `A` and `D` keys. - pub fn axis_strafing( - &mut self, - axis: Option, - ) -> &mut Self { + pub fn axis_strafing(&mut self, axis: Option) -> &mut Self { self.axes.strafing = axis; self } @@ -195,10 +165,7 @@ impl Builder { /// Setup button for moving up/down. /// /// Defaults to `None`. - pub fn axis_vertical( - &mut self, - axis: Option, - ) -> &mut Self { + pub fn axis_vertical(&mut self, axis: Option) -> &mut Self { self.axes.vertical = axis; self } @@ -232,37 +199,25 @@ impl FirstPerson { } /// Sets the yaw angle in radians. - pub fn set_yaw( - &mut self, - yaw: f32, - ) -> &mut Self { + pub fn set_yaw(&mut self, yaw: f32) -> &mut Self { self.yaw = yaw; self } /// Sets the pitch angle in radians. - pub fn set_pitch( - &mut self, - pitch: f32, - ) -> &mut Self { + pub fn set_pitch(&mut self, pitch: f32) -> &mut Self { self.pitch = pitch; self } /// Sets the pitch range in radians. - pub fn pitch_range( - &mut self, - range: Option>, - ) -> &mut Self { + pub fn pitch_range(&mut self, range: Option>) -> &mut Self { self.pitch_range = range; self } /// Sets the object position. - pub fn set_position

( - &mut self, - position: P, - ) -> &mut Self + pub fn set_position

(&mut self, position: P) -> &mut Self where P: Into>, { @@ -271,75 +226,51 @@ impl FirstPerson { } /// Sets the movement speed in world units per second. - pub fn set_move_speed( - &mut self, - speed: f32, - ) -> &mut Self { + pub fn set_move_speed(&mut self, speed: f32) -> &mut Self { self.move_speed = speed; self } /// Sets the mouse sensitivity. - pub fn set_look_speed( - &mut self, - speed: f32, - ) -> &mut Self { + pub fn set_look_speed(&mut self, speed: f32) -> &mut Self { self.look_speed = speed; self } /// Specifies whether controlled object should move along `y` axis when looking /// down or up. - pub fn set_vertical_movement( - &mut self, - value: bool, - ) -> &mut Self { + pub fn set_vertical_movement(&mut self, value: bool) -> &mut Self { self.vertical_move = value; self } /// Specifies whether controlled object can adjust pitch using mouse. - pub fn set_vertical_look( - &mut self, - value: bool, - ) -> &mut Self { + pub fn set_vertical_look(&mut self, value: bool) -> &mut Self { self.vertical_look = value; self } /// Sets the key axis for moving forward/backward. - pub fn set_axis_forward( - &mut self, - axis: Option, - ) -> &mut Self { + pub fn set_axis_forward(&mut self, axis: Option) -> &mut Self { self.axes.forward = axis; self } /// Sets the button for "strafing" left/right. - pub fn set_axis_strafing( - &mut self, - axis: Option, - ) -> &mut Self { + pub fn set_axis_strafing(&mut self, axis: Option) -> &mut Self { self.axes.strafing = axis; self } /// Sets button for moving up/down. - pub fn set_axis_vertical( - &mut self, - axis: Option, - ) -> &mut Self { + pub fn set_axis_vertical(&mut self, axis: Option) -> &mut Self { self.axes.vertical = axis; self } /// Updates the position, yaw, and pitch of the controlled object according to /// the last frame input. - pub fn update( - &mut self, - input: &Input, - ) { + pub fn update(&mut self, input: &Input) { let dlook = input.delta_time() * self.look_speed; let mouse = input.mouse_delta_raw(); diff --git a/src/controls/mod.rs b/src/controls/mod.rs index 223113f..4971f27 100644 --- a/src/controls/mod.rs +++ b/src/controls/mod.rs @@ -32,7 +32,7 @@ pub use self::first_person::FirstPerson; #[doc(inline)] pub use self::orbit::Orbit; -pub use input::{axis, - Button, Delta, Hit, HitCount, Key, Input, Timer, MouseButton, - AXIS_DOWN_UP, AXIS_LEFT_RIGHT, KEY_ESCAPE, KEY_SPACE, MOUSE_LEFT, MOUSE_RIGHT, +pub use input::{ + axis, Button, Delta, Hit, HitCount, Input, Key, MouseButton, Timer, AXIS_DOWN_UP, + AXIS_LEFT_RIGHT, KEY_ESCAPE, KEY_SPACE, MOUSE_LEFT, MOUSE_RIGHT, }; diff --git a/src/controls/orbit.rs b/src/controls/orbit.rs index ce1ba40..bed275e 100644 --- a/src/controls/orbit.rs +++ b/src/controls/orbit.rs @@ -49,10 +49,7 @@ impl Builder { /// Set the initial position. /// /// Defaults to the world origin. - pub fn position

( - &mut self, - position: P, - ) -> &mut Self + pub fn position

(&mut self, position: P) -> &mut Self where P: Into>, { @@ -63,12 +60,9 @@ impl Builder { /// Sets the initial up direction. /// /// Defaults to the unit z axis. - pub fn up

( - &mut self, - up: P, - ) -> &mut Self + pub fn up

(&mut self, up: P) -> &mut Self where - P: Into> + P: Into>, { self.up = up.into(); self @@ -77,10 +71,7 @@ impl Builder { /// Set the target position. /// /// Defaults to the world origin. - pub fn target

( - &mut self, - target: P, - ) -> &mut Self + pub fn target

(&mut self, target: P) -> &mut Self where P: Into>, { @@ -89,19 +80,13 @@ impl Builder { } /// Setup the speed of the movements. Default value is 1.0 - pub fn speed( - &mut self, - speed: f32, - ) -> &mut Self { + pub fn speed(&mut self, speed: f32) -> &mut Self { self.speed = speed; self } /// Setup control button. Default is left mouse button (`MOUSE_LEFT`). - pub fn button( - &mut self, - button: Button, - ) -> &mut Self { + pub fn button(&mut self, button: Button) -> &mut Self { self.button = button; self } @@ -137,10 +122,7 @@ impl Orbit { } /// Update current position and rotation of the controlled object according to the last frame input. - pub fn update( - &mut self, - input: &Input, - ) { + pub fn update(&mut self, input: &Input) { let mouse_delta = if input.hit(self.button) { input.mouse_delta_ndc() } else { diff --git a/src/custom.rs b/src/custom.rs index 693a4fe..040887f 100644 --- a/src/custom.rs +++ b/src/custom.rs @@ -1,5 +1,5 @@ //! Contains re-exports for custom pipeline state. -pub use gfx::Primitive; pub use gfx::preset; pub use gfx::state; +pub use gfx::Primitive; diff --git a/src/factory/load_gltf.rs b/src/factory/load_gltf.rs index 3d1bd96..fc31dcb 100644 --- a/src/factory/load_gltf.rs +++ b/src/factory/load_gltf.rs @@ -16,20 +16,15 @@ use std::collections::HashMap; use camera::{Orthographic, Perspective, Projection}; use std::path::Path; -use {Material, Texture}; +use super::Factory; use geometry::{Geometry, Shape}; use image::{DynamicImage, ImageBuffer}; use node::Transform; -use super::Factory; use template::{ - AnimationTemplate, - BoneTemplate, - CameraTemplate, - InstancedGeometry, - MeshTemplate, - ObjectTemplate, - Template, + AnimationTemplate, BoneTemplate, CameraTemplate, InstancedGeometry, MeshTemplate, + ObjectTemplate, Template, }; +use {Material, Texture}; fn load_textures( factory: &mut Factory, @@ -41,36 +36,24 @@ fn load_textures( let (width, height) = (data.width, data.height); let image = match data.format { gltf::image::Format::R8 => DynamicImage::ImageLuma8( - ImageBuffer::from_raw( - width, - height, - data.pixels, - ).expect("incorrect image dimensions") + ImageBuffer::from_raw(width, height, data.pixels) + .expect("incorrect image dimensions"), ), gltf::image::Format::R8G8 => DynamicImage::ImageLumaA8( - ImageBuffer::from_raw( - width, - height, - data.pixels, - ).expect("incorrect image dimensions") + ImageBuffer::from_raw(width, height, data.pixels) + .expect("incorrect image dimensions"), ), gltf::image::Format::R8G8B8 => DynamicImage::ImageRgb8( - ImageBuffer::from_raw( - width, - height, - data.pixels, - ).expect("incorrect image dimensions") - ), - gltf::image::Format::R8G8B8A8 => DynamicImage::ImageRgba8( - ImageBuffer::from_raw( - width, - height, - data.pixels, - ).unwrap() + ImageBuffer::from_raw(width, height, data.pixels) + .expect("incorrect image dimensions"), ), - }.to_rgba(); - use {FilterMethod, WrapMode}; + gltf::image::Format::R8G8B8A8 => { + DynamicImage::ImageRgba8(ImageBuffer::from_raw(width, height, data.pixels).unwrap()) + } + } + .to_rgba(); use gltf::texture::{MagFilter, WrappingMode}; + use {FilterMethod, WrapMode}; let params = texture.sampler(); // gfx does not support separate min / mag // filters yet, so for now we'll use `mag_filter` for both. @@ -89,19 +72,18 @@ fn load_textures( WrappingMode::Repeat => WrapMode::Tile, }; let sampler = factory.sampler(mag_filter, wrap_s, wrap_t); - let texture = factory.load_texture_from_memory(width as u16, height as u16, &image, sampler); + let texture = + factory.load_texture_from_memory(width as u16, height as u16, &image, sampler); textures.push(texture); } textures } -fn load_material<'a>( - mat: gltf::Material<'a>, - textures: &[Texture<[f32; 4]>], -) -> Material { +fn load_material<'a>(mat: gltf::Material<'a>, textures: &[Texture<[f32; 4]>]) -> Material { let pbr = mat.pbr_metallic_roughness(); let mut is_basic_material = true; - let base_color_map = pbr.base_color_texture() + let base_color_map = pbr + .base_color_texture() .map(|t| textures[t.as_ref().index()].clone()); let normal_map = mat.normal_texture().map(|t| { is_basic_material = false; @@ -124,30 +106,29 @@ fn load_material<'a>( (color::from_linear_rgb([x[0], x[1], x[2]]), x[3]) }; - if false {// is_basic_material { + if false { + // is_basic_material { material::Basic { color: base_color_factor, map: base_color_map, - }.into() + } + .into() } else { material::Pbr { base_color_factor, base_color_alpha, metallic_factor: pbr.metallic_factor(), roughness_factor: pbr.roughness_factor(), - occlusion_strength: mat.occlusion_texture().map_or(1.0, |t| { - t.strength() - }), + occlusion_strength: mat.occlusion_texture().map_or(1.0, |t| t.strength()), emissive_factor: color::from_linear_rgb(mat.emissive_factor()), - normal_scale: mat.normal_texture().map_or(1.0, |t| { - t.scale() - }), + normal_scale: mat.normal_texture().map_or(1.0, |t| t.scale()), base_color_map, normal_map, emissive_map, metallic_roughness_map, occlusion_map, - }.into() + } + .into() } } @@ -165,11 +146,8 @@ fn load_primitive<'a>( if let Some(iter) = reader.read_indices() { faces.extend(iter.into_u32().tuples().map(|(a, b, c)| [a, b, c])); } - let vertices: Vec> = reader - .read_positions() - .unwrap() - .map(|x| x.into()) - .collect(); + let vertices: Vec> = + reader.read_positions().unwrap().map(|x| x.into()).collect(); let normals = if let Some(iter) = reader.read_normals() { iter.map(|x| x.into()).collect() } else { @@ -209,7 +187,12 @@ fn load_primitive<'a>( shape.normals.extend(iter.map(mint::Vector3::::from)); } if let Some(iter) = tangents { - shape.tangents.extend(iter.map(|v| mint::Vector4{ x: v[0], y: v[1], z: v[2], w: 1.0 })); + shape.tangents.extend(iter.map(|v| mint::Vector4 { + x: v[0], + y: v[1], + z: v[2], + w: 1.0, + })); } shape }) @@ -254,7 +237,7 @@ fn load_skin<'a>( use std::iter::repeat; let reader = skin.reader(|buffer| Some(&buffers[buffer.index()].0)); - + let mut ibms = Vec::new(); if let Some(iter) = reader.read_inverse_bind_matrices() { for ibm in iter { @@ -267,19 +250,15 @@ fn load_skin<'a>( [0., 0., 1., 0.], [0., 0., 0., 1.], ]); - let ibm_iter = ibms. - into_iter() - .chain(repeat(mx_id)); + let ibm_iter = ibms.into_iter().chain(repeat(mx_id)); - let joint_iter = skin - .joints() - .map(|joint| joint.index()); + let joint_iter = skin.joints().map(|joint| joint.index()); for (index, (joint_index, inverse_bind_matrix)) in joint_iter.zip(ibm_iter).enumerate() { // Create a bone node corresponding to the joint. let object = objects.len(); objects.push(ObjectTemplate { parent: Some(joint_index), - .. Default::default() + ..Default::default() }); bones.push(BoneTemplate { object, @@ -293,7 +272,7 @@ fn load_skin<'a>( let object = objects.len(); objects.push(ObjectTemplate { parent: skin.skeleton().map(|node| node.index()), - .. Default::default() + ..Default::default() }); object @@ -323,9 +302,7 @@ fn load_animation<'a>( let times: Vec = reader.read_inputs().unwrap().collect(); let (binding, values) = match reader.read_outputs().unwrap() { gltf::animation::util::ReadOutputs::Translations(iter) => { - let values = iter - .map(|v| mint::Vector3::from(v)) - .collect::>(); + let values = iter.map(|v| mint::Vector3::from(v)).collect::>(); assert_eq!(values.len(), times.len()); (Binding::Position, Values::Vector3(values)) } @@ -371,16 +348,12 @@ fn load_animation<'a>( times, values, }, - // Target the object for the group that corresponds to the target node. groups[node.index()], )); } - AnimationTemplate { - name, - tracks, - } + AnimationTemplate { name, tracks } } /// Partially loads a single glTF node and creates template nodes from its data. @@ -447,7 +420,7 @@ fn load_node<'a>( let object = objects.len(); objects.push(ObjectTemplate { parent: Some(node.index()), - .. Default::default() + ..Default::default() }); meshes.push(MeshTemplate { object, @@ -463,7 +436,7 @@ fn load_node<'a>( let object = objects.len(); objects.push(ObjectTemplate { parent: Some(node.index()), - .. Default::default() + ..Default::default() }); cameras.push(CameraTemplate { object, @@ -474,23 +447,25 @@ fn load_node<'a>( object_index } -fn load_camera<'a>( - entry: gltf::Camera<'a>, -) -> Projection { +fn load_camera<'a>(entry: gltf::Camera<'a>) -> Projection { match entry.projection() { gltf::camera::Projection::Orthographic(values) => { let center = mint::Point2::::from([0.0, 0.0]); let extent_y = values.ymag(); - let range = values.znear() .. values.zfar(); - Projection::Orthographic(Orthographic { center, extent_y, range }) + let range = values.znear()..values.zfar(); + Projection::Orthographic(Orthographic { + center, + extent_y, + range, + }) } gltf::camera::Projection::Perspective(values) => { let fov_y = values.yfov().to_degrees(); let near = values.znear(); let zrange = match values.zfar() { - Some(far) => (near .. far).into(), - None => (near ..).into(), + Some(far) => (near..far).into(), + None => (near..).into(), }; Projection::Perspective(Perspective { fov_y, zrange }) } @@ -502,7 +477,7 @@ fn load_scene<'a>(scene: gltf::Scene<'a>, raw: &Template) -> Template { Template { name: scene.name().map(Into::into), - .. raw.clone() + ..raw.clone() } } @@ -542,15 +517,11 @@ impl super::Factory { /// [`template`]: ./template/index.html /// [`Template`]: ./template/struct.Template.html /// [`Factory::instantiate_template`]: #method.instantiate_template - pub fn load_gltf( - &mut self, - path_str: &str, - ) -> Vec