godot stuff

This commit is contained in:
Your Name 2024-06-07 16:11:04 +02:00
parent aacd8e92ad
commit 7cafc09390
3 changed files with 155 additions and 128 deletions

@ -1 +1 @@
Subproject commit 21d526e5e5b1e5d8b6be4db05a704c2c2e7837a9 Subproject commit a62f633cebee4b36356dc903d00670733cd28fb1

View file

@ -1,4 +1,5 @@
#include "RecastNavMesh.hpp" #include "RecastNavMesh.hpp"
#include <godot_cpp/classes/global_constants.hpp>
godot::RecastNavMesh::RecastNavMesh() { godot::RecastNavMesh::RecastNavMesh() {
} }
@ -44,6 +45,18 @@ void godot::RecastNavMesh::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_walkable_height"), &RecastNavMesh::get_walkable_height); ClassDB::bind_method(D_METHOD("get_walkable_height"), &RecastNavMesh::get_walkable_height);
ADD_PROPERTY(PropertyInfo(Variant::INT, "walkable_height"), "set_walkable_height", "get_walkable_height"); ADD_PROPERTY(PropertyInfo(Variant::INT, "walkable_height"), "set_walkable_height", "get_walkable_height");
ClassDB::bind_method(D_METHOD("set_filter_low_hanging_obstacles", "filter_low_hanging_obstacles"), &RecastNavMesh::set_filter_low_hanging_obstacles);
ClassDB::bind_method(D_METHOD("get_filter_low_hanging_obstacles"), &RecastNavMesh::get_filter_low_hanging_obstacles);
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "filter_low_hanging_obstacles"), "set_filter_low_hanging_obstacles", "get_filter_low_hanging_obstacles");
ClassDB::bind_method(D_METHOD("set_filter_ledge_spans", "filter_ledge_spans"), &RecastNavMesh::set_filter_ledge_spans);
ClassDB::bind_method(D_METHOD("get_filter_ledge_spans"), &RecastNavMesh::get_filter_ledge_spans);
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "filter_ledge_spans"), "set_filter_ledge_spans", "get_filter_ledge_spans");
ClassDB::bind_method(D_METHOD("set_filter_walkable_low_height_spans", "filter_walkable_low_height_spans"), &RecastNavMesh::set_filter_walkable_low_height_spans);
ClassDB::bind_method(D_METHOD("get_filter_walkable_low_height_spans"), &RecastNavMesh::get_filter_walkable_low_height_spans);
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "filter_walkable_low_height_spans"), "set_filter_walkable_low_height_spans", "get_filter_walkable_low_height_spans");
ClassDB::bind_method(D_METHOD("set_walkable_climb", "walkable_climb"), &RecastNavMesh::set_walkable_climb); ClassDB::bind_method(D_METHOD("set_walkable_climb", "walkable_climb"), &RecastNavMesh::set_walkable_climb);
ClassDB::bind_method(D_METHOD("get_walkable_climb"), &RecastNavMesh::get_walkable_climb); ClassDB::bind_method(D_METHOD("get_walkable_climb"), &RecastNavMesh::get_walkable_climb);
ADD_PROPERTY(PropertyInfo(Variant::INT, "walkable_climb"), "set_walkable_climb", "get_walkable_climb"); ADD_PROPERTY(PropertyInfo(Variant::INT, "walkable_climb"), "set_walkable_climb", "get_walkable_climb");

View file

