VoxelBufferInternal doesnt depend on Image

master
Marc Gilleron 2022-04-16 16:07:45 +01:00
parent 3f9faad0cd
commit 8aec9cf777
6 changed files with 31 additions and 34 deletions

View File

@ -168,7 +168,29 @@ void VoxelBuffer::clear_voxel_metadata() {
}
Ref<Image> VoxelBuffer::debug_print_sdf_to_image_top_down() {
return _buffer->debug_print_sdf_to_image_top_down();
return debug_print_sdf_to_image_top_down(*_buffer);
}
Ref<Image> VoxelBuffer::debug_print_sdf_to_image_top_down(const VoxelBufferInternal &vb) {
Ref<Image> im;
im.instantiate();
const Vector3i size = vb.get_size();
im->create(size.x, size.z, false, Image::FORMAT_RGB8);
Vector3i pos;
for (pos.z = 0; pos.z < size.z; ++pos.z) {
for (pos.x = 0; pos.x < size.x; ++pos.x) {
for (pos.y = size.y - 1; pos.y >= 0; --pos.y) {
float v = vb.get_voxel_f(pos.x, pos.y, pos.z, VoxelBufferInternal::CHANNEL_SDF);
if (v < 0.0) {
break;
}
}
float h = pos.y;
float c = h / size.y;
im->set_pixel(pos.x, pos.z, Color(c, c, c));
}
}
return im;
}
void VoxelBuffer::_b_deprecated_optimize() {

View File

@ -2,6 +2,7 @@
#define VOXEL_BUFFER_GD_H
#include "voxel_buffer_internal.h"
#include <core/object/ref_counted.h>
#include <memory>
class Image;
@ -170,6 +171,7 @@ public:
// Debugging
Ref<Image> debug_print_sdf_to_image_top_down();
static Ref<Image> debug_print_sdf_to_image_top_down(const VoxelBufferInternal &vb);
private:
void _b_deprecated_optimize();

View File

@ -9,7 +9,6 @@
#include "../util/string_funcs.h"
#include "voxel_buffer_internal.h"
#include <core/io/image.h>
#include <core/io/marshalls.h>
#include <core/math/math_funcs.h>
@ -887,25 +886,4 @@ void VoxelBufferInternal::copy_voxel_metadata(const VoxelBufferInternal &src_buf
_block_metadata.user_data = src_buffer._block_metadata.user_data.duplicate();
}
Ref<Image> VoxelBufferInternal::debug_print_sdf_to_image_top_down() {
Ref<Image> im;
im.instantiate();
im->create(_size.x, _size.z, false, Image::FORMAT_RGB8);
Vector3i pos;
for (pos.z = 0; pos.z < _size.z; ++pos.z) {
for (pos.x = 0; pos.x < _size.x; ++pos.x) {
for (pos.y = _size.y - 1; pos.y >= 0; --pos.y) {
float v = get_voxel_f(pos.x, pos.y, pos.z, CHANNEL_SDF);
if (v < 0.0) {
break;
}
}
float h = pos.y;
float c = h / _size.y;
im->set_pixel(pos.x, pos.z, Color(c, c, c));
}
}
return im;
}
} // namespace zylann::voxel

View File

@ -7,12 +7,10 @@
#include "../util/math/box3i.h"
#include "funcs.h"
#include <core/object/ref_counted.h>
#include <core/os/rw_lock.h>
#include <core/variant/variant.h>
#include <limits>
class Image;
namespace zylann::voxel {
class VoxelTool;
@ -465,10 +463,6 @@ public:
return _rw_lock;
}
// Debugging
Ref<Image> debug_print_sdf_to_image_top_down();
private:
bool create_channel_noinit(int i, Vector3i size);
bool create_channel(int i, uint64_t defval);

View File

@ -5,9 +5,9 @@
#include "../../util/fixed_array.h"
#include "../../util/math/color8.h"
#include "../../util/math/vector3i.h"
#include <vector>
class FileAccess;
#include <core/io/file_access.h>
#include <vector>
namespace zylann::voxel {

View File

@ -4,6 +4,7 @@
#include "../../meshers/transvoxel/voxel_mesher_transvoxel.h"
#include "../../server/voxel_server_gd.h"
#include "../../server/voxel_server_updater.h"
#include "../../storage/voxel_buffer_gd.h"
#include "../../util/container_funcs.h"
#include "../../util/godot/funcs.h"
#include "../../util/log.h"
@ -2128,7 +2129,7 @@ Array VoxelLodTerrain::_b_debug_print_sdf_top_down(Vector3i center, Vector3i ext
buffer.set_voxel_f(v, rpos.x, rpos.y, rpos.z, VoxelBufferInternal::CHANNEL_SDF);
});
Ref<Image> image = buffer.debug_print_sdf_to_image_top_down();
Ref<Image> image = gd::VoxelBuffer::debug_print_sdf_to_image_top_down(buffer);
image_array.append(image);
}