diff options
author | metamuffin <metamuffin@disroot.org> | 2025-01-21 18:02:07 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2025-01-21 18:02:07 +0100 |
commit | 20d5d575ad84da3d37bd581425fc335016f33c82 (patch) | |
tree | c4c9db916c838a293c3ee44effb9460c2f034d70 | |
parent | 8ec1b82052cfe6d73be988a7e22a10fdc8f6e1f3 (diff) | |
download | weareserver-20d5d575ad84da3d37bd581425fc335016f33c82.tar weareserver-20d5d575ad84da3d37bd581425fc335016f33c82.tar.bz2 weareserver-20d5d575ad84da3d37bd581425fc335016f33c82.tar.zst |
world: prepare skin loading
-rw-r--r-- | client/src/meshops.rs | 16 | ||||
-rw-r--r-- | world/src/main.rs | 85 |
2 files changed, 61 insertions, 40 deletions
diff --git a/client/src/meshops.rs b/client/src/meshops.rs index afa50ce..0a3f963 100644 --- a/client/src/meshops.rs +++ b/client/src/meshops.rs @@ -1,3 +1,19 @@ +/* + wearechat - generic multiplayer game with voip + Copyright (C) 2025 metamuffin + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, version 3 of the License only. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. +*/ use glam::{Vec2, Vec3, vec2}; pub fn generate_normals(index: &[[u32; 3]], position: &[Vec3]) -> Vec<Vec3> { 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, |