Hello.
I am using the ImageTracking feature with NRSDK 2.2.1.
The glass used is NReal Air 2 Ultra.
I am having a problem where this ImageTracking cannot be loaded again once it has been loaded.
There are 3 markers to be read (m0, m1, m2) and all of them are above 60%, and in fact one of them can be read at a time.
We want to read these markers one by one and update their positions and text.
The program has been created as follows.
[Controller side]
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using NRKernal;
public class MyImageTrackingManager : MonoBehaviour
{
[SerializeField] private MyImageControllee _arObject;
private MyImageControllee _cacheArObject;
private List<NRTrackableImage> m_TempTrackingImages = new List<NRTrackableImage>();
private Dictionary<int, MyImageControllee> m_Visualizers = new Dictionary<int, MyImageControllee>();
void Start()
{
_arObject.gameObject.transform.parent = transform;
_cacheArObject = (MyImageControllee)Instantiate(_arObject, Vector3.zero, Quaternion.identity);
}
void Update()
{
#if !UNITY_EDITOR
if (NRFrame.SessionStatus != SessionState.Running)
{
return;
}
#endif
NRFrame.GetTrackables<NRTrackableImage>(m_TempTrackingImages, NRTrackableQueryFilter.New);
foreach (var image in m_TempTrackingImages)
{
if (image.GetTrackingState() == TrackingState.Tracking)
{
_cacheArObject.Image = image;//
_cacheArObject.transform.parent = transform;
}
}
}
/// <summary> Enables the image tracking. </summary>
public void EnableImageTracking()
{
var config = NRSessionManager.Instance.NRSessionBehaviour.SessionConfig;
config.ImageTrackingMode = TrackableImageFindingMode.ENABLE;
NRSessionManager.Instance.SetConfiguration(config);
}
/// <summary> Disables the image tracking. </summary>
public void DisableImageTracking()
{
var config = NRSessionManager.Instance.NRSessionBehaviour.SessionConfig;
config.ImageTrackingMode = TrackableImageFindingMode.DISABLE;
NRSessionManager.Instance.SetConfiguration(config);
}
}
[Controllee side]
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using NRKernal;
public class MyImageControllee : MonoBehaviour
{
[SerializeField] private TMP_Text _positionText;
[SerializeField] private TMP_Text _idText;
private NRTrackableImage _image;
private int _imageIndex;
public NRTrackableImage Image
{
set
{
// if (value.GetDataBaseIndex() != _imageIndex)
// {
// _image = null;
// }
_image = value;
_imageIndex = value.GetDataBaseIndex();
}
}
private List<GameObject> _points = new List<GameObject>();
private void Start()
{
for (int i = 1; i < this.transform.childCount; i++)
{
_points.Add(this.transform.GetChild(i).gameObject);
}
}
// Update is called once per frame
void Update()
{
if (_image is null) return;
var center = _image.GetCenterPose();
if (center.position == Vector3.zero) return;
if (_image.GetTrackingState() == TrackingState.Tracking)
{
transform.position = center.position;
transform.rotation = center.rotation;
_positionText.text = center.position.ToString();
_idText.text = _imageIndex.ToString();
transform.position -= _points[_imageIndex].transform.localPosition;
}
}
}
[Controllee Object]
Please refer to the image.
Then the operation is as follows
m0 → m1 → m0 → m1 → m2 → m0 → m2
OK → OK → NG → NG → NG → OK → NG → NG
“OK” means that object moves directly above the marker and updates the text.
With “NG,” the object does not move and the text is not updated.
In the NRSDK sample, the gizmo object is created and destroyed each time according to the tracking status, and we have confirmed that multiple markers can be loaded in this way.
This time, however, we are only changing the position of one instance, and we do not want to destroy it while it is off-tracking.
We only need to move the object to the position of the tracked marker for the one instance that has already been generated.
The ARFoundation ImageTracking provided by Unity works similar to what I have in mind.
Thank you.