#AR Dynamic Tracking On Image Capture

1 messages · Page 1 of 1 (latest)

astral oar
#
public class ARTrackedImageRuntimeManager : MonoBehaviour
{
    [SerializeField]
    private Button captureImageButton;

    [SerializeField]
    private GameObject trackedImageObject;

    [SerializeField]
    private MutableRuntimeReferenceImageLibrary runtimeImageLibrary;

    private ARTrackedImageManager trackImageManager;

    void Awake()
    {
        Screen.sleepTimeout = SleepTimeout.NeverSleep;
        trackImageManager = gameObject.AddComponent<ARTrackedImageManager>();
        trackImageManager.enabled = true;
        trackImageManager.maxNumberOfMovingImages = 1;
        trackImageManager.trackedImagePrefab = trackedImageObject;
        trackImageManager.trackedImagesChanged += OnTrackedImagesChanged;
        runtimeImageLibrary = trackImageManager.CreateRuntimeLibrary() as MutableRuntimeReferenceImageLibrary;
        captureImageButton.onClick.AddListener(() => StartCoroutine(CaptureImage()));
    }

    private IEnumerator CaptureImage()
    {
        yield return new WaitForEndOfFrame();
        Texture2D texture = ScreenCapture.CaptureScreenshotAsTexture();
        yield return StartCoroutine(AddImageJob(texture));
    }

    public IEnumerator AddImageJob(Texture2D texture2D)
    {
        trackImageManager.enabled = false;
        yield return null;
        JobHandle jobHandle = runtimeImageLibrary.ScheduleAddImageJob(texture2D, Guid.NewGuid().ToString(), 0.1f);
        yield return new WaitUntil(() => jobHandle.IsCompleted);
        trackImageManager.enabled = true;
    }

    void OnTrackedImagesChanged(ARTrackedImagesChangedEventArgs eventArgs)
    {
        foreach (ARTrackedImage trackedImage in eventArgs.added)
            trackedImage.transform.Rotate(Vector3.up, 180);
        foreach (ARTrackedImage trackedImage in eventArgs.updated)
            trackedImage.transform.Rotate(Vector3.up, 180);
    }
}```
#

AR Dynamic Tracking On Image Capture

gloomy isle
#

You did not say what your issue is.

#

Only what you have done/need to do.

astral oar
#

my issue is that script for dynamic tracking is not working at all. my prefab image will never spawn on my mobile device while trying to track a captured image.

gloomy isle
#

I do not know the library itself nor what is your particular issue and what could be the cause. I can only give you general guidance.

The first step would be to try to know what exactly is the issue. You can do this by testing individual part; Taking it small bit by small bit. By example, trying to only do a screenshot.

#

In fact, you might even take it further and try your button first.

astral oar
#

okay, so I have added cs textTester.text = "Number of images in runtimeImageLibrary: " + runtimeImageLibrary.count; in awake after runtimeimagelibrary and end of addImageJob function.

#

it definitely works, it starts from 0 images and then on every button press it goes up by 1.

#

what might be the issue tho is that it wont work because it starts on 0 images

#

I think I have read somewhere that might cause an issue. so what do I do about that?

#

Basically what we know that works is: button and adding images to library

gloomy isle
#

Usually, it is expected to start at 0. If everything works, except the library, you will need to read documentation.

#

If you cannot figure out, you will need to reach out to the developer of the library.