Looking for a good solution for server-side NavMesh

I’m trying to add AI controlled enemies to my multiplayer game 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

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

Has anyone else been able to do this?

I’m pretty sure that you can run meep 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.

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 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… although I would try to do that offline instead, if you can.

1 Like

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

Thanks Don!

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.

1 Like

Eyy you’re the man @Mugen87!

1 Like

@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.

You’ll probably need something roughly like this: 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.

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

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 );
}
2 Likes