Log in or register to post comments

DataSet Type

September 30, 2013 - 9:19pm #1

Hi,
i try to create virtual button in run time, but there is a note said that the database must be deactivated before creating a virtual button.
So, I try to deactivated my data set, but i got a problem, the dataset always return null.
Is there anything wrong if i write the code something like this:

myDataSet.Load("Assets/StreamingAssets/QCAR/TA_5109100114",  DataSet.StorageType.STORAGE_APPRESOURCE);

Thank you,

DataSet Type

October 3, 2013 - 5:03am #12

That's great.
that really help me. Thank you.

I had edited my reply, hehehhehe,, i think i can handle that problem.
But can i ask you another question?

in prefab that i want to instantiate, should i attach the virtual button from the vuforia SDK prefab?
something like this one:

or this one:

and what about the event handler. I want to destroy my object with it's virtual button every times the player touch it.
But, i think i get a problem, because if there are more than 1 object, it's just the first object which can be touched and distroyed.

umm,, i think i want to ask one more question.
in the example virtual button in vuforia, there is file which is replaced in AR Camera, name VirtualButtonMenu. What is this used for?

Thank you, i'm really sorry

DataSet Type

October 2, 2013 - 8:19am #11

Your code below is incorrect because in line 34 you are calling mDataset.Load() without having created it first (see imageTracker.CreateDataset()) at line 18);

 

you need to polish your code so to only Load from file when you are sure that the dataset has been created (otherwise it will be null, logically)

 

DataSet Type

October 2, 2013 - 6:51am #10

I'm so sory, that's my mistake,
i think, i should not put script for creating the virtual button there. I modified it. This is the script that i modified:

void Update () {
		if (waktuCounter <= 0 && i!=1)
		{
			int ran = Random.Range(0,3);
			//instantiate the object
			mObj = (GameObject)Instantiate(semut, posisi[ran], Quaternion.identity);
			//make the object become image target's child
			mObj.transform.parent = imgTargetTemp.transform;
			
			//create Virtual Button
			if(QCARRuntimeUtilities.IsQCAREnabled())
			{
				if(!mDataSetLoaded)
				{
					//load my data set
					imageTracker = TrackerManager.Instance.GetTracker(Tracker.Type.IMAGE_TRACKER) as ImageTracker;
					
					myDataset = imageTracker.CreateDataSet();
					if(myDataset == null)
					{
						Debug.Log("Failed to create dataset, dataset is null");
					}
					else
					{
						Debug.Log("Dataset successfully created.");
					}
					
					myDataset.Load("TA_5109100114");
					Debug.Log("Dataset Loaded from file : " + myDataset.Path);
					mDataSetLoaded = true;
				}								
			}
			imageTracker = TrackerManager.Instance.GetTracker(Tracker.Type.IMAGE_TRACKER) as ImageTracker;
			myDataset.Load("TA_5109100114");
			imageTracker.DeactivateDataSet(myDataset);
			
			//create the virtual button
			vbb = ImageTargetBehaviour.CreateVirtualButton("ant",
				new Vector2(0,0),
				mObj);
			//register an event handler
			vbb.RegisterEventHandler(this);
			
			//Reactivate the dataset
			imageTracker.ActivateDataSet(myDataset);
			i++;
			
			waktuCounter = waktu;
		}		
		waktuCounter-= Time.deltaTime;
	}

but, it got an error, the data set keep return null.

I'm so sorry if i sound so dumb.

DataSet Type

October 2, 2013 - 6:28am #9

your answer is really help me, i'm so excited.
I got no error in my programme, but i cann't find my virtual button that i'd made before.

i modified you code to be like this:

