diff options
author | metamuffin <metamuffin@disroot.org> | 2025-02-25 20:45:14 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2025-02-25 20:45:14 +0100 |
commit | e642e804f6309796117a4f823a42eb8f49d12809 (patch) | |
tree | 0479d2eeae396e1309701b6f60780f784132e4cc /world/src/animation.rs | |
parent | be22ec62f2f692b5dc4ca0b334d905164fb45ff2 (diff) | |
download | weareserver-e642e804f6309796117a4f823a42eb8f49d12809.tar weareserver-e642e804f6309796117a4f823a42eb8f49d12809.tar.bz2 weareserver-e642e804f6309796117a4f823a42eb8f49d12809.tar.zst |
pre applying ibm is hard
Diffstat (limited to 'world/src/animation.rs')
-rw-r--r-- | world/src/animation.rs | 38 |
1 files changed, 22 insertions, 16 deletions
diff --git a/world/src/animation.rs b/world/src/animation.rs index cb10123..3473371 100644 --- a/world/src/animation.rs +++ b/world/src/animation.rs @@ -15,6 +15,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>. */ use anyhow::Result; +use glam::Quat; use gltf::{ Animation, animation::{Property, util::ReadOutputs}, @@ -43,23 +44,28 @@ pub fn import_animation<'a>( let node = c.target().node().index(); let reader = c.reader(|i| Some(&buffers[i.index()].0)); let inputs: Vec<f32> = reader.read_inputs().unwrap().collect::<Vec<f32>>(); - let outputs: Vec<f32> = if let Some(_ibm) = joint_index_to_ibm.get(&node) { + let outputs: Vec<f32> = if let Some(ibm) = joint_index_to_ibm.get(&node) { debug!("pre-applying inverse bind matricies"); - // let ibm = - // match reader.read_outputs().unwrap() { - // // ReadOutputs::Translations(iter) => iter - // // .flat_map(|[x, y, z]| (ibm.matrix3 * vec3a(x, y, z)).to_array()) - // // .collect(), - // ReadOutputs::Rotations(iter) => iter.into_f32().map(|[a,b,c,d]| { - - // }).flatten().collect(), - // // ReadOutputs::Scales(iter) => iter - // // .flat_map(|[x, y, z]| (ibm.matrix3 * vec3a(x, y, z)).to_array()) - // // .collect(), - // ReadOutputs::MorphTargetWeights(iter) => iter.into_f32().collect(), - // _ => continue, - // } - todo!() + let ibm = ibm.inverse(); + // eprintln!("{:#?}", ibm); + let (_, ibm_rot, _) = ibm.to_scale_rotation_translation(); + match reader.read_outputs().unwrap() { + // ReadOutputs::Translations(iter) => iter + // .flat_map(|[x, y, z]| (ibm.matrix3 * vec3a(x, y, z)).to_array()) + // .collect(), + ReadOutputs::Rotations(iter) => iter + .into_f32() + .map(Quat::from_array) + .map(|q| ibm_rot.mul_quat(q)) + .map(|q| q.to_array()) + .flatten() + .collect(), + // ReadOutputs::Scales(iter) => iter + // .flat_map(|[x, y, z]| (ibm.matrix3 * vec3a(x, y, z)).to_array()) + // .collect(), + ReadOutputs::MorphTargetWeights(iter) => iter.into_f32().collect(), + _ => continue, + } } else { match reader.read_outputs().unwrap() { ReadOutputs::Translations(iter) => iter.flatten().collect(), |