Path finding that returns a collection of nodes

in my project I needed to implement path finding and I only needed a collection of nodes. The path finding in PandAI insists on moving the “character” and instantiating an AIWorld and other things that are completely useless to my project.

So I decided that I would make a class that is loosely coupled away from the PandAI classes, that would only need a navmesh, source and a destination and in would return a collection of nodes.

Note: It is not completely loosely coupled, since PathFindImpulsion.h uses “aiPathFinder.h” from PandAI.

I made a class called PathFindImpulsion.h and an “interface” called GetNodesToDestination.h.

The PathFindImpulsion class is heavily based on PathFind.h from PandAI, but it is without all of the things that I didn’t need.

The GetNodesToDestination class has one job, and that is to recieve a navmesh,source and destination, call functions from PathFindImpulsion.h and then returning a collection of LVecBase3 variables which are the nodes/coordinates from the path finding.

To use my classes I added them to “\panda3d-1.8.0\contrib\src\ai” directory in the source code and recompiled Panda3D and made an Installer. The Installer can be found here.

[size=150]Compiling the classes with Panda3d[/size]
In case you need to recompile the source code(if there is a newer version of Panda3d for instance).

Download the source files, add PathFindImpulsion.h/cxx and GetNodesToDestination.h/cxx into this directory “\panda3d[version-no]\contrib\src\ai”, go to your command-line program of choice, go to the directory ““\panda3d[version-no]” and use the command

./makepanda/makepanda.bat --everything --installer

This is of course if you are on Windows.

This will compile panda3d, parse the C++ classes through interrogate and make an installer. Note: That compiling the Panda3D source for the first time will take about an hour.

Here are the classes.

[size=150]Getting a Navmesh[/size]
The navmesh is created by the navmesh generator from PandAI

Here is a tutorial on how to make a navmesh
A few notes on things I encountered when using the navmesh generator:
Every vertices will become a node, so when making the plane make sure there are a lot of faces, the more faces you have, the more nodes you get. When making the cutout, you can only delete faces, anything else will result in an error. It is important that the coordinates of the two planes have not shifted away from each other and that there is no texture on the .egg file when creating the navmesh.

[size=150]How to call the path finding function[/size]

First import the pandai library like so

from import *

Then you can call the function like this to get path finding nodes.

self.[variableName] = GetNodesToDestination(LocationOfNavMeshFile)
self.[anotherVariable] = variableName.getNodes(source,destination)

Example of how to print the path finding nodes

self.test = GetNodesToDestination('NavMesh/navmesh.csv')
self.C = self.test.getNodes((-102.605,77.2619,0),(14.0408,-94.624,0))
for item in self.C:
   print item

Special thanks to rdb and zhao for their help here on the forums.

EDIT: Fixed the code a bit, so that it didn’t initiate the GetNodeToDestination class every time a path was calculated, which also prevents the navmesh file being open and read each time, now it is only been done once.

This is what pandAI was missing. Can we get this in the next stable p3d version?

I could really use this, has it made its way into a official release?