Navigation Mesh Pathfinding - Critter AI (port of Recast)

Aralox

08-01-2012 04:29:43

Update: I have been using CAI for a while now, and it is great! The Mesh to Navmesh class I wrote can be found a few posts down.

Hey guys, im new to MOGRE (and OGRE), and have collected a few libraries on my quest to make a game :)

I'm looking for a good navigation mesh pathfinding library. I find recast to be perfect, and have used a port of it for Unity in the past.
I recently discovered Critter AI (http://www.critterai.org/) which is also a port of Recast, but with no dependencies.

Has anyone here used it before? What do you think of it?
I want to use it, but am trying to find a way to use a pre-existing mesh as a navigation mesh, instead of using one generated by recast.
Has anyone run into this problem before, and know of any useful classes to help me with this?

Thanks for any tips and advice,
Aralox

Tubulii

12-01-2012 09:57:52

I looked around and found no navigation library like recast. I tried to make a wrapper for it using SWIG. It worked but I have NO expierence in c++ -> Every single error is terrible. But It is possible. I was able to inject all mesh data into recast (or load it from file), cook it and get the navmesh back, do raycast, pathfinding, ... but I stopped it because I run into several Access Violation exceptions (my c++ code seems to be wrong :wink: ).

I looked at Critter, too, but I never used it.

Aralox

13-01-2012 00:29:59

Wow looks like that was quite a difficult task, good job on making it work! I dont think I can manage that though :P
I'm making good progress with CAINav, so I'll see where I go, and post here if I manage to write up a class for loading a custom navmesh.

Tubulii

14-01-2012 14:41:37

Wow looks like that was quite a difficult task, good job on making it work! I dont think I can manage that though :P
Oh, SWIG does that automatically, just parse the headers and ready. And again, I stopped because it was unstable -> unuseable.

And good luck. I am looking forward to it...

Aralox

02-02-2012 12:49:22

Hey there lumen, I managed to write up a working mesh importer, and now i have CAI (read: Recast) navigation mesh pathfinding working! :D

Here is the extended discussion that helped me write it:
http://groups.google.com/group/crittera ... 8fd9b3e401

Here is the MeshToNavmesh class I wrote (and a few debug draw classes to view it):
http://www.box.com/s/2o9fyjnb3lx71cxajxho

Hope it helps you, and others! :)
Aralox

PS: I might put this up on the wiki sometime, if there is enough interest

Tubulii

02-02-2012 17:39:51

Thanks, how complex is the integration into mogre? Are there any other dependencies beside CAI (Unity?)?

Aralox

02-02-2012 23:07:01

Its actually pretty easy - and no, you dont need Unity. I wrote more about the dependencies in the MeshToNavmesh class, but basically the only necessary dependencies you need are the ones
provided by Critter AI. (and Mogre, for us)

Its actually possible to use navmesh pathfinding by letting CAI (Recast) generate the navmesh for you (which is how it was intended to be used), but I like to visually see my navmesh generation, so
I am using a Recast demo program which generates and saves navmeshes. I fix up these navmeshes in blender, then import them using the class I wrote.

