Java Port of Recast and Detour navigation mesh toolset.
Recast is state of the art navigation mesh construction toolset for games.
Recast is...
- 🤖 Automatic - throw any level geometry at it and you will get a robust navmesh out
- 🏎️ Fast - swift turnaround times for level designers
- 🧘 Flexible - easily customize the navmesh generation and runtime navigation systems to suit your specific game's needs.
Recast constructs a navmesh through a multi-step rasterization process:
- First Recast voxelizes the input triangle mesh by rasterizing the triangles into a multi-layer heightfield.
- Voxels in areas where the character would not be able to move are removed by applying simple voxel data filters.
- The walkable areas described by the voxel grid are then divided into sets of 2D polygonal regions.
- The navigation polygons are generated by triangulating and stiching together the generated 2d polygonal regions.
Recast is accompanied by Detour, a path-finding and spatial reasoning toolkit. You can use any navigation mesh with Detour, but of course the data generated with Recast fits perfectly.
Detour offers a simple static navmesh data representation which is suitable for many simple cases. It also provides a tiled navigation mesh representation, which allows you to stream of navigation data in and out as the player progresses through the world and regenerate sections of the navmesh data as the world changes.
More information about Recast and Detour
The API is kept as close to https://github.com/recastnavigation/recastnavigation as possible so most of the information and hints apply to recast4j too. You can find a lot of examples in tests e.g.
- building a nav mesh from obj files: https://github.com/recast4j/recast4j/blob/master/detour/src/test/java/org/recast4j/detour/RecastTestMeshBuilder.java
- finding a path: https://github.com/recast4j/recast4j/blob/master/detour/src/test/java/org/recast4j/detour/FindPathTest.java#L94
- persisting a nav mesh: https://github.com/recast4j/recast4j/blob/master/detour/src/test/java/org/recast4j/detour/io/MeshSetReaderWriterTest.java
- dynamic nav mesh: https://github.com/recast4j/recast4j/blob/master/detour-dynamic/src/test/java/org/recast4j/dynamic/DynamicNavMeshTest.java
- out-of-the-box support for multi-threaded builds
- support for rasterizing filled volumes: sphere, capsule and box
- finding random points constrained by a cricle
- more compact file format due to reduced data structures and better compression with LZ4
- simple tool to import navmeshes created with A* Pathfinding Project
- robust support for dynamic nav meshes combining pre-built voxels with dynamic objects which can be freely added and removed
All the modules can be built with a single gradle command:
./gradlew clean build shadow
Once the build is completed, the recast-demo application can be run as follows:
java -jar ./recast-demo/build/libs/recast-demo-1.5.8-SNAPSHOT-all.jar
Recast4j releases are available in Maven Central Repository. Maven:
<dependency>
<groupId>org.recast4j</groupId>
<artifactId>recast</artifactId>
<version>1.5.7</version>
</dependency>
<dependency>
<groupId>org.recast4j</groupId>
<artifactId>detour</artifactId>
<version>1.5.7</version>
</dependency>
<dependency>
<groupId>org.recast4j</groupId>
<artifactId>detour-crowd</artifactId>
<version>1.5.7</version>
</dependency>
<dependency>
<groupId>org.recast4j</groupId>
<artifactId>detour-tile-cache</artifactId>
<version>1.5.7</version>
</dependency>
<dependency>
<groupId>org.recast4j</groupId>
<artifactId>detour-extras</artifactId>
<version>1.5.7</version>
</dependency>
<dependency>
<groupId>org.recast4j</groupId>
<artifactId>detour-dynamic</artifactId>
<version>1.5.7</version>
</dependency>
Gradle:
implementation 'org.recast4j:recast:1.5.7'
implementation 'org.recast4j:detour:1.5.7'
implementation 'org.recast4j:detour-crowd:1.5.7'
implementation 'org.recast4j:detour-tile-cache:1.5.7'
implementation 'org.recast4j:detour-extras:1.5.7'
implementation 'org.recast4j:detour-dynamic:1.5.7'
Recast & Detour is licensed under ZLib license, see License.txt for more information.