-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMeshTessellate.cs
68 lines (58 loc) · 2.37 KB
/
MeshTessellate.cs
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
using System.Collections.Generic;
using System.Linq;
using Sceelix.Core.Annotations;
using Sceelix.Core.Attributes;
using Sceelix.Core.IO;
using Sceelix.Core.Parameters;
using Sceelix.Core.Procedures;
using Sceelix.Extensions;
using Sceelix.Mathematics.Data;
using Sceelix.Meshes.Data;
using Sceelix.Meshes.Procedures;
using Sceelix.Paths.Data;
namespace Sceelix.MyNewEngineLibrary
{
/// <summary>
/// Subdivides the mesh's faces (preferably triangles) into smaller faces,
/// like Mesh Split, but independent of the faces' orientations.
/// </summary>
[Procedure("8034DF9C-9104-453D-B249-B06D9073AC32", Label = "Mesh Tessellate")]
public class MeshTessellate : SystemProcedure
{
/// <summary>
/// Inputs and Output
/// </summary>
private readonly SingleInput<MeshEntity> _inputA = new SingleInput<MeshEntity>("Input");
private readonly Output<MeshEntity> _output = new Output<MeshEntity>("Output");
/// <summary>
/// The desired operation
/// </summary>
private readonly ChoiceParameter _parameterOperation = new ChoiceParameter("Operation", "Triangulate", new string[]
{
"Triangulate",
"Tessellate"
});
protected override void Run()
{
MeshEntity meshEntityA = _inputA.Read();
List<Face> tris = new List<Face>();
if(_parameterOperation.Value == "Triangulate")
foreach(Face face0 in meshEntityA.Faces)
Tessellation.TriangleFan(face0, tris);
if(_parameterOperation.Value == "Tessellate")
foreach(Face face1 in meshEntityA.Faces)
{
List<Face> intermediate = new List<Face>();
Tessellation.TriangleFan(face1, intermediate);
foreach(Face intFace in intermediate)
Tessellation.Tessellate(intFace, tris);
}
MeshEntity output = new MeshEntity(tris.ToArray());
// And, weld the vertices of adjacent faces.
MeshUnifyProcedure.UnifyVerticesParameter.Unify(output);
meshEntityA.Attributes.SetAttributesTo(output.Attributes);
//finally, return the newly create meshEntity
_output.Write(output);
}
}
}