1
Fork 0
mirror of https://github.com/redstrate/Physis.git synced 2025-05-03 09:17:46 +00:00
physis/src/havok/animation_binding.rs

60 lines
1.7 KiB
Rust
Raw Normal View History

// SPDX-FileCopyrightText: 2020 Inseok Lee
// SPDX-License-Identifier: MIT
use crate::havok::object::HavokObject;
use crate::havok::spline_compressed_animation::HavokSplineCompressedAnimation;
2024-04-20 13:18:03 -04:00
use crate::havok::HavokAnimation;
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();
2024-04-20 13:18:03 -04:00
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 {
2024-04-20 13:18:03 -04:00
"hkaSplineCompressedAnimation" => {
Box::new(HavokSplineCompressedAnimation::new(raw_animation.clone()))
}
_ => panic!(),
};
Self {
transform_track_to_bone_indices,
blend_hint,
animation,
}
}
}