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 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); } }
void AddMeshForSquare(SquareCell cell) { Vector3 centre = cell.transform.localPosition; Vector3 verticleCentre = centre + Vector3.up * cell.CentreElevation * GridMetrics.elevationStep; Vector3 vb0 = centre + GridMetrics.GetEdge(GridDirection.SW); Vector3 vb1 = centre + GridMetrics.GetEdge(GridDirection.NW); Vector3 vb2 = centre + GridMetrics.GetEdge(GridDirection.NE); Vector3 vb3 = centre + GridMetrics.GetEdge(GridDirection.SE); vb0 = vb0 + Vector3.up * (cell.GridElevations.Y0) * GridMetrics.elevationStep; vb1 = vb1 + Vector3.up * (cell.GridElevations.Y1) * GridMetrics.elevationStep; vb2 = vb2 + Vector3.up * (cell.GridElevations.Y2) * GridMetrics.elevationStep; vb3 = vb3 + Vector3.up * (cell.GridElevations.Y3) * GridMetrics.elevationStep; Vector3 vs0 = centre + GridMetrics.GetSolidEdge(GridDirection.SW); Vector3 vs1 = centre + GridMetrics.GetSolidEdge(GridDirection.NW); Vector3 vs2 = centre + GridMetrics.GetSolidEdge(GridDirection.NE); Vector3 vs3 = centre + GridMetrics.GetSolidEdge(GridDirection.SE); Vector3 bridgeW = GridMetrics.GetBridge(GridDirection.W); Vector3 bridgeN = GridMetrics.GetBridge(GridDirection.N); Vector3 bridgeE = GridMetrics.GetBridge(GridDirection.E); Vector3 bridgeS = GridMetrics.GetBridge(GridDirection.S); Vector3 vS0 = vs0 + bridgeS + GetVertexBlendElevation(cell.GridElevations, GridDirection.SW, GridDirection.S); Vector3 vW0 = vs0 + bridgeW + GetVertexBlendElevation(cell.GridElevations, GridDirection.SW, GridDirection.W); Vector3 vN1 = vs1 + bridgeN + GetVertexBlendElevation(cell.GridElevations, GridDirection.NW, GridDirection.N); Vector3 vW1 = vs1 + bridgeW + GetVertexBlendElevation(cell.GridElevations, GridDirection.NW, GridDirection.W); Vector3 vN2 = vs2 + bridgeN + GetVertexBlendElevation(cell.GridElevations, GridDirection.NE, GridDirection.N); Vector3 vE2 = vs2 + bridgeE + GetVertexBlendElevation(cell.GridElevations, GridDirection.NE, GridDirection.E); Vector3 vE3 = vs3 + bridgeE + GetVertexBlendElevation(cell.GridElevations, GridDirection.SE, GridDirection.E); Vector3 vS3 = vs3 + bridgeS + GetVertexBlendElevation(cell.GridElevations, GridDirection.SE, GridDirection.S); if (cell.GridElevations.Y0 == cell.GridElevations.Y2) // keep diagonals level { vs0 += Vector3.up * (cell.GridElevations.Y0) * GridMetrics.elevationStep; vs1 += GetDoubleVertexBlendElevation(cell.GridElevations, GridDirection.NW); vs2 += Vector3.up * (cell.GridElevations.Y2) * GridMetrics.elevationStep; vs3 += GetDoubleVertexBlendElevation(cell.GridElevations, GridDirection.SE); } else if (cell.GridElevations.Y1 == cell.GridElevations.Y3) { vs0 += GetDoubleVertexBlendElevation(cell.GridElevations, GridDirection.SW); vs1 += Vector3.up * (cell.GridElevations.Y1) * GridMetrics.elevationStep; vs2 += GetDoubleVertexBlendElevation(cell.GridElevations, GridDirection.NE); vs3 += Vector3.up * (cell.GridElevations.Y3) * GridMetrics.elevationStep; } else { vs0 += GetDoubleVertexBlendElevation(cell.GridElevations, GridDirection.SW); vs1 += GetDoubleVertexBlendElevation(cell.GridElevations, GridDirection.NW); vs2 += GetDoubleVertexBlendElevation(cell.GridElevations, GridDirection.NE); vs3 += GetDoubleVertexBlendElevation(cell.GridElevations, GridDirection.SE); } // Works out which diagonal to add if (cell.GridElevations.Y0 == cell.GridElevations.Y2 || Mathf.Abs(cell.GridElevations.Y0 - cell.GridElevations.Y2) < Mathf.Abs(cell.GridElevations.Y1 - cell.GridElevations.Y3)) // sets direction of the triangle pairs in the quad { AddHalfCell(cell, GridDirection.NW, centre, vs0, vs1, vs2, vN1, vN2, vW0, vW1, vb1, vb2, vE2); AddHalfCell(cell, GridDirection.SE, centre, vs2, vs3, vs0, vS3, vS0, vE2, vE3, vb3, vb0, vW0); } else { AddHalfCell(cell, GridDirection.SW, centre, vs3, vs0, vs1, vW0, vW1, vS3, vS0, vb0, vb1, vN1); AddHalfCell(cell, GridDirection.NE, centre, vs1, vs2, vs3, vE2, vE3, vN1, vN2, vb2, vb3, vS3); } if (cell.HasRoads) { TriangulateRoadCentre(cell, verticleCentre, vs0, vs1, vs2, vs3); } if (cell.HasRiver) { if (cell.HasRiverThroughEdge(GridDirection.N)) { TriangulateWithRiver(GridDirection.N, cell, centre, vs1, vb1, vb2, vs2, 0f); } else { TriangulateWithRiver(GridDirection.N, cell, centre, vs1, vb1, vb2, vs2, 0f); } if (cell.HasRiverThroughEdge(GridDirection.E)) { TriangulateWithRiver(GridDirection.E, cell, centre, vs2, vb2, vb3, vs3, 0.5f); } else { TriangulateWithRiver(GridDirection.E, cell, centre, vs2, vb2, vb3, vs3, 0.5f); } if (cell.HasRiverThroughEdge(GridDirection.S)) { TriangulateWithRiver(GridDirection.S, cell, centre, vs3, vb3, vb0, vs0, 1f); } else { TriangulateWithRiver(GridDirection.S, cell, centre, vs3, vb3, vb0, vs0, 1f); } if (cell.HasRiverThroughEdge(GridDirection.W)) { TriangulateWithRiver(GridDirection.W, cell, centre, vs0, vb0, vb1, vs1, 0.5f); } else { TriangulateWithRiver(GridDirection.W, cell, centre, vs0, vb0, vb1, vs1, 0.5f); } } if (cell.IsUnderwater) { AddWaterForSquare(cell, centre); } if (!cell.IsUnderwater && !cell.HasRoads) { features.AddFeature(cell, verticleCentre); } }