private List <FarmQuad> AssembleQuadsFromLines( List <IHexCell> farmBlob, List <FarmLine> toNortheastLines, List <FarmLine> toNorthwestLines ) { var retval = new List <FarmQuad>(); for (int northeastIndex = 0; northeastIndex < toNortheastLines.Count - 1; northeastIndex++) { for (int northwestIndex = 0; northwestIndex < toNorthwestLines.Count - 1; northwestIndex++) { Vector2 northVertex, eastVertex, southVertex, westVertex; Geometry2D.ClosestPointsOnTwoLines( toNortheastLines[northeastIndex + 1].Point, toNortheastLines[northeastIndex + 1].Direction, toNorthwestLines[northwestIndex + 1].Point, toNorthwestLines[northwestIndex + 1].Direction, out northVertex, out northVertex ); Geometry2D.ClosestPointsOnTwoLines( toNortheastLines[northeastIndex].Point, toNortheastLines[northeastIndex].Direction, toNorthwestLines[northwestIndex + 1].Point, toNorthwestLines[northwestIndex + 1].Direction, out eastVertex, out eastVertex ); Geometry2D.ClosestPointsOnTwoLines( toNortheastLines[northeastIndex].Point, toNortheastLines[northeastIndex].Direction, toNorthwestLines[northwestIndex].Point, toNorthwestLines[northwestIndex].Direction, out southVertex, out southVertex ); Geometry2D.ClosestPointsOnTwoLines( toNortheastLines[northeastIndex + 1].Point, toNortheastLines[northeastIndex + 1].Direction, toNorthwestLines[northwestIndex].Point, toNorthwestLines[northwestIndex].Direction, out westVertex, out westVertex ); if (ShouldAddQuad(farmBlob, northVertex, eastVertex, southVertex, westVertex)) { var newQuad = new FarmQuad(southVertex, eastVertex, westVertex, northVertex); var hexHash = NoiseGenerator.SampleHashGrid((southVertex + eastVertex + westVertex + northVertex) / 4f); GetUVPatch(hexHash, newQuad); retval.Add(newQuad); } } } return(retval); }
private void GetUVPatch( HexHash hash, FarmQuad quad ) { if (hash.A <= 0.5f) { quad.BottomLeftUV = new Vector2(0f, 0f); quad.BottomRightUV = new Vector2(1f, 0f); quad.TopLeftUV = new Vector2(0f, 1f); quad.TopRightUV = new Vector2(1f, 1f); } else { quad.BottomLeftUV = new Vector2(0f, 0f); quad.BottomRightUV = new Vector2(0f, 1f); quad.TopLeftUV = new Vector2(1f, 0f); quad.TopRightUV = new Vector2(1f, 1f); } quad.Color = RenderConfig.FarmColors[Mathf.FloorToInt(hash.C * RenderConfig.FarmColors.Count)]; }