voxel_data.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #pragma once
  2. #include <vector>
  3. #include <unordered_map>
  4. #include "coral_mesh.h"
  5. enum class BlockType : uint8_t
  6. {
  7. AIR = 0,
  8. DIRT = 1,
  9. GRASS_BLOCK = 2,
  10. SAND = 4,
  11. WATER = 5,
  12. BEDROCK = 6,
  13. STONE = 7,
  14. COBBLESTONE = 8,
  15. SANDSTONE = 9,
  16. OAK_LOG = 12,
  17. OAK_LEAVES = 14
  18. };
  19. enum class FaceType : uint8_t
  20. {
  21. AIR,
  22. DIRT,
  23. GRASS_TOP,
  24. GRASS_SIDE,
  25. SAND,
  26. WATER,
  27. BEDROCK,
  28. STONE,
  29. COBBLESTONE,
  30. SANDSTONE_SIDE,
  31. SANDSTONE_BOTTOM,
  32. SANDSTONE_TOP,
  33. OAK_LOG_SIDE,
  34. OAK_LOG_TOP,
  35. OAK_LEAVES
  36. };
  37. enum class FaceOrientation : uint8_t
  38. {
  39. FRONT,
  40. BACK,
  41. LEFT,
  42. RIGHT,
  43. BOTTOM,
  44. TOP
  45. };
  46. struct VoxelFace
  47. {
  48. std::vector<coral_3d::Vertex> vertices;
  49. std::vector<uint32_t> indices;
  50. FaceType type{ FaceType::STONE };
  51. bool operator==(const VoxelFace& other) const
  52. {
  53. return vertices == other.vertices && indices == other.indices;
  54. }
  55. };
  56. struct Block
  57. {
  58. BlockType type{ BlockType::STONE };
  59. std::vector<VoxelFace> faces;
  60. bool is_solid;
  61. };
  62. class voxel_data final
  63. {
  64. public:
  65. static Block get_block(const BlockType& block_type);
  66. static bool is_block_solid(const BlockType& block_type);
  67. private:
  68. static std::vector<coral_3d::Vertex> get_vertices();
  69. static std::vector<uint32_t> get_indices();
  70. static std::vector<VoxelFace> get_faces();
  71. static std::unordered_map<BlockType, std::unordered_map<FaceOrientation, FaceType>> block_face_map_;
  72. static std::vector<VoxelFace> block_faces_;
  73. };