summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock16
-rw-r--r--doc/resources.md1
-rw-r--r--shared/src/resources.rs3
-rw-r--r--world/Cargo.toml1
-rw-r--r--world/src/main.rs21
-rw-r--r--world/src/mesh.rs41
-rw-r--r--world/src/physics.rs4
7 files changed, 61 insertions, 26 deletions
diff --git a/Cargo.lock b/Cargo.lock
index b2e76e4..fb28ca4 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1169,6 +1169,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dfa686283ad6dd069f105e5ab091b04c62850d3e4cf5d67debad1933f55023df"
[[package]]
+name = "humansize"
+version = "2.1.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6cb51c9a029ddc91b07a787f1d86b53ccfa49b0e86688c946ebe8d3555685dd7"
+dependencies = [
+ "libm",
+]
+
+[[package]]
name = "humantime"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1373,6 +1382,12 @@ dependencies = [
]
[[package]]
+name = "libm"
+version = "0.2.11"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8355be11b20d696c8f18f6cc018c4e372165b1fa8126cef092399c9951984ffa"
+
+[[package]]
name = "libredox"
version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -3005,6 +3020,7 @@ dependencies = [
"clap",
"env_logger",
"gltf",
+ "humansize",
"image",
"log",
"rand 0.9.0-beta.1",
diff --git a/doc/resources.md b/doc/resources.md
index 61a5781..e4944ef 100644
--- a/doc/resources.md
+++ b/doc/resources.md
@@ -87,6 +87,7 @@ white except normals are zero.
| Key | Value Type |
| ---------- | ------------------------ |
+| `name` | `String` |
| `radius` | `Float` |
| `emission` | `Vec3` |
| `spot` | `Vec3`, `Float`, `Float` |
diff --git a/shared/src/resources.rs b/shared/src/resources.rs
index 40a9cad..5c207a9 100644
--- a/shared/src/resources.rs
+++ b/shared/src/resources.rs
@@ -35,6 +35,7 @@ pub struct Prefab {
#[derive(Debug, Default, Clone)]
pub struct LightPart {
+ pub name: Option<String>,
pub emission: Option<Vec3A>,
pub radius: Option<f32>,
}
@@ -186,6 +187,7 @@ impl ReadWrite for Prefab {
}
impl ReadWrite for LightPart {
fn write(&self, w: &mut dyn Write) -> Result<()> {
+ write_kv_opt(w, b"name", &self.name)?;
write_kv_opt(w, b"emission", &self.emission)?;
write_kv_opt(w, b"radius", &self.radius)?;
Ok(())
@@ -194,6 +196,7 @@ impl ReadWrite for LightPart {
fn read(r: &mut dyn Read) -> Result<Self> {
let mut s = Self::default();
read_kv_iter(r, |k, v| match k {
+ b"name" => Ok(s.name = Some(read_slice(v)?)),
b"emission" => Ok(s.emission = Some(read_slice(v)?)),
b"radius" => Ok(s.radius = Some(read_slice(v)?)),
x => Ok(warn!(
diff --git a/world/Cargo.toml b/world/Cargo.toml
index 8bf5e02..db199bc 100644
--- a/world/Cargo.toml
+++ b/world/Cargo.toml
@@ -22,3 +22,4 @@ weareshared = { path = "../shared" }
rand = "0.9.0-beta.1"
image = "0.25.5"
rayon = "1.10.0"
+humansize = "2.1.3"
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()