1
Fork 0
mirror of https://github.com/redstrate/Physis.git synced 2025-04-23 13:17:44 +00:00

Properly set bone parenting Skeleton::from_skel, export bone transforms

This commit is contained in:
Joshua Goins 2022-08-10 14:52:11 -04:00
parent 5ca60cb95d
commit 214e5495fe
3 changed files with 26 additions and 20 deletions

7
Cargo.lock generated
View file

@ -248,6 +248,12 @@ version = "1.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3f107b87b6afc2a64fd13cac55fe06d6c8859f12d4b14cbcdd2c67d0976781be" checksum = "3f107b87b6afc2a64fd13cac55fe06d6c8859f12d4b14cbcdd2c67d0976781be"
[[package]]
name = "glam"
version = "0.21.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "518faa5064866338b013ff9b2350dc318e14cc4fcd6cb8206d7e7c9886c98815"
[[package]] [[package]]
name = "half" name = "half"
version = "1.8.2" version = "1.8.2"
@ -437,6 +443,7 @@ dependencies = [
"bitfield-struct", "bitfield-struct",
"crc", "crc",
"criterion", "criterion",
"glam",
"half", "half",
"hard-xml", "hard-xml",
"libz-sys", "libz-sys",

View file

@ -46,4 +46,7 @@ serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
# needed for file info (fiin) # needed for file info (fiin)
sha1_smol = "1.0.0" sha1_smol = "1.0.0"
# needed for deconstructing skeleton pose matrices
glam = "0.21.3"

View file

@ -1,19 +1,20 @@
use crate::gamedata::MemoryBuffer; use crate::gamedata::MemoryBuffer;
use hard_xml::XmlRead; use hard_xml::XmlRead;
use glam::Mat4;
#[derive(Debug)] #[derive(Debug)]
pub struct Bone { pub struct Bone {
name: String, pub name: String,
parent_index: usize, pub parent_index: i32,
position: [f32; 3], pub position: [f32; 3],
rotation: [f32; 4], pub rotation: [f32; 4],
scale: [f32; 3] pub scale: [f32; 3]
} }
#[derive(Debug)] #[derive(Debug)]
pub struct Skeleton { pub struct Skeleton {
bones : Vec<Bone> pub bones : Vec<Bone>
} }
impl Skeleton { impl Skeleton {
@ -116,24 +117,19 @@ impl Skeleton {
}; };
for bone in &json_bones { for bone in &json_bones {
let pose_matrix = Mat4::from_cols_array(&bone.pose_matrix);
let (scale, rotation, translation) = pose_matrix.to_scale_rotation_translation();
skeleton.bones.push(Bone { skeleton.bones.push(Bone {
name: bone.bone_name.clone(), name: bone.bone_name.clone(),
parent_index: 0, parent_index: bone.bone_parent,
position: [0.0; 3], position: translation.to_array(),
rotation: [0.0; 4], rotation: rotation.to_array(),
scale: [0.0; 3] scale: scale.to_array()
}); });
} }
// assign parenting
for bone in &json_bones {
if bone.bone_parent != -1 {
let mut new_bone = &mut skeleton.bones[bone.bone_number as usize];
new_bone.parent_index = bone.bone_parent as usize;
}
}
Some(skeleton) Some(skeleton)
} }
} }