Unreal 中的空間對應Spatial Mapping in Unreal

空間對應可讓您將物件放在真實世界的實體表面上。Spatial mapping lets you place objects on physical surfaces in the real-world. 對應了 HoloLens 周圍的環境後,對使用者而言,全像投影看起來會更真實。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.

啟用空間對應Enabling Spatial Mapping

若要在 HoloLens 上啟用空間對應:To enable spatial mapping on HoloLens:

  • 開啟 [編輯] > [專案設定],然後向下捲動至 [平台] 區段。Open Edit > Project Settings and scroll down to the Platforms section.
    • 選取 HoloLens 並勾選 [空間感知]。Select HoloLens and check Spatial Perception.

螢幕擷取畫面:已醒目提示空間感知的 HoloLens 專案設定功能

若要在 HoloLens 遊戲中加入空間對應,並偵錯 MRMeshTo opt into spatial mapping and debug the MRMesh in a HoloLens game:

  1. 開啟 ARSessionConfig,並展開 [ARSettings] > [世界對應] 區段。Open the ARSessionConfig and expand the ARSettings > World Mapping section.

  2. 勾選 [從追蹤的幾何圖形產生網格資料],這會指示 HoloLens 外掛程式啟動,以非同步方式取得空間對應資料,並透過 MRMesh 將其呈現給 Unreal。Check Generate Mesh Data from Tracked Geometry, which tells the HoloLens plugin to start asynchronously getting spatial mapping data and surface it to Unreal through the MRMesh.

  3. 勾選 [以線框呈現網格資料],以在 MRMesh 中顯示每個三角形的白色線框。Check Render Mesh Data in Wireframe to show a white wireframe outline of every triangle in the MRMesh.


執行階段的空間對應Spatial Mapping at runtime

您可以修改下列參數,以更新空間對應執行階段行為:You can modify the following parameters to update the spatial mapping runtime behavior:

  • 開啟 [編輯] > [專案設定]、向下捲動至 [平台] 區段,然後選取 [HoloLens] > [空間對應]:Open Edit > Project Settings, scroll down to the Platforms section, and select HoloLens > Spatial Mapping:


  • 每立方米的三角形數量上限計量 會更新空間對應網格中三角形的密度。Max Triangles Per Cubic Meter updates the density of the triangles in the spatial mapping mesh.
  • 空間網格體積大小 是玩家周圍用來呈現和更新空間對應資料的立方體大小。Spatial Meshing Volume Size is the size of the cube around the player to render and update spatial mapping data.
    • 如果預期的應用程式執行階段環境預期會很大,此值可能需要很大,才能符合真實世界的空間。If the expected application runtime environment is expected to be large, this value may need to be large to match the real-world space. 如果應用程式只需要在使用者附近的表面上放置全像投影,則此值可能會比較小。The value can be smaller if the application only needs to place holograms on surfaces immediately around the user. 當使用者在世界中行走時,空間對應體積會隨著他們移動。As the user walks around the world, the spatial mapping volume will move with them.

使用 MongoDBWorking with MRMesh

首先,您必須啟動空間對應:First, you need to start Spatial Mapping:

已醒目提示空間對應擷取類型的 ToggleARCapture 函式藍圖

在為空間擷取了空間對應後,建議您關閉空間對應。Once spatial mapping has been captured for the space, we recommend toggling off spatial mapping. 空間對應可能會在一段時間後完成,也可能會在每個方向的光線投射針對 MRMesh 傳回碰撞時完成。The spatial mapping may be completed either after a certain amount of time, or when raycasts in each direction return collisions against the MRMesh.

若要可在執行階段存取 MRMeshTo get access to the MRMesh at runtime:

  1. ARTrackableNotify 元件新增至藍圖動作項目。Add an ARTrackableNotify Component to a Blueprint actor.

空間錨點的 AR Trackable Notify

  1. 選取 ARTrackableNotify 元件,然後展開 [詳細資料] 面板中的 [事件] 區段。Select the ARTrackableNotify component and expand the Events section in the Details panel.
    • 對您要監視的事件選取 + 按鈕。Select the + button on the events you want to monitor.


在此情況下,會監視 On Add Tracked Geometry 事件,這會尋找與空間對應資料相符的有效世界網格。In this case, the On Add Tracked Geometry event is being monitored, which looks for valid world meshes matching to spatial mapping data. 您可以在 UARTrackableNotify 元件 API 中找到完整的事件清單。You can find the full list of events in the UARTrackableNotify component API.

您可以在藍圖事件圖形或 C++ 中變更網格的材質。You can change the mesh’s material in the Blueprint Event Graph or in C++. 下方螢幕擷取畫面會顯示藍圖路由:The screenshot below shows the Blueprint route:


C++ 中的空間對應Spatial Mapping in C++

在遊戲的 build.cs 檔案中,將 AugmentedRealityMRMesh 新增至 PublicDependencyModuleNames 清單:In your game's build.cs file, add AugmentedReality and MRMesh to the PublicDependencyModuleNames list:

    new string[] {

若要存取 MRMesh,請訂閱 OnTrackableAdded 委派:To access the MRMesh, subscribe to the OnTrackableAdded delegates:

#include "ARBlueprintLibrary.h"
#include "MRMeshComponent.h"

void AARTrackableMonitor::BeginPlay()

    // Subscribe to Tracked Geometry delegates
        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();


已更新和已移除的事件有類似的委派,分別是 AddOnTrackableUpdatedDelegate_HandleAddOnTrackableRemovedDelegate_HandleThere are similar delegates for updated and removed events, AddOnTrackableUpdatedDelegate_Handle and AddOnTrackableRemovedDelegate_Handle respectively.

您可以在 UARTrackedGeometry API 中找到完整的事件清單。You can find the full list of events in the UARTrackedGeometry API.

另請參閱See also