This commit is contained in:
Spencer Killen 2024-01-06 19:17:48 -07:00
parent b83fed45df
commit a49bd2b123
Signed by: sjkillen
GPG Key ID: 3AF3117BA6FBB75B
3 changed files with 35 additions and 12 deletions

View File

@ -3,4 +3,5 @@
# Note: due to how Godot finds paths, this works best if cwd is this directory
./pack_res.gd ++ $@
BASENAMES=$(find -name 'VA_*.mdd' | sed s@\./@@ | sed s@\.mdd@@ | tr "\n" " ")
./pack_res.gd ++ $BASENAMES

View File

@ -17,6 +17,7 @@ var VertexAnimations = preload("VertexAnimations.gd")
func _init():
var basenames := OS.get_cmdline_user_args()
print(basenames)
var animations = VertexAnimations.new()
animations.name = "VertexAnimations"

View File

@ -122,15 +122,17 @@ fn _write_animation_info(filename: &str, info: AnimationInfo) -> Result<(), Box<
enum PointState {
Unseen,
OneValue { point_idx: usize, point: Point },
Varying { new_idx: usize },
Varying,
Reindexed { new_idx: usize },
}
use PointState::*;
impl PointState {
fn mask_value(&self) -> f32 {
match *self {
Unseen => panic!("no point should be unseen"),
Varying => panic!("no point should be unindexed"),
OneValue { .. } => -1.0,
Varying { new_idx, .. } => new_idx as f32,
Reindexed { new_idx, .. } => new_idx as f32,
}
}
fn point_changed(a: &Point, b: &Point) -> bool {
@ -138,7 +140,6 @@ impl PointState {
}
}
fn main() {
let basename = std::env::args()
.nth(1)
@ -152,7 +153,6 @@ fn main() {
let mut mask_last: Vec<PointState> = vec![Unseen; info.total_points];
let pc = MDDSeekableFile::read_frames(mdd_file.try_clone().unwrap()).unwrap();
let mut total_varying = 0;
for frame in pc {
let MDDFrame {
point, point_idx, ..
@ -165,13 +165,34 @@ fn main() {
} => {
assert_eq!(old_point_idx, point_idx);
if PointState::point_changed(&point, &old_point) {
mask_last[point_idx] = Varying {
new_idx: total_varying,
};
mask_last[point_idx] = Varying;
}
}
Varying => {}
Reindexed { .. } => unreachable!()
}
}
let mut total_varying = 0;
for point in mask_last.iter_mut() {
if let Varying = point {
*point = Reindexed { new_idx: total_varying };
total_varying += 1;
}
}
Varying { .. } => {}
// Check that the varing indices are increasing w.r.t. point_idx
let mut mask_iter = mask_last.iter().filter_map(|x| {
if let &Reindexed { new_idx } = x {
Some(new_idx)
} else {
None
}
});
if let Some(mut prev_idx) = mask_iter.next() {
for next_idx in mask_iter {
assert_eq!(prev_idx + 1, next_idx);
prev_idx = next_idx;
}
}
@ -199,9 +220,9 @@ fn main() {
point_idx, point, ..
} = frame.unwrap();
match mask_last[point_idx] {
Unseen => panic!(),
Varying | Unseen => panic!(),
OneValue { .. } => None,
Varying { .. } => Some(point),
Reindexed { .. } => Some(point),
}
}));