2020-01-26 14:34:26 -08:00
|
|
|
#ifndef VOXEL_GENERATOR_H
|
|
|
|
#define VOXEL_GENERATOR_H
|
|
|
|
|
2021-01-17 09:18:05 -08:00
|
|
|
#include "../streams/voxel_block_request.h"
|
2021-12-13 13:38:10 -08:00
|
|
|
#include <core/io/resource.h>
|
2020-01-26 14:34:26 -08:00
|
|
|
|
2021-10-02 17:48:07 -07:00
|
|
|
union VoxelSingleValue {
|
|
|
|
uint64_t i;
|
|
|
|
float f;
|
|
|
|
};
|
|
|
|
|
2020-01-26 14:34:26 -08:00
|
|
|
// Provides access to read-only generated voxels.
|
|
|
|
// Must be implemented in a multi-thread-safe way.
|
2021-01-17 09:18:05 -08:00
|
|
|
class VoxelGenerator : public Resource {
|
|
|
|
GDCLASS(VoxelGenerator, Resource)
|
2020-01-26 14:34:26 -08:00
|
|
|
public:
|
|
|
|
VoxelGenerator();
|
|
|
|
|
2021-09-16 12:33:45 -07: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;
|
|
|
|
};
|
|
|
|
|
|
|
|
virtual Result generate_block(VoxelBlockRequest &input);
|
2020-01-26 14:34:26 -08:00
|
|
|
// TODO Single sample
|
|
|
|
|
2021-10-02 17:48:07 -07:00
|
|
|
virtual bool supports_single_generation() const { return false; }
|
|
|
|
|
|
|
|
// 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 09:18:05 -08:00
|
|
|
// Declares the channels this generator will use
|
|
|
|
virtual int get_used_channels_mask() const;
|
2020-01-26 14:34:26 -08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
void _b_generate_block(Ref<VoxelBuffer> out_buffer, Vector3 origin_in_voxels, int lod);
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // VOXEL_GENERATOR_H
|