Navigation Mesh and crowd Agents

I just reproduct on PG my backend validation of movement. It looks very good now.

https://playground.babylonjs.com/#CYS4N4#12

Is crowd have method to stop goTo action? I want to fire it, when enemy intersect with player mesh.

No, there is nothing to stop an agent. But you can call goto with the current agent position.

1 Like

Yeah! This is that! Maybe someone need similar code: https://playground.babylonjs.com/#CYS4N4#13

Thanks a lot!

1 Like

Yo @Cedric

Did you ever add support to use an already baked navmesh.

Iā€™m looking to update the unity exporter to use recastJsPlugin with the nav mesh baked in unity and exported as a GLTF mesh

Can you add support for existing meshesā€¦ pretty please :pleading_face:

Not yet. I have some time next week. Iā€™ll try to do something.

1 Like

Thanks bro :slight_smile:

Yo @Cedric ā€¦ Can you please add rotation support so that the agent is rotated towards the direction he is heading. When using animated characters as the transform node (model parent) it looks funny when the character is not rotated towards the direction of travel.

Can you please look at that as well :pleading_face:

recast doesnā€™t handle orientation. But itā€™s possible to handle it on your side. The orientation vector is the velocity when its length is > 0. otherwise, itā€™s unchanged.

Could show me a quick sample to set the orientation/rotation from the agent velocityā€¦, please

https://playground.babylonjs.com/#LPTLZM

check lines [32 ā€¦ 44]
agent direction is interpolated to reach the velocity vector. That direction vector is then used to compute an orientation angle (lines 46 - 48)

3 Likes

Thanks again @Cedric ā€¦ rotation code works great :+1:

1 Like

@MackeyK24

Itā€™s not possible to use an arbitrary mesh with recast. There are constraints that basically force to have a navmesh built as a top down projection. But Iā€™m adding the ability to load a binary representation of the navmesh. No construction needed then.

Whatā€™s your pipeline for building a navmesh? Can you export a binary file from recast in Unity? I guess itā€™s the same binary representation and Iā€™d like to test it if you can send me an export.

What do mean binary representation of a navmeshā€¦ what file formatā€¦ ???

Right now I simply bake the unity navmesh to GLTF or GLB fileā€¦ and I was using the Babylon Navigation-Mesh extension and passing the native babylon mesh to it

There are no other type of export?

Nope just GLTF export.
What binary format are you thinking of ???

I believe Recast is used in Unity and UE. I was hoping it could export navmesh with the same format.

Yo @Cedricā€¦ Im am just going to switch the unity export to use the native runtime recast.cpp approach to navigation instead of the Unity Pre-Baked navigation mesh geometry.

But i do have a question about off mesh linksā€¦ Do you plan on implementing off mesh links ???

Hi @MackeyK24

Iā€™ve added the ability to bake and restore the navmesh : Create Navigation Mesh - Babylon.js Documentation

Itā€™s available in the nightly. So, for you workflow, the best is to get the navmesh gltf, compute again the navmesh in babylon js, save the uint8array and then you can use it as you want to retore the navmesh.

3 Likes

Sweet ā€¦ btw ā€¦ what is the neat way to save the uintarray to disk

And the best way to load a uintarray from the server

Basically the best way to actually load and save the binary file ???

I know is newbie question. But I see a lot of different code snippets.

Can you show the best way, as far as your concerned to load and save these binary files

Also do you think we can get saving exporting the current Nav mesh from the inspector just like you can export a .env files

Then we can bake a full scene at design time and export the baked nav mesh for later runtime use in when loading the scene assets ?

To save it, I did that :


var downloadBlob, downloadURL;

downloadBlob = function(data, fileName, mimeType) {
  var blob, url;
  blob = new Blob([data], {
    type: mimeType
  });
  url = window.URL.createObjectURL(blob);
  downloadURL(url, fileName);
  setTimeout(function() {
    return window.URL.revokeObjectURL(url);
  }, 1000);
};

downloadURL = function(data, fileName) {
  var a;
  a = document.createElement('a');
  a.href = data;
  a.download = fileName;
  document.body.appendChild(a);
  a.style = 'display: none';
  a.click();
  a.remove();
};
...

navigationPlugin.createNavMesh(scene.meshes, parameters);
var binaryData = navigationPlugin.getNavmeshData();
var blob = new Blob(binaryData, {type: "application/octet-stream"});
var blobURL = URL.createObjectURL(blob);
downloadBlob(binaryData, 'some-file.bin', 'application/octet-stream');

And to use it back from a server :


var xhr = new XMLHttpRequest();

xhr.open("GET", "https://raw.githubusercontent.com/CedricGuillemet/dump/master/some-file.bin", true);
xhr.responseType = "arraybuffer";
xhr.addEventListener("readystatechange", function() {
    if (xhr.status === 200) {
     
if (xhr.response) {
    var uint8View = new Uint8Array(xhr.response);
    console.log(uint8View);
    navigationPlugin.buildFromNavmeshData(uint8View);
}

    }
}, false);
xhr.send();
4 Likes