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.
from direct.showbase.DirectObject import DirectObject
from panda3d.core import PNMImageHeader, Vec3, Texture, GeoMipTerrain, VBase4
from panda3d.core import Filename, BitMask32, TextureStage
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.
#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_tex = loader.loadTexture('Terrain/Level 1/ground.jpg')
# Store root NodePath for convenience then set root settings for the terrain
root = self.terrain.getRoot()
#Set the terrain itself to be collide-able.
ts = TextureStage('ts')
header = PNMImageHeader()
hy = header.getYSize()
hx = header.getXSize()
bs = self.terrain.getBlockSize()
cuber = (hx-1)/bs
cubing2 = ((hx-1)/bs)/2
def doLine(*x): file.write(','.join( str(v) for v in x)+'\n')
for j in range(bs):
cubing = ((hx-1)/bs)/2
for i in range(bs):
if f: doLine(1,1,0,0,0,0,0,0,0,0)
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
#this updates the terrain when needed
def updateTask(self, task):