//! Print a resource's first N decoded positions (buffer order), for matching a
//! capture draw's `pos:` dump to a part:
//!   cargo run --release --example part_pos -- <xpr path> <resource> [n]
use std::collections::HashSet;
use sylpheed_formats::mesh::Xbg7Model;

fn main() {
    let a: Vec<String> = std::env::args().collect();
    let bytes = std::fs::read(&a[1]).unwrap();
    let n: usize = a.get(3).and_then(|s| s.parse().ok()).unwrap_or(4);
    let want: HashSet<String> = [a[2].clone()].into();
    for m in Xbg7Model::models_named(&bytes, &want, &|| false) {
        let vc: usize = m.meshes.iter().map(|s| s.positions.len()).sum();
        print!("{} vtx={}:", m.name, vc);
        for p in m.meshes.iter().flat_map(|s| &s.positions).take(n) {
            print!(" ({:.4},{:.4},{:.4})", p[0], p[1], p[2]);
        }
        println!();
    }
}
