空間錨點Spatial anchors

空間錨點代表一段時間內系統追蹤的一個重點。A spatial anchor represents an important point in the world that the system tracks over time. 每個錨點都有一個可調整的 座標系統(根據其他錨點或參考的框架),以確保錨定的全像位置保持精確。Each anchor has an adjustable coordinate system, based on other anchors or frames of reference, to ensure anchored holograms stay precisely in place. 在錨點座標系統中轉譯全息圖,可讓您在任何指定時間最精確地放置該全像投影。Rendering a hologram in an anchor's coordinate system gives you the most precise positioning for that hologram at any given time. 這是因為系統會根據真實世界,不斷地將其移回原位的位置,而將一段時間的小型調整成本納入考慮。This comes at the cost of small adjustments over time to the hologram's position as the system continually moves it back into place based on the real world.

您也可以跨應用程式會話和跨裝置來保存和共用空間錨點:You can also persist and share spatial anchors across application sessions and across devices:

  • 藉由將本機空間錨點儲存到磁片,並于稍後再將其載入,您的應用程式可以在單一 HoloLens 上的多個應用程式會話之間計算相同的位置。By saving local spatial anchors to disk and loading them back later, your application can calculate the same location in the real world across multiple application sessions on a single HoloLens.
  • 藉由使用 Azure 空間錨點 來建立雲端錨點,您的應用程式可以跨多個 HoloLens、IOS 和 Android 裝置共用空間錨點。By using Azure Spatial Anchors to create a cloud anchor, your application can share a spatial anchor across multiple HoloLens, iOS, and Android devices. 藉由讓每個裝置使用相同的空間錨點轉譯全像影像,使用者會看到在真實世界中的相同位置出現全像投影。By having each device render a hologram using the same spatial anchor, users will see the hologram appear at the same place in the real world. 這可提供即時共用體驗。This allows for real-time shared experiences.
  • 您也可以使用 Azure 空間錨點 ,在 HoloLens、IOS 和 Android 裝置上進行非同步全像保存。You can also use Azure Spatial Anchors for asynchronous hologram persistence across HoloLens, iOS, and Android devices. 藉由共用長期雲端空間錨點,即使這些裝置不會同時存在,多個裝置也可以觀察經過一段時間的相同保存全息圖。By sharing a durable cloud spatial anchor, multiple devices can observe the same persisted hologram over time, even if those devices aren't present together at the same time.

您通常可以使用 參考的階段框架 (而不是空間錨點),針對行動網卡桌上型耳機提供固定規模或房間規模的體驗,這會提供您單一座標系統來轉譯所有內容。For standing-scale or room-scale experiences for tethered desktop headsets that will stay within a 5-meter diameter, you can typically use the stage frame of reference instead of spatial anchors, which provides you a single coordinate system in which to render all content. 但是,如果您的應用程式可讓使用者在 HoloLens 中穿梭超過5個計量,則可能在整個大樓的整個樓層中運作,您將需要空間錨點,以保持內容的穩定。However, if your application lets users wander beyond 5 meters in HoloLens, perhaps operating throughout an entire floor of a building, you'll need spatial anchors to keep content stable.

