Hello everyone.

We have decided to phase out the Mixed Reality Forums over the next few months in favor of other ways to connect with us.

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.

The plan between now and the beginning of May is to clean up old, unanswered questions that are no longer relevant. The forums will remain open and usable.

On May 1st we will be locking the forums to new posts and replies. They will remain available for another three months for the purposes of searching them, and then they will be closed altogether on August 1st.

So, where does that leave our awesome community to ask questions? Well, there are a few places we want to engage with you. 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. And always feel free to hit us up on Twitter @MxdRealityDev.

Finding a random point inside the spatial map?

I'm trying to find random points inside of the spatial map to spawn objects. Any ideas as to how this can be accomplished? As of now, things can spawn outside of the map because my points are completely random.

Best Answers

Answers

  • PentosePentose ✭✭

    Random angle + distance should work.

    Pick a random rotation from the user's head and a random distance out from that rotation to the room mesh.

  • Jarrod1937Jarrod1937 ✭✭✭

    I'm interested in seeing what other ideas people have. I've been tackling this issue in my application as well. Assuming you're using Unity, my current thought process is this:

    • The Hololens user location must be inside the spatial mesh, to be otherwise should be impossible.
    • This is a known point you can know test around. For my application, I am ray casting 360 degrees, breaking the circle up into enough sections that the arc length at the scan distance is at a fine enough granularity that I need to find any obstructions in place to not place an object there or place an object before that obstruction.

    Another approach that I'm looking at it tying the random placement in with the path finding I already have implemented. It takes the spatial mesh and generates a grid graph (with height map) which you can use for placement. The grid points marked as inaccessible, simply don't place something there.

  • Jarrod1937Jarrod1937 ✭✭✭

    Ah, thanks for the code. For my purpose I'm thinking something simpler, but if that method fails I'll be looking at this spiral method.

  • Could you put out a large bounding box with collision, then raycast out at a random angle? Then place it on a random position between the position of your head and the position of your raycast hit?

  • Jarrod1937Jarrod1937 ✭✭✭

    @tacroy said:
    Could you put out a large bounding box with collision, then raycast out at a random angle? Then place it on a random position between the position of your head and the position of your raycast hit?

    Theoretically, yes, that should work, just reiterate if the random spot failed.
    In my mind, the idea should be to test to make sure your instanced object is within the spatial area with the least amount of checks. The spiral method looks like it'll solve the issue, but depending on your needs, something computationally simpler may do the trick. Of course the method to use also depends on how often you'll be doing this task and if it is during the initialization or during active play where it may impact frame rate.
    I'm having the user place the "goal," and then from there am having a ray cast at various angles performed to a certain distance, any that are good (no hits) are placed into an array, and then a random index is chosen for that array. This works well enough for my use. The downside of any raycasting method is that it assumes you only want a random spot within the visible area. If you want to place an object behind something, this method will fail as a raycast is inherently a line of sight test.
    That's why a navmesh or grid graph path finding design may be better, depending on your needs but can be a lot more computationally expensive (especially if you're updating the spatial mesh).

Sign In or Register to comment.