diff --git a/examples/gltfutil/CMakeLists.txt b/examples/gltfutil/CMakeLists.txt new file mode 100644 index 0000000..dc09156 --- /dev/null +++ b/examples/gltfutil/CMakeLists.txt @@ -0,0 +1,11 @@ +cmake_minimum_required (VERSION 3.6) +project (gltfutil) + +set(CMAKE_CXX_STANDARD 11) + +include_directories( + ../../ + ) + +file(GLOB gltfutil_sources *.cc *.h) +add_executable(gltfutil ${gltfutil_sources}) diff --git a/examples/gltfutil/gltfuilconfig.h b/examples/gltfutil/gltfuilconfig.h new file mode 100644 index 0000000..9571a5a --- /dev/null +++ b/examples/gltfutil/gltfuilconfig.h @@ -0,0 +1,18 @@ +#include + +namespace gltfutil { +enum class ui_mode { cli, interactive }; + +enum class cli_action { not_set, help, dump }; + +struct configuration { + std::string input_path, output_dir; + ui_mode mode; + cli_action action = cli_action::not_set; + bool has_output_dir; + bool is_valid() { + // TODO impl check + return false; + } +}; +} // namespace gltfutil diff --git a/examples/gltfutil/main.cc b/examples/gltfutil/main.cc new file mode 100644 index 0000000..aa7c379 --- /dev/null +++ b/examples/gltfutil/main.cc @@ -0,0 +1,70 @@ +#include +#include + +#include "gltfuilconfig.h" + +namespace gltfutil { +int usage() { + using std::cout; + cout << "gltfutil: tool for manipulating gltf files\n" + << " usage information:\n\n" + << "\t gltfutil (-i|-d|-h) [path to .gltf/glb] (-o [path to output " + "directory])\n\n" + << "\t\t -i: start in interactive mode\n" + << "\t\t -d: dump enclosed content (image assets)\n" + << "\t\t -h: print this help\n"; + return 0; +} + +int arg_error() { + (void)usage(); + return -1; +} + +int parse_args(int argc, char** argv) { + gltfutil::configuration config; + + for (size_t i = 1; i < size_t(argc); ++i) { + char* arg = argv[i]; + if (arg[0] == '-') switch (arg[1]) { + case 'h': + config.mode = ui_mode::cli; + config.action = cli_action::help; + case 'd': + // TODO impl + break; + case 'i': + config.mode = ui_mode::interactive; + break; + // TODO impl + default: + return arg_error(); + } + } + + if (config.is_valid()) { + if (config.mode == ui_mode::interactive) { + // interactive usage now; + // TODO impl + } else { + switch (config.action) { + case cli_action::help: + return usage(); + case cli_action::dump: + // TODO impl + break; + default: + return arg_error(); + } + } + } else { + return arg_error(); + } + return 0; +} +} // namespace gltfutil + +int main(int argc, char* argv[]) { + if (argc == 1) return gltfutil::usage(); + if (argc > 1) return gltfutil::parse_args(argc, argv); +}