NavMesh error on big mesh

Hi i have problem with create navmesh, when ground is big plane. In console i can see

recast.js:24 OOM
abort	@	recast.js:24
abortOnCannotGrowMemory	@	recast.js:10

https://www.babylonjs-playground.com/#X5XCVT#14 playground to reproduce problem.

Hi @FurcaTomasz

The navmesh is computed thanks to a voxelization of the geometry. If the cell size (cs and ch parameters) are too small compared to the geometry, this leads to many many cells being allocated (which is failing).
The number of cells on a side = side length / cs. In your case: 300/0.2 = 1500. For an horizontal slice 1500 * 1500 = 2M+ cells.
Even if it was possible to allocate that much memory, the cpu time used to compute the navmesh would take ages.
Try with bigger values for the cell size or try scaling down the geometry.

2 Likes

Thanks for help! :slight_smile:

@Cedric,

As far as I know, the cell size and cell height are directly responsible for the accuracy of the navmesh. A smaller cell size attribute leads to a much better defined navmesh am I correct? Wouldn’t increasing the cell size lead to a less accurate navmesh?

It would be great if we could feed it an already generated navmesh and use the Path finding functionalities later on. This would make it possible to use big meshes and have a detailed navmesh without losing anything performance wise. I think it would be worth it to take a look into it.

Yes, you are right. bigger cs/ch will give less precision. You’ll have to tweak (mesh simplification values too) to get a precise enough mesh will trying to not blow up with memory allocation.

1 Like

Hi @Cedric , looping back to this as we are facing some memory issues with our navigation meshes. I’ll get OOM errors on it once in a while that cause my scene to freeze entirely, and we’ve been trying to track this down a bit better. One issue that we noticed is this one which we are curious for your take on, Apparent memory leak in RecastJS, but I’m curious about what you say above in this thread about the mesh simplification value being one of the properties that could be tweaked to not blow up the memory allocation.

We’ve got this going for our navMeshParameters:

let navMeshParameters = {
cs: 0.2,
ch: 0.2,
walkableSlopeAngle: 20,
walkableHeight: 4,
walkableClimb: 4,
walkableRadius: 3,
maxEdgeLen: 12,
maxSimplificationError: 1.3,
minRegionArea: 8,
mergeRegionArea: 20,
maxVertsPerPoly: 6,
detailSampleDist: 6,
detailSampleMaxError: 1
};

I know that bringing the cs will help us here, but how would you recommend tweaking the other properties?

CC @SirFizX

1 Like

Parameters that will have the biggest impact on memory usage are cs and ch. They determine the cell size of the voxelisation. The lower the value = the smaller cell = bigger precision = more cells = more memory. Concerning the simplification, it also has an (lower) impact on memory. Depending on your scene size and precision of the resulting navmesh, you will have to find ‘good’ values. Usually, I test with high values of cs and ch, then decrease the value until I find a good spot with precision/time to process/memory usage.