2020-01-26 22:34:26 +00:00
|
|
|
#include "voxel_generator.h"
|
2021-02-21 23:58:00 +00:00
|
|
|
#include "../constants/voxel_string_names.h"
|
2022-02-15 21:49:20 +00:00
|
|
|
#include "../storage/voxel_buffer_gd.h"
|
2020-01-26 22:34:26 +00:00
|
|
|
|
2022-01-09 22:13:10 +00:00
|
|
|
namespace zylann::voxel {
|
2022-01-08 22:49:48 +00:00
|
|
|
|
2021-12-13 21:38:10 +00:00
|
|
|
VoxelGenerator::VoxelGenerator() {}
|
2020-01-26 22:34:26 +00:00
|
|
|
|
2022-02-12 23:37:02 +00:00
|
|
|
VoxelGenerator::Result VoxelGenerator::generate_block(VoxelQueryData &input) {
|
2021-09-16 20:33:45 +01:00
|
|
|
return Result();
|
2020-01-26 22:34:26 +00:00
|
|
|
}
|
|
|
|
|
2021-01-17 17:18:05 +00:00
|
|
|
int VoxelGenerator::get_used_channels_mask() const {
|
|
|
|
return 0;
|
2020-01-26 22:34:26 +00:00
|
|
|
}
|
|
|
|
|
2021-10-03 01:48:07 +01:00
|
|
|
VoxelSingleValue VoxelGenerator::generate_single(Vector3i pos, unsigned int channel) {
|
2022-07-31 16:14:36 +01:00
|
|
|
VoxelSingleValue v;
|
|
|
|
v.i = 0;
|
|
|
|
ZN_ASSERT_RETURN_V(channel >= 0 && channel < VoxelBufferInternal::MAX_CHANNELS, v);
|
2021-10-03 01:48:07 +01:00
|
|
|
// Default slow implementation
|
2022-03-27 21:36:30 +01:00
|
|
|
// TODO Optimize: a small part of the slowness is caused by the allocator.
|
|
|
|
// It is not a good use of `VoxelMemoryPool` for such a small size called so often.
|
|
|
|
// Instead it would be faster if it was a thread-local using the default allocator.
|
2021-10-03 01:48:07 +01:00
|
|
|
VoxelBufferInternal buffer;
|
|
|
|
buffer.create(1, 1, 1);
|
2022-02-12 23:37:02 +00:00
|
|
|
VoxelQueryData q{ buffer, pos, 0 };
|
|
|
|
generate_block(q);
|
2021-10-03 01:48:07 +01:00
|
|
|
if (channel == VoxelBufferInternal::CHANNEL_SDF) {
|
|
|
|
v.f = buffer.get_voxel_f(0, 0, 0, channel);
|
|
|
|
} else {
|
|
|
|
v.i = buffer.get_voxel(0, 0, 0, channel);
|
|
|
|
}
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2022-07-31 16:14:36 +01:00
|
|
|
void VoxelGenerator::generate_series(Span<const float> positions_x, Span<const float> positions_y,
|
|
|
|
Span<const float> positions_z, unsigned int channel, Span<float> out_values, Vector3f min_pos,
|
|
|
|
Vector3f max_pos) {
|
|
|
|
ZN_PRINT_ERROR("Not implemented");
|
|
|
|
}
|
|
|
|
|
2022-02-15 21:49:20 +00:00
|
|
|
void VoxelGenerator::_b_generate_block(Ref<gd::VoxelBuffer> out_buffer, Vector3 origin_in_voxels, int lod) {
|
2020-01-26 22:34:26 +00:00
|
|
|
ERR_FAIL_COND(lod < 0);
|
2022-02-13 17:37:20 +00:00
|
|
|
ERR_FAIL_COND(lod >= int(constants::MAX_LOD));
|
2021-09-26 04:14:50 +01:00
|
|
|
ERR_FAIL_COND(out_buffer.is_null());
|
2022-02-13 16:19:54 +00:00
|
|
|
VoxelQueryData q = { out_buffer->get_buffer(), origin_in_voxels, uint8_t(lod) };
|
2022-02-12 23:37:02 +00:00
|
|
|
generate_block(q);
|
2020-01-26 22:34:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void VoxelGenerator::_bind_methods() {
|
2021-12-13 21:38:10 +00:00
|
|
|
ClassDB::bind_method(
|
|
|
|
D_METHOD("generate_block", "out_buffer", "origin_in_voxels", "lod"), &VoxelGenerator::_b_generate_block);
|
2020-01-26 22:34:26 +00:00
|
|
|
}
|
2022-01-09 22:13:10 +00:00
|
|
|
|
|
|
|
} // namespace zylann::voxel
|