Here is an example of querying the navmesh for a path (it is pretty drawn out, as I was trying to learn it properly, but there are faster ways to do it, eg. the overload of FindPath() which I commented out.

private void TestNavmesh()
{
NavStatus status;
NavmeshQuery query;
float[] vagueStartPoint = { -8, 0.6f, -3 };
float[] vagueEndPoint = { 16.3f, 0.8f, 4.5f };
uint startPoly;
uint endPoly;
float[] startPoint = new float[3];
float[] endPoint = new float[3];
float[] extents = { 2, 2, 2 };

status = NavmeshQuery.Build(navmesh, 100, out query);
Console.WriteLine("Status returned when NavmeshQuery was built: " + status);

NavmeshQueryFilter filter = new NavmeshQueryFilter();
filter.IncludeFlags = 1;

status = query.GetNearestPoly(vagueStartPoint, extents, filter, out startPoly, startPoint);
Console.WriteLine("\nStatus of startPoint getNearestPoly: " + status);
Console.WriteLine("Start polyref: " + startPoly + " startpoint: (" + startPoint[0] + ", " + startPoint[1] + ", " + startPoint[2] + ")");

query.GetNearestPoly(vagueEndPoint, extents, filter, out endPoly, endPoint);
Console.WriteLine("\nStatus of endPoint getNearestPoly: " + status);
Console.WriteLine("end polyref: " + endPoly + " endpoint: (" + endPoint[0] + ", " + endPoint[1] + ", " + endPoint[2] + ")");

uint[] path = new uint[100];
int pathCount;

status = query.FindPath(startPoly, endPoly, startPoint, endPoint, filter, path, out pathCount);
//status = query.FindPath(ref startPoly, ref endPoly, vagueStartPoint, vagueEndPoint, extents, filter, path, out pathCount);

Console.WriteLine("\nStatus of FindPath: " + status);
Console.WriteLine("Pathcount: " + pathCount);

//MessageBox.Show( Debug.ToString(navmesh.GetTile(0).GetHeader()));
}



And In your CreateScene method:

Navmesh navmesh = new MeshToNavmesh().MogreLoadNavmesh("yourNavmesh.obj");

//If you want to see it
NavDebug.Singleton.Initialise(mSceneMgr, 0.9f);
DebugDraw.Singleton.Initialise(mSceneMgr, 0.9f);
NavDebug.Singleton.Draw(navmesh);

Tubulii

03-02-2012 15:53:02

Thanks, i will look at it. But shouldn't it be possilible to inject meshdata into CAI and cook it there (and get the cooked navmesh back)? I managed to do so in my horrible Recast wrapper and it was very easy. The step with the recast demo is quite ... inefficient ... but of course possible.

Aralox

03-02-2012 23:40:23

Yup thats definitely possible, I just haven't done it :P
I need precise navmeshes (for an RTS game), so I need to be able to edit the mesh externally. I think CAI has a way of serializing generated navmeshes, but I dont know if it
does so In a convenient format usable by blender; but in any case I prefer the visual editor of the recast demo. So I dont mind the inefficiency :P (its more a part of my workflow, really)

JuggernautOGRE

28-06-2012 07:52:14

Can anybody help about how to use OpenSteerDotNet library (http://code.google.com/p/opensteerdotnet/) in OGRE ? The is no documentation available on how to use those cs files. Please help.

Tubulii

02-07-2012 19:21:25

Can anybody help about how to use OpenSteerDotNet library (http://code.google.com/p/opensteerdotnet/) in OGRE ? The is no documentation available on how to use those cs files. Please help.
Sorry, but I never used it. Anyway I suggest to create a new topic, its another topic.

JuggernautOGRE

04-07-2012 10:00:19

What did you use instead of opensteer ?

Tubulii

04-07-2012 10:31:38

What did you use instead of opensteer ?
Recast and Detour. Its an navigation mesh and pathfinding library (both written in plain c++). And Critter is an port of it (but with NO useful documentation).
Recast makes the navigation mesh and Detour provides pathfinding, crowd behaviour (with local steering) and obstacles. I guess most of the features can be used with Critter AI.
But I guess its not a full replacement of a real steering library. But first you need a path (for the AI)(->Recast and Detour) and when you can use steering (-> OpenSteer or something similar).

By the way: OpensteerDotNet is a port of Opensteer -> Opensteer has examples and documentation. Take a look at the source code. Unmanaged and managed code should the similar enough.

Edit: Just found SharpSteer: Homepage. It's written for XNA but its a port of OpenSteer, too, and even its written for XNA, SharpSteer is an non-graphical library: Conversion should be easy. Beside that, you could use their samples and docu.

Edit2: Take a look here. A list of AI middleware. 99% of them is commercial except: Recast and Detour, OpenSteer and SharpSteer.