void Update () {
		if (timeCounter<= 0)
		{
			int ran = Random.Range(0,3);
			//instantiate the object
			mObj = (GameObject)Instantiate(semut, posisi[ran], Quaternion.identity);
			//make the object become image target's child
			mObj.transform.parent = imgTargetTemp.transform;
			
			//create Virtual Button
			if(QCARRuntimeUtilities.IsQCAREnabled())
			{
				if(!mDataSetLoaded)
				{
					//load my data set
					imageTracker = TrackerManager.Instance.GetTracker(Tracker.Type.IMAGE_TRACKER) as ImageTracker;
					
					myDataset = imageTracker.CreateDataSet();
					if(myDataset == null)
					{
						Debug.Log("Failed to create dataset, dataset is null");
					}
					else
					{
						Debug.Log("Dataset successfully created.");
					}
					
					myDataset.Load(" TA_5109100114");
					Debug.Log("Dataset Loaded from file : " + myDataset.Path);
					mDataSetLoaded = true;
				}
				imageTracker = TrackerManager.Instance.GetTracker(Tracker.Type.IMAGE_TRACKER) as ImageTracker;
				myDataset.Load(" TA_5109100114");
				imageTracker.DeactivateDataSet(myDataset);
				
				//create the virtual button
				vbb = ImageTargetBehaviour.CreateVirtualButton("ant",
					new Vector2(0,0),
					mObj);
				//register an event handler
				vbb.RegisterEventHandler(this);
				
				//Reactivate the dataset
				imageTracker.ActivateDataSet(myDataset);				
			}
			
			timeCounter= time;
		}		
		timeCounter-= Time.deltaTime;
	}

and i'd modified the xml file to,

this is the print screen of the xml file.

I'm so sorry for always asking you and disturb you,, thank you very much.
I'm going to make a game like ant smasher, did you ever know it before? What do you think, if i create the button one by one, and that buttons will become the clone object's child.
Or may be you have another suggestion?
Thank you.
 

DataSet Type

October 1, 2013 - 6:59am #8

You can define VBs in XML, of course.

Have a look at the VB sample, and also at this page about using VBs in Unity:

https://developer.vuforia.com/resources/dev-guide/virtual-buttons-unity

 

DataSet Type

October 1, 2013 - 5:47am #7

thank you very much, :)
should i write my virtual button in .xml file? like the teapot example?

Thank you, i'm so sorry,, i am just too afraid if i make a mistake.
and sorry for my bad english

DataSet Type

October 1, 2013 - 5:42am #6

Tarmac (in my example) is the name of the Dataset, i..e the name of the XML file located in your StreamingAssets/QCAR dir,

it is not the name of the specific Image Target; 

note that a Dataset may contain multiple Image Targets (for instance, the ChipsAndStones dataset contains two targets, one is Chips and one is Stones);

in your case, you would use the TA_5109100114, provided that you have a Dataset whose files are:

TA_5109100114.xml

TA_5109100114.dat

 

DataSet Type

October 1, 2013 - 5:32am #5

thanks for your respond, this is very usefull for me,, :)
but can i ask you something?
Is "Tarmac" the name of image target that i defined in inspector or the name of image target prefab that i put in hierarchy?

In my case, in inspector, my image target prefab's name is aRthSmasherWood but in hierarchy, i keep the name ImageTarget. Which one is it?

this one

or this one

i'm so sorry, i'm newbie here.

DataSet Type

October 1, 2013 - 4:34am #4

Looking at your code, you miss the Dataset creation step, i.e.e you need to add a line like this, before calling "Load()":

ImageTracker imageTracker = TrackerManager.Instance.GetTracker(Tracker.Type.IMAGE_TRACKER) as ImageTracker;
				
DataSet myDataset = imageTracker.CreateDataSet();

And this is a little test scripts that I have quickly written up and you can use for reference:

public class LoadDataset : MonoBehaviour {
	
