diff options
Diffstat (limited to 'world/src')
-rw-r--r-- | world/src/main.rs | 85 |
1 files changed, 45 insertions, 40 deletions
diff --git a/world/src/main.rs b/world/src/main.rs index 61f895f..a31ef63 100644 --- a/world/src/main.rs +++ b/world/src/main.rs @@ -44,7 +44,7 @@ use weareshared::{ Affine3A, Vec3A, helper::ReadWrite, packets::{Data, Object, Packet, Resource}, - resources::{EnvironmentPart, Image, LightPart, Prefab}, + resources::{Armature, EnvironmentPart, Image, LightPart, Prefab}, store::ResourceStore, vec3a, }; @@ -118,50 +118,55 @@ 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<String>, &mut Vec<Affine3A>, &mut Vec<u16>), + trans: Affine3A, + parent: Option<u16>, + 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::<Result<Vec<_>>>()?; + + eprintln!("{armatures:?}"); + let mut prefab = nodes .par_iter() .map(|(trans, node)| { let mut prefab = Prefab::default(); - // if let Some(skin) = node.skin() { - // eprintln!("{:?}", skin.joints().map(|j| j.name()).collect::<Vec<_>>()); - // if let Some(root) = skin.skeleton() { - // fn traverse( - // ars: &mut (&mut Vec<String>, &mut Vec<Affine3A>, &mut Vec<u16>), - // trans: Affine3A, - // parent: Option<u16>, - // node: &Node, - // ) { - // let trans = trans * transform_to_affine(node.transform()); - // let ind = ars.0.len() as u16; - // // print!("{} ", node.index()); - // 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, - // ); - // // println!(); - // let armature = Armature { - // name: Some(name), - // parent: Some(parent), - // transform: Some(transform), - // }; - // let armature = store.set(&armature)?; - // // eprintln!("{armature:?}") - // } - // } - if let Some(mesh) = node.mesh() { import_mesh( mesh, |