diff options
author | metamuffin <metamuffin@disroot.org> | 2025-01-09 22:30:46 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2025-01-09 22:30:46 +0100 |
commit | 1aca139c985cb71be90da1de6d65adc3c7d0d073 (patch) | |
tree | f271d3fddcd05897a0cbfdca0e134233f213b6f4 | |
parent | ecaa6a08527bad93c71bdb8211b6c2f8232ff878 (diff) | |
download | weareserver-1aca139c985cb71be90da1de6d65adc3c7d0d073.tar weareserver-1aca139c985cb71be90da1de6d65adc3c7d0d073.tar.bz2 weareserver-1aca139c985cb71be90da1de6d65adc3c7d0d073.tar.zst |
KHR_materials_unlit
-rw-r--r-- | server/src/main.rs | 8 | ||||
-rw-r--r-- | shared/src/helper.rs | 8 | ||||
-rw-r--r-- | shared/src/resources.rs | 2 | ||||
-rw-r--r-- | world/src/main.rs | 15 | ||||
-rw-r--r-- | world/src/mesh.rs | 12 |
5 files changed, 39 insertions, 6 deletions
diff --git a/server/src/main.rs b/server/src/main.rs index 5cfbb96..4528ede 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -69,10 +69,10 @@ impl State { }) } pub fn prime_client(&self, conn: u128, net: &ServerNetwork) -> Result<()> { - // net.broadcast( - // Packet::PrefabIndex(self.store.set(&self.prefab_index)?), - // true, - // ); + net.broadcast( + Packet::PrefabIndex(self.store.set(&self.prefab_index)?), + true, + ); for p in self.tree.prime_client() { net.send(conn, p, true); } diff --git a/shared/src/helper.rs b/shared/src/helper.rs index d91313c..706e36b 100644 --- a/shared/src/helper.rs +++ b/shared/src/helper.rs @@ -126,3 +126,11 @@ impl<T: ReadWrite, const N: usize> ReadWrite for [T; N] { [(); N].try_map(|()| T::read(r)) } } +impl ReadWrite for () { + fn write(&self, _w: &mut dyn Write) -> Result<()> { + Ok(()) + } + fn read(_r: &mut dyn Read) -> Result<Self> { + Ok(()) + } +} diff --git a/shared/src/resources.rs b/shared/src/resources.rs index 25dd965..7a52e85 100644 --- a/shared/src/resources.rs +++ b/shared/src/resources.rs @@ -57,6 +57,7 @@ pub struct MeshPart { pub g_refractive_index: Option<f32>, pub g_attenuation: Option<Vec3A>, pub g_dispersion: Option<f32>, + pub g_unlit: Option<()>, pub va_position: Option<[Resource<AttributeArray>; 3]>, pub va_normal: Option<[Resource<AttributeArray>; 3]>, pub va_texcoord: Option<[Resource<AttributeArray>; 2]>, @@ -183,6 +184,7 @@ impl ReadWrite for MeshPart { write_kv_opt(w, b"g_transmission", &self.g_transmission)?; write_kv_opt(w, b"g_alpha", &self.g_alpha)?; write_kv_opt(w, b"g_emission", &self.g_emission)?; + write_kv_opt(w, b"g_unlit", &self.g_unlit)?; write_kv_opt(w, b"va_position", &self.va_position)?; write_kv_opt(w, b"va_normal", &self.va_normal)?; write_kv_opt(w, b"va_texcoord", &self.va_texcoord)?; diff --git a/world/src/main.rs b/world/src/main.rs index 7f531b4..af32222 100644 --- a/world/src/main.rs +++ b/world/src/main.rs @@ -19,7 +19,7 @@ pub mod mesh; use anyhow::{Result, bail}; use clap::Parser; -use gltf::image::Source; +use gltf::{Gltf, image::Source, import_buffers}; use image::{ImageReader, codecs::webp::WebPEncoder}; use log::info; use mesh::import_mesh; @@ -78,10 +78,21 @@ fn main() -> Result<()> { Packet::Connect(random()).write(&mut sock)?; - let (gltf, buffers, _) = gltf::import(&args.scene)?; + // let (gltf, buffers, _) = gltf::import(&args.scene)?; let path_base = args.scene.parent().unwrap(); + let gltf = Gltf::from_reader_without_validation(File::open(&args.scene)?)?; + + let buffers = import_buffers(&gltf, Some(path_base), None)?; + let mut prefab = Prefab::default(); + + prefab.name = gltf + .default_scene() + .map(|n| n.name()) + .flatten() + .map(|n| n.to_owned()); + for node in gltf.nodes() { if let Some(mesh) = node.mesh() { import_mesh( diff --git a/world/src/mesh.rs b/world/src/mesh.rs index 2c868ab..1f19c28 100644 --- a/world/src/mesh.rs +++ b/world/src/mesh.rs @@ -308,6 +308,17 @@ pub fn import_mesh( info!("name is {name:?}"); } + let g_unlit = if p + .material() + .extensions() + .map(|e| e.contains_key("KHR_materials_unlit")) + .unwrap_or(false) + { + Some(()) + } else { + None + }; + let mesh = store.set(&MeshPart { name, index, @@ -321,6 +332,7 @@ pub fn import_mesh( g_thickness, g_refractive_index, g_dispersion, + g_unlit, va_position, va_normal, va_texcoord, |