see pathfinding3d
Are you seeking to identify the nearest triangle based on known coordinates? In pathfinding3d, the get_closest_node function might be of assistance. I recommend exploring this library; it is remarkably efficient.
The get_closest_node_id function can be of assistance. By setting the final parameter, check_polygon, to false, the returned result need not be restricted to a node on the navmesh; instead, it will identify the nearest node in the entire space. During the algorithm’s construction phase, a k-d tree is employed to optimize spatial searches, ensuring exceptional speed. Furthermore, as it is implemented in WebAssembly (WASM), its performance is 10 to 20 times faster than that of JavaScript.
@ manthrax
I need the nearest point on an object surface exaclty for the case described in the first link : To get my characters to go back on the navigation mesh.
Im trying to make it work but currently i struggle with the “Failed to load module script: Expected a JavaScript-or-Wasm module script but the server responded with a MIME type of “application/wasm”. Strict MIME type checking is enforced for module scripts per HTML spec.”
is it possible to make it work in native js browser without rebuild myself ? (i dont know about rust environment)
Could you share the error you’re encountering, or perhaps the most minimal reproducible code on GitHub? The WASM files under the /pkg/ directory should be functioning correctly and can be imported and executed as ES modules. I had to make some adjustments in both Vite and Webpack configurations. However, I still haven’t been able to reproduce your error.
I tried setting this up using an importmap and also got the error, Failed to load module script: Expected a JavaScript-or-Wasm module script but the server responded with a MIME type of “application/wasm
A major reason why this might not be implemented out-of-the-box on these libraries, is that the library can’t know in advance what kind of structures you’re using to segment your scene.
For instance If you are using a BVH to speed up your raycasts, the pathfinding library wouldn’t know about it, so its “find nearest surface to point” would be much slower than if you did it yourself using your acceleration structures.. so they may choose to omit exposing that kind of functionality entirely.
Otherwise people might try to use it and then complain “This pathfinding library made my app slow”.
This way the burden is on the user to control the time complexity of how they do operations like raycasting.
So that’s one good reason I can think of why they don’t include that functionality.
If you want an acceleration structure to make that raycasting to find the point really fast.. look into the excellent “three-mesh-bvh” library.