greedy mesh texturing

This commit is contained in:
tylermurphy534 2022-09-30 11:28:38 -04:00
parent 34131a56b1
commit 795dce1272

View file

@ -132,21 +132,28 @@ void AddVertex(xe::Model::Data& data, glm::vec3 Pos, glm::vec3 Nor, FMask Mask,
void CreateQuad(xe::Model::Data& data, FMask Mask, glm::vec3 AxisMask, glm::vec3 V1, glm::vec3 V2, glm::vec3 V3, glm::vec3 V4, uint32_t width, uint32_t height) { void CreateQuad(xe::Model::Data& data, FMask Mask, glm::vec3 AxisMask, glm::vec3 V1, glm::vec3 V2, glm::vec3 V3, glm::vec3 V4, uint32_t width, uint32_t height) {
const auto Normal = glm::vec3(AxisMask) * glm::vec3(Mask.normal); const auto Normal = glm::vec3(AxisMask) * glm::vec3(Mask.normal);
std::vector<glm::vec3> verticies = {V4, V2, V3, V1}; std::vector<glm::vec3> verticies = {V1, V2, V3, V4};
float uv[4][2]; float uv[4][2];
uv[0][0] = height; uv[0][1] = width; if(AxisMask.x == 1) {
uv[0][0] = height; uv[0][1] = width;
uv[1][0] = height; uv[1][1] = 0; uv[1][0] = height; uv[1][1] = 0;
uv[2][0] = 0; uv[2][1] = width; uv[2][0] = 0; uv[2][1] = width;
uv[3][0] = 0; uv[3][1] = 0; uv[3][0] = 0; uv[3][1] = 0;
} else {
uv[0][0] = width; uv[0][1] = height;
uv[1][0] = 0; uv[1][1] = height;
uv[2][0] = width; uv[2][1] = 0;
uv[3][0] = 0; uv[3][1] = 0;
}
AddVertex(data, verticies[0], Normal, Mask, AxisMask, uv[1]); AddVertex(data, verticies[0], Normal, Mask, AxisMask, uv[0]);
AddVertex(data, verticies[2 + Mask.normal], Normal, Mask, AxisMask, uv[2]); AddVertex(data, verticies[2 - Mask.normal], Normal, Mask, AxisMask, uv[2 - Mask.normal]);
AddVertex(data, verticies[2 - Mask.normal], Normal, Mask, AxisMask, uv[0]); AddVertex(data, verticies[2 + Mask.normal], Normal, Mask, AxisMask, uv[2 + Mask.normal]);
AddVertex(data, verticies[3], Normal, Mask, AxisMask, uv[2]); AddVertex(data, verticies[3], Normal, Mask, AxisMask, uv[3]);
AddVertex(data, verticies[1 - Mask.normal], Normal, Mask, AxisMask, uv[1]); AddVertex(data, verticies[1 + Mask.normal], Normal, Mask, AxisMask, uv[1 + Mask.normal]);
AddVertex(data, verticies[1 + Mask.normal], Normal, Mask, AxisMask, uv[3]); AddVertex(data, verticies[1 - Mask.normal], Normal, Mask, AxisMask, uv[1 - Mask.normal]);
} }
@ -236,8 +243,8 @@ void Chunk::createMesh(Chunk* c) {
ChunkItr + DeltaAxis1, ChunkItr + DeltaAxis1,
ChunkItr + DeltaAxis2, ChunkItr + DeltaAxis2,
ChunkItr + DeltaAxis1 + DeltaAxis2, ChunkItr + DeltaAxis1 + DeltaAxis2,
height, width,
width height
); );
DeltaAxis1 = glm::vec3(0.f); DeltaAxis1 = glm::vec3(0.f);