-
Notifications
You must be signed in to change notification settings - Fork 71
/
Copy pathExtruder.cs
82 lines (67 loc) · 2.26 KB
/
Extruder.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DWriteFactory = SharpDX.DirectWrite.Factory;
using D2DFactory = SharpDX.Direct2D1.Factory;
using D2DGeometry = SharpDX.Direct2D1.Geometry;
using SharpDX.DirectWrite;
using SharpDX;
using VVVV.DX11.Nodes;
using SharpDX.Direct2D1;
namespace VVVV.DX11.Text3d
{
public class Extruder
{
private D2DFactory factory;
public Extruder(D2DFactory factory)
{
this.factory = factory;
}
const float sc_flatteningTolerance = .1f;
private D2DGeometry FlattenGeometry(D2DGeometry geometry, float tolerance)
{
PathGeometry path = new PathGeometry(this.factory);
using (GeometrySink sink = path.Open())
{
geometry.Simplify(GeometrySimplificationOption.Lines, tolerance, sink);
sink.Close();
}
return path;
}
private D2DGeometry OutlineGeometry(D2DGeometry geometry)
{
PathGeometry path = new PathGeometry(this.factory);
using (GeometrySink sink = path.Open())
{
geometry.Outline(sink);
sink.Close();
}
return path;
}
public void GetVertices(D2DGeometry geometry, List<Pos3Norm3VertexSDX> vertices, float height = 24.0f)
{
vertices.Clear();
//Empty mesh
if (geometry == null)
{
Pos3Norm3VertexSDX zero = new Pos3Norm3VertexSDX();
vertices.Add(zero);
vertices.Add(zero);
vertices.Add(zero);
}
using (D2DGeometry flattenedGeometry = this.FlattenGeometry(geometry, sc_flatteningTolerance))
{
using (D2DGeometry outlinedGeometry = this.OutlineGeometry(flattenedGeometry))
{
using (ExtrudingSink sink = new ExtrudingSink(vertices, height))
{
outlinedGeometry.Simplify(GeometrySimplificationOption.Lines, sink);
outlinedGeometry.Tessellate(sink);
}
}
}
}
}
}