public void TrianglateOasis(IHexCell cell, IHexMesh waterMesh, IHexMesh landMesh) { if (cell.Feature != CellFeature.Oasis) { return; } float waterDistance = RenderConfig.OasisWaterRadius; float landDistance = RenderConfig.OasisWaterRadius + RenderConfig.OasisLandWidth; float tDelta = 2 * Mathf.PI / RenderConfig.OasisBoundarySegments; Vector3 perturbedCenter = NoiseGenerator.Perturb(cell.AbsolutePosition); Vector3 waterTwo = NoiseGenerator.Perturb( cell.AbsolutePosition + new Vector3(waterDistance, 0f, 0f) ); Vector3 landTwo = NoiseGenerator.Perturb( cell.AbsolutePosition + new Vector3(landDistance, 0f, 0f) ); for (float t = 0f; t < 2 * Mathf.PI; t += tDelta) { Vector3 waterOne = waterTwo; Vector3 landOne = landTwo; waterTwo = NoiseGenerator.Perturb( cell.AbsolutePosition + new Vector3(waterDistance * Mathf.Cos(t), 0f, waterDistance * Mathf.Sin(t)) ); landTwo = NoiseGenerator.Perturb( cell.AbsolutePosition + new Vector3(landDistance * Mathf.Cos(t), 0f, landDistance * Mathf.Sin(t)) ); waterMesh.AddTriangle(perturbedCenter, waterTwo, waterOne); waterMesh.AddTriangleUV(Vector2.one, Vector2.one, Vector2.one); landMesh.AddQuad(waterTwo, waterOne, landTwo, landOne); } waterMesh.AddTriangle( perturbedCenter, NoiseGenerator.Perturb(cell.AbsolutePosition + new Vector3(waterDistance, 0f, 0f)), waterTwo ); landMesh.AddQuad( NoiseGenerator.Perturb(cell.AbsolutePosition + new Vector3(waterDistance, 0f, 0f)), waterTwo, NoiseGenerator.Perturb(cell.AbsolutePosition + new Vector3(landDistance, 0f, 0f)), landTwo ); waterMesh.AddTriangleUV(Vector2.one, Vector2.one, Vector2.one); }
private void TriangulateMarshCenter(IHexCell center, HexDirection direction, IHexMesh mesh) { mesh.AddTriangle( center.AbsolutePosition, center.AbsolutePosition + RenderConfig.GetFirstSolidCorner(direction), center.AbsolutePosition + RenderConfig.GetSecondSolidCorner(direction) ); mesh.AddTriangleUV(Vector2.one, Vector2.one, Vector2.one); }
private void TriangulateMarshCorner( IHexCell center, IHexCell left, IHexCell right, float centerV, float leftV, float rightV, HexDirection direction, IHexMesh mesh ) { Vector3 centerPoint = center.AbsolutePosition + RenderConfig.GetFirstSolidCorner(direction); Vector3 leftPoint = left.AbsolutePosition + RenderConfig.GetFirstSolidCorner(direction.Next2()); Vector3 rightPoint = right.AbsolutePosition + RenderConfig.GetFirstSolidCorner(direction.Previous2()); mesh.AddTriangle(centerPoint, leftPoint, rightPoint); mesh.AddTriangleUV(new Vector2(0f, centerV), new Vector2(0f, leftV), new Vector2(0f, rightV)); }
private void TriangulateCultureCorners_FlatEdge( IHexCell center, IHexCell left, IHexCell right, IHexCell nextRight, HexDirection direction, ICivilization centerOwner, ReadOnlyCollection <Vector2> centerRightContour, ReadOnlyCollection <Vector2> rightCenterContour, IHexMesh cultureMesh ) { if (left != null && CivTerritoryLogic.GetCivClaimingCell(left) != centerOwner) { Color cultureColor = centerOwner.Template.Color; var centerLeftContour = CellEdgeContourCanon.GetContourForCellEdge(center, direction.Previous()); var rightLeftContour = CellEdgeContourCanon.GetContourForCellEdge(right, direction.Previous2()); Vector2 centerLeftFirstInner = Vector2.Lerp(centerLeftContour.First(), center.AbsolutePositionXZ, RenderConfig.CultureWidthPercent); Vector2 centerLeftLastInner = Vector2.Lerp(centerLeftContour.Last(), center.AbsolutePositionXZ, RenderConfig.CultureWidthPercent); Vector2 rightLeftFirstInner = Vector2.Lerp(rightLeftContour.First(), right.AbsolutePositionXZ, RenderConfig.CultureWidthPercent); Vector2 rightleftLastInner = Vector2.Lerp(rightLeftContour.Last(), right.AbsolutePositionXZ, RenderConfig.CultureWidthPercent); Vector2 rayAlongCenterLeft = (centerLeftLastInner - centerLeftFirstInner).normalized; Vector2 rayAlongRightLeft = (rightLeftFirstInner - rightleftLastInner).normalized; Vector2 bezierControl; if (!Geometry2D.ClosestPointsOnTwoLines( centerLeftLastInner, rayAlongCenterLeft, rightLeftFirstInner, rayAlongRightLeft, out bezierControl, out bezierControl )) { Debug.LogError("TriangulateCultureCorners_FlatEdge failed to find a valid control point"); return; } Vector3 pivotXYZ = new Vector3(centerLeftContour.Last().x, 0f, centerLeftContour.Last().y); float paramDelta = 5f / RenderConfig.RiverQuadsPerCurve; for (float t = 0; t < 1f; t = Mathf.Clamp01(t + paramDelta)) { float nextT = Mathf.Clamp01(t + paramDelta); Vector2 bezierOne = BezierQuadratic.GetPoint(centerLeftLastInner, bezierControl, rightLeftFirstInner, nextT); Vector2 bezierTwo = BezierQuadratic.GetPoint(centerLeftLastInner, bezierControl, rightLeftFirstInner, t); cultureMesh.AddTriangle(pivotXYZ, new Vector3(bezierOne.x, 0f, bezierOne.y), new Vector3(bezierTwo.x, 0f, bezierTwo.y)); cultureMesh.AddTriangleUV(new Vector2(0f, 1f), Vector2.zero, Vector2.zero); cultureMesh.AddTriangleColor(cultureColor); } if (rightCenterContour.Count == 3) { Vector2 innerPoint = Vector2.Lerp(rightCenterContour.Last(), right.AbsolutePositionXZ, RenderConfig.CultureWidthPercent); Vector2 secondToLastContour = rightCenterContour[rightCenterContour.Count - 2]; Vector2 lastContour = rightCenterContour.Last(); cultureMesh.AddTriangle( new Vector3(innerPoint.x, 0f, innerPoint.y), new Vector3(secondToLastContour.x, 0f, secondToLastContour.y), new Vector3(lastContour.x, 0f, lastContour.y) ); cultureMesh.AddTriangleUV(new Vector2(0f, 0f), new Vector2(0f, 1f), new Vector2(0f, 1f)); cultureMesh.AddTriangleColor(cultureColor); } } }