示例#1
0
    // Triangle creation

    public void AddTriangle(Vector3 v1, Vector3 v2, Vector3 v3)
    {
        int vertexIndex = _vertices.Count;

        _vertices.Add(VoronoiMetrics.Perturb(v1));
        _vertices.Add(VoronoiMetrics.Perturb(v2));
        _vertices.Add(VoronoiMetrics.Perturb(v3));

        _triangles.Add(vertexIndex);
        _triangles.Add(vertexIndex + 1);
        _triangles.Add(vertexIndex + 2);
    }
示例#2
0
    private void TriangulateCornerCliffTerraces(
        Vector3 begin, VoronoiCell beginCell,
        Vector3 left, VoronoiCell leftCell,
        Vector3 right, VoronoiCell rightCell)
    {
        float b = 1f / (leftCell.Elevation - beginCell.Elevation);

        b = b < 0 ? -b : b;
        Vector3 boundary      = Vector3.Lerp(VoronoiMetrics.Perturb(begin), VoronoiMetrics.Perturb(left), b);
        Color   boundaryColor = Color.Lerp(beginCell.Color, leftCell.Color, b);

        TriangulateBoundaryTriangle(right, rightCell, begin, beginCell, boundary, boundaryColor);

        if (leftCell.GetEdgeType(rightCell) == VoronoiEdgeType.Slope)
        {
            TriangulateBoundaryTriangle(left, leftCell, right, rightCell, boundary, boundaryColor);
        }
        else
        {
            Terrain.AddTriangleUnperturbed(VoronoiMetrics.Perturb(left), VoronoiMetrics.Perturb(right), boundary);
            Terrain.AddTriangleColor(leftCell.Color, rightCell.Color, boundaryColor);
        }
    }
示例#3
0
    private void TriangulateBoundaryTriangle(
        Vector3 begin, VoronoiCell beginCell,
        Vector3 left, VoronoiCell leftCell,
        Vector3 boundary, Color boundaryColor)
    {
        Vector3 v2 = VoronoiMetrics.Perturb(VoronoiMetrics.TerraceLerp(begin, left, 1));
        Color   c2 = VoronoiMetrics.TerraceLerp(beginCell.Color, leftCell.Color, 1);

        Terrain.AddTriangleUnperturbed(VoronoiMetrics.Perturb(begin), v2, boundary);
        Terrain.AddTriangleColor(beginCell.Color, c2, boundaryColor);

        for (int i = 2; i < VoronoiMetrics.TerraceSteps; ++i)
        {
            Vector3 v1 = v2;
            Color   c1 = c2;
            v2 = VoronoiMetrics.Perturb(VoronoiMetrics.TerraceLerp(begin, left, i));
            c2 = VoronoiMetrics.TerraceLerp(beginCell.Color, leftCell.Color, i);
            Terrain.AddTriangleUnperturbed(v1, v2, boundary);
            Terrain.AddTriangleColor(c1, c2, boundaryColor);
        }

        Terrain.AddTriangleUnperturbed(v2, VoronoiMetrics.Perturb(left), boundary);
        Terrain.AddTriangleColor(c2, leftCell.Color, boundaryColor);
    }