2019-04-28 20:48:59 +01:00
|
|
|
#ifndef VOXEL_MESHER_H
|
|
|
|
#define VOXEL_MESHER_H
|
|
|
|
|
2021-02-21 23:58:00 +00:00
|
|
|
#include "../constants/cube_tables.h"
|
2019-12-31 16:48:46 +00:00
|
|
|
#include "../util/fixed_array.h"
|
2019-04-28 20:48:59 +01:00
|
|
|
#include <scene/resources/mesh.h>
|
|
|
|
|
2022-01-08 22:49:48 +00:00
|
|
|
namespace zylann::voxel {
|
2022-01-09 22:13:10 +00:00
|
|
|
|
2022-02-15 21:49:20 +00:00
|
|
|
namespace gd {
|
2022-01-09 22:13:10 +00:00
|
|
|
class VoxelBuffer;
|
2022-02-15 21:49:20 +00:00
|
|
|
}
|
2022-03-27 21:36:30 +01:00
|
|
|
|
2021-09-26 04:14:50 +01:00
|
|
|
class VoxelBufferInternal;
|
2022-03-27 21:36:30 +01:00
|
|
|
class VoxelGenerator;
|
|
|
|
struct VoxelDataLodMap;
|
2020-09-14 19:33:02 +01:00
|
|
|
|
2020-12-18 21:01:50 +00:00
|
|
|
class VoxelMesher : public Resource {
|
|
|
|
GDCLASS(VoxelMesher, Resource)
|
2019-04-28 20:48:59 +01:00
|
|
|
public:
|
2020-01-04 23:24:33 +00:00
|
|
|
struct Input {
|
2022-03-27 21:36:30 +01:00
|
|
|
// Voxels to be used as the primary source of data.
|
2022-01-09 22:13:10 +00:00
|
|
|
const VoxelBufferInternal &voxels;
|
2022-03-27 21:36:30 +01:00
|
|
|
// When using LOD, some meshers can use the generator and edited voxels to affine results.
|
|
|
|
// If not provided, the mesher will only use `voxels`.
|
|
|
|
VoxelGenerator *generator;
|
|
|
|
const VoxelDataLodMap *data;
|
|
|
|
// Origin of the block is required when doing deep sampling.
|
|
|
|
Vector3i origin_in_voxels;
|
|
|
|
// LOD index. 0 means highest detail. 1 means half detail etc.
|
|
|
|
// Not initialized because it confused GCC.
|
|
|
|
int lod; // = 0;
|
2020-01-04 23:24:33 +00:00
|
|
|
};
|
|
|
|
|
2019-04-28 20:48:59 +01:00
|
|
|
struct Output {
|
2019-09-10 20:04:08 +01:00
|
|
|
// Each surface correspond to a different material
|
2022-02-06 22:26:30 +00:00
|
|
|
std::vector<Array> surfaces;
|
|
|
|
FixedArray<std::vector<Array>, Cube::SIDE_COUNT> transition_surfaces;
|
2019-12-26 20:29:55 +00:00
|
|
|
Mesh::PrimitiveType primitive_type = Mesh::PRIMITIVE_TRIANGLES;
|
2021-12-13 21:38:10 +00:00
|
|
|
unsigned int mesh_flags = 0;
|
2021-08-02 19:03:35 +01:00
|
|
|
Ref<Image> atlas_image;
|
2019-04-28 20:48:59 +01:00
|
|
|
};
|
|
|
|
|
2020-12-18 21:01:50 +00:00
|
|
|
// This can be called from multiple threads at once. Make sure member vars are protected or thread-local.
|
2020-01-04 23:24:33 +00:00
|
|
|
virtual void build(Output &output, const Input &voxels);
|
2019-04-28 20:48:59 +01:00
|
|
|
|
2020-12-18 21:01:50 +00:00
|
|
|
// Builds a mesh from the given voxels. This function is simplified to be used by the script API.
|
2022-02-15 21:49:20 +00:00
|
|
|
Ref<Mesh> build_mesh(Ref<gd::VoxelBuffer> voxels, TypedArray<Material> materials);
|
2020-12-18 21:01:50 +00:00
|
|
|
|
|
|
|
// Gets how many neighbor voxels need to be accessed around the meshed area, toward negative axes.
|
2019-12-31 16:48:46 +00:00
|
|
|
// If this is not respected, the mesher might produce seams at the edges, or an error
|
2020-08-25 23:00:38 +01:00
|
|
|
unsigned int get_minimum_padding() const;
|
2020-12-18 21:01:50 +00:00
|
|
|
|
|
|
|
// Gets how many neighbor voxels need to be accessed around the meshed area, toward positive axes.
|
|
|
|
// If this is not respected, the mesher might produce seams at the edges, or an error
|
2020-08-25 23:00:38 +01:00
|
|
|
unsigned int get_maximum_padding() const;
|
2019-12-31 16:48:46 +00:00
|
|
|
|
2021-12-13 21:38:10 +00:00
|
|
|
virtual Ref<Resource> duplicate(bool p_subresources = false) const {
|
|
|
|
return Ref<Resource>();
|
|
|
|
}
|
2019-05-19 18:27:49 +01:00
|
|
|
|
2021-07-11 16:27:17 +01:00
|
|
|
// Gets which channels this mesher is able to use in its current configuration.
|
|
|
|
// This is returned as a bitmask where channel index corresponds to bit position.
|
2021-12-13 21:38:10 +00:00
|
|
|
virtual int get_used_channels_mask() const {
|
|
|
|
return 0;
|
|
|
|
}
|
2019-04-28 20:48:59 +01:00
|
|
|
|
2021-07-11 16:27:17 +01:00
|
|
|
// Returns true if this mesher supports generating voxel data at multiple levels of detail.
|
2021-12-13 21:38:10 +00:00
|
|
|
virtual bool supports_lod() const {
|
|
|
|
return true;
|
|
|
|
}
|
2021-05-15 23:41:19 +01:00
|
|
|
|
2022-03-06 01:10:47 +00:00
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
virtual void get_configuration_warnings(TypedArray<String> &out_warnings) const {}
|
|
|
|
#endif
|
|
|
|
|
2019-04-28 20:48:59 +01:00
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
2019-12-31 16:48:46 +00:00
|
|
|
|
|
|
|
void set_padding(int minimum, int maximum);
|
|
|
|
|
|
|
|
private:
|
2021-01-17 23:47:16 +00:00
|
|
|
// Set in constructor and never changed after.
|
2020-08-25 23:00:38 +01:00
|
|
|
unsigned int _minimum_padding = 0;
|
|
|
|
unsigned int _maximum_padding = 0;
|
2019-04-28 20:48:59 +01:00
|
|
|
};
|
|
|
|
|
2022-01-09 22:13:10 +00:00
|
|
|
} // namespace zylann::voxel
|
|
|
|
|
2019-04-28 20:48:59 +01:00
|
|
|
#endif // VOXEL_MESHER_H
|