add graph/visualization for interpolated keyframes
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -2,12 +2,20 @@ use super::{
|
||||
entities::common::AnimationData,
|
||||
keyframe::{Keyframe, Keyframes},
|
||||
};
|
||||
use rayon::prelude::{IndexedParallelIterator, IntoParallelIterator, ParallelIterator};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
pub trait AnimatedValue<T> {
|
||||
fn sort_keyframes(&mut self);
|
||||
fn get_value_at_frame(&self, curr_frame: i32, animation_data: &AnimationData, fps: i16) -> T;
|
||||
fn get_values_at_frame_range(
|
||||
&self,
|
||||
start_frame: i32,
|
||||
end_frame: i32,
|
||||
animation_data: &AnimationData,
|
||||
fps: i16,
|
||||
) -> Vec<T>;
|
||||
}
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
pub struct AnimatedFloat {
|
||||
@@ -24,6 +32,39 @@ pub struct AnimatedFloatVec3 {
|
||||
pub keyframes: (AnimatedFloat, AnimatedFloat, AnimatedFloat),
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn get_values_at_frame_range_from_animated_float(
|
||||
animated_value: AnimatedFloat,
|
||||
start_frame: i32,
|
||||
end_frame: i32,
|
||||
animation_data: AnimationData,
|
||||
fps: i16,
|
||||
) -> Vec<f32> {
|
||||
animated_value.get_values_at_frame_range(start_frame, end_frame, &animation_data, fps)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn get_values_at_frame_range_from_animated_float_vec2(
|
||||
animated_value: AnimatedFloatVec2,
|
||||
start_frame: i32,
|
||||
end_frame: i32,
|
||||
animation_data: AnimationData,
|
||||
fps: i16,
|
||||
) -> Vec<(f32, f32)> {
|
||||
animated_value.get_values_at_frame_range(start_frame, end_frame, &animation_data, fps)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub fn get_values_at_frame_range_from_animated_float_vec3(
|
||||
animated_value: AnimatedFloatVec3,
|
||||
start_frame: i32,
|
||||
end_frame: i32,
|
||||
animation_data: AnimationData,
|
||||
fps: i16,
|
||||
) -> Vec<(f32, f32, f32)> {
|
||||
animated_value.get_values_at_frame_range(start_frame, end_frame, &animation_data, fps)
|
||||
}
|
||||
|
||||
impl AnimatedFloat {
|
||||
pub fn new(val: f32) -> AnimatedFloat {
|
||||
AnimatedFloat {
|
||||
@@ -68,6 +109,21 @@ impl AnimatedValue<f32> for AnimatedFloat {
|
||||
self.keyframes
|
||||
.get_value_at_frame(curr_frame, &animation_data, fps)
|
||||
}
|
||||
|
||||
fn get_values_at_frame_range(
|
||||
&self,
|
||||
start_frame: i32,
|
||||
end_frame: i32,
|
||||
animation_data: &AnimationData,
|
||||
fps: i16,
|
||||
) -> Vec<f32> {
|
||||
let values = (start_frame..end_frame)
|
||||
.into_par_iter()
|
||||
.map(|i| self.get_value_at_frame(i, animation_data, fps))
|
||||
.collect();
|
||||
|
||||
values
|
||||
}
|
||||
}
|
||||
|
||||
impl AnimatedValue<(f32, f32, f32)> for AnimatedFloatVec3 {
|
||||
@@ -100,6 +156,40 @@ impl AnimatedValue<(f32, f32, f32)> for AnimatedFloatVec3 {
|
||||
|
||||
return (x, y, z);
|
||||
}
|
||||
|
||||
fn get_values_at_frame_range(
|
||||
&self,
|
||||
start_frame: i32,
|
||||
end_frame: i32,
|
||||
animation_data: &AnimationData,
|
||||
fps: i16,
|
||||
) -> Vec<(f32, f32, f32)> {
|
||||
let x =
|
||||
self.keyframes
|
||||
.0
|
||||
.get_values_at_frame_range(start_frame, end_frame, animation_data, fps);
|
||||
let y =
|
||||
self.keyframes
|
||||
.1
|
||||
.get_values_at_frame_range(start_frame, end_frame, animation_data, fps);
|
||||
let z =
|
||||
self.keyframes
|
||||
.2
|
||||
.get_values_at_frame_range(start_frame, end_frame, animation_data, fps);
|
||||
|
||||
let vectors: Vec<(f32, f32, f32)> = x
|
||||
.into_par_iter()
|
||||
.enumerate()
|
||||
.map(|(index, val_x)| {
|
||||
let val_y: f32 = *y.get(index).unwrap();
|
||||
let val_z: f32 = *z.get(index).unwrap();
|
||||
|
||||
(val_x, val_y, val_z)
|
||||
})
|
||||
.collect();
|
||||
|
||||
vectors
|
||||
}
|
||||
}
|
||||
|
||||
impl AnimatedValue<(f32, f32)> for AnimatedFloatVec2 {
|
||||
@@ -126,4 +216,33 @@ impl AnimatedValue<(f32, f32)> for AnimatedFloatVec2 {
|
||||
|
||||
return (x, y);
|
||||
}
|
||||
|
||||
fn get_values_at_frame_range(
|
||||
&self,
|
||||
start_frame: i32,
|
||||
end_frame: i32,
|
||||
animation_data: &AnimationData,
|
||||
fps: i16,
|
||||
) -> Vec<(f32, f32)> {
|
||||
let x =
|
||||
self.keyframes
|
||||
.0
|
||||
.get_values_at_frame_range(start_frame, end_frame, animation_data, fps);
|
||||
let y =
|
||||
self.keyframes
|
||||
.1
|
||||
.get_values_at_frame_range(start_frame, end_frame, animation_data, fps);
|
||||
|
||||
let vectors: Vec<(f32, f32)> = x
|
||||
.into_par_iter()
|
||||
.enumerate()
|
||||
.map(|(index, val_x)| {
|
||||
let val_y: f32 = *y.get(index).unwrap();
|
||||
|
||||
(val_x, val_y)
|
||||
})
|
||||
.collect();
|
||||
|
||||
vectors
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,14 @@
|
||||
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
|
||||
|
||||
use crate::{
|
||||
animation::timeline::calculate_timeline_entities_at_frame,
|
||||
animation::{
|
||||
primitives::values::{
|
||||
get_values_at_frame_range_from_animated_float,
|
||||
get_values_at_frame_range_from_animated_float_vec2,
|
||||
get_values_at_frame_range_from_animated_float_vec3,
|
||||
},
|
||||
timeline::calculate_timeline_entities_at_frame,
|
||||
},
|
||||
fonts::{get_system_families, get_system_font, get_system_fonts},
|
||||
};
|
||||
|
||||
@@ -15,7 +22,10 @@ fn main() {
|
||||
calculate_timeline_entities_at_frame,
|
||||
get_system_font,
|
||||
get_system_families,
|
||||
get_system_fonts
|
||||
get_system_fonts,
|
||||
get_values_at_frame_range_from_animated_float,
|
||||
get_values_at_frame_range_from_animated_float_vec2,
|
||||
get_values_at_frame_range_from_animated_float_vec3
|
||||
])
|
||||
.run(tauri::generate_context!())
|
||||
.expect("error while running tauri application");
|
||||
|
||||
Reference in New Issue
Block a user