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 check if there is a stored world anchor?

SamJaSamJa
edited February 2017 in Questions And Answers

Im using the Holotoolkit's TapToPlace so I can anchor my game to a spot in the room. But the problem is the walls of the mapped space get in the way of tapping things, so i wanted to deactivate the mapped space after the anchor is set. When restarting the app or scene, the only way I can do this is by checking if there is at least one anchor stored first.

As far as I can tell the variable for storage is anchorStore, but I can't say "if(anchorStored != null)" because it being null means something else.

Best Answer

Answers

  • Options
    stepan_stulovstepan_stulov ✭✭✭
    edited February 2017

    Not sure how to do this with the HoloToolkit but basically at the core of any "placing" or "tapping" functionality is a raycast using Physics.Raycast() function that finds intersection of a ray with a collider within the layers specified by a layer mask. So you can basically play around with those layer masks to ignore what you don't want and only raycast against what you do.

    Spatial mapping ("mapped space") by default has layer 31.

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

  • Options
    SamJaSamJa
    edited February 2017

    @HoloSheep

    The "map" I refer to is the stored mesh of a room I scanned in using the Holotoolkit's Spatial Mapping. As far as I can tell, that's the only way to get a unity project to know the room its in and understand what the room its in looks like. yet it can't seem to place an object in a specific place in that room so its there every time, which infuriates me.

    Sorry for rejecting your previous answer, but I can not make heads or tails of it. This "TapToPlace" script in the Holotoolkit is the only thing I've been able to find to place a world anchor in any respect, and it leaves a helluva lot to be desired. It puts a world anchor on a spot in the room by just dragging the object you want anchored to that spot, and I can't think of any other way to do it, because while I have seen stuff of the coordinate plain, I have been able to find nothing on how I'm supposed to know what the coordinates of the real-world place I want the anchor to be. Or how to tell an anchor to be placed there. And now that I look at all the stuff in holotoolkit about storing anchors and I'm even more confused.

  • Options
    SamJaSamJa
    edited February 2017

    @stepan_stulov said:
    Not sure how to do this with the HoloToolkit but basically at the core of any "placing" or "tapping" functionality is a raycast using Physics.Raycast() function that finds intersection of a ray with a collider within the layers specified by a layer mask. So you can basically play around with those layer masks to ignore what you don't want and only raycast against what you do.

    Spatial mapping ("mapped space") by default has layer 31.

    Which I figured, and to my knowledge that should meant that if I set the spatial mapping object to the "Ignore Raycast" layer, the cursor would no longer hit it. Except that doesn't work and it hits it regardless.

  • Options
    stepan_stulovstepan_stulov ✭✭✭
    edited February 2017

    @SamJa said:
    @HoloSheep

    The "map" I refer to is the stored mesh of a room I scanned in using the Holotoolkit's Spatial Mapping. As far as I can tell, that's the only way to get a unity project to know the room its in and understand what the room its in looks like. yet it can't seem to place an object in a specific place in that room so its there every time, which infuriates me.

    Sorry for rejecting your previous answer, but I can not make heads or tails of it. This "TapToPlace" script in the Holotoolkit is the only thing I've been able to find to place a world anchor in any respect, and it leaves a helluva lot to be desired. It puts a world anchor on a spot in the room by just dragging the object you want anchored to that spot, and I can't think of any other way to do it, because while I have seen stuff of the coordinate plain, I have been able to find nothing on how I'm supposed to know what the coordinates of the real-world place I want the anchor to be. Or how to tell an anchor to be placed there. And now that I look at all the stuff in holotoolkit about storing anchors and I'm even more confused.

    @SamJa , HoloToolkit is an unarchitectured pile of misc scripts for this-and-that in my humble opinion, although one may disagree. It's a good source of learning but I would not place it at the core of a bigger project. As least the last time I checked the kit it was so. And yes, it can be rather confusing. I personally don't use HoloToolkit unless as a reference. It's not an advice though, if it works for you - please do.

    I also agree with @HoloSheep , you may be trying to solve multiple problems at once.

    There are basically several almost independent components to persistent placement of objects:

    1. Forget about any anchors for a minute. Think they don't exist. You want to be able to tell the point in the environment you're looking at. This is simply finding a raycast intersection of you camera's forward vector with the spatial mapping collider (Unity's SpatialMappingCollider component). That collider is situated in layer 31 by default and from what I've gathered there may be a hardcoded value somewhere under Unity's hood (not confirmed but also not disproved) so I don't recommend moving spatial mapping to another layer. You simply raycast down to spatial mapping only and get the desired point. Simply give a layer mask to the raycast and say you're only interested in SpatialMapping.

    2. Now forget about SpatialMapping, raycasts etc. Once you positioned an object either by means of 1. or really by any other means you can tell HoloLens "hey, can you please make sure now, that my object is here, that it stays here in the most visually stable way while I'm walking around?". This is done by adding a WorldAnchor component to the game object and ONLY THAT. Once that is done, you lose control of manual adjustments to your object's position, they are simply ignored. So basically being anchored and being manually moved are two mutually exclusive processes. To be able to manipulate object's position again you need to destroy the anchor component, move the object and add a new anchor again, obviously. Anchors also have isLocated flag and tracking change event so even if an anchor is added, it may become located or unlocated again. You can subscribe to the event and choose the reaction of your liking like simply hiding the object when it's not located. Bear in mind that world anchors as explained now are not persistent. This will work within one launch and there won't be any world anchors attached in the next launch. Which leads us to 3.

    3. Finally, you can make sure your objects stay anchored between relaunches. You can do this in two ways. The first way is using WorldAnchorStore. The store is simply a dictionary of anchors encoded in an unknown manner. There is only one store per app and also apps cannot share their stores with each other. You can get the list of anchors of the store, apply an anchor from the store onto an object, add or delete the anchors. Bear in mind the store is sensitive about adding anchors so you need to delete an anchor with the same id first before adding. You can get a store instance asynchronously by calling WorldAnchorStore.GetAsync(). The second way of persistence is WorldAnchorTransferBatch. This is in a way very similar to the store except it's not one-per-app, it's agnostic to where and how it's used as it can be serialized to bytes and deserialized back from those bytes. This enables you to anchor objects on one HoloLens and restore those anchored objects in their world positions on another HoloLens or basically any other wild scenario you can come up with. You can write the bytes to file, send to server or even send peer-to-peer to another HoloLens. When you apply an anchor from a store of from a transfer batch you don't add the WorldAnchor component to your game object directly anymore, you use the methods of the store (Load) or the batch (LockObject) accordingly. It's therefore important what the origin of the added anchor is.

    Does this make it a little bit clearer?

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

Sign In or Register to comment.