2020-01-26 22:34:26 +00:00
|
|
|
#ifndef VOXEL_GENERATOR_H
|
|
|
|
#define VOXEL_GENERATOR_H
|
|
|
|
|
2021-12-13 21:38:10 +00:00
|
|
|
#include <core/io/resource.h>
|
2022-02-12 23:37:02 +00:00
|
|
|
#include <core/math/vector3i.h>
|
2022-03-06 01:10:47 +00:00
|
|
|
#include <core/variant/typed_array.h>
|
2020-01-26 22:34:26 +00:00
|
|
|
|
2022-01-09 22:13:10 +00:00
|
|
|
namespace zylann::voxel {
|
|
|
|
|
2022-02-12 23:37:02 +00:00
|
|
|
class VoxelBufferInternal;
|
2022-02-03 00:02:10 +00:00
|
|
|
|
2022-02-15 21:49:20 +00:00
|
|
|
namespace gd {
|
|
|
|
class VoxelBuffer;
|
|
|
|
}
|
|
|
|
|
2022-02-26 22:51:29 +00:00
|
|
|
// Non-encoded, generic voxel value.
|
|
|
|
// (Voxels stored inside VoxelBuffers are encoded to take less space)
|
2021-10-03 01:48:07 +01:00
|
|
|
union VoxelSingleValue {
|
|
|
|
uint64_t i;
|
|
|
|
float f;
|
|
|
|
};
|
|
|
|
|
2020-01-26 22:34:26 +00:00
|
|
|
// Provides access to read-only generated voxels.
|
|
|
|
// Must be implemented in a multi-thread-safe way.
|
2021-01-17 17:18:05 +00:00
|
|
|
class VoxelGenerator : public Resource {
|
|
|
|
GDCLASS(VoxelGenerator, Resource)
|
2020-01-26 22:34:26 +00:00
|
|
|
public:
|
|
|
|
VoxelGenerator();
|
|
|
|
|
2021-09-16 20:33:45 +01:00
|
|
|
struct Result {
|
|
|
|
// Used for block optimization when LOD is used.
|
|
|
|
// If this is `false`, more precise data may be found if a lower LOD index is requested.
|
|
|
|
// If `true`, any block below this LOD are considered to not bring more details or will be the same.
|
|
|
|
// This allows to reduce the number of blocks to load when LOD is used.
|
|
|
|
bool max_lod_hint = false;
|
|
|
|
};
|
|
|
|
|
2022-02-12 23:37:02 +00:00
|
|
|
struct VoxelQueryData {
|
|
|
|
VoxelBufferInternal &voxel_buffer;
|
|
|
|
Vector3i origin_in_voxels;
|
2022-06-25 22:48:39 +01:00
|
|
|
uint32_t lod;
|
2022-02-12 23:37:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
virtual Result generate_block(VoxelQueryData &input);
|
2020-01-26 22:34:26 +00:00
|
|
|
|
2022-01-09 22:13:10 +00:00
|
|
|
virtual bool supports_single_generation() const {
|
|
|
|
return false;
|
|
|
|
}
|
2021-10-03 01:48:07 +01:00
|
|
|
|
|
|
|
// TODO Not sure if it's a good API regarding performance
|
|
|
|
virtual VoxelSingleValue generate_single(Vector3i pos, unsigned int channel);
|
|
|
|
|
|
|
|
// virtual void generate_series(
|
|
|
|
// Span<const Vector3> positions,
|
|
|
|
// Span<const uint8_t> channels,
|
|
|
|
// Span<Span<VoxelSingleValue>> out_values);
|
|
|
|
|
2021-01-17 17:18:05 +00:00
|
|
|
// Declares the channels this generator will use
|
|
|
|
virtual int get_used_channels_mask() const;
|
2020-01-26 22:34:26 +00:00
|
|
|
|
2022-03-06 01:10:47 +00:00
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
virtual void get_configuration_warnings(TypedArray<String> &out_warnings) const {}
|
|
|
|
#endif
|
|
|
|
|
2020-01-26 22:34:26 +00:00
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
|
2022-02-15 21:49:20 +00:00
|
|
|
void _b_generate_block(Ref<gd::VoxelBuffer> out_buffer, Vector3 origin_in_voxels, int lod);
|
2020-01-26 22:34:26 +00:00
|
|
|
};
|
|
|
|
|
2022-01-09 22:13:10 +00:00
|
|
|
} // namespace zylann::voxel
|
|
|
|
|
2020-01-26 22:34:26 +00:00
|
|
|
#endif // VOXEL_GENERATOR_H
|