From 2e3912fbc8d0e2c100a8d75bd2e8d3a579d25db0 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Mon, 20 Jan 2025 19:49:46 +0100 Subject: armature --- shared/src/helper.rs | 42 ++++++++++++++++++++++++++++++++++++++++++ shared/src/resources.rs | 25 +++++++++++++++++++++++++ 2 files changed, 67 insertions(+) (limited to 'shared') diff --git a/shared/src/helper.rs b/shared/src/helper.rs index d46a830..723f91e 100644 --- a/shared/src/helper.rs +++ b/shared/src/helper.rs @@ -161,6 +161,48 @@ impl ReadWrite for Vec<[u32; 3]> { .collect()) } } +impl ReadWrite for Vec<[u16; 4]> { + fn write(&self, w: &mut dyn Write) -> Result<()> { + for e in self { + w.write_all(&e[0].to_be_bytes())?; + w.write_all(&e[1].to_be_bytes())?; + w.write_all(&e[2].to_be_bytes())?; + w.write_all(&e[3].to_be_bytes())?; + } + Ok(()) + } + fn read(r: &mut dyn Read) -> Result { + let mut buf = Vec::new(); + r.read_to_end(&mut buf)?; + Ok(buf + .into_iter() + .array_chunks::<{ size_of::() }>() + .map(u16::from_be_bytes) + .array_chunks::<4>() + .collect()) + } +} +impl ReadWrite for Vec<[f32; 4]> { + fn write(&self, w: &mut dyn Write) -> Result<()> { + for e in self { + w.write_all(&e[0].to_be_bytes())?; + w.write_all(&e[1].to_be_bytes())?; + w.write_all(&e[2].to_be_bytes())?; + w.write_all(&e[3].to_be_bytes())?; + } + Ok(()) + } + fn read(r: &mut dyn Read) -> Result { + let mut buf = Vec::new(); + r.read_to_end(&mut buf)?; + Ok(buf + .into_iter() + .array_chunks::<{ size_of::() }>() + .map(f32::from_be_bytes) + .array_chunks::<4>() + .collect()) + } +} impl ReadWrite for Vec { fn write(&self, w: &mut dyn Write) -> Result<()> { for e in self { diff --git a/shared/src/resources.rs b/shared/src/resources.rs index 54a34b8..59d88b6 100644 --- a/shared/src/resources.rs +++ b/shared/src/resources.rs @@ -50,6 +50,7 @@ pub struct EnvironmentPart { pub struct MeshPart { pub name: Option, pub index: Option>>, + pub armature: Option, pub g_metallic: Option, pub g_roughness: Option, pub g_albedo: Option, @@ -72,6 +73,8 @@ pub struct MeshPart { pub va_transmission: Option>>, pub va_alpha: Option>>, pub va_emission: Option>>, + pub va_joint_index: Option>>, + pub va_joint_weight: Option>>, pub tex_normal: Option>>, pub tex_roughness: Option>>, pub tex_metallic: Option>>, @@ -81,6 +84,14 @@ pub struct MeshPart { pub tex_emission: Option>>, pub tex_thickness: Option>>, pub tex_occlusion: Option>>, + pub hint_mirror: Option<()>, +} + +#[derive(Debug, Default, Clone)] +pub struct Armature { + pub parent: Option>, + pub transform: Option>, + pub name: Option>, } #[derive(Debug, Default, Clone)] @@ -122,6 +133,14 @@ impl ReadWrite for PrefabIndex { } } +impl ReadWrite for Armature { + fn write(&self, w: &mut dyn Write) -> Result<()> { + todo!() + } + fn read(r: &mut dyn Read) -> Result { + todo!() + } +} impl ReadWrite for CollisionPart { fn write(&self, w: &mut dyn Write) -> Result<()> { write_kv_opt(w, b"restitution_coeff", &self.restitution_coeff)?; @@ -249,6 +268,8 @@ impl ReadWrite for MeshPart { write_kv_opt(w, b"va_transmission", &self.va_transmission)?; write_kv_opt(w, b"va_alpha", &self.va_transmission)?; write_kv_opt(w, b"va_emission", &self.va_emission)?; + write_kv_opt(w, b"va_joint_weight", &self.va_joint_weight)?; + write_kv_opt(w, b"va_joint_index", &self.va_joint_index)?; write_kv_opt(w, b"tex_normal", &self.tex_normal)?; write_kv_opt(w, b"tex_roughness", &self.tex_roughness)?; write_kv_opt(w, b"tex_metallic", &self.tex_metallic)?; @@ -257,6 +278,7 @@ impl ReadWrite for MeshPart { write_kv_opt(w, b"tex_alpha", &self.tex_alpha)?; write_kv_opt(w, b"tex_emission", &self.tex_emission)?; write_kv_opt(w, b"tex_occlusion", &self.tex_occlusion)?; + write_kv_opt(w, b"hint_mirror", &self.hint_mirror)?; Ok(()) } fn read(r: &mut dyn Read) -> Result { @@ -282,6 +304,8 @@ impl ReadWrite for MeshPart { b"va_transmission" => Ok(s.va_transmission = Some(read_slice(v)?)), b"va_alpha" => Ok(s.va_alpha = Some(read_slice(v)?)), b"va_emission" => Ok(s.va_emission = Some(read_slice(v)?)), + b"va_joint_weight" => Ok(s.va_joint_weight = Some(read_slice(v)?)), + b"va_joint_index" => Ok(s.va_joint_index = Some(read_slice(v)?)), b"tex_normal" => Ok(s.tex_normal = Some(read_slice(v)?)), b"tex_roughness" => Ok(s.tex_roughness = Some(read_slice(v)?)), b"tex_metallic" => Ok(s.tex_metallic = Some(read_slice(v)?)), @@ -290,6 +314,7 @@ impl ReadWrite for MeshPart { b"tex_alpha" => Ok(s.tex_alpha = Some(read_slice(v)?)), b"tex_emission" => Ok(s.tex_emission = Some(read_slice(v)?)), b"tex_occlusion" => Ok(s.tex_occlusion = Some(read_slice(v)?)), + b"hint_mirror" => Ok(s.hint_mirror = Some(read_slice(v)?)), x => Ok(warn!( "unknown mesh part key: {:?}", String::from_utf8_lossy(x) -- cgit v1.2.3-70-g09d2