Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates (Rust edition & dependencies) #7

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 64 additions & 53 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,71 +103,82 @@ density-mesh mesh -i image.png -o mesh.obj --obj

#### Options
```
density-mesh-cli 1.4.0
Patryk 'PsichiX' Budzynski <[email protected]>
density-mesh 1.5.0
CLI app for density mesh generator
Patryk 'PsichiX' Budzynski <[email protected]>

USAGE:
density-mesh.exe [SUBCOMMAND]
Usage:
density-mesh <COMMAND>

FLAGS:
-h, --help Prints help information
-V, --version Prints version information
Commands:
image Produce density map image
mesh Produce density mesh
help Print this message or the help of the given subcommand(s)

SUBCOMMANDS:
help Prints this message or the help of the given subcommand(s)
image Produce density map image
mesh Produce density mesh
Options:
-h, --help Print help
-V, --version Print version
```

```
density-mesh.exe-image
density-mesh-image
Produce density map image

USAGE:
density-mesh.exe image [FLAGS] [OPTIONS] --input <PATH> --output <PATH>

FLAGS:
-h, --help Prints help information
-s, --steepness Produce steepness image
-V, --version Prints version information
--verbose Display settings used

OPTIONS:
--density-source <NAME> Density source: luma, luma-alpha, red, green, blue, alpha [default: luma-alpha]
-i, --input <PATH> Input image file
-o, --output <PATH> Output image file
--scale <INTEGER> Image scale [default: 1]
Usage:
density-mesh image [OPTIONS] --input <PATH> --output <PATH>

Options:
-i, --input <PATH> Input file path
-o, --output <PATH> Output file path
--density-source <CHANNEL> Use an alternate channel as density source [default: luma-alpha] [possible values: luma, luma-alpha, red, green, blue, alpha]
--scale <INTEGER> Image scale [default: 1]
--verbose Display settings used
-s, --steepness Produce steepness image
-h, --help Print help
```

```
density-mesh.exe-mesh
density-mesh-mesh
Produce density mesh

USAGE:
density-mesh.exe mesh [FLAGS] [OPTIONS] --input <PATH> --output <PATH> <--json|--json-pretty|--yaml|--obj|--png>

FLAGS:
-h, --help Prints help information
--json Produce JSON mesh
--json-pretty Produce pretty JSON mesh
--keep-invisible-triangles Keep invisible triangles
--obj Produce OBJ mesh
--png Produce PNG mesh visualization
-V, --version Prints version information
--verbose Display settings used
--yaml Produce YAML mesh

OPTIONS:
--density-source <NAME> Density source: luma, luma-alpha, red, green, blue, alpha [default: luma-
alpha]
--extrude-size <NUMBER> Extrude size
-i, --input <PATH> Input image file
--max-iterations <INTEGER> Maximum tries number when finding point to place [default: 32]
-o, --output <PATH> Output mesh file
--points-separation <NUMBER> Points separation [default: 10]
--scale <INTEGER> Image scale [default: 1]
--steepness-threshold <NUMBER> Steepness threshold [default: 0.01]
--update-region-margin <NUMBER> Margin around update region box [default: 0]
--visibility-threshold <NUMBER> VIsibility threshold [default: 0.01]
Usage:
density-mesh mesh [OPTIONS] --input <PATH> --output <PATH> <--json|--json-pretty|--yaml|--obj|--png>

Options:
-i, --input <PATH>
Input file path
-o, --output <PATH>
Output file path
--density-source <CHANNEL>
Use an alternate channel as density source [default: luma-alpha] [possible values: luma, luma-alpha, red, green, blue, alpha]
--scale <INTEGER>
Image scale [default: 1]
--verbose
Display settings used
--json
Produce JSON mesh
--json-pretty
Produce pretty JSON mesh
--yaml
Produce YAML mesh
--obj
Produce OBJ mesh
--png
Produce PNG mesh visualization
--points-separation <NUMBER_OR_RANGE>
Points separation [default: 10]
--visibility-threshold <NUMBER>
Visibility threshold [default: 0.01]
--steepness-threshold <NUMBER>
Steepness threshold [default: 0.01]
--max-iterations <INTEGER>
Maximum number of tries when finding point to place [default: 32]
--extrude-size <NUMBER>
Extrude size
--update-region-margin <NUMBER>
Margin around update region box; currently unused [default: 0]
--keep-invisible-triangles
Keep invisible triangles
-h, --help
Print help (see more with '--help')
```
13 changes: 8 additions & 5 deletions density-mesh-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "density-mesh-cli"
version = "1.5.0"
authors = ["Patryk 'PsichiX' Budzynski <[email protected]>"]
edition = "2018"
edition = "2021"
description = "CLI app for density mesh generator"
license = "MIT"
homepage = "https://github.com/PsichiX/density-mesh"
Expand All @@ -15,10 +15,13 @@ name = "density-mesh"
path = "./src/main.rs"

