2019-04-28 12:48:59 -07:00
|
|
|
#ifndef VOXEL_MESHER_H
|
|
|
|
#define VOXEL_MESHER_H
|
|
|
|
|
2019-12-31 08:48:46 -08:00
|
|
|
#include "../cube_tables.h"
|
|
|
|
#include "../util/fixed_array.h"
|
2019-04-28 12:48:59 -07:00
|
|
|
#include "../voxel_buffer.h"
|
|
|
|
#include <scene/resources/mesh.h>
|
|
|
|
|
|
|
|
class VoxelMesher : public Reference {
|
|
|
|
GDCLASS(VoxelMesher, Reference)
|
|
|
|
public:
|
2020-01-04 15:24:33 -08:00
|
|
|
struct Input {
|
|
|
|
const VoxelBuffer &voxels;
|
2020-01-06 12:08:51 -08:00
|
|
|
int lod; // = 0; // Not initialized because it confused GCC
|
2020-01-04 15:24:33 -08:00
|
|
|
};
|
|
|
|
|
2019-04-28 12:48:59 -07:00
|
|
|
struct Output {
|
2019-09-10 12:04:08 -07:00
|
|
|
// Each surface correspond to a different material
|
2019-04-28 12:48:59 -07:00
|
|
|
Vector<Array> surfaces;
|
2019-12-31 08:48:46 -08:00
|
|
|
FixedArray<Vector<Array>, Cube::SIDE_COUNT> transition_surfaces;
|
2019-12-26 12:29:55 -08:00
|
|
|
Mesh::PrimitiveType primitive_type = Mesh::PRIMITIVE_TRIANGLES;
|
|
|
|
unsigned int compression_flags = Mesh::ARRAY_COMPRESS_DEFAULT;
|
2019-04-28 12:48:59 -07:00
|
|
|
};
|
|
|
|
|
2020-01-04 15:24:33 -08:00
|
|
|
virtual void build(Output &output, const Input &voxels);
|
2019-04-28 12:48:59 -07:00
|
|
|
|
2019-12-31 08:48:46 -08:00
|
|
|
// Get how many neighbor voxels need to be accessed around the meshed area.
|
|
|
|
// If this is not respected, the mesher might produce seams at the edges, or an error
|
|
|
|
int get_minimum_padding() const;
|
|
|
|
int get_maximum_padding() const;
|
|
|
|
|
|
|
|
// Must be cloneable so can be duplicated for use by more than one thread
|
2019-05-19 10:27:49 -07:00
|
|
|
virtual VoxelMesher *clone();
|
|
|
|
|
2019-04-28 12:48:59 -07:00
|
|
|
Ref<Mesh> build_mesh(Ref<VoxelBuffer> voxels);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
2019-12-31 08:48:46 -08:00
|
|
|
|
|
|
|
void set_padding(int minimum, int maximum);
|
|
|
|
|
|
|
|
private:
|
|
|
|
int _minimum_padding = 0;
|
|
|
|
int _maximum_padding = 0;
|
2019-04-28 12:48:59 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // VOXEL_MESHER_H
|