mirror of
https://github.com/Relintai/voxelman.git
synced 2024-11-12 10:15:12 +01:00
Didi the same optimization to the transvoxel uv mesher.
This commit is contained in:
parent
f7842e1ab2
commit
9fe51572f4
@ -36,14 +36,28 @@ void VoxelMesherUVTransvoxel::set_texture_scale(const int value) {
|
||||
}
|
||||
|
||||
void VoxelMesherUVTransvoxel::get_voxel_type_array(int *arr, Ref<VoxelChunk> chunk, const int x, const int y, const int z, const int size) {
|
||||
arr[0] = chunk->get_voxel(x, y, z, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE);
|
||||
arr[1] = chunk->get_voxel(x, y + size, z, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE);
|
||||
arr[2] = chunk->get_voxel(x, y, z + size, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE);
|
||||
arr[3] = chunk->get_voxel(x, y + size, z + size, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE);
|
||||
arr[4] = chunk->get_voxel(x + size, y, z, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE);
|
||||
arr[5] = chunk->get_voxel(x + size, y + size, z, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE);
|
||||
arr[6] = chunk->get_voxel(x + size, y, z + size, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE);
|
||||
arr[7] = chunk->get_voxel(x + size, y + size, z + size, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE);
|
||||
uint8_t *channel_type = chunk->get_channel(VoxelChunkDefault::DEFAULT_CHANNEL_TYPE);
|
||||
|
||||
if (channel_type == NULL) {
|
||||
arr[0] = 0;
|
||||
arr[1] = 0;
|
||||
arr[2] = 0;
|
||||
arr[3] = 0;
|
||||
arr[4] = 0;
|
||||
arr[5] = 0;
|
||||
arr[6] = 0;
|
||||
arr[7] = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
arr[0] = channel_type[chunk->get_index(x, y, z)];
|
||||
arr[1] = channel_type[chunk->get_index(x, y + size, z)];
|
||||
arr[2] = channel_type[chunk->get_index(x, y, z + size)];
|
||||
arr[3] = channel_type[chunk->get_index(x, y + size, z + size)];
|
||||
arr[4] = channel_type[chunk->get_index(x + size, y, z)];
|
||||
arr[5] = channel_type[chunk->get_index(x + size, y + size, z)];
|
||||
arr[6] = channel_type[chunk->get_index(x + size, y, z + size)];
|
||||
arr[7] = channel_type[chunk->get_index(x + size, y + size, z + size)];
|
||||
}
|
||||
int VoxelMesherUVTransvoxel::get_case_code_from_arr(const int *data) {
|
||||
int case_code = 0;
|
||||
@ -75,74 +89,86 @@ int VoxelMesherUVTransvoxel::get_case_code_from_arr(const int *data) {
|
||||
return case_code;
|
||||
}
|
||||
int VoxelMesherUVTransvoxel::get_case_code(Ref<VoxelChunk> chunk, const int x, const int y, const int z, const int size) {
|
||||
uint8_t *channel_type = chunk->get_channel(VoxelChunkDefault::DEFAULT_CHANNEL_TYPE);
|
||||
|
||||
if (channel_type == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int case_code = 0;
|
||||
|
||||
if (chunk->get_voxel(x, y, z, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE) != 0)
|
||||
if (channel_type[chunk->get_index(x, y, z)] != 0)
|
||||
case_code = case_code | VOXEL_ENTRY_MASK_000;
|
||||
|
||||
if (chunk->get_voxel(x, y + size, z, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE) != 0)
|
||||
if (channel_type[chunk->get_index(x, y + size, z)] != 0)
|
||||
case_code = case_code | VOXEL_ENTRY_MASK_010;
|
||||
|
||||
if (chunk->get_voxel(x, y, z + size, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE) != 0)
|
||||
if (channel_type[chunk->get_index(x, y, z + size)] != 0)
|
||||
case_code = case_code | VOXEL_ENTRY_MASK_001;
|
||||
|
||||
if (chunk->get_voxel(x, y + size, z + size, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE) != 0)
|
||||
if (channel_type[chunk->get_index(x, y + size, z + size)] != 0)
|
||||
case_code = case_code | VOXEL_ENTRY_MASK_011;
|
||||
|
||||
if (chunk->get_voxel(x + size, y, z, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE) != 0)
|
||||
if (channel_type[chunk->get_index(x + size, y, z)] != 0)
|
||||
case_code = case_code | VOXEL_ENTRY_MASK_100;
|
||||
|
||||
if (chunk->get_voxel(x + size, y + size, z, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE) != 0)
|
||||
if (channel_type[chunk->get_index(x + size, y + size, z)] != 0)
|
||||
case_code = case_code | VOXEL_ENTRY_MASK_110;
|
||||
|
||||
if (chunk->get_voxel(x + size, y, z + size, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE) != 0)
|
||||
if (channel_type[chunk->get_index(x + size, y, z + size)] != 0)
|
||||
case_code = case_code | VOXEL_ENTRY_MASK_101;
|
||||
|
||||
if (chunk->get_voxel(x + size, y + size, z + size, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE) != 0)
|
||||
if (channel_type[chunk->get_index(x + size, y + size, z + size)] != 0)
|
||||
case_code = case_code | VOXEL_ENTRY_MASK_111;
|
||||
|
||||
return case_code;
|
||||
}
|
||||
|
||||
int VoxelMesherUVTransvoxel::get_voxel_type(Ref<VoxelChunk> chunk, const int x, const int y, const int z, const int size) {
|
||||
uint8_t *channel_type = chunk->get_channel(VoxelChunkDefault::DEFAULT_CHANNEL_TYPE);
|
||||
|
||||
if (channel_type == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int type = 0;
|
||||
|
||||
type = chunk->get_voxel(x, y + size, z, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE);
|
||||
type = channel_type[chunk->get_index(x, y + size, z)];
|
||||
|
||||
if (type != 0)
|
||||
return type;
|
||||
|
||||
type = chunk->get_voxel(x, y, z + size, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE);
|
||||
type = channel_type[chunk->get_index(x, y, z + size)];
|
||||
|
||||
if (type != 0)
|
||||
return type;
|
||||
|
||||
type = chunk->get_voxel(x, y + size, z + size, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE);
|
||||
type = channel_type[chunk->get_index(x, y + size, z + size)];
|
||||
|
||||
if (type != 0)
|
||||
return type;
|
||||
|
||||
type = chunk->get_voxel(x + size, y + size, z + size, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE);
|
||||
type = channel_type[chunk->get_index(x + size, y + size, z + size)];
|
||||
|
||||
if (type != 0)
|
||||
return type;
|
||||
|
||||
type = chunk->get_voxel(x, y, z, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE);
|
||||
type = channel_type[chunk->get_index(x, y, z)];
|
||||
|
||||
if (type != 0)
|
||||
return type;
|
||||
|
||||
type = chunk->get_voxel(x + size, y + size, z, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE);
|
||||
type = channel_type[chunk->get_index(x + size, y + size, z)];
|
||||
|
||||
if (type != 0)
|
||||
return type;
|
||||
|
||||
type = chunk->get_voxel(x + size, y, z, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE);
|
||||
type = channel_type[chunk->get_index(x + size, y, z)];
|
||||
|
||||
if (type != 0)
|
||||
return type;
|
||||
|
||||
type = chunk->get_voxel(x + size, y, z + size, VoxelChunkDefault::DEFAULT_CHANNEL_TYPE);
|
||||
type = channel_type[chunk->get_index(x + size, y, z + size)];
|
||||
|
||||
return type;
|
||||
}
|
||||
|
@ -467,6 +467,10 @@ void VoxelChunk::set_channel_compressed(int channel_index, const PoolByteArray &
|
||||
LZ4_decompress_safe(reinterpret_cast<char *>(data_arr), reinterpret_cast<char *>(ch), ds, size);
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ int VoxelChunk::get_index(const int x, const int y, const int z) const {
|
||||
return (y + _margin_start) + _data_size_y * ((x + _margin_start) + _data_size_x * (z + _margin_start));
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ int VoxelChunk::get_data_index(const int x, const int y, const int z) const {
|
||||
return y + _data_size_y * (x + _data_size_x * z);
|
||||
}
|
||||
@ -977,6 +981,7 @@ void VoxelChunk::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_channel_compressed", "channel_index"), &VoxelChunk::get_channel_compressed);
|
||||
ClassDB::bind_method(D_METHOD("set_channel_compressed", "channel_index", "array"), &VoxelChunk::set_channel_compressed);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_index", "x", "y", "z"), &VoxelChunk::get_index);
|
||||
ClassDB::bind_method(D_METHOD("get_data_index", "x", "y", "z"), &VoxelChunk::get_data_index);
|
||||
ClassDB::bind_method(D_METHOD("get_data_size"), &VoxelChunk::get_data_size);
|
||||
|
||||
|
@ -156,6 +156,7 @@ public:
|
||||
PoolByteArray get_channel_compressed(int channel_index) const;
|
||||
void set_channel_compressed(int channel_index, const PoolByteArray &data);
|
||||
|
||||
int get_index(int x, int y, int z) const;
|
||||
int get_data_index(int x, int y, int z) const;
|
||||
int get_data_size() const;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user