Proper way to pass Navigation mesh

I am well into writing the new AI tutorial but since I have not developed a 3d game before I am reduced to what my instincts tell me to do when passing the navMesh around and I don’t want to mislead readers if I am wrong.

Please correct me if anything below is better done a different way.

For a production game I would add the pre-generated navigation meshes to the assets folder. I do this now by storing the geometry in a .j3o.

My instincts tell me to load the Mesh into the Spatials UserData upon its creation so that when the pathfinding control is added to the spatial, all it does is grab it from UserData.

        //load navMesh into spatial UserData
        charNode.setUserData(DataKey.NAVMESH, loadNavMesh(DataKey.NAVMESH).getMesh());

This means each spatial can have its own navigation mesh. Which is desirable since some NPC’s may need a custom mesh based off their size. assetManager will also clone duplicate meshes which is also desirable.

Any comments are appreciated.

It has a node and it has a navmesh amongst other things. Why not just create an object to store it all? I presume you do already. So why (ab)use userdata?

Do you mean .obj file?

You would need to pass Application to the path-finding control to load the object. As I understand things, States are used for that purpose and UserData is for passing things like this around.

I think what your saying is that its best to have a reference to the object in the control rather than the spatial carrying around the mesh in UserData?

I am trying to understand why you say this?

This is from the SDK,

Whats the difference between NPC/PC UserData and rootNode UserData?

I mean why have you lost the reference to the player/mob/enemy/thing? That would contain all the data that makes it what it is, including a pathfinding mesh if you wished. Why even store it in userdata at all?

Presumably something like this would be interfaced out so that the method to retrieve the mesh is expected on the objects that need it.

EDIT: And the more I think about it the more it makes complete sense. You shouldn’t store things that aren’t visible in the scene - in the scene (hence extending Node and storing all manner of useless stuff is not recommended). I would like to know of a viable use-case for userdata out of interest tbh. It must be there for a reason :stuck_out_tongue:

For example, I tag spatials all the time with their entity IDs. User data is useful for all kinds of stuff you want to hang on a spatial without gaining the overhead of a new update() (x 2) call every frame (like you would with a control).

1 Like

And whenever you want to save data bound to a spatial within a j3o, which is why the sdk chose this way. You load the geometry of the world/map and immediately are able to reference the nav mesh

1 Like