small-projects/cpp-voxel-engine/GreedyMesher.h
2025-04-05 22:14:06 -05:00

28 lines
825 B
C++

#ifndef GREEDYMESHER_H
#define GREEDYMESHER_H
#include <vector>
// A single quad face in world space.
struct Quad {
// Position of the minimal corner of the quad
float x, y, z;
// Dimensions of the quad along its two axes
float du[3], dv[3];
// Offset of the second corner: (x+du[0]+dv[0], y+du[1]+dv[1], z+du[2]+dv[2])
// Normal direction (0..5) indicates which face this is:
// 0 = -X, 1 = +X, 2 = -Y, 3 = +Y, 4 = -Z, 5 = +Z
int normal;
// Texture ID for this face (block type)
int textureID;
};
// GreedyMesher namespace
namespace GreedyMesher {
// Given a 3D voxel grid [x][y][z] with integer block IDs (0 = empty),
// returns a list of merged Quad faces.
std::vector<Quad> mesh(const std::vector<std::vector<std::vector<int>>>& voxels);
}
#endif // GREEDYMESHER_H