Log in or register to post comments

Reloading dataset while looking at an ImageMarker messes up the alignment of items

March 14, 2012 - 5:19pm #8

Hi

I have an app that uses the Unity plugin that can change datasets at runtime - the problem I have is that if I load the new dataset while I am currently looking at one of the ImageTargets with the camera, the positioning of everything seems to get offset by an amount equal to the offset of the ImageTarget in the cameras frame, and it won't get fixed until I quit the app and re-launch.

Anyone else experienced this and have a work-around?

Re: Reloading dataset while looking at an ImageMarker messes up

March 14, 2012 - 6:18pm #7

Are you deactivating the dataset associated with the target's ImageTracker first?

Check out the Swappable Datasets section of the Getting Started Guide under Unity Extension : Mastering Advanced Topics.

https://ar.qualcomm.at/qdevnet/sdk

Re: Reloading dataset while looking at an ImageMarker messes up

March 14, 2012 - 6:49pm #6

I am! I even tried putting a delay in the time between de-activating and then creating a new one

Re: Reloading dataset while looking at an ImageMarker messes up

March 14, 2012 - 7:01pm #5

Can you post the code that you're using? I'll try to reproduce the problem.

So what you're seeing is that when swapping datasets, if a target from the prior dataset is actively being tracked, that the new trackables will show a persistent offset of their models that seems to relate to the position of the prior trackable on the screen? - is that accurate?

Re: Reloading dataset while looking at an ImageMarker messes up

March 19, 2012 - 9:09pm #4

Yes that is an accurate summary.

The code is kind of part of too much stuff to easily post it but I'll try and put together a paired down thing and see if I can replicate it there.

Re: Reloading dataset while looking at an ImageMarker messes up

March 22, 2012 - 5:39pm #3

I did some more investigating. I wrote a function to print outt the location of things, like this:

	public void PrintDebugInfo()
	{
		Debug.Log("Camera is at: " + Camera.mainCamera.transform.position);
		
		GameObject[] trackables = GameObject.FindGameObjectsWithTag("Trackable");
		
		foreach (GameObject trackable in trackables)
		{
			Debug.Log("Trackable " + trackable.name + " is located at: " + trackable.transform.position);
		}
	}

I then load a dataset containing two image targets, one named ArtSchoolPrep and one named Zimmerman.

Running the debug functions gives results like this:

Camera is at: (256.0, 230.0, -149.0)
Trackable ArtSchoolPrep is located at: (0.0, 0.0, 0.0)
Trackable Zimmerman is located at: (0.0, 0.0, 0.0)

I then reload the same dataset, while the Zimmerman trackable is in view, with code something like this:


private bool LoadDataSet (string dataSetPath, DataSet.StorageType storageType)
{	
	if (dataSet != null) {
		DestroyDataSet (dataSet);
		dataSet = null;
	}
	// Check if the data set exists at the given path.
	if (!DataSet.Exists (dataSetPath, storageType)) {
		Debug.LogError ("Data set " + dataSetPath + " does not exist.");
		return false;
	}

	// Request an ImageTracker instance from the TrackerManager.
	ImageTracker imageTracker = (ImageTracker)TrackerManager.Instance.GetTracker (Tracker.Type.IMAGE_TRACKER);

	// Create a new empty data set.
	dataSet = imageTracker.CreateDataSet ();

	// Load the data set from the given path.
	if (!dataSet.Load (dataSetPath, storageType)) {
		Debug.LogError ("Failed to load data set " + dataSetPath + ".");
		return false;
	}
	// (Optional) Activate the data set.
	imageTracker.ActivateDataSet (dataSet);

	AttachContentToTrackables (dataSet); // This attaches game objects as children of the dataset game objects

	PrintDebugInfo();

	return true;
	}
}


// Destroy a dataset.
private bool DestroyDataSet (DataSet dataSet)
{
	
	// Request an ImageTracker instance from the TrackerManager.
	ImageTracker imageTracker = (ImageTracker)TrackerManager.Instance.GetTracker (Tracker.Type.IMAGE_TRACKER);
	
	// Make sure the data set is not active.
	imageTracker.DeactivateDataSet (dataSet);
	
	// (choose true to also destroy the Trackable objects that belong to the data set).
	bool success = imageTracker.DestroyDataSet (dataSet, true);
	
	return success;
}

// Add Trackable event handler and content to the Trackables.
private void AttachContentToTrackables (DataSet dataSet)
{
	// Get the number of Trackables defined in the data set.
	int numTrackables = dataSet.GetNumTrackables ();
	// Loop over all Trackables.
	for (int i = 0; i < numTrackables; ++i) {
		DataSetTrackableBehaviour dstb = dataSet.GetTrackable (i);
		
		TrackableData data = null;
		// Find the data that goes with this trackable...
		for (int j = 0; j < issue.trackables.Count; j++) {
			if (issue.trackables[j].id == dstb.TrackableName) {
				data = issue.trackables[j];
				break;
			}
		}
		
		if (data == null)
			continue;
		
		CreateTrackableObject (dstb, data); // This creates various GameObjects based ont he contents of data, and sets their parent to the dstb.gameObject
		
	}
}

After doing that, I get values like this from my PritnDebugInfo function:

Camera is at: (256.0, 230.0, -149.0)
Trackable Trackable: ArtSchoolPrep is located at: (0.0, 0.0, 0.0)
Trackable Trackable: Zimmerman is located at: (27.1, -1.9, -19.8)

So Zimmerman has been offset from the position it should be at, and is no longer at 0,0,0.

I tried forcing it back to 0,0,0 in my CreateTrackableObject function but the QCAR stuff sets it back to the offset position right away.

Any ideas or workarounds? I had a feeling it could be related to the "World Center Mode" setting but I don't really understand what that setting does.

Re: Reloading dataset while looking at an ImageMarker messes up

March 22, 2012 - 6:29pm #2

I'm going to try to recreate this. Which World Center Mode are you using? - AUTO?

If you reload the dataset with ArtSchoolPrep in view, is that trackable offset?

The world center mode allows you to define the origin of the world coordinates that you want to use.

    // The world center mode defines how the relative coordinates between
    // Trackables and camera are translated into Unity world coordinates.
    // If a world center is present the virtual camera in the Unity scene is
    // transformed with respect to that.
    // The world center mode is set through the Unity inspector.
    public enum WorldCenterMode
    {
        // User defines a single Trackable that defines the world center.
        USER,
        // Tracker uses the first Trackable that comes into view as the world
        // center (world center changes during runtime).
        AUTO,
        // Do not define a world center but only move Trackables with respect
        // to a fixed camera.
        NONE
    }

BTW why are you reloading the same dataset?

Re: Reloading dataset while looking at an ImageMarker messes up

March 25, 2012 - 4:12pm #1

Yes Auto.

And yes, any image marker will be offset if you do this, not just the Zimmerman one.

As for why I am reloading the same data set - I guess that is a good point :). It's mostly because my 3D data is being driven by a CMS. I guess I can just detect if the data set is the same on reload and only load my CMS driven content instead.

Log in or register to post comments