@ -7,134 +7,148 @@
namespace godot { namespace godot {
enum RecastPartitionType { enum RecastPartitionType {
WATERSHED = 0, WATERSHED = 0,
MONOTONE, MONOTONE,
LAYERS, LAYERS,
PARTITION_TYPE_COUNT PARTITION_TYPE_COUNT
}; };
class RecastNavMesh : public Node3D { class RecastNavMesh : public Node3D {
GDCLASS(RecastNavMesh, Node3D) GDCLASS(RecastNavMesh, Node3D)
private: private:
bool m_calculated = false; bool m_calculated = false;
rcConfig config; bool filter_low_hanging_obstacles = false;
RecastPartitionType partition_type = WATERSHED; bool filter_ledge_spans = false;
rcHeightfield* m_heightfield = NULL; bool filter_walkable_low_height_spans = false;
protected:
static void _bind_methods();
public:
RecastNavMesh();
~RecastNavMesh();
// config
/// The width of the field along the x-axis. [Limit: >= 0] [Units: vx] rcConfig config;
int get_width() { return config.width; } RecastPartitionType partition_type = WATERSHED;
/// The height of the field along the z-axis. [Limit: >= 0] [Units: vx]
int get_height() { return config.height; } rcHeightfield* m_heightfield = NULL;
/// The width/height size of tile's on the xz-plane. [Limit: >= 0] [Units: vx] rcCompactHeightfield* m_compact_heightfield = NULL;
void set_tile_size(float tile_size) { config.tileSize = tile_size; } protected:
float get_tile_size() { return config.tileSize; } static void _bind_methods();
/// The size of the non-navigable border around the heightfield. [Limit: >=0] [Units: vx] public:
void set_border_size(int border_size) { config.borderSize = border_size; } RecastNavMesh();
int get_border_size() { return config.borderSize; } ~RecastNavMesh();
/// The xz-plane cell size to use for fields. [Limit: > 0] [Units: wu] // config
void set_cs(float cs) {
config.cs = cs; /// The width of the field along the x-axis. [Limit: >= 0] [Units: vx]
// update width & height of the grid int get_width() { return config.width; }
rcCalcGridSize(config.bmin, config.bmax, config.cs, &config.width, &config.height); /// The height of the field along the z-axis. [Limit: >= 0] [Units: vx]
} int get_height() { return config.height; }
float get_cs() { return config.cs; } /// The width/height size of tile's on the xz-plane. [Limit: >= 0] [Units: vx]
/// The y-axis cell size to use for fields. [Limit: > 0] [Units: wu] void set_tile_size(float tile_size) { config.tileSize = tile_size; }
void set_ch(float ch) { config.ch = ch; } float get_tile_size() { return config.tileSize; }
float get_ch() { return config.ch; } /// The size of the non-navigable border around the heightfield. [Limit: >=0] [Units: vx]
/// The minimum bounds of the field's AABB. [(x, y, z)] [Units: wu] void set_border_size(int border_size) { config.borderSize = border_size; }
void set_bmin(const Vector3& bmin) { int get_border_size() { return config.borderSize; }
// Vector3 can be float or double precision, but Recast expects float /// The xz-plane cell size to use for fields. [Limit: > 0] [Units: wu]
config.bmin[0] = bmin.x; void set_cs(float cs) {
config.bmin[1] = bmin.y; config.cs = cs;
config.bmin[2] = bmin.z; // update width & height of the grid
// update width & height of the grid rcCalcGridSize(config.bmin, config.bmax, config.cs, &config.width, &config.height);
rcCalcGridSize(config.bmin, config.bmax, config.cs, &config.width, &config.height); }
} float get_cs() { return config.cs; }
Vector3 get_bmin() { /// The y-axis cell size to use for fields. [Limit: > 0] [Units: wu]
return Vector3(config.bmin[0], config.bmin[1], config.bmin[2]); void set_ch(float ch) { config.ch = ch; }
} float get_ch() { return config.ch; }
/// The maximum bounds of the field's AABB. [(x, y, z)] [Units: wu] /// The minimum bounds of the field's AABB. [(x, y, z)] [Units: wu]
void set_bmax(const Vector3& bmax) { void set_bmin(const Vector3& bmin) {
config.bmax[0] = bmax.x; // Vector3 can be float or double precision, but Recast expects float
config.bmax[1] = bmax.y; config.bmin[0] = bmin.x;
config.bmax[2] = bmax.z; config.bmin[1] = bmin.y;
// update width & height of the grid config.bmin[2] = bmin.z;
rcCalcGridSize(config.bmin, config.bmax, config.cs, &config.width, &config.height); // update width & height of the grid
} rcCalcGridSize(config.bmin, config.bmax, config.cs, &config.width, &config.height);
Vector3 get_bmax() { }
return Vector3(config.bmax[0], config.bmax[1], config.bmax[2]); Vector3 get_bmin() {
} return Vector3(config.bmin[0], config.bmin[1], config.bmin[2]);
/// The maximum slope that is considered walkable. [Limits: 0 <= value < 90] [Units: Degrees] }
void set_walkable_slope_angle(float walkable_slope_angle) { config.walkableSlopeAngle = walkable_slope_angle; } /// The maximum bounds of the field's AABB. [(x, y, z)] [Units: wu]
float get_walkable_slope_angle() { return config.walkableSlopeAngle; } void set_bmax(const Vector3& bmax) {
/// Minimum floor to 'ceiling' height that will still allow the floor area to config.bmax[0] = bmax.x;
/// be considered walkable. [Limit: >= 3] [Units: vx] config.bmax[1] = bmax.y;
void set_walkable_height(float walkable_height) { config.walkableHeight = walkable_height; } config.bmax[2] = bmax.z;
float get_walkable_height() { return config.walkableHeight; } // update width & height of the grid
/// Maximum ledge height that is considered to still be traversable. [Limit: >=0] [Units: vx] rcCalcGridSize(config.bmin, config.bmax, config.cs, &config.width, &config.height);
void set_walkable_climb(float walkable_climb) { config.walkableClimb = walkable_climb; } }
float get_walkable_climb() { return config.walkableClimb; } Vector3 get_bmax() {
/// The distance to erode/shrink the walkable area of the heightfield away from return Vector3(config.bmax[0], config.bmax[1], config.bmax[2]);
/// obstructions. [Limit: >=0] [Units: vx] }
void set_walkable_radius(float walkable_radius) { config.walkableRadius = walkable_radius; }
float get_walkable_radius() { return config.walkableRadius; } void set_filter_low_hanging_obstacles(bool filter_low_hanging_obstacles) { this->filter_low_hanging_obstacles = filter_low_hanging_obstacles; }
/// The maximum allowed length for contour edges along the border of the mesh. [Limit: >=0] [Units: vx] bool get_filter_low_hanging_obstacles() { return filter_low_hanging_obstacles; }
void set_max_edge_len(int max_edge_len) { config.maxEdgeLen = max_edge_len; } void set_filter_ledge_spans(bool filter_ledge_spans) { this->filter_ledge_spans = filter_ledge_spans; }
int get_max_edge_len() { return config.maxEdgeLen; } bool get_filter_ledge_spans() { return filter_ledge_spans; }
/// The maximum distance a simplified contour's border edges should deviate void set_filter_walkable_low_height_spans(bool filter_walkable_low_height_spans) { this->filter_walkable_low_height_spans = filter_walkable_low_height_spans; }
/// the original raw contour. [Limit: >=0] [Units: vx] bool get_filter_walkable_low_height_spans() { return filter_walkable_low_height_spans; }
void set_max_simplification_error(float max_simplification_error) { config.maxSimplificationError = max_simplification_error; }
float get_max_simplification_error() { return config.maxSimplificationError; } /// The maximum slope that is considered walkable. [Limits: 0 <= value < 90] [Units: Degrees]
/// The minimum number of cells allowed to form isolated island areas. [Limit: >=0] [Units: vx] void set_walkable_slope_angle(float walkable_slope_angle) { config.walkableSlopeAngle = walkable_slope_angle; }
void set_min_region_area(int min_region_area) { config.minRegionArea = min_region_area; } float get_walkable_slope_angle() { return config.walkableSlopeAngle; }
int get_min_region_area() { return config.minRegionArea; } /// Minimum floor to 'ceiling' height that will still allow the floor area to
/// Any regions with a span count smaller than this value will, if possible, /// be considered walkable. [Limit: >= 3] [Units: vx]
/// be merged with larger regions. [Limit: >=0] [Units: vx] void set_walkable_height(float walkable_height) { config.walkableHeight = walkable_height; }
void set_merge_region_area(int merge_region_area) { config.mergeRegionArea = merge_region_area; } float get_walkable_height() { return config.walkableHeight; }
int get_merge_region_area() { return config.mergeRegionArea; } /// Maximum ledge height that is considered to still be traversable. [Limit: >=0] [Units: vx]
/// The maximum number of vertices allowed for polygons generated during the void set_walkable_climb(float walkable_climb) { config.walkableClimb = walkable_climb; }
/// contour to polygon conversion process. [Limit: >= 3] float get_walkable_climb() { return config.walkableClimb; }
void set_max_verts_per_poly(int max_verts_per_poly) { config.maxVertsPerPoly = max_verts_per_poly; } /// The distance to erode/shrink the walkable area of the heightfield away from
int get_max_verts_per_poly() { return config.maxVertsPerPoly; } /// obstructions. [Limit: >=0] [Units: vx]
/// Sets the sampling distance to use when generating the detail mesh. void set_walkable_radius(float walkable_radius) { config.walkableRadius = walkable_radius; }
/// (For height detail only.) [Limits: 0 or >= 0.9] [Units: wu] float get_walkable_radius() { return config.walkableRadius; }
void set_detail_sample_dist(float detail_sample_dist) { config.detailSampleDist = detail_sample_dist; } /// The maximum allowed length for contour edges along the border of the mesh. [Limit: >=0] [Units: vx]
float get_detail_sample_dist() { return config.detailSampleDist; } void set_max_edge_len(int max_edge_len) { config.maxEdgeLen = max_edge_len; }
/// The maximum distance the detail mesh surface should deviate from heightfield int get_max_edge_len() { return config.maxEdgeLen; }
/// data. (For height detail only.) [Limit: >=0] [Units: wu] /// The maximum distance a simplified contour's border edges should deviate
void set_detail_sample_max_error(float detail_sample_max_error) { config.detailSampleMaxError = detail_sample_max_error; } /// the original raw contour. [Limit: >=0] [Units: vx]
float get_detail_sample_max_error() { return config.detailSampleMaxError; } void set_max_simplification_error(float max_simplification_error) { config.maxSimplificationError = max_simplification_error; }
/// The partition type to use for the heightfield. float get_max_simplification_error() { return config.maxSimplificationError; }
/// /// The minimum number of cells allowed to form isolated island areas. [Limit: >=0] [Units: vx]
/// Allowed values are: void set_min_region_area(int min_region_area) { config.minRegionArea = min_region_area; }
/// - WATERSHED int get_min_region_area() { return config.minRegionArea; }
/// - MONOTONE /// Any regions with a span count smaller than this value will, if possible,
/// - LAYERS /// be merged with larger regions. [Limit: >=0] [Units: vx]
/// void set_merge_region_area(int merge_region_area) { config.mergeRegionArea = merge_region_area; }
/// Any other value will lead to no change in the partition type. int get_merge_region_area() { return config.mergeRegionArea; }
void set_partition_type(int partition_type) { /// The maximum number of vertices allowed for polygons generated during the
if((partition_type >= 0) && (partition_type < PARTITION_TYPE_COUNT)) { /// contour to polygon conversion process. [Limit: >= 3]
this->partition_type = (RecastPartitionType)partition_type; void set_max_verts_per_poly(int max_verts_per_poly) { config.maxVertsPerPoly = max_verts_per_poly; }
} int get_max_verts_per_poly() { return config.maxVertsPerPoly; }
} /// Sets the sampling distance to use when generating the detail mesh.
int get_partition_type() { /// (For height detail only.) [Limits: 0 or >= 0.9] [Units: wu]
return (int)partition_type; void set_detail_sample_dist(float detail_sample_dist) { config.detailSampleDist = detail_sample_dist; }
} float get_detail_sample_dist() { return config.detailSampleDist; }
/// The maximum distance the detail mesh surface should deviate from heightfield
// Recast /// data. (For height detail only.) [Limit: >=0] [Units: wu]
bool init(); void set_detail_sample_max_error(float detail_sample_max_error) { config.detailSampleMaxError = detail_sample_max_error; }
void cleanup(); float get_detail_sample_max_error() { return config.detailSampleMaxError; }
void clear_vertices(); /// The partition type to use for the heightfield.
void add_vertices(PackedByteArray vertices, unsigned char area_id); ///
bool recalculate_navmesh(); /// Allowed values are:
bool is_calculated() { return m_calculated; } /// - WATERSHED
}; /// - MONOTONE
/// - LAYERS
///
/// Any other value will lead to no change in the partition type.
void set_partition_type(int partition_type) {
if((partition_type >= 0) && (partition_type < PARTITION_TYPE_COUNT)) {
this->partition_type = (RecastPartitionType)partition_type;
}
}
int get_partition_type() {
return (int)partition_type;
}
public:
// Recast
bool init();
void cleanup();
void clear_vertices();
void add_vertices(PackedByteArray vertices, unsigned char area_id);
bool recalculate_navmesh();
bool is_calculated() { return m_calculated; }
};
} }