# Looking for a good solution for server-side NavMesh

**URL:** <https://discourse.threejs.org/t/looking-for-a-good-solution-for-server-side-navmesh/11142>\
**Category:** Questions\
**Tags:** game-dev\
**Created:** [December 1, 2019, 10:04pm UTC](https://discourse.threejs.org/t/looking-for-a-good-solution-for-server-side-navmesh/11142 "2019-12-01T22:04:26Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Snubber](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/snubber/32/7563_2.png) [@Snubber](https://discourse.threejs.org/u/Snubber)\
**Post date:** [December 1, 2019, 10:04pm UTC](https://discourse.threejs.org/t/looking-for-a-good-solution-for-server-side-navmesh/11142/1 "2019-12-01T22:04:26Z")

</div>

I’m trying to add AI controlled enemies to my multiplayer game [https://bowdown.io](https://bowdown.io)

I’ve tried Yuka, but it seems that it’s not quite ready for running on a node server: [https://github.com/Mugen87/yuka/issues/14](https://github.com/Mugen87/yuka/issues/14)

At this point I’m willing to try anything, even if it isn’t JavaScript.

Has anyone else been able to do this?

---

<div class="post-metadata">

**Author:** ![Usnul](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/usnul/32/2355_2.png) [@Usnul](https://discourse.threejs.org/u/Usnul)\
**Post date:** [December 1, 2019, 10:41pm UTC](https://discourse.threejs.org/t/looking-for-a-good-solution-for-server-side-navmesh/11142/2 "2019-12-01T22:41:53Z")

</div>

I’m pretty sure that you can run [meep](https://discourse.threejs.org/t/meep-a-game-engine/10098) on server-side. It’s not browser-specific. You have navigation tools in there, mostly grid stuff though, and you have behavior trees. It’s all open source under MIT. If you have some specific questions - i can provide a bit of support.

---

<div class="post-metadata">

**Author:** ![donmccurdy](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/donmccurdy/32/33209_2.png) [@donmccurdy](https://discourse.threejs.org/u/donmccurdy)\
**Post date:** [December 2, 2019, 12:50am UTC](https://discourse.threejs.org/t/looking-for-a-good-solution-for-server-side-navmesh/11142/3 "2019-12-02T00:50:42Z")

</div>

Are you asking about generating a navmesh serverside? Or controlling the AI? If you want to do pathfinding on a navmesh you already have, [https://github.com/donmccurdy/three-pathfinding](https://github.com/donmccurdy/three-pathfinding) will do that. But it’s probably not as full-featured for a game as something like Yuka or Meep.

I have an example of serverside navmesh creation here: [https://github.com/donmccurdy/aframe-inspector-plugin-recast](https://github.com/donmccurdy/aframe-inspector-plugin-recast)… although I would try to do that offline instead, if you can.

---

<div class="post-metadata">

**Author:** ![Snubber](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/snubber/32/7563_2.png) [@Snubber](https://discourse.threejs.org/u/Snubber)\
**Post date:** [December 2, 2019, 1:29am UTC](https://discourse.threejs.org/t/looking-for-a-good-solution-for-server-side-navmesh/11142/4 "2019-12-02T01:29:42Z")

</div>

Oh cool! I see you used Recast, I was thinking about using that too. This looks like a good option.

Thanks Don!

---

<div class="post-metadata">

**Author:** ![Mugen87](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/mugen87/32/5645_2.png) [@Mugen87](https://discourse.threejs.org/u/Mugen87)\
**Post date:** [December 2, 2019, 1:15pm UTC](https://discourse.threejs.org/t/looking-for-a-good-solution-for-server-side-navmesh/11142/5 "2019-12-02T13:15:58Z")

</div>

> [@Snubber](#):
>
> I’ve tried Yuka, but it seems that it’s not quite ready for running on a node server:

I’ve published a new version today which makes the handling of `NavMeshLoader` more node friendly. There is now a `parse()` method that can be used if you load the file contents e.g. via `fs`.

---

<div class="post-metadata">

**Author:** ![Snubber](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/snubber/32/7563_2.png) [@Snubber](https://discourse.threejs.org/u/Snubber)\
**Post date:** [December 2, 2019, 6:26pm UTC](https://discourse.threejs.org/t/looking-for-a-good-solution-for-server-side-navmesh/11142/6 "2019-12-02T18:26:07Z")

</div>

Eyy you’re the man @Mugen87!

---

<div class="post-metadata">

**Author:** ![Snubber](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/snubber/32/7563_2.png) [@Snubber](https://discourse.threejs.org/u/Snubber)\
**Post date:** [December 3, 2019, 7:10pm UTC](https://discourse.threejs.org/t/looking-for-a-good-solution-for-server-side-navmesh/11142/7 "2019-12-03T19:10:01Z")

</div>

@donmccurdy I can’t seem to get GLTFLoader to work in node when I try to use `three-pathfinding`. I keep getting: `ReferenceError: THREE is not defined`

It really feels like I’m swimming upstream with this whole pathfinding on a nav mesh thing. I mean there has to be a tool that does it somewhere, that can work on a server.

---

<div class="post-metadata">

**Author:** ![donmccurdy](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/donmccurdy/32/33209_2.png) [@donmccurdy](https://discourse.threejs.org/u/donmccurdy)\
**Post date:** [December 3, 2019, 7:15pm UTC](https://discourse.threejs.org/t/looking-for-a-good-solution-for-server-side-navmesh/11142/8 "2019-12-03T19:15:54Z")

</div>

You’ll probably need something roughly like this: [https://gist.github.com/donmccurdy/323c6363ac7ca8a7de6a3362d7fdddb4](https://gist.github.com/donmccurdy/323c6363ac7ca8a7de6a3362d7fdddb4) … in general it takes a bit of work to use three.js tools in node.js, where WebGL does not exist. The jsm/ versions of files may be easier to use than the js/ versions.

---

<div class="post-metadata">

**Author:** ![arpu](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/arpu/32/6583_2.png) [@arpu](https://discourse.threejs.org/u/arpu)\
**Post date:** [December 3, 2019, 7:29pm UTC](https://discourse.threejs.org/t/looking-for-a-good-solution-for-server-side-navmesh/11142/9 "2019-12-03T19:29:08Z")

</div>

maybe you can use [https://github.com/robertlong/recastCLI.js](https://github.com/robertlong/recastCLI.js) but it needs wasm module in nodejs

---

<div class="post-metadata">

**Author:** ![Snubber](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/snubber/32/7563_2.png) [@Snubber](https://discourse.threejs.org/u/Snubber)\
**Post date:** [December 3, 2019, 10:54pm UTC](https://discourse.threejs.org/t/looking-for-a-good-solution-for-server-side-navmesh/11142/10 "2019-12-03T22:54:20Z")

</div>

That did the trick @donmccurdy, thank you!

For anyone that runs into the same problem, here is what worked for me:

```
const fs = require('fs');
const THREE = global.THREE = require('three');
global.TextDecoder = require('util').TextDecoder;
require('three/examples/js/loaders/GLTFLoader.js');
const { Pathfinding } = require('three-pathfinding');
const content = fs.readFileSync('./lowildNavMesh.glb');
global.THREE = THREE
const loader = new THREE.GLTFLoader();
const pathfinding = new Pathfinding();
let navmesh;
    
    loader.parse( trimBuffer( content ), '', ( gltf ) => {
        gltf.scene.traverse((node) => {
            if (node.isMesh) navmesh = node;
        });
        pathfinding.setZoneData(ZONE, Pathfinding.createZone(navmesh.geometry));
    }, ( e ) => {
        console.error( e );
    });

function trimBuffer ( buffer ) {
    const { byteOffset, byteLength } = buffer;
    return buffer.buffer.slice( byteOffset, byteOffset + byteLength );
}
```
