feature: stages
stages: separate scanning and parsing, allowing `v`, `vn`, `vt` lines to be mapped to line numbers and store line data (once). first stage parsing: parse face data and validate vertices. TODO: * improve validation (detect partial normals/texcoords); * maybe improve storage of triangle line number instead of storing line number for each vertex;
This commit is contained in:
36
src/main.cpp
36
src/main.cpp
@@ -12,7 +12,8 @@
|
||||
#include <stdexcept>
|
||||
#include <variant>
|
||||
|
||||
#include "file.hpp"
|
||||
#include "parse.hpp"
|
||||
#include "scan.hpp"
|
||||
#include "settings.hpp"
|
||||
|
||||
static void usage(const char* prog) {
|
||||
@@ -27,8 +28,17 @@ static void usage(const char* prog) {
|
||||
" -- end of options\n";
|
||||
}
|
||||
|
||||
#define CATCH_AND_RETURN(variable, exception, return_value, initializer) \
|
||||
decltype(initializer) variable; \
|
||||
try { \
|
||||
variable = initializer; \
|
||||
} catch (exception __ex__) { \
|
||||
std::cerr << __ex__.what() << std::endl; \
|
||||
return return_value; \
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
using namespace wavefront::parser;
|
||||
using namespace wavefront;
|
||||
|
||||
if (argc < 3) {
|
||||
usage(argv[0]);
|
||||
@@ -108,17 +118,19 @@ int main(int argc, char** argv) {
|
||||
|
||||
Settings settings = settings_builder.build();
|
||||
|
||||
std::variant<File<float, uint32_t>, File<double, uint32_t>> file = [&]() -> decltype(file) {
|
||||
if (settings.use_float64()) {
|
||||
return File<double, uint32_t>();
|
||||
} else {
|
||||
return File<float, uint32_t>();
|
||||
}
|
||||
}();
|
||||
CATCH_AND_RETURN(scan_data, wavefront::scan_error, 1, wavefront::scan(
|
||||
settings.input(),
|
||||
settings.selected_objects(),
|
||||
settings.selected_groups())
|
||||
);
|
||||
|
||||
std::visit([&](auto& file) {
|
||||
file.parse(settings);
|
||||
}, file);
|
||||
CATCH_AND_RETURN(triangle_data, wavefront::parse_error, 1, wavefront::parse_face_data(scan_data));
|
||||
|
||||
std::cerr << "Scanned " << scan_data.total_lines << " lines\n";
|
||||
std::cerr << "Found " << scan_data.category_map["v"].size() << " vertices\n";
|
||||
std::cerr << "Found " << scan_data.category_map["vn"].size() << " normals\n";
|
||||
std::cerr << "Found " << scan_data.category_map["vt"].size() << " texture coordinates\n";
|
||||
std::cerr << "Found " << scan_data.category_map["f"].size() << " faces\n";
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user