Skip to content

Commit f603f4b

Browse files
committed
First basic working version of pathfinding
1 parent 127d1e4 commit f603f4b

25 files changed

+1146
-296
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
target/
2+
coverage/
23
Cargo.lock

Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ version = "0.1.0"
44
edition = "2021"
55

66
[features]
7-
#bundled-recast = ["recast-sys/bundled"]
8-
default = ["detour", "recast"]
7+
default = ["detour_crowd", "recast"]
8+
99
detour = ["recast-sys/detour"]
10+
detour_crowd = ["detour", "recast-sys/detour_crowd"]
1011
recast = ["recast-sys/recast"]
1112

1213
[workspace]

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,11 @@ likely to happen when this crate becomes usable enough to build a minimal Bevy p
1313

1414
`recast-rs` contains two crates:
1515

16-
* `recast-sys`: low level FFI bindings to the Recast library.
16+
* `recast-sys`: low level FFI bindings to the Recast library. You will need a working C++14 compiler to compile the
17+
Recast code. There is no option to use system libraries yet, just the bundled one.
1718
* `recast`: higher level bindings.
19+
20+
## License
21+
22+
Recast-rs includes code from the recastnavigation project, provided under the Zlib license. Recast-rs itself is provided
23+
under either the MIT or Apache 2.0 license, at your option.

recast-sys/Cargo.toml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@ version = "0.1.0"
44
edition = "2021"
55

66
[features]
7-
default = ["recast", "detour"]
7+
default = ["recast", "detour", "detour_crowd"]
8+
89
detour = []
10+
detour_crowd = ["detour"]
911
recast = []
1012

11-
# Only support bundled builds for now
12-
#bundled = []
13-
1413
[dependencies]
1514
cxx = "1.0"
1615

1716
[build-dependencies]
18-
cxx-build = "1.0"
17+
cxx-build = "1.0"

