//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); }
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); }