Log in or register to post comments

Keep the 3D object on the device's screen, even without the marker

October 31, 2011 - 6:22pm #1

Dear All,

nowadays I try to learn more about Unity3D qualcomm AR extensions, and I would like to ask your help.

after the first detected and tracked phase, I want to create some AR app that if we touch some GUI button or other function like double tap etc, the 3D object can still appear on the device's screen even without the marker exist on the screen and the 3D object still able to have the user interactivity such as drag and rotate. then when user touch the GUI once again (or double tap once again), the 3D can disappear.

I hope anyone of you can help me to solve this problem. I already try not to put the TrackableEventHandler script but using this way, the 3D object will appear since the beginning of app running. it's not what I want. any kind of help would be highly appreciated.

Markus

Re: Keep the 3D object on the device's screen, even without the

November 1, 2011 - 9:05pm #4

The TrackableEventHander needs to be written in C#, because it extends a QCAR C# interface. You can call javascript methods from this class to handle the OnTrackingFound and OnTrackingLost events. So, for example, you can edit the TrackableEventHander.cs file like this:

    private MyJavascriptClass myJS;

    void Start()
    {
        myJS = (MyJavascriptClass) FindObjectOfType(typeof(MyJavascriptClass));
        ...
    }

    private void OnTrackingLost()
    {
    	myJS.OnTrackingLost(gameObject);
    }

And then your javascript could contain a function like this:

function OnTrackingLost(obj : GameObject)
{
    // add logic for skipping this here
    var rendererComponents : Renderer[];
    rendererComponents = obj.GetComponentsInChildren.<Renderer>();
    for (var component : Renderer in rendererComponents)
    {
        component.enabled = false;
    }
}

The only trick is that your javascript file must be compiled before the C# scripts. You can place it in the Plugins folder to force it to compile first.

For more on compilation order: http://unity3d.com/support/documentation/ScriptReference/index.Script_compilation_28Advanced29.html

- Kim

Re: Keep the 3D object on the device's screen, even without the

October 31, 2011 - 7:32pm #3

Dear Kim,

Thank you so much for your help.
How about if I want to attach the script into some GUI texture so that after the user touch that GUI, the 3D object will stay on the iPad screen even without the marker.

if you dont mind, could you please write the script in java script because I just learn the scripting language and I dont know about C#.
Thank you so much for your help Kim.

Markus

Re: Keep the 3D object on the device's screen, even without the

October 31, 2011 - 6:55pm #2

You can modify the TrackableEventHandler script to do what you want. Something like this:

    public bool mShouldHideAugmentation = true;

    private void OnTrackingLost()
    {
    	if (mShouldHideAugmentation)
    	{
            Renderer[] rendererComponents = GetComponentsInChildren<Renderer>();

            // Disable rendering:
            foreach (Renderer component in rendererComponents) {
                component.enabled = false;
            }

            Debug.Log("Trackable " + mTrackableBehaviour.TrackableName + " lost");
    	}
    }

Then just set mShouldHideAugmentation to true or false in response to some event.

- Kim

Log in or register to post comments