recast-sys/build.rs

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,46 @@
11
fn main() {
22
let mut bridge = cxx_build::bridge("src/lib.rs");
3+
bridge.flag_if_supported("-std=c++14").shared_flag(true);
34

45
#[cfg(feature = "detour")]
56
{
7+
bridge
8+
.include("recastnavigation/Detour/Include")
9+
// TODO: not a fan of sweeping this under the rug, look into the warning
10+
.flag_if_supported("-Wno-class-memaccess")
11+
// Detour source files
12+
.file("recastnavigation/Detour/Source/DetourAlloc.cpp")
13+
.file("recastnavigation/Detour/Source/DetourCommon.cpp")
14+
.file("recastnavigation/Detour/Source/DetourNavMesh.cpp")
15+
.file("recastnavigation/Detour/Source/DetourNavMeshBuilder.cpp")
16+
.file("recastnavigation/Detour/Source/DetourNavMeshQuery.cpp")
17+
.file("recastnavigation/Detour/Source/DetourNode.cpp")
18+
// Our additional functions
19+
.file("src/detour.cpp");
20+
21+
#[cfg(feature = "detour_crowd")]
22+
{
23+
bridge
24+
.include("recastnavigation/DetourCrowd/Include")
25+
// Detour source files
26+
.file("recastnavigation/DetourCrowd/Source/DetourCrowd.cpp")
27+
.file("recastnavigation/DetourCrowd/Source/DetourLocalBoundary.cpp")
28+
.file("recastnavigation/DetourCrowd/Source/DetourObstacleAvoidance.cpp")
29+
.file("recastnavigation/DetourCrowd/Source/DetourPathCorridor.cpp")
30+
.file("recastnavigation/DetourCrowd/Source/DetourPathQueue.cpp")
31+
.file("recastnavigation/DetourCrowd/Source/DetourProximityGrid.cpp")
32+
// Our additional functions
33+
//.file("src/detour_crowd.cpp")
34+
;
35+
}
636
}
737
#[cfg(feature = "recast")]
838
{
939
bridge
1040
.include("recastnavigation/Recast/Include/")
41+
// Silences a comment related warning in recast
1142
.flag_if_supported("-Wno-comment")
43+
// Recast source files
1244
.file("recastnavigation/Recast/Source/Recast.cpp")
1345
.file("recastnavigation/Recast/Source/RecastAlloc.cpp")
1446
.file("recastnavigation/Recast/Source/RecastArea.cpp")
@@ -18,17 +50,10 @@ fn main() {
1850
.file("recastnavigation/Recast/Source/RecastMesh.cpp")
1951
.file("recastnavigation/Recast/Source/RecastMeshDetail.cpp")
2052
.file("recastnavigation/Recast/Source/RecastRasterization.cpp")
21-
.file("recastnavigation/Recast/Source/RecastRegion.cpp");
53+
.file("recastnavigation/Recast/Source/RecastRegion.cpp")
54+
// Our additional functions
55+
.file("src/recast.cpp");
2256
}
2357

24-
//#[cfg(not(feature = "bundled"))]
25-
//{
26-
//println!("cargo:rustc-link-lib=Recast");
27-
//}
28-
29-
bridge.file("src/recast.cpp")
30-
.flag_if_supported("-std=c++14")
31-
//.flag_if_supported("Wl,--no-allow-shlib-undefined")
32-
.shared_flag(true)
33-
.compile("recast-sys");
58+
bridge.compile("recast-sys");
3459
}

recast-sys/include/detour.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#pragma once
2+
3+
#include "rust/cxx.h"
4+
#include <memory>
5+
6+
#include "recast-sys/recastnavigation/Detour/Include/DetourNavMesh.h"
7+
#include "recast-sys/recastnavigation/Detour/Include/DetourNavMeshBuilder.h"
8+
#include "recast-sys/recastnavigation/Detour/Include/DetourNavMeshQuery.h"
9+
#include "recast-sys/recastnavigation/Detour/Include/DetourStatus.h"
10+
11+
struct NavMeshCreateParams;
12+
13+
std::unique_ptr<dtNavMesh> newDtNavMesh();
14+
std::unique_ptr<dtNavMeshQuery> newDtNavMeshQuery();
15+
std::unique_ptr<dtQueryFilter> newDtQueryFilter();
16+
17+
bool createNavMeshData(NavMeshCreateParams* params, std::uint8_t **outData, std::int32_t *outDataSize);

recast-sys/include/detour_crowd.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#pragma once
2+
3+
#include "rust/cxx.h"
4+
#include <memory>
5+
6+
#include "recast-sys/recastnavigation/DetourCrowd/Include/DetourPathCorridor.h"
7+
8+
struct NavMeshCreateParams;
9+
10+
std::unique_ptr<dtPathCorridor> newDtPathCorridor();

recast-sys/include/recast.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
#include "rust/cxx.h"
44
#include "recast-sys/recastnavigation/Recast/Include/Recast.h"
5-
#include <functional>
65
#include <memory>
76

87
std::unique_ptr<rcContext> newRcContext(bool diagnostics);
@@ -13,9 +12,17 @@ std::unique_ptr<rcPolyMesh> newRcPolyMesh();
1312
std::unique_ptr<rcPolyMeshDetail> newRcPolyMeshDetail();
1413

1514
const std::uint16_t* polyMeshGetVerts(rcPolyMesh const& poly_mesh);
15+
std::uint16_t* polyMeshGetVertsMut(rcPolyMesh & poly_mesh);
1616
const std::uint16_t* polyMeshGetPolys(rcPolyMesh const& poly_mesh);
17+
std::uint16_t* polyMeshGetPolysMut(rcPolyMesh& poly_mesh);
1718
const std::uint16_t* polyMeshGetRegions(rcPolyMesh const& poly_mesh);
19+
std::uint16_t* polyMeshGetRegionsMut(rcPolyMesh& poly_mesh);
20+
const std::uint16_t* polyMeshGetFlags(rcPolyMesh const& poly_mesh);
21+
std::uint16_t* polyMeshGetFlagsMut(rcPolyMesh& poly_mesh);
1822
const std::uint8_t* polyMeshGetAreas(rcPolyMesh const& poly_mesh);
23+
std::uint8_t* polyMeshGetAreasMut(rcPolyMesh& poly_mesh);
24+
25+
1926
std::int32_t polyMeshGetPolyCount(rcPolyMesh const& poly_mesh);
2027
std::int32_t polyMeshGetVertexCount(rcPolyMesh const& poly_mesh);
2128
std::int32_t polyMeshGetMaxVertexCountPerPoly(rcPolyMesh const& poly_mesh);

recast-sys/src/detour.cpp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#include "recast-sys/include/detour.h"
2+
3+
#include "recast-sys/src/lib.rs.h"
4+
5+
std::unique_ptr<dtNavMesh> newDtNavMesh() {
6+
return std::make_unique<dtNavMesh>();
7+
}
8+
9+
std::unique_ptr<dtNavMeshQuery> newDtNavMeshQuery() {
10+
return std::make_unique<dtNavMeshQuery>();
11+
}
12+
13+
std::unique_ptr<dtQueryFilter> newDtQueryFilter() {
14+
return std::make_unique<dtQueryFilter>();
15+
}
16+
17+
std::unique_ptr<dtPathCorridor> newDtPathCorridor() {
18+
return std::make_unique<dtPathCorridor>();
19+
}
20+
21+
bool createNavMeshData(NavMeshCreateParams* params, std::uint8_t **outData, std::int32_t *outDataSize) {
22+
auto dtParams = dtNavMeshCreateParams();
23+
dtParams.verts = params->vertices;
24+
dtParams.vertCount = params->num_vertices;
25+
dtParams.polys = params->polygons;
26+
dtParams.polyFlags = params->polygon_flags;
27+
dtParams.polyAreas = params->polygon_areas;
28+
dtParams.polyCount = params->num_polys;
29+
dtParams.nvp = params->max_vertices_per_poly;
30+
dtParams.detailMeshes = params->detail_meshes;
31+
dtParams.detailVerts = params->detail_vertices;
32+
dtParams.detailVertsCount = params->num_detail_vertices;
33+
dtParams.detailTris = params->detail_triangles;
34+
dtParams.detailTriCount = params->num_detail_triangles;
35+
dtParams.offMeshConVerts = params->off_mesh_conn_vertices;
36+
dtParams.offMeshConRad = params->off_mesh_conn_radii;
37+
dtParams.offMeshConFlags = params->off_mesh_conn_flags;
38+
dtParams.offMeshConAreas = params->off_mesh_conn_areas;
39+
dtParams.offMeshConDir = params->off_mesh_conn_dir;
40+
dtParams.offMeshConUserID = params->off_mesh_conn_ids;
41+
dtParams.offMeshConCount = params->off_mesh_conn_count;
42+
dtParams.userId = params->user_id;
43+
dtParams.tileX = params->tile_x;
44+
dtParams.tileY = params->tile_y;
45+
dtParams.tileLayer = params->tile_layer;
46+
std::copy(params->b_min.begin(), params->b_min.end(), dtParams.bmin);
47+
std::copy(params->b_max.begin(), params->b_max.end(), dtParams.bmax);
48+
dtParams.walkableHeight = params->walkable_height;
49+
dtParams.walkableRadius = params->walkable_radius;
50+
dtParams.walkableClimb = params->walkable_climb;
51+
dtParams.cs = params->cs;
52+
dtParams.ch = params->ch;
53+
dtParams.buildBvTree = params->build_bv_tree;
54+
55+
return dtCreateNavMeshData(&dtParams, outData, outDataSize);
56+
}

0 commit comments

Comments
 (0)