slicer: implement minimal argument parsing
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -4491,6 +4491,7 @@ name = "slicer"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
|
"clap",
|
||||||
"common",
|
"common",
|
||||||
"criterion",
|
"criterion",
|
||||||
"goo_format",
|
"goo_format",
|
||||||
|
@@ -5,6 +5,7 @@ edition = "2021"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow.workspace = true
|
anyhow.workspace = true
|
||||||
|
clap.workspace = true
|
||||||
image.workspace = true
|
image.workspace = true
|
||||||
nalgebra.workspace = true
|
nalgebra.workspace = true
|
||||||
obj-rs.workspace = true
|
obj-rs.workspace = true
|
||||||
|
@@ -1,11 +1,13 @@
|
|||||||
use std::{
|
use std::{
|
||||||
fs::{self, File},
|
fs::{self, File},
|
||||||
io::{stdout, BufReader, Write},
|
io::{stdout, BufReader, Write},
|
||||||
|
path::PathBuf,
|
||||||
thread,
|
thread,
|
||||||
time::Instant,
|
time::Instant,
|
||||||
};
|
};
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
use clap::Parser;
|
||||||
use nalgebra::{Vector2, Vector3};
|
use nalgebra::{Vector2, Vector3};
|
||||||
|
|
||||||
use common::{
|
use common::{
|
||||||
@@ -16,9 +18,16 @@ use common::{
|
|||||||
use goo_format::{File as GooFile, LayerEncoder};
|
use goo_format::{File as GooFile, LayerEncoder};
|
||||||
use slicer::{mesh::load_mesh, slicer::Slicer, Pos};
|
use slicer::{mesh::load_mesh, slicer::Slicer, Pos};
|
||||||
|
|
||||||
|
#[derive(Parser)]
|
||||||
|
struct Args {
|
||||||
|
/// Path to the .stl file
|
||||||
|
input_file: PathBuf,
|
||||||
|
/// Path to the .goo file
|
||||||
|
output_file: PathBuf,
|
||||||
|
}
|
||||||
|
|
||||||
fn main() -> Result<()> {
|
fn main() -> Result<()> {
|
||||||
const FILE_PATH: &str = "teapot.stl";
|
let args = Args::parse();
|
||||||
const OUTPUT_PATH: &str = "output.goo";
|
|
||||||
|
|
||||||
let slice_config = SliceConfig {
|
let slice_config = SliceConfig {
|
||||||
format: Format::Goo,
|
format: Format::Goo,
|
||||||
@@ -39,7 +48,7 @@ fn main() -> Result<()> {
|
|||||||
transition_layers: 10,
|
transition_layers: 10,
|
||||||
};
|
};
|
||||||
|
|
||||||
let file = File::open(FILE_PATH)?;
|
let file = File::open(args.input_file)?;
|
||||||
let mut buf = BufReader::new(file);
|
let mut buf = BufReader::new(file);
|
||||||
let mut mesh = load_mesh(&mut buf, "stl")?;
|
let mut mesh = load_mesh(&mut buf, "stl")?;
|
||||||
let (min, max) = mesh.bounds();
|
let (min, max) = mesh.bounds();
|
||||||
@@ -90,7 +99,7 @@ fn main() -> Result<()> {
|
|||||||
// Once slicing is complete write to a .goo file
|
// Once slicing is complete write to a .goo file
|
||||||
let mut serializer = DynamicSerializer::new();
|
let mut serializer = DynamicSerializer::new();
|
||||||
goo.join().unwrap().serialize(&mut serializer);
|
goo.join().unwrap().serialize(&mut serializer);
|
||||||
fs::write(OUTPUT_PATH, serializer.into_inner())?;
|
fs::write(args.output_file, serializer.into_inner())?;
|
||||||
|
|
||||||
println!("\nDone. Elapsed: {:.1}s", now.elapsed().as_secs_f32());
|
println!("\nDone. Elapsed: {:.1}s", now.elapsed().as_secs_f32());
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user