Spatial mapping lets you place objects on physical surfaces in the real-world. When the world around the HoloLens is mapped, holograms seem more real to the user. Spatial mapping also anchors objects in the user’s world by taking advantage of depth cues, helping convince them that these holograms are actually in their space. Holograms floating in space or moving with the user won’t feel as real, so you always want to place items for comfort whenever possible.
You can find more information on spatial mapping quality, placement, occlusion, rendering, and more, in the Spatial mapping document.
The Microsoft OpenXR plugin should be downloaded to use spatial mapping, available on Unreal Marketplace or GitHub.
To enable spatial mapping on HoloLens:
To opt into spatial mapping and debug the MRMesh in a HoloLens game:
Open the ARSessionConfig and expand the ARSettings > World Mapping section.
You can modify the following parameters to update the spatial mapping runtime behavior:
First, you need to start Spatial Mapping:
Once spatial mapping has been captured for the space, we recommend toggling off spatial mapping. The spatial mapping may be completed either after a certain amount of time, or when raycasts in each direction return collisions against the MRMesh.
To get access to the MRMesh at runtime:
In this case, the On Add Tracked Geometry event is being monitored, which looks for valid world meshes matching to spatial mapping data. You can find the full list of events in the UARTrackableNotify component API.
You can change the mesh’s material in the Blueprint Event Graph or in C++. The screenshot below shows the Blueprint route:
In your game’s build.cs file, add AugmentedReality and MRMesh to the PublicDependencyModuleNames list:
PublicDependencyModuleNames.AddRange(
new string[] {
"Core",
"CoreUObject",
"Engine",
"InputCore",
"EyeTracker",
"AugmentedReality",
"MRMesh"
});
To access the MRMesh, subscribe to the OnTrackableAdded delegates:
#include "ARBlueprintLibrary.h"
#include "MRMeshComponent.h"
void AARTrackableMonitor::BeginPlay()
{
Super::BeginPlay();
// Subscribe to Tracked Geometry delegates
UARBlueprintLibrary::AddOnTrackableAddedDelegate_Handle(
FOnTrackableAddedDelegate::CreateUObject(this, &AARTrackableMonitor::OnTrackableAdded)
);
}
void AARTrackableMonitor::OnTrackableAdded(UARTrackedGeometry* Added)
{
// When tracked geometry is received, check that it's from spatial mapping
if(Added->GetObjectClassification() == EARObjectClassification::World)
{
UMRMeshComponent* MRMesh = Added->GetUnderlyingMesh();
}
}
[!NOTE] There are similar delegates for updated and removed events, AddOnTrackableUpdatedDelegate_Handle and AddOnTrackableRemovedDelegate_Handle respectively.
You can find the full list of events in the UARTrackedGeometry API.