mirror of
https://github.com/overte-org/overte.git
synced 2025-07-29 16:20:00 +02:00
Finish TriangleListMesh generation, rename some things
This commit is contained in:
parent
7d37a064f2
commit
023d73a25d
3 changed files with 25 additions and 27 deletions
|
@ -230,7 +230,7 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/// Simple Triangle List <esh
|
/// Simple Triangle List Mesh
|
||||||
struct TriangleListMesh {
|
struct TriangleListMesh {
|
||||||
std::vector<glm::vec3> vertices;
|
std::vector<glm::vec3> vertices;
|
||||||
std::vector<uint32_t> indices;
|
std::vector<uint32_t> indices;
|
||||||
|
|
|
@ -16,6 +16,9 @@
|
||||||
|
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
|
||||||
|
// TODO: Remove after testing
|
||||||
|
#include <unordered_set>
|
||||||
|
|
||||||
#include <GLMHelpers.h>
|
#include <GLMHelpers.h>
|
||||||
#include <glm/gtx/hash.hpp>
|
#include <glm/gtx/hash.hpp>
|
||||||
|
|
||||||
|
@ -144,38 +147,36 @@ ReweightedDeformers getReweightedDeformers(const size_t numMeshVertices, const s
|
||||||
return reweightedDeformers;
|
return reweightedDeformers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const TriangleListMesh generateTriangleListMesh(const std::vector<glm::vec3>& srcVertices, const std::vector<HFMMeshPart>& srcParts) {
|
const TriangleListMesh generateTriangleListMesh(const std::vector<glm::vec3>& srcVertices, const std::vector<HFMMeshPart>& srcParts) {
|
||||||
|
|
||||||
TriangleListMesh dest;
|
TriangleListMesh dest;
|
||||||
|
|
||||||
// just copy vertices
|
// copy vertices for now
|
||||||
dest.vertices.insert(dest.vertices.end(), srcVertices.cbegin(), srcVertices.cend());
|
dest.vertices = srcVertices;
|
||||||
|
|
||||||
/* std::vector<uint32_t> remap(srcVertices.size());
|
std::vector<uint32_t> oldToNewIndex(srcVertices.size());
|
||||||
{
|
{
|
||||||
std::unordered_map<glm::vec3, uint32_t> uniqueVertices;
|
std::unordered_map<glm::vec3, uint32_t> uniqueVertexToNewIndex;
|
||||||
int vi = 0;
|
int oldIndex = 0;
|
||||||
int vu = 0;
|
int newIndex = 0;
|
||||||
for (const auto& v : srcVertices) {
|
for (const auto& srcVertex : srcVertices) {
|
||||||
auto foundIndex = uniqueVertices.find(v);
|
auto foundIndex = uniqueVertexToNewIndex.find(srcVertex);
|
||||||
if (foundIndex != uniqueVertices.end()) {
|
if (foundIndex != uniqueVertexToNewIndex.end()) {
|
||||||
remap[vi] = foundIndex->second;
|
oldToNewIndex[oldIndex] = foundIndex->second;
|
||||||
} else {
|
} else {
|
||||||
uniqueVertices[v] = vu;
|
uniqueVertexToNewIndex[srcVertex] = newIndex;
|
||||||
remap[vi] = vu;
|
oldToNewIndex[oldIndex] = newIndex;
|
||||||
dest.vertices[vu] = v;
|
dest.vertices[newIndex] = srcVertex;
|
||||||
vu++;
|
++newIndex;
|
||||||
}
|
}
|
||||||
++vi;
|
++oldIndex;
|
||||||
}
|
}
|
||||||
if (uniqueVertices.size() < srcVertices.size()) {
|
if (uniqueVertexToNewIndex.size() < srcVertices.size()) {
|
||||||
dest.vertices.resize(uniqueVertices.size());
|
dest.vertices.resize(uniqueVertexToNewIndex.size());
|
||||||
dest.vertices.shrink_to_fit();
|
dest.vertices.shrink_to_fit();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
auto newIndicesCount = 0;
|
auto newIndicesCount = 0;
|
||||||
for (const auto& part : srcParts) {
|
for (const auto& part : srcParts) {
|
||||||
newIndicesCount += part.triangleIndices.size() + part.quadTrianglesIndices.size();
|
newIndicesCount += part.triangleIndices.size() + part.quadTrianglesIndices.size();
|
||||||
|
@ -187,18 +188,15 @@ const TriangleListMesh generateTriangleListMesh(const std::vector<glm::vec3>& sr
|
||||||
for (const auto& part : srcParts) {
|
for (const auto& part : srcParts) {
|
||||||
glm::ivec2 spart(i, 0);
|
glm::ivec2 spart(i, 0);
|
||||||
for (const auto& qti : part.quadTrianglesIndices) {
|
for (const auto& qti : part.quadTrianglesIndices) {
|
||||||
dest.indices[i] = qti; //remap[qti];
|
dest.indices[i] = oldToNewIndex[qti];
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
for (const auto& ti : part.triangleIndices) {
|
for (const auto& ti : part.triangleIndices) {
|
||||||
dest.indices[i] = ti; //remap[ti];
|
dest.indices[i] = oldToNewIndex[ti];
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
spart.y = i - spart.x;
|
spart.y = i - spart.x;
|
||||||
dest.parts.push_back(spart);
|
dest.parts.push_back(spart);
|
||||||
|
|
||||||
// dest.indices.insert(dest.indices.end(), part.quadTrianglesIndices.cbegin(), part.quadTrianglesIndices.cend());
|
|
||||||
// dest.indices.insert(dest.indices.end(), part.triangleIndices.cbegin(), part.triangleIndices.cend());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -65,7 +65,7 @@ namespace baker {
|
||||||
for (int i = 0; i < meshesIn.size(); i++) {
|
for (int i = 0; i < meshesIn.size(); i++) {
|
||||||
auto& mesh = meshesIn[i];
|
auto& mesh = meshesIn[i];
|
||||||
|
|
||||||
auto meshPointer = const_cast<HFMMesh*> (&mesh);
|
auto meshPointer = const_cast<HFMMesh*>(&mesh);
|
||||||
meshPointer->_vertices = meshPointer->vertices.toStdVector();
|
meshPointer->_vertices = meshPointer->vertices.toStdVector();
|
||||||
|
|
||||||
indexedTrianglesMeshOut[i] = hfm::generateTriangleListMesh(meshPointer->_vertices, mesh.parts);
|
indexedTrianglesMeshOut[i] = hfm::generateTriangleListMesh(meshPointer->_vertices, mesh.parts);
|
||||||
|
|
Loading…
Reference in a new issue