You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

voxelinfo.cpp 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. #include "voxelinfo.h"
  2. #include "world.h"
  3. namespace vtk {
  4. void VoxelInfo::pushTexCoordFromWorldCoords(std::vector<float>& data, const glm::ivec3& pos, const Face3D& face, const Corner2D& corner) {
  5. pushTexCoordFromVoxelID(data, linkedWorld->getVoxelType(pos), face, corner);
  6. }
  7. void VoxelInfo::pushTexCoordFromVoxelID(std::vector<float>& data, const unsigned& id, const Face3D& face, const Corner2D& corner) {
  8. auto coord = getTexCoordFromID(id, face, corner);
  9. data.push_back(coord.first);
  10. data.push_back(coord.second);
  11. data.push_back(getTexIndexFromID(id, face));
  12. }
  13. float VoxelInfo::getTexIndexFromID(const unsigned& id, const Face3D& face) {
  14. if (voxelDataMap.find(id) == voxelDataMap.end()) return 0.0f;
  15. return voxelDataMap[id].faceTextureIndices[face];
  16. }
  17. std::pair<float, float> VoxelInfo::getTexCoordFromID(const unsigned& id, const Face3D& face, const Corner2D& corner) {
  18. if (voxelDataMap.find(id) == voxelDataMap.end()) return std::make_pair(0.0f, 0.0f);
  19. Orientation2D orient = voxelDataMap[id].faceOrientation[face];
  20. switch (orient) {
  21. case Orientation2D::UP:
  22. switch (corner) {
  23. case Corner2D::TOPLEFT:
  24. return std::make_pair(0.0f, 1.0f);
  25. break;
  26. case Corner2D::TOPRIGHT:
  27. return std::make_pair(1.0f, 1.0f);
  28. break;
  29. case Corner2D::BOTTOMLEFT:
  30. return std::make_pair(0.0f, 0.0f);
  31. break;
  32. case Corner2D::BOTTOMRIGHT:
  33. return std::make_pair(1.0f, 0.0f);
  34. break;
  35. }
  36. break;
  37. case Orientation2D::DOWN:
  38. switch (corner) {
  39. case Corner2D::TOPLEFT:
  40. return std::make_pair(0.0f, 0.0f);
  41. break;
  42. case Corner2D::TOPRIGHT:
  43. return std::make_pair(1.0f, 0.0f);
  44. break;
  45. case Corner2D::BOTTOMLEFT:
  46. return std::make_pair(0.0f, 1.0f);
  47. break;
  48. case Corner2D::BOTTOMRIGHT:
  49. return std::make_pair(1.0f, 1.0f);
  50. break;
  51. }
  52. break;
  53. case Orientation2D::LEFT:
  54. switch (corner) {
  55. case Corner2D::TOPLEFT:
  56. return std::make_pair(0.0f, 1.0f);
  57. break;
  58. case Corner2D::TOPRIGHT:
  59. return std::make_pair(1.0f, 1.0f);
  60. break;
  61. case Corner2D::BOTTOMLEFT:
  62. return std::make_pair(0.0f, 0.0f);
  63. break;
  64. case Corner2D::BOTTOMRIGHT:
  65. return std::make_pair(1.0f, 0.0f);
  66. break;
  67. }
  68. break;
  69. case Orientation2D::RIGHT:
  70. switch (corner) {
  71. case Corner2D::TOPLEFT:
  72. return std::make_pair(0.0f, 1.0f);
  73. break;
  74. case Corner2D::TOPRIGHT:
  75. return std::make_pair(1.0f, 1.0f);
  76. break;
  77. case Corner2D::BOTTOMLEFT:
  78. return std::make_pair(0.0f, 0.0f);
  79. break;
  80. case Corner2D::BOTTOMRIGHT:
  81. return std::make_pair(1.0f, 0.0f);
  82. break;
  83. }
  84. break;
  85. }
  86. return std::make_pair(0.0f, 0.0f);
  87. }
  88. unsigned VoxelInfo::getTextureIndex(const unsigned int &id, const FaceDirection &face) {
  89. return voxelDataMap[id].faceTextures[face];
  90. }
  91. void VoxelInfo::setTextureIndex(const unsigned int &id, const FaceDirection &face, const unsigned int &index) {
  92. voxelDataMap[id].faceTextures[face] = index;
  93. }
  94. void VoxelInfo::setAllTextureIndexes(const unsigned int &id, const unsigned int &index) {
  95. auto& textures = voxelDataMap[id].faceTextures;
  96. textures[FaceDirection::TOP] = index;
  97. textures[FaceDirection::BOTTOM] = index;
  98. textures[FaceDirection::NORTH] = index;
  99. textures[FaceDirection::SOUTH] = index;
  100. textures[FaceDirection::EAST] = index;
  101. textures[FaceDirection::WEST] = index;
  102. }
  103. void VoxelInfo::setTextureData(const unsigned& id, const Face3D& face, const Orientation2D& orientation, const float& textureIndex) {
  104. voxelDataMap[id].faceOrientation[face] = orientation;
  105. voxelDataMap[id].faceTextureIndices[face] = textureIndex;
  106. }
  107. void VoxelInfo::setTransparent(const unsigned& id, const bool& transparent) {
  108. voxelDataMap[id].transparent = transparent;
  109. }
  110. bool VoxelInfo::isTransparent(const unsigned& id) {
  111. return voxelDataMap[id].transparent;
  112. }
  113. void VoxelInfo::setEmission(const unsigned int &id, const unsigned short &emission) {
  114. voxelDataMap[id].emission = emission;
  115. }
  116. unsigned short VoxelInfo::getEmission(const unsigned int &id) {
  117. return voxelDataMap[id].emission;
  118. }
  119. }