stutter when dynamically adding/removing navmeshes #405
-
In my game, I am doing what I think is a rather common thing, which is that I have split my world into chunks and am dynamically loading/unloading them as the user approaches/moves away from a zone. For now, I just created the most naive solution possible, which is that I conditionally render the zones as children of my navmesh (R3F) and use a I haven't looked into it yet, since I wanted to check if there are known solutions to this. One thing I am thinking about is using the tilecache, like I am with obstacles, but it doesn't "feel" like that's a correct solution, since these chunks aren't obstacles. Thanks in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 3 replies
-
So, I used the example provided here https://github.com/isaac-mason/recast-navigation-js/tree/next/examples/vite-worker-example, using a worker, and it works great! The time to generate a navmesh are somewhat longer, but comparable, but since they are done in a worker thread, there is no visible stutter at all! Very nice. However, when attempting to use a tilecache ( Thanks again! |
Beta Was this translation helpful? Give feedback.
-
I dug up this from the source: https://github.com/isaac-mason/recast-navigation-js/blob/main/packages/recast-navigation-generators/src/generators/generate-tile-cache.ts#L117C1-L123C6 const tcmp = new TileCacheMeshProcess((navMeshCreateParams, polyAreas, polyFlags) => {
for (let i = 0; i < navMeshCreateParams.polyCount(); ++i) {
polyAreas.set(i, 0)
polyFlags.set(i, 1)
}
}) Now, everything is working great 🎉 thanks for this amazing package! 🙏🏼 |
Beta Was this translation helpful? Give feedback.
-
Here's the result btw 20240703_073953.mp4 |
Beta Was this translation helpful? Give feedback.
-
Nice! Thanks for sharing 😁 It's also possible to build just the nav mesh tiles on a worker, and maintain one nav mesh on the main thread / another thread. This is what this demo does: This is not as straightforward to do with a TileCache right now though. In the c++ library itself the DetourTileCache takes more control over nav mesh building so it's less flexible, and also this library generally needs to expose more of the TileCache interface. |
Beta Was this translation helpful? Give feedback.
-
There's probably also an action here to improve the docs for importing/exporting a TileCache :) I've also considered having a seperate |
Beta Was this translation helpful? Give feedback.
-
@isaac-mason I think the implementation as it is now is pretty straight forward, once you get it, with the exception of |
Beta Was this translation helpful? Give feedback.
@GGAlanSmithee I've ended up splitting importNavMesh/exportNavMesh and importTileCache/exportTileCache as I've realised importNavMesh was unnecessarily creating tilecache structures when importing just a navmesh.
I've also added to the import/export tilecache readme section so hopefully the usage is clearer 🙂