From 7d70c8af2189dadf229459f99d2abcb30f263222 Mon Sep 17 00:00:00 2001 From: _ <_@_> Date: Mon, 21 Feb 2022 23:36:14 +0000 Subject: [PATCH] :heavy_plus_sign: add CLI args --- .gitignore | 4 ++++ src/main.rs | 24 ++++++++++++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index ea8c4bf..cd378c5 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,5 @@ /target + +*.blend +*.glb +*.iqm diff --git a/src/main.rs b/src/main.rs index 05d821c..f719bb5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,7 +9,27 @@ use glam::{ }; fn main () { - let (document, buffers, _images) = gltf::import ("input.glb").unwrap (); + // The `clap` crate is very popular but also very slow to compile, + // so I'll do my own CLI parsing + let mut args = std::env::args (); + let _exe_name = args.next ().unwrap (); + + let mut input_path = None; + let mut output_path = None; + + while let Some (arg) = args.next () { + if arg == "--input" || arg == "-i" { + input_path = args.next (); + } + else if arg == "--output" || arg == "-o" { + output_path = args.next (); + } + } + + let input_path = input_path.unwrap (); + let output_path = output_path.unwrap (); + + let (document, buffers, _images) = gltf::import (input_path).unwrap (); let buffer = buffers.get (0).unwrap (); let mut vertexes = Vec::default (); @@ -121,7 +141,7 @@ fn main () { let filesize = ofs_text + num_text; - let mut f = File::create ("output.iqm").unwrap (); + let mut f = File::create (output_path).unwrap (); f.write_all (b"INTERQUAKEMODEL\0").unwrap ();