From a714e81db38457c80d37fe9d77956684d6c932d8 Mon Sep 17 00:00:00 2001 From: Relintai Date: Mon, 12 Oct 2020 22:59:27 +0200 Subject: [PATCH] Fix a few issues with the cubic mesher. --- meshers/cubic/voxel_cube_points.cpp | 15 +++++++++++++++ meshers/cubic/voxel_mesher_cubic.cpp | 10 +++++----- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/meshers/cubic/voxel_cube_points.cpp b/meshers/cubic/voxel_cube_points.cpp index d587c24..2a5f96b 100644 --- a/meshers/cubic/voxel_cube_points.cpp +++ b/meshers/cubic/voxel_cube_points.cpp @@ -467,6 +467,12 @@ void VoxelCubePoints::setup(Ref chunk, int x, int y, int z, int size if (!has_points()) return; + //for (int i = 0; i < 8; ++i) { + // if (_point_types[i] == 0) { + // _point_types[i] = 1; + // } + //} + _point_fills[P000] = chunk->get_voxel(x, y, z, _channel_index_isolevel); _point_fills[P100] = chunk->get_voxel(x + size, y, z, _channel_index_isolevel); _point_fills[P010] = chunk->get_voxel(x, y + size, z, _channel_index_isolevel); @@ -476,6 +482,12 @@ void VoxelCubePoints::setup(Ref chunk, int x, int y, int z, int size _point_fills[P101] = chunk->get_voxel(x + size, y, z + size, _channel_index_isolevel); _point_fills[P111] = chunk->get_voxel(x + size, y + size, z + size, _channel_index_isolevel); + //for (int i = 0; i < 8; ++i) { + // if (_point_fills[i] == 0) { + // _point_fills[i] = 1; + // } + //} + _point_aos[P000] = chunk->get_voxel(x, y, z, VoxelChunkDefault::DEFAULT_CHANNEL_AO); _point_aos[P100] = chunk->get_voxel(x + size, y, z, VoxelChunkDefault::DEFAULT_CHANNEL_AO); _point_aos[P010] = chunk->get_voxel(x, y + size, z, VoxelChunkDefault::DEFAULT_CHANNEL_AO); @@ -767,6 +779,9 @@ uint8_t VoxelCubePoints::get_face_type(int face) { bool VoxelCubePoints::has_points() { return (_point_types[P000] != 0 && _point_types[P100] != 0 && _point_types[P010] != 0 && _point_types[P001] != 0 && _point_types[P110] != 0 && _point_types[P011] != 0 && _point_types[P101] != 0 && _point_types[P111] != 0); + + //return !(_point_types[P000] == 0 && _point_types[P100] == 0 && _point_types[P010] == 0 && _point_types[P001] == 0 && + // _point_types[P110] == 0 && _point_types[P011] == 0 && _point_types[P101] == 0 && _point_types[P111] == 0); } int VoxelCubePoints::get_opposite_face(int face) { diff --git a/meshers/cubic/voxel_mesher_cubic.cpp b/meshers/cubic/voxel_mesher_cubic.cpp index e01e43f..19e6d42 100644 --- a/meshers/cubic/voxel_mesher_cubic.cpp +++ b/meshers/cubic/voxel_mesher_cubic.cpp @@ -33,7 +33,7 @@ void VoxelMesherCubic::_add_chunk(Ref p_chunk) { ERR_FAIL_COND(!chunk.is_valid()); - if (!chunk->get_channel(_channel_index_type)) { + if (!chunk->get_channel(_channel_index_type) || !chunk->get_channel(_channel_index_isolevel)) { return; } @@ -41,9 +41,9 @@ void VoxelMesherCubic::_add_chunk(Ref p_chunk) { // chunk->generate_ao(); //} - int x_size = chunk->get_size_x(); - int y_size = chunk->get_size_y(); - int z_size = chunk->get_size_z(); + int x_size = chunk->get_size_x() - 1; + int y_size = chunk->get_size_y() - 1; + int z_size = chunk->get_size_z() - 1; float voxel_size = 1; float voxel_scale = get_voxel_scale(); @@ -68,7 +68,7 @@ void VoxelMesherCubic::_add_chunk(Ref p_chunk) { if (!cube_points->is_face_visible(face)) continue; - uint8_t type = cube_points->get_face_type(face); + uint8_t type = cube_points->get_face_type(face) - 1; Ref surface = _library->get_voxel_surface(type);