2019-05-04 00:02:10 +01:00
|
|
|
#ifndef VOXEL_LOD_TERRAIN_HPP
|
|
|
|
#define VOXEL_LOD_TERRAIN_HPP
|
|
|
|
|
2022-07-16 23:59:06 +01:00
|
|
|
#include "../../engine/mesh_block_task.h"
|
|
|
|
#include "../../engine/voxel_engine.h"
|
2022-08-28 20:45:42 +01:00
|
|
|
#include "../../storage/voxel_data.h"
|
2022-08-19 19:48:05 +01:00
|
|
|
#include "../../util/godot/shader_material_pool.h"
|
2022-03-20 22:57:53 +00:00
|
|
|
#include "../voxel_mesh_map.h"
|
|
|
|
#include "../voxel_node.h"
|
2019-05-04 00:02:10 +01:00
|
|
|
#include "lod_octree.h"
|
2022-03-15 00:29:39 +00:00
|
|
|
#include "voxel_lod_terrain_update_data.h"
|
2022-03-20 22:04:53 +00:00
|
|
|
#include "voxel_mesh_block_vlt.h"
|
2020-12-18 22:58:41 +00:00
|
|
|
|
2022-05-17 19:44:58 +01:00
|
|
|
#include <map>
|
2021-09-23 23:49:18 +01:00
|
|
|
#include <unordered_set>
|
2019-05-04 00:02:10 +01:00
|
|
|
|
2020-10-24 00:08:14 +01:00
|
|
|
#ifdef TOOLS_ENABLED
|
2022-03-20 22:57:53 +00:00
|
|
|
#include "../../editor/voxel_debug.h"
|
2020-10-24 00:08:14 +01:00
|
|
|
#endif
|
|
|
|
|
2022-01-09 22:13:10 +00:00
|
|
|
namespace zylann::voxel {
|
|
|
|
|
2019-09-05 19:43:25 +01:00
|
|
|
class VoxelTool;
|
|
|
|
class VoxelStream;
|
2020-12-29 22:25:22 +00:00
|
|
|
class VoxelInstancer;
|
2019-05-04 00:02:10 +01:00
|
|
|
|
2022-08-19 19:48:05 +01:00
|
|
|
class ShaderMaterialPoolVLT : public ShaderMaterialPool {
|
|
|
|
public:
|
|
|
|
void recycle(Ref<ShaderMaterial> material);
|
|
|
|
};
|
|
|
|
|
2019-05-04 00:02:10 +01:00
|
|
|
// Paged terrain made of voxel blocks of variable level of detail.
|
|
|
|
// Designed for highest view distances, preferably using smooth voxels.
|
|
|
|
// Voxels are polygonized around the viewer by distance in a very large sphere, usually extending beyond far clip.
|
2022-01-31 21:23:39 +00:00
|
|
|
// VoxelStream and VoxelGenerator must support LOD.
|
2020-12-18 22:58:41 +00:00
|
|
|
class VoxelLodTerrain : public VoxelNode {
|
|
|
|
GDCLASS(VoxelLodTerrain, VoxelNode)
|
2019-05-04 00:02:10 +01:00
|
|
|
public:
|
|
|
|
VoxelLodTerrain();
|
|
|
|
~VoxelLodTerrain();
|
|
|
|
|
|
|
|
Ref<Material> get_material() const;
|
|
|
|
void set_material(Ref<Material> p_material);
|
|
|
|
|
2020-12-18 22:58:41 +00:00
|
|
|
Ref<VoxelStream> get_stream() const override;
|
|
|
|
void set_stream(Ref<VoxelStream> p_stream) override;
|
2019-05-04 00:02:10 +01:00
|
|
|
|
2021-01-17 17:18:05 +00:00
|
|
|
Ref<VoxelGenerator> get_generator() const override;
|
|
|
|
void set_generator(Ref<VoxelGenerator> p_stream) override;
|
|
|
|
|
2020-12-18 22:58:41 +00:00
|
|
|
Ref<VoxelMesher> get_mesher() const override;
|
|
|
|
void set_mesher(Ref<VoxelMesher> p_mesher) override;
|
2020-12-18 21:01:50 +00:00
|
|
|
|
2019-05-04 00:02:10 +01:00
|
|
|
int get_view_distance() const;
|
2019-09-03 22:56:57 +01:00
|
|
|
void set_view_distance(int p_distance_in_voxels);
|
2019-05-04 00:02:10 +01:00
|
|
|
|
2021-03-27 16:38:20 +00:00
|
|
|
void set_lod_distance(float p_lod_distance);
|
|
|
|
float get_lod_distance() const;
|
2019-05-04 00:02:10 +01:00
|
|
|
|
2019-08-24 01:44:27 +01:00
|
|
|
void set_lod_count(int p_lod_count);
|
2021-05-07 22:39:06 +01:00
|
|
|
int get_lod_count() const;
|
2019-05-04 00:02:10 +01:00
|
|
|
|
2019-08-25 13:04:49 +01:00
|
|
|
void set_generate_collisions(bool enabled);
|
2022-07-03 21:36:07 +01:00
|
|
|
bool get_generate_collisions() const;
|
2019-08-25 13:04:49 +01:00
|
|
|
|
|
|
|
// Sets up to which amount of LODs collision will generate. -1 means all of them.
|
|
|
|
void set_collision_lod_count(int lod_count);
|
2021-05-08 17:15:15 +01:00
|
|
|
int get_collision_lod_count() const;
|
2019-08-25 13:04:49 +01:00
|
|
|
|
2021-05-09 20:49:45 +01:00
|
|
|
void set_collision_layer(int layer);
|
|
|
|
int get_collision_layer() const;
|
|
|
|
|
|
|
|
void set_collision_mask(int mask);
|
|
|
|
int get_collision_mask() const;
|
|
|
|
|
2021-07-10 22:14:17 +01:00
|
|
|
void set_collision_margin(float margin);
|
|
|
|
float get_collision_margin() const;
|
|
|
|
|
2021-04-03 20:39:37 +01:00
|
|
|
int get_data_block_region_extent() const;
|
|
|
|
int get_mesh_block_region_extent() const;
|
2019-05-04 00:02:10 +01:00
|
|
|
|
2021-12-13 21:38:10 +00:00
|
|
|
Vector3i voxel_to_data_block_position(Vector3 vpos, int lod_index) const;
|
|
|
|
Vector3i voxel_to_mesh_block_position(Vector3 vpos, int lod_index) const;
|
2021-04-03 20:39:37 +01:00
|
|
|
|
|
|
|
unsigned int get_data_block_size_pow2() const;
|
|
|
|
unsigned int get_data_block_size() const;
|
2021-10-03 01:28:29 +01:00
|
|
|
//void set_data_block_size_po2(unsigned int p_block_size_po2);
|
2021-04-03 20:39:37 +01:00
|
|
|
|
|
|
|
unsigned int get_mesh_block_size_pow2() const;
|
|
|
|
unsigned int get_mesh_block_size() const;
|
2021-04-03 23:51:11 +01:00
|
|
|
void set_mesh_block_size(unsigned int mesh_block_size);
|
2019-08-24 01:44:27 +01:00
|
|
|
|
2021-10-03 01:48:07 +01:00
|
|
|
void set_full_load_mode_enabled(bool enabled);
|
|
|
|
bool is_full_load_mode_enabled() const;
|
|
|
|
|
2022-03-15 00:29:39 +00:00
|
|
|
void set_threaded_update_enabled(bool enabled);
|
|
|
|
bool is_threaded_update_enabled() const;
|
|
|
|
|
2022-08-14 19:15:55 +01:00
|
|
|
void set_normalmap_enabled(bool enable);
|
|
|
|
bool is_normalmap_enabled() const;
|
|
|
|
|
|
|
|
void set_octahedral_normal_encoding(bool enable);
|
|
|
|
bool get_octahedral_normal_encoding() const;
|
|
|
|
|
|
|
|
void set_normalmap_tile_resolution_min(int resolution);
|
|
|
|
int get_normalmap_tile_resolution_min() const;
|
|
|
|
|
|
|
|
void set_normalmap_tile_resolution_max(int resolution);
|
|
|
|
int get_normalmap_tile_resolution_max() const;
|
|
|
|
|
|
|
|
void set_normalmap_begin_lod_index(int lod_index);
|
|
|
|
int get_normalmap_begin_lod_index() const;
|
|
|
|
|
2019-09-03 22:54:40 +01:00
|
|
|
// These must be called after an edit
|
2021-05-31 17:10:54 +01:00
|
|
|
void post_edit_area(Box3i p_box);
|
2022-06-18 23:14:18 +01:00
|
|
|
void post_edit_modifiers(Box3i p_voxel_box);
|
2019-09-03 22:54:40 +01:00
|
|
|
|
2021-10-04 19:20:36 +01:00
|
|
|
// TODO This still sucks atm cuz the edit will still run on the main thread
|
2022-01-09 22:13:10 +00:00
|
|
|
void push_async_edit(IThreadedTask *task, Box3i box, std::shared_ptr<AsyncDependencyTracker> tracker);
|
2021-10-04 19:20:36 +01:00
|
|
|
void abort_async_edits();
|
|
|
|
|
2021-05-31 17:10:54 +01:00
|
|
|
void set_voxel_bounds(Box3i p_box);
|
2022-03-15 00:29:39 +00:00
|
|
|
|
2021-12-13 21:38:10 +00:00
|
|
|
inline Box3i get_voxel_bounds() const {
|
2022-08-28 20:45:42 +01:00
|
|
|
ZN_ASSERT(_data != nullptr);
|
|
|
|
return _data->get_bounds();
|
2021-12-13 21:38:10 +00:00
|
|
|
}
|
2020-10-22 22:43:31 +01:00
|
|
|
|
2021-02-18 19:50:47 +00:00
|
|
|
void set_collision_update_delay(int delay_msec);
|
|
|
|
int get_collision_update_delay() const;
|
|
|
|
|
2021-03-02 22:49:42 +00:00
|
|
|
void set_lod_fade_duration(float seconds);
|
|
|
|
float get_lod_fade_duration() const;
|
|
|
|
|
2021-12-14 00:10:09 +00:00
|
|
|
enum ProcessCallback { //
|
|
|
|
PROCESS_CALLBACK_IDLE = 0,
|
|
|
|
PROCESS_CALLBACK_PHYSICS,
|
|
|
|
PROCESS_CALLBACK_DISABLED
|
|
|
|
};
|
2020-10-30 19:02:00 +00:00
|
|
|
|
|
|
|
// This was originally added to fix a problem with rigidbody teleportation and floating world origin:
|
|
|
|
// The player teleported at a different rate than the rest of the world due to delays in transform updates,
|
|
|
|
// which caused the world to unload and then reload entirely over the course of 3 frames,
|
|
|
|
// producing flickers and CPU lag. Changing process mode allows to align update rate,
|
|
|
|
// and freeze LOD for the duration of the teleport.
|
2021-12-14 00:10:09 +00:00
|
|
|
void set_process_callback(ProcessCallback mode);
|
|
|
|
ProcessCallback get_process_callback() const {
|
|
|
|
return _process_callback;
|
2021-12-13 21:38:10 +00:00
|
|
|
}
|
2020-10-30 19:02:00 +00:00
|
|
|
|
2022-07-03 03:39:50 +01:00
|
|
|
Ref<VoxelTool> get_voxel_tool() override;
|
2019-09-03 22:54:40 +01:00
|
|
|
|
2019-05-05 01:09:12 +01:00
|
|
|
struct Stats {
|
2022-03-20 18:30:18 +00:00
|
|
|
// Amount of octree nodes waiting for data. It should reach zero when everything is loaded.
|
|
|
|
uint32_t blocked_lods = 0;
|
|
|
|
// How many data blocks were rejected this frame (due to loading too late for example).
|
|
|
|
uint32_t dropped_block_loads = 0;
|
|
|
|
// How many mesh blocks were rejected this frame (due to loading too late for example).
|
|
|
|
uint32_t dropped_block_meshs = 0;
|
|
|
|
// Time spent in the last update unloading unused blocks and detecting required ones, in microseconds
|
2021-02-18 19:50:47 +00:00
|
|
|
uint32_t time_detect_required_blocks = 0;
|
2022-03-20 18:30:18 +00:00
|
|
|
// Time spent in the last update requesting data blocks, in microseconds
|
|
|
|
uint32_t time_io_requests = 0;
|
|
|
|
// Time spent in the last update requesting meshes, in microseconds
|
|
|
|
uint32_t time_mesh_requests = 0;
|
|
|
|
// Total time spent in the last update task, in microseconds.
|
|
|
|
// This only includes the threadable part, not the whole `process` function.
|
|
|
|
uint32_t time_update_task = 0;
|
2019-05-05 01:09:12 +01:00
|
|
|
};
|
|
|
|
|
2020-12-25 17:08:40 +00:00
|
|
|
const Stats &get_stats() const;
|
2020-01-15 21:04:23 +00:00
|
|
|
|
2020-12-18 22:58:41 +00:00
|
|
|
void restart_stream() override;
|
|
|
|
void remesh_all_blocks() override;
|
2020-08-14 20:33:09 +01:00
|
|
|
|
2020-12-29 22:10:31 +00:00
|
|
|
// Debugging
|
|
|
|
|
2021-04-03 20:39:37 +01:00
|
|
|
Array debug_raycast_mesh_block(Vector3 world_origin, Vector3 world_direction) const;
|
2021-04-05 03:46:15 +01:00
|
|
|
Dictionary debug_get_data_block_info(Vector3 fbpos, int lod_index) const;
|
2021-04-03 20:39:37 +01:00
|
|
|
Dictionary debug_get_mesh_block_info(Vector3 fbpos, int lod_index) const;
|
2021-03-11 22:55:52 +00:00
|
|
|
Array debug_get_octree_positions() const;
|
|
|
|
Array debug_get_octrees_detailed() const;
|
2019-05-05 01:09:12 +01:00
|
|
|
|
2022-06-26 14:04:12 +01:00
|
|
|
enum DebugDrawFlag {
|
|
|
|
DEBUG_DRAW_OCTREE_NODES = 0,
|
|
|
|
DEBUG_DRAW_OCTREE_BOUNDS = 1,
|
|
|
|
DEBUG_DRAW_MESH_UPDATES = 2,
|
|
|
|
DEBUG_DRAW_EDIT_BOXES = 3,
|
|
|
|
DEBUG_DRAW_VOLUME_BOUNDS = 4,
|
|
|
|
DEBUG_DRAW_EDITED_BLOCKS = 5,
|
|
|
|
|
|
|
|
DEBUG_DRAW_FLAGS_COUNT = 6
|
|
|
|
};
|
|
|
|
|
|
|
|
void debug_set_draw_enabled(bool enabled);
|
|
|
|
bool debug_is_draw_enabled() const;
|
|
|
|
|
|
|
|
void debug_set_draw_flag(DebugDrawFlag flag_index, bool enabled);
|
|
|
|
bool debug_get_draw_flag(DebugDrawFlag flag_index) const;
|
|
|
|
|
2020-12-29 22:10:31 +00:00
|
|
|
// Editor
|
|
|
|
|
|
|
|
void set_run_stream_in_editor(bool enable);
|
|
|
|
bool is_stream_running_in_editor() const;
|
|
|
|
|
2020-10-24 00:08:14 +01:00
|
|
|
#ifdef TOOLS_ENABLED
|
2022-03-06 01:10:47 +00:00
|
|
|
|
2021-12-13 21:38:10 +00:00
|
|
|
TypedArray<String> get_configuration_warnings() const override;
|
2021-09-16 21:54:04 +01:00
|
|
|
|
2022-03-06 01:10:47 +00:00
|
|
|
#endif // TOOLS_ENABLED
|
|
|
|
|
2020-12-29 22:25:22 +00:00
|
|
|
// Internal
|
|
|
|
|
|
|
|
void set_instancer(VoxelInstancer *instancer);
|
2022-04-09 20:40:03 +01:00
|
|
|
uint32_t get_volume_id() const override {
|
2021-12-13 21:38:10 +00:00
|
|
|
return _volume_id;
|
|
|
|
}
|
2022-05-22 00:18:58 +01:00
|
|
|
std::shared_ptr<StreamingDependency> get_streaming_dependency() const override {
|
|
|
|
return _streaming_dependency;
|
|
|
|
}
|
2020-12-29 22:25:22 +00:00
|
|
|
|
2021-04-03 20:39:37 +01:00
|
|
|
Array get_mesh_block_surface(Vector3i block_pos, int lod_index) const;
|
2022-02-06 21:26:48 +00:00
|
|
|
void get_meshed_block_positions_at_lod(int lod_index, std::vector<Vector3i> &out_positions) const;
|
2021-02-14 21:55:31 +00:00
|
|
|
|
2022-08-28 20:45:42 +01:00
|
|
|
inline VoxelData &get_storage() const {
|
|
|
|
ZN_ASSERT(_data != nullptr);
|
|
|
|
return *_data;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline std::shared_ptr<VoxelData> get_storage_shared() const {
|
2021-12-13 21:38:10 +00:00
|
|
|
return _data;
|
|
|
|
}
|
2021-10-13 20:28:20 +01:00
|
|
|
|
2019-05-04 00:02:10 +01:00
|
|
|
protected:
|
|
|
|
void _notification(int p_what);
|
|
|
|
|
2021-12-16 00:11:11 +00:00
|
|
|
void _on_gi_mode_changed() override;
|
|
|
|
|
2019-05-04 00:02:10 +01:00
|
|
|
private:
|
2021-09-16 21:54:04 +01:00
|
|
|
void _process(float delta);
|
2022-03-16 00:05:04 +00:00
|
|
|
void apply_main_thread_update_tasks();
|
2021-10-05 20:47:28 +01:00
|
|
|
|
2022-07-16 23:59:06 +01:00
|
|
|
void apply_mesh_update(VoxelEngine::BlockMeshOutput &ob);
|
|
|
|
void apply_data_block_response(VoxelEngine::BlockDataOutput &ob);
|
2022-08-13 16:40:46 +01:00
|
|
|
void apply_virtual_texture_update(VoxelEngine::BlockVirtualTextureOutput &ob);
|
|
|
|
void apply_virtual_texture_update_to_block(
|
2022-08-14 22:34:27 +01:00
|
|
|
VoxelMeshBlockVLT &block, VirtualTextureOutput &ob, unsigned int lod_index);
|
2021-09-16 21:54:04 +01:00
|
|
|
|
2019-08-24 01:44:27 +01:00
|
|
|
void start_updater();
|
|
|
|
void stop_updater();
|
|
|
|
void start_streamer();
|
|
|
|
void stop_streamer();
|
|
|
|
void reset_maps();
|
2022-06-03 18:30:42 +01:00
|
|
|
void reset_mesh_maps();
|
2019-08-24 01:44:27 +01:00
|
|
|
|
2020-10-25 21:21:37 +00:00
|
|
|
Vector3 get_local_viewer_pos() const;
|
2019-08-24 01:44:27 +01:00
|
|
|
void _set_lod_count(int p_lod_count);
|
2022-07-10 16:57:09 +01:00
|
|
|
void set_mesh_block_active(VoxelMeshBlockVLT &block, bool active, bool with_fading);
|
2021-10-13 20:28:20 +01:00
|
|
|
|
2019-08-24 01:44:27 +01:00
|
|
|
void _on_stream_params_changed();
|
2019-05-04 00:02:10 +01:00
|
|
|
|
2022-08-19 19:48:05 +01:00
|
|
|
void update_shader_material_pool_template();
|
|
|
|
|
2019-09-07 21:19:12 +01:00
|
|
|
void save_all_modified_blocks(bool with_copy);
|
2022-03-15 00:29:39 +00:00
|
|
|
|
2021-02-18 19:50:47 +00:00
|
|
|
void process_deferred_collision_updates(uint32_t timeout_msec);
|
2021-03-02 22:49:42 +00:00
|
|
|
void process_fading_blocks(float delta);
|
2019-09-03 22:54:40 +01:00
|
|
|
|
2022-07-10 16:57:09 +01:00
|
|
|
struct LocalCameraInfo {
|
|
|
|
Vector3 position;
|
|
|
|
Vector3 forward;
|
|
|
|
};
|
|
|
|
|
|
|
|
LocalCameraInfo get_local_camera_info() const;
|
|
|
|
|
2020-07-25 16:29:16 +01:00
|
|
|
void _b_save_modified_blocks();
|
2020-10-22 22:43:31 +01:00
|
|
|
void _b_set_voxel_bounds(AABB aabb);
|
|
|
|
AABB _b_get_voxel_bounds() const;
|
2022-06-26 14:04:12 +01:00
|
|
|
|
2021-12-13 21:38:10 +00:00
|
|
|
Array _b_debug_print_sdf_top_down(Vector3i center, Vector3i extents);
|
2021-04-03 20:39:37 +01:00
|
|
|
int _b_debug_get_mesh_block_count() const;
|
|
|
|
int _b_debug_get_data_block_count() const;
|
2021-12-30 04:25:42 +00:00
|
|
|
Error _b_debug_dump_as_scene(String fpath, bool include_instancer) const;
|
2022-06-26 14:04:12 +01:00
|
|
|
|
2020-12-25 17:08:40 +00:00
|
|
|
Dictionary _b_get_statistics() const;
|
2020-02-04 15:37:52 +01:00
|
|
|
|
2020-10-24 00:08:14 +01:00
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
void update_gizmos();
|
|
|
|
#endif
|
|
|
|
|
2021-09-16 21:54:04 +01:00
|
|
|
static void _bind_methods();
|
|
|
|
|
2020-10-24 00:08:14 +01:00
|
|
|
private:
|
2022-06-22 22:05:25 +01:00
|
|
|
friend class BuildTransitionMeshTask;
|
|
|
|
|
2020-08-31 21:51:30 +01:00
|
|
|
uint32_t _volume_id = 0;
|
2021-12-14 00:10:09 +00:00
|
|
|
ProcessCallback _process_callback = PROCESS_CALLBACK_IDLE;
|
2019-05-04 00:02:10 +01:00
|
|
|
|
|
|
|
Ref<Material> _material;
|
2022-08-19 19:48:05 +01:00
|
|
|
|
2022-07-10 16:57:09 +01:00
|
|
|
// The main reason this pool even exists is because of this: https://github.com/godotengine/godot/issues/34741
|
|
|
|
// Blocks need individual shader parameters for several features,
|
|
|
|
// so a lot of ShaderMaterial copies using the same shader are created.
|
|
|
|
// The terrain must be able to run in editor, but in that context, Godot connects a signal of Shader to
|
|
|
|
// every ShaderMaterial using it. Godot does that in order to update properties in THE inspector if the shader
|
|
|
|
// changes (which is debatable since only the edited material needs this, if it even is edited!).
|
|
|
|
// The problem is, that also means every time `ShaderMaterial::duplicate()` is called, when it assigns `shader`,
|
|
|
|
// it has to add a connection to a HUGE list. Which is very slow, enough to cause stutters.
|
2022-08-19 19:48:05 +01:00
|
|
|
ShaderMaterialPoolVLT _shader_material_pool;
|
2019-05-04 00:02:10 +01:00
|
|
|
|
2022-03-20 22:04:53 +00:00
|
|
|
FixedArray<VoxelMeshMap<VoxelMeshBlockVLT>, constants::MAX_LOD> _mesh_maps_per_lod;
|
2022-03-19 19:43:33 +00:00
|
|
|
|
2022-07-10 16:57:09 +01:00
|
|
|
// Copies of meshes just for fading out.
|
|
|
|
// Used when a transition mask changes. This can make holes appear if not smoothly faded.
|
|
|
|
struct FadingOutMesh {
|
|
|
|
// Position in space coordinates local to the volume
|
|
|
|
Vector3 local_position;
|
|
|
|
DirectMeshInstance mesh_instance;
|
|
|
|
// Changing properties is the reason we may want to fade the mesh, so we may hold on a copy of the material with
|
|
|
|
// properties before the fade starts.
|
|
|
|
Ref<ShaderMaterial> shader_material;
|
|
|
|
// Going from 1 to 0
|
|
|
|
float progress;
|
|
|
|
};
|
|
|
|
|
|
|
|
// These are "fire and forget"
|
|
|
|
std::vector<FadingOutMesh> _fading_out_meshes;
|
|
|
|
|
2021-04-18 01:29:26 +01:00
|
|
|
unsigned int _collision_lod_count = 0;
|
2021-05-09 20:49:45 +01:00
|
|
|
unsigned int _collision_layer = 1;
|
|
|
|
unsigned int _collision_mask = 1;
|
2022-01-09 22:13:10 +00:00
|
|
|
float _collision_margin = constants::DEFAULT_COLLISION_MARGIN;
|
2021-02-18 19:50:47 +00:00
|
|
|
int _collision_update_delay = 0;
|
2022-03-15 00:29:39 +00:00
|
|
|
FixedArray<std::vector<Vector3i>, constants::MAX_LOD> _deferred_collision_updates_per_lod;
|
2019-08-25 13:04:49 +01:00
|
|
|
|
2022-03-15 00:29:39 +00:00
|
|
|
float _lod_fade_duration = 0.f;
|
|
|
|
// Note, direct pointers to mesh blocks should be safe because these blocks are always destroyed from the same
|
|
|
|
// thread that updates fading blocks. If a mesh block is destroyed, these maps should be updated at the same time.
|
|
|
|
// TODO Optimization: use FlatMap? Need to check how many blocks get in there, probably not many
|
2022-05-17 19:44:58 +01:00
|
|
|
FixedArray<std::map<Vector3i, VoxelMeshBlockVLT *>, constants::MAX_LOD> _fading_blocks_per_lod;
|
2021-10-13 20:28:20 +01:00
|
|
|
|
2022-08-13 16:40:46 +01:00
|
|
|
struct FadingVirtualTexture {
|
|
|
|
Vector3i block_position;
|
|
|
|
uint32_t lod_index;
|
|
|
|
float progress;
|
|
|
|
};
|
|
|
|
|
|
|
|
std::vector<FadingVirtualTexture> _fading_virtual_textures;
|
|
|
|
|
2022-03-15 00:29:39 +00:00
|
|
|
VoxelInstancer *_instancer = nullptr;
|
2021-10-13 20:28:20 +01:00
|
|
|
|
2022-03-15 00:29:39 +00:00
|
|
|
Ref<VoxelMesher> _mesher;
|
2021-10-04 19:20:36 +01:00
|
|
|
|
2021-10-13 20:28:20 +01:00
|
|
|
// Data stored with a shared pointer so it can be sent to asynchronous tasks
|
2022-03-15 00:29:39 +00:00
|
|
|
bool _threaded_update_enabled = false;
|
2022-08-28 20:45:42 +01:00
|
|
|
std::shared_ptr<VoxelData> _data;
|
2022-03-15 00:29:39 +00:00
|
|
|
std::shared_ptr<VoxelLodTerrainUpdateData> _update_data;
|
|
|
|
std::shared_ptr<StreamingDependency> _streaming_dependency;
|
|
|
|
std::shared_ptr<MeshingDependency> _meshing_dependency;
|
2021-10-04 19:20:36 +01:00
|
|
|
|
2022-06-09 20:35:29 +01:00
|
|
|
struct ApplyMeshUpdateTask : public ITimeSpreadTask {
|
|
|
|
void run(TimeSpreadTaskContext &ctx) override;
|
|
|
|
|
|
|
|
uint32_t volume_id = 0;
|
|
|
|
VoxelLodTerrain *self = nullptr;
|
2022-07-16 23:59:06 +01:00
|
|
|
VoxelEngine::BlockMeshOutput data;
|
2022-06-09 20:35:29 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
FixedArray<std::unordered_map<Vector3i, RefCount>, constants::MAX_LOD> _queued_main_thread_mesh_updates;
|
|
|
|
|
2020-10-24 00:08:14 +01:00
|
|
|
#ifdef TOOLS_ENABLED
|
2022-06-26 14:04:12 +01:00
|
|
|
bool _debug_draw_enabled = false;
|
|
|
|
uint8_t _debug_draw_flags = 0;
|
|
|
|
uint8_t _edited_blocks_gizmos_lod_index = 0;
|
|
|
|
|
2022-01-09 22:13:10 +00:00
|
|
|
DebugRenderer _debug_renderer;
|
2022-06-26 14:04:12 +01:00
|
|
|
|
2022-06-05 23:26:17 +01:00
|
|
|
struct DebugMeshUpdateItem {
|
|
|
|
static constexpr uint32_t LINGER_FRAMES = 10;
|
|
|
|
Vector3i position;
|
|
|
|
uint32_t lod;
|
|
|
|
uint32_t remaining_frames;
|
|
|
|
};
|
2022-06-26 14:04:12 +01:00
|
|
|
|
2022-06-05 23:26:17 +01:00
|
|
|
std::vector<DebugMeshUpdateItem> _debug_mesh_update_items;
|
2022-06-26 14:04:12 +01:00
|
|
|
|
2022-06-26 00:34:43 +01:00
|
|
|
struct DebugEditItem {
|
|
|
|
static constexpr uint32_t LINGER_FRAMES = 10;
|
|
|
|
Box3i voxel_box;
|
|
|
|
uint32_t remaining_frames;
|
|
|
|
};
|
2022-06-26 14:04:12 +01:00
|
|
|
|
2022-06-26 00:34:43 +01:00
|
|
|
std::vector<DebugEditItem> _debug_edit_items;
|
2020-10-24 00:08:14 +01:00
|
|
|
#endif
|
2020-08-14 20:33:09 +01:00
|
|
|
|
2019-05-05 01:09:12 +01:00
|
|
|
Stats _stats;
|
2019-05-04 00:02:10 +01:00
|
|
|
};
|
|
|
|
|
2022-01-09 22:13:10 +00:00
|
|
|
} // namespace zylann::voxel
|
|
|
|
|
|
|
|
VARIANT_ENUM_CAST(zylann::voxel::VoxelLodTerrain::ProcessCallback)
|
2022-06-26 14:04:12 +01:00
|
|
|
VARIANT_ENUM_CAST(zylann::voxel::VoxelLodTerrain::DebugDrawFlag)
|
2020-10-30 19:02:00 +00:00
|
|
|
|
2019-05-04 00:02:10 +01:00
|
|
|
#endif // VOXEL_LOD_TERRAIN_HPP
|