small-projects/cpp-voxel-engine/GreedyMesher.cpp

31 lines
974 B
C++
Raw Normal View History

2025-04-06 02:03:23 +00:00
#include "GreedyMesher.h"
std::vector<Quad> GreedyMesher::mesh(const std::vector<std::vector<std::vector<int>>>& voxelData) {
std::vector<Quad> quads;
int sizeX = voxelData.size();
if (sizeX == 0) return quads;
int sizeY = voxelData[0].size();
int sizeZ = voxelData[0][0].size();
// For simplicity, we create one quad per non-empty voxel.
// A complete greedy mesher would merge adjacent quads.
for (int x = 0; x < sizeX; ++x) {
for (int y = 0; y < sizeY; ++y) {
for (int z = 0; z < sizeZ; ++z) {
if (voxelData[x][y][z] != 0) {
Quad q;
q.x = (float)x;
q.y = (float)y;
q.z = (float)z;
q.width = 1.0f;
q.height = 1.0f;
q.textureID = voxelData[x][y][z];
quads.push_back(q);
}
}
}
}
return quads;
}