How can a nav mesh be generated using code?. I would like to load some “.scene” and generate it nav mesh on runtime.
I think I have it (thanks to MonkeyZone):
public Geometry createNavMesh(Node node) {
Mesh mesh = new Mesh();
NavMesh navMesh = new NavMesh();
NavMeshGenerator generator = new NavMeshGenerator();
generator.setCellHeight(1f);
GeometryBatchFactory.mergeGeometries(findGeometries(node, new LinkedList<Geometry>()), mesh);
Mesh optiMesh = generator.optimize(mesh);
navMesh.loadFromMesh(optiMesh);
Geometry navGeom = new Geometry("NavMesh");
navGeom.setMesh(optiMesh);
Material green = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
green.setColor("Color", ColorRGBA.Green);
green.getAdditionalRenderState().setWireframe(true);
navGeom.setMaterial(green);
return navGeom;
}