summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2023-03-18 02:12:21 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2023-03-18 02:12:21 +0000
commitf412b04cc367168b1a6f921dfa1171a17e1353fc (patch)
treeb6062e786d76dc0a46264492247385b8e42ac9c8
parentFix texture packer return value so positions match inputs (diff)
downloadilt-f412b04cc367168b1a6f921dfa1171a17e1353fc.tar.bz2
ilt-f412b04cc367168b1a6f921dfa1171a17e1353fc.tar.xz
ilt-f412b04cc367168b1a6f921dfa1171a17e1353fc.zip
Use indices instead of triangulation
-rw-r--r--assetFactory/factoryMesh.cpp15
1 files changed, 11 insertions, 4 deletions
diff --git a/assetFactory/factoryMesh.cpp b/assetFactory/factoryMesh.cpp
index c47e80e..59b390f 100644
--- a/assetFactory/factoryMesh.cpp
+++ b/assetFactory/factoryMesh.cpp
@@ -10,24 +10,31 @@ FactoryMesh::createMesh() const
for (const auto & use : uses) {
use->createMesh(mesh, 1);
}
- mesh.garbage_collection();
- mesh.triangulate();
mesh.update_face_normals();
mesh.update_vertex_normals();
std::vector<Vertex> vertices;
+ std::vector<unsigned int> indices;
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)) {
+ auto vrange = mesh.fv_range(face);
+ const unsigned int start = static_cast<unsigned int>(vertices.size());
+ for (const auto & vertex : vrange) {
const auto textureUV = mesh.texcoord2D(vertex);
vertices.emplace_back(mesh.point(vertex), textureUV,
smooth ? mesh.property(mesh.vertex_normals_pph(), vertex)
: mesh.property(mesh.face_normals_pph(), face),
colour);
}
+ const auto vcount = std::distance(vrange.begin(), vrange.end());
+ for (unsigned int i = 2; i < vcount; i++) {
+ indices.push_back(start);
+ indices.push_back(start + i - 1);
+ indices.push_back(start + i);
+ }
}
- return std::make_shared<Mesh>(vertices, vectorOfN(vertices.size()));
+ return std::make_shared<Mesh>(vertices, indices);
}
bool