/gdx-recast

A bridge between libGDX and Recast4j

Primary LanguageJavaApache License 2.0Apache-2.0

image

gdx-recast

gdx-recast is a library for libGDX that provides a bridge between libGDX and the Recast/Detour pathfinding libraries. This is possible by using recast4j, a Java port of Recast/Detour.

GWT is supported by using a forked version of recast4j, gwt-recast which has been modified to work with GWT.

NOTE: This library is still in development. API changes may occur at any time.

Features

  • NavMesh generation (can use libGDX ModelInstances)
  • NavMesh saving / loading
  • Pathfinding
  • Detour Crowd (Experimental)
  • GWT support
  • Debug rendering for libGDX

Usage

Generating a NavMesh

NavMeshGenSettings settings = NavMeshGenSettings.Builder.SettingsBuilder()
        .useTiles(true)
        .tileSizeX(128)
        .tileSizeZ(128)
        .build();

// NavMeshGenerator provides multiple constructors
NavMeshGenerator navMeshGenerator = new NavMeshGenerator(modelInstance);
NavMeshData data = navMeshGenerator.build(settings); // Contains NavMesh

Saving / loading a generated NavMesh

// Saving
NavMeshIO.save(navMeshData.getNavMesh(), Gdx.files.internal("navmesh.nav"));

// Loading
NavMesh navMesh = NavMeshIO.load(Gdx.files.internal("navmesh.nav"));
NavMeshData navMeshData = new NavMeshData(navMesh);

Pathfinding

private Pathfinder pathfinder;
...
pathfinder = new Pathfinder(navMeshData);
        
Array<float[]> paths = new Array<>(); // This will be populated with the path
pathfinder.getPath(new Vector3(-0.99f, 15.24f, 11.98f), new Vector3(17.63f,-2.37f,-21.86f), paths);

Resources

Recast Navigation Google Group

Recast4j