AI Libraries for Panda3D


#86

I would wish me some more examples how to use the code. Yeah, i know on download section is explained how to use it. But when i do this i total fail.

For example evade:
aichar does nothing until i reach his destination and then he runs away and never stops or changes direction even i move in his way. and my relax_distance is twice the panic_distance.

i tried to make a swarm. after adding them all to swarm, swarm behavior was disabled. i checked c+±code and found a function to start this behavior. but nothing changed.

examples on download section are really good, iff they would do what i expect. so some graphical examples that shows behavior would be great. only small examples not that big like rralph. just a plane and then some chars which are using the behavior.

and it would be great if you can release your examples that you used for your videos. there is this swarm example with these moving trees and those chickens.

would be really nice!

btw our advancement:

  1. we edited code so every aichar uses the same navmesh in the world for pathfinding. disadvantage is that you can only do one A* at the same time. We don’t know how big this disadvantage is for bigger worlds but it is still possible that every aichar uses his own navmesh if coder wants to.

  2. Another thing we did is what darek mentioned. It is possible to do a A*-search on the navmesh and a Python list with waypoints will be returned. Then you can do stuff like using physics or assure a consistent world in a p2p game (thats what we do :laughing:).

i know, not much progress but team has much to do for university in the last weeks. Next week we focus on PandAI again and hopefully fix some issues.


#87

@ Mindblighter

We did try dynamic pathfinding which you talk about. Could you check out the demo on our downloads page:

etc.cmu.edu/projects/pandai/Download.html

called Dynamic Obstacle Avoidance Demo.

We did not test this extensively for the maximum number of characters it could support but it did dynamically avoid other pathfinding characters.

Also, the LOS is a neat feature, I will add it to the to do list.


#88


@ derek

Thanks for the info. Will be updated.

@ peerpanda

Will put up the video examples. Thanks for adding to Pandai (yay for opensource!).


#89

Thanks a lot guys for doing this! This is what open source is all about. We really hope the libraries will grow this way by adding new features and fixes. Also since you are editing the code, a few things to keep in mind,

  1. Please make sure you are following all the Panda3D conventions. This is a must if it has to get into CVS. You can get the details here,

http://panda3d.cvs.sourceforge.net/viewvc/checkout/panda3d/panda/src/doc/coding-style.txt

  1. Comment the code clearly so that people can easily understand and make modifications in future.
  2. It would be great to have a maintenance log at the top of each file that you are editing. This would record the new features you have added and on what date.
  3. We want to start updating the Panda3D manual soon so that it is easier to understand and implement the AI. If you guys can maintain a document of how to use the new features you have added that will be very helpful while we update the manual.

Could you provide a code snippet of how you are using the evade function? That would really help us to find out why it is not working.

Same goes for this one too. A code snippent of how you are doing it will be really helpful. Did you add the flock object to the AI World? That is very important.

Once again thanks for all your help and suggestions. We really want to push some fixes and features into the library. We shall come up with a priority list and share it with everyone soon.[/url]


#90

am i missing something or is the update mechanism bound to the system clock? (i’d like to be able to accelerate and delay gameplay/movement speed).

i am currently trying to recompile with a added timeDelta in update of AiWorld and AiCharacter and a modified acceleration calculation ( LVecBase3f acceleration = steering_force / _mass * timeDelta; )


#91

It is a threaded process and there isn’t any control to do that for now.

It looks like you are on the right path. Let me know if you run into problems or if you get it working.


#92

So is there any plans to do this dynamically ingame or by adding a way to generate from a heightmap for geomipterrain users?

If i understood the csv better i probable could hand build the csv info so i could use this. any chance we could find out more about the csv and what each line is in relation to the others?

(heck if i understood this part better i could probable build a python script that takes your ingame geomipterrain and builds the csv if this would work for the code)


#93

Currently we do not have any plans to do this because of the amount of time commitment required.

