Log in or register to post comments

ITrackableEventHandler Implementation in 1.0 Prefab?

May 6, 2011 - 11:02am #1

The Getting Started walk-through for the Unity extension shows a Trackable Event Handler script attached to the Image Target prefab (see below). But this script isn't present in the prefab that I have. Should it be, or is this something that I need to add using the ITrackableEventHandler interface?

I'm trying to determine whether my prefab is corrupt, or if the docs are out of sync with the new extension version.

If it's the latter, how do I implement the interface? Is this simply a matter of defining a concrete class that implements ITrackableEventHandler and adding this to the Image Target prefab instance? - any examples?

What I'm seeing now is that the 3D object that I've added to the scene is rendered regardless of the presence of the image target. It will follow the image target when it's in view, but is always visible regardless of whether the image target is present. I'm guessing that this is because the rendering isn't being controlled by trackable events.

Here's the walk-through screen shot that I'm referring to..

Re: ITrackableEventHandler Implementation in 1.0 Prefab?

May 11, 2011 - 6:34am #10

Most of the Dev Guide is also applicable to Unity. There aren't that many moving parts, really you have the prefabs and the interfaces to work with. The samples provide sample implementations of each interface.

Let us know if there's anything in particular you'd like to know more about!

- Kim

Re: ITrackableEventHandler Implementation in 1.0 Prefab?

May 10, 2011 - 6:07pm #9

So is the extent of the Unity API documentation currently, the sample code, and Getting Started materials? - is there an API doc similar to the QCAR SDK documentation somewhere? I haven't found anything else here, or on the unity3d.com site.

Re: ITrackableEventHandler Implementation in 1.0 Prefab?

May 9, 2011 - 12:44pm #8

aha! - found them. Thanks. I'd blanked on that default install folder, and they don't show up in a search of the file system. But they are there.

Re: ITrackableEventHandler Implementation in 1.0 Prefab?

May 9, 2011 - 12:19pm #7

They're in there, but only the base package is installed to the Unity Standard Packages folder. The samples are installed to the folder that you designate during the installation. Try installing these to a different location that's easy to check.

- Kim

Re: ITrackableEventHandler Implementation in 1.0 Prefab?

May 9, 2011 - 12:11pm #6

I'd used the ar.qualcomm.com installer and those sample packages weren't included. I only have the QCAR 1.0.0 package, and have checked my Unity installation folder to confirm that they're not present. This is why I'd wondered if the docs are out of sync.

If you can confirm that they are included w/ the installer, I'll try a re-install of the extension - do you remove the extension simply by deleting the QCAR 1.0.0 package?

Re: ITrackableEventHandler Implementation in 1.0 Prefab?

May 9, 2011 - 12:01pm #5

The samples are separate Unity packages included in the installer available on this site. They are not available in the Unity Asset Store at this time. The package breakdown is outlined in Step 1 of the Getting Started - Unity Extension guide, at http://ar.qualcomm.com

Quote:

QCAR-1.0.0.unitypackage: the base QCAR extension
QCAR-ImageTargets-1.0.0.unitypackage: a sample project using Image Targets
QCAR-FrameMarkers-1.0.0.unitypackage: a sample project using Frame Markers
QCAR-MultiTargets-1.0.0.unitypackage: a sample project using Multi Targets
QCAR-VirtualButtons-1.0.0.unitypackage: a sample project using Virtual Buttons

For each sample, simply create a new Unity project and import the package. There is a fully set up scene included in each.

- Kim

Re: ITrackableEventHandler Implementation in 1.0 Prefab?

May 9, 2011 - 11:46am #4

Where are these sample apps?

I didn't see any mention of them in the docs, or when installing the extension.

Re: ITrackableEventHandler Implementation in 1.0 Prefab?

May 9, 2011 - 5:40am #3

All of the sample applications include a sample implementation of the ITrackableEventHandler with OnTrackingFound/OnTrackingLost functionality. You're correct that you create a concrete class that implements the interface and attach it to your trackable objects. You can handle these events in any way, but one typical approach is to turn the renderers on and off (as you have done in your sample).

Your code will work if there is a single trackable, in our sample implementation we use GetComponent() to get the TrackableBehaviour attached to the particular trackable the event handler is attached to. This also allows you to create different event handlers per trackable.

- Kim

Re: ITrackableEventHandler Implementation in 1.0 Prefab?

May 6, 2011 - 3:25pm #2

I'm guessing that the TrackableEventHandler is our own implementation of ITrackableEventHandler. So here's what I'm using, which works fine. But I'm new to Unity. Is the following the correct approach for registering the event handler, and also for referencing and controlling the visibility of the 3D model ("earthcube"). This script has been added to the ImageTarget instance as per the walk-through.

using UnityEngine;
using System.Collections;

public class TrackableEventHandler : MonoBehaviour , ITrackableEventHandler {
	
	TrackableBehaviour trackable;
	GameObject earthcube;

	// initialization
	void Start () {
	        trackable =
            (TrackableBehaviour)UnityEngine.Object.FindObjectOfType(
                                                    typeof(TrackableBehaviour));
		
	        trackable.RegisterTrackableEventHandler(this);
		
		earthcube = GameObject.Find("EarthCube");
		earthcube.renderer.enabled = false;
	}
	
	// Update is called once per frame
	void Update () {
	
	}
	
       // Called when the trackable state has changed.
       public void OnTrackableStateChanged(TrackableBehaviour.Status previousStatus,TrackableBehaviour.Status newStatus){
				
		if( newStatus == TrackableBehaviour.Status.DETECTED || newStatus == TrackableBehaviour.Status.TRACKED ){
			earthcube.renderer.enabled = true;
		}else{
			earthcube.renderer.enabled = false;
		}
	}
}
Log in or register to post comments