summaryrefslogtreecommitdiff
path: root/world/src
diff options
context:
space:
mode:
Diffstat (limited to 'world/src')
-rw-r--r--world/src/main.rs87
-rw-r--r--world/src/mesh.rs10
2 files changed, 43 insertions, 54 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)?;
diff --git a/world/src/mesh.rs b/world/src/mesh.rs
index 8afefb4..b0b55b7 100644
--- a/world/src/mesh.rs
+++ b/world/src/mesh.rs
@@ -21,7 +21,7 @@ use log::{debug, info};
use std::path::Path;
use weareshared::{
Affine3A, Vec3A,
- resources::{Armature, MeshPart, Prefab},
+ resources::{MeshPart, Prefab},
store::ResourceStore,
vec2, vec3a, vec4,
};
@@ -36,7 +36,6 @@ pub fn import_mesh(
prefab: &mut Prefab,
args: &Args,
texture_cache: &TextureCache,
- armatures: &[Option<Armature>],
) -> Result<()> {
for p in mesh.primitives() {
let name = mesh.name().or(node.name()).map(|e| e.to_owned());
@@ -336,12 +335,7 @@ pub fn import_mesh(
None
};
- let mut armature = None;
- if let Some(skin) = node.skin() {
- if let Some(a) = &armatures[skin.index()] {
- armature = Some(store.set(a)?);
- }
- }
+ let armature = node.skin().map(|s| s.index() as u32);
let mesh = store.set(&MeshPart {
name,