summaryrefslogtreecommitdiff
path: root/world/src/main.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2025-02-03 21:46:29 +0100
committermetamuffin <metamuffin@disroot.org>2025-02-03 21:46:29 +0100
commitae14c194a25e258659104e89553ad48a8ae9ca3b (patch)
tree793b73af2c045d7acf218912afbc182a6720436f /world/src/main.rs
parent163e10c9f618f0e4cd7b4456476ad1c2322db5d7 (diff)
downloadweareserver-ae14c194a25e258659104e89553ad48a8ae9ca3b.tar
weareserver-ae14c194a25e258659104e89553ad48a8ae9ca3b.tar.bz2
weareserver-ae14c194a25e258659104e89553ad48a8ae9ca3b.tar.zst
armatures in prefab
Diffstat (limited to 'world/src/main.rs')
-rw-r--r--world/src/main.rs87
1 files changed, 41 insertions, 46 deletions
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<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)| {
@@ -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<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 = ArmaturePart {
+ name: Some(name),
+ parent: Some(parent),
+ transform: Some(transform),
+ };
+ store.set(&armature)
+ } else {
+ store.set(&ArmaturePart::default())
+ }
+ })
+ .collect::<Result<Vec<_>>>()?;
+
if let Some(skybox) = &args.skybox {
let mut buf = Vec::new();
File::open(skybox)?.read_to_end(&mut buf)?;