diff options
Diffstat (limited to 'world/src')
-rw-r--r-- | world/src/main.rs | 20 | ||||
-rw-r--r-- | world/src/mesh.rs | 59 | ||||
-rw-r--r-- | world/src/physics.rs | 6 |
3 files changed, 39 insertions, 46 deletions
diff --git a/world/src/main.rs b/world/src/main.rs index d46f4d1..c65342f 100644 --- a/world/src/main.rs +++ b/world/src/main.rs @@ -15,6 +15,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>. */ #![feature(iter_array_chunks)] +#![allow(clippy::too_many_arguments, clippy::type_complexity)] pub mod mesh; pub mod physics; @@ -181,7 +182,7 @@ fn main() -> Result<()> { &buffers, &store, path_base, - &node, + node, &mut prefab, &args, &texture_cache, @@ -209,7 +210,7 @@ fn main() -> Result<()> { })?, )); } - import_physics(&gltf, *trans, &node, &mut prefab, &store, &buffers)?; + import_physics(&gltf, *trans, node, &mut prefab, &store, &buffers)?; Ok::<_, anyhow::Error>(prefab) }) .reduce( @@ -237,8 +238,7 @@ fn main() -> Result<()> { prefab.name = args.name.clone().or(gltf .default_scene() - .map(|n| n.name()) - .flatten() + .and_then(|n| n.name()) .map(|n| n.to_owned())); if args.debug_light { @@ -285,7 +285,7 @@ fn main() -> Result<()> { } if args.spin { - let ob = obs[0].clone(); + let ob = obs[0]; let mut sock2 = sock.try_clone().unwrap(); thread::spawn(move || { let mut x = 0.; @@ -321,12 +321,10 @@ fn main() -> Result<()> { } } Packet::Add(ob_a, _) => { - if args.clear { - if !obs.contains(&ob_a) { - info!("removing object {ob_a}"); - Packet::Remove(ob_a).write(&mut sock)?; - sock.flush()?; - } + if args.clear && !obs.contains(&ob_a) { + info!("removing object {ob_a}"); + Packet::Remove(ob_a).write(&mut sock)?; + sock.flush()?; } } _ => (), diff --git a/world/src/mesh.rs b/world/src/mesh.rs index b8dc0c3..4e6317d 100644 --- a/world/src/mesh.rs +++ b/world/src/mesh.rs @@ -38,7 +38,7 @@ pub fn import_mesh( texture_cache: &TextureCache, armatures: &[Option<Armature>], ) -> Result<()> { - Ok(for p in mesh.primitives() { + for p in mesh.primitives() { let name = mesh.name().or(node.name()).map(|e| e.to_owned()); if let Some(name) = &name { info!("adding mesh {name:?}"); @@ -52,7 +52,7 @@ pub fn import_mesh( .map(|iter| { let a = iter.map(|[x, y, z]| vec3a(x, y, z)).collect::<Vec<_>>(); debug!("{} vertex positions", a.len()); - Ok::<_, anyhow::Error>(store.set(&a)?) + store.set(&a) }) .transpose()?; @@ -61,7 +61,7 @@ pub fn import_mesh( .map(|iter| { let a = iter.map(|[x, y, z]| vec3a(x, y, z)).collect::<Vec<_>>(); debug!("{} vertex normals", a.len()); - Ok::<_, anyhow::Error>(store.set(&a)?) + store.set(&a) }) .transpose()?; @@ -71,7 +71,7 @@ pub fn import_mesh( // TODO dont ignore handedness let a = iter.map(|[x, y, z, _h]| vec3a(x, y, z)).collect::<Vec<_>>(); debug!("{} vertex tangents", a.len()); - Ok::<_, anyhow::Error>(store.set(&a)?) + store.set(&a) }) .transpose()?; @@ -80,7 +80,7 @@ pub fn import_mesh( .map(|iter| { let a = iter.into_u16().collect::<Vec<_>>(); debug!("{} vertex joint indecies", a.len()); - Ok::<_, anyhow::Error>(store.set(&a)?) + store.set(&a) }) .transpose()?; @@ -89,7 +89,7 @@ pub fn import_mesh( .map(|iter| { let a = iter.into_f32().collect::<Vec<_>>(); debug!("{} vertex joint weights", a.len()); - Ok::<_, anyhow::Error>(store.set(&a)?) + store.set(&a) }) .transpose()?; @@ -98,7 +98,7 @@ pub fn import_mesh( .map(|iter| { let a = iter.into_f32().map(|[x, y]| vec2(x, y)).collect::<Vec<_>>(); debug!("{} vertex texture coordinates", a.len()); - Ok::<_, anyhow::Error>(store.set(&a)?) + store.set(&a) }) .transpose()?; @@ -110,7 +110,7 @@ pub fn import_mesh( .map(|[x, y, z]| vec3a(x, y, z)) .collect::<Vec<_>>(); debug!("{} vertex colors", a.len()); - Ok::<_, anyhow::Error>(store.set(&a)?) + store.set(&a) }) .transpose()?; @@ -147,9 +147,9 @@ pub fn import_mesh( if let Some(tex) = p.material().pbr_metallic_roughness().base_color_texture() { let r = load_texture( "albedo", - &store, + store, path_base, - &buffers, + buffers, &tex.texture().source().source(), args.webp, texture_cache, @@ -161,9 +161,9 @@ pub fn import_mesh( if let Some(tex) = p.material().normal_texture() { tex_normal = Some(load_texture( "normal", - &store, + store, path_base, - &buffers, + buffers, &tex.texture().source().source(), args.webp, texture_cache, @@ -173,9 +173,9 @@ pub fn import_mesh( if let Some(tex) = p.material().emissive_texture() { tex_emission = Some(load_texture( "emission", - &store, + store, path_base, - &buffers, + buffers, &tex.texture().source().source(), args.webp, texture_cache, @@ -185,14 +185,13 @@ pub fn import_mesh( if let Some(tex) = p .material() .transmission() - .map(|t| t.transmission_texture()) - .flatten() + .and_then(|t| t.transmission_texture()) { tex_transmission = Some(load_texture( "transmission", - &store, + store, path_base, - &buffers, + buffers, &tex.texture().source().source(), args.webp, texture_cache, @@ -202,14 +201,13 @@ pub fn import_mesh( if let Some(tex) = p .material() .volume() - .map(|t| t.thickness_texture()) - .flatten() + .and_then(|t| t.thickness_texture()) { tex_thickness = Some(load_texture( "thickness", - &store, + store, path_base, - &buffers, + buffers, &tex.texture().source().source(), args.webp, texture_cache, @@ -219,9 +217,9 @@ pub fn import_mesh( if let Some(tex) = p.material().occlusion_texture() { tex_occlusion = Some(load_texture( "occlusion", - &store, + store, path_base, - &buffers, + buffers, &tex.texture().source().source(), args.webp, texture_cache, @@ -236,9 +234,9 @@ pub fn import_mesh( { let r = load_texture( "metallic+roughness", - &store, + store, path_base, - &buffers, + buffers, &tex.texture().source().source(), args.webp, texture_cache, @@ -299,10 +297,8 @@ pub fn import_mesh( let g_dispersion = p .material() .extension_value("KHR_materials_dispersion") - .map(|e| e.get("dispersion")) - .flatten() - .map(|e| e.as_f64()) - .flatten() + .and_then(|e| e.get("dispersion")) + .and_then(|e| e.as_f64()) .map(|e| e as f32); if let Some(d) = g_dispersion { debug!("dispersion is {d}"); @@ -391,5 +387,6 @@ pub fn import_mesh( })?; prefab.mesh.push((trans, mesh)) - }) + }; + Ok(()) } diff --git a/world/src/physics.rs b/world/src/physics.rs index 37201af..84f1095 100644 --- a/world/src/physics.rs +++ b/world/src/physics.rs @@ -34,8 +34,7 @@ pub fn import_physics( ) -> Result<()> { if let Some(physics) = node .extensions() - .map(|e| e.get("KHR_physics_rigid_bodies")) - .flatten() + .and_then(|e| e.get("KHR_physics_rigid_bodies")) { info!("--- COLLISION ---"); if let Some(collider) = physics.get("collider") { @@ -43,8 +42,7 @@ pub fn import_physics( if geometry.get("convexHull") == Some(&Value::Bool(true)) { let node = geometry .get("node") - .map(|n| n.as_u64()) - .flatten() + .and_then(|n| n.as_u64()) .ok_or(anyhow!("convexHull node missing"))?; let node = gltf .nodes() |