Log in or register to post comments

Vuforia Video Playback sample and dynamic image target problem

August 2, 2016 - 8:41pm #1

Hi,

I can't get Vuforia Video Playback sample app to work with dynamically (run-time) loaded image target. The reason I want to use the playback sample is because I want to play video when a dynamically loaded image target is detected and tracked.

Now here what I have done step by step.

1) Installed and launched Unity 5.3.6 Personal Edition on El Capitan OS X and created a new project
2) Imported vuforia-unity-5-5-9.unitypackage
3) Downloaded/imported a 3D model from asset store (doesn't matter whether it's 3D model or video or image)
4) Clicked on ARCamera, opened up the DatabaseLoadBehaviour script and edited it as per the code below (note that the StonesAndChips data set is in folder /Users/E-Learning/Documents/media/)
5) Dragged and dropped the 3D model (step 3) onto the Augmentation Object field of Database Load Behaviour in the Inspector
6) Launched/played Unity Editor and successfully saw the 3D model being rendered against 'stones' image target, which is loaded dynamically
7) Imported VideoPlayback-5-5-9.unitypackage
8) Opened Vuforia-3-VideoPlayback scene and removed ImageTargetStones and ImagaTargetChips from the scene
9) Copied and pasted the below code into the DatabaseLoadBehaviour class/script attached to ARCamera in the scene
10) Launched/played Unity Editor and although I saw the debug comment "Tackable stones found" the 3D model is not visible at all as if there's nothing attached to the image target, but I can see '1:DynamicImageTarget-stones' in the Hierarchy at run-time and there's a child 'Windmill(Clone)' object attached to it, which is the 3D model

QUESTION: I know the dynamic image target code works on its own and I know the video playback sample works on its own, so why combining the two does NOT work??? My goal here is to attach video (MP4) to any custom image target.

public class DatabaseLoadBehaviour : DatabaseLoadAbstractBehaviour
{
// specify these in Unity Inspector
public GameObject augmentationObject = null;  // you can use teapot or other object
string dataSetName;  //  Assets/StreamingAssets/QCAR/DataSetName
bool update = true;

// Use this for initialization
void Start()
{
  dataSetName = "/Users/E-Learning/Documents/media/StonesAndChips.xml";
}

// Update is called once per frame
void Update()
{
  if (update) {
    update = false;
    LoadDataSet ();
  }
}

void LoadDataSet()
{

  ObjectTracker objectTracker = TrackerManager.Instance.GetTracker<ObjectTracker>();

  DataSet dataSet = objectTracker.CreateDataSet();

  if (dataSet.Load(dataSetName, VuforiaUnity.StorageType.STORAGE_ABSOLUTE)) {

    objectTracker.Stop();  // stop tracker so that we can add new dataset

    if (!objectTracker.ActivateDataSet(dataSet)) {
      // Note: ImageTracker cannot have more than 100 total targets activated
      Debug.Log("<color=yellow>Failed to Activate DataSet: " + dataSetName + "</color>");
    }

    if (!objectTracker.Start()) {
      Debug.Log("<color=yellow>Tracker Failed to Start.</color>");
    }

    int counter = 0;

    IEnumerable<TrackableBehaviour> tbs = TrackerManager.Instance.GetStateManager().GetTrackableBehaviours();
    foreach (TrackableBehaviour tb in tbs) {
      if (tb.name == "New Game Object") {

        // change generic name to include trackable name
        tb.gameObject.name = ++counter + ":DynamicImageTarget-" + tb.TrackableName;

        // add additional script components for trackable
        tb.gameObject.AddComponent<DefaultTrackableEventHandler>();
        tb.gameObject.AddComponent<TurnOffBehaviour>();

        if (augmentationObject != null) {
          // instantiate augmentation object and parent to trackable
          GameObject augmentation = (GameObject)GameObject.Instantiate(augmentationObject);
          augmentation.transform.parent = tb.gameObject.transform;
          augmentation.transform.localPosition = new Vector3(0f, 0f, 0f);
          augmentation.transform.localRotation = Quaternion.identity;
          augmentation.transform.localScale = new Vector3(0.4f, 0.4f, 0.4f);
          augmentation.gameObject.SetActive(true);
        } else {
          Debug.Log("<color=yellow>Warning: No augmentation object specified for: " + tb.TrackableName + "</color>");
        }
      }
    }
  } else {
    Debug.LogError("<color=yellow>Failed to load dataset: '" + dataSetName + "'</color>");
  }
}
}

Vuforia Video Playback sample and dynamic image target problem

August 31, 2016 - 9:19pm #3

Thanks medabit for your suggestions, but I have tried all those long time ago and nothing worked.

 

After 3 weeks of excruciating trial and error I have finally figured it out. Turns out that "VideoPlayback-5-5-9.unitypackage" contains scene "Vuforia-3-VideoPlayback.unity". If you open that scene (which I used as the basis for my app) and expand "AR Camera", then click on the child "Camera" and look in the Inspector, then the value for Clipping Planes -> Far is set to 5. After I set it to 1000 I finally saw the augmented objects.

 

I checked another version of the video playback sample package (can't remember its version), and that camera value was set to 5000 (i.e. how far the camera can see)

 

Sorry to say this, but that particular version of the sample package wasted a lot of my time. Not cool, Vuforia

 

AttachmentSize
Image icon CameraDepth.PNG18.46 KB

Vuforia Video Playback sample and dynamic image target problem

August 8, 2016 - 3:16pm #2

Hello,

The two can work together, but you need to make sure that the VideoPlaybackBehaviour script gets attached to the dynamically created objects. If an ImageTarget is dynamically created and an augmentation is added to it as a child at run time, the app code should also take care of attaching the VideoPlaybackBehaviour component to the augmentation gameObject. The app code should take care of programmatically setting the m_Path variable in the VideoPlaybackBehaviour script (this is set through the Unity inspector in the VideoPlayback sample app, but the inspector approach won't work for dynamically created targets). Additionally, the VideoPlayback sample includes a "PlayVideo" script which handles the trigger of a video when the user taps on a target - this script must also be included.

As VideoPlayback is sample code and is not a "drag-and-drop" feature of Vuforia, some minor adaptations (like the ones describe above) may have to be applied.

Thanks.

Log in or register to post comments