add Merge::transform, Model::merge

This commit is contained in:
MihailRis 2026-01-13 21:50:20 +03:00
parent e01cc25f7c
commit 495e5fa994
2 changed files with 33 additions and 0 deletions

View file

@ -156,6 +156,12 @@ void Mesh::scale(const glm::vec3& size) {
}
}
void Mesh::transform(const glm::mat4& matrix) {
for (auto& vertex : vertices) {
vertex.coord = matrix * glm::vec4(vertex.coord, 1.0f);
}
}
void Model::clean() {
meshes.erase(
std::remove_if(meshes.begin(), meshes.end(),
@ -165,3 +171,20 @@ void Model::clean() {
meshes.end()
);
}
void Model::transform(const glm::mat4& matrix) {
for (auto& mesh : meshes) {
mesh.transform(matrix);
}
}
void Model::merge(const Model& source) {
for (const auto& srcMesh : source.meshes) {
auto& dstMesh = addMesh(srcMesh.texture, srcMesh.shading);
dstMesh.vertices.insert(
dstMesh.vertices.end(),
srcMesh.vertices.begin(),
srcMesh.vertices.end()
);
}
}

View file

@ -72,6 +72,9 @@ namespace model {
const glm::mat4& transform
);
void scale(const glm::vec3& size);
/// @brief Apply transformation matrix to vertices coordinates
void transform(const glm::mat4& matrix);
};
struct Model {
@ -91,5 +94,12 @@ namespace model {
}
/// @brief Remove all empty meshes
void clean();
/// @brief Apply transformation matrix to vertices coordinates
void transform(const glm::mat4& matrix);
/// @brief Copy or merge meshes from source model to this.
/// Does not remove duplicates
void merge(const Model& source);
};
}