Azure Spatial Anchors is a cloud-based service that allows you to create and manage shared, persistent, and viewable spatial anchors in the real world. These anchors can be used to provide a common reference point for multiple devices to share and interact with.
To create a spatial anchor, you'll need to generate a unique key, which is done using the Azure Spatial Anchors SDK. This key is then used to create the anchor.
Azure Spatial Anchors uses a combination of computer vision and machine learning to determine the location and orientation of the device in relation to the anchor. This allows for accurate and reliable tracking of the device.
Worth a look: The Azure Key
Setting Up Azure Spatial Anchors
To set up Azure Spatial Anchors, you need to create a new anchor. This involves checking that an Azure Spatial Anchors session is running, as the application can't create or persist an anchor without it.
First, create or obtain an Unreal Scene Component that should have its location persisted. This is a crucial step in creating a new Azure Spatial Anchor.
Worth a look: How to Anchor a Dishwasher?
To construct and save an Azure Spatial Anchor for an Unreal Scene Component, you need to call the Pin Component for the Unreal Scene Component and specify the Scene Component's World Transform as the World Transform used for the AR Pin.
Next, call Create Cloud Anchor using the newly created AR Pin. This will create a new Azure Spatial Anchor.
You can also set the Azure Spatial Anchor expiration by specifying in seconds how long the anchor should be maintained by the service. This is done by calling the Create Cloud Anchor function with the Lifetime parameter.
Here's a step-by-step guide to creating a new Azure Spatial Anchor:
- Check that an Azure Spatial Anchors session is running.
- Create or obtain an Unreal Scene Component.
- Call the Pin Component for the Unreal Scene Component.
- Call Create Cloud Anchor using the newly created AR Pin.
- Set the Azure Spatial Anchor expiration.
Creating and Managing Anchors
Creating an Azure Spatial Anchor is a straightforward process that requires a running Azure Spatial Anchors session. To create an anchor, you need to check that the session is running, create or obtain an Unreal Scene Component, and then call the Pin Component for the Scene Component.
You'll also need to specify the Scene Component's World Transform as the World Transform used for the AR Pin. After that, you can call Create Cloud Anchor using the newly created AR Pin, set the anchor's expiration, and declare it as ready to save.
To save an anchor, you'll need to call Save Cloud Anchor, which is an asynchronous function that can only be called on a game thread event such as EventTick. This function may take multiple attempts to succeed, depending on the amount of spatial data created by the Azure Spatial Anchors session.
Here's a step-by-step process to create and save an anchor:
- Create an Azure Spatial Anchors session
- Pin the Unreal Scene Component to the world transform
- Create a cloud anchor using the AR Pin
- Set the anchor's expiration and declare it as ready to save
- Call Save Cloud Anchor on a game thread event like EventTick
Creating an Anchor
To create a new Azure Spatial Anchor, you need to check that an Azure Spatial Anchors session is running.
You'll also need to create or obtain an Unreal Scene Component that should have its location persisted. This component will serve as the anchor point for your augmented reality content.
To construct and save an Azure Spatial Anchor for an Unreal Scene Component, call the Pin Component for the Unreal Scene Component and specify the Scene Component's World Transform as the World Transform used for the AR Pin.
You'll then need to call Create Cloud Anchor using the newly created AR Pin. This will create a new Azure Spatial Anchor that can be shared among different users.
To set the anchor's parameters, you can specify the lifetime of the anchor in seconds, allowing you to control how long the anchor is maintained by the service.
Here's a step-by-step guide to creating an Azure Spatial Anchor:
- Call the Pin Component for the Unreal Scene Component.
- Specify the Scene Component's World Transform as the World Transform used for the AR Pin.
- Call Create Cloud Anchor using the newly created AR Pin.
- Set the Azure Spatial Anchor expiration by specifying the lifetime of the anchor in seconds.
- Declare the anchor as ready to save by adding it to a set of Azure Spatial Anchors needing saving.
Deleting an Anchor
Deleting an anchor is a crucial step in managing your Azure Spatial Anchor service. You can delete anchors by calling Delete Cloud Anchor.
This function is latent and can only be called on a game thread event, such as EventTick. This means you won't see it as an available blueprint function in custom blueprint functions.
To delete an anchor, flag it for deletion on a custom input event. Then, attempt to delete the anchor on the EventTick.
If the deletion fails, add the Azure Spatial Anchor to the set of anchors flagged for deletion and try again on later EventTicks. This ensures that the anchor is eventually deleted.
Connecting and Verifying Anchors
Connecting and verifying anchors is a crucial step in using Azure Spatial Anchors. You can connect anchors in a single session by creating a CloudSpatialAnchorSession and using it to create multiple anchors in different locations.
To verify anchor connections, you can issue a query for nearby anchors using a CloudSpatialAnchorWatcher and set the NearAnchorCriteria. If the query's result contains the target anchor, the anchor connection is verified. If not, you can try to connect them again.
Anchors might fail to connect due to underlying platform tracking issues or network errors during communication with the Spatial Anchors service. Here are some common reasons why anchors might fail to connect:
- The underlying mixed-reality or augmented-reality platform lost tracking during the process of connecting anchors.
- Because of a network error during communication with the Spatial Anchors service, the anchor connection couldn't be persisted.
Single Session Connection
Connecting anchors in a single session is a straightforward process. You simply walk to the first location and create Anchor A by using a CloudSpatialAnchorSession.
To create a connection between anchors, you need to use the same CloudSpatialAnchorSession. This is crucial, as it allows the Spatial Anchors service to maintain the relationship between anchors.
Here's a step-by-step guide to connecting anchors in a single session:
- Walk to the first location and create Anchor A by using a CloudSpatialAnchorSession.
- Walk to the second location. The underlying MR/AR platform tracks the movement.
- Create Anchor B by using the same CloudSpatialAnchorSession.
- Continue the procedure for the remaining anchors.
By following these steps, you can easily connect anchors in a single session and maintain their relationship through the Spatial Anchors service.
Multi-Session Connection
Connecting anchors over multiple sessions is a powerful feature of the Azure Spatial Anchors service. You can create and connect anchors at one time, and then later create and connect more anchors in a new session.
The process involves creating some anchors in one CloudSpatialAnchorSession, and then later locating one of these anchors using a new CloudSpatialAnchorSession. You can continue this procedure for more anchors and more sessions over time.
Curious to learn more? Check out: Azure Data Studio Connect to Azure Sql
Here's a step-by-step guide to connecting anchors over multiple sessions:
1. Create some anchors (Anchors A and B) in one CloudSpatialAnchorSession.
2. At a different time, locate one of these anchors (for example, Anchor A) by using a new CloudSpatialAnchorSession.
3. Walk to a new location, and the underlying mixed-reality or augmented-reality platform tracks the movement.
4. Create Anchor C by using the same CloudSpatialAnchorSession, and Anchors A, B, and C are now connected.
The Spatial Anchors service maintains this relationship, allowing you to connect anchors over multiple sessions. This feature is particularly useful for applications that require anchors to be connected across different sessions or locations.
Frequently Asked Questions
What are Azure spatial anchors?
Azure Spatial Anchors is a cloud-based service that enables multi-user, spatially aware mixed reality and augmented reality experiences. It supports HoloLens, iOS, and Android devices, making it a versatile platform for MR/AR app development.
Sources
- https://learn.microsoft.com/en-us/azure/spatial-anchors/concepts/anchor-relationships-way-finding
- https://azure.microsoft.com/en-us/products/spatial-anchors
- https://learn.microsoft.com/en-us/windows/mixed-reality/develop/unreal/unreal-azure-spatial-anchors
- https://blog.davemdavis.net/2019/05/16/a-look-into-azure-spatial-anchors/
- https://learn.microsoft.com/en-us/azure/spatial-anchors/concepts/guidelines-effective-anchor-experiences
Featured Images: pexels.com