If you look at page 2 in this post, towards the end there are details about what the csv data is. If you need further information let us know.

Hope this helps. Thank you!


#94

ok so i found this:

Grid Size - size of the mesh.

NULL - specifies if a node exists or not.
0 - exists
1 - does not exist.

Node Type - specifies if it is the main node or the neighbor node.
0 - main node.
1 - neighbor node.

GridX - row index
GridY - col index

Length - length of each cell.
Width - width of each cell.
Height - currently overwritten as 0 since height info is not used.

PosX, PosY, PosZ - position of the node in the cell.

and it tells me a little about the Navmesh.csv in the fact theatim assuming it gives all info but things i dont understand are:

  1. ordering (does it care what order the information is in?)
  2. what does the position of the node do?
  3. shouldnt most of the length/widths of the cells be the same as squares are generally used?
    4.does the info start at the bottom left or does it matter?
  4. if a node does not exist does this mean not at all? if so why did we record it??
  5. I see in the static ob demo we can make things marked as not traverable is there an easy way to setup a csv to use my terrain as completely traverable then I can mark the stuff off i need? (I use a 1024X1024 terrain for now and i would like the map to use the same size if possible)

this is just some basic info that is nice to know course some of it really dosnt matter but i think it will help since i will probable have to build my mesh by hand. (Bascally im trying to come up with a way to use your system to hand write a csv but this will be time consuming and i need to know alot of what the system does without being able to read c++ so maybe a simple tutorial on writing the csv would suffice instead of answering all this)(the plan is to use this to write a python code to write a csv it may take time but its a tool so it dosnt need to be fast)

I hope that i didnt bother you too much and thank you in advance for any help you can provide!

Edit: Course I could just need to understand NavMeshes better myself I will be researching this subject to see if I can get a better understanding and with that hopefully be able to work with navmeshes with heightmaps.

Edit 2: I think i have found a round about way to make a navmesh. I use a heightmap in blender to make the terrain export it to egg this allows me to have my terrain info so that i can use it with PandaAI. If you wish to know how to do this go to: en.wikibooks.org/wiki/Blender_3D … heightmaps
the only downside is that the ratio in blender and Panda are not exactly the same so you may have to work with Panda or blender a bit to get it working properly for you.


#95

this should probably be changed:

Pursue::Pursue(AICharacter *ai_ch, NodePath target_object, float pursue_wt) {
	_ai_char = ai_ch;

	_pursue_target = target_object;
	_pursue_weight = pursue_wt;
// i think this should be added
	_pursue_direction = LVecBase3f(0.0, 0.0, 0.0);

	_pursue_done = false;
}

#96

another thing, the completion of the seek and pursue is determined by “int(target_distance) == 0”. meaning a distance to the target < 1 will make it finish, but depending on the scale of the models used in a game this isnt very practical.


#97
  1. Yes you need to maintain the order as the data will be read in the same order into a vector which is then used for pathfinding.
  2. The AI characters will be using these node positions to traverse the mesh. These are the world space coordinates of the nodes. It will be the center of each grid cell.
  3. The constraint for the mesh is that it should have the same number of rows and columns. So if you have a rectangular mesh, then all the grid cells will not be squares and cells will have some minute dimension variance.
  4. The info starts at bottom left if I am not mistaken. I will confirm this anyhow.
  5. If a node does not exist (which means it is an obstacle) it will be specified as null when the data gets written into the vector during runtime. During pathfinding the A* checks if a node is traversable by doing a null check.
  6. So you can pretty much divide your entire 1024 X 1024 map into a grid. Make sure your grid has same number of rows and columns and then find the center position of each of the grid cells and assign it as the node positions in your csv. At this point all the nodes in your grid exist and are traversable. Now in the code you can toggle whether these nodes are traversable or not. As long as the data in the csv that you generate is in the same format I don’t see why you should have any issue using our pathfinding.

