| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- #pragma once
- #include <vector>
- #include <unordered_map>
- #include "coral_mesh.h"
- enum class BlockType : uint8_t
- {
- AIR = 0,
- DIRT = 1,
- GRASS_BLOCK = 2,
- SAND = 4,
- WATER = 5,
- BEDROCK = 6,
- STONE = 7,
- COBBLESTONE = 8,
- SANDSTONE = 9,
- OAK_LOG = 12,
- OAK_LEAVES = 14
- };
- enum class FaceType : uint8_t
- {
- AIR,
- DIRT,
- GRASS_TOP,
- GRASS_SIDE,
- SAND,
- WATER,
- BEDROCK,
- STONE,
- COBBLESTONE,
- SANDSTONE_SIDE,
- SANDSTONE_BOTTOM,
- SANDSTONE_TOP,
- OAK_LOG_SIDE,
- OAK_LOG_TOP,
- OAK_LEAVES
- };
- enum class FaceOrientation : uint8_t
- {
- FRONT,
- BACK,
- LEFT,
- RIGHT,
- BOTTOM,
- TOP
- };
- struct VoxelFace
- {
- std::vector<coral_3d::Vertex> vertices;
- std::vector<uint32_t> indices;
- FaceType type{ FaceType::STONE };
- bool operator==(const VoxelFace& other) const
- {
- return vertices == other.vertices && indices == other.indices;
- }
- };
- struct Block
- {
- BlockType type{ BlockType::STONE };
- std::vector<VoxelFace> faces;
- bool is_solid;
- };
- class voxel_data final
- {
- public:
- static Block get_block(const BlockType& block_type);
- static bool is_block_solid(const BlockType& block_type);
- private:
- static std::vector<coral_3d::Vertex> get_vertices();
- static std::vector<uint32_t> get_indices();
- static std::vector<VoxelFace> get_faces();
- static std::unordered_map<BlockType, std::unordered_map<FaceOrientation, FaceType>> block_face_map_;
- static std::vector<VoxelFace> block_faces_;
- };
|