unlimitedbacon / stl-thumb

Thumbnail generator for STL files
MIT License
1.09k stars 93 forks source link

Detect colors from file name #87

Open unlimitedbacon opened 6 months ago

unlimitedbacon commented 6 months ago

STL files do not have any way of storing color information, but perhaps we could render files in different colors by detecting strings in the filename. Here are some ideas.

Color Names red, green, blue, etc.

HTML/Hex Color Codes #1a2b3c

Voron Naming Scheme Accent color files are prefixed with [a]. Primary color files have no prefix.

gyscos commented 2 weeks ago

Could potentially use a config file to describe a set of rules and the colors to pick in each case. This could totally be a wrapper script around stl-thumb itself (but wouldn't hurt to include it directly there).

For example, a list of regexes and resulting colors - here's a quick mockup:

[[patterns]]
regex = '''\[a\]'''
ambient = "#123456"
diffuse = "#789012"
specular = "#345678"
background = "#901234"

[default]
ambient = "blue"
diffuse = "grey"
specular = "white"

With a config like:

#[derive(Deserialize)]
struct PatternConfig {
    patterns: Vec<Pattern>,
    default: Option<Colors>
}

#[derive(Deserialize)]
struct Pattern {
    regex: String,

    #[serde(flatten)]
    color: Colors,
}

#[derive(Deserialize)]
struct Colors {
    background: Option<String>,
    ambient:  Option<String>,
    diffuse:  Option<String>,
    specular:  Option<String>,
}

Main drawbacks:

Maybe arbitrary regexes are a bit overkill/too powerful/complex and just checking for the presence of a substring/glob is enough?