feat: support alternative vcm models syntax

This commit is contained in:
MihailRis
2025-06-01 23:08:59 +03:00
parent 8f342fe429
commit 4333d9ab06
10 changed files with 155 additions and 28 deletions
+14 -7
View File
@@ -5,6 +5,7 @@
#include "xml.hpp"
#include "util/stringutil.hpp"
#include "graphics/commons/Model.hpp"
#include "io/io.hpp"
using namespace vcm;
using namespace xml;
@@ -143,12 +144,18 @@ static std::unique_ptr<model::Model> load_model(const xmlelement& root) {
std::unique_ptr<model::Model> vcm::parse(
std::string_view file, std::string_view src
) {
auto doc = xml::parse(file, src);
const auto& root = *doc->getRoot();
if (root.getTag() != "model") {
throw std::runtime_error(
"'model' tag expected as root, got '" + root.getTag() + "'"
);
try {
auto doc = io::path(std::string(file)).extension() == ".xml"
? xml::parse(file, src) : xml::parse_vcm(file, src, "model");
const auto& root = *doc->getRoot();
if (root.getTag() != "model") {
throw std::runtime_error(
"'model' tag expected as root, got '" + root.getTag() + "'"
);
}
std::cout << xml::stringify(*doc) << std::endl;
return load_model(root);
} catch (const parsing_error& err) {
throw std::runtime_error(err.errorLog());
}
return load_model(root);
}