Let's say that you have two models named 'modelA' and 'modelB' in your project Hierarchy, and you want to augment your CR targets with these models based on the metadata associated with each target. A simple approach will be to create a text file for each target that contains the name of the associated model, and to upload these text files as the metadata for their respective targets. So one has a metadata file containing the text modelA and the other target's metadata file contains the text modelB.
Then you can use the following code to retrieve the metadata from your CR search result, find and clone the model, and assign this clone as the augmentation for the target. You want to clone the model because the parent target is going to be destroyed whenever a new search result is obtained.
In CloudRecoEventHandler.cs ..
public void OnNewSearchResult(TargetFinder.TargetSearchResult targetSearchResult)
{
string modelName = "";
GameObject model = null;
Vector3 localPos = new Vector3( 0,0,0 ); // to center the model on the target
if( targetSearchResult.MetaData != null ){
modelName = targetSearchResult.MetaData; // the modelName is assigned the metadata text as a string.
Debug.Log("Metadata = "+modelName );
model = GameObject.Find( modelName ); // find the model by this name
Debug.Log("Found model "+ model.name );
}
// duplicate the referenced image target
GameObject newImageTarget = Instantiate(ImageTargetTemplate.gameObject) as GameObject;
// enable the new result with the same ImageTargetBehaviour:
ImageTargetBehaviour imageTargetBehaviour = mImageTracker.TargetFinder.EnableTracking(targetSearchResult, newImageTarget);
if( model != null ){
GameObject modelClone = Instantiate( model ) as GameObject;
// this is how to parent an augmentation w/ an ImageTarget instance
modelClone.transform.parent = imageTargetBehaviour.gameObject.transform;
modelClone.transform.position = localPos;
Debug.Log("Parented "+modelClone.name +" to "+ modelClone.transform.parent.name );
}
if (imageTargetBehaviour != null)
{
// stop the target finder
mCloudRecoBehaviour.CloudRecoEnabled = true;
}
}
I'm using same way and the app is working fine in the below vuforia 4 but after upgrading vuforia 4 it's not augmenting properly...I combined vuforia cloud & video playback app.