mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-06-05 14:21:10 +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<glm::vec3> vertices;
|
||||||
std::vector<uint32_t> indices;
|
std::vector<uint32_t> indices;
|
||||||
std::vector<glm::ivec2> parts; // Offset in the indices, Number of 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).
|
/// A single mesh (with optional blendshapes).
|
||||||
|
|
|
@ -40,6 +40,20 @@ void thickenFlatExtents(Extents& extents) {
|
||||||
extents.maximum += glm::vec3(EPSILON, EPSILON, EPSILON);
|
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) {
|
void calculateExtentsForShape(hfm::Shape& shape, const std::vector<hfm::Mesh>& meshes, const std::vector<hfm::Joint> joints) {
|
||||||
auto& shapeExtents = shape.transformedExtents;
|
auto& shapeExtents = shape.transformedExtents;
|
||||||
shapeExtents.reset();
|
shapeExtents.reset();
|
||||||
|
@ -196,6 +210,8 @@ const TriangleListMesh generateTriangleListMesh(const std::vector<glm::vec3>& sr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
calculateExtentsForTriangleListMesh(dest);
|
||||||
|
|
||||||
return dest;
|
return dest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,8 @@ void forEachIndex(const hfm::MeshPart& meshPart, std::function<void(uint32_t)> f
|
||||||
|
|
||||||
void initializeExtents(Extents& extents);
|
void initializeExtents(Extents& extents);
|
||||||
|
|
||||||
|
void calculateExtentsForTriangleListMesh(TriangleListMesh& triangleListMesh);
|
||||||
|
|
||||||
// This can't be moved to model-baker until
|
// 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);
|
void calculateExtentsForShape(hfm::Shape& shape, const std::vector<hfm::Mesh>& meshes, const std::vector<hfm::Joint> joints);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue