【问题标题】:How do I get a position from a detected ObjectInstance?如何从检测到的 ObjectInstance 中获取位置?
【发布时间】:2022-08-08 15:39:49
【问题描述】:

我一直在尝试遵循https://docs.microsoft.com/en-us/azure/object-anchors/concepts/sdk-overview 中的内容并取得了一些成功。我成功地检测到了一个 ObjectInstance,但是如何获得将我的 GameObject 放置在匹配位置的坐标? SpatialGraphCoordinateSystem 等文档中有很多对我来说不熟悉的概念,我不知道如何进一步了解它。

更新

我终于通过首先将 SpatialGraphCoordinateSystem 转换为 SpatialCoordinateSystem 来使其工作。

SpatialGraphCoordinateSystem coordinateSystem
[...]

//After getting an ObjectInstance instance
SpatialCoordinateSystem spatialCoordinateSystem = instance.TryGetCurrentState().Center.ToSpatialCoordinateSystem();
var instancePos = spatialCoordinateSystem.TryGetTransformTo(coordinateSystem.Value.ToSpatialCoordinateSystem()).Value.ToUnityLocation().Position;
var instanceOrientation = spatialCoordinateSystem.TryGetTransformTo(coordinateSystem.Value.ToSpatialCoordinateSystem()).Value.ToUnityLocation().Ori;

//Place my hologram on the detected position
mySphere.transform.SetPositionAndRotation(instancePos, instanceOri);

    标签: azure-object-anchors


    【解决方案1】:

    在阅读您上面的问题时,我认为根据您的要求,您需要将其称为: ObjectInstance.TryGetCurrentState Method (Microsoft.Azure.ObjectAnchors) | Microsoft Docs

    这将返回一个具有中心属性的 ObjectInstanceState,该属性是 SpatialGraphLocation Struct (Microsoft.Azure.ObjectAnchors.SpatialGraph) | Microsoft Docs

    SpatialGraphLocation 将包含您正在寻找的姿势信息。

    如果您对混合现实中的一般坐标系有疑问,我建议您从这里开始了解更多信息: Coordinate systems - Mixed Reality

    如果您还没有查看示例,可以在此处获得有关 AOA 的另一个好资源: https://github.com/Azure/azure-object-anchors

    这里还有一个教程介绍了这个示例: Quickstart: In-depth MRTK walkthrough - Azure Object Anchors | Microsoft Docs

    【讨论】:

    • 我设法用对象的位置和方向提取了 SpatialGraphLocation,但是用这个姿势实例化一个 GameObject 会将它放在一个偏移处。我认为必须转换姿势,但即使在尽可能多地研究了 SDK 之后,我也不明白如何将其转换为常规的 Unity 坐标系。
    猜你喜欢
    • 1970-01-01
    • 2016-05-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-25
    相关资源
    最近更新 更多