Unreal 中的本機空間錨點Local Spatial Anchors in Unreal

空間錨點能夠以 ARPin 的形式將全像投影儲存在應用程式工作階段之間的真實世界空間中。Spatial anchors save holograms in real-world space between application sessions as ARPin s. ARPin 儲存在 HoloLens 的錨定存放區之後,就可以在未來的工作階段中載入,且在沒有網際網路連線時,將是理想的備用選項。Once saved in the HoloLens' anchor store, ARPin's can be loaded in future sessions and are an ideal fallback option when there's no internet connectivity.

注意

UE 4.25 的錨點函式在 4.26 已過時,請以較新的函式加以取代。Anchor functions from UE 4.25 are obsolete in 4.26 and should be replaced with newer ones.

重要

本機錨點會儲存在裝置上,而 Azure Spatial Anchors 會儲存在雲端。Local anchors are stored on device, while Azure Spatial Anchors are stored in the cloud. 如果您想要使用 Azure 雲端服務來儲存您的錨點,我們有一份文件可引導您整合 Azure Spatial AnchorsIf you're looking to use Azure cloud services to store your anchors, we have a document that can walk you through integrating Azure Spatial Anchors. 請注意,您在同一個專案中可以有本機和 Azure 錨點,而不會發生衝突。Note that you can have local and Azure anchors in the same project without conflict.

檢查錨定存放區Checking the anchor store

在儲存或載入錨點之前,必須先檢查錨點存放區是否準備就緒。Before saving or loading anchors, you need to check if the anchor store is ready. 在錨點存放區準備就緒之前,呼叫任何 HoloLens 錨點功能將會失敗。Calling any of the HoloLens anchor functions before the anchor store is ready won't succeed.

儲存錨點Saving anchors

一旦應用程式具有您需要釘選到世界的元件,就可以下列序列儲存到錨點存放區:Once the application has a component you need to pin to the world, it can be saved to the anchor store with the following sequence:

將此細分:Breaking this down:

  1. 在已知位置繁衍動作項目。Spawn an actor at a known location.

  2. 根據動作項目的類別,建立具有該位置和名稱的 ARPinCreate an ARPin with that location and a name based on the actor’s class.

  3. 將動作項目新增至 ARPin,並將圖釘儲存至 HoloLens 錨點存放區。Add the actor to the ARPin and save the pin to the HoloLens anchor store.

    • 您選擇的錨點名稱必須是唯一的,在這個範例中,其為目前的時間戳記。The anchor name you choose must be unique, which in this example is the current timestamp.
  4. 如果錨點成功儲存至錨點存放區,則您可以在 [系統] > [對應管理員] > [裝置上儲存的錨點檔案] 底下的 HoloLens 裝置入口網站中查看該錨點。If the anchor is successfully saved to the anchor store, you can see it in the HoloLens device portal under System > Map manager > Anchor Files Saved On Device.

載入錨點Loading anchors

當應用程式啟動時,您可以使用下列藍圖來將元件還原至其錨點位置:When an application starts, you can use the following blueprint to restore components to their anchor locations:

將此細分:Breaking this down:

  1. 逐一查看錨點存放區中的所有錨點。Iterate over all of the anchors in the anchor store.

  2. 在身分識別中繁衍動作項目。Spawn an actor at identity.

  3. 從錨點存放區將該動作項目釘選到 ARPinPin that actor to the ARPin from the anchor store.

    • 請務必在身分識別繁衍動作項目,因為錨點會負責根據儲存位置在世界中重新放置全像投影。It's important to spawn the actor at identity since the anchor is responsible for repositioning the hologram in the world based on where it was saved. 此處新增的任何轉換都會將位移新增至錨點。Any transform added here will add an offset to the anchor.

也會查詢錨點識別碼,以便根據錨點的儲存名稱來繁衍不同的動作項目。The anchor ID is also queried so that different actors can be spawned depending on the anchor’s saved name.

移除錨點Removing anchors

當您完成錨點時,可以使用 Remove ARPin from WMRAnchor StoreRemove All ARPins from WMRAnchor Store 元件,清除個別錨點或整個錨點存放區。When you're done with an anchor, you can clear individual anchors or the entire anchor store with the Remove ARPin from WMRAnchor Store and Remove All ARPins from WMRAnchor Store components.

注意

請記住,空間錨點仍是 Beta 版,因此請務必回頭查看是否有更新的資訊和功能。Bear in mind that Spatial Anchors are still in Beta, so be sure to check back for updated information and features.

下一個開發檢查點Next Development Checkpoint

依循我們配置的 Unreal 開發旅程,此時您會探索 MRTK核心建置組塊。If you're following the Unreal development journey we've laid out, you're in the midst of exploring the MRTK core building blocks. 接下來,您可以繼續進行下一個建置組塊:From here, you can continue to the next building block:

或者,直接跳到混合實境平台功能和 API 的主題:Or jump to Mixed Reality platform capabilities and APIs:

您可以隨時回到 Unreal 開發檢查點You can always go back to the Unreal development checkpoints at any time.

另請參閱See also