Hello everyone.

The Mixed Reality Forums here are no longer being used or maintained.

There are a few other places we would like to direct you to for support, both from Microsoft and from the community.

The first way we want to connect with you is our mixed reality developer program, which you can sign up for at https://aka.ms/IWantMR.

For technical questions, please use Stack Overflow, and tag your questions using either hololens or windows-mixed-reality.

If you want to join in discussions, please do so in the HoloDevelopers Slack, which you can join by going to https://aka.ms/holodevelopers, or in our Microsoft Tech Communities forums at https://techcommunity.microsoft.com/t5/mixed-reality/ct-p/MicrosoftMixedReality.

And always feel free to hit us up on Twitter @MxdRealityDev.

My continuing problem using WorldAnchorStore data

Gosh I feel I am very foolish not to get this issue solved when working on it for so long. To explain the situation, my US buddy has a HoloLens and I just have to use the HoloLens Emulator. So have to rely on both devices being reliably interchangeable in regards to what I am trying to achieve. In a nutshell , I am still finding it very difficult to use the WorldAnchorStore on the Emulator. I followed (perhaps incorrectly) the example suggested by the moderator Partick who, on the 26th April suggested a class called PersistoMatic which saves the WorldAnchor _variable only when the public boolean value _isLocated is true. A procedure is delegated to look at the tracking changes and then the isLocated variable is re-examined. Inspired by this piece of code I rejigged it to work in my environment.

    static public WorldAnchorStore anchorStore = null;
    void Start()
    {
        WorldAnchorStore.GetAsync(StoreLoad);
    }
    private void StoreLoad(WorldAnchorStore store)
    {
        anchorStore = store;
    }

Now I have a series of static procedures which are called inside a MonBehaviour Class. One of these is to create a sphere:-

    static public GameObject create_sphere(Vector3 pos)
    {
        var m = GameObject.CreatePrimitive(PrimitiveType.Sphere);
        if (pos!=Vector3.zero)m.transform.position = pos;
        comment = "";
        WorldAnchor anchor = null;
        m.AddComponent<MeshFilter>();
        m.AddComponent<BoxCollider>();
        m.AddComponent<MeshRenderer>();
        m.transform.localScale = Vector3.one * 0.04f;
        if (anchor_now)
        {
            anchor_now = false;
            anchor = m.AddComponent<WorldAnchor>();
            anchor.transform.localScale = m.transform.localScale;
            if (anchor != null)
            {
//we always seem to get to this point
                save_anchor_point(anchor);
                if (anchor.isLocated)
                {
                    //currently this never gets called!
                    comment = "world anchor is located";
                    posmarker.logmessage(comment);
                }
            }
            else
            {
                comment = "not added worldanchor";
            }
        }
        else comment = "Click";
        return m;
    }
    static public bool save_anchor_point(WorldAnchor wa)
    {
        var sa= new saveanka(wa, anchorStore);
        return sa.saved;
    }

The class which deals with storing the WorldAnchor is below

public class saveanka
{
    WorldAnchor wa;
    WorldAnchorStore was;
    bool issaved = false;
    public saveanka(WorldAnchor wa,WorldAnchorStore was)
    {
        this.wa = wa;
        this.was = was;
        if (wa.isLocated)
        {
            wa.tag = System.DateTime.Now.TimeOfDay.TotalMilliseconds.ToString();
            posmarker.comment = "added world anchor id: " + wa.tag;
            posmarker.logmessage(posmarker.comment);
            issaved = was.Save(wa.tag, wa);
            tellitsok = true;
        }
        else
        {
            wa.OnTrackingChanged += wa_OnTrackingChanged;
        }

    }
    private void wa_OnTrackingChanged(WorldAnchor wa, bool located)
    {
        if (wa.isLocated)
        {

            //Debug.Log("Saving persisted position in callback");
            wa.tag = System.DateTime.Now.TimeOfDay.TotalMilliseconds.ToString();
            posmarker.comment = "added and located world anchor id: " + wa.tag;
            issaved = was.Save(wa.tag, wa);
            if (issaved) tellitsok = true;
            //Debug.Log("saved: " + saved);
            wa.OnTrackingChanged -= wa_OnTrackingChanged;
        }
    }
    bool tellitsok
    {
        set
        {
            addcomment.comment = "anchor saved ok at: " + wa.transform.position.ToString();
            value = true; 
        }

    }
    public bool saved
    {
        get
        {
            return issaved;
        }
    }
    public bool located
    {
        get
        {
            return wa.isLocated;
        }
    }
}

A sample set of anchor points looks like this on the Emulator:-

So in summary my question is:- _Does the WorldAnchor ever get the isLocated boolen set to true when using the Emulator or do I have to use the real HoloLens?
_

Many thanks in advance.

Sign In or Register to comment.