Exemple #1
0
        //This method was customized by me to generate the Sparsegrid from XYZ city bounds
        //while also subtracting plots occupied by buildings
        public static Grid3d MakeWithCity(Bounds bounds, MeshCollider [] voids, float voxelSize)
        {
            var watch = Stopwatch.StartNew();
            var grid  = new Grid3d(voxelSize);
            int count = 0;

            var min = grid.IndexFromPoint(bounds.min);
            var max = grid.IndexFromPoint(bounds.max);

            for (int z = min.z; z <= max.z; z++)
            {
                for (int y = min.y; y <= max.y; y++)
                {
                    for (int x = min.x; x <= max.x; x++)
                    {
                        var index = new Vector3Int(x, y, z);
                        var point = new Vector3(index.x * voxelSize, index.y * voxelSize, index.z * voxelSize);

                        if (!grid.inVoids(point, voids))
                        {
                            grid.AddVoxel(index);
                            count++;
                        }
                    }
                }
            }

            Debug.Log($"Grid took: {watch.ElapsedMilliseconds} ms to create.\r\nGrid size: {count} voxels.");

            return(grid);
        }
Exemple #2
0
        public static Grid3d MakeGridWithBounds(IEnumerable <Bounds> bounds, float voxelSize)
        {
            var grid = new Grid3d(voxelSize);

            foreach (var bound in bounds)
            {
                var min = grid.IndexFromPoint(bound.min);
                var max = grid.IndexFromPoint(bound.max);

                for (int z = min.z; z <= max.z; z++)
                {
                    for (int y = min.y; y <= max.y; y++)
                    {
                        for (int x = min.x; x <= max.x; x++)
                        {
                            var index = new Vector3Int(x, y, z);
                            grid.AddVoxel(index);
                        }
                    }
                }
            }

            return(grid);
        }
Exemple #3
0
    public void PopulateWithHQ()
    {
        int count  = 0;
        var voxHQ  = gridHQ.Voxels.ToList();
        var genVox = grid.Voxels.ToList();


        for (int k = 0; k < genVox.Count; k++)
        {
            var center = genVox[k].Value.Center;
            for (int v = 0; v < voxHQ.Count; v++)
            {
                if (voxHQ[v].Value.Center == center)
                {
                    genVox[k].Value.Index = grid.IndexFromPoint(center);
                    genVox[k].Value.SwitchOn();
                    genVox[k].Value.HQ = true;
                    count++;
                }
            }
        }
    }