diff options
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(), |