From 1328a4b96fe9a672b403f958b0861b9ad020a440 Mon Sep 17 00:00:00 2001 From: Par Winzell Date: Fri, 11 Jan 2019 20:47:08 -0800 Subject: [PATCH] Another, better argument parsing fix. --- src/FBX2glTF.cpp | 44 ++++++++++++++++---------------------------- 1 file changed, 16 insertions(+), 28 deletions(-) diff --git a/src/FBX2glTF.cpp b/src/FBX2glTF.cpp index c54aa02..7d44777 100644 --- a/src/FBX2glTF.cpp +++ b/src/FBX2glTF.cpp @@ -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> 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"); } }