Just so that we are on the same page, we use waypoint meshes in PandAI as compared to Navmesh. And we know the confusion is due to the naming convention we used to explain the mesh generation process and pathfinding. Our apologies.

Hope you find this useful.

Thanks!


#98

That was a great responce and it really helped I managed to get it working but there are a few issues: as i already posted this info see thread below for question. There seems to be something wrong with the egg file it looks right though…

discourse.panda3d.org/viewtopic.php?t=8786

I think you guys are probable the only ones that can tell me what im doing wrong.


#99

Unfortunately PandaAI currently does not support blender models. We are still working on it. The way triangles are ordered in Blender eggs are very different from how Maya and Max does it. Hopefully we can get it working soon. Meanwhile if you have access to Maya or Max you shouldn’t have any problems.


#100

Noted. I think rather than post bugs here on this post, we should do it on a common front. Any suggestions on a bug repository.


#101

How about Launchpad?
bugs.launchpad.net/panda3d/
You could possibly use a tag to mark PandAI-related bugs.


#102

Ok so I would like to announce that the first version of the code to produce a navmesh.csv has been successful. This system was setup for use with geomipterrain. I am now able to pathfind perfectly with this code.

How it works: I used the code to setup a geomipterrain and then grab a bunch of information from the terrain then math code is looped through and a set of points are created that represent the grid that will be used to setup the paths. This does include finding all the neighboring grid squares in the correct order. as it is going throught the lines of the code it is writing them to navmesh.csv now you have the file you need to use PandaAI without having to recreate your terrain in maya or Max.

This system could be rewritten to use any type of terrain the only limit ive found so far is the number of lines in excel. This means that larger terrains Like geomip or |Craigs| new paging terrain may have issues if you make them too big as you would need lots of decent size squares to fill the terrain. (This system could be changed to paging as well if the code runs fast enough)
also depending on the version of excel used this may limit you to 65k lines (office 2003: around 75 squares per row so terrain smaller than 700px X 700px).

To find out the number of excel rows needed before you try to make the file use (N*N)*9 where N is number of sqaures requested. to find a good number for squares you may need to test although i find using the length of my picture/9 shows me aprox the number of squares i want as i find 9px per square is pretty accurate.

I plan on releasing the code later today once optimizing the code is completed.

I would like to take the time to thank a few people that made this possible:
JohnKol (for giving me the info for setting up the navmesh)
|Craig| (For walking me through optimizing the code)
CMU (For making the PandaAI)

Also thank you to everyone in IRC chat that let me bounce ideas off you for this as it was a big help in figuring out how to write the code.
Edit: This code has been fixed for issues that were found below this post.

import direct.directbase.DirectStart
from direct.showbase.DirectObject import DirectObject
from panda3d.core import PNMImageHeader, Vec3, Texture, GeoMipTerrain, VBase4
from panda3d.core import Filename, BitMask32, TextureStage
#import csv
class World(DirectObject):
    def __init__(self):
        """
        This is a simple system to make PandaAI work with Geomip terrain
        Use ctrl-F to find the line you need to change by using the code inserted at the number in this text
        Things you need to change to make this work:
        1.use your heightmap                            - self.terrain.setHeightfield(Filename("Terrain/Level 1/terraintest.bmp"))
        2.change to number of blocks you want to use    - self.terrain.setBlockSize(64)
        3.Change your texture                           - loader.loadTexture('Terrain/Level 1/ground.jpg')
        4.change this to your heightmap again           - header.readHeader(Filename("Terrain/Level 1/terraintest.bmp"))
        
        Now you can use this code to make your Navmesh.csv for PandaAI.
        """
        base.cam.setPos(-100,512,3000)
        base.cam.lookAt(512,512,0)
        #Load the first environment model
        self.terrain = GeoMipTerrain("ground")
        self.terrain.setHeightfield(Filename("Terrain/Level 1/terraintest.bmp")) #Terrain/game heightmap.bmp
        # Set terrain properties
        self.terrain.setBlockSize(256)
        self.terrain.getRoot().reparentTo(render)
        self.terrain_tex = loader.loadTexture('Terrain/Level 1/ground.jpg')
        self.terrain_tex.setMagfilter (Texture.FTLinear) 
        self.terrain_tex.setMinfilter(Texture.FTLinearMipmapLinear)

        # Store root NodePath for convenience then set root settings for the terrain
        root = self.terrain.getRoot()
        #Set the terrain itself to be collide-able.
        root.setCollideMask(BitMask32.bit(0))
        root.reparentTo(render)
        ts = TextureStage('ts')
        root.setPos(0,0,0)
        root.setSz(50)
        root.setTexScale(ts.getDefault(),15,15)
        root.setTexture(self.terrain_tex,1)
        root.setTwoSided(True)
        
        header = PNMImageHeader()
        header.readHeader(Filename("Terrain/Level 1/terraintest.bmp"))
        hy = header.getYSize()
        hx = header.getXSize()
        bs = self.terrain.getBlockSize()
        cuber = (hx-1)/bs
        cubing2 = ((hx-1)/bs)/2

        file=open("navmesh.csv", "w")
        def doLine(*x): file.write(','.join( str(v) for v in x)+'\n')
        
        doLine("Grid Size",bs)
                
        doLine("NULL","NodeType","GridX","GridY","Length","Width","Height","PosX","PosY","PosZ")
        
        for j in range(bs):
            cubing = ((hx-1)/bs)/2
            for i in range(bs):
                
                def h(f,a,b,c=1):
                    if f: doLine(1,1,0,0,0,0,0,0,0,0)
                    else: doLine(0,c,i+a,j+b,cuber,cuber,0,cubing+cuber*a,cubing2+cuber*b,self.terrain.getElevation(cubing+cuber*a,cubing2+cuber*b)*self.terrain.getRoot().getSz())
                
                h(False,                   0, 0,c=0)
                h(i-1 < 0 or j+1 > bs-1,  -1, 1)
                h(i-1 < 0,                -1, 0)
                h(i-1 < 0 or j-1 < 0,     -1,-1)
                h(j-1 < 0,                 0,-1)
                
                h(i+1 > bs-1 or j-1 < 0,   1,-1)
                h(i+1 > bs-1,              1, 0)
                h(i+1 > bs-1 or j+1 >bs-1, 1, 1)
                h(j+1 > bs-1,              0, 1)
                
                cubing += cuber
            cubing2 = cubing2 + cuber
                 
        #Updates the taskMgr
        taskMgr.add(self.updateTask, "update")

        #this updates the terrain when needed
    def updateTask(self, task): 
        self.terrain.update()
        self.terrain.getRoot().setCollideMask(BitMask32.bit(0)) 
        return task.cont 

w=World()
run()

#103

@rdb

Thanks. I have started setting up bugs in bugs.launchpad.

@Hypnos

Added your pursue find to the bug list.

To the community, please feel free to add bugs to this list. Tag them as PandAI for easy searches.

@Chia_Pet

Sounds exciting! I am really interested in looking at this working and the source code.


#104

Nice job Chia_Pet! It would be great if you could post your code to the community so that others can make use of it. And thanks for making use of our libraries.

.csv just means a bunch of comma separated data and is not in anyway an excel format. You can always open it in a notepad or any other text editor for debugging. Excel just recognizes the format and shows it to you in a clean tabular form. So in short the .csv format is not limited by Excel’s limitation. Hope that makes sense.


#105

Well I hope everyone likes the above code. I know I do and again thanks to |Craig| who made this code run in like 2 seconds rather than 6 minutes (origional runtime) lol.

Now one thing you need to know when you can see your terrain the code is done so shutdown and grab your navmesh.csv to use in your real game! (I did it this way so you knew that it didnt just crash on you and i had to load the terrain to make it work with auto number system anyway)