setup foo

This commit is contained in:
Your Name 2024-06-04 15:46:31 +02:00
parent 2a8b530c98
commit 7e3bc89a16
7 changed files with 127 additions and 9 deletions

2
.gitignore vendored
View file

@ -1,2 +1,4 @@
.cache
compile_commands.json
build
cmake-build-debug

View file

@ -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)

29
src/RecastConfig.cpp Normal file
View file

@ -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);
}

74
src/RecastConfig.hpp Normal file
View file

@ -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; }
};
}

View file

@ -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);
}

View file

@ -1,6 +1,6 @@
#pragma once
#include <godot_cpp/classes/node3d.hpp>
#include "godot_cpp/classes/node3d.hpp"
namespace godot {
@ -20,3 +20,4 @@ namespace godot {
};
}

View file

@ -1,6 +1,7 @@
#include <godot_cpp/godot.hpp>
#include <godot_cpp/core/class_db.hpp>
#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<RecastNavMesh>();
godot::ClassDB::register_class<godot::RecastConfig>();
godot::ClassDB::register_class<godot::RecastNavMesh>();
}
void unregister_gameplay_types(godot::ModuleInitializationLevel p_level) {