void TriangulateBoundaryTriangle(Vector3 begin, Color beginColor, Vector3 left, Color leftColor, Vector3 boundary, Color boundaryColor, Vector3 types) { Vector3 v2 = HexMetric.Perturb(HexMetric.TerraceLerp(begin, left, 1)); Color c2 = HexMetric.TerraceLerp(beginColor, leftColor, 1); // first triangle terrain.AddTriangleUnperturbed(HexMetric.Perturb(begin), v2, boundary); terrain.AddTriangleColor(beginColor, c2, boundaryColor); terrain.AddTriangleTerrainTypes(types); //connect terrace with cliff for (int i = 2; i < HexMetric.terraceSteps; i++) { Vector3 v1 = v2; Color c1 = c2; v2 = HexMetric.Perturb(HexMetric.TerraceLerp(begin, left, i)); c2 = HexMetric.TerraceLerp(beginColor, leftColor, i); terrain.AddTriangleUnperturbed(v1, v2, boundary); terrain.AddTriangleColor(c1, c2, boundaryColor); terrain.AddTriangleTerrainTypes(types); } //last triangle terrain.AddTriangleUnperturbed(v2, HexMetric.Perturb(left), boundary); terrain.AddTriangleColor(c2, leftColor, boundaryColor); terrain.AddTriangleTerrainTypes(types); }
private void TriangulateCornerCliffTerraces(Vector3 begin, HexCell beginCell, Vector3 left, HexCell leftCell, Vector3 right, HexCell rightCell) { float b = 1f / (leftCell.Elevation - beginCell.Elevation); if (b < 0) { b = -b; } Vector3 boundary = Vector3.Lerp(HexMetric.Perturb(begin), HexMetric.Perturb(left), b); Color boundaryColor = Color.Lerp(color1, color2, b); Vector3 types; types.x = beginCell.TerrainTypeIndex; types.y = leftCell.TerrainTypeIndex; types.z = rightCell.TerrainTypeIndex; //lower connection TriangulateBoundaryTriangle(right, color3, begin, color1, boundary, boundaryColor, types); //upper terrace connection if (leftCell.GetEdgeType(rightCell) == HexEdgeType.Slope) { TriangulateBoundaryTriangle(left, color2, right, color3, boundary, boundaryColor, types); } else //upper cliff connection { terrain.AddTriangleUnperturbed(HexMetric.Perturb(left), HexMetric.Perturb(right), boundary); terrain.AddTriangleColor(color2, color3, boundaryColor); terrain.AddTriangleTerrainTypes(types); } }
public void AddTriangle(Vector3 v1, Vector3 v2, Vector3 v4) { int vertexIndex = vertices.Count; vertices.Add(HexMetric.Perturb(v1)); vertices.Add(HexMetric.Perturb(v2)); vertices.Add(HexMetric.Perturb(v4)); triangles.Add(vertexIndex); triangles.Add(vertexIndex + 1); triangles.Add(vertexIndex + 2); }
void TriangulateWaterfallInWater(Vector3 v1, Vector3 v2, Vector3 v3, Vector3 v4, float y1, float y2, float waterY) { v1.y = v2.y = y1; v3.y = v4.y = y2; v1 = HexMetric.Perturb(v1); v2 = HexMetric.Perturb(v2); v3 = HexMetric.Perturb(v3); v4 = HexMetric.Perturb(v4); float t = (waterY - y2) / (y1 - y2); v3 = Vector3.Lerp(v3, v1, t); v4 = Vector3.Lerp(v4, v2, t); rivers.AddQuadUnperturbed(v1, v2, v3, v4); rivers.AddQuadUV(0f, 1f, 0.8f, 1f); }
public void AddFeature(Vector3 position, HexCell cell) { HexHash hash = HexMetric.SampleHashGrid(position); Transform prefab = PickPrefab(cell.UrbanLevel, 0, 0); if (!prefab) { return; } Transform instance = Instantiate(prefab); position.y += instance.localScale.y * 0.5f; instance.localPosition = HexMetric.Perturb(position); instance.localRotation = Quaternion.Euler(0f, 360f, 0f); instance.SetParent(container, false); }