private static void MeshNegZ(VoxelGridData voxels, Action <ushort, VoxelSide, VoxelSide, Quad, Vector2i> quadProcessor) { var xLength = voxels.XLength; var yLength = voxels.YLength; var zLength = voxels.ZLength; var plane = new VoxelPoint[xLength, yLength]; for (int z = 0; z < zLength; z++) { bool someFacesExist = false; for (int x = 0; x < xLength; x++) { for (int y = 0; y < yLength; y++) { var open = z == 0 || !voxels[x, y, z - 1].Exists; var voxel = voxels[x, y, z]; someFacesExist = (open && voxel.Exists) || someFacesExist; plane[x, y] = new VoxelPoint() { Voxel = voxels[x, y, z], Processed = !open }; } } if (someFacesExist) { var zPos = z; FindPlaneRects(plane, (typeNum, orientation, rect) => { var quad = new Quad( new Vector3(rect.Right, rect.Top, zPos) * voxels.VoxelSize, new Vector3(rect.Right, rect.Bottom, zPos) * voxels.VoxelSize, new Vector3(rect.Left, rect.Bottom, zPos) * voxels.VoxelSize, new Vector3(rect.Left, rect.Top, zPos) * voxels.VoxelSize, -Vector3.UnitZ); quadProcessor(typeNum, orientation, VoxelSide.NORTH, quad, new Vector2i(rect.Width, rect.Height)); }); } } }
private static void MeshPosY(VoxelGridData voxels, Action <ushort, VoxelSide, VoxelSide, Quad, Vector2i> quadProcessor) { var xLength = voxels.XLength; var yLength = voxels.YLength; var zLength = voxels.ZLength; var plane = new VoxelPoint[xLength, zLength]; for (int y = 0; y < yLength; y++) { bool someFacesExist = false; for (int x = 0; x < xLength; x++) { for (int z = 0; z < zLength; z++) { var open = y + 1 == yLength || !voxels[x, y + 1, z].Exists; var voxel = voxels[x, y, z]; someFacesExist = (open && voxel.Exists) || someFacesExist; plane[x, z] = new VoxelPoint() { Voxel = voxels[x, y, z], Processed = !open }; } } var yPos = (y + 1); if (someFacesExist) { FindPlaneRects(plane, (typeNum, orientation, rect) => { var quad = new Quad( new Vector3(rect.Left, yPos, rect.Top) * voxels.VoxelSize, new Vector3(rect.Right, yPos, rect.Top) * voxels.VoxelSize, new Vector3(rect.Right, yPos, rect.Bottom) * voxels.VoxelSize, new Vector3(rect.Left, yPos, rect.Bottom) * voxels.VoxelSize, Vector3.UnitY); quadProcessor(typeNum, orientation, VoxelSide.TOP, quad, new Vector2i(rect.Width, rect.Height)); }); } } }