Log in or register to post comments

creating frame targets dynamically

February 16, 2012 - 7:00am #1

Anyone know if there's a way you can create frame targets dynamically in Unity3D? I was hoping I could instantiate a frame target prefab like 50 times and increment the marker ID for each one. I've tried doing that thru script but it doesn't work. I don't get any errors but it runs with strange side-effects that suggest that when one marker is detected it triggers the detection of all the clones. Is there any way of doing this during runtime or do I have to manually put 50 frame targets into the scene?

creating frame targets dynamically

July 24, 2012 - 7:46am #6

Dynamic FrameMarker creation, and destruction, is a feature of the current release. This script demonstrates how to create and destroy FrameMarkers at runtime..

using UnityEngine;
using System.Collections;

public class MarkerController : MonoBehaviour
{
    private int mNextMarkerID = 0;

    void OnGUI()
    {
        MarkerTracker markerTracker = (MarkerTracker)TrackerManager.Instance.GetTracker(Tracker.Type.MARKER_TRACKER);
       
        GUILayout.BeginArea( new Rect( 25, 100, 300, 500 ) );

        if (GUILayout.Button("Create Marker"))
        {
            MarkerBehaviour mb = markerTracker.CreateMarker(mNextMarkerID, "marker" + mNextMarkerID, 100);
            if (mb != null)
            {
                mb.gameObject.AddComponent<DefaultTrackableEventHandler>();
                GameObject cube = GameObject.CreatePrimitive(PrimitiveType.Cube);
                cube.transform.parent = mb.transform;
                cube.transform.localScale = new Vector3(0.5f, 0.5f, 0.5f);
                cube.transform.localPosition = new Vector3(0.0f, 0.25f, 0.0f);
                mNextMarkerID++;
            }
        }

        if (GUILayout.Button("Destroy Last Marker"))
        {
            for (int i = 0; i < markerTracker.GetNumMarkers(); i++)
            {
                MarkerBehaviour marker = markerTracker.GetMarker(i);
                if (marker.MarkerID == mNextMarkerID - 1)
                {
                    markerTracker.Stop();
                    if (markerTracker.DestroyMarker(marker, true))
                    {
                        mNextMarkerID--;
                    }
                    markerTracker.Start();
                    break;
                }
            }
        }

        if (GUILayout.Button( "Destroy All Markers"))
        {
            markerTracker.DestroyAllMarkers(true);
            mNextMarkerID = 0;
        }
       
        GUILayout.EndArea();
    }
}

creating frame targets dynamically

July 24, 2012 - 12:08am #5

I meet the same problem with you, let's discuss about it. contract me by

Re: creating frame targets dynamically

February 17, 2012 - 4:08pm #4

Also this thread: http://ar.qualcomm.at/node/2001313

1.5 will be officially released in Q1 of this year.

- Kim

Re: creating frame targets dynamically

February 17, 2012 - 4:44am #3

Cool thanks! I have come across your unified coordinate system before but I have yet to use it. Do you know by any chance when QCAR 1.5 Beta becomes an official release?

Re: creating frame targets dynamically

February 16, 2012 - 10:49pm #2

You need the 1.5 beta for this. Look at my code here for an example:
http://ar.qualcomm.at/node/2001030

Log in or register to post comments