Merge branch 'main' into volume-renderer

This commit is contained in:
MihailRis 2026-01-10 23:28:28 +03:00
commit 305f44d1c6
70 changed files with 802 additions and 580 deletions

View file

@ -3,6 +3,7 @@
#include <algorithm>
#include <glm/gtc/quaternion.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
#include "xml.hpp"
#include "util/stringutil.hpp"
@ -71,6 +72,42 @@ static void perform_rect(const xmlelement& root, model::Model& model) {
);
}
static void perform_triangle(const xmlelement& root, model::Model& model) {
auto pointA = root.attr("a").asVec3();
auto pointB = root.attr("b").asVec3();
auto pointC = root.attr("c").asVec3();
glm::vec2 uvs[3] {{0, 0}, {1, 0}, {1, 1}};
bool shading = true;
if (root.has("shading")) {
shading = to_boolean(root.attr("shading"));
}
glm::vec3 ba = pointB - pointA;
glm::vec3 ca = pointC - pointA;
glm::vec3 normal = glm::normalize(glm::cross(ba, ca));
if (root.has("uv")) {
root.attr("uv").asNumbers(glm::value_ptr(uvs[0]), 6);
} else {
UVRegion region {};
if (root.has("region")) {
region.set(root.attr("region").asVec4());
}
if (root.has("region-scale")) {
region.scale(root.attr("region-scale").asVec2());
}
for (auto& uv : uvs) {
uv = region.apply(uv);
}
}
std::string texture = root.attr("texture", "$0").getText();
auto& mesh = model.addMesh(texture, shading);
mesh.addTriangle(pointA, pointB, pointC, normal, uvs[0], uvs[1], uvs[2]);
}
static void perform_box(const xmlelement& root, model::Model& model) {
auto from = root.attr("from").asVec3();
auto to = root.attr("to").asVec3();
@ -181,6 +218,8 @@ static std::unique_ptr<model::Model> load_model(const xmlelement& root) {
perform_rect(*elem, model);
} else if (tag == "box") {
perform_box(*elem, model);
} else if (tag == "tri") {
perform_triangle(*elem, model);
}
}

View file

@ -105,6 +105,19 @@ glm::vec4 Attribute::asColor() const {
}
}
int Attribute::asNumbers(float* dst, size_t dstSize) const {
size_t pos = 0;
size_t count = 0;
while (pos < text.length() && count < dstSize) {
size_t end = text.find(',', pos);
dst[count++] = util::parse_double(
text, pos, std::min<size_t>(end - pos, text.length() - pos)
);
pos = end + 1;
}
return count;
}
Node::Node(std::string tag) : tag(std::move(tag)) {
}

View file

@ -29,6 +29,7 @@ namespace xml {
glm::vec3 asVec3() const;
glm::vec4 asVec4() const;
glm::vec4 asColor() const;
int asNumbers(float* dst, size_t dstSize) const;
};
/// @brief XML element class. Text element has tag 'text' and attribute