简体   繁体   English

使用 MRTK 的 WorldAnchorManager

[英]Using WorldAnchorManager from MRTK

at the moment I try to use the experimental WorldAnchorManager (see official API entry ) of MRTK 2.4.目前我尝试使用 MRTK 2.4 的实验性 WorldAnchorManager(参见官方 API 条目)。 Over all everything looks quiet easy.总的来说,一切看起来都很安静。 First of all, you have to create an Instance of the Manager and assign it to the script where you want to use it.首先,您必须创建管理器的实例并将其分配给要使用它的脚本。 Afterwards, it should be possible to load an anchor into a object with this piece of code:之后,应该可以使用以下代码将锚点加载到对象中:

public string AttachAnchor(GameObject gameObjectToAnchor, string anchorName = null)

This code also saves the Anchor as mentioned in the API.此代码还保存了 API 中提到的 Anchor。

If I want to remove the anchor from a GameObject I can call:如果我想从游戏对象中删除锚点,我可以调用:

public void RemoveAnchor(GameObject gameObjectToUnanchor)

In my Unity-Project (2019.3.7) I calculate a position of some gameobjects and afterwards assign them Anchors via the Method above.在我的 Unity-Project (2019.3.7) 中,我计算了一些游戏对象的位置,然后通过上面的方法为它们分配了锚点。 If I move the Gameobjects, I remove the anchors and attatch them again after the moving process is finished.如果我移动游戏对象,我会移除锚点并在移动过程完成后再次附加它们。

If I deploy the solution on HoloLens2, position the gameobjects, attatch the anchors and get a log that the anchors have been attatched successfully, those anchors should be accessable on hololens2 locally across sessions.如果我在 HoloLens2 上部署解决方案、定位游戏对象、附加锚点并获取锚点已成功附加的日志,那么这些锚点应该可以跨会话在 hololens2 上本地访问。 Unfortunately, in my case after restarting the application on the device and reloading the anchors, they cant be loaded.不幸的是,在我的情况下,在设备上重新启动应用程序并重新加载锚点后,它们无法加载。 The Manager Logs "Anchor could not be loaded for ' GO name ' ... creating a new anchor".管理器记录“无法为‘ GO 名称’加载锚点……创建新锚点”。

I am not sure what I did wrong, should this Manager already work?我不确定我做错了什么,这个经理应该已经工作了吗? Do I have to Configure something in the Unity-Project to use the Manager?我是否必须在 Unity-Project 中配置一些东西才能使用 Manager? Maybe someone already uses the Manager and can help me with this issue.也许有人已经在使用 Manager 并且可以帮助我解决这个问题。

Ok, I wrote a small example app that uses the world anchor manager from MRTK.好的,我编写了一个使用 MRTK 的世界锚点管理器的小示例应用程序。 Based on these steps: https://docs.microsoft.com/en-us/windows/mixed-reality/develop/unity/persistence-in-unity , the app enables the user to place a cube at any location, automatically creating and saving an anchor each time the cube is released.基于以下步骤: https : //docs.microsoft.com/en-us/windows/mixed-reality/develop/unity/persistence-in-unity ,该应用程序使用户能够在任何位置放置立方体,自动创建并在每次释放立方体时保存一个锚点。 When the app is closed and re-started, the anchor is loaded and the cube is placed at its saved location.当应用程序关闭并重新启动时,会加载锚点并将立方体放置在其保存的位置。

The source can be found here: https://github.com/anders-lundgren/mrtk-world-anchors来源可以在这里找到: https : //github.com/anders-lundgren/mrtk-world-anchors

Verified on Unity 2019.4.9f1, Visual Studio 2019, HoloLens 2 (Build 10.0.19041.1377).在 Unity 2019.4.9f1、Visual Studio 2019、HoloLens 2(内部版本 10.0.19041.1377)上验证。

In addition to the above steps, I added the base MRTK components, according to the MRTK getting started tutorial at https://docs.microsoft.com/en-us/windows/mixed-reality/develop/unity/tutorials/mr-learning-base-02 .除了上述步骤之外,我还根据https://docs.microsoft.com/en-us/windows/mixed-reality/develop/unity/tutorials/mr-上的 MRTK 入门教程添加了基础 MRTK 组件学习基地02 I also added a simple debugging prefab from this example: https://docs.microsoft.com/en-us/windows/mixed-reality/develop/unity/tutorials/mr-learning-asa-02#importing-the-tutorial-assets , and the manipulation handler from this example: https://microsoft.github.io/MixedRealityToolkit-Unity/Documentation/README_ManipulationHandler.html .我还从这个例子中添加了一个简单的调试预制件: https : //docs.microsoft.com/en-us/windows/mixed-reality/develop/unity/tutorials/mr-learning-asa-02#importing-the-tutorial -assets ,以及此示例中的操作处理程序: https : //microsoft.github.io/MixedRealityToolkit-Unity/Documentation/README_ManipulationHandler.html

Even if it is far too late, I want to finish this question.即使已经太晚了,我也想结束这个问题。 The WorldAnchorManager only functions when built for the WSA platform using legacy XR. WorldAnchorManager 仅在使用旧版 XR 为 WSA 平台构建时才起作用。 It doesn´t work within the editor or with the Unity-XR-Plugin.它不适用于编辑器或 Unity-XR-Plugin。 I tried to use it with the XR-Plugin.我尝试将它与 XR-Plugin 一起使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM