authority/modules/terrain/terrain_chunk.h
Sara da0419bc13 fix: no gaps in terrain collision time/space
Terrain collision is generated before the first _process

Terrain collision is generated from and to the edges of chunks with no
gaps inbetween
2026-03-09 11:28:17 +01:00

49 lines
1.1 KiB
C++

#pragma once
#include "core/math/rect2.h"
#include "macros.h"
#include "scene/3d/mesh_instance_3d.h"
#include "scene/3d/physics/collision_shape_3d.h"
#include "scene/3d/physics/static_body_3d.h"
#include "scene/resources/3d/height_map_shape_3d.h"
#include "scene/resources/mesh.h"
#include "scene/resources/surface_tool.h"
class Terrain;
class TerrainChunkMesh : public MeshInstance3D {
GDCLASS(TerrainChunkMesh, MeshInstance3D);
static void _bind_methods();
void ready();
void generate_vertices();
void generate_faces();
protected:
void _notification(int what);
public:
void apply_new_mesh();
void update_mesh();
size_t points_per_side() const;
int heightmap_side_length() const;
private:
Mutex lock{};
Vector3 position_buffer{};
Ref<SurfaceTool> surface{};
Ref<ArrayMesh> new_mesh{};
Terrain *terrain{ nullptr };
size_t detail{ 1 };
size_t size{ 1 };
Rect2 bounds{};
Ref<HeightMapShape3D> shape{};
StaticBody3D *body{ nullptr };
CollisionShape3D *collider{ nullptr };
Vector<real_t> heightmap{};
public:
GET_SET_FNS(Rect2, bounds);
GET_SET_FNS(Terrain *, terrain);
GET_SET_FNS(size_t, detail);
GET_SET_FNS(size_t, size);
};