upgrade entities frustum culling

This commit is contained in:
MihailRis 2026-10-31 23:41:40 +03:00
parent 414a0947ab
commit c21871c3c9
9 changed files with 206 additions and 63 deletions

View file

@ -3,6 +3,7 @@
#include "Model.hpp"
#include <algorithm>
#include <limits>
#include <glm/gtc/quaternion.hpp>
#include <glm/gtx/matrix_decompose.hpp>
@ -168,6 +169,25 @@ void Mesh::translate(const glm::vec3& offset) {
}
}
void Model::calcBounds() {
glm::vec3 min(std::numeric_limits<float>::max());
glm::vec3 max(std::numeric_limits<float>::lowest());
for (const auto& mesh : meshes) {
for (const auto& vertex : mesh.vertices) {
min = glm::min(min, vertex.coord);
max = glm::max(max, vertex.coord);
}
}
if (min.x > max.x) {
min = max = glm::vec3(0.0f);
}
bounds = AABB(min, max);
}
const AABB& Model::getBounds() const {
return bounds;
}
void Model::clean() {
meshes.erase(
std::remove_if(meshes.begin(), meshes.end(),

View file

@ -5,6 +5,7 @@
#include <glm/glm.hpp>
#include "maths/UVRegion.hpp"
#include "maths/aabb.hpp"
namespace model {
struct Vertex {
@ -82,6 +83,7 @@ namespace model {
struct Model {
std::vector<Mesh> meshes;
AABB bounds {glm::vec3(0.0f), glm::vec3(0.0f)};
/// @brief Add mesh to the model
/// @param texture texture name
@ -96,6 +98,9 @@ namespace model {
return meshes[meshes.size() - 1];
}
void calcBounds();
const AABB& getBounds() const;
/// @brief Remove all empty meshes
void clean();

View file

@ -187,6 +187,7 @@ model::Model ModelsGenerator::fromCustom(
mesh.vertices.push_back({v2, glm::vec2(reg.u2, reg.v2), norm});
mesh.vertices.push_back({v3, glm::vec2(reg.u1, reg.v2), norm});
}
model.calcBounds();
return model;
}