[dependencies]
density-mesh-core = { version = "1.3", path = "../density-mesh-core", features = ["parallel"] }
density-mesh-core = { version = "1.3", path = "../density-mesh-core", features = [
"parallel",
] }
density-mesh-image = { version = "1.3", path = "../density-mesh-image" }
serde_json = "1"
serde_yaml = "0.8"
serde_yaml = "0.9"
obj-exporter = "0.2"
clap = "2.23"
image = { default-features = false, features = ["png"], version = "0.23" }
clap = { version = "4.4", features = ["derive", "unicode", "cargo"] }
image = { default-features = false, features = ["png"], version = "0.24" }
strum = { version = "0.25.0", features = ["derive"] }
168 changes: 168 additions & 0 deletions density-mesh-cli/src/cli.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
use std::path::PathBuf;

use clap::{Args, Parser, Subcommand, ValueEnum, ValueHint};
use density_mesh_core::{prelude::PointsSeparation, Scalar};
use density_mesh_image::settings::ImageDensitySource;

#[derive(Clone, Debug, Parser)]
#[command(name = "density-mesh", version, author, about)]
#[command(help_template = "\
{name} {version}
{about}
{author}

{usage-heading}
{tab}{usage}

{all-args}
")]
pub struct CliArgs {
#[command(subcommand)]
pub action: Action,
}

#[derive(Clone, Debug, Args)]
pub struct CommonArgs {
/// Input file path
#[arg(short, long, value_name = "PATH", value_hint(ValueHint::FilePath))]
pub input: PathBuf,

/// Output file path
#[arg(short, long, value_name = "PATH", value_hint(ValueHint::FilePath))]
pub output: PathBuf,

/// Use an alternate channel as density source
#[arg(long, value_name = "CHANNEL", default_value_t)]
pub density_source: DensitySourceSelection,

/// Image scale
#[arg(long, value_name = "INTEGER", default_value_t = 1)]
pub scale: usize,

/// Display settings used
#[arg(long)]
pub verbose: bool,
}

#[derive(Clone, Copy, Debug, Default, strum::Display, ValueEnum)]
#[strum(serialize_all = "kebab-case")]
pub enum DensitySourceSelection {
Luma,
#[default]
LumaAlpha,
Red,
Green,
Blue,
Alpha,
}
impl From<DensitySourceSelection> for ImageDensitySource {
fn from(value: DensitySourceSelection) -> Self {
use DensitySourceSelection as S; // source
use ImageDensitySource as T; // target
match value {
S::Luma => T::Luma,
S::LumaAlpha => T::LumaAlpha,
S::Red => T::Red,
S::Green => T::Green,
S::Blue => T::Blue,
S::Alpha => T::Alpha,
}
}
}

#[derive(Clone, Debug, Subcommand)]
pub enum Action {
/// Produce density map image
#[command(help_template = "\
{name}
{about}

{usage-heading}
{tab}{usage}

{all-args}
")]
Image {
#[command(flatten)]
common: CommonArgs,

/// Produce steepness image
#[arg(short, long)]
steepness: bool,
},

/// Produce density mesh
#[command(help_template = "\
{name}
{about}

{usage-heading}
{tab}{usage}

{all-args}
")]
Mesh {
#[command(flatten)]
common: CommonArgs,

#[command(flatten)]
format: Format,

/// Points separation
///
/// Accepts either a single number, or a range in the format of `MIN..MAX`
///
/// - Single number: constant separation
/// - Range: separation varies depending on steepness
#[arg(long, value_name = "NUMBER_OR_RANGE", default_value_t = PointsSeparation::Constant(10.0))]
points_separation: PointsSeparation,

/// Visibility threshold
#[arg(long, value_name = "NUMBER", default_value_t = 0.01)]
visibility_threshold: Scalar,

/// Steepness threshold
#[arg(long, value_name = "NUMBER", default_value_t = 0.01)]
steepness_threshold: Scalar,

/// Maximum number of tries when finding point to place
#[arg(long, value_name = "INTEGER", default_value_t = 32)]
max_iterations: usize,

/// Extrude size
#[arg(long, value_name = "NUMBER")]
extrude_size: Option<Scalar>,

/// Margin around update region box; currently unused
#[arg(long, value_name = "NUMBER", default_value_t = 0.0)]
update_region_margin: Scalar,

/// Keep invisible triangles
#[arg(long)]
keep_invisible_triangles: bool,
},
}

#[derive(Clone, Debug, Args)]
#[group(required = true)]
pub struct Format {
/// Produce JSON mesh
#[arg(long)]
pub json: bool,

/// Produce pretty JSON mesh
#[arg(long)]
pub json_pretty: bool,

/// Produce YAML mesh
#[arg(long)]
pub yaml: bool,

/// Produce OBJ mesh
#[arg(long)]
pub obj: bool,

/// Produce PNG mesh visualization
#[arg(long)]
pub png: bool,
}
Loading