feat: added slope handle
This commit is contained in:
parent
07f193a04b
commit
b34362c7ae
10 changed files with 80 additions and 40 deletions
|
|
@ -2,9 +2,7 @@
|
|||
#include "core/config/engine.h"
|
||||
#include "macros.h"
|
||||
#include "scene/3d/camera_3d.h"
|
||||
#include "scene/3d/physics/static_body_3d.h"
|
||||
#include "scene/main/viewport.h"
|
||||
#include "scene/resources/mesh.h"
|
||||
#include "terrain_editor/terrain_mesh_generator.h"
|
||||
|
||||
void TerrainChunk::_bind_methods() {
|
||||
|
|
@ -36,7 +34,7 @@ void TerrainChunk::on_terrain_changed() {
|
|||
if (!status.mesh.is_valid()) {
|
||||
status.mesh.instantiate();
|
||||
}
|
||||
size_t base_detail{ lod == 0 ? this->lod0_detail : this->lod0_detail / (2 * lod * lod) };
|
||||
size_t base_detail{ lod == 0 ? this->lod0_detail : this->lod0_detail / (2 * lod) };
|
||||
status.dirty = true;
|
||||
this->generator->push_task({ { position.x, position.z }, { this->size, this->size } }, status.mesh, base_detail > 1 ? base_detail : 1, callable_mp(this, &self_type::lod_generated).bind(lod));
|
||||
lod++;
|
||||
|
|
@ -45,23 +43,7 @@ void TerrainChunk::on_terrain_changed() {
|
|||
}
|
||||
|
||||
void TerrainChunk::lod_generated(size_t lod) {
|
||||
//if (this->collisions && lod <= this->collisions_lod && (lod == 0 || lod == (this->meshes.size() - 1))) {
|
||||
#if 0
|
||||
if (this->collisions && lod == this->meshes.size() - 1) {
|
||||
this->collisions->queue_free();
|
||||
this->collisions = nullptr;
|
||||
}
|
||||
if (!this->collisions) {
|
||||
this->set_mesh(this->meshes[lod].mesh);
|
||||
//static Ref<MeshConvexDecompositionSettings> settings{};
|
||||
if ((this->collisions = create_multiple_convex_collisions_node())) {
|
||||
add_child(this->collisions);
|
||||
}
|
||||
this->collisions_lod = lod;
|
||||
}
|
||||
#endif
|
||||
this->meshes.set(lod, { this->meshes[lod].mesh, false });
|
||||
process_lod();
|
||||
}
|
||||
|
||||
void TerrainChunk::process_lod() {
|
||||
|
|
@ -70,7 +52,7 @@ void TerrainChunk::process_lod() {
|
|||
Vector3 position{ get_global_position() };
|
||||
Vector3 camera{ get_viewport()->get_camera_3d()->get_global_position() };
|
||||
Vector3 diff{ (position - camera).abs() };
|
||||
float distance{ (diff.x > diff.z ? diff.z : diff.x) - this->size };
|
||||
float distance{ (diff.x < diff.z ? diff.z : diff.x) - this->size / 2.f };
|
||||
distance = distance > 0.f ? distance : 0.f;
|
||||
size_t lod{ size_t(Math::floor(distance / (this->lod_end_distance / this->meshes.size()))) };
|
||||
result = lod < this->meshes.size() ? lod : (this->meshes.size() - 1);
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ private:
|
|||
size_t collisions_lod{ 0 };
|
||||
Vector<MeshStatus> meshes{};
|
||||
int lod0_detail{ 200 };
|
||||
float lod_end_distance{ 1000 };
|
||||
float lod_end_distance{ 600 };
|
||||
float size{ 200 };
|
||||
TerrainMeshGenerator *generator{ nullptr };
|
||||
};
|
||||
|
|
|
|||
|
|
@ -31,19 +31,25 @@ void TerrainMeshGenerator::enter_tree() {
|
|||
}
|
||||
|
||||
void TerrainMeshGenerator::process() {
|
||||
if (this->input_lock.try_lock()) {
|
||||
set_process(!this->input_queue.is_empty());
|
||||
this->input_lock.unlock();
|
||||
}
|
||||
if (this->output_lock.try_lock()) {
|
||||
for (TerrainMeshTask &task : this->output_queue) {
|
||||
task.mesh->clear_surfaces();
|
||||
task.out_surface->commit(task.mesh);
|
||||
for (TerrainMeshTask &queued : this->input_queue) {
|
||||
if (queued.mesh == task.mesh) {
|
||||
goto exit_outer;
|
||||
}
|
||||
}
|
||||
task.callback.call();
|
||||
}
|
||||
exit_outer:
|
||||
this->output_queue.clear();
|
||||
this->output_lock.unlock();
|
||||
}
|
||||
if (this->input_lock.try_lock()) {
|
||||
set_process(!this->input_queue.is_empty());
|
||||
this->input_lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
void TerrainMeshGenerator::on_configuration_changed() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue