Search Unity

Question Navigation with NavMesh in a know room

Discussion in 'AR' started by Underworse, Jan 21, 2022.

  1. Underworse

    Underworse

    Joined:
    Jun 17, 2021
    Posts:
    7
    Hello dear AR developers!

    I want to create a navigation application using the HoloLens2.

    Current situation
    So far I have created a user menue with possible destinations in a list received from a server. The elements in this list have Unity coordinates (Vector3, e.g. (1.0f, 0.2f, 0.8f)) and will spawn as soon as the user hits the "Start navigation" button. Currently I am using a solver (Directional Indicator to be more specific) but it is not a real navigation because the solver does not navigate but only points at the destination.

    Talking about navigation I immediately thought of Unity's NavMesh system. Unfortunately Microsoft states that "the built-in NavMesh functionality in Unity cannot be used with spatial mapping surfaces. This is because spatial mapping surfaces aren't known until the application starts, ..." (Source: https://docs.microsoft.com/en-us/windows/mixed-reality/design/spatial-mapping#navigation).

    Now here is the clue: I already know the room's area (width and length) and additionally, on which parts of the area I can walk on and on which I don't. Optimally there is an arrow or a line that the user can follow always targeting in the right direction without crossing the not walkable area.

    The picture given below shows what I really want.

    Path.png

    My app knows the room (big black square) and also not walkable area (area within red square). Now it should not see the black line as an option. As soon as it starts it knows that the user can't cross the read area (e.g. a wall, table, shelf, cars crossing this area). It should navigate the user by letting him follow the blue line.


    What I have tried so far
    • Reconstructing the room using Unity's Terrain and Cube GameObjects. Unfortunately Unity won't let me bake with NavMesh. Appearently because my GameObjects are too small? As soon as I hit "Bake" it says in the bottom right corner that it is creating a NavMesh, but nothing is created afterwards.
    • Following Vuforia's Guide (https://library.vuforia.com/develop-area-targets/using-unitys-navmesh-navigation-area-targets) but there I am stuck again because I can't create my own NavMesh.

    What I want to know
    My questions know are:

    • Are there already known or easy ways to implement this navigation for my app?
    • Can I use the spatial mapping provided by HoloLens2 to forbid movement through obstacles during run time?
    • Somehow the scaling of my app might be a problem for the NavMesh, but a cube for example has the scaling of (0.1f, 0.1f, 0.1f) and has the perfect size. Giving it a size of 1.0f results in almost seeing nothing else. Is there a good way to create a NavMesh for HoloLens?
    • Can the NavMesh be created during run time? I want my App to be as dynamic as possible so I want to get the information about the room from a server, then build the NavMesh and then apply it for the navigation.
    I know there are a lot of questions and I am already thankful for everybody reading this.
    Thanks in advance!


    Best regards,
    David
     
    Last edited: Jan 21, 2022
  2. Underworse

    Underworse

    Joined:
    Jun 17, 2021
    Posts:
    7
    Hello everyone!

    Just wanted to update you about my current status.
    I was finally able to create a working navigation for my case.

    Mandatory elements
    • Create a good representation of your environment. In the picture below you can see my GameObject "Environment" with the GameObject "Floor" and 7 wall elements. I recreated my room in Unity with all the correct lengths and widths (see picture of my first post). A very nice addition provided by the Mixed Reality Toolkit is that you can create a special material for the HoloLens and give it to the wall elements. In your project's Assets: Right-click > create > material, click on the created material and name it wall. Click on it and in the shader use VR > SpatialMapping > Occlusion and attach it to the Mesh Renderer > Materials of your wall GameObjects. Now Unity knows that those walls exist in your real world environment (and your HoloLens knows them, too!). But be aware: It destroys Unity's "Play mode" so better deactivate it while testing. Now finally select your Environment GameObject and create a NavMesh (see Unity Manual).
    • Use Unity's Position Constraint and Line Renderer. The GameObject "Indicator" in the given picture has those two components. Your Main Camera has to be the position constraint's source. Now add a script for navigation to this Indicator GameObject and use Unity's NavMesh.CalculatePath() method.

    ExampleNavigation.png


    I hope I was able to help anybody looking for a solution!
     
  3. Nilzfar

    Nilzfar

    Joined:
    Feb 2, 2021
    Posts:
    1
    Hello,
    Thank you for sharing your experience. I am doing something similar. did you also visualize the path? I am using LineRenderer for visualizing the path but when I deployed it to the HoloLens 2 device, I don't see the line. Do you have experience with that?