Fix channel depth not being applied to VoxelMap::get_buffer_copy()

This commit is contained in:
Marc Gilleron 2020-07-11 18:05:26 +01:00
parent bc7ec0c966
commit 071c5ee5c0
4 changed files with 8 additions and 5 deletions

View File

@ -102,8 +102,8 @@ VoxelStream::Stats VoxelStream::get_statistics() const {
}
void VoxelStream::_bind_methods() {
// TODO Make these proper virtual, it confuses C# bindings
// Note: C++ inheriting classes don't need to re-bind these, because they are bindings that call the actual virtual methods
ClassDB::bind_method(D_METHOD("emerge_block", "out_buffer", "origin_in_voxels", "lod"), &VoxelStream::_emerge_block);
ClassDB::bind_method(D_METHOD("immerge_block", "buffer", "origin_in_voxels", "lod"), &VoxelStream::_immerge_block);
ClassDB::bind_method(D_METHOD("get_used_channels_mask"), &VoxelStream::_get_used_channels_mask);

View File

@ -33,6 +33,7 @@ public:
// This function is recommended if you save to files, because you can batch their access.
virtual void immerge_blocks(Vector<VoxelBlockRequest> &p_blocks);
// Declares the format expected from this stream
virtual int get_used_channels_mask() const;
virtual bool is_thread_safe() const;

View File

@ -22,7 +22,6 @@ VoxelStreamBlockFiles::VoxelStreamBlockFiles() {
// TODO Have configurable block size
void VoxelStreamBlockFiles::emerge_block(Ref<VoxelBuffer> out_buffer, Vector3i origin_in_voxels, int lod) {
ERR_FAIL_COND(out_buffer.is_null());
if (_directory_path.empty()) {
@ -260,7 +259,6 @@ Vector3i VoxelStreamBlockFiles::get_block_position(const Vector3i &origin_in_vox
}
void VoxelStreamBlockFiles::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_directory", "directory"), &VoxelStreamBlockFiles::set_directory);
ClassDB::bind_method(D_METHOD("get_directory"), &VoxelStreamBlockFiles::get_directory);

View File

@ -189,11 +189,13 @@ void VoxelMap::get_buffer_copy(Vector3i min_pos, VoxelBuffer &dst_buffer, unsign
for (bpos.z = min_block_pos.z; bpos.z < max_block_pos.z; ++bpos.z) {
for (bpos.x = min_block_pos.x; bpos.x < max_block_pos.x; ++bpos.x) {
for (bpos.y = min_block_pos.y; bpos.y < max_block_pos.y; ++bpos.y) {
VoxelBlock *block = get_block(bpos);
if (block) {
if (block) {
VoxelBuffer &src_buffer = **block->voxels;
dst_buffer.set_channel_depth(channel, src_buffer.get_channel_depth(channel));
Vector3i offset = block_to_voxel(bpos);
// Note: copy_from takes care of clamping the area if it's on an edge
dst_buffer.copy_from(src_buffer,
@ -203,6 +205,8 @@ void VoxelMap::get_buffer_copy(Vector3i min_pos, VoxelBuffer &dst_buffer, unsign
channel);
} else {
// For now, inexistent blocks default to hardcoded defaults, corresponding to "empty space".
// If we want to change this, we may have to add an API for that it in `VoxelStream`.
Vector3i offset = block_to_voxel(bpos);
dst_buffer.fill_area(
_default_voxel[channel],