diff options
Diffstat (limited to 'world')
-rw-r--r-- | world/Cargo.toml | 1 | ||||
-rw-r--r-- | world/src/animation.rs | 38 | ||||
-rw-r--r-- | world/src/main.rs | 2 | ||||
-rw-r--r-- | world/src/vrm.rs | 1 |
4 files changed, 24 insertions, 18 deletions
diff --git a/world/Cargo.toml b/world/Cargo.toml index cb47c70..8ce9a77 100644 --- a/world/Cargo.toml +++ b/world/Cargo.toml @@ -25,3 +25,4 @@ image = "0.25.5" rayon = "1.10.0" humansize = "2.1.3" serde_json = "1.0.138" +glam = "0.29.2" 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(), diff --git a/world/src/main.rs b/world/src/main.rs index be39a4a..14a4477 100644 --- a/world/src/main.rs +++ b/world/src/main.rs @@ -438,7 +438,7 @@ fn main() -> Result<()> { prefab.animation.push(import_animation( a, &store, - &BTreeMap::new(), + &joint_index_to_ibm, &anim_joint_index_to_arm_index, &BTreeMap::new(), &buffers, diff --git a/world/src/vrm.rs b/world/src/vrm.rs index 80865cb..c408b1d 100644 --- a/world/src/vrm.rs +++ b/world/src/vrm.rs @@ -59,7 +59,6 @@ pub fn extract_vrm_data(gltf: &Gltf) -> Result<VrmInfo> { } } } - eprintln!("{o:#?}"); Ok(o) } |