void Triangulate(Cell cell) { Vector3 center = cell.transform.localPosition; Vector3 v1 = center + CellMetrics.corners[0]; Vector3 v2 = center + CellMetrics.corners[1]; Vector3 v3 = center + CellMetrics.corners[2]; Vector3 v4 = center + CellMetrics.corners[3]; terrain.AddQuad(v1, v2, v3, v4); terrain.AddQuadColor(cell.Color); if (cell.isUnderWater) { Vector3 waterCenter = center; waterCenter.y = cell.WaterSurfaceY; v1 = waterCenter + CellMetrics.corners[0]; v2 = waterCenter + CellMetrics.corners[1]; v3 = waterCenter + CellMetrics.corners[2]; v4 = waterCenter + CellMetrics.corners[3]; water.AddQuad(v1, v2, v3, v4); } TriangulateConnection(cell, Direction.S); TriangulateConnection(cell, Direction.E); }
void MakeCornerBridge(GridMesh mesh, Vector3 v0, GridDirection bridgeDirection) { Vector3 b0 = GridMetrics.GetBridge(bridgeDirection.Previous()); Vector3 b1 = GridMetrics.GetBridge(bridgeDirection.Next()); mesh.AddQuad(v0, v0 + b0, v0 + b0 + b1, v0 + b1); if (mesh.useUVCoordinates) { mesh.AddQuadUV(0f, 0f, 0f, 1f); } }
void AddCliffEdge(SquareCell cell, GridDirection direction) { GridDirection prev = direction.Previous(); GridDirection next = direction.Next(); GridDirection prevN = prev.Previous2(); GridDirection nextN = next.Next2(); SquareCell neighbor = cell.GetNeighbor(direction); if (neighbor != null) { Vector3 c0 = new Vector3(cell.coordinates.X, 0, cell.coordinates.Z) + GridMetrics.GetEdge(prev) + Vector3.up * (int)cell.GridElevations[prev] * GridMetrics.elevationStep; Vector3 c1 = new Vector3(cell.coordinates.X, 0, cell.coordinates.Z) + GridMetrics.GetEdge(next) + Vector3.up * (int)cell.GridElevations[next] * GridMetrics.elevationStep; Vector3 n0 = new Vector3(neighbor.coordinates.X, 0, neighbor.coordinates.Z) + GridMetrics.GetEdge(prevN) + Vector3.up * (int)neighbor.GridElevations[prevN] * GridMetrics.elevationStep; Vector3 n1 = new Vector3(neighbor.coordinates.X, 0, neighbor.coordinates.Z) + GridMetrics.GetEdge(nextN) + Vector3.up * (int)neighbor.GridElevations[nextN] * GridMetrics.elevationStep; if (c0 != n0 && c1 != n1) { if (c0.y > n0.y && n1.y > c1.y) // if edges cross heights along edge X { Vector2 cross = CrossingPoint(c1.y - c0.y, n1.y - n0.y, c0.y, n0.y); Vector3 worldCross = new Vector3(cell.coordinates.X, 0, cell.coordinates.Z) + GridMetrics.GetEdge(direction.Previous()) + (cross.x * 2 * GridMetrics.GetEdge(direction.Next2())) + new Vector3(0, cross.y, 0); terrain.AddTriangle(worldCross, c0, n0); terrain.AddTriangleColor(Color.cyan); terrain.AddTriangle(worldCross, n1, c1); terrain.AddTriangleColor(Color.green); } else if (c0.y > n0.y && c1.y > n1.y) // if one edge is always above the other { terrain.AddQuad(c0, n0, n1, c1); terrain.AddQuadColor(retainingWallColor); } } else if (c0.y > n0.y) { terrain.AddTriangle(c0, n0, c1); terrain.AddTriangleColor(retainingWallColor); } else if (c1.y > n1.y) { terrain.AddTriangle(c0, n1, c1); terrain.AddTriangleColor(retainingWallColor); } } }
void MakeBridge(GridMesh mesh, Vector3 v0, Vector3 v1, GridDirection bridgeDirection) { Vector3 bridge = GridMetrics.GetBridge(bridgeDirection); Vector3 e0 = v0 + bridge; Vector3 e1 = v1 + bridge; mesh.AddQuad(v0, e0, e1, v1); if (mesh.useUVCoordinates) { mesh.AddQuadUV(0f, 0f, 0f, 1f); } }