Start working on a gltf utility program

Signed-off-by: Arthur Brainville (Ybalrid) <ybalrid@ybalrid.info>
This commit is contained in:
Arthur Brainville 2018-03-19 15:08:47 +01:00 committed by Arthur Brainville (Ybalrid)
parent f1cdd1c4cb
commit ea2b1c5e5d
No known key found for this signature in database
GPG Key ID: BC05C4812A06BCF3
3 changed files with 99 additions and 0 deletions

View File

@ -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})

View File

@ -0,0 +1,18 @@
#include <string>
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

70
examples/gltfutil/main.cc Normal file
View File

@ -0,0 +1,70 @@
#include <iostream>
#include <string>
#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);
}