空间定位点Spatial anchors

空间定位点表示系统应随时间跟踪的世界上的重要点。A spatial anchor represents an important point in the world that the system should keep track of over time. 每个定位点具有可根据需要进行调整的坐标系(相对于其他定位点或参照系),以确保锚定的全息影像保持位置精确。Each anchor has a coordinate system that adjusts as needed, relative to other anchors or frames of reference, in order to ensure that anchored holograms stay precisely in place. 在定位点的坐标系中呈现全息影像可以在任何给定时间为你提供最准确的全息影像定位。Rendering a hologram in an anchor's coordinate system gives you the most accurate 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 relative to the real world.

还可以跨应用会话和跨设备持久保存和共享空间定位点:You can also persist and share spatial anchors across app sessions and across devices:

  • 通过将局部空间定位点保存到磁盘并稍后重新加载这些定位点,应用可以在单个 HoloLens 设备上的多个应用会话中推断现实世界中的相同位置。By saving local spatial anchors to disk and loading them back later, your app can reason about the same location in the real world across multiple app sessions on a single HoloLens device.
  • 通过使用 Azure 空间定位点创建云定位点,应用可以跨多个 HoloLens、iOS 和 Android 设备共享空间定位点。By using Azure Spatial Anchors to create a cloud anchor, your app can share a spatial anchor across multiple HoloLens, iOS and Android devices. 通过使每个设备使用相同的空间定位点呈现全息影像,所有用户将看到全息影像显示在现实世界中的相同位置。By having each device render a hologram using the same spatial anchor, all 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 are not present together at the same time.

对于保持在直径 5 米以内的固定的桌面头戴显示设备,如果想要获得站立范围或房间范围的体验,通常只需使用状态参照系(而不是空间定位点),它可以提供用于呈现所有内容的单一坐标系。For standing-scale or room-scale experiences for tethered desktop headsets that will stay within a 5-meter diameter, you can usually just use the stage frame of reference instead of spatial anchors, providing you a single coordinate system in which to render all content. 但是,如果应用希望让用户在 HoloLens 上漫步超过 5 米(也许在建筑物的某一个楼层中漫步),你需要使用空间定位点来保持内容稳定。However, if your app intends to let users wander beyond 5 meters on 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 should tag along with the user. 最好使用固定的参照系(Unity 世界坐标的基础)或附加的参照系来定位动态全息影像。It is 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

大多数情况下,应该由用户明确放置空间定位点。Most of the time, users should be the ones explicitly placing spatial anchors.

例如,在 HoloLens 上,应用可以让用户的凝视线与空间映射网格相交,让用户确定放置全息影像的位置。For example, on HoloLens, an app 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, and the system will consolidate their internal data if multiple anchors can share their underlying sensor data. 通常应为用户明确放置的每个全息影像创建一个新的局部空间定位点,但下面列出的情况除外,例如固定的全息影像组。You should typically create 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 米以上,由于杠杆效应,这些全息影像可能会出现与它们距离原点的距离成比例的明显位置误差。If you render holograms more than about 3 meters from that origin, those holograms may experience noticeable positional errors in proportion to their distance from that origin, due to lever-arm effects. 如果用户站在定位点附近,这种方法是有效的,因为全息影像也离用户较远,这意味着远的全息影像的角度误差将较小。That works if the user stands near the anchor, since the hologram is far away from the user too, meaning the angular error of the distant hologram will be small. 然而,如果用户走向远处的全息影像,它会在他们的视野中变大,这使得远处定位点原点的杠杆效应非常明显。However, if the user walks up to that distant hologram, it will then be large in their view, making the lever-arm effects from the faraway anchor origin quite obvious.

聚集应形成固定群集的全息影像Group holograms that should form a rigid cluster

如果应用希望这些全息影像彼此保持固定的关系,那么多个全息影像可以使用同一个空间定位点。Multiple holograms can share the same spatial anchor if the app expects those holograms to maintain fixed relationships to one another.

例如,如果你在房间里制作一个全息太阳系动画,最好将所有太阳系对象绑定到中心的单个定位点,这样它们就可以相对流畅地移动。For example, if you are 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, so that they move smoothly relative to each other. 在这种情况下,太阳系作为一个整体被锚定,即使其组成部分围绕定位点动态移动,也是如此。In this case, it is the solar system as a whole that is anchored, even though its component parts are moving dynamically around the anchor.

