diff options
author | metamuffin <metamuffin@disroot.org> | 2025-01-07 17:36:07 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2025-01-07 17:36:07 +0100 |
commit | 4032ef64aa33f616a2009ad1e6270cdf646242e7 (patch) | |
tree | d4a19ada3cbfef181851152413fa32eaef311cad | |
parent | a82dad99984c074136062f8cd34a91517b8c801c (diff) | |
download | weareserver-4032ef64aa33f616a2009ad1e6270cdf646242e7.tar weareserver-4032ef64aa33f616a2009ad1e6270cdf646242e7.tar.bz2 weareserver-4032ef64aa33f616a2009ad1e6270cdf646242e7.tar.zst |
update notes and support all part attrs
-rw-r--r-- | a.md | 38 | ||||
-rw-r--r-- | world/src/main.rs | 78 |
2 files changed, 93 insertions, 23 deletions
@@ -47,25 +47,25 @@ Combinations of g__, va__ and tex_* are multiplied except normal which is added. Defaults should be the identity for that operation, so default is 1 / white except normals are zero. -| Key | Value Type | | -| ---------------- | ------------- | ---------------------- | -| index | Resource | | -| g_metallic | f32 | | -| g_roughness | f32 | | -| g_albedo | Vec3A | | -| g_transmission | f32 | | -| va_position | [Resource; 3] | | -| va_normal | [Resource; 3] | | -| va_texcoord | [Resource; 2] | | -| va_roughness | Resource | | -| va_metallic | Resource | | -| va_albedo | [Resource; 3] | | -| va_transmission | Resource | | -| tex_normal | Resource | | -| tex_roughness | Resource | Use only green channel | -| tex_metallic | Resource | Use only blue channel | -| tex_albedo | Resource | | -| tex_transmission | Resource | | +| Key | Value Type | | +| ---------------- | ------------- | ------------------ | +| index | Resource | | +| g_metallic | f32 | | +| g_roughness | f32 | | +| g_albedo | \[f32;3\] | | +| g_transmission | f32 | | +| va_position | [Resource; 3] | | +| va_normal | [Resource; 3] | | +| va_texcoord | [Resource; 2] | | +| va_roughness | Resource | | +| va_metallic | Resource | | +| va_albedo | [Resource; 3] | | +| va_transmission | Resource | | +| tex_normal | Resource | Use color channels | +| tex_roughness | Resource | Use green channel | +| tex_metallic | Resource | Use blue channel | +| tex_albedo | Resource | Use color channels | +| tex_transmission | Resource | Use alpha channel | ### Texture diff --git a/world/src/main.rs b/world/src/main.rs index f0b10ff..81d411e 100644 --- a/world/src/main.rs +++ b/world/src/main.rs @@ -2,7 +2,7 @@ use anyhow::{Result, bail}; use clap::Parser; use gltf::image::Source; -use log::info; +use log::{debug, info}; use rand::random; use std::{ fs::File, @@ -87,6 +87,7 @@ fn main() -> Result<()> { ]) }) .transpose()?; + let va_texcoord = reader .read_tex_coords(0) .map(|iter| { @@ -104,6 +105,45 @@ fn main() -> Result<()> { }) .transpose()?; + let va_albedo = reader + .read_colors(0) + .map(|iter| { + let mut color_r = vec![]; + let mut color_g = vec![]; + let mut color_b = vec![]; + for p in iter.into_rgb_f32() { + color_r.push(p[0]); + color_g.push(p[1]); + color_b.push(p[2]); + } + info!("{} vertex colors", color_r.len()); + Ok::<_, anyhow::Error>([ + store.set(&AttributeArray(color_r).write_alloc())?, + store.set(&AttributeArray(color_g).write_alloc())?, + store.set(&AttributeArray(color_b).write_alloc())?, + ]) + }) + .transpose()?; + + let va_transmission = reader + .read_colors(0) + .map(|iter| { + let mut color_a = vec![]; + for p in iter.into_rgba_f32() { + color_a.push(p[3]); + } + let o = if color_a.iter().any(|x| *x != 1.) { + info!("{} vertex transmissions", color_a.len()); + Some(store.set(&AttributeArray(color_a).write_alloc())?) + } else { + debug!("vertex transmission pruned"); + None + }; + Ok::<_, anyhow::Error>(o) + }) + .transpose()? + .flatten(); + let index = reader .read_indices() .unwrap() @@ -115,14 +155,17 @@ fn main() -> Result<()> { let index = Some(store.set(&IndexArray(index).write_alloc())?); let mut tex_albedo = None; + let mut tex_transmission = None; if let Some(tex) = p.material().pbr_metallic_roughness().base_color_texture() { - tex_albedo = Some(load_texture( + let r = load_texture( "albedo", &store, path_base, &buffers, &tex.texture().source().source(), - )?); + )?; + tex_albedo = Some(r); + tex_transmission = Some(r); } let mut tex_normal = None; if let Some(tex) = p.material().normal_texture() { @@ -155,19 +198,46 @@ fn main() -> Result<()> { let g_metallic = Some(p.material().pbr_metallic_roughness().metallic_factor()); let g_roughness = Some(p.material().pbr_metallic_roughness().roughness_factor()); + 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!( + "global albedo is r={},g={},b={}", + base_color[0], base_color[1], base_color[2] + ); + Some(Vec3A::new(base_color[0], base_color[1], base_color[2])) + } else { + debug!("global albedo pruned"); + None + }; + let g_transmission = if base_color[3] != 1. { + info!("global transmission is {}", base_color[3]); + Some(base_color[3]) + } else { + debug!("global transmission pruned"); + None + }; + let part = store.set( &Part { + g_albedo, + g_transmission, g_metallic, g_roughness, va_position, va_normal, va_texcoord, + va_albedo, + va_transmission, tex_albedo, tex_normal, tex_roughness, tex_metallic, + tex_transmission, index, - ..Part::default() + va_metallic: None, // not supported by gltf + va_roughness: None, // not supported by gltf } .write_alloc(), )?; |