Navigation Mesh

I apologize for spamming two forums with this, now. I wasn’t sure where to post this, so initially I posted it in Support>Physics, as this is a physics-related question, sort of. I decided to start one here, as I’m not entirely sure the other one even belonged there, let alone was receiving views from people who knew any answers.

http://www.blenderartists.org/forum/showthread.php?301903-BGE-Navigation-Mesh

The objective is to “uncover” additional NavMesh… ‘space’, I suppose. If any of you can remember back to Dungeon Keeper your imps would mine out walls and create additional paths. I’m attempting to achieve a similar mechanic. However, to keep Navigation updated for the imps, I would need to add the space that is now uncovered (wall removed) to the current Navigation Mesh.

Currently, with the basic method I use of using all scene objects to create the NavMesh from the Scene Panel, the Agent moves from his starting point in the “Field”, through the maze, and to his finishing point at the “Goal Cheese”.

http://www.blenderartists.org/forum/attachment.php?attachmentid=249075&d=1374849732

The problem is that I can’t seem to be able to edit the NavMesh in real-time, this due to the BGE’s inability to interact with Blender, though I did find something about RAS_MeshObject somewhere - something that I can’t seem to find any documentation on…

The following is the current version of my script. It does not work, though it returns no errors in the Terminal. I have two scripts, now. One to generate the NavMesh, the second to commit it to the Steering Actuator on the agent.

NavMesh Generation


import bge


print ('ASSEMBLING NAVMESH')


print ('Getting scene data')
owner = bge.logic.getCurrentController().owner
scene = bge.logic.getCurrentScene()


print ('Configuring navMesh parts')
navMeshParts = []
#NavMesh from the field
navMeshParts.append(scene.objects['nmField'].meshes[0])
#NavMesh from the maze
navMeshParts.append(scene.objects['nmMaze'].meshes[0])
baseObject = 'nmBase'
meshLoc = scene.objects['Ground']
pX = meshLoc.localPosition.x + .2
pY = meshLoc.localPosition.y + .2
pZ = meshLoc.localPosition.z + .2


print ('Assembling the NavMesh')
navMeshWhole = scene.addObject(baseObject, meshLoc)
navMeshWhole.meshes.append(navMeshParts)
navMeshWhole.localPosition = [pX, pY, pZ]


print ('Committing NavMesh to KX_NavMeshObject')
navMesh = bge.types.KX_NavMeshObject(navMeshWhole)


print ('Assign NavMesh to Agent')
owner['navMesh'] = navMesh.name

Steering Configuration


import bge


keyboard = bge.logic.keyboard
JUST_ACTIVATED = bge.logic.KX_INPUT_JUST_ACTIVATED


if keyboard.events[bge.events.SPACEKEY] == JUST_ACTIVATED:
    print ('STEERING')
    
    print ('Getting scene data')
    owner = bge.logic.getCurrentController().owner
    sensors = bge.logic.getCurrentController().sensors
    actuators = bge.logic.getCurrentController().actuators
    scene = bge.logic.getCurrentScene()
    
    print ('Getting Target and NavMesh')
    target = scene.objects['Goal Cheese']
    navMesh = scene.objects[owner['navMesh']]
    
    print ('Assigning data to Actuator')
    actuators['Steering'].target = target
    actuators['Steering'].navmesh = navMesh
    
    path = navMesh.findPath(owner.localPosition, target.localPosition)

Neither script returns errors in the console. However, attempting to print out ‘path’ returns an empty array. If I replace


navMesh = scene.objects[owner['navMesh']]

with


navMesh = scene.objects['nmField']

I DO get a returned array of points along the path (for the field, but not the maze). This tells me I can’t pass two meshes in one object to KX_NavMeshObject. Either that, or I’m not passing something to NavMeshObject that I should be.

Help!!!

Lastnight I tried using KX_ProxyMesh to get and iterate over KX_VertexProxy. With a mesh set as Physics>Static, every iteration of the script adds [X-.1] to each vert. The mesh appears to be moving to the left, as expected.

So I changed to Physics>Navigation, set up an Agent and a Goal, and tried it again. The path doesn’t move. This indicates to me that either NavMeshes are unaffected by KX_VertexProxy manipulation, or the path drawn isn’t reliant on the changes to [BGE] mesh data.

By the way, moving the NavMesh object does move the path in real-time.

I think your best option is to create your own navigation mesh system.
Or you could of course also go with an easier pathnode system, I’m almost sure dungeon keeper used such a system.

Of course only if you don’t get any other reply, but I think it’s just not possible with blenders navmesh system, so don’t use it at all.

Yeah. I’m playing with that right now. Here’s my idea:

  • In the 3D Editor generate a grid, that uses 9 subcells per grid cell. The grid must cover the extent of your game world.

  • In the grid’s Logic Panel set up ALWAYS>LOGIC[‘dynamicMesh’]

  • Using a script called dynamicMesh, I’m going to attempt to iterate through each face of the grid.

  • First we’ll pass the mesh to a new instance of the Grid object

  • Using RAY[Z+] we’ll check to see if there is an object over each face with property ‘Wall’

  • If an object exists, that face will be turned ‘off’

  • If no object exists, the face will be turned ‘on’

  • From there, I have to learn something about Heuristics. I’ve read a little once before, but it seems like the whole process is very complex. In theory, the next part of the script would check only faces of the instanced Grid object to generate a Node Map.

agoose77 has done a lot of work in this regard. Might see if I can’t port his script over to achieve this. I do believe he’s got a working version of his own set-up that behaves very much like the built-in NavMesh system. If I could use his version to check a NodeMap array, I think we’d have a working dynamic NavMesh.

Did you look at the game blender websight for this?The Pathfinding using Nodes thread in the python/logic forum.There is a blend of it.

3D, if this works, I owe you a drink.

I can’t seem to find the thread, 3D. Any chance you have a link somewhere?

Here you go.I don’t drink.
http://www.gameblender.org/viewtopic.php?f=20&t=2537

Hmm. Looks like they stalled on the script being resource-intensive. At least, that’s what the thread says last. It looks pretty good to me. Doesn’t even seem to require a collision or nav mesh, though there are 3 separate meshes making up the floor.

All in all, that script works very well. I think I might replicate it using Blender’s NavMesh to see how it compares in resource usage. Grats to whoever ‘justrun’ is. And thanks a lot for pointing me in the right direction. Going to pick it apart tonight and see if I can’t set up a game environment using this as the base for navigation.