	private bool mDataSetLoaded = false;
	
	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
		if (QCARRuntimeUtilities.IsQCAREnabled()) {
			if (!mDataSetLoaded) {
				
				// Load my dataset
				ImageTracker imageTracker = TrackerManager.Instance.GetTracker(Tracker.Type.IMAGE_TRACKER) as ImageTracker;
				
				DataSet myDataset = imageTracker.CreateDataSet();
				if (myDataset == null) {
					Debug.Log ("Failed to create dataset, dataset is null");	
				}
				else {
					Debug.Log ("Dataset successfully created.");	
				}
				
				myDataset.Load("Tarmac");
				
				Debug.Log ("Dataset loaded from file: " + myDataset.Path);
				
				mDataSetLoaded = true;
			}
		}
	}
}

Hope this helps.

 

As a side note: you don't actually need to include the ".xml" extension in the filename (see my code above).

DataSet Type

October 1, 2013 - 12:00am #3

It still returns null, and the virtual button can not be created.
Would You like to help me? May be you can find my mistakes.
 

using UnityEngine;
using System.Collections;

public class ImgTargetBehaviour : MonoBehaviour , IVirtualButtonEventHandler{
	#region PRIVATE_VARIABLES	
	private GameObject mObj;
	const float timer = 5f;
	float timeCounter;
	private static VirtualButtonBehaviour vbb;
	#endregion
	
	#region PUBLIC_VARIABLES
	//public GameObject obj;
	public Vector3 [] pos;
	public GameObject obj;
	public int ran;
	public GameObject imgTargetTemp;
	public DataSet myDataSet;
	#endregion
	
	#region UNITY_MONO_BEHVIOUR_METHODS
	// Use this for initialization
	void Start () {
		imgTargetTemp = GameObject.Find("ImageTarget");
		myDataSet.Load("TA_5109100114.xml",  DataSet.StorageType.STORAGE_APPRESOURCE);
	}
	
	// Update is called once per frame
	void Update () {
		if (timeCounter <= 0)
		{
			ran = Random.Range(0,2);
			
			//instantiate the object
			mObj = (GameObject)Instantiate(obj, pos[ran], Quaternion.identity);
			
			//make object to child of image target					
			mObj.transform.parent = imgTargetTemp.transform;
			
			// Create a virtual button	
			
			ImageTracker imageTracker = (ImageTracker)TrackerManager.Instance.GetTracker(Tracker.Type.IMAGE_TRACKER);

           	imageTracker.DeactivateDataSet(myDataSet);           
			 
			// Create a virtual button
			//ImageTargetBehaviour itb = GetComponent<ImageTargetBehaviour>();
			vbb = ImageTargetBehaviour.CreateVirtualButton("ant",
			        new Vector2(0, 0),
			        mObj);
			 
			// Register an event handler
			// Here we assume this class extends IVirtualButtonEventHandler
			vbb.RegisterEventHandler(this);
			 
			// Reactivate the dataset
			imageTracker.ActivateDataSet(myDataSet);
			
			i++;
			//set time for loading the object
			timeCounter = timer;
		}		
		timeCounter-= Time.deltaTime;
	}
	#endregion
	
	#region PUBLIC_METHODS
    /// <summary>
    /// Called when the virtual button has just been pressed:
    /// </summary>
    public void OnButtonPressed(VirtualButtonBehaviour vb)
    {
        Debug.Log("OnButtonPressed");
		Destroy(gameObject);
    }


    /// <summary>
    /// Called when the virtual button has just been released:
    /// </summary>
    public void OnButtonReleased(VirtualButtonBehaviour vb)
    {
        Debug.Log("OnButtonReleased");
    }

    #endregion // PUBLIC_METHODS
}

This is my script. I'm sorry if there are a lot of wrong script there,.

Thank you very much.

DataSet Type

September 30, 2013 - 11:41pm #2

You should not use the full path in this case (as you are using STORAGE_APPRESOURCES);

simply use the name of your dataset, and also make sure to add the XML extension, i.e.:

myDataSet.Load("TA_5109100114.xml",  DataSet.StorageType.STORAGE_APPRESOURCE);

Log in or register to post comments