Robmaister / SharpNav

Advanced Pathfinding for C#
sharpnav.com
Other
542 stars 128 forks source link

When you load a mesh, calculate where the nearest Y axis is for a mesh #7

Open SallyDT opened 11 years ago

SallyDT commented 11 years ago

How would you do this?

When there is a mesh loaded, given that X and Z is given, how would you find the nearest Y axis position for the mesh?

Robmaister commented 11 years ago

The navigation portion of SharpNav is not written yet. Once it is, the navmesh will have an associated bounding volume tree that will make it very fast to do something like this.

At the moment, you could iterate over every polygon in a NavMesh, see if the XZ point is contained in the triangle, then compare it with the Y distance of the last triangle you tested that contained the point. This will be fairly slow, but it'll get the job done for now.

I'm starting to write some code to visualize a NavMesh/NavMeshDetail, so I can't say for sure that you're going to be given proper data from a NavMesh right now.

I'll leave this issue open until I start on the navigation portion and can provide some sample code for doing this.

SallyDT commented 11 years ago

I'll explain what the use-case is:

When the game-server loads, it loads twice - the meshes and the navigation mesh, headless where FPS = 0.

The game server has to check whether or not the move is valid or not.

X not being the min and max width of the terrain, Y not being the height of the terrain Z not being the min and max of the terrain.

X Z is easy to get because those are parameters from the origin X, Z of the terrain loaded and the min, max returned by the mesh.

The Y axis is a bit troublesome because it is on the mesh itself.

It would be something like a probe or function where input is X, Z, return a valid Y position. If Y = INF, then that position is NOT walkable.

There would also be function: where input is X, return TRUE or FALSE, where FALSE = position is not walkable. Or exceeds the mesh boundary. Example: -5, 0, 0, returns false 5, 0, 0 returns true. assuming the mesh loads into positive 0,0 space and where the mesh is 0-100, 0-5, 0-100.

SallyDT commented 11 years ago

It's not part of the navigation codes.

Here is the second use-case: I had some difficulties last week, so I converted from Collada to Wavefront OBJ format.

The game server uses 2 meshes - terrain and navigation meshes.

There's a fiddly problem because there is so few, so little reference codes in C# for terrain meshes. There's meshomatic but no way to get the world-space without loading OpenTK.

The terrain is represented thrice - one as a quad tree, terrain and as navigation mesh.

There are more than 3,000 NPCs on the terrain. As the user walks around, the NPCs are made visible or invisible depending on the situation. - that's what the quad tree is for.

Terrain - store the list of Y values so when the NPCs instantiate on the client, the player don't go underground, the NPCs don't go underground or float in the air either :)

When the NPCs instantiates, it stores the X, Z values and gets the terrain data to get the exact Y values.

To check if it is a valid move or note, the player can move to all locations where the mesh is, except where the height is +3, -3 of the previous Y value.

The navigation mesh executes the Recast, Crowd and detour algorithm so the NPCs move around.

Robmaister commented 11 years ago

For use-case 1, the algorithm I described will work, only you would return true if you ever found an overlapping polygon.

For the second use-case, that sounds like you just want to compare the Y values of the start/end points and reject the path if the difference is too high, which is simply checking the difference, unless I'm missing something.

I'd also like to re-iterate that I'm not actually done with the navmesh generation code yet, and anything about interacting with the navmesh I'd consider in the navigation section of the library (much like Detour is the navigation library for Recast-generated meshes). There hasn't been any code written to interact with a NavMesh yet.

Robmaister commented 10 years ago

Update: A large portion of Detour has been ported (though some possible bugs in PolyMeshDetail may hinder you), both use-cases should be possible to do now. The API for doing so is probably going to be somewhat awkward at the moment though. I'm working on refactoring a lot of it right now.