From 465e8c3e18b20c266731882fddf2149308157df9 Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Mon, 21 Oct 2019 16:29:35 -0700 Subject: [PATCH] Prototyping the slim mesh generation --- libraries/fbx/src/FBXSerializer_Mesh.cpp | 1 + libraries/hfm/src/hfm/HFM.h | 1 + libraries/hfm/src/hfm/HFMModelMath.cpp | 19 +++++++++++++------ libraries/hfm/src/hfm/HFMModelMath.h | 3 ++- .../src/model-networking/ModelCache.cpp | 8 ++++++++ libraries/shared/src/GLMHelpers.h | 10 ++++++++++ 6 files changed, 35 insertions(+), 7 deletions(-) diff --git a/libraries/fbx/src/FBXSerializer_Mesh.cpp b/libraries/fbx/src/FBXSerializer_Mesh.cpp index e687f5e9f2..895059c6ad 100644 --- a/libraries/fbx/src/FBXSerializer_Mesh.cpp +++ b/libraries/fbx/src/FBXSerializer_Mesh.cpp @@ -174,6 +174,7 @@ void appendIndex(MeshData& data, QVector& 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); diff --git a/libraries/hfm/src/hfm/HFM.h b/libraries/hfm/src/hfm/HFM.h index 41f2e1d501..ee3a25fc46 100644 --- a/libraries/hfm/src/hfm/HFM.h +++ b/libraries/hfm/src/hfm/HFM.h @@ -235,6 +235,7 @@ public: std::vector parts; + std::vector positions; QVector vertices; QVector normals; QVector tangents; diff --git a/libraries/hfm/src/hfm/HFMModelMath.cpp b/libraries/hfm/src/hfm/HFMModelMath.cpp index b5ff47e6c0..f34a43bf19 100644 --- a/libraries/hfm/src/hfm/HFMModelMath.cpp +++ b/libraries/hfm/src/hfm/HFMModelMath.cpp @@ -16,6 +16,9 @@ #include +#include +#include + namespace hfm { void forEachIndex(const hfm::MeshPart& meshPart, std::function func) { @@ -142,12 +145,13 @@ ReweightedDeformers getReweightedDeformers(const size_t numMeshVertices, const s } -MeshIndexedTrianglesPos generateMeshIndexedTrianglePos(const std::vector& srcVertices, const std::vector srcParts) { +const MeshIndexedTrianglesPos generateMeshIndexedTrianglePos(const std::vector& srcVertices, const std::vector& srcParts) { MeshIndexedTrianglesPos dest; - dest.vertices.resize(srcVertices.size()); + // dest.vertices.resize(srcVertices.size()); + dest.vertices = srcVertices; - std::vector remap(srcVertices.size()); + /* std::vector remap(srcVertices.size()); { std::unordered_map uniqueVertices; int vi = 0; @@ -170,7 +174,7 @@ MeshIndexedTrianglesPos generateMeshIndexedTrianglePos(const std::vector vertices; std::vector indices; + std::vector parts; // Offset in the indices, Number of indices }; -MeshIndexedTrianglesPos generateMeshIndexedTrianglePos(const std::vector& srcVertices, const std::vector srcParts); +const MeshIndexedTrianglesPos generateMeshIndexedTrianglePos(const std::vector& srcVertices, const std::vector& srcParts); }; diff --git a/libraries/model-networking/src/model-networking/ModelCache.cpp b/libraries/model-networking/src/model-networking/ModelCache.cpp index bb911c6914..f427326f68 100644 --- a/libraries/model-networking/src/model-networking/ModelCache.cpp +++ b/libraries/model-networking/src/model-networking/ModelCache.cpp @@ -29,6 +29,8 @@ #include #include +#include + 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 materialIDAtlas; for (const HFMMaterial& material : _hfmModel->materials) { @@ -328,11 +331,16 @@ void ModelResource::setGeometryDefinition(HFMModel::Pointer hfmModel, const Mate } std::shared_ptr meshes = std::make_shared(); + std::vector triangleListMeshes = std::vector(); 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; diff --git a/libraries/shared/src/GLMHelpers.h b/libraries/shared/src/GLMHelpers.h index cfb4bb6398..5787295da6 100644 --- a/libraries/shared/src/GLMHelpers.h +++ b/libraries/shared/src/GLMHelpers.h @@ -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