physis/havok/
animation_binding.rs1#![allow(dead_code)]
5
6use crate::havok::HavokAnimation;
7use crate::havok::object::HavokObject;
8use crate::havok::spline_compressed_animation::HavokSplineCompressedAnimation;
9use core::cell::RefCell;
10use std::sync::Arc;
11
12#[repr(u8)]
13pub enum HavokAnimationBlendHint {
14 Normal = 0,
15 Additive = 1,
16}
17
18impl HavokAnimationBlendHint {
19 pub fn from_raw(raw: u8) -> Self {
20 match raw {
21 0 => Self::Normal,
22 1 => Self::Additive,
23 _ => panic!(),
24 }
25 }
26}
27
28pub struct HavokAnimationBinding {
29 pub transform_track_to_bone_indices: Vec<u16>,
30 pub blend_hint: HavokAnimationBlendHint,
31 pub animation: Box<dyn HavokAnimation>,
32}
33
34impl HavokAnimationBinding {
35 pub fn new(object: Arc<RefCell<HavokObject>>) -> Self {
36 let root = object.borrow();
37
38 let raw_transform_track_to_bone_indices =
39 root.get("transformTrackToBoneIndices").as_array();
40 let transform_track_to_bone_indices = raw_transform_track_to_bone_indices
41 .iter()
42 .map(|x| x.as_int() as u16)
43 .collect::<Vec<_>>();
44
45 let blend_hint = HavokAnimationBlendHint::from_raw(root.get("blendHint").as_int() as u8);
46
47 let raw_animation = root.get("animation").as_object();
48 let animation = match &*raw_animation.borrow().object_type.name {
49 "hkaSplineCompressedAnimation" => {
50 Box::new(HavokSplineCompressedAnimation::new(raw_animation.clone()))
51 }
52 _ => panic!(),
53 };
54
55 Self {
56 transform_track_to_bone_indices,
57 blend_hint,
58 animation,
59 }
60 }
61}