Log in or register to post comments

DataSet.Exists works on IOS but not on Android

March 12, 2012 - 12:56am #1

I am trying to load a dataset placed in StramingAssets\QCAR in the Unity3d editor. The code below works fine on IOS but on Android it fails to find the dataset. If I use an absolute path, it works though. Testing is done on Windows with Unity3d, and using the windows Vuforia SDK of course. This is the code I use:

void createImageTargetsRuntime(){
	
	if(!ARinitialized){
		
		ImageTracker imageTracker = (ImageTracker)TrackerManager.Instance.GetTracker(Tracker.Type.IMAGE_TRACKER);
		
		if(imageTracker != null){
		
			DataSet.StorageType storageType = DataSet.StorageType.STORAGE_APPRESOURCE;
			string dataSetPath = "/QCAR/ImageTargets.xml";
	
			//TODO: figure out why it can't find the dataset on Android.
			if(!DataSet.Exists(dataSetPath, storageType)){
				
				Debug.LogError("Dataset does not exist");					
				message0 = message1 = "Marker dataset not found. Program can not run.";
				startMessage(3);
			}
			
			dataSet = imageTracker.CreateDataSet();			
			dataSet.Load(dataSetPath, storageType);
			imageTracker.ActivateDataSet(dataSet);			
			markerAmount = dataSet.GetNumTrackables();
			
			for(int i = 0; i < markerAmount; i++){
	
				//set the size of the image targets
				imageTargetBehaviours[i] = dataSet.GetTrackable(i);	

#if SAMESIZE
				//TODO: this is caused by a confirmed bug. Remove this line once the bug is fixed.
				//reset the scale because imageTargetBehaviours[i].gameObject contains an incorrect scale.
				//In the meantime, if not all markers in the scene have the same size, set the correct scale
				//manually here for each of them. But apparently this bug only happens when the x size in the
				//xml file is 1, so if another size is used, it should work fine. In that case, delete this line.
				imageTargetBehaviours[i].gameObject.transform.localScale = new Vector3(1,1,1);
#endif
				//set the game object
				rootObjects[i] = imageTargetBehaviours[i].gameObject;

				//set the name
				rootObjects[i].name = "Root Object " + i;

				//get this particular image target size
				ImageTargetBehaviour imageTargetBehaviour = imageTargetBehaviours[i].gameObject.GetComponent<ImageTargetBehaviour>();
				Vector2 fullSize = imageTargetBehaviour.GetSize();
    			markerSize[i] = fullSize / 2.0f;
				
				//create a line object (square outline) 
				outlineObjects[i] = Instantiate(outlinePrefab, Vector3.zero, outlinePrefab.transform.rotation) as GameObject; 
				
				outlineObjects[i].transform.localScale = new Vector3(markerSize[i].x * 2, 0.001f, markerSize[i].y * 2);
				
				//attach a line object to the marker
				outlineObjects[i].transform.parent = rootObjects[i].transform;	
	
				//set the relative location to zero
				outlineObjects[i].transform.localPosition = Vector3.zero;
				outlineObjects[i].transform.localRotation = Quaternion.identity;
	
				//Make the rootObjects a child of the camera to make the positioning logic the same as with String
				rootObjects[i].transform.parent = Camera.main.transform;	
				
				rootObjectsFiltered[i] = new GameObject("Filtered " + rootObjects[i].transform.name);
				rootObjectsFiltered[i].transform.parent = rootObjects[i].transform.parent;
				
				//Just before we instantiate the outline prefab, we need to set the marker size global variable which
				//will be fetched by the AxisLineManager script attached to the prefab.
				markerSizeGlobal = markerSize[i];
				
				//create markerLine
				markerlineObjects[i] = Instantiate(markerlinePrefab, Vector3.zero, Quaternion.identity) as GameObject;
				markerlineObjects[i].active = false;
				markerlineObjects[i].transform.parent = rootObjectsReference[i].transform;
			}
			
			ARinitialized = true;
		}
		
		//imageTracker==null
		else{
			TrackerManager.Instance.InitTracker(Tracker.Type.IMAGE_TRACKER);
		}
	}
}

Any ideas?

Edit:
It works on both Android and IOS if I remove the extension and don't use the StorageType variable. Is it caused by a bug? How comes the code above does work on IOS?

Here is the working code:

string dataSetName = "ImageTargets";

if(!DataSet.Exists(dataSetName)){
	
	Debug.LogError("Dataset does not exist");					
	message0 = message1 = "Marker dataset not found. Program can not run.";
	startMessage(3);
}

dataSet = imageTracker.CreateDataSet();			
dataSet.Load(dataSetName);
imageTracker.ActivateDataSet(dataSet);			
markerAmount = dataSet.GetNumTrackables();

Re: DataSet.Exists works on IOS but not on Android

March 12, 2012 - 11:19pm #3

Using "QCAR/ImageTargets.xml" instead of "/QCAR/ImageTargets.xml" on both Android and IOS works.
Thanks.

Re: DataSet.Exists works on IOS but not on Android

March 12, 2012 - 1:45pm #2

If you set the data set path to "QCAR/ImageTargets.xml" instead of "/QCAR/ImageTargets.xml" does that help? Also note that there are two default methods that append the "QCAR/" automatically:

public static bool Exists(String name)
public bool Load(String name)

Look at those methods in DataSet.cs and you'll see that they don't include a leading "/". The extra slash might cause a platform-dependent issue.

- Kim

Log in or register to post comments