AI Libraries for Panda3D


#107

Hi all,

Is anyone else using PandAI with Maya? I’ve followed the tutorial videos but the resulting navmesh.csv doesn’t seem to work. I always get the errors “couldnt find destination” and “couldnt find source.”

Here’s the sequence I used:

  1. Created a 60x60 plane centered at (0,0,0) in Maya 2009
  2. Under INPUTS->polyPlane1 (my plane) I changed the subdivision width and heights to 4 to give me a 4x4 grid
  3. Exported this plane as “env_full.egg” and verified it looked right in pview
  4. Selected three of the center faces and deleted them
  5. Exported this new plane as “env_col.egg” and verified it looked right in pview
  6. Ran C:\Panda3D-1.6.2\bin\egg-trans on BOTH “env_full.egg” and “env_col.egg” to create “env_full_tri.egg” and “env_col_tri.egg,” respectively
  7. Ran “meshgen env_full_tri.egg env_col_tri.egg” to create navmesh
  8. Swapped out my “env_col_tri.egg” and navmesh in the PandAI demo StaticObstacleDemo as a means to test it out. (Note: I repositioned ralph and the destination so that they were inside of my area at the start)

Both ralph and the arrow are definitely inside of the plane, but I get the source and destination errors mentioned above. Any ideas what I’m doing wrong?

Thanks for your help!

EDIT:
Well, I’ve tracked down the source of the problem. Here it is for others to learn from.

The navmesh.csv that’s being generated from my eggs appears to have swapped Length with Height and PosY with PosZ.

Sample:

Grid Size	3								
NULL	NodeType	GridX	GridY	Length	Width	Height	PosX	PosY	PosZ
0	0	0	0	4.44E-15	20	20	-20	-4.44E-15	20
1	1	0	0	0	0	0	0	0	0
1	1	0	0	0	0	0	0	0	0
1	1	0	0	0	0	0	0	0	0
1	1	0	0	0	0	0	0	0	0
1	1	0	0	0	0	0	0	0	0
0	1	1	0	4.44E-15	20	20	0	-4.44E-15	20

If I swap them by hand, then the navmesh works great.

Root cause:
I was using Maya in Y-Up instead of Z-Up coordinate system. Do’h.


#108

I’m really excited you guys are looking at AI stuff for Panda3D, but I was a bit disappointed by the navigation mesh functionality. It seems as if it’s more of a navigation grid than a mesh, and it looks like it needs to be created manually.

So, I took a look at that Recast project, and ended up getting a small portion of it working with Panda3D. Basically I modified the source of their demo application to export .obj files, which I then imported into Blender, and exported to .egg files. Then I used Panda’s vertex reading utilities to go through the vertices and generate pathfinding data.

I got pathfinding to work pretty well with my own methods brainstormed in Python, but I cut some corners for performance, and it’s certainly not a textbook navmesh implementation. However, it makes me think that someone experienced with the C++ workings of Panda3D could crank out some good code fairly quickly, especially since a lot (if not all?) of it is already done in PandAI.

I think the ability to use automatically-generated navmeshes from Recast is a great feature, and it’s already saved me a lot of time. So, does the current version of PandAI support navigation meshes with different shapes (actually, just triangles)? If not I might look into working on it in C++, but it will take me some time to get up to speed.


#109

Wofire guys also used it:
blog.wolfire.com/2010/05/Automat … ion-meshes


#110

@ et1337

Yes you are right it is really a navigation grid.

I think it would be a great idea to get Recast working with PandAI and it was something we really didn’t have the time to integrate into Panda3D but really wanted to.
It is something I have been meaning to work on too. If you wish to try it, let me know if you reach any hurdles on the PandAI side of the code.

Also,

Could you please elaborate on which ones you used and an explanation of how.

@ treeform

Thanks for the link.

Cheers


#111

Here’s my vertex processing code, It’s mostly ripped straight from the manual.

I extract all the edges, and then use them to form “nodes” which are basically triangular areas in the mesh. The edges then link the nodes together, forming a graph which I can traverse with A*.

def _processNode(self, node):
		geomNodeCollection = node.findAllMatches('**/+GeomNode')
		for nodePath in geomNodeCollection:
			geomNode = nodePath.node()
			self._processGeomNode(geomNode)
		for edge in self.edges:
			if len(edge.nodes) <= 1:
				# This edge isn't between two nodes, so we don't need to worry about it when pathfinding.
				# But we still need it for determining which node an agent is in.
				edge.navigable = False

	def _processGeomNode(self, geomNode):
		for i in range(geomNode.getNumGeoms()):
			geom = geomNode.getGeom(i)
			state = geomNode.getGeomState(i)
			self._processGeom(geom)

	def _processGeom(self, geom):
		vdata = geom.getVertexData()
		for i in range(geom.getNumPrimitives()):
			prim = geom.getPrimitive(i)
			self._processPrimitive(prim, vdata)

	def _processPrimitive(self, prim, vdata):
		vertex = GeomVertexReader(vdata, "vertex")
		prim = prim.decompose()
		def getVertex(index):
			vi = prim.getVertex(index)
			vertex.setRow(vi)
			return vertex.getData3f()
		for p in range(prim.getNumPrimitives()):
			s = prim.getPrimitiveStart(p)
			e = prim.getPrimitiveEnd(p)
			for i in range(s, e):
				v = getVertex(i)
				if i + 1 >= e:
					break
				v2 = getVertex(i + 1)
				edge1 = self.addEdge(v, v2)
				if i + 2 >= e:
					break
				v3 = getVertex(i + 2)
				edge2 = self.addEdge(v2, v3)
				edge3 = self.addEdge(v3, v)
				self.nodes.append(NavNode(edge1, edge2, edge3))

To determine which node an agent is in, I just do a dot product from the agent’s position to the center of each of the three edges. If all three dot products are positive (or negative, I can’t remember), the agent must be inside the node. I do some other stuff for vertical testing as well. It’s all in the A3P repository.


#112

I hope it’s my search skills failing, but I haven’t been able to find a version of the Navigation Mesh Generator for Linux. In the download section of the PandaAI website there’s only Windows exe and source. Is it included in Panda 1.7? And if so, under what name and/or in what directory (of it’s not /usr/bin)? Thanx in advance.


#113

@coppertop

You are right. There isn’t one. But to aid you I have re-factored some of the code and have the source code for the Mesh Generator available to be downloaded at :

www.srinavinnair.com/downloads (MeshGen_Linux)

Unfortunately, I don’t have an executable ready to use, so you will have to build it in your version of Linux using this source code.

The executable should work the same way as the documentation states.

Do let me know if this works fine.


#114

Thanks for the reply. I’ve actually managed to build it in the meantime (had to recall how to use g++, hehe) from the source on the PandaAI download website. It seems to work, but if I happen to hit a wall with it, I’ll try your version.

Still, I think it should be included with Panda itself. It’s kind of a non-sense for PandaAI itself to be included, but not the most important tool to make full use of it.


#115

Is there any progress on the Blender side of things? I’ve tried making the most simple possible navmesh (a sudivided plane) and failed completely, with the character ending up totally confused with the map (as expected given the previous post on the subject). Is there any chance this will get resolved soon? I have no access to neither Max nor Maya and I need PandaAI, so it’s a rather huge problem for me…


#116

Cool. Good to hear you got it working. I will leave this code up anyways since it is a cleaner version and have removed any panda dependencies (since the mesh generator really doesn’t need any).

Sorry, the blender support is still in progress due to time constraints.

Try to use a trial version of Max or Maya till then.


#117

I fully understand that time is a problem, and I really appreciate your work so far. However, is it possible to estimate how long it will take to get it to work? I’m only asking this because I’m working on a rather big project (in which I’m planning to make extensive use of PandaAI), and need at least some indication, so that I can plan my work. Don’t get me wrong, I’m not trying to hurry you up, I just need to know where I’m standing. I hope you understand that.

Unfortunately I really can’t use Maya nor Max, trial included. Max is not an option because I’m on Linux, and I don’t seem to currently meet the requirements for Maya.

Thanks very much.


#118

Sure. I understand.

Give me a couple of days(upto a week) to get back to you on this.

Thanks.


#119

Thanks very much, I really appreciate it.


#120

@ coppertop

I am sorry but I don’t think we can give a definite answer on the Blender support as of now due to time constraints and lack of our knowledge on the EggData side, which I have been researching.

I hope I can get more time to spend on this apart from my other responsibilities (as I am not full time on PandAI anymore). Please assume that there is no Blender support as of now. I hope you still can use other parts of PandAI.

I will post it up when it is fixed.


#121

That’s a shame, but I fully understand the situation. And I will definitely make use of the rest of PandaAI. Thanks.


#122

Good News!!!

We are excited to say that the PandAI pathfinding solution now supports Blender. We have created a separate mesh generation tool for creating a navigation grid from a plane made using Blender. You can download the required files from here:

www.srinavinnair.com/downloads/BlenderMeshGen.zip

In the above zip file you will find the following:

  1. A ReadMe file which explains how to use the tool.
  2. The python script required to generate navmesh.csv from Blender full and collision planes.
  3. Sample planes created in Blender which were used for testing.

A few IMPORTANT things:

a. Make sure your the full and collision planes that you make are on the ‘X - Z plane’ of Blender.
b. This is for planes created using ONLY Blender. For Max and Maya please continue to use our previous meshgen tool.

Here is a video of pathfinding working with planes created in Blender:

youtube.com/watch?v=M72PcdYvbVE

NOTE: The lag is due to a lot of spheres being rendered as nodes.

Lastly, it would be really helpful if people using PandAI and Blender could give us feedback about this new tool we have provided. If you come across any bugs or discrepancies please report it in this thread.

Thanks a lot for your support!

  • Team PandAI.

Help with Egg File Parsing in Python
#123

You guys are just fantastic. I have downloaded already and I will test it and give feedback as soon as I can. This is really great news.

Thanks very much for all your hard work.


#124

Thanks a lot.

We are glad that you can still use it.


#125

This looks like it will be very useful in my current project; I’m trying to build an RTS game, and hope to use PandAI for navigation, since it’s far more practical than writing my own algorithms.

I am a little confused as to how to use the Navigation Mesh Generator Tool for Blender, however. It says in the instructions to use two arguments, a plane file and a plan collision file. At the moment, I have my visible geometry and my collision geometry in the same .egg file, on different layers. Does this mean I have to make a separate file with collision geometry? And if so, what is the geometry I need to pass - all collision geometry, i.e. floors, walls, and everything else?

Also, it may be related to me misusing the mesh generator, but when I try to run it the meshgen crashes, either at step 2 or step 3 (creating notes on the mesh, or identifying neighbour nodes for each node on the mesh). I get no error message in the console, just a windows pop-up telling me that meshgen.exe is no longer working and needs to be shut down.

Thanks a lot for this work, by the way - I’m sure it will save a lot of people a lot of trouble! I look forward to incorporating PandAI into my game.


#126

@ GarrickW

I would suggest the best way to test it out is to create a simple 5x5 plane in Blender in the x-z axis. (By 5x5 I mean use subdivisions)

This will be your full_mesh.egg.

Now remove a couple of faces from the plane and export another egg as the coll_mesh.egg.

See if you can use the mesh generator on this to get a navmesh.csv.

Use this nevmesh.csv in PandAI pathfinding and see if you can get an AI character to pathfind to another.

  • Note :
    If A and B are AI characters and A is to pathfind to B, make sure the starting positions of A and B should be on the faces which can be traversed.