Unity - Loading DataSet from SD Card

October 7, 2013 - 2:23am #1

The Vuforia SDK allows loading datasets from various locations;

if your device has an SD card, one option is to store your dataset (.XML and .DAT files) into the external storage (SD Card) of your device and to tell Vuforia to load it from there.

The following code snippet shows how this can be achieved within a simple C# script; in this example, we assume that the dataset is called Tarmac and the relevant files (Tarmac.xml and Tarmac.dat) have been copied into the SD card path '/mnt/sdcard/':

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class SDCardDataSetLoader : MonoBehaviour {
	
	private bool mLoaded = false;
	private DataSet mDataset = null;
	
	// Update is called once per frame
	void Update () {
		if (QCARRuntimeUtilities.IsQCAREnabled() && !mLoaded) {
			
			string externalPath = "/mnt/sdcard/tarmac.xml";
			
			if (mDataset == null) {
				// First, create the dataset
				ImageTracker tracker = TrackerManager.Instance.GetTracker(Tracker.Type.IMAGE_TRACKER) as ImageTracker;
				mDataset = tracker.CreateDataSet();
			}
			
			if (mDataset.Load(externalPath, DataSet.StorageType.STORAGE_ABSOLUTE)) {
				mLoaded = true;	
			}
			else {
				Debug.LogError ("Failed to load dataset!");	
			}
		}
	}
}

 

Topic locked