-
-
Notifications
You must be signed in to change notification settings - Fork 236
/
mesh_block_task.h
89 lines (75 loc) · 3.12 KB
/
mesh_block_task.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#ifndef VOXEL_MESH_BLOCK_TASK_H
#define VOXEL_MESH_BLOCK_TASK_H
#include "../constants/voxel_constants.h"
#include "../engine/detail_rendering/detail_rendering.h"
#include "../engine/ids.h"
#include "../engine/meshing_dependency.h"
#include "../engine/priority_dependency.h"
#include "../generators/generate_block_gpu_task.h"
#include "../storage/voxel_buffer.h"
#include "../util/containers/std_vector.h"
#include "../util/godot/classes/array_mesh.h"
#include "../util/tasks/cancellation_token.h"
#include "../util/tasks/threaded_task.h"
namespace zylann::voxel {
class VoxelData;
// Asynchronous task generating a mesh from voxel blocks and their neighbors, in a particular volume
class MeshBlockTask : public IGeneratingVoxelsThreadedTask {
public:
MeshBlockTask();
~MeshBlockTask();
const char *get_debug_name() const override {
return "MeshBlock";
}
void run(ThreadedTaskContext &ctx) override;
TaskPriority get_priority() override;
bool is_cancelled() override;
void apply_result() override;
void set_gpu_results(StdVector<GenerateBlockGPUTaskResult> &&results) override;
static int debug_get_running_count();
// 3x3x3 or 4x4x4 grid of voxel blocks.
FixedArray<std::shared_ptr<VoxelBuffer>, constants::MAX_BLOCK_COUNT_PER_REQUEST> blocks;
// TODO Need to provide format
// FixedArray<uint8_t, VoxelBuffer::MAX_CHANNELS> channel_depths;
Vector3i mesh_block_position; // In mesh blocks of the specified lod
VolumeID volume_id;
uint8_t lod_index = 0;
uint8_t blocks_count = 0;
// If true, a rendering mesh resource will be created if possible.
bool require_visual = true;
// If true, a collision mesh is required if possible
bool collision_hint = false;
// If true, the mesh will be used in a context with LOD, which might require a few extra things in the way it is
// built
bool lod_hint = false;
// Detail textures might be enabled, but we don't always want to update them in every mesh update.
// So this boolean is also checked to know if they should be computed.
bool require_detail_texture = false;
uint8_t detail_texture_generator_override_begin_lod_index = 0;
bool detail_texture_use_gpu = false;
bool block_generation_use_gpu = false;
PriorityDependency priority_dependency;
std::shared_ptr<MeshingDependency> meshing_dependency;
std::shared_ptr<VoxelData> data;
DetailRenderingSettings detail_texture_settings;
Ref<VoxelGenerator> detail_texture_generator_override;
TaskCancellationToken cancellation_token;
private:
void gather_voxels_gpu(zylann::ThreadedTaskContext &ctx);
void gather_voxels_cpu();
void build_mesh();
bool _has_run = false;
bool _too_far = false;
bool _has_mesh_resource = false;
uint8_t _stage = 0;
VoxelBuffer _voxels;
VoxelMesher::Output _surfaces_output;
Ref<Mesh> _mesh;
StdVector<uint16_t> _mesh_material_indices; // Indexed by mesh surface
std::shared_ptr<DetailTextureOutput> _detail_textures;
StdVector<GenerateBlockGPUTaskResult> _gpu_generation_results;
};
Ref<ArrayMesh> build_mesh(Span<const VoxelMesher::Output::Surface> surfaces, Mesh::PrimitiveType primitive, int flags,
StdVector<uint16_t> &mesh_material_indices);
} // namespace zylann::voxel
#endif // VOXEL_MESH_BLOCK_TASK_H