Recently, I took it upon myself to reexpose the built-in PandAI (panda3d.ai) artificial intelligence system, now allowing for A* pathfinding over terrain, stairs, and arbitrary trimeshes. Visual examples can be found below. The full source repository is available here: https://github.com/rayanalysis/pandai-samples/
This work has involved writing a new navmesh generation routine, centered around the creation of:
A PandAI navmesh initialization layer and
(optional) a collision mesh for the built-in collision system from Blender or another loaded model which can interoperate with the navmesh initialization and the built-in collision system at the same time.
The new navmesh generation routine has been kept very minimal, primarily taking place in the EggPrimitiveCreation.py set of definitions. Fundamentally, this new routine allows a user of IE Blender 4.1 to directly export a level mesh to .glb and have it work immediately with PandAI, no converters or special flags necessary. The source provided with these new pandai-samples takes your input model (which may be .glb, gltf, or something else) and saves it to .bam right away, extracting by default “Plane.001” as the target geom (which is the Blender layer name).
The technical complexity of the 2D A* pathfinder, the navmesh initialization routine, the trimesh generator for the built-in collision system, and the various multi-character possibilities inherent with PandAI makes this a somewhat advanced use case. I’d be happy to field questions that may come up as more people make use of panda3d.ai and these new character AI sample programs.
I am open to PRs, feature requests, and as mentioned technical questions regarding how these sample programs work. I’d like to get at least one multi-Actor behavioral sample program completed as a next step.
Brief example gifs below from the sample programs:
hii @Simulan , how did you generate the navmeshes for the map ? i have 4 .glb 3d map models and i would like to generate the navmeshes for them and use it with pandai in my FPS game.
There are two main navmesh generation systems working here – calls to EggPrimitiveCreation.py like so:
primitive_data_1 = EggPrimitiveCreation.makeSquaresEVPXZ(30, 30, 10, "Full",0)
primitive_data_2 = EggPrimitiveCreation.makeSquaresEVPXZ(30, 30, 10, "Coll",0)
# primitive_data_2 = EggPrimitiveCreation.makeSquaresEVPXZSparse(30, 30, 10, "Coll",0)
primitive_data_1.writeEgg(Filename(prim_1_name + ".egg"))
primitive_data_2.writeEgg(Filename(prim_2_name + ".egg"))
# now we'll take these .egg files generated on the fly
# and convert them to the 2D A* pathfinding system
navmesh = NavMeshGenerator(prim_1_name + ".egg", prim_2_name + ".egg")
# the navmesh has now been automatically created
# and we can add it to the PandAI init_path_find()
self.AIbehaviors.initPathFind("navmesh.csv")
# self.AIbehaviors.initPathFind("models/navmesh.csv")
…and then also usage of the built-in collision system, which takes models from Blender to update Ralph’s Z-position. It’s a bit of a bricolage, but it works.
extracting by default “Plane.001” as the target geom (which is the Blender layer name).
@Simulan does this mean that if a model does not have a Plane.001 geom, then the EggPrimitiveCreation.py wouldn’t be able to generate the correct navmesh for the level ?
this is the project i am working on, and i have no idea what i have done wrong for the pandAI to misbehave like that. it is causing all sorts of issues, like randomly moving in the air, circling the player, etc etc.
i woild very much appreciate if you gave a few minutes of your precious time to see what might be wrong.
I wrote EggPrimitiveCreation.py to allow PandAI, which uses a Y-up convention IIRC, to work natively with the Z-up convention practically everybody uses today. So yeah, that’s probably not clear from just looking at the demo source.
With regards to your other questions, I’m afraid it’d take too long for me to diagnose/develop your project to that degree.
@Simulan is it possible to set some kind of a limit to the height for the navmesh generation, so as prevent the navmeshes from being genetaed for the walls as well !?
The problem i am having is that the AI is jumping over the walls, instead of going around it, to reach the player, ( no matter how high the walls are )
And, it turns out i was applying the transforms incorrectly !
Now including preprocessed level .bam files by default to avoid potential panda3d-gltf issues due to improper venv/system Python setups
I noticed recently that on a clean install of Ubuntu 24 and when using the now-standard Python venv conventions, panda3d would convert the .glb files incorrectly on the fly, giving the long-dreaded incorrect model orientation issue but in a new form. Hopefully we can get a clean fix for panda3d-gltf and/or the built-in write_bam_file() support sometime in the near future so that naive venv instantiations “just work”. It was cool to do the model file processing on the fly while it worked.