public Edge(int x, int y, int z, Axis direction, Grid3d grid) { _grid = grid; Index = new Vector3Int(x, y, z); Direction = direction; Center = GetCenter(); }
public Army(BuildCity city) { _city = city; _voids = city.voidsOther.ToArray(); armyVacancyRate = new float(); hqBestVacant = new Vector3Int(); _bounds = city.cityBounds; _voxelSize = city.voxelSize; hq = new MeshCollider[1]; hq[0] = city.globalHQ; hqBounds = new Bounds[1]; hqBounds[0] = city.globalHQ.bounds; _A = Resources.Load("_A", typeof(GameObject)) as GameObject; _B = Resources.Load("_B", typeof(GameObject)) as GameObject; grid = SparseGrid.Grid3d.MakeWithCity(_bounds, _voids, _voxelSize); gridHQ = SparseGrid.Grid3d.MakeGridWithBounds(hqBounds, _voxelSize); InitGraph(); AttachGameObjects(); PopulateWithHQ(); }
//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 Voxel(Vector3Int index, Grid3d grid) { _grid = grid; Index = index; Center = new Vector3(index.x + 0.5f, index.y + 0.5f, index.z + 0.5f) * grid.VoxelSize; IsActive = true; }
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); }
public Corner(Vector3Int index, Grid3d grid) { _grid = grid; Index = index; Position = new Vector3(index.x, index.y, index.z) * grid.VoxelSize; }