void TriangulateBoundaryTriangle(Vector3 begin, Color beginColor, Vector3 left, Color leftColor, Vector3 boundary, Color boundaryColor, Vector3 types) { Vector3 v2 = HexMetrics_Script.Perturb(HexMetrics_Script.TerraceLerp(begin, left, 1)); Color c2 = HexMetrics_Script.TerraceLerp(beginColor, leftColor, 1); terrain.AddTriangleUnperturbed(HexMetrics_Script.Perturb(begin), v2, boundary); //Search for Rand Error terrain.AddTriangleColor(beginColor, c2, boundaryColor); terrain.AddTriangleTerrainTypes(types); for (int i = 2; i < HexMetrics_Script.terraceSteps; i++) { Vector3 v1 = v2; Color c1 = c2; v2 = HexMetrics_Script.Perturb(HexMetrics_Script.TerraceLerp(begin, left, i)); c2 = HexMetrics_Script.TerraceLerp(beginColor, leftColor, i); terrain.AddTriangleUnperturbed(v1, v2, boundary); terrain.AddTriangleColor(c1, c2, boundaryColor); terrain.AddTriangleTerrainTypes(types); } terrain.AddTriangleUnperturbed(v2, HexMetrics_Script.Perturb(left), boundary); //Search for Rand Error terrain.AddTriangleColor(c2, leftColor, boundaryColor); terrain.AddTriangleTerrainTypes(types); }
void AddWallWedge(Vector3 near, Vector3 far, Vector3 point) { near = HexMetrics_Script.Perturb(near); far = HexMetrics_Script.Perturb(far); point = HexMetrics_Script.Perturb(point); Vector3 center = HexMetrics_Script.WallLerp(near, far); Vector3 thickness = HexMetrics_Script.WallThicknessOffset(near, far); Vector3 v1, v2, v3, v4; Vector3 pointTop = point; point.y = center.y; v1 = center - thickness; v2 = center + thickness; v3 = center - thickness; v4 = center + thickness; v3.y = center.y + HexMetrics_Script.wallHeight; v4.y = center.y + HexMetrics_Script.wallHeight; pointTop.y = center.y + HexMetrics_Script.wallHeight; walls.AddQuadUnperturbed(v1, point, v3, pointTop); walls.AddQuadUnperturbed(point, v2, pointTop, v4); walls.AddTriangleUnperturbed(pointTop, v3, v4); }
void TriangulateCornerCliffTerraces(Vector3 begin, HexCell_Script beginCell, Vector3 left, HexCell_Script leftCell, Vector3 right, HexCell_Script rightCell) { float b = 1f / (leftCell.Elevation - beginCell.Elevation); if (b < 0) { b = -b; } Vector3 boundary = Vector3.Lerp(HexMetrics_Script.Perturb(begin), HexMetrics_Script.Perturb(left), b); Color boundaryColor = Color.Lerp(color1, color2, b); Vector3 types; types.x = beginCell.TerrainTypeIndex; types.y = beginCell.TerrainTypeIndex; types.z = beginCell.TerrainTypeIndex; TriangulateBoundaryTriangle(right, color3, begin, color1, boundary, boundaryColor, types); if (leftCell.GetEdgeType(rightCell) == HexEdgeType.Slope) { TriangulateBoundaryTriangle(left, color2, right, color3, boundary, boundaryColor, types); } else { terrain.AddTriangleUnperturbed(HexMetrics_Script.Perturb(left), HexMetrics_Script.Perturb(right), boundary); //Search for Rand Error terrain.AddTriangleColor(color2, color3, boundaryColor); terrain.AddTriangleTerrainTypes(types); } }
public void AddSpecialFeature(HexCell_Script cell, Vector3 position) { Transform instance = Instantiate(specials[cell.SpecialIndex - 1]); instance.localPosition = HexMetrics_Script.Perturb(position); HexHash hash = HexMetrics_Script.SampleHashGrid(position); instance.localRotation = Quaternion.Euler(0f, 360f * hash.e, 0f); instance.SetParent(container, false); }
public void AddTriangle(Vector3 v1, Vector3 v2, Vector3 v3) { int vertexIndex = vertices.Count; vertices.Add(HexMetrics_Script.Perturb(v1)); vertices.Add(HexMetrics_Script.Perturb(v2)); vertices.Add(HexMetrics_Script.Perturb(v3)); triangles.Add(vertexIndex); triangles.Add(vertexIndex + 1); triangles.Add(vertexIndex + 2); }
public void AddFeature(HexCell_Script cell, Vector3 position) { if (cell.IsSpecial) { return; } HexHash hash = HexMetrics_Script.SampleHashGrid(position); //if (hash.a >= cell.UrbanLevel*0.25f) // return; //Transform instance = Instantiate(urbanPrefabs[cell.UrbanLevel-1]); Transform prefab = PickPrefab(urbanPrefabs, cell.UrbanLevel, hash.a, hash.d); Transform otherprefab = PickPrefab(farmPrefabs, cell.FarmLevel, hash.b, hash.d); float usedHash = hash.a; if (prefab) { if (otherprefab && hash.b < hash.a) { prefab = otherprefab; usedHash = hash.b; } } else if (otherprefab) { prefab = otherprefab; usedHash = hash.b; } otherprefab = PickPrefab(plantPrefabs, cell.PlantLevel, hash.c, hash.d); if (prefab) { if (otherprefab && hash.c < usedHash) { prefab = otherprefab; } } else if (otherprefab) { prefab = otherprefab; } else { return; } Transform instance = Instantiate(prefab); position.y += instance.localScale.y * 0.5f; instance.localPosition = HexMetrics_Script.Perturb(position); instance.localRotation = Quaternion.Euler(0f, 360f * hash.e, 0f); instance.SetParent(container, false); }
void AddWallSegment(Vector3 nearLeft, Vector3 farLeft, Vector3 nearRight, Vector3 farRight, bool addTower = false) { nearLeft = HexMetrics_Script.Perturb(nearLeft); farLeft = HexMetrics_Script.Perturb(farLeft); nearRight = HexMetrics_Script.Perturb(nearRight); farRight = HexMetrics_Script.Perturb(farRight); Vector3 left = HexMetrics_Script.WallLerp(nearLeft, farLeft); Vector3 right = HexMetrics_Script.WallLerp(nearRight, farRight); Vector3 leftThicknessOffset = HexMetrics_Script.WallThicknessOffset(nearLeft, farLeft); Vector3 rightThicknessOffset = HexMetrics_Script.WallThicknessOffset(nearRight, farRight); float leftTop = left.y + HexMetrics_Script.wallHeight; float rightTop = right.y + HexMetrics_Script.wallHeight; Vector3 v1, v2, v3, v4; v1 = left - leftThicknessOffset; v2 = right - rightThicknessOffset; v3 = left - leftThicknessOffset; v4 = right - rightThicknessOffset; v3.y = leftTop; v4.y = rightTop; walls.AddQuadUnperturbed(v1, v2, v3, v4); Vector3 t1 = v3; Vector3 t2 = v4; v1 = left + leftThicknessOffset; v2 = right + rightThicknessOffset; v3 = left + leftThicknessOffset; v4 = right + rightThicknessOffset; v3.y = leftTop; v4.y = rightTop; walls.AddQuadUnperturbed(v2, v1, v4, v3); walls.AddQuadUnperturbed(t1, t2, v3, v4); if (addTower) { Transform towerInstance = Instantiate(wallTower); towerInstance.transform.localPosition = (left + right) * 0.5f; Vector3 rightDirection = right - left; rightDirection.y = 0f; towerInstance.transform.right = rightDirection; towerInstance.SetParent(container, false); } }
public void AddBridge(Vector3 roadCenter1, Vector3 roadCenter2) { roadCenter1 = HexMetrics_Script.Perturb(roadCenter1); roadCenter2 = HexMetrics_Script.Perturb(roadCenter2); Transform instance = Instantiate(bridge); instance.localPosition = (roadCenter1 + roadCenter2) * 0.5f; instance.forward = roadCenter2 - roadCenter1; float length = Vector3.Distance(roadCenter1, roadCenter2); instance.localScale = new Vector3(1, 1, length * (1f / HexMetrics_Script.bridgeDesignLength)); instance.SetParent(container, false); }
void AddWallCap(Vector3 near, Vector3 far) { near = HexMetrics_Script.Perturb(near); far = HexMetrics_Script.Perturb(far); Vector3 center = HexMetrics_Script.WallLerp(near, far); Vector3 thickness = HexMetrics_Script.WallThicknessOffset(near, far); Vector3 v1, v2, v3, v4; v1 = center - thickness; v2 = center + thickness; v3 = center - thickness; v4 = center + thickness; v3.y = center.y + HexMetrics_Script.wallHeight; v4.y = center.y + HexMetrics_Script.wallHeight; walls.AddQuadUnperturbed(v1, v2, v3, v4); }
void TriangulateWaterfallInWater(Vector3 v1, Vector3 v2, Vector3 v3, Vector3 v4, float y1, float y2, float waterY) { v1.y = y1; v2.y = y1; v3.y = y2; v4.y = y2; v1 = HexMetrics_Script.Perturb(v1); v2 = HexMetrics_Script.Perturb(v2); v3 = HexMetrics_Script.Perturb(v3); v4 = HexMetrics_Script.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); }