mirror of
https://github.com/overte-org/overte.git
synced 2025-04-06 18:53:16 +02:00
Prototyping the slim mesh generation
This commit is contained in:
parent
24e6a966a8
commit
465e8c3e18
6 changed files with 35 additions and 7 deletions
|
@ -174,6 +174,7 @@ void appendIndex(MeshData& data, QVector<int>& indices, int index, bool deduplic
|
|||
data.indices.insert(vertex, newIndex);
|
||||
data.extracted.newIndices.insert(vertexIndex, newIndex);
|
||||
data.extracted.mesh.vertices.append(position);
|
||||
data.extracted.mesh.positions.emplace_back(position);
|
||||
data.extracted.mesh.originalIndices.append(vertexIndex);
|
||||
data.extracted.mesh.normals.append(normal);
|
||||
data.extracted.mesh.texCoords.append(vertex.texCoord);
|
||||
|
|
|
@ -235,6 +235,7 @@ public:
|
|||
|
||||
std::vector<MeshPart> parts;
|
||||
|
||||
std::vector<glm::vec3> positions;
|
||||
QVector<glm::vec3> vertices;
|
||||
QVector<glm::vec3> normals;
|
||||
QVector<glm::vec3> tangents;
|
||||
|
|
|
@ -16,6 +16,9 @@
|
|||
|
||||
#include <unordered_map>
|
||||
|
||||
#include <GLMHelpers.h>
|
||||
#include <glm/gtx/hash.hpp>
|
||||
|
||||
namespace hfm {
|
||||
|
||||
void forEachIndex(const hfm::MeshPart& meshPart, std::function<void(uint32_t)> func) {
|
||||
|
@ -142,12 +145,13 @@ ReweightedDeformers getReweightedDeformers(const size_t numMeshVertices, const s
|
|||
}
|
||||
|
||||
|
||||
MeshIndexedTrianglesPos generateMeshIndexedTrianglePos(const std::vector<glm::vec3>& srcVertices, const std::vector<HFMMeshPart> srcParts) {
|
||||
const MeshIndexedTrianglesPos generateMeshIndexedTrianglePos(const std::vector<glm::vec3>& srcVertices, const std::vector<HFMMeshPart>& srcParts) {
|
||||
|
||||
MeshIndexedTrianglesPos dest;
|
||||
dest.vertices.resize(srcVertices.size());
|
||||
// dest.vertices.resize(srcVertices.size());
|
||||
dest.vertices = srcVertices;
|
||||
|
||||
std::vector<uint32_t> remap(srcVertices.size());
|
||||
/* std::vector<uint32_t> remap(srcVertices.size());
|
||||
{
|
||||
std::unordered_map<glm::vec3, uint32_t> uniqueVertices;
|
||||
int vi = 0;
|
||||
|
@ -170,7 +174,7 @@ MeshIndexedTrianglesPos generateMeshIndexedTrianglePos(const std::vector<glm::ve
|
|||
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
auto newIndicesCount = 0;
|
||||
for (const auto& part : srcParts) {
|
||||
newIndicesCount += part.triangleIndices.size() + part.quadTrianglesIndices.size();
|
||||
|
@ -180,14 +184,17 @@ MeshIndexedTrianglesPos generateMeshIndexedTrianglePos(const std::vector<glm::ve
|
|||
dest.indices.resize(newIndicesCount);
|
||||
int i = 0;
|
||||
for (const auto& part : srcParts) {
|
||||
glm::ivec2 spart(i, 0);
|
||||
for (const auto& qti : part.quadTrianglesIndices) {
|
||||
dest.indices[i] = remap[qti];
|
||||
dest.indices[i] = qti; //remap[qti];
|
||||
++i;
|
||||
}
|
||||
for (const auto& ti : part.quadTrianglesIndices) {
|
||||
dest.indices[i] = remap[ti];
|
||||
dest.indices[i] = ti; //remap[ti];
|
||||
++i;
|
||||
}
|
||||
spart.y = i - spart.x;
|
||||
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());
|
||||
|
|
|
@ -42,9 +42,10 @@ struct MeshIndexedTrianglesPos {
|
|||
public:
|
||||
std::vector<glm::vec3> vertices;
|
||||
std::vector<uint32_t> indices;
|
||||
std::vector<glm::ivec2> parts; // Offset in the indices, Number of indices
|
||||
};
|
||||
|
||||
MeshIndexedTrianglesPos generateMeshIndexedTrianglePos(const std::vector<glm::vec3>& srcVertices, const std::vector<HFMMeshPart> srcParts);
|
||||
const MeshIndexedTrianglesPos generateMeshIndexedTrianglePos(const std::vector<glm::vec3>& srcVertices, const std::vector<HFMMeshPart>& srcParts);
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -29,6 +29,8 @@
|
|||
#include <GLTFSerializer.h>
|
||||
#include <model-baker/Baker.h>
|
||||
|
||||
#include <hfm/HFMModelMath.h>
|
||||
|
||||
Q_LOGGING_CATEGORY(trace_resource_parse_geometry, "trace.resource.parse.geometry")
|
||||
|
||||
class GeometryExtra {
|
||||
|
@ -320,6 +322,7 @@ void ModelResource::setGeometryDefinition(HFMModel::Pointer hfmModel, const Mate
|
|||
_hfmModel = hfmModel;
|
||||
_materialMapping = materialMapping;
|
||||
|
||||
|
||||
// Copy materials
|
||||
QHash<QString, size_t> materialIDAtlas;
|
||||
for (const HFMMaterial& material : _hfmModel->materials) {
|
||||
|
@ -328,11 +331,16 @@ void ModelResource::setGeometryDefinition(HFMModel::Pointer hfmModel, const Mate
|
|||
}
|
||||
|
||||
std::shared_ptr<GeometryMeshes> meshes = std::make_shared<GeometryMeshes>();
|
||||
std::vector<hfm::MeshIndexedTrianglesPos> triangleListMeshes = std::vector<hfm::MeshIndexedTrianglesPos>();
|
||||
int meshID = 0;
|
||||
for (const HFMMesh& mesh : _hfmModel->meshes) {
|
||||
// Copy mesh pointers
|
||||
meshes->emplace_back(mesh._mesh);
|
||||
meshID++;
|
||||
|
||||
auto simpleMesh = hfm::generateMeshIndexedTrianglePos(mesh.positions, mesh.parts);
|
||||
|
||||
triangleListMeshes.emplace_back(simpleMesh);
|
||||
}
|
||||
_meshes = meshes;
|
||||
|
||||
|
|
|
@ -392,4 +392,14 @@ inline glm::vec4 extractFov( const glm::mat4& m) {
|
|||
return result;
|
||||
}
|
||||
|
||||
inline bool operator<(const glm::vec3& lhs, const glm::vec3& rhs) {
|
||||
return (lhs.x < rhs.x) || (
|
||||
(lhs.x == rhs.x) && (
|
||||
(lhs.y < rhs.y) || (
|
||||
(lhs.y == rhs.y) && (lhs.z < rhs.z)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
#endif // hifi_GLMHelpers_h
|
||||
|
|
Loading…
Reference in a new issue