From 7e3bc89a16b8504a7744135a412e485f92460e64 Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 4 Jun 2024 15:46:31 +0200 Subject: [PATCH] setup foo --- .gitignore | 2 ++ CMakeLists.txt | 13 ++++++-- src/RecastConfig.cpp | 29 +++++++++++++++++ src/RecastConfig.hpp | 74 +++++++++++++++++++++++++++++++++++++++++++ src/RecastNavMesh.cpp | 11 ++++--- src/RecastNavMesh.hpp | 3 +- src/registration.cpp | 4 ++- 7 files changed, 127 insertions(+), 9 deletions(-) create mode 100644 src/RecastConfig.cpp create mode 100644 src/RecastConfig.hpp diff --git a/.gitignore b/.gitignore index 6be3b8f..2b2a360 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ +.cache +compile_commands.json build cmake-build-debug diff --git a/CMakeLists.txt b/CMakeLists.txt index 519b12f..3ce6919 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,9 +5,16 @@ set(CMAKE_CXX_STANDARD 23) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_POSITION_INDEPENDENT_CODE ON) -add_subdirectory(godot-cpp) +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) -add_library(godot-recast-navigation SHARED src/registration.cpp) +add_subdirectory(godot-cpp) +add_subdirectory(recastnavigation) + +add_library(godot-recast-navigation SHARED +src/registration.cpp +src/RecastConfig.cpp +src/RecastNavMesh.cpp +) target_include_directories(godot-recast-navigation PRIVATE src/) -target_link_libraries(godot-recast-navigation PUBLIC godot::cpp) +target_link_libraries(godot-recast-navigation PUBLIC godot::cpp Recast) diff --git a/src/RecastConfig.cpp b/src/RecastConfig.cpp new file mode 100644 index 0000000..8a76517 --- /dev/null +++ b/src/RecastConfig.cpp @@ -0,0 +1,29 @@ +#include "RecastConfig.hpp" + +godot::RecastConfig::RecastConfig() { +} + +godot::RecastConfig::~RecastConfig() { +} + +void godot::RecastConfig::_bind_methods() { + ClassDB::bind_method(D_METHOD("set_width", "width"), &RecastConfig::set_width); + ClassDB::bind_method(D_METHOD("set_height", "height"), &RecastConfig::set_height); + ClassDB::bind_method(D_METHOD("set_tile_size", "tile_size"), &RecastConfig::set_tile_size); + ClassDB::bind_method(D_METHOD("set_border_size", "border_size"), &RecastConfig::set_border_size); + ClassDB::bind_method(D_METHOD("set_cs", "cs"), &RecastConfig::set_cs); + ClassDB::bind_method(D_METHOD("set_ch", "ch"), &RecastConfig::set_ch); + ClassDB::bind_method(D_METHOD("set_bmin", "bmin"), &RecastConfig::set_bmin); + ClassDB::bind_method(D_METHOD("set_bmax", "bmax"), &RecastConfig::set_bmax); + ClassDB::bind_method(D_METHOD("set_walkable_slope_angle", "walkable_slope_angle"), &RecastConfig::set_walkable_slope_angle); + ClassDB::bind_method(D_METHOD("set_walkable_height", "walkable_height"), &RecastConfig::set_walkable_height); + ClassDB::bind_method(D_METHOD("set_walkable_climb", "walkable_climb"), &RecastConfig::set_walkable_climb); + ClassDB::bind_method(D_METHOD("set_walkable_radius", "walkable_radius"), &RecastConfig::set_walkable_radius); + ClassDB::bind_method(D_METHOD("set_max_edge_len", "max_edge_len"), &RecastConfig::set_max_edge_len); + ClassDB::bind_method(D_METHOD("set_max_simplification_error", "max_simplification_error"), &RecastConfig::set_max_simplification_error); + ClassDB::bind_method(D_METHOD("set_min_region_area", "min_region_area"), &RecastConfig::set_min_region_area); + ClassDB::bind_method(D_METHOD("set_merge_region_area", "merge_region_area"), &RecastConfig::set_merge_region_area); + ClassDB::bind_method(D_METHOD("set_max_verts_per_poly", "max_verts_per_poly"), &RecastConfig::set_max_verts_per_poly); + ClassDB::bind_method(D_METHOD("set_detail_sample_dist", "detail_sample_dist"), &RecastConfig::set_detail_sample_dist); + ClassDB::bind_method(D_METHOD("set_detail_sample_max_error", "detail_sample_max_error"), &RecastConfig::set_detail_sample_max_error); +} diff --git a/src/RecastConfig.hpp b/src/RecastConfig.hpp new file mode 100644 index 0000000..4dbca66 --- /dev/null +++ b/src/RecastConfig.hpp @@ -0,0 +1,74 @@ +#pragma once + +#include "Recast.h" + +#include "godot_cpp/classes/object.hpp" +#include "godot_cpp/classes/node3d.hpp" + +namespace godot { +struct RecastConfig : public Object { + GDCLASS(RecastConfig, Object) +private: + rcConfig config; +protected: + static void _bind_methods(); +public: + RecastConfig(); + ~RecastConfig(); + rcConfig get_config() { return config; } + /// The width of the field along the x-axis. [Limit: >= 0] [Units: vx] + void set_width(int width) { config.width = width; } + /// The height of the field along the z-axis. [Limit: >= 0] [Units: vx] + void set_height(int height) { config.height = height; } + /// The width/height size of tile's on the xz-plane. [Limit: >= 0] [Units: vx] + void set_tile_size(float tile_size) { config.tileSize = tile_size; } + /// The size of the non-navigable border around the heightfield. [Limit: >=0] [Units: vx] + void set_border_size(int border_size) { config.borderSize = border_size; } + /// The xz-plane cell size to use for fields. [Limit: > 0] [Units: wu] + void set_cs(float cs) { config.cs = cs; } + /// The y-axis cell size to use for fields. [Limit: > 0] [Units: wu] + void set_ch(float ch) { config.ch = ch; } + /// The minimum bounds of the field's AABB. [(x, y, z)] [Units: wu] + void set_bmin(const Vector3& bmin) { + // Vector3 can be float or double precision, but Recast expects float + config.bmin[0] = bmin.x; + config.bmin[1] = bmin.y; + config.bmin[2] = bmin.z; + } + /// The maximum bounds of the field's AABB. [(x, y, z)] [Units: wu] + void set_bmax(const Vector3& bmax) { + config.bmax[0] = bmax.x; + config.bmax[1] = bmax.y; + config.bmax[2] = bmax.z; + } + /// 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; } + /// Minimum floor to 'ceiling' height that will still allow the floor area to + /// be considered walkable. [Limit: >= 3] [Units: vx] + void set_walkable_height(float walkable_height) { config.walkableHeight = walkable_height; } + /// Maximum ledge height that is considered to still be traversable. [Limit: >=0] [Units: vx] + void set_walkable_climb(float walkable_climb) { config.walkableClimb = walkable_climb; } + /// The distance to erode/shrink the walkable area of the heightfield away from + /// obstructions. [Limit: >=0] [Units: vx] + void set_walkable_radius(float walkable_radius) { config.walkableRadius = walkable_radius; } + /// The maximum allowed length for contour edges along the border of the mesh. [Limit: >=0] [Units: vx] + void set_max_edge_len(int max_edge_len) { config.maxEdgeLen = max_edge_len; } + /// The maximum distance a simplified contour's border edges should deviate + /// the original raw contour. [Limit: >=0] [Units: vx] + void set_max_simplification_error(float max_simplification_error) { config.maxSimplificationError = max_simplification_error; } + /// The minimum number of cells allowed to form isolated island areas. [Limit: >=0] [Units: vx] + void set_min_region_area(int min_region_area) { config.minRegionArea = min_region_area; } + /// Any regions with a span count smaller than this value will, if possible, + /// be merged with larger regions. [Limit: >=0] [Units: vx] + void set_merge_region_area(int merge_region_area) { config.mergeRegionArea = merge_region_area; } + /// The maximum number of vertices allowed for polygons generated during the + /// contour to polygon conversion process. [Limit: >= 3] + void set_max_verts_per_poly(int max_verts_per_poly) { config.maxVertsPerPoly = max_verts_per_poly; } + /// Sets the sampling distance to use when generating the detail mesh. + /// (For height detail only.) [Limits: 0 or >= 0.9] [Units: wu] + void set_detail_sample_dist(float detail_sample_dist) { config.detailSampleDist = detail_sample_dist; } + /// The maximum distance the detail mesh surface should deviate from heightfield + /// data. (For height detail only.) [Limit: >=0] [Units: wu] + void set_detail_sample_max_error(float detail_sample_max_error) { config.detailSampleMaxError = detail_sample_max_error; } +}; +} diff --git a/src/RecastNavMesh.cpp b/src/RecastNavMesh.cpp index a0fd4a9..7a12ebc 100644 --- a/src/RecastNavMesh.cpp +++ b/src/RecastNavMesh.cpp @@ -1,15 +1,18 @@ #include "RecastNavMesh.hpp" -RecastNavMesh::RecastNavMesh() { +godot::RecastNavMesh::RecastNavMesh() { } -RecastNavMesh::~RecastNavMesh() { +godot::RecastNavMesh::~RecastNavMesh() { } -void RecastNavMesh::_bind_methods() { - +void godot::RecastNavMesh::_bind_methods() { + ClassDB::bind_method(D_METHOD("clear_vertices"), &RecastNavMesh::clear_vertices); + ClassDB::bind_method(D_METHOD("add_vertices", "vertices"), &RecastNavMesh::add_vertices); + ClassDB::bind_method(D_METHOD("recalculate_navmesh"), &RecastNavMesh::recalculate_navmesh); + ClassDB::bind_method(D_METHOD("is_calculated"), &RecastNavMesh::is_calculated); } diff --git a/src/RecastNavMesh.hpp b/src/RecastNavMesh.hpp index 1de2f42..41ab166 100644 --- a/src/RecastNavMesh.hpp +++ b/src/RecastNavMesh.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include "godot_cpp/classes/node3d.hpp" namespace godot { @@ -20,3 +20,4 @@ namespace godot { }; } + diff --git a/src/registration.cpp b/src/registration.cpp index 66fdc14..15aede6 100644 --- a/src/registration.cpp +++ b/src/registration.cpp @@ -1,6 +1,7 @@ #include #include +#include "RecastConfig.hpp" #include "RecastNavMesh.hpp" void register_gameplay_types(godot::ModuleInitializationLevel p_level) { @@ -8,7 +9,8 @@ void register_gameplay_types(godot::ModuleInitializationLevel p_level) { return; } - ClassDB::register_class(); + godot::ClassDB::register_class(); + godot::ClassDB::register_class(); } void unregister_gameplay_types(godot::ModuleInitializationLevel p_level) {