summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2023-04-09 12:24:55 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2023-04-09 12:24:55 +0100
commitb222c21715384efc2eaa53d3ba295fb34da5b599 (patch)
tree66149833358cbadb891159fd0faf74ef221e5073
parentSimplify extruding (diff)
downloadilt-b222c21715384efc2eaa53d3ba295fb34da5b599.tar.bz2
ilt-b222c21715384efc2eaa53d3ba295fb34da5b599.tar.xz
ilt-b222c21715384efc2eaa53d3ba295fb34da5b599.zip
Start to factor out geometric place from face controller split
-rw-r--r--assetFactory/faceController.cpp16
-rw-r--r--assetFactory/faceController.h4
-rw-r--r--lib/geometricPlane.cpp9
-rw-r--r--lib/geometricPlane.h12
4 files changed, 31 insertions, 10 deletions
diff --git a/assetFactory/faceController.cpp b/assetFactory/faceController.cpp
index 7992fba..37aaa4c 100644
--- a/assetFactory/faceController.cpp
+++ b/assetFactory/faceController.cpp
@@ -76,7 +76,6 @@ FaceController::extrude(ModelFactoryMesh & mesh, const std::string & faceName, O
return newFaces;
}
-enum class PlaneRelation { Above, Below, On };
Shape::CreatedFaces
FaceController::split(
ModelFactoryMesh & mesh, const std::string & name, OpenMesh::FaceHandle & fh, const Split & split) const
@@ -84,15 +83,16 @@ FaceController::split(
// Map face vertex handles to their relationship to the split plane
const auto vertices = materializeRange(mesh.fv_range(fh));
auto vertexRelations = vertices * [&split, &mesh](OpenMesh::VertexHandle vh) {
- const auto d = glm::dot(split.normal, mesh.point(vh) - split.origin);
- return std::make_pair(vh, d < 0.f ? PlaneRelation::Below : d > 0.f ? PlaneRelation::Above : PlaneRelation::On);
+ return std::make_pair(vh, split.getRelation(mesh.point(vh)));
};
// Insert new vertices where half edges intersect the split plane
for (size_t curIdx = 0; curIdx < vertexRelations.size(); ++curIdx) {
const size_t nextIdx = (curIdx + 1) % vertexRelations.size();
const auto &current = vertexRelations[curIdx], next = vertexRelations[nextIdx];
- if ((current.second == PlaneRelation::Above && next.second == PlaneRelation::Below)
- || (current.second == PlaneRelation::Below && next.second == PlaneRelation::Above)) {
+ if ((current.second == GeometricPlane::PlaneRelation::Above
+ && next.second == GeometricPlane::PlaneRelation::Below)
+ || (current.second == GeometricPlane::PlaneRelation::Below
+ && next.second == GeometricPlane::PlaneRelation::Above)) {
const auto origin = mesh.point(current.first), dir = glm::normalize(mesh.point(next.first) - origin);
float dist {};
@@ -101,7 +101,7 @@ FaceController::split(
auto where = vertexRelations.begin();
++curIdx;
std::advance(where, curIdx);
- vertexRelations.emplace(where, newv, PlaneRelation::On);
+ vertexRelations.emplace(where, newv, GeometricPlane::PlaneRelation::On);
}
}
// Create vertex vectors
@@ -113,8 +113,8 @@ FaceController::split(
}
}
};
- filterVertices(out.front(), PlaneRelation::Above);
- filterVertices(out.back(), PlaneRelation::Below);
+ filterVertices(out.front(), GeometricPlane::PlaneRelation::Above);
+ filterVertices(out.back(), GeometricPlane::PlaneRelation::Below);
if (out.back().size() > 2) {
Shape::CreatedFaces newFaces;
diff --git a/assetFactory/faceController.h b/assetFactory/faceController.h
index 8d30dc6..0376241 100644
--- a/assetFactory/faceController.h
+++ b/assetFactory/faceController.h
@@ -1,5 +1,6 @@
#pragma once
+#include "geometricPlane.h"
#include "modelFactoryMesh_fwd.h"
#include "mutation.h"
#include "persistence.h"
@@ -10,10 +11,9 @@
class FaceController : public Mutation, public Style, public Persistence::Persistable {
public:
- class Split : public Persistable {
+ class Split : public Persistable, public GeometricPlane {
public:
std::string id;
- glm::vec3 origin, normal;
private:
friend Persistence::SelectionPtrBase<std::unique_ptr<Split>>;
diff --git a/lib/geometricPlane.cpp b/lib/geometricPlane.cpp
new file mode 100644
index 0000000..cb52997
--- /dev/null
+++ b/lib/geometricPlane.cpp
@@ -0,0 +1,9 @@
+#include "geometricPlane.h"
+#include <glm/geometric.hpp>
+
+GeometricPlane::PlaneRelation
+GeometricPlane::getRelation(glm::vec3 p) const
+{
+ const auto d = glm::dot(normal, p - origin);
+ return d < 0.f ? PlaneRelation::Below : d > 0.f ? PlaneRelation::Above : PlaneRelation::On;
+}
diff --git a/lib/geometricPlane.h b/lib/geometricPlane.h
new file mode 100644
index 0000000..96816f2
--- /dev/null
+++ b/lib/geometricPlane.h
@@ -0,0 +1,12 @@
+#pragma once
+
+#include <glm/vec3.hpp>
+
+class GeometricPlane {
+public:
+ enum class PlaneRelation { Above, Below, On };
+
+ glm::vec3 origin, normal;
+
+ PlaneRelation getRelation(glm::vec3 point) const;
+};