Another, better argument parsing fix.

This commit is contained in:
Par Winzell 2019-01-11 20:47:08 -08:00
parent 5c07d274c3
commit 1328a4b96f
1 changed files with 16 additions and 28 deletions

View File

@ -103,29 +103,10 @@ int main(int argc, char* argv[]) {
"When to compute vertex normals from mesh geometry.")
->type_name("(never|broken|missing|always)");
bool flip_u = false;
bool flip_v = true;
app.add_flag_function(
"--flip-u",
[&](const size_t count) { flip_u = flip_u || (count > 0); },
"Flip all V texture coordinates.");
app.add_flag_function(
"--no-flip-u",
[&](const size_t count) { flip_u = flip_u && (count == 0); },
"Don't flip U texture coordinates.")
->excludes("--flip-u");
app.add_flag_function(
"--flip-v",
[&](const size_t count) { flip_v = flip_v || (count > 0); },
"Flip all V texture coordinates.");
app.add_flag_function(
"--no-flip-v",
[&](const size_t count) { flip_v = flip_v && (count == 0); },
"Don't flip V texture coordinates.")
->excludes("--flip-v");
const auto opt_flip_u = app.add_flag("--flip-u", "Flip all U texture coordinates.");
const auto opt_no_flip_u = app.add_flag("--no-flip-u", "Don't flip U texture coordinates.");
const auto opt_flip_v = app.add_flag("--flip-v", "Flip all V texture coordinates.");
const auto opt_no_flip_v = app.add_flag("--no-flip-v", "Don't flip V texture coordinates.");
app.add_flag(
"--pbr-metallic-rougnness",
@ -246,21 +227,28 @@ int main(int argc, char* argv[]) {
CLI11_PARSE(app, argc, argv);
bool do_flip_u = false;
bool do_flip_v = true;
// somewhat tedious way to resolve --flag vs --no-flag in order provided
for (const auto opt : app.parse_order()) {
do_flip_u = (do_flip_u || (opt == opt_flip_u)) && (opt != opt_no_flip_u);
do_flip_v = (do_flip_v || (opt == opt_flip_v)) && (opt != opt_no_flip_v);
}
std::vector<std::function<Vec2f(Vec2f)>> texturesTransforms;
if (flip_u || flip_v) {
if (flip_u && flip_v) {
if (do_flip_u || do_flip_v) {
if (do_flip_u && do_flip_v) {
texturesTransforms.emplace_back([](Vec2f uv) { return Vec2f(1.0 - uv[0], 1.0 - uv[1]); });
} else if (flip_u) {
} else if (do_flip_u) {
texturesTransforms.emplace_back([](Vec2f uv) { return Vec2f(1.0 - uv[0], uv[1]); });
} else {
texturesTransforms.emplace_back([](Vec2f uv) { return Vec2f(uv[0], 1.0 - uv[1]); });
}
}
if (verboseOutput) {
if (flip_u) {
if (do_flip_u) {
fmt::printf("Flipping texture coordinates in the 'U' dimension.\n");
}
if (!flip_v) {
if (!do_flip_v) {
fmt::printf("NOT flipping texture coordinates in the 'V' dimension.\n");
}
}