List
Visual SLAM Tool - Access anchors via script
Posted Date: 2019-03-26 12:01     Edited Date: 2019-03-28 1:14     Writer: inactive

Hi,

I am using the Visual SLAM Tool for creating 3D Maps. Once created I'm adding anchors at the desired places within the map and exporting it to unity.

Those anchors are visible in Unity but is there a way to automatically get the position of all the anchors in the loaded object at runtime via script?

Thanks in advance.

Posted Date: 2019-03-27 2:29     Edited Date: 2019-03-27 2:29     Writer: inactive

Thank you for your interest in MAXST SDK.

You can get the location of the anchor through the script.

First, I do not know how to implement it in a script, but if you want to get the location of an anchor simply do the following.

public class anchorParentBehavior: MonoBehaviour
{
     Transform tr;
     // Start is called before the first frame update
     void Start ()
     {
         tr = GetComponent <Transform> ();

         Debug.Log ("anchor x =" + tr.position.x);
         Debug.Log ("anchor y =" + tr.position.y);
         Debug.Log ("anchor z =" + tr.position.z);
     }
}

After you create the above script and apply it to the anchor, you can see that the location of the anchor is displayed in the console window when Unity is executed.

 

Leo

Maxst Support Team

Posted Date: 2019-03-27 8:12     Edited Date: 2019-03-27 8:12     Writer: inactive

Thanks Leo for your quick reply.

But should I attach this script to the anchors within the editor?

If yes, then that's not what I'm looking for.

I want to skip the editor part and I want the position of the anchors (which I added while generating the 3D map via Visual SLAM Tool) at Runtime via script. Is it possible?

Posted Date: 2019-03-27 8:52     Edited Date: 2019-03-27 8:52     Writer: inactive

The following is a part of ObjectTrackerSample.cs code.

You can get the information (position, rotation, scale) of the anchor through GetTagAnchors () as shown below.

 

    void Update()
    {
        DisableAllTrackables();

        TrackingState state = TrackerManager.GetInstance().UpdateTrackingState();

        cameraBackgroundBehaviour.UpdateCameraBackgroundImage(state);
        TrackingResult trackingResult = state.GetTrackingResult();

        GuideInfo guideInfo = TrackerManager.GetInstance().GetGuideInfo();
        TagAnchor[] anchors = guideInfo.GetTagAnchors();

        for (int i = 0; i < trackingResult.GetCount(); i++)
        {
            Trackable trackable = trackingResult.GetTrackable(i);

            if (!objectTrackablesMap.ContainsKey(trackable.GetName()))
            {
                return;
            }

            objectTrackablesMap[trackable.GetName()].OnTrackSuccess(trackable.GetId(), trackable.GetName(),
                                                                   trackable.GetPose());
        }
    }

 

Is this the right information you want?

 

Leo

Maxst Support Team

Posted Date: 2019-03-27 10:50     Edited Date: 2019-03-27 10:50     Writer: inactive

Yes, looks like it. I'll give it a try.

Thanks. :)

Posted Date: 2019-03-28 1:14     Edited Date: 2019-03-28 1:14     Writer: inactive

I am glad that it has helped you.

Good luck to you :)

 

Leo

Maxst Support Team