Log in or register to post comments

1 ARCamera and 1 dynamic frame marker?

June 6, 2012 - 6:33am #1

Hello,

what iam trying to do is to use all 512 frame markers in unity.
although not all markers have object in it, just preparing them for future use.

my question:
* is it possible to detect marker id without put all 512 frame markers in unity's scene?

in this case the scene only have 1 ARCamera and 1 dynamic frame marker.

Re: 1 ARCamera and 1 dynamic frame marker?

June 10, 2012 - 6:15am #5

MarkerTracker is null in Editor, we have to deploy it to device to see it work.
cmiiw.

Re: 1 ARCamera and 1 dynamic frame marker?

June 10, 2012 - 5:00am #4

For some reason I keep on getting this error: "NullReferenceException: Object reference not set to an instance of an object" for MarkerBehaviour mb = markerTracker.CreateMarker(i, "marker" + i.ToString(), 100);

Apparently markerTracker is returning null, even though I am calling it not in Start, but in OnGUI and Update as mentioned http://ar.qualcomm.at/node/2001679

NullReferenceException: Object reference not set to an instance of an object

[QUOTE=DavidBeard" />Yes you can create and destroy FrameMarkers procedurally.

This script demonstrates how..
[CODE" />

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();
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 {
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();
}
}[/CODE" />

* the marker ID's don't need to be assigned incrementally.[/QUOTE" />

Re: 1 ARCamera and 1 dynamic frame marker?

June 6, 2012 - 9:24am #3

Great.. thank you DavidBeard :)

Re: 1 ARCamera and 1 dynamic frame marker?

June 6, 2012 - 7:40am #2

Yes you can create and destroy FrameMarkers procedurally.

This script demonstrates how..



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();
    }
}

* the marker ID's don't need to be assigned incrementally.

Log in or register to post comments