From 870166e536aadef018cee2d93eba6b818607767c Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Tue, 25 Apr 2023 02:29:20 +0100 Subject: Allow setting a flag to say (vertex) normals have been provided --- assetFactory/modelFactoryMesh.h | 1 + 1 file changed, 1 insertion(+) (limited to 'assetFactory') diff --git a/assetFactory/modelFactoryMesh.h b/assetFactory/modelFactoryMesh.h index 4eac7ee..012977a 100644 --- a/assetFactory/modelFactoryMesh.h +++ b/assetFactory/modelFactoryMesh.h @@ -47,6 +47,7 @@ struct ModelFactoryTraits : public OpenMesh::DefaultTraits { struct ModelFactoryMesh : public OpenMesh::PolyMesh_ArrayKernelT { ModelFactoryMesh(); + bool normalsProvidedProperty {}; OpenMesh::FPropHandleT smoothFaceProperty; OpenMesh::FPropHandleT materialFaceProperty; OpenMesh::FPropHandleT nameFaceProperty; -- cgit v1.2.3 From 9a16e572ab54c9f2598af5c02643cc1db7a30a91 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Tue, 25 Apr 2023 02:46:03 +0100 Subject: Don't update face/vertex normals if normals were provided, simply use them as is --- assetFactory/factoryMesh.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'assetFactory') diff --git a/assetFactory/factoryMesh.cpp b/assetFactory/factoryMesh.cpp index f7bc7c8..784179f 100644 --- a/assetFactory/factoryMesh.cpp +++ b/assetFactory/factoryMesh.cpp @@ -13,10 +13,13 @@ FactoryMesh::createMesh() const ModelFactoryMesh mesh; use->createMesh(mesh, 1); - mesh.update_face_normals(); - mesh.update_vertex_normals(); + if (!mesh.normalsProvidedProperty) { + mesh.update_face_normals(); + mesh.update_vertex_normals(); + } for (const auto & face : mesh.faces()) { - const auto & smooth = mesh.property(mesh.smoothFaceProperty, face); + const auto & useVertexNormals + = mesh.property(mesh.smoothFaceProperty, face) || mesh.normalsProvidedProperty; const auto & colour = mesh.color(face); const auto & material = mesh.property(mesh.materialFaceProperty, face); @@ -25,8 +28,8 @@ FactoryMesh::createMesh() const const auto & vertex = mesh.to_vertex_handle(heh); const auto & textureUV = mesh.texcoord2D(heh); const auto & point = mesh.point(vertex); - const auto & normal = smooth ? mesh.property(mesh.vertex_normals_pph(), vertex) - : mesh.property(mesh.face_normals_pph(), face); + const auto & normal = useVertexNormals ? mesh.property(mesh.vertex_normals_pph(), vertex) + : mesh.property(mesh.face_normals_pph(), face); Vertex outVertex {point, textureUV, normal, colour, material}; if (const auto existingItr = std::find(vertices.rbegin(), vertices.rend(), outVertex); existingItr != vertices.rend()) { -- cgit v1.2.3 From 18189cf376f7a0a18544df552f1fe8e905d87e38 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Tue, 25 Apr 2023 02:46:55 +0100 Subject: Set vertex normals from AssImp data if available --- assetFactory/assimp.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'assetFactory') diff --git a/assetFactory/assimp.cpp b/assetFactory/assimp.cpp index 840c5a9..74b1c54 100644 --- a/assetFactory/assimp.cpp +++ b/assetFactory/assimp.cpp @@ -59,9 +59,15 @@ public: void addMesh(CreatedFaces & faces, ModelFactoryMesh & mesh, const aiMesh * amesh) const { - const auto vhs = AIRANGE(amesh, Vertices) * [&mesh](auto && v) { - return mesh.add_vertex(*v); - }; + mesh.normalsProvidedProperty = amesh->HasNormals(); + const auto vhs = AIRANGE(amesh, Vertices) * + [&mesh, normals = amesh->HasNormals() ? amesh->mNormals : nullptr](auto && v) mutable { + const auto vh = mesh.add_vertex(*v); + if (normals) { + mesh.set_normal(vh, **(normals++)); + } + return vh; + }; const auto & m = scene->mMaterials[amesh->mMaterialIndex]->GetName(); GLuint material {}; -- cgit v1.2.3