From ae14c194a25e258659104e89553ad48a8ae9ca3b Mon Sep 17 00:00:00 2001 From: metamuffin Date: Mon, 3 Feb 2025 21:46:29 +0100 Subject: armatures in prefab --- world/src/main.rs | 87 ++++++++++++++++++++++++++----------------------------- 1 file changed, 41 insertions(+), 46 deletions(-) (limited to 'world/src/main.rs') diff --git a/world/src/main.rs b/world/src/main.rs index b0b9dad..67747c8 100644 --- a/world/src/main.rs +++ b/world/src/main.rs @@ -45,7 +45,7 @@ use weareshared::{ Affine3A, Vec3A, helper::ReadWrite, packets::{Data, Object, Packet, Resource}, - resources::{Armature, EnvironmentPart, Image, LightPart, Prefab}, + resources::{ArmaturePart, EnvironmentPart, Image, LightPart, Prefab}, store::ResourceStore, vec3a, }; @@ -126,50 +126,6 @@ fn main() -> Result<()> { traverse(&mut nodes, node, root_affine); } - let armatures = gltf - .skins() - .map(|skin| { - if let Some(root) = skin.skeleton() { - fn traverse( - ars: &mut (&mut Vec, &mut Vec, &mut Vec), - trans: Affine3A, - parent: Option, - node: &Node, - ) { - let trans = trans * transform_to_affine(node.transform()); - let ind = ars.0.len() as u16; - ars.0.push(node.name().unwrap_or("").to_owned()); - ars.1.push(trans); - ars.2.push(parent.unwrap_or(ind)); - for c in node.children() { - traverse(ars, trans, Some(ind), &c); - } - } - let mut name = Vec::new(); - let mut transform = Vec::new(); - let mut parent = Vec::new(); - traverse( - &mut (&mut name, &mut transform, &mut parent), - Affine3A::IDENTITY, - None, - &root, - ); - let armature = Armature { - name: Some(name), - parent: Some(parent), - transform: Some(transform), - }; - // let armature = store.set(&armature)?; - // eprintln!("{armature:?}") - Ok::<_, anyhow::Error>(Some(armature)) - } else { - Ok::<_, anyhow::Error>(None) - } - }) - .collect::>>()?; - - eprintln!("{armatures:?}"); - let mut prefab = nodes .par_iter() .map(|(trans, node)| { @@ -186,7 +142,6 @@ fn main() -> Result<()> { &mut prefab, &args, &texture_cache, - &armatures, )?; } let (position, _, _) = node.transform().decomposed(); @@ -227,6 +182,46 @@ fn main() -> Result<()> { }, )?; + prefab.armature = gltf + .skins() + .map(|skin| { + if let Some(root) = skin.skeleton() { + fn traverse( + ars: &mut (&mut Vec, &mut Vec, &mut Vec), + trans: Affine3A, + parent: Option, + node: &Node, + ) { + let trans = trans * transform_to_affine(node.transform()); + let ind = ars.0.len() as u16; + ars.0.push(node.name().unwrap_or("").to_owned()); + ars.1.push(trans); + ars.2.push(parent.unwrap_or(ind)); + for c in node.children() { + traverse(ars, trans, Some(ind), &c); + } + } + let mut name = Vec::new(); + let mut transform = Vec::new(); + let mut parent = Vec::new(); + traverse( + &mut (&mut name, &mut transform, &mut parent), + Affine3A::IDENTITY, + None, + &root, + ); + let armature = ArmaturePart { + name: Some(name), + parent: Some(parent), + transform: Some(transform), + }; + store.set(&armature) + } else { + store.set(&ArmaturePart::default()) + } + }) + .collect::>>()?; + if let Some(skybox) = &args.skybox { let mut buf = Vec::new(); File::open(skybox)?.read_to_end(&mut buf)?; -- cgit v1.2.3-70-g09d2