godot_voxel/voxel_mesher.h

60 lines
1.6 KiB
C
Raw Normal View History

#ifndef VOXEL_MESHER
#define VOXEL_MESHER
#include "voxel.h"
#include "voxel_buffer.h"
#include "voxel_library.h"
#include "zprofiling.h"
2017-08-12 16:19:39 -07:00
#include <reference.h>
#include <scene/resources/mesh.h>
// TODO Should be renamed VoxelMesherCubic or something like that
class VoxelMesher : public Reference {
2017-03-24 17:23:36 -07:00
GDCLASS(VoxelMesher, Reference)
public:
2016-12-31 19:40:16 -08:00
static const unsigned int MAX_MATERIALS = 8; // Arbitrary. Tweak if needed.
2016-12-31 19:40:16 -08:00
VoxelMesher();
2016-12-31 19:40:16 -08:00
void set_material(Ref<Material> material, unsigned int id);
2016-12-31 20:23:22 -08:00
Ref<Material> get_material(unsigned int id) const;
2016-12-31 19:40:16 -08:00
void set_library(Ref<VoxelLibrary> library);
2016-12-31 20:23:22 -08:00
Ref<VoxelLibrary> get_library() const { return _library; }
2016-12-31 19:40:16 -08:00
void set_occlusion_darkness(float darkness);
2016-12-31 20:23:22 -08:00
float get_occlusion_darkness() const { return _baked_occlusion_darkness; }
2016-12-31 19:40:16 -08:00
void set_occlusion_enabled(bool enable);
2016-12-31 20:23:22 -08:00
bool get_occlusion_enabled() const { return _bake_occlusion; }
2016-12-31 19:40:16 -08:00
2017-08-12 16:19:39 -07:00
Ref<ArrayMesh> build(const VoxelBuffer &buffer_ref, unsigned int channel, Vector3i min, Vector3i max, Ref<ArrayMesh> mesh = Ref<Mesh>());
Ref<ArrayMesh> build_ref(Ref<VoxelBuffer> buffer_ref, unsigned int channel, Ref<ArrayMesh> mesh = Ref<ArrayMesh>());
protected:
2016-12-31 19:40:16 -08:00
static void _bind_methods();
2016-12-31 20:23:22 -08:00
private:
struct Arrays {
Vector<Vector3> positions;
Vector<Vector3> normals;
Vector<Vector2> uvs;
Vector<Color> colors;
Vector<int> indices;
};
2016-12-31 20:23:22 -08:00
Ref<VoxelLibrary> _library;
Ref<Material> _materials[MAX_MATERIALS];
Arrays _arrays[MAX_MATERIALS];
2016-12-31 20:23:22 -08:00
float _baked_occlusion_darkness;
bool _bake_occlusion;
#ifdef VOXEL_PROFILING
ZProfiler _zprofiler;
Dictionary get_profiling_info() const { return _zprofiler.get_all_serialized_info(); }
#endif
};
#endif // VOXEL_MESHER