summaryrefslogtreecommitdiff
path: root/assetFactory/factoryMesh.cpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2023-03-05 01:59:16 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2023-03-05 01:59:16 +0000
commitd4c073a18adaed73973f34c6c39fc15664d9211d (patch)
tree44536af3af0284ab75eae79ef81a5e4452019269 /assetFactory/factoryMesh.cpp
parentAdd helper operator to perform vec3*mat4 and perspective divide (diff)
parentRemove old hard coded asset factory test, run entirely from XML load and rend... (diff)
downloadilt-d4c073a18adaed73973f34c6c39fc15664d9211d.tar.bz2
ilt-d4c073a18adaed73973f34c6c39fc15664d9211d.tar.xz
ilt-d4c073a18adaed73973f34c6c39fc15664d9211d.zip
Merge branch 'model-factory'
Diffstat (limited to 'assetFactory/factoryMesh.cpp')
-rw-r--r--assetFactory/factoryMesh.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/assetFactory/factoryMesh.cpp b/assetFactory/factoryMesh.cpp
new file mode 100644
index 0000000..0cfed85
--- /dev/null
+++ b/assetFactory/factoryMesh.cpp
@@ -0,0 +1,40 @@
+#include "factoryMesh.h"
+#include "collections.hpp"
+#include "gfx/models/vertex.hpp"
+#include "modelFactoryMesh.h"
+#include <glm/ext/matrix_transform.hpp>
+
+Mesh::Ptr
+FactoryMesh::createMesh() const
+{
+ constexpr glm::vec2 NullUV {};
+
+ ModelFactoryMesh mesh;
+ for (const auto & use : uses) {
+ use->createMesh(mesh, glm::identity<Mutation::Matrix>());
+ }
+ mesh.garbage_collection();
+
+ mesh.triangulate();
+ mesh.update_face_normals();
+ mesh.update_vertex_normals();
+ std::vector<Vertex> vertices;
+ for (const auto & face : mesh.faces()) {
+ const auto smooth = mesh.property(mesh.smoothFaceProperty, face);
+ const auto colour = mesh.color(face);
+ for (const auto & vertex : mesh.fv_range(face)) {
+ vertices.emplace_back(mesh.point(vertex), NullUV,
+ smooth ? mesh.property(mesh.vertex_normals_pph(), vertex)
+ : mesh.property(mesh.face_normals_pph(), face),
+ colour);
+ }
+ }
+ return std::make_shared<Mesh>(vertices, vectorOfN(vertices.size()));
+}
+
+bool
+FactoryMesh::persist(Persistence::PersistenceStore & store)
+{
+ return STORE_TYPE && STORE_MEMBER(id) && STORE_MEMBER(size)
+ && STORE_NAME_HELPER("use", uses, Persistence::Appender<Use::Collection>);
+}