mirror of
https://github.com/overte-org/overte.git
synced 2025-04-08 02:14:26 +02:00
Introduce extents for TriangleListMesh and calculate them
This commit is contained in:
parent
67e05a70d4
commit
ba257634f2
3 changed files with 19 additions and 0 deletions
|
@ -235,6 +235,7 @@ struct TriangleListMesh {
|
|||
std::vector<glm::vec3> vertices;
|
||||
std::vector<uint32_t> indices;
|
||||
std::vector<glm::ivec2> parts; // Offset in the indices, Number of indices
|
||||
std::vector<Extents> partExtents; // Extents of each part with no transform applied. Same length as parts.
|
||||
};
|
||||
|
||||
/// A single mesh (with optional blendshapes).
|
||||
|
|
|
@ -40,6 +40,20 @@ void thickenFlatExtents(Extents& extents) {
|
|||
extents.maximum += glm::vec3(EPSILON, EPSILON, EPSILON);
|
||||
}
|
||||
|
||||
void calculateExtentsForTriangleListMesh(TriangleListMesh& triangleListMesh) {
|
||||
triangleListMesh.partExtents.resize(triangleListMesh.parts.size());
|
||||
for (size_t partIndex = 0; partIndex < triangleListMesh.parts.size(); ++partIndex) {
|
||||
const auto& part = triangleListMesh.parts[partIndex];
|
||||
auto& extents = triangleListMesh.partExtents[partIndex];
|
||||
int partEnd = part.x + part.y;
|
||||
for (int i = part.x; i < partEnd; ++i) {
|
||||
auto index = triangleListMesh.indices[i];
|
||||
const auto& position = triangleListMesh.vertices[index];
|
||||
extents.addPoint(position);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void calculateExtentsForShape(hfm::Shape& shape, const std::vector<hfm::Mesh>& meshes, const std::vector<hfm::Joint> joints) {
|
||||
auto& shapeExtents = shape.transformedExtents;
|
||||
shapeExtents.reset();
|
||||
|
@ -196,6 +210,8 @@ const TriangleListMesh generateTriangleListMesh(const std::vector<glm::vec3>& sr
|
|||
}
|
||||
}
|
||||
|
||||
calculateExtentsForTriangleListMesh(dest);
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,8 @@ void forEachIndex(const hfm::MeshPart& meshPart, std::function<void(uint32_t)> f
|
|||
|
||||
void initializeExtents(Extents& extents);
|
||||
|
||||
void calculateExtentsForTriangleListMesh(TriangleListMesh& triangleListMesh);
|
||||
|
||||
// This can't be moved to model-baker until
|
||||
void calculateExtentsForShape(hfm::Shape& shape, const std::vector<hfm::Mesh>& meshes, const std::vector<hfm::Joint> joints);
|
||||
|
||||
|
|
Loading…
Reference in a new issue