2019-04-28 18:58:29 +02:00
|
|
|
#ifndef VOXEL_MESHER_BLOCKY_H
|
|
|
|
#define VOXEL_MESHER_BLOCKY_H
|
2016-05-01 15:00:02 +02:00
|
|
|
|
2019-04-28 18:58:29 +02:00
|
|
|
#include "../../util/zprofiling.h"
|
|
|
|
#include "../../voxel.h"
|
|
|
|
#include "../../voxel_library.h"
|
2019-04-28 21:48:59 +02:00
|
|
|
#include "../voxel_mesher.h"
|
2018-09-19 21:25:04 +02:00
|
|
|
#include <core/reference.h>
|
2017-08-13 01:19:39 +02:00
|
|
|
#include <scene/resources/mesh.h>
|
2019-04-28 22:02:42 +02:00
|
|
|
#include <vector>
|
2017-04-06 23:44:11 +02:00
|
|
|
|
2019-04-28 21:48:59 +02:00
|
|
|
class VoxelMesherBlocky : public VoxelMesher {
|
|
|
|
GDCLASS(VoxelMesherBlocky, VoxelMesher)
|
2016-05-01 15:00:02 +02:00
|
|
|
|
2016-05-01 22:20:27 +02:00
|
|
|
public:
|
2017-01-01 04:40:16 +01:00
|
|
|
static const unsigned int MAX_MATERIALS = 8; // Arbitrary. Tweak if needed.
|
2019-04-28 02:32:23 +02:00
|
|
|
static const int MINIMUM_PADDING = 1;
|
2016-05-01 15:00:02 +02:00
|
|
|
|
2019-04-28 18:58:29 +02:00
|
|
|
VoxelMesherBlocky();
|
2016-05-01 15:00:02 +02:00
|
|
|
|
2017-01-01 04:40:16 +01:00
|
|
|
void set_library(Ref<VoxelLibrary> library);
|
2017-01-01 05:23:22 +01:00
|
|
|
Ref<VoxelLibrary> get_library() const { return _library; }
|
2016-05-01 22:20:27 +02:00
|
|
|
|
2017-01-01 04:40:16 +01:00
|
|
|
void set_occlusion_darkness(float darkness);
|
2017-01-01 05:23:22 +01:00
|
|
|
float get_occlusion_darkness() const { return _baked_occlusion_darkness; }
|
2017-01-01 04:40:16 +01:00
|
|
|
|
|
|
|
void set_occlusion_enabled(bool enable);
|
2017-01-01 05:23:22 +01:00
|
|
|
bool get_occlusion_enabled() const { return _bake_occlusion; }
|
2017-01-01 04:40:16 +01:00
|
|
|
|
2019-04-28 21:48:59 +02:00
|
|
|
void build(VoxelMesher::Output &output, const VoxelBuffer &voxels, int padding) override;
|
|
|
|
int get_minimum_padding() const override;
|
2016-05-04 14:52:23 +02:00
|
|
|
|
2016-05-01 15:00:02 +02:00
|
|
|
protected:
|
2017-01-01 04:40:16 +01:00
|
|
|
static void _bind_methods();
|
2016-05-01 15:00:02 +02:00
|
|
|
|
2017-01-01 05:23:22 +01:00
|
|
|
private:
|
2019-04-28 22:02:42 +02:00
|
|
|
// Using std::vector because they make this mesher twice as fast than Godot Vectors.
|
|
|
|
// See why: https://github.com/godotengine/godot/issues/24731
|
2017-08-19 21:10:31 +02:00
|
|
|
struct Arrays {
|
2019-04-28 22:02:42 +02:00
|
|
|
std::vector<Vector3> positions;
|
|
|
|
std::vector<Vector3> normals;
|
|
|
|
std::vector<Vector2> uvs;
|
|
|
|
std::vector<Color> colors;
|
|
|
|
std::vector<int> indices;
|
2017-08-19 21:10:31 +02:00
|
|
|
};
|
|
|
|
|
2017-01-01 05:23:22 +01:00
|
|
|
Ref<VoxelLibrary> _library;
|
2017-08-19 21:10:31 +02:00
|
|
|
Arrays _arrays[MAX_MATERIALS];
|
2017-01-01 05:23:22 +01:00
|
|
|
float _baked_occlusion_darkness;
|
|
|
|
bool _bake_occlusion;
|
|
|
|
|
2017-04-01 20:10:38 +02:00
|
|
|
#ifdef VOXEL_PROFILING
|
|
|
|
ZProfiler _zprofiler;
|
|
|
|
Dictionary get_profiling_info() const { return _zprofiler.get_all_serialized_info(); }
|
|
|
|
#endif
|
2016-05-01 15:00:02 +02:00
|
|
|
};
|
|
|
|
|
2019-04-28 18:58:29 +02:00
|
|
|
#endif // VOXEL_MESHER_BLOCKY_H
|