雖然空間錨點對於在真實世界中應保持固定的全像投影非常有用,但是一旦將錨點放至定位,就無法移動它。While spatial anchors are great for holograms that should remain fixed in the world, once an anchor is placed, it can't be moved. 錨點有一些替代方式,更適合用來與使用者一起標記的動態全像投影。There are alternatives to anchors that are more appropriate for dynamic holograms that tag along with the user. 最好使用固定的參考框架來定位動態全像, (Unity 的全局座標) 或附加的參考框架。It's best to position dynamic holograms using a stationary frame of reference (the foundation for Unity's world coordinates) or an attached frame of reference.

最佳作法Best practices

這些空間錨點指南將協助您轉譯穩定、且能準確追蹤現實世界的全像投影。These spatial anchor guidelines will help you render stable holograms that accurately track the real world.

建立使用者放置的空間錨點Create spatial anchors where users place them

一般而言,使用者是明確放置空間錨點的使用者。Typically, users are the ones explicitly placing spatial anchors.

例如,在 HoloLens 上,應用程式可以將使用者的 注視 光線與 空間對應 網格相交,讓使用者決定要放置全像影像的位置。For example, on HoloLens, an application can intersect the user's gaze ray with the spatial mapping mesh to let the user decide where to place a hologram. 當使用者按下該影像時,請在交集點建立空間錨點,然後將全像位置放在錨點座標系統的原點。When the user taps to place that hologram, create a spatial anchor at the intersection point, and then place the hologram at the origin of that anchor's coordinate system.

本機空間錨點很容易就能建立。Local spatial anchors are easy and performant to create. 如果有多個錨點可以共用其基礎感應器資料,系統就會合並內部資料。The system combines internal data if multiple anchors can share their underlying sensor data. 建議您為使用者明確放置的每個全息圖建立新的本機空間錨點,但以下所述的案例除外,例如固定的全像投影群組。We recommend creating a new local spatial anchor for each hologram that a user explicitly places, except in cases outlined below, such as rigid groups of holograms.

一律轉譯位於錨點 3 公尺範圍內的錨定全像投影Always render anchored holograms within 3 meters of their anchor

空間錨點可穩固錨點原始位置附近的座標系統。Spatial anchors stabilize their coordinate system near the anchor's origin. 如果您從原點轉譯超過3個量表的全像投影,則可能會因為拉杆 arm 的影響,而從該原點的距離來看,可能會遇到明顯的位置錯誤。If you render holograms more than 3 meters from the origin, the holograms might experience noticeable positional errors in proportion to their distance from that origin because of lever-arm effects. 這適用于使用者接近錨點,因為全像全像使用者一樣。This works if the user stands near the anchor, since the hologram is far away from the user, too. 換句話說,最遠的全像影像的角度錯誤將會很小。In other words, the angular error of the distant hologram will be small. 不過,如果使用者往上移到最遠的全像全像影像,則會在其觀賞中很大,因此,遠處錨點來源的拉杆 arm 效果也很明顯。However, if the user walks up to that distant hologram, it will be large in their view, making the lever-arm effects from the faraway anchor origin obvious.

應形成固定叢集的群組全像投影Group holograms that should form a rigid cluster

如果應用程式預期這些全像間的全像之間保持固定的關聯性,則多個全像影像可以共用同一個空間錨點。Multiple holograms can share the same spatial anchor if the application expects those holograms to maintain fixed relationships with one another.

例如,如果您要在房間內以動畫顯示全像攝影系統,最好將所有的日光系統物件系結至中央的單一錨點。For example, if you're animating a holographic solar system in a room, it's better to tie all of the solar system objects to a single anchor in the center. 如此一來,它們就會以彼此順暢地移動。That way, they'll move smoothly based on each other. 在此情況下,它是錨定的整個日光系統,即使它的元件部分在錨點動態移動也是一樣。In this case, it's the solar system as a whole that is anchored, even though its component parts are moving dynamically around the anchor.

維持全像影像穩定性的關鍵是遵循上述的3計量規則。The key caveat to maintain hologram stability is to follow the 3-meter rule above.

使用靜止的參考架構而不是本機空間錨點來轉譯高動態全像投影Render highly dynamic holograms using the stationary frame of reference instead of a local spatial anchor

如果您有高度動態的全像點,例如沿著使用者附近的房間或浮動 UI 的字元,則最好略過本機空間錨點,並直接在 參考的靜止框架所提供的座標系統中轉譯這些全像投影。If you have a highly dynamic hologram, such as a character walking around a room or a floating UI that follows along the wall near the user, it's best to skip local spatial anchors, and render those holograms directly in the coordinate system provided by the stationary frame of reference. 在 Unity 中,您可以直接在全局座標中放入全像無 WorldAnchor,以達到這個目的。In Unity, you achieve this by placing holograms directly in world coordinates without a WorldAnchor. 當使用者離全像全像全像全像一樣,在固定的參考框架中的全息圖可能會發生漂移。Holograms in a stationary frame of reference might experience drift when the user is far from the hologram. 但這對動態的全像是較不明顯的現象:可能是因為全像全像全像移動的全像移動一樣,也可能是因為動態的移動會讓它接近最小化漂移的使用者。But this is less likely to be noticeable for dynamic holograms: either the hologram is constantly moving anyway or its motion constantly keeps it close to the user where drift will be minimized.

動態全像投影的一個有趣的例子是一個物件從某個錨定座標系統移動至另一個座標系統的動畫。One interesting case of dynamic holograms is an object that is animating from one anchored coordinate system to another. 例如,您可能會有兩個 castles 的10個計量,每個都在自己的空間錨點,而一個 castle 引發另一個 castle 的 cannonball。For example, you might have two castles 10 meters apart, each on their own spatial anchor with one castle firing a cannonball at the other castle. 當 cannonball 引發時,您可以將它呈現在固定的參考框架中的適當位置,以與第一個 castle 的錨定座標系統中的 cannon 一致。When the cannonball is fired, you can render it at the appropriate location in the stationary frame of reference to coincide with the cannon in the first castle's anchored coordinate system. 然後它可以在靜止的參考架構中追蹤砲彈在空中飛行 10 公尺的軌跡。It can then follow its trajectory in the stationary frame of reference as it flies 10 meters through the air. 當 cannonball 到達其他 castle 時,您可以將它移到第二個 castle 的錨定座標系統,以允許使用該 castle 固定主體的物理計算。As the cannonball reaches the other castle, you can move it into the second castle's anchored coordinate system to allow for physics calculations with that castle's rigid bodies.

如果您要跨裝置共用高度動態的全像影像,請挑選一些雲端空間錨點做為其父系,因為無法在裝置間共用固定的參考框架。If you're sharing a highly dynamic hologram across devices, pick some cloud spatial anchor to act as their parent because stationary frames of reference cannot be shared across devices. 不過,您應該確保動態全像影像或裝置的觀看位置都維持在錨點的3計量半徑內,如此一來,全像全像所有裝置上的全像是穩定的。However, you should ensure either the dynamic hologram or the devices viewing it stay within the anchor's 3-meter radius so the hologram appears stable on all devices.

避免建立空間錨點的網格Avoid creating a grid of spatial anchors

您可能會想要讓應用程式在使用者四處移動時,卸載空間錨點的一般方格,將動態物件從錨點轉換至錨點。You may be tempted to have your application drop a regular grid of spatial anchors as the user walks around, transitioning dynamic objects from anchor to anchor as they move around. 不過,這牽涉到更多的應用程式管理,而不會有系統本身在內部維護的深度感應器資料的好處。However, this involves more management for your application, without the benefit of the deep sensor data that the system itself maintains internally. 在這些情況下,您可以藉由將您的全像上一節所述,將您的全像放在參考的靜止框架中來達到更好的For these cases, you'll achieve better results by placing your holograms in the stationary frame of reference as described in the section above. 當您在靜態空間周圍預先放置一組雲端空間錨點時,請考慮將空間錨點放在使用者的金鑰磁碟空間的位置,而不是建立任意的錨點方格。When you're pre-positioning a set of cloud spatial anchors around a static space, consider placing the spatial anchors at the locations of the key holograms the user comes across per the principle above rather than creating an arbitrary grid of anchors. 這可確保您能夠讓那些關鍵的全像投影獲得最高的穩定性。This ensures that you'll get maximum stability for those key holograms.

釋出您不再需要的本機空間錨點Release local spatial anchors you no longer need

當本機空間錨點為作用中時,系統會優先保留位於該錨點附近的感應器資料。While a local spatial anchor is active, the system prioritizes keeping the sensor data that is near that anchor. 如果您不再使用空間錨點,請停止存取其座標系統。If you're no longer using a spatial anchor, stop accessing its coordinate system. 這可讓其基礎感應器資料視需要移除。This allows its underlying sensor data to be removed as necessary.

對於您已保存到空間錨點存放區的本機錨點而言,這一點特別重要。This is especially important for local anchors you've persisted to the spatial anchor store. 這些錨點後方的感應器資料將會永久保留,讓您的應用程式在未來的會話中找出該錨點,進而減少可用來追蹤其他錨點的空間。The sensor data behind these anchors will be kept around permanently to allow your application to find that anchor in future sessions, which reduces the space available to track other anchors. 只保存您需要在未來的會話中再次尋找的本機錨點。Only persist local anchors that you need to find again in future sessions. 當使用者不再有意義時,建議您將它們從存放區中移除。We recommend removing them from the store when they're no longer meaningful to the user.

對於雲端空間錨點,您的儲存體可以依照案例需要調整規模。For cloud spatial anchors, your storage can scale as your scenario requires. 您可以儲存所需數量的雲端錨點,並在您知道使用者不再需要錨點時釋放它們。You can store as many cloud anchors as you need, releasing them when you know that your users won't need the anchor again.

請參閱See also