2017-08-20 06:48:55 -07:00
|
|
|
#ifndef VOXEL_BLOCK_H
|
|
|
|
#define VOXEL_BLOCK_H
|
|
|
|
|
2019-04-28 09:58:29 -07:00
|
|
|
#include "../voxel_buffer.h"
|
2017-08-20 06:48:55 -07:00
|
|
|
|
|
|
|
#include <scene/3d/mesh_instance.h>
|
|
|
|
#include <scene/3d/physics_body.h>
|
|
|
|
|
|
|
|
// Internal structure holding a reference to mesh visuals, physics and a block of voxel data.
|
|
|
|
class VoxelBlock {
|
|
|
|
public:
|
2019-05-09 11:11:17 -07:00
|
|
|
enum MeshState {
|
|
|
|
MESH_NEVER_UPDATED = 0,
|
|
|
|
MESH_UP_TO_DATE,
|
|
|
|
MESH_UPDATE_NOT_SENT, // The mesh is out of date, but no update request have been sent
|
|
|
|
MESH_UPDATE_SENT // The mesh is out of date, and an update request is pending
|
|
|
|
};
|
|
|
|
|
2019-05-03 16:02:10 -07:00
|
|
|
Ref<VoxelBuffer> voxels;
|
|
|
|
Vector3i pos; // TODO Rename position
|
|
|
|
unsigned int lod_index = 0;
|
2019-05-04 08:29:52 -07:00
|
|
|
|
2019-05-03 16:02:10 -07:00
|
|
|
static VoxelBlock *create(Vector3i bpos, Ref<VoxelBuffer> buffer, unsigned int size, unsigned int p_lod_index);
|
2017-08-20 06:48:55 -07:00
|
|
|
|
2019-05-08 12:36:27 -07:00
|
|
|
~VoxelBlock();
|
|
|
|
|
2017-08-20 09:37:08 -07:00
|
|
|
void set_mesh(Ref<Mesh> mesh, Ref<World> world);
|
2019-05-03 16:02:10 -07:00
|
|
|
bool has_mesh() const;
|
2017-08-20 06:48:55 -07:00
|
|
|
|
2019-05-09 14:00:54 -07:00
|
|
|
void set_mesh_state(MeshState ms);
|
|
|
|
MeshState get_mesh_state() const;
|
|
|
|
|
|
|
|
void mark_been_meshed();
|
|
|
|
bool has_been_meshed() const;
|
|
|
|
|
2017-08-27 17:32:23 -07:00
|
|
|
void enter_world(World *world);
|
|
|
|
void exit_world();
|
|
|
|
void set_visible(bool visible);
|
2019-05-03 16:02:10 -07:00
|
|
|
bool is_visible() const;
|
2017-08-27 17:32:23 -07:00
|
|
|
|
2019-05-10 10:56:48 -07:00
|
|
|
inline bool is_mesh_update_scheduled() {
|
|
|
|
return _mesh_state == MESH_UPDATE_NOT_SENT || _mesh_state == MESH_UPDATE_SENT;
|
|
|
|
}
|
|
|
|
|
2017-08-20 06:48:55 -07:00
|
|
|
private:
|
|
|
|
VoxelBlock();
|
2017-08-20 09:37:08 -07:00
|
|
|
|
|
|
|
Vector3i _position_in_voxels;
|
|
|
|
|
|
|
|
Ref<Mesh> _mesh;
|
|
|
|
RID _mesh_instance;
|
2019-05-08 12:36:27 -07:00
|
|
|
int _mesh_update_count = 0;
|
2019-05-03 16:02:10 -07:00
|
|
|
bool _visible = true;
|
2019-05-09 14:00:54 -07:00
|
|
|
|
|
|
|
MeshState _mesh_state = MESH_NEVER_UPDATED;
|
|
|
|
|
|
|
|
// The mesh might be null, but we don't know if it's actually empty or if it's loading.
|
|
|
|
// This boolean tells if we attempted to mesh this block at least once.
|
|
|
|
bool _has_been_meshed = false;
|
2017-08-20 06:48:55 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // VOXEL_BLOCK_H
|