private void TriangulateCultureAlongContour( IHexCell center, HexDirection direction, Color color, IHexMesh cultureMesh ) { var contour = CellEdgeContourCanon.GetContourForCellEdge(center, direction); Vector2 innerCCW, innerCW, outerCCW, outerCW; for (int i = 0; i < contour.Count - 1; i++) { outerCCW = contour[i]; outerCW = contour[i + 1]; innerCCW = Vector2.Lerp(outerCCW, center.AbsolutePositionXZ, RenderConfig.CultureWidthPercent); innerCW = Vector2.Lerp(outerCW, center.AbsolutePositionXZ, RenderConfig.CultureWidthPercent); cultureMesh.AddQuad( new Vector3(innerCCW.x, 0f, innerCCW.y), new Vector3(innerCW.x, 0f, innerCW.y), new Vector3(outerCCW.x, 0f, outerCCW.y), new Vector3(outerCW.x, 0f, outerCW.y) ); cultureMesh.AddQuadUV(new Vector2(0f, 0f), new Vector2(0f, 0f), new Vector2(0f, 1f), new Vector2(0f, 1f)); cultureMesh.AddQuadColor(color); } }
public void TriangulateContoursBetween( IHexCell center, IHexCell right, HexDirection direction, Color centerWeights, Color rightWeights, IHexMesh mesh ) { var centerRightContour = CellContourCanon.GetContourForCellEdge(center, direction); var rightCenterContour = CellContourCanon.GetContourForCellEdge(right, direction.Opposite()); int centerRightIndex = 1, rightCenterIndex = rightCenterContour.Count - 1; while (centerRightIndex < centerRightContour.Count && rightCenterIndex > 0) { mesh.AddQuad( centerRightContour[centerRightIndex - 1].ToXYZ(), centerRightContour[centerRightIndex].ToXYZ(), rightCenterContour[rightCenterIndex].ToXYZ(), rightCenterContour[rightCenterIndex - 1].ToXYZ() ); mesh.AddQuadColor(centerWeights, rightWeights); centerRightIndex++; rightCenterIndex--; } for (; centerRightIndex < centerRightContour.Count; centerRightIndex++) { mesh.AddTriangle( centerRightContour[centerRightIndex - 1].ToXYZ(), rightCenterContour[0].ToXYZ(), centerRightContour[centerRightIndex].ToXYZ() ); mesh.AddTriangleColor(centerWeights, rightWeights, centerWeights); } for (; rightCenterIndex > 0; rightCenterIndex--) { mesh.AddTriangle( centerRightContour.Last().ToXYZ(), rightCenterContour[rightCenterIndex].ToXYZ(), rightCenterContour[rightCenterIndex - 1].ToXYZ() ); mesh.AddTriangleColor(centerWeights, rightWeights, rightWeights); } if (RiverCanon.HasRiverAlongEdge(right, direction.Next2())) { var nextRight = Grid.GetNeighbor(center, direction.Next()); var rightNextRightContour = CellContourCanon.GetContourForCellEdge(right, direction.Next2()); var nextRightRightContour = CellContourCanon.GetContourForCellEdge(nextRight, direction.Previous()); mesh.AddTriangle( centerRightContour.Last().ToXYZ(), rightNextRightContour.Last().ToXYZ(), nextRightRightContour.First().ToXYZ() ); mesh.AddTriangleColor(centerWeights, rightWeights, rightWeights); } }
private void TriangulateCellWeights_River( IHexCell center, IHexCell right, HexDirection direction, bool hasCenterRightRiver, IHexMesh weightsMesh ) { var centerRightContour = CellContourCanon.GetContourForCellEdge(center, direction); Vector3 innerOne, innerTwo, contourOneXYZ, contourTwoXYZ; for (int i = 1; i < centerRightContour.Count; i++) { contourOneXYZ = centerRightContour[i - 1].ToXYZ(); contourTwoXYZ = centerRightContour[i].ToXYZ(); innerOne = Vector3.Lerp(center.AbsolutePosition, contourOneXYZ, RenderConfig.SolidFactor); innerTwo = Vector3.Lerp(center.AbsolutePosition, contourTwoXYZ, RenderConfig.SolidFactor); weightsMesh.AddTriangle(center.AbsolutePosition, innerOne, innerTwo); weightsMesh.AddTriangleColor(CenterWeights); weightsMesh.AddQuad(innerOne, innerTwo, contourOneXYZ, contourTwoXYZ); if (hasCenterRightRiver) { weightsMesh.AddQuadColor(CenterWeights); } else { weightsMesh.AddQuadColor(CenterWeights, CenterRightWeights); } } if (hasCenterRightRiver && direction <= HexDirection.SE) { ContourTriangulator.TriangulateContoursBetween( center, right, direction, CenterWeights, RightWeights, weightsMesh ); } }
private void TriangulateWaterEdge( IHexCell center, Vector3 localCenterPos, Color centerColor, IHexCell right, Vector3 localRightPos, Color rightColor, HexDirection direction, IHexMesh mesh ) { mesh.AddQuad( localCenterPos + RenderConfig.GetFirstSolidCorner(direction), localCenterPos + RenderConfig.GetSecondSolidCorner(direction), localRightPos + RenderConfig.GetSecondSolidCorner(direction.Opposite()), localRightPos + RenderConfig.GetFirstSolidCorner(direction.Opposite()) ); mesh.AddQuadColor(centerColor, rightColor); }
private void TriangulateCellWeights_NoRiver( IHexCell center, IHexCell right, HexDirection direction, IHexMesh weightsMesh ) { if (right == null) { weightsMesh.AddTriangle( center.AbsolutePosition, center.AbsolutePosition + RenderConfig.GetFirstCorner(direction), center.AbsolutePosition + RenderConfig.GetSecondCorner(direction) ); weightsMesh.AddTriangleColor(CenterWeights); return; } Vector3 firstEdgeInner = center.AbsolutePosition + RenderConfig.GetFirstSolidCorner(direction); Vector3 secondEdgeInner = center.AbsolutePosition + RenderConfig.GetSecondSolidCorner(direction); //Solid center region weightsMesh.AddTriangle(center.AbsolutePosition, firstEdgeInner, secondEdgeInner); weightsMesh.AddTriangleColor(CenterWeights); Vector3 firstEdgeOuter = (firstEdgeInner + right.AbsolutePosition + RenderConfig.GetSecondSolidCorner(direction.Opposite())) / 2f; Vector3 secondEdgeOuter = (secondEdgeInner + right.AbsolutePosition + RenderConfig.GetFirstSolidCorner(direction.Opposite())) / 2f; //The edge between Center and Right, going up to the dividing line weightsMesh.AddQuad(firstEdgeInner, secondEdgeInner, firstEdgeOuter, secondEdgeOuter); weightsMesh.AddQuadColor(CenterWeights, CenterRightWeights); //Previous corner out to the edge of the cell weightsMesh.AddTriangle(firstEdgeInner, center.AbsolutePosition + RenderConfig.GetFirstCorner(direction), firstEdgeOuter); weightsMesh.AddTriangleColor(CenterWeights, CenterLeftRightWeights, CenterRightWeights); //Next corner out to the edge of the cell weightsMesh.AddTriangle(secondEdgeInner, secondEdgeOuter, center.AbsolutePosition + RenderConfig.GetSecondCorner(direction)); weightsMesh.AddTriangleColor(CenterWeights, CenterRightWeights, CenterRightNextRightWeights); }
private void TriangulateCultureCorners_River( IHexCell center, IHexCell left, IHexCell right, IHexCell nextRight, HexDirection direction, ICivilization centerOwner, ReadOnlyCollection <Vector2> centerRightContour, IHexMesh cultureMesh ) { Color cultureColor = centerOwner.Template.Color; if (left != null && CivTerritoryLogic.GetCivClaimingCell(left) != centerOwner) { float ccwTransparency = 1f, cwTransparency; Vector2 innerCCW, innerCW, outerCCW, outerCW; float cultureWidth = (centerRightContour.First() - center.AbsolutePositionXZ).magnitude * RenderConfig.CultureWidthPercent; int i = 0; do { outerCCW = centerRightContour[i]; outerCW = centerRightContour[i + 1]; float distanceFromStart = (centerRightContour.First() - outerCW).magnitude; cwTransparency = Mathf.Clamp01(1f - distanceFromStart / cultureWidth); innerCCW = Vector2.Lerp(outerCCW, center.AbsolutePositionXZ, RenderConfig.CultureWidthPercent); innerCW = Vector2.Lerp(outerCW, center.AbsolutePositionXZ, RenderConfig.CultureWidthPercent); cultureMesh.AddQuad( new Vector3(innerCCW.x, 0f, innerCCW.y), new Vector3(innerCW.x, 0f, innerCW.y), new Vector3(outerCCW.x, 0f, outerCCW.y), new Vector3(outerCW.x, 0f, outerCW.y) ); cultureMesh.AddQuadUV( new Vector2(0f, 0f), new Vector2(0f, 0f), new Vector2(0f, ccwTransparency), new Vector2(0f, cwTransparency) ); cultureMesh.AddQuadColor(cultureColor); ccwTransparency = cwTransparency; i++; } while(cwTransparency > 0f && i < centerRightContour.Count - 1); } if (nextRight != null && CivTerritoryLogic.GetCivClaimingCell(nextRight) != centerOwner) { float cwTransparency = 1f, ccwTransparency; Vector2 innerCCW, innerCW, outerCCW, outerCW; float cultureWidth = (centerRightContour.Last() - center.AbsolutePositionXZ).magnitude * RenderConfig.CultureWidthPercent; int i = centerRightContour.Count - 1; do { outerCCW = centerRightContour[i - 1]; outerCW = centerRightContour[i]; float distanceFromStart = (centerRightContour.Last() - outerCCW).magnitude; ccwTransparency = Mathf.Clamp01(1f - distanceFromStart / cultureWidth); innerCCW = Vector2.Lerp(outerCCW, center.AbsolutePositionXZ, RenderConfig.CultureWidthPercent); innerCW = Vector2.Lerp(outerCW, center.AbsolutePositionXZ, RenderConfig.CultureWidthPercent); cultureMesh.AddQuad( new Vector3(innerCCW.x, 0f, innerCCW.y), new Vector3(innerCW.x, 0f, innerCW.y), new Vector3(outerCCW.x, 0f, outerCCW.y), new Vector3(outerCW.x, 0f, outerCW.y) ); cultureMesh.AddQuadUV( new Vector2(0f, 0f), new Vector2(0f, 0f), new Vector2(0f, ccwTransparency), new Vector2(0f, cwTransparency) ); cultureMesh.AddQuadColor(cultureColor); cwTransparency = ccwTransparency; i--; }while(ccwTransparency > 0f && i > 0); } }