blender_armature/action/action_keyframes/sample.rs
1use std::collections::BTreeMap;
2
3use crate::{interpolate_bone, ActionKeyframes, Bone};
4
5pub use self::joint_indices::*;
6pub use self::sample_desc::*;
7pub use self::surrounding_keyframes::get_surrounding_keyframes;
8
9mod joint_indices;
10mod sample_desc;
11mod surrounding_keyframes;
12
13impl ActionKeyframes {
14 /// Sample the bone transforms from the action
15 pub fn sample(&self, joint_indices: &[u8], sample_desc: SampleDesc) -> BTreeMap<u8, Bone> {
16 // let mut interpolated_bones = BTreeMap::new();
17 //
18 // if joint_indices.len() == 0 {
19 // return interpolated_bones;
20 // }
21 //
22 // let keyframes = self.keyframes();
23 //
24 // let (lowest_keyframe, highest_keyframe) =
25 // (self.smallest_frame as f32, self.largest_frame as f32);
26 //
27 // let mut frames_elapsed = sample_desc.frame_offset.get();
28 //
29 // let mut key_time_to_sample = lowest_keyframe as f32 + frames_elapsed;
30 //
31 // let action_duration = (highest_keyframe - lowest_keyframe) as f32;
32 //
33 // if frames_elapsed > action_duration {
34 // if sample_desc.should_loop {
35 // frames_elapsed = frames_elapsed % action_duration;
36 // } else {
37 // frames_elapsed = action_duration;
38 // }
39 //
40 // key_time_to_sample = lowest_keyframe as f32 + frames_elapsed;
41 // }
42 //
43 // let (action_lower_keyframe, action_upper_keyframe) =
44 // get_surrounding_keyframes(keyframes, key_time_to_sample);
45 //
46 // let percent_elapsed_into_keyframe = if action_lower_keyframe == action_upper_keyframe {
47 // 0.0
48 // } else {
49 // (key_time_to_sample - action_lower_keyframe.frame as f32)
50 // / (action_upper_keyframe.frame - action_lower_keyframe.frame) as f32
51 // };
52 //
53 // for joint_index in joint_indices.iter() {
54 // let joint_index = *joint_index;
55 //
56 // let lower_bone = &action_lower_keyframe.bones[joint_index as usize];
57 // let upper_bone = &action_upper_keyframe.bones[joint_index as usize];
58 //
59 // let interpolated_bone =
60 // interpolate_bone(&lower_bone, &upper_bone, percent_elapsed_into_keyframe);
61 // interpolated_bones.insert(joint_index, interpolated_bone);
62 // }
63 //
64 // interpolated_bones
65 unimplemented!()
66 }
67}