Pathfinding with spatial mapping

edited November 2017 in Questions And Answers

Background:
I am building a POC (proof of concept) project that uses spatial mapping to be upgraded at one point to spatial understanding and models, that come towards the user. All elements are in place using spatial mapping from the toolkit and imported models etc. Modifying examples from 230 my models are placed somewhat correctly! Now, I want them to come towards the camera location.

Problem:
It is my understanding that you need to use navmeshes and pathfinding. So I tried and failed to implement NavMeshComponents on my project and didn't get it to work.

Is there a common way of handling pathfinding with spatial mapping/understanding?

The forums seems to have no conclusive response and therefore uncertain as to how to proceed. Is there an a solution and an example of code that can be implemented?

Thank you for any assistance.

Answers

  • Hey, @jepsteinmobile

    I'm no expert in NavMesh, but here is what I found:
    https://unity3d.com/learn/tutorials/topics/navigation/baking-navmesh-runtime

    Does it help?

    Building the future of holographic navigation. We're hiring.

  • It looks promising and thanks for finding it. I am going to go through it and update this, hopefully they will explain how to interface with the spatial map layer.

    Will keep this open. But thank you if you find anything about connecting the mesh to spatial mapping that would be great.

  • Here is another recent thread about the topic:
    https://forums.hololens.com/discussion/comment/18901

    Building the future of holographic navigation. We're hiring.

  • I ended up using A* with some slight mods (very minor) and pathfinding is working with the spatial mesh. It still isn't a perfect solution but workable a this point.

  • Hello Jespsteinmobile. I use A* and navmeshbuilding but did not find how to extract Hololens Navmesh and inject it in A* component. Can you tell me how did you do it? Thanks :)

  • @jepsteinmobile Can you describe what you modified in a* to get it up and running with hololens?

  • I did some pathfinding using the spatial mapping a while ago. I'll give a brief overview of the approach:

    I used the free version of the "A* Pathfinding" library for Unity: https://arongranberg.com/astar/ . The way this library works is that it defines a 2D grid where each cell on the grid is either navigable or not navigable, and it uses that for pathfinding. These grids can be created or updated at runtime without needing to pre-generate navmeshes or anything beforehand. Instead, you can use raycasts against geometry to determine what is navigable.

    In my approach, I had two layers for geometry: (1) the spatial mapping layer, and (2) a layer representing a "cutoff" location near the floor. On the cutoff layer, I created an invisible plane that would be automatically placed a few inches above the spatial mapping floor (you can determine this by doing a raycast against the spatial mapping straight down from the user's current position, and using that Y position as the floor location). Using the A* pathfinding library, I calculated navigable spaces by the following logic:

    • For each cell in the A* grid, define a ray with an origin somewhere above the user's head (a meter above worked well for me) and a direction pointing straight downward (negative Y direction)
    • Do a raycast along this ray. If the closest hit is the "cutoff" quad that is just above the spatial mapping floor, then there is (probably) nothing in the space that would interfere with navigation, and so the space is navigable.
    • On the other hand, if the closest raycast hit instead hits something on the spatial mapping layer, then that means there is some part of the spatial mapping that is above the floor (like a table), and is not navigable.

    The A* library also has support for doing this sort of raycasting with cylinders rather than 1-dimensional rays, so you can see if a region of space is empty or full.

    You will need to experiment with the resolution of this A* grid. If the space between grid cells is too large, then narrow pathways that are physically navigable will not be marked as navigable. If the spacing is too small, then it will think that tiny gaps in the mesh are navigable even though a user would not be able to physically move through them.

  • I know I have been away from this for a bit - But thought I would come back. The mods that I did I will find for you- it was mainly targeting in the seeker code I believe. there was also an error with the build that aron helped with - in terms of it not being compatible. I know there is a newer version and have not tried it yet.

    I plan on uploading most of my 'game' code at one point as it does work as a nice little tutorial of some of what to do and some of what not to do. It is messy because getting things to work right with Unity/Hololens/Holo-toolkit is often not easy to figure out.

    Why pathfinding (which is necessary is such a pain in the neck) and doesn't seem to be properly supported by Unity or anybody else is frustrating and as far as I am concerned hurts the platform.

  • Dan- thank you for your detailed input I found it interesting. I also get a basic pathfinding done by creating an object after the spatial mesh and having it move towards the headset. For the most part you can adjust for the floor and the object does attempt to move past objects in the way.

    Having said that can you share elements of your project that you got working with A*? If not no big deal. Just curious how it looks in project form,

Sign In or Register to comment.