Log in or register to post comments

1 Model 10 Trackers

October 19, 2011 - 9:07am #1

Hi,
I'm looking for a little bit of advice on the best way to accomplish what I would assume to be a fairly common task. Unfortunately I can't for the life of me find the answer.

I have a Unity QCAR Project that needs to track 10 different trackers. The trackers have been uploaded to the Tracking Web app and downloaded as a custom unity package, and imported into the project. The Experience is exactly the same regardless of which tracker is tracked -- a 3D model is displayed and animated. The part I can't figure out is the best way to set up the project.

I've tried adding 10 different Imagetargets and attaching the model to each of them but there is a HUGE performance hit when you do this. Ideally I'd like to be able to set which tracker QCAR should be looking for when I load the scene, as it only needs to look for one tracker at a given time, and I'll know which tracker it should be looking for when the scene loads, I thought I could do this programatically, however after a look at TrackableBehaviour.cs this appears to be not allowed. Acknowledging this is not allowed what is the best way to accomplish the task at hand without creating 10 different scenes?

Please point me in the right direction.

Thanks

Joe

#######TrackableBehaviour.cs#########
// The name of the trackable.
public string TrackableName
{
get { return mTrackableName; }
set
{
if (!Application.isEditor)
{
Debug.LogError("TrackableBehaviour: The name of a trackable " +
"must not be set at run-time.");
return;
}

mTrackableName = value;
}
}

Re: 1 Model 10 Trackers

October 28, 2011 - 6:10am #4

Thanks Kim, works like a charm! :)

What worked for me was duplicating the original TrackableEventHandler script that is attached with the ImageMarker prefab and pasted just these lines from Kim`s code:

if (mModel != null)
{
    mModel.transform.position = tb.transform.position;
    mModel.transform.rotation = tb.transform.rotation;
}

Then I switched the original TrackableEventHandler to my custom one, it has the same base functionalities and also sets my model position to the current trackable one.

Re: 1 Model 10 Trackers

October 19, 2011 - 7:43pm #3

One option would be to disable the trackables that you aren't interested in:

trackable.enabled = false;

Another option is to have the model present in your scene but not bound to any trackables. You can handle the trackable events by hand yourself, something like this:

using UnityEngine;

// A custom handler that implements the ITrackerEventHandler interface.
public class MatchTrackablePose : MonoBehaviour,
                                  ITrackerEventHandler
{

    public GameObject mModel = null;

    private TrackableBehaviour[] mTrackableBehaviours;

    void Start()
    {
        TrackerBehaviour trackerBehaviour = GetComponent<TrackerBehaviour>();
        if (trackerBehaviour)
        {
            trackerBehaviour.RegisterTrackerEventHandler(this);
        }

        mTrackableBehaviours = (TrackableBehaviour[]) FindObjectsOfType(typeof(TrackableBehaviour));
    }


    // Implementation of the ITrackerEventHandler function called after all
    // trackables have changed.
    public void OnTrackablesUpdated()
    {
        foreach (TrackableBehaviour tb in mTrackableBehaviours)
        {
            if (tb.CurrentStatus == TrackableBehaviour.Status.DETECTED ||
                tb.CurrentStatus == TrackableBehaviour.Status.TRACKED)
            {
                Debug.Log("found trackable " + tb.TrackableName);

                if (mModel != null)
                {
                    mModel.transform.position = tb.transform.position;
                    mModel.transform.rotation = tb.transform.rotation;
                }
            }
        }
    }
}

Note you'll have to add logic to hide the model when the trackable is lost.

- Kim

Re: 1 Model 10 Trackers

October 19, 2011 - 2:09pm #2

I think this might be my issue as well. I'm trying to use a complex model with 3 different markers, and i am just brute force copying the model 3 times attached to each marker... But, this might be causing my Unity app to just take too long to load for iOS to just auto-crash it (but it runs when connected by USB)

Log in or register to post comments