summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2023-04-25 17:53:49 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2023-04-25 17:53:49 +0100
commitac3d38f019b9593d4dda49921c0db6c0b8c9a1a6 (patch)
treeeecd6de4c49d9f775db38c5cbedc0a4db55f248e
parentRemove duplicate Tree-01-1 definition (diff)
parentClear world objects explicitly (diff)
downloadilt-ac3d38f019b9593d4dda49921c0db6c0b8c9a1a6.tar.bz2
ilt-ac3d38f019b9593d4dda49921c0db6c0b8c9a1a6.tar.xz
ilt-ac3d38f019b9593d4dda49921c0db6c0b8c9a1a6.zip
Merge remote-tracking branch 'origin/assimp-normals'
-rw-r--r--application/main.cpp1
-rw-r--r--assetFactory/assimp.cpp12
-rw-r--r--assetFactory/factoryMesh.cpp13
-rw-r--r--assetFactory/modelFactoryMesh.h1
4 files changed, 19 insertions, 8 deletions
diff --git a/application/main.cpp b/application/main.cpp
index 9feb80b..177c795 100644
--- a/application/main.cpp
+++ b/application/main.cpp
@@ -99,6 +99,7 @@ public:
t_start = t_end;
}
+ world.objects.clear();
return 0;
}
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 {};
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()) {
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<ModelFactoryTraits> {
ModelFactoryMesh();
+ bool normalsProvidedProperty {};
OpenMesh::FPropHandleT<bool> smoothFaceProperty;
OpenMesh::FPropHandleT<GLuint> materialFaceProperty;
OpenMesh::FPropHandleT<std::string> nameFaceProperty;