Exemplo n.º 1
0
        int count(Vector3 v, HashSet <Vector3> points)
        {
            int i = 0;

            foreach (Vector3 v2 in VoxelIterators.VonNeumanNeighbors())
            {
                var v3 = v + v2;
                if (points.Contains(v3))
                {
                    i++;
                }
            }
            return(i);
        }
Exemplo n.º 2
0
        IEnumerator <WaitForSeconds> test()
        {
            var r     = new System.Random();
            var set1  = new List <Vector3>();
            var black = new HashSet <Vector3>();
            var white = new List <Vector3>();
            Dictionary <Vector3, GameObject> map = new Dictionary <Vector3, GameObject>();

            for (int i = 0; i < size.x; i++)
            {
                for (int j = 0; j < size.y; j++)
                {
                    for (int k = 0; k < size.z; k++)
                    {
                        var v0 = new Vector3(i, j, k);
                        set1.Add(v0);
                        map[v0] = GameObject.CreatePrimitive(PrimitiveType.Cube);
                        map[v0].transform.position = v0;
                    }
                }
            }


            var set2    = new List <Vector3>(set1);
            var edgemap = EdgeMap.constructEdgemapFromPoints(set1);
            var v       = set1[r.Next(0, set1.Count)];

            set1.Remove(v);
            white.Add(v);

            while (set1.Count > 0)
            {
                var v1 = set1[r.Next(0, set1.Count)];
                set1.Remove(v1);
                bool dontSearch = false;
                foreach (Vector2 x in VoxelIterators.VonNeumanNeighbors())
                {
                    if (white.Contains(v1 + (Vector3)x))
                    {
                        dontSearch = true;
                    }
                }
                if (dontSearch)
                {
                    continue;
                }
                Vector3 v2 = white[r.Next(0, white.Count)];



                var path = Dijkstras.ASTAR(edgemap, v1, v2);

                for (int j = 0; j < path.Count - 1; j++)
                {
                    var x1 = path[j];
                    var x2 = path[j + 1];
                    var e0 = edgemap.edgeMap[x1].Intersect(edgemap.edgeMap[x2]).ToList()[0];

                    e0.weight = .1f;

                    var v3 = path[j];
                    set1.Remove(v3);
                    white.Add(v3);
                    black.Remove(v3);
                    map[v3].GetComponent <MeshRenderer>().material = whiteMat;

                    foreach (Vector3 v4 in VoxelIterators.VonNeumanNeighbors())
                    {
                        var v5 = v4 + v3;
                        set1.Remove(v5);
                        if (!white.Contains(v5) && set2.Contains(v5))
                        {
                            black.Add(v5);
                            set1.Remove(v5);
                            map[v5].GetComponent <MeshRenderer>().material = blackMat;
                        }
                    }
                    yield return(new WaitForSeconds(.05f));
                }
            }
        }