public static void UpdateCornerRamps(VoxelChunk chunk) { Voxel v = chunk.MakeVoxel(0, 0, 0); Voxel vAbove = chunk.MakeVoxel(0, 0, 0); List <Voxel> diagNeighbors = chunk.AllocateVoxels(3); List <VoxelVertex> top = new List <VoxelVertex>() { VoxelVertex.FrontTopLeft, VoxelVertex.FrontTopRight, VoxelVertex.BackTopLeft, VoxelVertex.BackTopRight }; for (int x = 0; x < chunk.SizeX; x++) { for (int y = 0; y < chunk.SizeY; y++) { for (int z = 0; z < chunk.SizeZ; z++) { v.GridPosition = new Vector3(x, y, z); bool isTop = false; if (y < chunk.SizeY - 1) { vAbove.GridPosition = new Vector3(x, y + 1, z); isTop = vAbove.IsEmpty; } if (v.IsEmpty || !v.IsVisible || !isTop || !v.Type.CanRamp) { v.RampType = RampType.None; continue; } v.RampType = RampType.None; foreach (VoxelVertex bestKey in top) { List <Vector3> neighbors = VertexNeighbors2D[bestKey]; chunk.GetNeighborsSuccessors(neighbors, (int)v.GridPosition.X, (int)v.GridPosition.Y, (int)v.GridPosition.Z, diagNeighbors); bool emptyFound = diagNeighbors.Any(vox => vox.IsEmpty); if (!emptyFound) { continue; } switch (bestKey) { case VoxelVertex.FrontTopLeft: v.RampType |= RampType.TopBackLeft; break; case VoxelVertex.FrontTopRight: v.RampType |= RampType.TopBackRight; break; case VoxelVertex.BackTopLeft: v.RampType |= RampType.TopFrontLeft; break; case VoxelVertex.BackTopRight: v.RampType |= RampType.TopFrontRight; break; } } } } } }
public static void UpdateCornerRamps(VoxelChunk chunk) { Voxel v = chunk.MakeVoxel(0, 0, 0); Voxel vAbove = chunk.MakeVoxel(0, 0, 0); List<Voxel> diagNeighbors = chunk.AllocateVoxels(3); List<VoxelVertex> top = new List<VoxelVertex>() { VoxelVertex.FrontTopLeft, VoxelVertex.FrontTopRight, VoxelVertex.BackTopLeft, VoxelVertex.BackTopRight }; for(int x = 0; x < chunk.SizeX; x++) { for(int y = 0; y < chunk.SizeY; y++) { for(int z = 0; z < chunk.SizeZ; z++) { v.GridPosition = new Vector3(x, y, z); bool isTop = false; if(y < chunk.SizeY - 1) { vAbove.GridPosition = new Vector3(x, y + 1, z); isTop = vAbove.IsEmpty; } if(v.IsEmpty || !v.IsVisible || !isTop || !v.Type.CanRamp) { v.RampType = RampType.None; continue; } v.RampType = RampType.None; foreach (VoxelVertex bestKey in top) { List<Vector3> neighbors = VertexNeighbors2D[bestKey]; chunk.GetNeighborsSuccessors(neighbors, (int)v.GridPosition.X, (int)v.GridPosition.Y, (int)v.GridPosition.Z, diagNeighbors); bool emptyFound = diagNeighbors.Any(vox => vox.IsEmpty); if(!emptyFound) { continue; } switch(bestKey) { case VoxelVertex.FrontTopLeft: v.RampType |= RampType.TopBackLeft; break; case VoxelVertex.FrontTopRight: v.RampType |= RampType.TopBackRight; break; case VoxelVertex.BackTopLeft: v.RampType |= RampType.TopFrontLeft; break; case VoxelVertex.BackTopRight: v.RampType |= RampType.TopFrontRight; break; } } } } } }