2020-10-24 00:08:14 +01:00
|
|
|
#ifndef VOXEL_DEBUG_H
|
|
|
|
#define VOXEL_DEBUG_H
|
|
|
|
|
2021-09-16 21:54:04 +01:00
|
|
|
#include "../util/godot/direct_multimesh_instance.h"
|
2021-12-13 21:38:10 +00:00
|
|
|
#include <core/object/ref_counted.h>
|
2020-10-24 00:08:14 +01:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
class Mesh;
|
2022-01-04 22:57:21 +00:00
|
|
|
class World3D;
|
|
|
|
|
2022-01-04 22:37:37 +00:00
|
|
|
namespace zylann {
|
2022-01-04 22:57:21 +00:00
|
|
|
namespace DebugColors {
|
2020-10-24 00:08:14 +01:00
|
|
|
|
2021-12-14 00:23:26 +00:00
|
|
|
enum ColorID { //
|
2020-10-24 00:08:14 +01:00
|
|
|
ID_VOXEL_BOUNDS = 0,
|
|
|
|
ID_OCTREE_BOUNDS,
|
2021-03-21 18:48:00 +00:00
|
|
|
ID_VOXEL_GRAPH_DEBUG_BOUNDS,
|
2021-09-16 21:54:04 +01:00
|
|
|
ID_WHITE,
|
2020-10-24 00:08:14 +01:00
|
|
|
ID_COUNT
|
|
|
|
};
|
|
|
|
|
2022-01-04 22:57:21 +00:00
|
|
|
} //namespace DebugColors
|
|
|
|
|
|
|
|
Ref<Mesh> get_debug_wirecube(DebugColors::ColorID id);
|
|
|
|
void free_debug_resources();
|
2020-10-24 00:08:14 +01:00
|
|
|
|
2021-09-16 21:54:04 +01:00
|
|
|
class DebugMultiMeshRenderer {
|
|
|
|
public:
|
|
|
|
DebugMultiMeshRenderer();
|
2021-12-14 00:23:26 +00:00
|
|
|
~DebugMultiMeshRenderer();
|
2021-09-16 21:54:04 +01:00
|
|
|
|
2021-12-13 21:38:10 +00:00
|
|
|
void set_world(World3D *world);
|
2021-09-16 21:54:04 +01:00
|
|
|
void begin();
|
2022-01-04 22:57:21 +00:00
|
|
|
void draw_box(const Transform3D &t, Color8 color);
|
2021-09-16 21:54:04 +01:00
|
|
|
void end();
|
|
|
|
void clear();
|
|
|
|
|
|
|
|
private:
|
2021-12-13 21:38:10 +00:00
|
|
|
std::vector<DirectMultiMeshInstance::TransformAndColor32> _items;
|
2021-09-16 21:54:04 +01:00
|
|
|
Ref<MultiMesh> _multimesh;
|
|
|
|
DirectMultiMeshInstance _multimesh_instance;
|
2021-12-30 22:20:30 +00:00
|
|
|
// TODO World3D is a reference, do not store it by pointer
|
2021-12-13 21:38:10 +00:00
|
|
|
World3D *_world = nullptr;
|
2021-09-16 21:54:04 +01:00
|
|
|
bool _inside_block = false;
|
2021-12-13 21:38:10 +00:00
|
|
|
PackedFloat32Array _bulk_array;
|
|
|
|
Ref<StandardMaterial3D> _material;
|
2021-09-16 21:54:04 +01:00
|
|
|
};
|
|
|
|
|
2020-11-21 18:15:12 +00:00
|
|
|
class DebugRendererItem;
|
|
|
|
|
2020-10-24 00:08:14 +01:00
|
|
|
class DebugRenderer {
|
|
|
|
public:
|
|
|
|
~DebugRenderer();
|
|
|
|
|
2021-12-30 22:20:30 +00:00
|
|
|
// This class does not uses nodes. Call this first to choose in which world it renders.
|
2021-12-13 21:38:10 +00:00
|
|
|
void set_world(World3D *world);
|
2020-10-24 00:08:14 +01:00
|
|
|
|
2021-12-30 22:20:30 +00:00
|
|
|
// Call this before issuing drawing commands
|
2020-10-24 00:08:14 +01:00
|
|
|
void begin();
|
2021-12-30 22:20:30 +00:00
|
|
|
|
2022-01-04 22:57:21 +00:00
|
|
|
void draw_box(const Transform3D &t, DebugColors::ColorID color);
|
2021-12-30 22:20:30 +00:00
|
|
|
|
|
|
|
// Draws a box wireframe using MultiMesh, allowing to draw much more without slowing down.
|
|
|
|
// The box's origin is its lower corner. Size is defined by the transform's basis.
|
2022-01-04 22:57:21 +00:00
|
|
|
void draw_box_mm(const Transform3D &t, Color8 color);
|
2021-12-30 22:20:30 +00:00
|
|
|
|
|
|
|
// Call this after issuing all drawing commands
|
2020-10-24 00:08:14 +01:00
|
|
|
void end();
|
2021-12-30 22:20:30 +00:00
|
|
|
|
2020-10-24 00:08:14 +01:00
|
|
|
void clear();
|
|
|
|
|
|
|
|
private:
|
2020-11-21 18:15:12 +00:00
|
|
|
std::vector<DebugRendererItem *> _items;
|
2020-10-24 00:08:14 +01:00
|
|
|
unsigned int _current = 0;
|
|
|
|
bool _inside_block = false;
|
2021-12-30 22:20:30 +00:00
|
|
|
// TODO World3D is a reference, do not store it by pointer
|
2021-12-13 21:38:10 +00:00
|
|
|
World3D *_world = nullptr;
|
2021-09-16 21:54:04 +01:00
|
|
|
DebugMultiMeshRenderer _mm_renderer;
|
2020-10-24 00:08:14 +01:00
|
|
|
};
|
|
|
|
|
2022-01-04 22:57:21 +00:00
|
|
|
} //namespace zylann
|
2020-10-24 00:08:14 +01:00
|
|
|
|
|
|
|
#endif // VOXEL_DEBUG_H
|