forked from gradientspace/geometry3Sharp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added loop extrusion. Filler & Extrude get Validate() fns, to make su…
…re they can be computed. MeshValidation is place for validation checks. Add MeshEditor.stitchLoop for Extrude.
- Loading branch information
Showing
4 changed files
with
178 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace g3 | ||
{ | ||
public class MeshExtrusion | ||
{ | ||
public DMesh3 Mesh; | ||
public EdgeLoop Loop; | ||
|
||
// arguments | ||
|
||
// set new position based on original loop vertex position, normal, and index | ||
public Func<Vector3d, Vector3f, int, Vector3d> PositionF; | ||
|
||
// outputs | ||
|
||
public int[] NewTriangles; | ||
public EdgeLoop NewLoop; | ||
|
||
|
||
public MeshExtrusion(DMesh3 mesh, EdgeLoop loop) | ||
{ | ||
Mesh = mesh; | ||
Loop = loop; | ||
|
||
PositionF = (pos, normal, idx) => { | ||
return pos + Vector3d.AxisY; | ||
}; | ||
} | ||
|
||
|
||
public virtual ValidationStatus Validate() | ||
{ | ||
ValidationStatus loopStatus = MeshValidation.IsBoundaryLoop(Mesh, Loop); | ||
return loopStatus; | ||
} | ||
|
||
|
||
public virtual bool Extrude(int group_id = -1) | ||
{ | ||
// duplicate loop vertices | ||
int NV = Loop.Vertices.Length; | ||
NewLoop = new EdgeLoop(Mesh); | ||
NewLoop.Vertices = new int[NV]; | ||
|
||
for ( int i = 0; i < NV; ++i ) { | ||
int vid = Loop.Vertices[i]; | ||
NewLoop.Vertices[i] = Mesh.AppendVertex(Mesh, vid); | ||
} | ||
|
||
// move to offset positions | ||
for ( int i = 0; i < NV; ++i ) { | ||
Vector3d v = Mesh.GetVertex(Loop.Vertices[i]); | ||
Vector3f n = Mesh.GetVertexNormal(Loop.Vertices[i]); | ||
Vector3d new_v = PositionF(v, n, i); | ||
Mesh.SetVertex(NewLoop.Vertices[i], new_v); | ||
} | ||
|
||
// stitch interior | ||
MeshEditor edit = new MeshEditor(Mesh); | ||
NewTriangles = edit.StitchLoop(Loop.Vertices, NewLoop.Vertices, group_id); | ||
|
||
return true; | ||
} | ||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
|
||
namespace g3 | ||
{ | ||
public enum ValidationStatus | ||
{ | ||
Ok, | ||
|
||
NotBoundaryVertex, | ||
NotBoundaryEdge, | ||
|
||
VerticesNotConnectedByEdge, | ||
IncorrectLoopOrientation | ||
} | ||
|
||
|
||
public static class MeshValidation | ||
{ | ||
|
||
public static ValidationStatus IsBoundaryLoop(DMesh3 mesh, EdgeLoop loop) | ||
{ | ||
int N = loop.Vertices.Length; | ||
|
||
for ( int i = 0; i < N; ++i ) { | ||
if ( ! mesh.vertex_is_boundary(loop.Vertices[i]) ) | ||
return ValidationStatus.NotBoundaryVertex; | ||
} | ||
|
||
for ( int i = 0; i < N; ++i ) { | ||
int a = loop.Vertices[i]; | ||
int b = loop.Vertices[(i + 1) % N]; | ||
|
||
int eid = mesh.FindEdge(a, b); | ||
if (eid == DMesh3.InvalidID) | ||
return ValidationStatus.VerticesNotConnectedByEdge; | ||
|
||
if (mesh.edge_is_boundary(eid) == false) | ||
return ValidationStatus.NotBoundaryEdge; | ||
|
||
Index2i ev = mesh.GetOrientedBoundaryEdgeV(eid); | ||
if (!(ev.a == a && ev.b == b)) | ||
return ValidationStatus.IncorrectLoopOrientation; | ||
} | ||
|
||
return ValidationStatus.Ok; | ||
} | ||
|
||
|
||
} | ||
} |