-
Notifications
You must be signed in to change notification settings - Fork 434
Expand file tree
/
Copy pathMeshExtrudeLoop.cs
More file actions
74 lines (56 loc) · 2.03 KB
/
MeshExtrudeLoop.cs
File metadata and controls
74 lines (56 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using System;
using System.Diagnostics;
namespace g3
{
/// <summary>
/// Assumption is that Loop is a boundary loop on Mesh.
/// Operation makes a duplicate loop of vertices, at location defind by PositionF,
/// then stitches input and new loops together with a ring of triangles.
/// </summary>
public class MeshExtrudeLoop
{
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 MeshExtrudeLoop(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;
}
}
}