Hello there.
I was wondering if it was possible to change the image database for image tracking on like a button click.
I tried something like this:
[SerializeField]
private UnityLogVisualizer logVisualizer;
[SerializeField]
private NRTrackingImageDatabase markerDatabase;
[SerializeField]
private NRTrackingImageDatabase myDatabase;
[SerializeField]
private TMP_Text text;
private NRTrackingImageDatabase currentDatabase;
private NRSessionConfig config;
void Start()
{
if(null != NRSessionManager.Instance.NRSessionBehaviour.SessionConfig)
{
config = NRSessionManager.Instance.NRSessionBehaviour.SessionConfig;
}
if (null != config && null != config.TrackingImageDatabase)
{
currentDatabase = config.TrackingImageDatabase;
}
}
void Update()
{
if (null != text && null != config && null != config.TrackingImageDatabase && config.ImageTrackingMode == TrackableImageFindingMode.ENABLE)
{
text.text = "Active database: "+ config.TrackingImageDatabase.name;
}
}
public void DoSwitchDatabase()
{
if(null == currentDatabase)
{
logVisualizer.AddLog("Current database is null");
return;
}
if (null == markerDatabase)
{
logVisualizer.AddLog("MarkerDatabase is null");
return;
}
if (currentDatabase.name.Equals(markerDatabase.name)){
if(null == myDatabase)
{
logVisualizer.AddLog("MyDatabase is null");
}
ActivateDatabase(myDatabase);
}
else
{
ActivateDatabase(markerDatabase);
}
}
private void ActivateDatabase(NRTrackingImageDatabase newDatabase)
{
if(null != config)
logVisualizer.AddLog(string.Format("Switching database from {0} to {1}", currentDatabase.name, newDatabase.name));
config.ImageTrackingMode = TrackableImageFindingMode.DISABLE;
config.TrackingImageDatabase = newDatabase;
config.ImageTrackingMode = TrackableImageFindingMode.ENABLE;
currentDatabase = newDatabase;
}
the thing is, in the text given in the Update() it shows me that it’s actually changing the database file at the button press.
However, let’s say i’ve bult the apk with database A, if i run the app and look at an image inside database A, it works just fine, but if i then switch to database B and look at an image of this database, it won’t work, but will instead work on the images of database A.
Am I doing something wrong?
Please let me know if you have some questions about it.
Thanks!!
[edit]: I also need to mention that one of the databases is actually one from the coaster pack for xreal markers, so maybe that’s the issue. I don’t know if you REALLY can’t use both “normal image databases” and coasters database in the same applicaiton.