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:
parent
5ca60cb95d
commit
214e5495fe
3 changed files with 26 additions and 20 deletions
7
Cargo.lock
generated
7
Cargo.lock
generated
|
@ -248,6 +248,12 @@ version = "1.7.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3f107b87b6afc2a64fd13cac55fe06d6c8859f12d4b14cbcdd2c67d0976781be"
|
||||
|
||||
[[package]]
|
||||
name = "glam"
|
||||
version = "0.21.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "518faa5064866338b013ff9b2350dc318e14cc4fcd6cb8206d7e7c9886c98815"
|
||||
|
||||
[[package]]
|
||||
name = "half"
|
||||
version = "1.8.2"
|
||||
|
@ -437,6 +443,7 @@ dependencies = [
|
|||
"bitfield-struct",
|
||||
"crc",
|
||||
"criterion",
|
||||
"glam",
|
||||
"half",
|
||||
"hard-xml",
|
||||
"libz-sys",
|
||||
|
|
|
@ -47,3 +47,6 @@ serde = { version = "1.0", features = ["derive"] }
|
|||
|
||||
# needed for file info (fiin)
|
||||
sha1_smol = "1.0.0"
|
||||
|
||||
# needed for deconstructing skeleton pose matrices
|
||||
glam = "0.21.3"
|
|
@ -1,19 +1,20 @@
|
|||
use crate::gamedata::MemoryBuffer;
|
||||
use hard_xml::XmlRead;
|
||||
use glam::Mat4;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Bone {
|
||||
name: String,
|
||||
parent_index: usize,
|
||||
pub name: String,
|
||||
pub parent_index: i32,
|
||||
|
||||
position: [f32; 3],
|
||||
rotation: [f32; 4],
|
||||
scale: [f32; 3]
|
||||
pub position: [f32; 3],
|
||||
pub rotation: [f32; 4],
|
||||
pub scale: [f32; 3]
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Skeleton {
|
||||
bones : Vec<Bone>
|
||||
pub bones : Vec<Bone>
|
||||
}
|
||||
|
||||
impl Skeleton {
|
||||
|
@ -116,24 +117,19 @@ impl Skeleton {
|
|||
};
|
||||
|
||||
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 {
|
||||
name: bone.bone_name.clone(),
|
||||
parent_index: 0,
|
||||
position: [0.0; 3],
|
||||
rotation: [0.0; 4],
|
||||
scale: [0.0; 3]
|
||||
parent_index: bone.bone_parent,
|
||||
position: translation.to_array(),
|
||||
rotation: rotation.to_array(),
|
||||
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)
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue