Update NavMesh dynamically

Hi Guys…
I have a NavMesh which was generated by the sceenComposer, which works “ok”. But there are some cells in the NavMesh which i would like remove so that
final Cell findClosestCell = navMesh.findClosestCell(location);
will not chose it…
I know that i can modify the triangle in the mesh
VertexBuffer uv = g.getMesh().getBuffer(Type.TexCoord);

float[] uvArray = BufferUtils.getFloatArray((FloatBuffer) uv.getData());`

But is there a way to remove a cell completely. Or change NavMesh not to use certain cells dynamically?


If i am not wrong
Each Cell is linked to 3 cells around it (if any cell exist in it’s surrounding) in JME-AI
You can first get cell you want to remove by providing it’s world position using findClosestCell(Vector3f point) method in NavMesh class. Then iterate through it’s linked cells using getLink(int side) and remove link to this cell (which you want to remove)
from them (by setting null link). Then path finder will not consider this cell when path finding.

Note that calling linkCells() on navmesh will relink cells again.

I also want to make my navmesh to be dynamic. For now it is semi dynamic thanks to Blender (Using Blender NavMesh generator and Boolean Modifier). Means it is dynamic in Level Design/Prototyping time but static at runtime.

I have not tested this myself you can try it and let me know if it works. :slight_smile:

Thanks for you reply

with ref to
“using getLink(int side) and remove link to this cell”

I had a look through the API
i cant find a way to remove a link in the mesh.

There is no remove link method in Cell. you can remove link by calling setLink(int Side, null); in neighbor cells to this cell.

In above image, suppose we want to remove cell which is in the center, so path finder will never find path trough this cell, to do that we should remove links from neighbor cells to this cell (green links in image) and for doing this we can call setLink(int Side, null); on all neighbor cells (here cell 0 , 1 are neighbors) to remove link from neighbors to the central cell.

If you have any questions please ask.

so do you mean

private void setLink(int Side, Cell Caller) {
    links[Side] = Caller;

its private so im not able to call it… AM i missing something?

Oops! :sweat_smile:
I did not notice it is private when looking to javadoc, really sorry about it.
I have no idea about any other way, maybe you should do this with editing mesh buffer as you mentioned in your first post.
Or hack through code and make that method public for your self !! :wink:

Actually i do create/edit my navmesh in blender then load it to NavMesh in JME AI.

Hope some one with more knowledge using JME AI can help. Maybe @Darkchaos can help.

ok so i kinda hacked it
i did

new PathCell(cell).unlinkFromMesh();

PAthCell is just a class i created which extends Cell. So i can call protected methods

public void unlinkFromMesh() {
1 Like

Ah, i did not notice there is this handy unLink(Cell c) method over there.
Thanks for the notice.

So now is every thing working as expected ?