1
Fork 0
mirror of https://github.com/redstrate/Physis.git synced 2025-05-02 08:47:45 +00:00
physis/src/havok/animation_binding.rs
Joshua Goins bb7c74fec8 Redesign how IndexFile parsing works, again
Now it reads much more of the index file format, and tries to handle
index1/index2 differences more opaquely. I'm not yet happy with the API, it
needs a bit more work.
2025-03-06 18:52:26 -05:00

61 lines
1.7 KiB
Rust

// SPDX-FileCopyrightText: 2020 Inseok Lee
// SPDX-License-Identifier: MIT
#![allow(dead_code)]
use crate::havok::HavokAnimation;
use crate::havok::object::HavokObject;
use crate::havok::spline_compressed_animation::HavokSplineCompressedAnimation;
use core::cell::RefCell;
use std::sync::Arc;
#[repr(u8)]
pub enum HavokAnimationBlendHint {
Normal = 0,
Additive = 1,
}
impl HavokAnimationBlendHint {
pub fn from_raw(raw: u8) -> Self {
match raw {
0 => Self::Normal,
1 => Self::Additive,
_ => panic!(),
}
}
}
pub struct HavokAnimationBinding {
pub transform_track_to_bone_indices: Vec<u16>,
pub blend_hint: HavokAnimationBlendHint,
pub animation: Box<dyn HavokAnimation>,
}
impl HavokAnimationBinding {
pub fn new(object: Arc<RefCell<HavokObject>>) -> Self {
let root = object.borrow();
let raw_transform_track_to_bone_indices =
root.get("transformTrackToBoneIndices").as_array();
let transform_track_to_bone_indices = raw_transform_track_to_bone_indices
.iter()
.map(|x| x.as_int() as u16)
.collect::<Vec<_>>();
let blend_hint = HavokAnimationBlendHint::from_raw(root.get("blendHint").as_int() as u8);
let raw_animation = root.get("animation").as_object();
let animation = match &*raw_animation.borrow().object_type.name {
"hkaSplineCompressedAnimation" => {
Box::new(HavokSplineCompressedAnimation::new(raw_animation.clone()))
}
_ => panic!(),
};
Self {
transform_track_to_bone_indices,
blend_hint,
animation,
}
}
}