/** * Assemble a downwards facing face. **/ public static MeshData CreateFaceDown(Chunk chunk, int x, int y, int z, Block block, MeshData meshData, float size) { meshData.AddVertex(new Vector3(x - size, y - size, z - size)); meshData.AddVertex(new Vector3(x + size, y - size, z - size)); meshData.AddVertex(new Vector3(x + size, y - size, z + size)); meshData.AddVertex(new Vector3(x - size, y - size, z + size)); meshData.AddQuadTriangles(); meshData.uv.AddRange(MeshData.GetFaceUVs(block, Direction.DOWN)); return meshData; }
/** * Get UVs matching the face in the given direction on the given block. **/ public static Vector2[] GetFaceUVs(Block block, Direction direction) { float tileSize = 1f / 32f; float antiBleed = 0.0001f; Vector2[] UVs = new Vector2[4]; Tile tile = block.GetTile(direction); UVs[0] = new Vector2(tileSize * tile.x + tileSize - antiBleed, tileSize * tile.y + antiBleed); UVs[1] = new Vector2(tileSize * tile.x + tileSize - antiBleed, tileSize * tile.y + tileSize - antiBleed); UVs[2] = new Vector2(tileSize * tile.x + antiBleed, tileSize * tile.y + tileSize - antiBleed); UVs[3] = new Vector2(tileSize * tile.x + antiBleed, tileSize * tile.y + antiBleed); return UVs; }