diff options
author | metamuffin <metamuffin@disroot.org> | 2025-01-13 00:13:54 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2025-01-13 00:13:54 +0100 |
commit | 3330af8a3417ce411ecb1c7c23343cc28f261b2f (patch) | |
tree | 67facac81b9233eb612e691f1fc72b71bce1d3f3 /world/src | |
parent | 9f5d815e932c9c01265fec2f5a079470d73d6cc8 (diff) | |
download | weareserver-3330af8a3417ce411ecb1c7c23343cc28f261b2f.tar weareserver-3330af8a3417ce411ecb1c7c23343cc28f261b2f.tar.bz2 weareserver-3330af8a3417ce411ecb1c7c23343cc28f261b2f.tar.zst |
add name to light part + show network size of prefab
Diffstat (limited to 'world/src')
-rw-r--r-- | world/src/main.rs | 21 | ||||
-rw-r--r-- | world/src/mesh.rs | 41 | ||||
-rw-r--r-- | world/src/physics.rs | 4 |
3 files changed, 40 insertions, 26 deletions
diff --git a/world/src/main.rs b/world/src/main.rs index efdd16b..7548d8f 100644 --- a/world/src/main.rs +++ b/world/src/main.rs @@ -21,6 +21,7 @@ pub mod physics; use anyhow::Result; use clap::Parser; use gltf::{Gltf, image::Source, import_buffers}; +use humansize::BINARY; use image::{ImageReader, codecs::webp::WebPEncoder}; use log::{debug, info}; use mesh::import_mesh; @@ -97,21 +98,26 @@ fn main() -> Result<()> { .map(|node| { let mut prefab = Prefab::default(); if let Some(mesh) = node.mesh() { - info!("--- MESH ---"); import_mesh(mesh, &buffers, &store, path_base, &node, &mut prefab, &args)?; } let (position, _, _) = node.transform().decomposed(); if let Some(light) = node.light() { - info!("--- LIGHT ---"); + let name = node.name().map(|e| e.to_owned()); + if let Some(name) = &name { + info!("adding light {name:?}"); + } else { + info!("adding light"); + } let emission = Some(Vec3A::from_array(light.color()) * light.intensity()); if let Some(e) = emission { - info!("emission is {e}"); + debug!("emission is {e}"); } prefab.light.push(( Vec3A::from_array(position), store.set(&LightPart { emission, - ..Default::default() + name, + radius: None, })?, )); } @@ -149,6 +155,13 @@ fn main() -> Result<()> { let pres = store.set(&prefab)?; + let mut size = 0; + store.iter(|d| size += d.len()).unwrap(); + info!( + "prefab has network size of {}", + humansize::format_size(size, BINARY) + ); + if args.dry_run { return Ok(()); } diff --git a/world/src/mesh.rs b/world/src/mesh.rs index fd6b6ae..16c2ce7 100644 --- a/world/src/mesh.rs +++ b/world/src/mesh.rs @@ -36,13 +36,19 @@ pub fn import_mesh( args: &Args, ) -> Result<()> { Ok(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:?}"); + } else { + info!("adding mesh"); + } let reader = p.reader(|buf| Some(&buffers[buf.index()])); let va_position = reader .read_positions() .map(|iter| { let a = iter.map(|[x, y, z]| vec3a(x, y, z)).collect::<Vec<_>>(); - info!("{} vertex positions", a.len()); + debug!("{} vertex positions", a.len()); Ok::<_, anyhow::Error>(store.set(&a)?) }) .transpose()?; @@ -51,7 +57,7 @@ pub fn import_mesh( .read_normals() .map(|iter| { let a = iter.map(|[x, y, z]| vec3a(x, y, z)).collect::<Vec<_>>(); - info!("{} vertex normals", a.len()); + debug!("{} vertex normals", a.len()); Ok::<_, anyhow::Error>(store.set(&a)?) }) .transpose()?; @@ -60,7 +66,7 @@ pub fn import_mesh( .read_tex_coords(0) .map(|iter| { let a = iter.into_f32().map(|[x, y]| vec2(x, y)).collect::<Vec<_>>(); - info!("{} vertex texture coordinates", a.len()); + debug!("{} vertex texture coordinates", a.len()); Ok::<_, anyhow::Error>(store.set(&a)?) }) .transpose()?; @@ -72,7 +78,7 @@ pub fn import_mesh( .into_rgb_f32() .map(|[x, y, z]| vec3a(x, y, z)) .collect::<Vec<_>>(); - info!("{} vertex colors", a.len()); + debug!("{} vertex colors", a.len()); Ok::<_, anyhow::Error>(store.set(&a)?) }) .transpose()?; @@ -85,7 +91,7 @@ pub fn import_mesh( color_a.push(p[3]); } let o = if color_a.iter().any(|x| *x != 1.) { - info!("{} vertex transmissions", color_a.len()); + debug!("{} vertex transmissions", color_a.len()); Some(store.set(&color_a)?) } else { debug!("vertex transmission pruned"); @@ -102,7 +108,7 @@ pub fn import_mesh( .into_u32() .array_chunks::<3>() .collect::<Vec<_>>(); - info!("{} indecies", index.len() * 3); + debug!("{} indecies", index.len() * 3); let index = Some(store.set(&index)?); let mut tex_albedo = None; @@ -209,7 +215,7 @@ pub fn import_mesh( let base_color = p.material().pbr_metallic_roughness().base_color_factor(); let g_albedo = if base_color[0] != 1. || base_color[1] != 1. || base_color[2] != 1. { - info!( + debug!( "albedo is r={},g={},b={}", base_color[0], base_color[1], base_color[2] ); @@ -219,7 +225,7 @@ pub fn import_mesh( None }; let g_alpha = if base_color[3] != 1. { - info!("alpha is {}", base_color[3]); + debug!("alpha is {}", base_color[3]); Some(base_color[3]) } else { debug!("alpha pruned"); @@ -228,7 +234,7 @@ pub fn import_mesh( let emission = p.material().emissive_factor(); let g_emission = if emission[0] != 0. || emission[1] != 0. || emission[2] != 0. { - info!( + debug!( "emission is r={},g={},b={}", base_color[0], base_color[1], base_color[2] ); @@ -245,7 +251,7 @@ pub fn import_mesh( .unwrap_or(0.); let g_transmission = if transmission != 0. { - info!("transmission is {transmission}"); + debug!("transmission is {transmission}"); Some(transmission) } else { debug!("transmission pruned"); @@ -263,7 +269,7 @@ pub fn import_mesh( .flatten() .map(|e| e as f32); if let Some(d) = g_dispersion { - info!("dispersion is {d}"); + debug!("dispersion is {d}"); } let g_attenuation = p.material().volume().map(|v| { @@ -272,34 +278,29 @@ pub fn import_mesh( // manually derived from attenuation coefficient formula. i hope this is correct. |factor| -(factor.powf(1. / ref_dist)).ln(), )); - info!("attenuation is {att}"); + debug!("attenuation is {att}"); att }); let g_refractive_index = p.material().ior(); if let Some(i) = g_refractive_index { - info!("refractive index is {i}"); + debug!("refractive index is {i}"); } let g_thickness = p.material().volume().map(|v| v.thickness_factor()); - let name = mesh.name().map(|e| e.to_owned()); - if let Some(name) = &name { - info!("name is {name:?}"); - } - let g_unlit = if p .material() .extensions() .map(|e| e.contains_key("KHR_materials_unlit")) .unwrap_or(false) { - info!("unlit"); + debug!("unlit"); Some(()) } else { None }; let g_double_sided = if p.material().double_sided() { - info!("double sided"); + debug!("double sided"); Some(()) } else { None diff --git a/world/src/physics.rs b/world/src/physics.rs index 4afeab7..b0c3ae6 100644 --- a/world/src/physics.rs +++ b/world/src/physics.rs @@ -17,7 +17,7 @@ use crate::{Args, mesh::node_transform_to_affine}; use anyhow::{Result, anyhow}; use gltf::{Gltf, Node, buffer::Data, json::Value}; -use log::info; +use log::{debug, info}; use weareshared::{ resources::{CollisionPart, Prefab}, store::ResourceStore, @@ -66,7 +66,7 @@ pub fn import_physics( .map(|[x, y, z]| vec3a(x, y, z)) .collect::<Vec<_>>(); - info!( + debug!( "convex hull has {} indecies and {} positions", index.len(), position.len() |