Compare commits
2 Commits
4ff099de99
...
940eb961cd
Author | SHA1 | Date | |
---|---|---|---|
|
940eb961cd | ||
|
8434f0f11e |
@ -126,7 +126,7 @@ namespace polygun::engine {
|
||||
return cuboids;
|
||||
}
|
||||
|
||||
static int faces_indiecies[] = {
|
||||
static unsigned int faces_indiecies[] = {
|
||||
0, 1, 3, 0, 3, 2, // bottom
|
||||
0, 2, 6, 0, 6, 4, // left
|
||||
0, 4, 5, 0, 5, 1, // back
|
||||
@ -135,63 +135,18 @@ namespace polygun::engine {
|
||||
2, 7, 6, 2, 3, 7, // front
|
||||
};
|
||||
|
||||
static int slice_axises_indices[] {
|
||||
static unsigned int slice_axises_indices[] {
|
||||
0, 3, 2, 5, 1, 4, // bottom/top face check
|
||||
1, 4, 2, 5, 0, 3, // left/right face check
|
||||
0, 3, 1, 4, 2, 5 // back/front face check
|
||||
};
|
||||
|
||||
verticies_indices greedy_meshing::generate_mesh(world::Chunk& chunk) {
|
||||
verticies_indices greedy_meshing::generate_mesh(cuboid_list cuboids) {
|
||||
std::vector<glm::vec3> vertices;
|
||||
std::vector<unsigned int> indices;
|
||||
|
||||
cuboid_list cuboids = merge(chunk);
|
||||
|
||||
for(const cuboid& c : cuboids) {
|
||||
std::vector<glm::vec3> cuboid_vertices = {
|
||||
{c.x1, c.y1, c.z1},
|
||||
{c.x2, c.y1, c.z1},
|
||||
{c.x1, c.y1, c.z2},
|
||||
{c.x2, c.y1, c.z2},
|
||||
{c.x1, c.y2, c.z1},
|
||||
{c.x2, c.y2, c.z1},
|
||||
{c.x1, c.y2, c.z2},
|
||||
{c.x2, c.y2, c.z2},
|
||||
};
|
||||
|
||||
std::vector<unsigned int> cuboid_vertices_indices;
|
||||
|
||||
for(const glm::vec3& vertex : cuboid_vertices) {
|
||||
auto found = std::find(vertices.begin(), vertices.end(), vertex);
|
||||
if (found != vertices.end()) {
|
||||
cuboid_vertices_indices.push_back(std::distance(vertices.begin(), found));
|
||||
} else {
|
||||
cuboid_vertices_indices.push_back(vertices.size());
|
||||
vertices.push_back(vertex);
|
||||
}
|
||||
}
|
||||
|
||||
for(size_t face_idx = 0; face_idx < 6; ++face_idx) {
|
||||
int face_sign, face_axis_idx;
|
||||
face_sign = face_idx / 3;
|
||||
face_axis_idx = face_idx % 3;
|
||||
|
||||
int slice_axis_C = c.x1 + (c.x2 - c.x1) * face_sign;
|
||||
bool stop_checking = false;
|
||||
|
||||
// Check the faces based on face_axis_idx here
|
||||
|
||||
if(!stop_checking) {
|
||||
indices.insert(indices.end(), {
|
||||
cuboid_vertices_indices[faces_indiecies[face_idx * 6 + 0]],
|
||||
cuboid_vertices_indices[faces_indiecies[face_idx * 6 + 1]],
|
||||
cuboid_vertices_indices[faces_indiecies[face_idx * 6 + 2]],
|
||||
cuboid_vertices_indices[faces_indiecies[face_idx * 6 + 3]],
|
||||
cuboid_vertices_indices[faces_indiecies[face_idx * 6 + 4]],
|
||||
cuboid_vertices_indices[faces_indiecies[face_idx * 6 + 5]],
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {vertices, indices};
|
||||
|
@ -46,11 +46,10 @@ namespace polygun::engine {
|
||||
greedy_meshing() = default;
|
||||
~greedy_meshing() = default;
|
||||
|
||||
verticies_indices generate_mesh(world::Chunk& chunk);
|
||||
|
||||
private:
|
||||
verticies_indices generate_mesh(cuboid_list cuboids);
|
||||
cuboid_list merge(world::Chunk& chunk);
|
||||
|
||||
private:
|
||||
const int voxel_count = 32;
|
||||
const int voxel_max_idx = voxel_count - 1;
|
||||
|
||||
|
@ -40,7 +40,7 @@ SOFTWARE.
|
||||
using namespace polygun::screens;
|
||||
|
||||
static int x_d, y_d, z_d;
|
||||
static unsigned id_d;
|
||||
static int id_d;
|
||||
|
||||
static const std::vector<float> vertices = {
|
||||
-0.1f , -0.1f, -0.1f,
|
||||
@ -268,6 +268,7 @@ void GameSessionScreen::render() {
|
||||
ImGui::Text("Player Pos: %.3f, %.3f, %.3f", m_camera.m_position.x, m_camera.m_position.y, m_camera.m_position.z);
|
||||
// Camera rot
|
||||
ImGui::Text("Player Rot: %.3f, %.3f", m_camera.m_yaw, m_camera.m_pitch);
|
||||
ImGui::InputInt("ID",&id_d);
|
||||
ImGui::InputInt("X", &x_d);
|
||||
ImGui::InputInt("Y", &y_d);
|
||||
ImGui::InputInt("Z", &z_d);
|
||||
|
Loading…
x
Reference in New Issue
Block a user