Quickstart: Create a HoloLens app with Azure Spatial Anchors, in C++/WinRT and DirectX
This quickstart covers how to create a HoloLens app using Azure Spatial Anchors in C++/WinRT and DirectX. Azure Spatial Anchors is a cross-platform developer service that allows you to create mixed reality experiences using objects that persist their location across devices over time. When you're finished, you'll have a HoloLens app that can save and recall a spatial anchor.
You'll learn how to:
- Create a Spatial Anchors account
- Configure the Spatial Anchors account identifier and account key
- Deploy and run on a HoloLens device
To complete this quickstart, make sure you have:
- A Windows machine with Visual Studio 2017+ installed with the Universal Windows Platform development workload and the Windows 10 SDK (10.0.17763.0 or newer) component, and Git for Windows.
- The C++/WinRT Visual Studio Extension (VSIX) for Visual Studio should be installed from the Visual Studio Marketplace.
- A HoloLens device with developer mode enabled. This article requires a HoloLens device with the Windows 10 October 2018 Update (also known as RS5). To update to the latest release on HoloLens, open the Settings app, go to Update & Security, then select the Check for updates button.
- Your app must set the spatialPerception capability in its AppX manifest.
Create a Spatial Anchors resource
Go to the Azure portal.
In the left navigation pane in the Azure portal, select Create a resource.
Use the search box to search for Spatial Anchors.
Select Spatial Anchors. In the dialog box, select Create.
In the Spatial Anchors Account dialog box:
Enter a unique resource name, using regular alphanumeric characters.
Select the subscription that you want to attach the resource to.
Create a resource group by selecting Create new. Name it myResourceGroup and select OK. A resource group is a logical container into which Azure resources like web apps, databases, and storage accounts are deployed and managed. For example, you can choose to delete the entire resource group in one simple step later.
Select a location (region) in which to place the resource.
Select New to begin creating the resource.
After the resource is created, Azure Portal will show that your deployment is complete. Click Go to resource.
Then, you can view the resource properties. Copy the resource's Account ID value into a text editor because you'll need it later.
Under Settings, select Key. Copy the Primary key value into a text editor. This value is the
Account Key. You'll need it later.
Open the sample project
Clone the samples repository by running the following command:
git clone https://github.com/Azure/azure-spatial-anchors-samples.git
HoloLens\DirectX\SampleHoloLens.sln in Visual Studio.
Configure account identifier and key
The next step is to configure the app to use your account identifier and account key. You copied them into a text editor when setting up the Spatial Anchors resource.
SpatialAnchorsAccountKey field and replace
Set me with the account key.
SpatialAnchorsAccountId field and replace
Set me with the account identifier.
Deploy the app to your HoloLens
Change the Solution Configuration to Release, change Solution Platform to x86, and select Device from the deployment target options.
If using HoloLens 2, use ARM as the Solution Platform, instead of x86.
Power on the HoloLens device, sign in, and connect it to the PC using a USB cable.
Select Debug > Start debugging to deploy your app and start debugging.
Follow the instructions in the app to place and recall an anchor.
In Visual Studio, stop the app by either selecting Stop Debugging or pressing Shift + F5.
Clean up resources
In the preceding steps, you created Azure resources in a resource group. If you don't expect to need these resources in the future, you can delete them by deleting the resource group.
From the left menu in the Azure portal, select Resource groups and then select myResourceGroup.
On the resource group page, make sure that the listed resources are the ones you want to delete.
Select Delete, type myResourceGroup in the text box, and then select Delete.
In this quickstart, you created a Spatial Anchors account. You then configured and deployed an app to save and recall spatial anchors. To learn more about how to improve the app so it can share spatial anchors with other devices, continue to the next tutorial.
Send feedback about: