This commit is contained in:
Spencer Killen 2024-01-02 10:19:11 -07:00
parent 56de6fefc3
commit ccf290f070
Signed by: sjkillen
GPG Key ID: 3AF3117BA6FBB75B
2 changed files with 19 additions and 17 deletions

View File

@ -51,6 +51,8 @@ pub struct AnimationInfo {
pub total_points: usize, pub total_points: usize,
pub start_frame: usize, pub start_frame: usize,
pub end_frame: usize, pub end_frame: usize,
// MDD file format supports varying FPS , but Blender's exporter does not
// FPS is only correct if it's not varying, see individual frame times for more granularity
pub fps: f32, pub fps: f32,
} }
@ -206,13 +208,14 @@ impl PointCache for MDDSeekableFile {
let mut fps: f32 = -1.0; let mut fps: f32 = -1.0;
let mut prev_frame = frames.next().ok_or(EmptyAnimationError)??; let mut prev_frame = frames.next().ok_or(EmptyAnimationError)??;
let start_frame = prev_frame.frame_idx; let start_frame = prev_frame.frame_idx;
if let Some(second_frame) = frames.next() { // TODO: sometimes the time difference between frames is 0, not sure why
let second_frame = second_frame?; // Need to rely on later frames to avoid divide by zero
fps = 1.0 / (second_frame.time - prev_frame.time);
prev_frame = second_frame;
}
for next_frame in frames { for next_frame in frames {
prev_frame = next_frame?; let next_frame = next_frame?;
if fps < 0.0 && (next_frame.time - prev_frame.time) > 0.0 {
fps = 1.0 / (next_frame.time - prev_frame.time);
}
prev_frame = next_frame;
} }
let end_frame = prev_frame.frame_idx; let end_frame = prev_frame.frame_idx;

View File

@ -126,7 +126,6 @@ impl PointState {
} }
} }
fn main() { fn main() {
let basename = std::env::args() let basename = std::env::args()
.nth(1) .nth(1)
@ -134,11 +133,11 @@ fn main() {
let mdd_filename = basename.clone() + ".mdd"; let mdd_filename = basename.clone() + ".mdd";
let mut mdd_file = File::open(mdd_filename).expect("Mdd filename is not valid"); let mdd_file = File::open(mdd_filename).expect("Mdd filename is not valid");
let (total_frames, total_points) = MDDSeekableFile::read_header(&mut mdd_file).unwrap(); let info = MDDSeekableFile::read_animation_info(mdd_file.try_clone().unwrap()).unwrap();
let mut mask_last: Vec<PointState> = vec![Unseen; total_points as usize]; let mut mask_last: Vec<PointState> = vec![Unseen; info.total_points];
let pc = MDDSeekableFile::read_frames(mdd_file.try_clone().unwrap()).unwrap(); let pc = MDDSeekableFile::read_frames(mdd_file.try_clone().unwrap()).unwrap();
let mut total_varying = 0; let mut total_varying = 0;
for frame in pc { for frame in pc {
@ -168,11 +167,11 @@ fn main() {
write_mask_image( write_mask_image(
&(basename.clone() + "_mask.exr"), &(basename.clone() + "_mask.exr"),
&mask, &mask,
total_points as usize, info.total_points,
) )
.unwrap(); .unwrap();
let mut pixels: Vec<Point> = Vec::with_capacity(total_varying * (total_frames as usize)); let mut pixels: Vec<Point> = Vec::with_capacity(total_varying * (info.total_frames));
let pc = MDDSeekableFile::read_frames(mdd_file.try_clone().unwrap()).unwrap(); let pc = MDDSeekableFile::read_frames(mdd_file.try_clone().unwrap()).unwrap();
let pc: Vec<_> = pc.collect(); let pc: Vec<_> = pc.collect();
@ -183,7 +182,7 @@ fn main() {
.cloned() .cloned()
.max() .max()
.unwrap(); .unwrap();
assert_eq!(max_point_idx + 1, total_points as usize); assert_eq!(max_point_idx + 1, info.total_points);
let pc = pc.into_iter(); let pc = pc.into_iter();
@ -198,7 +197,7 @@ fn main() {
} }
})); }));
assert!(pixels.len() == total_varying * (total_frames as usize)); assert!(pixels.len() == total_varying * (info.total_frames));
if total_varying == 0 { if total_varying == 0 {
eprintln!("No varying frames, not outputting .exr image"); eprintln!("No varying frames, not outputting .exr image");
@ -209,13 +208,13 @@ fn main() {
&(basename + ".exr"), &(basename + ".exr"),
&pixels, &pixels,
total_varying, total_varying,
total_frames as usize, info.total_frames,
) )
.unwrap(); .unwrap();
println!( println!(
"Total {} varying points of {} total points", "Total {} varying points of {} total points",
total_varying, total_points total_varying, info.total_points
); );
println!() println!("{:?}", info);
} }