Hello everyone.

The Mixed Reality Forums here are no longer being used or maintained.

There are a few other places we would like to direct you to for support, both from Microsoft and from the community.

The first way we want to connect with you is our mixed reality developer program, which you can sign up for at https://aka.ms/IWantMR.

For technical questions, please use Stack Overflow, and tag your questions using either hololens or windows-mixed-reality.

If you want to join in discussions, please do so in the HoloDevelopers Slack, which you can join by going to https://aka.ms/holodevelopers, or in our Microsoft Tech Communities forums at https://techcommunity.microsoft.com/t5/mixed-reality/ct-p/MicrosoftMixedReality.

And always feel free to hit us up on Twitter @MxdRealityDev.
Options

how to find the nearest wall to place an object on it at the beginning of the game?

Hi,

is there sample code demonstrating how to use the spatial mapping features to find the nearest wall?
id the PlaneFinding.FindPlanes method the way to go?

I want to automatically place some objects (in unity) to the nearest wall from the gamer when the app is started.

Best Answer

Answers

  • Options
    ContextVRContextVR ✭✭✭

    After you're done scanning the room, you can get the list of all vertical planes, then sort them by distance from camera and get the first element. You can also go through the list while keeping a variable pointing to the wall that's closest so far, and you'll have the closest wall after going through all the elements.

    You'll have to decide which point on the plane to use to calculate distance from camera. You can simply use transform.position, which I think is the centroid of all corners for planes returned by PlaneFinding.

    float distance = Vector3.Distance(Camera.main.transform.position, plane.transform.position);
    

    Take a look at the Planetarium example from Holographic Academy:
    https://developer.microsoft.com/en-us/windows/holographic/holograms_230

    Find a script called SpaceCollectionManager, which performs what you're looking to achieve: finds the nearest wall to put Placeable objects on.

  • Options
    JeromeJerome ✭✭

    yes... appear to be this :)
    mmm... for now my object putted in the collection is not display at all...
    I have to diagnose this.

  • Options
    ContextVRContextVR ✭✭✭

    How did you create the object that you want to display? Is it a prefab that you're putting into the SpaceCollectionManager list of prefabs to assign to vertical surfaces? It needs to have a Placeable script attached to it with Placement set to Vertical.

  • Options
    JeromeJerome ✭✭

    yes, its a prefab, starting with an empty object, then with child cylinders.
    I have the peacable script setup to vertical on it.
    and the placeonwall and the interactible ones.
    I'll do another try by setting up a second prefab in the collection list

  • Options

    @ContextVR said:
    After you're done scanning the room, you can get the list of all vertical planes, then sort them by distance from camera and get the first element. You can also go through the list while keeping a variable pointing to the wall that's closest so far, and you'll have the closest wall after going through all the elements.

    You'll have to decide which point on the plane to use to calculate distance from camera. You can simply use transform.position, which I think is the centroid of all corners for planes returned by PlaneFinding.

    float distance = Vector3.Distance(Camera.main.transform.position, plane.transform.position);
    

    Take a look at the Planetarium example from Holographic Academy:
    https://developer.microsoft.com/en-us/windows/holographic/holograms_230

    Find a script called SpaceCollectionManager, which performs what you're looking to achieve: finds the nearest wall to put Placeable objects on.

    It worked great for me, except one problem I had was that some of the objects are inside of the walls as opposed to along them, any fix for this?

Sign In or Register to comment.