public void TriangulateAllCells() { // This method could be invoked at any time, even when cells have already been triangulated earlier. // So we should begin by clearing the old data. Terrain.Clear(); Rivers.Clear(); Roads.Clear(); Water.Clear(); WaterShore.Clear(); Estuaries.Clear(); Features.Clear(); for (int i = 0; i < _cells.Length; i++) { Precalculation(_cells[i]); } for (int i = 0; i < _cells.Length; i++) { TriangulateCell(_cells[i]); AddFeatures(_cells[i]); } Terrain.Apply(); Rivers.Apply(); Roads.Apply(); Water.Apply(); WaterShore.Apply(); Estuaries.Apply(); Features.Apply(); }
void TriangulateEstuary(HexCell cell, HexDirection direction) { var neighbor = cell.GetNeighbor(direction); EdgeVertices closerWaterEdge = cell.WaterEdges[(int)direction]; EdgeVertices furtherWaterEdge = neighbor.WaterEdges[(int)direction.Opposite()]; EdgeVertices furtherEdge = neighbor.Edges[(int)direction.Opposite()]; furtherEdge.V1.y = HexMetrics.WaterSurfaceY; furtherEdge.V2.y = HexMetrics.WaterSurfaceY; furtherEdge.V3.y = HexMetrics.WaterSurfaceY; furtherEdge.V4.y = HexMetrics.WaterSurfaceY; furtherEdge.V5.y = HexMetrics.WaterSurfaceY; WaterShore.AddTriangleUnperturbed(furtherEdge.V5, closerWaterEdge.V2, closerWaterEdge.V1); WaterShore.AddTriangleUnperturbed(furtherEdge.V1, closerWaterEdge.V5, closerWaterEdge.V4); WaterShore.AddTriangleUV(new Vector2(0f, 1f), new Vector2(0f, 0f), new Vector2(0f, 0f)); WaterShore.AddTriangleUV(new Vector2(0f, 1f), new Vector2(0f, 0f), new Vector2(0f, 0f)); // left quad // quad is rotated 90 degrees to the right so the diagonal connection is shorter // it is done to maintain the symetry with the other quad Estuaries.AddQuadUnperturbed(furtherEdge.V5, closerWaterEdge.V2, furtherEdge.V4, closerWaterEdge.V3); Estuaries.AddQuadUV(new Vector2(0f, 1f), new Vector2(0f, 0f), new Vector2(1f, 1f), new Vector2(0f, 0f)); // big triangle in the middle Estuaries.AddTriangleUnperturbed(closerWaterEdge.V3, furtherEdge.V4, furtherEdge.V2); Estuaries.AddTriangleUV(new Vector2(0f, 0f), new Vector2(1f, 1f), new Vector2(0f, 1f)); // right quad Estuaries.AddQuadUnperturbed(closerWaterEdge.V3, closerWaterEdge.V4, furtherEdge.V2, furtherEdge.V1); Estuaries.AddQuadUV(new Vector2(0f, 0f), new Vector2(0f, 0f), new Vector2(1f, 1f), new Vector2(0f, 1f)); // is incoming river if (cell.IncomingRiver == direction) { Estuaries.AddQuadUV2( new Vector2(1.5f, 1f), new Vector2(0.7f, 1.15f), new Vector2(1f, 0.8f), new Vector2(0.5f, 1.1f)); Estuaries.AddTriangleUV2( new Vector2(0.5f, 1.1f), new Vector2(1f, 0.8f), new Vector2(0f, 0.8f)); Estuaries.AddQuadUV2( new Vector2(0.5f, 1.1f), new Vector2(0.3f, 1.15f), new Vector2(0f, 0.8f), new Vector2(-0.5f, 1f)); } else { // the U coordinates have to be mirrored for outgoing rivers // the V coordinates are a little bit less straightforward Estuaries.AddQuadUV2( new Vector2(-0.5f, -0.2f), new Vector2(0.3f, -0.35f), new Vector2(0f, 0f), new Vector2(0.5f, -0.3f)); Estuaries.AddTriangleUV2( new Vector2(0.5f, -0.3f), new Vector2(0f, 0f), new Vector2(1f, 0f)); Estuaries.AddQuadUV2( new Vector2(0.5f, -0.3f), new Vector2(0.7f, -0.35f), new Vector2(1f, 0f), new Vector2(1.5f, -0.2f)); } }
private void TriangulateEstuary(EdgeVertices e1, EdgeVertices e2, bool incomingRiver, Vector3 indices) { WaterShore.AddTriangle(e2.v1, e1.v2, e1.v1); WaterShore.AddTriangle(e2.v5, e1.v5, e1.v4); WaterShore.AddTriangleUV( new Vector2(0f, 1f), new Vector2(0f, 0f), new Vector2(0f, 0f) ); WaterShore.AddTriangleUV( new Vector2(0f, 1f), new Vector2(0f, 0f), new Vector2(0f, 0f) ); WaterShore.AddTriangleCellData(indices, weights2, weights1, weights1); WaterShore.AddTriangleCellData(indices, weights2, weights1, weights1); Estuaries.AddQuad(e2.v1, e1.v2, e2.v2, e1.v3); Estuaries.AddTriangle(e1.v3, e2.v2, e2.v4); Estuaries.AddQuad(e1.v3, e1.v4, e2.v4, e2.v5); Estuaries.AddQuadUV( new Vector2(0f, 1f), new Vector2(0f, 0f), new Vector2(1f, 1f), new Vector2(0f, 0f)); Estuaries.AddTriangleUV( new Vector2(0f, 0f), new Vector2(1f, 1f), new Vector2(1f, 1f)); Estuaries.AddQuadUV( new Vector2(0f, 0f), new Vector2(0f, 0f), new Vector2(1f, 1f), new Vector2(0f, 1f)); Estuaries.AddQuadCellData(indices, weights2, weights1, weights2, weights1); Estuaries.AddTriangleCellData(indices, weights1, weights2, weights2); Estuaries.AddQuadCellData(indices, weights1, weights2); if (incomingRiver) { Estuaries.AddQuadUV2( new Vector2(1.5f, 1f), new Vector2(0.7f, 1.15f), new Vector2(1f, 0.8f), new Vector2(0.5f, 1.1f)); Estuaries.AddTriangleUV2( new Vector2(0.5f, 1.1f), new Vector2(1f, 0.8f), new Vector2(0f, 0.8f)); Estuaries.AddQuadUV2( new Vector2(0.5f, 1.1f), new Vector2(0.3f, 1.15f), new Vector2(0f, 0.8f), new Vector2(-0.5f, 1f)); } else { Estuaries.AddQuadUV2( new Vector2(-0.5f, -0.2f), new Vector2(0.3f, -0.35f), new Vector2(0f, 0f), new Vector2(0.5f, -0.3f)); Estuaries.AddTriangleUV2( new Vector2(0.5f, -0.3f), new Vector2(0f, 0f), new Vector2(1f, 0f)); Estuaries.AddQuadUV2( new Vector2(0.5f, -0.3f), new Vector2(0.7f, -0.35f), new Vector2(1f, 0f), new Vector2(1.5f, -0.2f)); } }
/// <summary> /// Creates the estuary (when river meets shore) geometry. /// </summary> void TriangulateEstuary(EdgeVertices e1, EdgeVertices e2, bool incomingRiver, Vector3 indices) { // Some of the estuary is still water shore, namely one triangle on each side // that leaves the estuary itself with a trapezoid shape connecting the shore/river to water WaterShore.AddTriangle(e2.v1, e1.v2, e1.v1); WaterShore.AddTriangle(e2.v5, e1.v5, e1.v4); WaterShore.AddTriangleUV(new Vector2(0f, 1f), new Vector2(0f, 0f), new Vector2(0f, 0f)); WaterShore.AddTriangleUV(new Vector2(0f, 1f), new Vector2(0f, 0f), new Vector2(0f, 0f)); WaterShore.AddTriangleCellData(indices, weights2, weights1, weights1); WaterShore.AddTriangleCellData(indices, weights2, weights1, weights1); // Make the estuary trapezoid Estuaries.AddQuad(e2.v1, e1.v2, e2.v2, e1.v3); // Adding it rotated for symetric geometry Estuaries.AddTriangle(e1.v3, e2.v2, e2.v4); Estuaries.AddQuad(e1.v3, e1.v4, e2.v4, e2.v5); // For shore effect Estuaries.AddQuadUV( new Vector2(0f, 1f), new Vector2(0f, 0f), new Vector2(1f, 1f), new Vector2(0f, 0f) ); Estuaries.AddTriangleUV( new Vector2(0f, 0f), new Vector2(1f, 1f), new Vector2(1f, 1f) ); Estuaries.AddQuadUV( new Vector2(0f, 0f), new Vector2(0f, 0f), new Vector2(1f, 1f), new Vector2(0f, 1f) ); Estuaries.AddQuadCellData(indices, weights2, weights1, weights2, weights1); Estuaries.AddTriangleCellData(indices, weights1, weights2, weights2); Estuaries.AddQuadCellData(indices, weights1, weights2); // For river effect, depending on river flow direction UVs are different // That is if river flows into the water or out of the water (e.g. when a river starts from a lake) if (incomingRiver) { Estuaries.AddQuadUV2(new Vector2(1.5f, 1f), new Vector2(0.7f, 1.15f), new Vector2(1f, 0.8f), new Vector2(0.5f, 1.1f)); Estuaries.AddTriangleUV2(new Vector2(0.5f, 1.1f), new Vector2(1f, 0.8f), new Vector2(0f, 0.8f)); Estuaries.AddQuadUV2(new Vector2(0.5f, 1.1f), new Vector2(0.3f, 1.15f), new Vector2(0f, 0.8f), new Vector2(-0.5f, 1f)); } else { Estuaries.AddQuadUV2(new Vector2(-0.5f, -0.2f), new Vector2(0.3f, -0.35f), new Vector2(0f, 0f), new Vector2(0.5f, -0.3f)); Estuaries.AddTriangleUV2(new Vector2(0.5f, -0.3f), new Vector2(0f, 0f), new Vector2(1f, 0f)); Estuaries.AddQuadUV2(new Vector2(0.5f, -0.3f), new Vector2(0.7f, -0.35f), new Vector2(1f, 0f), new Vector2(1.5f, -0.2f)); } }
/// <summary> /// Builds the mesh of the hex grid out of the provided array of cells. /// </summary> public void Triangulate() { Terrain.Clear(); Rivers.Clear(); Roads.Clear(); Water.Clear(); WaterShore.Clear(); Estuaries.Clear(); Features.Clear(); for (int i = 0; i < Cells.Length; i++) { Triangulate(Cells[i]); } Terrain.Apply(); Rivers.Apply(); Roads.Apply(); Water.Apply(); WaterShore.Apply(); Estuaries.Apply(); Features.Apply(); }
public void Triangulate(HexCell[] cells) { Terrain.Clear(); Rivers.Clear(); Roads.Clear(); Water.Clear(); WaterShore.Clear(); Estuaries.Clear(); Features.Clear(); foreach (var cell in cells) { TriangulateCell(cell); } Terrain.Apply(); Rivers.Apply(); Roads.Apply(); Water.Apply(); WaterShore.Apply(); Estuaries.Apply(); Features.Apply(); }