Ejemplo n.º 1
0
    public List <Vector3> Improve(IEnumerable <Vector3> src)
    {
        voronoi = new VoronoiMesh2();
        List <Vertex2> vertexs = new List <Vertex2>();

        foreach (var v in src)
        {
            vertexs.Add(new Vertex2(v.x, v.y));
        }
        voronoi.Generate(vertexs);
        Debug.Log("Voronoi:" + voronoi.Cells.Count + " Regions:" + voronoi.Regions.Count);
        List <Vector3> tmp = new List <Vector3>();

        foreach (var v in voronoi.Regions)
        {
            Vector2 vcenter = new Vector2();

            foreach (var e in v.Cells)
            {
                vcenter.x += e.CircumCenter.X;
                vcenter.y += e.CircumCenter.Y;
            }
            vcenter = vcenter / v.Cells.Count;
            if (size.Contains(vcenter))
            {
                tmp.Add(vcenter);
            }
        }
        return(tmp);
    }
Ejemplo n.º 2
0
    void GenerateVoronoi()
    {
        float start = Time.realtimeSinceStartup;

        voronoi = new VoronoiMesh2();
        List <Vertex2> vertices = new List <Vertex2>();

        foreach (var neighbour in neighbours)
        {
            if (neighbour != null && neighbour.frontier != null)
            {
                foreach (var point in neighbour.points)
                {
                    if (bounds.Contains(point))
                    {
                        points.Add(point);
                    }
                }
            }
        }
        foreach (var point in points)
        {
            vertices.Add(new Vertex2(point.x, point.z));
        }

        voronoi.Generate(vertices);
        float end = Time.realtimeSinceStartup;

        Debug.Log("> Voronoi time:" + (end - start) + "ms");
    }
Ejemplo n.º 3
0
        private void Start()
        {
            lineMaterial = new Material(Shader.Find("Hidden/Internal-Colored"));

            List <Vertex2> vertices = new List <Vertex2>();

            Random.InitState(seed);
            for (int i = 0; i < NumberOfVertices; i++)
            {
                float x = size * Random.Range(-1.0f, 1.0f);
                float y = size * Random.Range(-1.0f, 1.0f);

                vertices.Add(new Vertex2(x, y));
            }

            voronoi = new VoronoiMesh2();
            voronoi.Generate(vertices);
        }