|
5 | 5 |
|
6 | 6 | public class Builder
|
7 | 7 | {
|
8 |
| - public static MeshData TesselatePolygon(Geometry geometry, Color color, float height) |
9 |
| - { |
10 |
| - var meshData = new MeshData(); |
11 |
| - var tess = new Tess(); |
12 |
| - |
13 |
| - int pointIndex = 0; |
14 |
| - foreach (var ringSize in geometry.rings) |
15 |
| - { |
16 |
| - var contour = new ContourVertex[ringSize]; |
17 |
| - |
18 |
| - for (int i = pointIndex, contourIndex = 0; i < pointIndex + ringSize; ++i, ++contourIndex) |
19 |
| - { |
20 |
| - var point = geometry.points[i]; |
21 |
| - contour[contourIndex].Position = new Vec3 { X = point.x, Y = height, Z = point.y }; |
22 |
| - } |
23 |
| - |
24 |
| - pointIndex += ringSize; |
25 |
| - |
26 |
| - tess.AddContour(contour, ContourOrientation.Original); |
27 |
| - } |
28 |
| - |
29 |
| - tess.Tessellate(WindingRule.NonZero, ElementType.Polygons, 3); |
30 |
| - |
31 |
| - for (int i = 0; i < tess.ElementCount * 3; ++i) |
32 |
| - { |
33 |
| - meshData.indices.Add(tess.Elements[i]); |
34 |
| - } |
35 |
| - |
36 |
| - for (int i = 0; i < tess.VertexCount; ++i) |
37 |
| - { |
38 |
| - var position = tess.Vertices[i].Position; |
39 |
| - meshData.vertices.Add(new Vector3(position.X, position.Y, position.Z)); |
40 |
| - meshData.colors.Add(color); |
41 |
| - } |
42 |
| - |
43 |
| - return meshData; |
44 |
| - } |
45 |
| - |
46 |
| - public static MeshData TesselatePolygonExtrusion(Geometry geometry, Color color, float minHeight, float height) |
47 |
| - { |
48 |
| - var meshData = new MeshData(); |
49 |
| - int pointIndex = 0; |
50 |
| - int indexOffset = 0; |
51 |
| - |
52 |
| - foreach (var ringSize in geometry.rings) |
53 |
| - { |
54 |
| - for (int i = pointIndex; i < pointIndex + ringSize - 1; i++) |
55 |
| - { |
56 |
| - var p0 = geometry.points[i]; |
57 |
| - var p1 = geometry.points[i+1]; |
58 |
| - |
59 |
| - meshData.vertices.Add(new Vector3(p0.x, height, p0.y)); |
60 |
| - meshData.vertices.Add(new Vector3(p1.x, height, p1.y)); |
61 |
| - meshData.vertices.Add(new Vector3(p0.x, minHeight, p0.y)); |
62 |
| - meshData.vertices.Add(new Vector3(p1.x, minHeight, p1.y)); |
63 |
| - |
64 |
| - for (int colorIndex = 0; colorIndex < 4; ++colorIndex) |
65 |
| - { |
66 |
| - meshData.colors.Add(color); |
67 |
| - } |
68 |
| - |
69 |
| - meshData.indices.Add(indexOffset + 2); |
70 |
| - meshData.indices.Add(indexOffset + 3); |
71 |
| - meshData.indices.Add(indexOffset + 1); |
72 |
| - meshData.indices.Add(indexOffset + 2); |
73 |
| - meshData.indices.Add(indexOffset + 1); |
74 |
| - meshData.indices.Add(indexOffset + 0); |
75 |
| - |
76 |
| - indexOffset += 4; |
77 |
| - } |
78 |
| - |
79 |
| - pointIndex += ringSize; |
80 |
| - } |
81 |
| - |
82 |
| - return meshData; |
83 |
| - } |
| 8 | + public static MeshData TesselatePolygon(Geometry geometry, Color color, float height) |
| 9 | + { |
| 10 | + var meshData = new MeshData(); |
| 11 | + var tess = new Tess(); |
| 12 | + |
| 13 | + int pointIndex = 0; |
| 14 | + foreach (var ringSize in geometry.rings) |
| 15 | + { |
| 16 | + var contour = new ContourVertex[ringSize]; |
| 17 | + |
| 18 | + for (int i = pointIndex, contourIndex = 0; i < pointIndex + ringSize; ++i, ++contourIndex) |
| 19 | + { |
| 20 | + var point = geometry.points[i]; |
| 21 | + contour[contourIndex].Position = new Vec3 { X = point.x, Y = height, Z = point.y }; |
| 22 | + } |
| 23 | + |
| 24 | + pointIndex += ringSize; |
| 25 | + |
| 26 | + tess.AddContour(contour, ContourOrientation.Original); |
| 27 | + } |
| 28 | + |
| 29 | + tess.Tessellate(WindingRule.NonZero, ElementType.Polygons, 3); |
| 30 | + |
| 31 | + for (int i = 0; i < tess.ElementCount * 3; ++i) |
| 32 | + { |
| 33 | + meshData.indices.Add(tess.Elements[i]); |
| 34 | + } |
| 35 | + |
| 36 | + for (int i = 0; i < tess.VertexCount; ++i) |
| 37 | + { |
| 38 | + var position = tess.Vertices[i].Position; |
| 39 | + meshData.vertices.Add(new Vector3(position.X, position.Y, position.Z)); |
| 40 | + meshData.colors.Add(color); |
| 41 | + } |
| 42 | + |
| 43 | + return meshData; |
| 44 | + } |
| 45 | + |
| 46 | + public static MeshData TesselatePolygonExtrusion(Geometry geometry, Color color, float minHeight, float height) |
| 47 | + { |
| 48 | + var meshData = new MeshData(); |
| 49 | + int pointIndex = 0; |
| 50 | + int indexOffset = 0; |
| 51 | + |
| 52 | + foreach (var ringSize in geometry.rings) |
| 53 | + { |
| 54 | + for (int i = pointIndex; i < pointIndex + ringSize - 1; i++) |
| 55 | + { |
| 56 | + var p0 = geometry.points[i]; |
| 57 | + var p1 = geometry.points[i + 1]; |
| 58 | + |
| 59 | + meshData.vertices.Add(new Vector3(p0.x, height, p0.y)); |
| 60 | + meshData.vertices.Add(new Vector3(p1.x, height, p1.y)); |
| 61 | + meshData.vertices.Add(new Vector3(p0.x, minHeight, p0.y)); |
| 62 | + meshData.vertices.Add(new Vector3(p1.x, minHeight, p1.y)); |
| 63 | + |
| 64 | + for (int colorIndex = 0; colorIndex < 4; ++colorIndex) |
| 65 | + { |
| 66 | + meshData.colors.Add(color); |
| 67 | + } |
| 68 | + |
| 69 | + meshData.indices.Add(indexOffset + 2); |
| 70 | + meshData.indices.Add(indexOffset + 3); |
| 71 | + meshData.indices.Add(indexOffset + 1); |
| 72 | + meshData.indices.Add(indexOffset + 2); |
| 73 | + meshData.indices.Add(indexOffset + 1); |
| 74 | + meshData.indices.Add(indexOffset + 0); |
| 75 | + |
| 76 | + indexOffset += 4; |
| 77 | + } |
| 78 | + |
| 79 | + pointIndex += ringSize; |
| 80 | + } |
| 81 | + |
| 82 | + return meshData; |
| 83 | + } |
84 | 84 | }
|
0 commit comments