Fix a few issues with the cubic mesher.

This commit is contained in:
Relintai 2020-10-12 22:59:27 +02:00
parent 5a9b99c199
commit a714e81db3
2 changed files with 20 additions and 5 deletions

View File

@ -467,6 +467,12 @@ void VoxelCubePoints::setup(Ref<VoxelChunk> 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<VoxelChunk> 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) {

View File

@ -33,7 +33,7 @@ void VoxelMesherCubic::_add_chunk(Ref<VoxelChunk> 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<VoxelChunk> 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<VoxelChunk> 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<VoxelSurface> surface = _library->get_voxel_surface(type);