add 'rotate' and 'origin' box modifier to vcm

This commit is contained in:
MihailRis
2025-10-16 22:57:45 +03:00
parent fc122ef3e1
commit 18d4cff678
3 changed files with 78 additions and 31 deletions
+27 -2
View File
@@ -1,6 +1,8 @@
#include "vcm.hpp"
#include <iostream>
#include <algorithm>
#include <glm/gtc/quaternion.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include "xml.hpp"
#include "util/stringutil.hpp"
@@ -73,6 +75,29 @@ static void perform_box(const xmlelement& root, model::Model& model) {
auto from = root.attr("from").asVec3();
auto to = root.attr("to").asVec3();
glm::vec3 origin = (from + to) * 0.5f;
if (root.has("origin")) {
origin = root.attr("origin").asVec3();
}
glm::mat4 tsf(1.0f);
from -= origin;
to -= origin;
tsf = glm::translate(tsf, origin);
if (root.has("rotate")) {
auto text = root.attr("rotate").getText();
if (std::count(text.begin(), text.end(), ',') == 3) {
auto quat = root.attr("rotate").asVec4();
tsf *= glm::mat4_cast(glm::quat(quat.w, quat.x, quat.y, quat.z));
} else {
auto rot = root.attr("rotate").asVec3();
tsf = glm::rotate(tsf, glm::radians(rot.x), glm::vec3(1, 0, 0));
tsf = glm::rotate(tsf, glm::radians(rot.y), glm::vec3(0, 1, 0));
tsf = glm::rotate(tsf, glm::radians(rot.z), glm::vec3(0, 0, 1));
}
}
UVRegion regions[6] {};
regions[0].scale(to.x - from.x, to.y - from.y);
regions[1].scale(from.x - to.x, to.y - from.y);
@@ -142,7 +167,7 @@ static void perform_box(const xmlelement& root, model::Model& model) {
bool enabled[6] {};
enabled[i] = true;
auto& mesh = model.addMesh(texfaces[i], shading);
mesh.addBox(center, halfsize, regions, enabled);
mesh.addBox(center, halfsize, regions, enabled, tsf);
}
}