Add CLI interface for exporting to `cuboid` model

This commit is contained in:
Hanno Braun 2023-05-30 10:45:32 +02:00
parent f307339bc3
commit 04e375790c
1 changed files with 27 additions and 2 deletions

View File

@ -1,8 +1,10 @@
use std::ops::Deref; use std::{ops::Deref, path::PathBuf};
use fj_kernel::algorithms::{approx::Tolerance, triangulate::Triangulate}; use fj_kernel::algorithms::{approx::Tolerance, triangulate::Triangulate};
fn main() -> anyhow::Result<()> { fn main() -> anyhow::Result<()> {
let args = Args::parse();
let cuboid = cuboid::cuboid(3., 2., 1.); let cuboid = cuboid::cuboid(3., 2., 1.);
// The tolerance makes no difference for this model, as there aren't any // The tolerance makes no difference for this model, as there aren't any
@ -10,7 +12,30 @@ fn main() -> anyhow::Result<()> {
let tolerance = Tolerance::from_scalar(1.)?; let tolerance = Tolerance::from_scalar(1.)?;
let mesh = (cuboid.deref(), tolerance).triangulate(); let mesh = (cuboid.deref(), tolerance).triangulate();
fj_window::run(mesh, false)?;
if let Some(path) = args.export {
fj_export::export(&mesh, &path)?;
} else {
fj_window::run(mesh, false)?;
}
Ok(()) Ok(())
} }
/// Standardized CLI for Fornjot models
#[derive(clap::Parser)]
pub struct Args {
/// Export model to this path
#[arg(short, long, value_name = "PATH")]
pub export: Option<PathBuf>,
}
impl Args {
/// Parse the command-line arguments
///
/// Convenience method that saves the caller from having to import the
/// `clap::Parser` trait.
pub fn parse() -> Self {
<Self as clap::Parser>::parse()
}
}