保持全息影像稳定性的关键点是遵循上面的 3 米规则。The key caveat here 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),最好跳过局部空间定位点并直接在固定参照系提供的坐标系中呈现这些全息影像(即在 Unity 中,可以通过将全息影像直接放置在没有 WorldAnchor 的世界坐标中来实现此目的)。If you have a highly dynamic hologram, such as a character walking around the room, or a floating UI that follows along the wall near the user, it is best to skip local spatial anchors and render those holograms directly in the coordinate system provided by the stationary frame of reference (i.e. in Unity, you achieve this by placing holograms directly in world coordinates without a WorldAnchor). 当用户远离全息影像时,静止参照系中的全息影像可能会发生漂移,但这对于动态全息影像来说不太可能是明显的:要么全息影像一直在移动,要么它的移动一直使它靠近用户,在这种情况下漂移就会最大限度减小。Holograms in a stationary frame of reference may 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. 例如,有两座相距 10 米的城堡,每座城堡都有自己的空间定位点,其中一座城堡向另一座城堡发射炮弹。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. 当炮弹发射时,你可以在固定参照系的适当位置呈现它,以便与第一座城堡的锚定坐标系中的大炮保持一致。At the moment the cannonball is fired, you can render it at the appropriate location in the stationary frame of reference, so as 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. 当炮弹到达另一座城堡时,可以选择将它移动到第二座城堡的锚定坐标系中,以便对该城堡的刚体进行物理计算。As the cannonball reaches the other castle, you may choose to move it into the second castle's anchored coordinate system to allow for physics calculations with that castle's rigid bodies.

如果跨设备共享高度动态全息影像,则需要选择一些云空间定位点充当其父级,因为不能跨设备共享固定参照系。If you are sharing a highly dynamic hologram across devices, you will need to pick some cloud spatial anchor to act as their parent, as stationary frames of reference cannot be shared across devices. 但是,在这种情况下,应该确保动态全息影像或观察它的设备保持在定位点的 3 米半径范围内,以确保全息影像在所有设备上看起来都是稳定的。However, in this case, you should ensure that either either the dynamic hologram or the devices viewing it remain within the anchor's 3 meter radius, to ensure the hologram appears stable on all devices.

避免创建空间定位点网格Avoid creating a grid of spatial anchors

你可能想要在用户四处移动时让应用放置空间定位点的常规网格,在用户移动时将动态对象从一个定位点转移到另一个定位点。You may be tempted to have your app 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 a lot of management for your app, without the benefit of the deep sensor data that the system itself maintains internally. 对于这些情况,通常可以通过将全息影像放置在固定的参照系中,以较少的工作量获得更好的结果,如上一节所述。For these cases, you will usually achieve better results with less effort by placing your holograms in the stationary frame of reference, as described in the section above.

当在静态空间周围预先定位一组云空间定位点时,请考虑按照上述原则将空间定位点放置在用户将遇到的关键全息影像的位置,而不是创建一个任意的定位点网格。When 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 will encounter 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 will prioritize keeping around the sensor data that is near that anchor. 如果你不再使用空间定位点,请停止访问其坐标系。If you are no longer using a spatial anchor, stop accessing its coordinate system. 这将允许根据需要移除其底层传感器数据。This will allow its underlying sensor data to be removed as necessary.

这对于你持久保存到空间定位点存储的局部定位点尤其重要。This is especially important for local anchors you have persisted to the spatial anchor store. 这些定位点后的传感器数据将永久保留,以便应用在将来的应用会话中找到该定位点,这将减少用于跟踪其他定位点的空间。The sensor data behind these anchors will be kept around permanently to allow your app to find that anchor in future app sessions, which will reduce the space available to track other anchors. 在将来的会话中仅保留你需要再次查找的局部定位点,并在它们对用户不再有意义时将其从存储中删除。Persist only those local anchors that you need to find again in future sessions and remove them from the store when they are no longer meaningful to the user.

对于云空间定位点,存储可以根据场景需要进行扩展。For cloud spatial anchors, your storage can scale as your scenario requires. 可以根据需要存储尽可能多的云定位点,仅当你知道用户不需要再次在该定位点上定位全息影像时才释放它们。You may store as many cloud anchors as needed, releasing them only when you know that your users will not need to locate holograms at that anchor again.

另请参阅See also