From 1bf7777815569e4c790ba0790feccf36b023102b Mon Sep 17 00:00:00 2001 From: EvilSpirit Date: Tue, 22 Mar 2016 16:52:09 +0600 Subject: [PATCH] Only export sharp edges of the triangle mesh. Before this commit, "emphasized edges" were displayed as well as exported. An "emphasized edge" is an edge between triangles that come from different faces. They are helpful in the rendered display because they hint at the locations of faces, but not in the 2d export since they just clutter the drawing. After this commit, "emphasized edges" are displayed but "sharp edges" are exported. A "sharp edge" is an edge between triangles where the two matching vertexes have different normals, indicating a discontiguity in the surface. "Sharp edges" are also displayed while post-viewing the exported geometry. --- src/groupmesh.cpp | 13 +++++++++++-- src/mesh.cpp | 37 +++++++++++++++++++++++++++++++------ src/polygon.h | 9 ++++++--- 3 files changed, 48 insertions(+), 11 deletions(-) diff --git a/src/groupmesh.cpp b/src/groupmesh.cpp index 430f1f5..35d9684 100644 --- a/src/groupmesh.cpp +++ b/src/groupmesh.cpp @@ -403,8 +403,17 @@ void Group::GenerateDisplayItems(void) { displayEdges.Clear(); if(SS.GW.showEdges) { - runningShell.MakeEdgesInto(&displayEdges); - runningMesh.MakeEmphasizedEdgesInto(&displayEdges); + if(runningMesh.l.n > 0) { + // Triangle mesh only; no shell or emphasized edges. + runningMesh.MakeCertainEdgesInto(&displayEdges, SKdNode::EMPHASIZED_EDGES); + } else { + if(SS.exportMode) { + displayMesh.MakeCertainEdgesInto(&displayEdges, SKdNode::SHARP_EDGES); + } else { + runningShell.MakeEdgesInto(&displayEdges); + displayMesh.MakeCertainEdgesInto(&displayEdges, SKdNode::EMPHASIZED_EDGES); + } + } } } diff --git a/src/mesh.cpp b/src/mesh.cpp index 8cf13f5..1cd800d 100644 --- a/src/mesh.cpp +++ b/src/mesh.cpp @@ -89,10 +89,9 @@ void SMesh::MakeEdgesInPlaneInto(SEdgeList *sel, Vector n, double d) { m.Clear(); } -void SMesh::MakeEmphasizedEdgesInto(SEdgeList *sel) { +void SMesh::MakeCertainEdgesInto(SEdgeList *sel, int type) { SKdNode *root = SKdNode::From(this); - root->MakeCertainEdgesInto(sel, SKdNode::EMPHASIZED_EDGES, - false, NULL, NULL); + root->MakeCertainEdgesInto(sel, type, false, NULL, NULL); } //----------------------------------------------------------------------------- @@ -828,8 +827,11 @@ void SKdNode::FindEdgeOn(Vector a, Vector b, int cnt, bool coplanarIsInter, } else { info->frontFacing = false; } - // And record the triangle's face - info->face = tr->meta.face; + // Record the triangle + info->tr = tr; + // And record which vertexes a and b correspond to + info->ai = a.Equals(tr->a) ? 0 : (a.Equals(tr->b) ? 1 : 2); + info->bi = b.Equals(tr->a) ? 0 : (b.Equals(tr->b) ? 1 : 2); } else if(((a.Equals(tr->a) && b.Equals(tr->b)) || (a.Equals(tr->b) && b.Equals(tr->c)) || (a.Equals(tr->c) && b.Equals(tr->a)))) @@ -946,7 +948,7 @@ void SKdNode::MakeCertainEdgesInto(SEdgeList *sel, int how, break; case EMPHASIZED_EDGES: - if(tr->meta.face != info.face && info.count == 1) { + if(tr->meta.face != info.tr->meta.face && info.count == 1) { // The two triangles that join at this edge come from // different faces; either really different faces, // or one is from a face and the other is zero (i.e., @@ -955,6 +957,29 @@ void SKdNode::MakeCertainEdgesInto(SEdgeList *sel, int how, } break; + case SHARP_EDGES: + if(info.count == 1) { + Vector na0 = (j == 0) ? tr->an : + ((j == 1) ? tr->bn : tr->cn); + Vector nb0 = (j == 0) ? tr->bn : + ((j == 1) ? tr->cn : tr->an); + Vector na1 = (info.ai == 0) ? info.tr->an : + ((info.ai == 1) ? info.tr->bn : info.tr->cn); + Vector nb1 = (info.bi == 0) ? info.tr->an : + ((info.bi == 1) ? info.tr->bn : info.tr->cn); + na0 = na0.WithMagnitude(1.0); + nb0 = nb0.WithMagnitude(1.0); + na1 = na1.WithMagnitude(1.0); + nb1 = nb1.WithMagnitude(1.0); + if(!((na0.Equals(na1) && nb0.Equals(nb1)) || + (na0.Equals(nb1) && nb0.Equals(na1)))) { + // The two triangles that join at this edge meet at a sharp + // angle. This implies they come from different faces. + sel->AddEdge(a, b); + } + } + break; + default: oops(); } diff --git a/src/polygon.h b/src/polygon.h index 00bb910..dbd8728 100644 --- a/src/polygon.h +++ b/src/polygon.h @@ -249,7 +249,7 @@ public: void MakeFromAssemblyOf(SMesh *a, SMesh *b); void MakeEdgesInPlaneInto(SEdgeList *sel, Vector n, double d); - void MakeEmphasizedEdgesInto(SEdgeList *sel); + void MakeCertainEdgesInto(SEdgeList *sel, int type); bool IsEmpty(void); void RemapFaces(Group *g, int remap); @@ -273,7 +273,9 @@ public: int count; bool frontFacing; bool intersectsMesh; - uint32_t face; + STriangle *tr; + int ai; + int bi; }; int which; // whether c is x, y, or z @@ -297,7 +299,8 @@ public: NAKED_OR_SELF_INTER_EDGES = 100, SELF_INTER_EDGES = 200, TURNING_EDGES = 300, - EMPHASIZED_EDGES = 400 + EMPHASIZED_EDGES = 400, + SHARP_EDGES = 500, }; void MakeCertainEdgesInto(SEdgeList *sel, int how, bool coplanarIsInter, bool *inter, bool *leaky);