Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
255 views
in Technique[技术] by (71.8m points)

unity3d - Using WorldAnchorManager from MRTK

at the moment I try to use the experimental WorldAnchorManager (see official API entry) of MRTK 2.4. 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.

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. 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. 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".

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? Maybe someone already uses the Manager and can help me with this issue.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Ok, I wrote a small example app that uses the world anchor manager from 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. 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

Verified on Unity 2019.4.9f1, Visual Studio 2019, HoloLens 2 (Build 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. 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...