Visual SLAM Tool - Access anchors via script
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.
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
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?
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
Yes, looks like it. I'll give it a try.
Thanks. :)
I am glad that it has helped you.
Good luck to you :)
Leo
Maxst Support Team